blob: 74c2036b05b7ce4f4e3381c7f78ac9c14225f2c3 [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);
Jeff Johnson9d295242017-08-29 14:39:48 -07007195 struct hdd_adapter *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
7256 total_rx += adapter->stats.rx_packets;
7257 total_tx += adapter->stats.tx_packets;
7258
7259 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7260 adapter->prev_tx_packets = adapter->stats.tx_packets;
7261 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307262 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7263 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007264 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7265 connected = true;
7266 }
7267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007268 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007269 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007270 return;
7271 }
7272
Yun Parka29974a2018-04-09 12:05:49 -07007273 /* add intra bss forwarded tx and rx packets */
7274 tx_packets += fwd_tx_packets_diff;
7275 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007276
Yun Parka29974a2018-04-09 12:05:49 -07007277 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7278 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7279 &ipa_rx_packets);
7280 tx_packets += (uint64_t)ipa_tx_packets;
7281 rx_packets += (uint64_t)ipa_rx_packets;
7282
7283 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7284 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7285 }
7286
7287 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007288
Jingxiang Gec64e1932017-08-22 14:38:59 +08007289restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007290 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007291 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007292 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307293 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007294 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007295 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007296}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007297
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307298/**
7299 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7300 * @arg: Argument of timer function
7301 *
7302 * Schedule a workqueue in this function where all the processing is done.
7303 *
7304 * Return: None.
7305 */
7306static void __hdd_bus_bw_cbk(void *arg)
7307{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007308 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307309
7310 if (wlan_hdd_validate_context(hdd_ctx))
7311 return;
7312
7313 schedule_work(&hdd_ctx->bus_bw_work);
7314}
7315
7316/**
7317 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7318 * @arg: Argument of timer function
7319 *
7320 * Return: None.
7321 */
7322static void hdd_bus_bw_cbk(void *arg)
7323{
7324 cds_ssr_protect(__func__);
7325 __hdd_bus_bw_cbk(arg);
7326 cds_ssr_unprotect(__func__);
7327}
7328
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007329int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007330{
7331 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307332 INIT_WORK(&hdd_ctx->bus_bw_work,
7333 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007334 hdd_ctx->bus_bw_timer_running = false;
7335 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307336 qdf_timer_init(NULL,
7337 &hdd_ctx->bus_bw_timer,
7338 hdd_bus_bw_cbk, (void *)hdd_ctx,
7339 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007340
7341 return 0;
7342}
7343
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007344void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007345{
Dustin Brownfce08d12017-01-17 16:29:38 -08007346 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007347 hdd_reset_tcp_delack(hdd_ctx);
7348
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007349 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307350 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307351 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007352 hdd_ctx->bus_bw_timer_running = false;
7353 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007354}
Lin Baic5c06882017-09-21 13:58:43 +08007355
7356void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7357{
7358 if (hdd_ctx)
7359 cancel_work_sync(&hdd_ctx->bus_bw_work);
7360}
jiadcdaf9bd2017-10-26 12:20:21 +08007361
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007362#endif
7363
7364/**
Nirav Shahed34b212016-04-25 10:59:16 +05307365 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7366 * @hdd_ctx: hdd context
7367 *
7368 * Return: 0 for success or error code
7369 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007370static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307371{
7372 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7373 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7374 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007375 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307376 return -ENOMEM;
7377 }
7378 return 0;
7379}
7380
7381/**
7382 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7383 * @hdd_ctx: hdd context
7384 *
7385 * Return: none
7386 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007387void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307388{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307389 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7390 return;
7391
7392 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7393 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307394}
7395
Nirav Shahda008342016-05-17 18:50:40 +05307396static uint8_t *convert_level_to_string(uint32_t level)
7397{
7398 switch (level) {
7399 /* initialize the wlan sub system */
7400 case WLAN_SVC_TP_NONE:
7401 return "NONE";
7402 case WLAN_SVC_TP_LOW:
7403 return "LOW";
7404 case WLAN_SVC_TP_MEDIUM:
7405 return "MED";
7406 case WLAN_SVC_TP_HIGH:
7407 return "HIGH";
7408 default:
7409 return "INVAL";
7410 }
7411}
7412
Nirav Shahed34b212016-04-25 10:59:16 +05307413
7414/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007415 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7416 * @hdd_ctx: hdd context
7417 *
7418 * Return: none
7419 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007420void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007421{
7422 int i;
7423
7424#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007425 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307426 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007427 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007428 hdd_ctx->config->busBandwidthHighThreshold,
7429 hdd_ctx->config->busBandwidthMediumThreshold,
7430 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007431 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307432 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007433 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007434 hdd_ctx->config->tcpDelackThresholdHigh,
7435 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007436 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307437 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007438#endif
7439
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007440 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307441 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7442
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007443 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007444
7445 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007446 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007447 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007448 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7449 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7450 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7451 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7452 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007453 hdd_ctx->hdd_txrx_hist[i].
7454 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007455 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007456 hdd_ctx->hdd_txrx_hist[i].
7457 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007458 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007459 hdd_ctx->hdd_txrx_hist[i].
7460 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007461 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007462}
7463
7464/**
7465 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7466 * @hdd_ctx: hdd context
7467 *
7468 * Return: none
7469 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007470void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007471{
7472 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307473 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7474 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007475}
7476
Mohit Khannaca4173b2017-09-12 21:52:19 -07007477/* length of the netif queue log needed per adapter */
7478#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7479
7480/**
7481 *
7482 * hdd_display_netif_queue_history_compact() - display compact netifq history
7483 * @hdd_ctx: hdd context
7484 *
7485 * Return: none
7486 */
7487static void
7488hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7489{
7490 int adapter_num = 0;
7491 int i;
7492 int bytes_written;
7493 u32 tbytes;
7494 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007495 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007496 char *comb_log_str;
7497 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007498 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007499
jiadbdefb252018-01-03 14:27:06 +08007500 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7501 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7502 if (!comb_log_str) {
7503 hdd_err("failed to alloc comb_log_str");
7504 return;
7505 }
7506
Mohit Khannaca4173b2017-09-12 21:52:19 -07007507 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007508
Dustin Brown920397d2017-12-13 16:27:50 -08007509 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007510 curr_time = qdf_system_ticks();
7511 total = curr_time - adapter->start_time;
7512 delta = curr_time - adapter->last_time;
7513
7514 if (adapter->pause_map) {
7515 pause = adapter->total_pause_time + delta;
7516 unpause = adapter->total_unpause_time;
7517 } else {
7518 unpause = adapter->total_unpause_time + delta;
7519 pause = adapter->total_pause_time;
7520 }
7521
7522 tbytes = 0;
7523 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7524 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7525 if (adapter->queue_oper_stats[i].pause_count == 0)
7526 continue;
7527 tbytes +=
7528 snprintf(
7529 &temp_str[tbytes],
7530 (tbytes >= sizeof(temp_str) ?
7531 0 : sizeof(temp_str) - tbytes),
7532 "%d(%d,%d) ",
7533 i,
7534 adapter->queue_oper_stats[i].
7535 pause_count,
7536 adapter->queue_oper_stats[i].
7537 unpause_count);
7538 }
7539 if (tbytes >= sizeof(temp_str))
7540 hdd_warn("log truncated");
7541
7542 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007543 bytes_written >= comb_log_str_size ? 0 :
7544 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007545 "[%d %d] (%d) %u/%ums %s|",
7546 adapter->session_id, adapter->device_mode,
7547 adapter->pause_map,
7548 qdf_system_ticks_to_msecs(pause),
7549 qdf_system_ticks_to_msecs(total),
7550 temp_str);
7551
Mohit Khannaca4173b2017-09-12 21:52:19 -07007552 adapter_num++;
7553 }
7554
7555 /* using QDF_TRACE to avoid printing function name */
7556 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7557 "STATS |%s", comb_log_str);
7558
jiadbdefb252018-01-03 14:27:06 +08007559 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007560 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007561
7562 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007563}
7564
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007565/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007566 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007567 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007568 *
7569 * Return: none
7570 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007571void
7572wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7573 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007574{
7575
Jeff Johnson9d295242017-08-29 14:39:48 -07007576 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007577 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307578 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007579
Mohit Khannaca4173b2017-09-12 21:52:19 -07007580 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7581 hdd_display_netif_queue_history_compact(hdd_ctx);
7582 return;
7583 }
7584
Dustin Brown920397d2017-12-13 16:27:50 -08007585 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007586 hdd_debug("Netif queue operation statistics:");
7587 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007588 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007589 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307590 curr_time = qdf_system_ticks();
7591 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307592 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307593 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307594 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307595 unpause = adapter->total_unpause_time;
7596 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307597 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307598 pause = adapter->total_pause_time;
7599 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007600 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307601 qdf_system_ticks_to_msecs(total),
7602 qdf_system_ticks_to_msecs(pause),
7603 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007604 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007605
Nirav Shahda008342016-05-17 18:50:40 +05307606 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7607 qdf_time_t pause_delta = 0;
7608
7609 if (adapter->pause_map & (1 << i))
7610 pause_delta = delta;
7611
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007612 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007613 hdd_debug("%s: %d: %d: %ums",
7614 hdd_reason_type_to_string(i),
7615 adapter->queue_oper_stats[i].pause_count,
7616 adapter->queue_oper_stats[i].unpause_count,
7617 qdf_system_ticks_to_msecs(
7618 adapter->queue_oper_stats[i].total_pause_time +
7619 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007620 }
7621
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007622 hdd_debug("Netif queue operation history:");
7623 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307624 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7625
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007626 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627
7628 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007629 /* using hdd_log to avoid printing function name */
7630 if (adapter->queue_oper_history[i].time == 0)
7631 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007632 hdd_debug("%d: %u: %s: %s: %x",
7633 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007634 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007635 hdd_action_type_to_string(
7636 adapter->queue_oper_history[i].netif_action),
7637 hdd_reason_type_to_string(
7638 adapter->queue_oper_history[i].netif_reason),
7639 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007640 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007641 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007642}
7643
7644/**
7645 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7646 * @hdd_ctx: hdd context
7647 *
7648 * Return: none
7649 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007650void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007651{
Jeff Johnson9d295242017-08-29 14:39:48 -07007652 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007653
Dustin Brown920397d2017-12-13 16:27:50 -08007654 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307655 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007656 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307657 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007658 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307659 adapter->history_index = 0;
7660 adapter->start_time = adapter->last_time = qdf_system_ticks();
7661 adapter->total_pause_time = 0;
7662 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007663 }
7664}
7665
7666/**
7667 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7668 * @halHandle: Hal handle
7669 * @pContext: Pointer to the context
7670 * @sessionId: Session ID
7671 * @scanId: Scan ID
7672 * @status: Status
7673 *
7674 * This is the callback to be executed when 11d scan is completed to flush out
7675 * the scan results
7676 *
7677 * 11d scan is done during driver load and is a passive scan on all
7678 * channels supported by the device, 11d scans may find some APs on
7679 * frequencies which are forbidden to be used in the regulatory domain
7680 * the device is operating in. If these APs are notified to the supplicant
7681 * it may try to connect to these APs, thus flush out all the scan results
7682 * which are present in SME after 11d scan is done.
7683 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307684 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007685 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307686static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007687 uint8_t sessionId, uint32_t scanId,
7688 eCsrScanStatus status)
7689{
Dustin Brown491d54b2018-03-14 12:39:11 -07007690 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007691
7692 sme_scan_flush_result(halHandle);
7693
Dustin Browne74003f2018-03-14 12:51:58 -07007694 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007695
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307696 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007697}
7698
7699#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7700/**
7701 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7702 * @hdd_ctx: hdd global context
7703 *
7704 * Return: none
7705 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007706static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007707{
7708 uint8_t i;
7709
7710 mutex_init(&hdd_ctx->op_ctx.op_lock);
7711 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7712 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7713 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7714 }
7715}
7716#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007717static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007718{
7719}
7720#endif
7721
Yingying Tang95409972016-10-20 15:16:15 +08007722#ifdef WLAN_FEATURE_WOW_PULSE
7723/**
7724 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007725 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007726 * @enable: enable or disable this behaviour
7727 *
7728 * Return: int
7729 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007730static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007731{
7732 struct hdd_config *pcfg_ini = phddctx->config;
7733 struct wow_pulse_mode wow_pulse_set_info;
7734 QDF_STATUS status;
7735
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007736 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007737
7738 if (false == phddctx->config->wow_pulse_support)
7739 return 0;
7740
7741 /* prepare the request to send to SME */
7742 if (enable == true) {
7743 wow_pulse_set_info.wow_pulse_enable = true;
7744 wow_pulse_set_info.wow_pulse_pin =
7745 pcfg_ini->wow_pulse_pin;
7746 wow_pulse_set_info.wow_pulse_interval_low =
7747 pcfg_ini->wow_pulse_interval_low;
7748 wow_pulse_set_info.wow_pulse_interval_high =
7749 pcfg_ini->wow_pulse_interval_high;
7750 } else {
7751 wow_pulse_set_info.wow_pulse_enable = false;
7752 wow_pulse_set_info.wow_pulse_pin = 0;
7753 wow_pulse_set_info.wow_pulse_interval_low = 0;
7754 wow_pulse_set_info.wow_pulse_interval_high = 0;
7755 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007756 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007757 wow_pulse_set_info.wow_pulse_enable,
7758 wow_pulse_set_info.wow_pulse_pin,
7759 wow_pulse_set_info.wow_pulse_interval_low,
7760 wow_pulse_set_info.wow_pulse_interval_high);
7761
7762 status = sme_set_wow_pulse(&wow_pulse_set_info);
7763 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007764 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007765 return -EIO;
7766 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007767 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007768 return 0;
7769}
7770#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007771static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007772{
7773 return 0;
7774}
7775#endif
7776
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007777#ifdef WLAN_FEATURE_FASTPATH
7778/**
7779 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7780 * @hdd_cfg: hdd config
7781 * @context: lower layer context
7782 *
7783 * Return: none
7784 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307785void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007786 void *context)
7787{
7788 if (hdd_cfg->fastpath_enable)
7789 hif_enable_fastpath(context);
7790}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007791#endif
7792
Yuanyuan Liu13738502016-04-06 17:41:37 -07007793#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007794/**
7795 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007796 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007797 * @level: thermal level
7798 *
7799 * Change IPA data path to SW path when the thermal throttle level greater
7800 * than 0, and restore the original data path when throttle level is 0
7801 *
7802 * Return: none
7803 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007804static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007805{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007806 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007808 /* Change IPA to SW path when throttle level greater than 0 */
7809 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307810 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007811 else
7812 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307813 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007814}
7815
7816/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307817 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7818 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307819 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007820 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307821 * Get a safe channel to restart SAP. PCL already takes into account the
7822 * unsafe channels. So, the PCL is validated with the ACS range to provide
7823 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007824 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307825 * Return: Channel number to restart SAP in case of success. In case of any
7826 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007827 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307828static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007829 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007830{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307831 struct sir_pcl_list pcl;
7832 QDF_STATUS status;
7833 uint32_t i, j;
7834 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007835 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307836 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007837 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007838
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307839 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7840 if (!hdd_ctx) {
7841 hdd_err("invalid HDD context");
7842 return INVALID_CHANNEL_ID;
7843 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007844
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307845 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7846 if (!hal_handle) {
7847 hdd_err("invalid HAL handle");
7848 return INVALID_CHANNEL_ID;
7849 }
7850
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007851 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7852 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007853 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7854 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307855 if (QDF_IS_STATUS_ERROR(status)) {
7856 hdd_err("Get PCL failed");
7857 return INVALID_CHANNEL_ID;
7858 }
7859
Frank Liudc2cefb2017-06-21 15:38:18 +08007860 /*
7861 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7862 * channel is unsafe channel, the pcl may be empty, instead of return,
7863 * try to choose a safe channel from acs range.
7864 */
7865 if (!pcl.pcl_len)
7866 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307867
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007868 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007869 adapter->session.ap.sap_config.acs_cfg.start_ch,
7870 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307871
7872 /* PCL already takes unsafe channel into account */
7873 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007874 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307875 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007876 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307877 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007878 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007879 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307880 return pcl.pcl_list[i];
7881 }
7882 }
7883
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007884 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307885
7886 /* Try for safe channel from all valid channel */
7887 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007888 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7889 &pcl.pcl_len);
7890 if (ret) {
7891 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307892 return INVALID_CHANNEL_ID;
7893 }
7894
7895 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007896 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307897 found = false;
7898 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007899 if (pcl.pcl_list[i] ==
7900 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007901 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307902 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007903 break;
7904 }
7905 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307906
7907 if (found)
7908 continue;
7909
7910 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007911 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307912 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007913 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007914 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307915 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007916 }
7917 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307918
7919 return INVALID_CHANNEL_ID;
7920}
Nirav Shaheb017be2018-02-15 11:20:58 +05307921#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307922
7923/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007924 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307925 * @adapter: AP adapter
7926 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007927 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307928 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007929 * Moves the SAP interface by invoking the function which
7930 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307931 *
7932 * Return: None
7933 */
Min Liu2fef5792018-01-19 17:59:42 +08007934void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7935 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307936{
Jeff Johnson87251032017-08-29 13:31:11 -07007937 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307938 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007939 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307940
7941 if (!adapter) {
7942 hdd_err("invalid adapter");
7943 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007944 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307945
7946 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7947
7948 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7949 if (!hal_handle) {
7950 hdd_err("invalid HAL handle");
7951 return;
7952 }
7953
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007954 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7955
Jeff Johnson91df29d2017-10-27 19:29:50 -07007956 hdd_ap_ctx->sap_config.channel = channel;
7957 hdd_ap_ctx->sap_config.ch_params.ch_width =
7958 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307959
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007960 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007961 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307962
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007963 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007964 hdd_ap_ctx->sap_config.channel,
7965 hdd_ap_ctx->sap_config.sec_ch,
7966 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307967
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007968 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007969 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007970 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007971}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307972
Jeff Johnson9d295242017-08-29 14:39:48 -07007973int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307974{
7975 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307976 int status;
7977 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307978
7979 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7980
7981 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007982 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307983 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007984 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307985 }
7986 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007987 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307988 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307989 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007990 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307991 WLAN_VENDOR_ACS_WAIT_TIME);
7992 if (qdf_status != QDF_STATUS_SUCCESS) {
7993 hdd_err("failed to start external acs timer");
7994 return -ENOSPC;
7995 }
7996 /* Update config to application */
7997 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07007998 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307999
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308000 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308001}
8002
Nirav Shaheb017be2018-02-15 11:20:58 +05308003#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308004/**
8005 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8006 * @hdd_ctx: hdd context pointer
8007 *
8008 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8009 * and if ACS is enabled, driver will ask userspace to restart the
8010 * sap. User space on LTE coex indication restart driver.
8011 *
8012 * Return - none
8013 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008014void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308015{
Dustin Brown920397d2017-12-13 16:27:50 -08008016 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308017 uint32_t i;
8018 bool found = false;
8019 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008020
Dustin Brown920397d2017-12-13 16:27:50 -08008021 hdd_for_each_adapter(hdd_ctxt, adapter) {
8022 if (!(adapter->device_mode == QDF_SAP_MODE &&
8023 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008024 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008025 adapter->device_mode,
8026 adapter->session.ap.sap_config.
8027 acs_cfg.acs_mode);
8028 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308029 }
8030
8031 found = false;
8032 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08008033 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05308034 hdd_ctxt->unsafe_channel_list[i]) {
8035 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008036 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08008037 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308038 break;
8039 }
8040 }
8041
8042 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008043 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008044 adapter->session.ap.operating_channel);
8045 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308046 }
8047
Kapil Gupta8878ad92017-02-13 11:56:04 +05308048 if (hdd_ctxt->config->vendor_acs_support &&
8049 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008050 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308051 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008052 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308053 } else
8054 restart_chan =
8055 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008056 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308057 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008058 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308059 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008060 /*
8061 * SAP restart due to unsafe channel. While
8062 * restarting the SAP, make sure to clear
8063 * acs_channel, channel to reset to
8064 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308065 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008066 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308067 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008068 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308069 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008070 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308071 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8072 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008073 hdd_debug("driver to start sap: %d",
8074 hdd_ctxt->config->sap_internal_restart);
8075 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008076 hdd_switch_sap_channel(adapter, restart_chan,
8077 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008078 else
8079 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308080 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308081 }
8082}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308083
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008084/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008085 * hdd_init_channel_avoidance() - Initialize channel avoidance
8086 * @hdd_ctx: HDD global context
8087 *
8088 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008089 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008090 * down to the lower layers. Then subscribe to subsequent channel
8091 * avoidance events.
8092 *
8093 * Return: None
8094 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008095static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008096{
8097 uint16_t unsafe_channel_count;
8098 int index;
8099
Yuanyuan Liu13738502016-04-06 17:41:37 -07008100 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8101 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008102 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008103 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008104
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008105 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008106 hdd_ctx->unsafe_channel_count);
8107
Anurag Chouhan6d760662016-02-20 16:05:43 +05308108 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008109 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008110
8111 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008112 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008113 hdd_ctx->unsafe_channel_list[index]);
8114
8115 }
8116
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008117}
Dustin Brown676a2322017-08-15 13:16:13 -07008118
Jeff Johnson9d295242017-08-29 14:39:48 -07008119static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008120 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008121{
8122 uint8_t restart_chan;
8123
8124 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8125 if (!restart_chan) {
8126 hdd_alert("fail to restart SAP");
8127 return;
8128 }
8129
8130 /* SAP restart due to unsafe channel. While restarting
8131 * the SAP, make sure to clear acs_channel, channel to
8132 * reset to 0. Otherwise these settings will override
8133 * the ACS while restart.
8134 */
8135 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008136 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008137
8138 hdd_debug("sending coex indication");
8139
8140 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8141 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008142 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008143}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008144
8145int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8146 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8147{
8148 uint32_t size;
8149 uint16_t *unsafe_list;
8150 uint16_t chan_count;
8151
8152 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8153 return -EINVAL;
8154
8155 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8156 NUM_CHANNELS);
8157 if (chan_count) {
8158 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8159 unsafe_list = qdf_mem_malloc(size);
8160 if (!unsafe_list) {
8161 hdd_err("No memory for unsafe chan list size%d",
8162 size);
8163 return -ENOMEM;
8164 }
8165 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8166 } else {
8167 unsafe_list = NULL;
8168 }
8169
8170 *local_unsafe_list = unsafe_list;
8171 *local_unsafe_list_count = chan_count;
8172
8173 return 0;
8174}
8175
8176bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8177 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8178{
8179 int i, j;
8180
8181 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8182 return true;
8183 if (local_unsafe_list_count == 0)
8184 return false;
8185 for (i = 0; i < local_unsafe_list_count; i++) {
8186 for (j = 0; j < local_unsafe_list_count; j++)
8187 if (local_unsafe_list[i] ==
8188 hdd_ctx->unsafe_channel_list[j])
8189 break;
8190 if (j >= local_unsafe_list_count)
8191 break;
8192 }
8193 if (i >= local_unsafe_list_count) {
8194 hdd_info("unsafe chan list same");
8195 return false;
8196 }
8197
8198 return true;
8199}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008200#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008201static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008202{
8203}
Dustin Brown676a2322017-08-15 13:16:13 -07008204
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008205static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008206{
8207}
Dustin Brown676a2322017-08-15 13:16:13 -07008208
Jeff Johnson9d295242017-08-29 14:39:48 -07008209static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008210 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008211{
8212 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8213}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008214#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008215
8216/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008217 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8218 * user space
8219 * @frame_ind: Management frame data to be informed.
8220 *
8221 * This function is used to indicate management frame to
8222 * user space
8223 *
8224 * Return: None
8225 *
8226 */
8227void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8228{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008229 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008230 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008231 int i;
8232
Rajeev Kumard004abc2016-02-17 12:09:56 -08008233 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008234 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008235
8236 if (0 != wlan_hdd_validate_context(hdd_ctx))
8237 return;
8238
8239 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8240 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8241 adapter =
8242 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8243 if (adapter)
8244 break;
8245 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008246 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8247 hdd_for_each_adapter(hdd_ctx, adapter) {
8248 if ((NULL != adapter) &&
8249 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8250 __hdd_indicate_mgmt_frame(adapter,
8251 frame_ind->frame_len,
8252 frame_ind->frameBuf,
8253 frame_ind->frameType,
8254 frame_ind->rxChan,
8255 frame_ind->rxRssi);
8256 }
8257 }
8258 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008259 } else {
8260 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8261 frame_ind->sessionId);
8262 }
8263
8264 if ((NULL != adapter) &&
8265 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8266 __hdd_indicate_mgmt_frame(adapter,
8267 frame_ind->frame_len,
8268 frame_ind->frameBuf,
8269 frame_ind->frameType,
8270 frame_ind->rxChan,
8271 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008272}
8273
Kapil Gupta8878ad92017-02-13 11:56:04 +05308274void hdd_acs_response_timeout_handler(void *context)
8275{
8276 struct hdd_external_acs_timer_context *timer_context =
8277 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008278 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008279 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308280 uint8_t reason;
8281
Dustin Brown491d54b2018-03-14 12:39:11 -07008282 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308283 if (!timer_context) {
8284 hdd_err("invlaid timer context");
8285 return;
8286 }
8287 adapter = timer_context->adapter;
8288 reason = timer_context->reason;
8289
8290
8291 if ((!adapter) ||
8292 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8293 hdd_err("invalid adapter or adapter has invalid magic");
8294 return;
8295 }
8296 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8297 if (wlan_hdd_validate_context(hdd_ctx))
8298 return;
8299
8300 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8301 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8302 else
8303 return;
8304
8305 hdd_err("ACS timeout happened for %s reason %d",
8306 adapter->dev->name, reason);
8307 switch (reason) {
8308 /* SAP init case */
8309 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8310 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8311 false);
8312 wlan_hdd_cfg80211_start_acs(adapter);
8313 break;
8314 /* DFS detected on current channel */
8315 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8316 wlan_sap_update_next_channel(
8317 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8318 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008319 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308320 break;
8321 /* LTE coex event on current channel */
8322 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8323 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8324 break;
8325 default:
8326 hdd_info("invalid reason for timer invoke");
8327
8328 }
8329}
8330
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008331/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008332 * hdd_override_ini_config - Override INI config
8333 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008334 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008335 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008336 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008337 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008338 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008339static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008340{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008341
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008342 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8343 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008344 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008345 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008346 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008347 if (0 == enable_11d || 1 == enable_11d) {
8348 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008349 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008350 }
Leo Chang11545d62016-10-17 14:53:50 -07008351
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308352 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008353 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008354 hdd_debug("IpaConfig override to %d",
8355 hdd_ctx->config->IpaConfig);
8356 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308357
8358 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8359 !hdd_ctx->config->enable_bcast_probe_rsp) {
8360 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8361 hdd_ctx->config->rssi_assoc_reject_enabled,
8362 hdd_ctx->config->enable_bcast_probe_rsp);
8363 hdd_ctx->config->oce_sta_enabled = 0;
8364 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008365}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008366
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008367/**
8368 * hdd_set_trace_level_for_each - Set trace level for each INI config
8369 * @hdd_ctx - HDD context
8370 *
8371 * Set trace level for each module based on INI config.
8372 *
8373 * Return: None
8374 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008375static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008376{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308377 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8378 hdd_ctx->config->qdf_trace_enable_wdi);
8379 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8380 hdd_ctx->config->qdf_trace_enable_hdd);
8381 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8382 hdd_ctx->config->qdf_trace_enable_sme);
8383 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8384 hdd_ctx->config->qdf_trace_enable_pe);
8385 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8386 hdd_ctx->config->qdf_trace_enable_wma);
8387 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8388 hdd_ctx->config->qdf_trace_enable_sys);
8389 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8390 hdd_ctx->config->qdf_trace_enable_qdf);
8391 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8392 hdd_ctx->config->qdf_trace_enable_sap);
8393 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8394 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8395 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8396 hdd_ctx->config->qdf_trace_enable_bmi);
8397 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8398 hdd_ctx->config->qdf_trace_enable_cfg);
8399 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8400 hdd_ctx->config->qdf_trace_enable_epping);
8401 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8402 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8403 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008404 hdd_ctx->config->qdf_trace_enable_txrx);
8405 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8406 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308407 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8408 hdd_ctx->config->qdf_trace_enable_htc);
8409 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8410 hdd_ctx->config->qdf_trace_enable_hif);
8411 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8412 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8413 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8414 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008415 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8416 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008417 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8418 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008419 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8420 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008421 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8422 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008424 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008425}
8426
8427/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008428 * hdd_context_init() - Initialize HDD context
8429 * @hdd_ctx: HDD context.
8430 *
8431 * Initialize HDD context along with all the feature specific contexts.
8432 *
8433 * return: 0 on success and errno on failure.
8434 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008435static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008436{
8437 int ret;
8438
8439 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8440 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8441
8442 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308443 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008444
8445 init_completion(&hdd_ctx->mc_sus_event_var);
8446 init_completion(&hdd_ctx->ready_to_suspend);
8447
8448 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308449 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008450 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308451
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008452 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008453
8454 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8455
8456 ret = hdd_scan_context_init(hdd_ctx);
8457 if (ret)
8458 goto list_destroy;
8459
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008460 hdd_rx_wake_lock_create(hdd_ctx);
8461
8462 ret = hdd_sap_context_init(hdd_ctx);
8463 if (ret)
8464 goto scan_destroy;
8465
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008466 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8467
8468 hdd_init_offloaded_packets_ctx(hdd_ctx);
8469
8470 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8471 hdd_ctx->config);
8472 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008473 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008474
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308475 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8476 "monitor_mode_wakelock");
8477
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008478 return 0;
8479
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008480sap_destroy:
8481 hdd_sap_context_destroy(hdd_ctx);
8482
8483scan_destroy:
8484 hdd_scan_context_destroy(hdd_ctx);
8485 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008486list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008487 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008488
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008489 return ret;
8490}
8491
8492/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308493 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8494 * @hdd_ctx: pointer to hdd context
8495 *
8496 * Return: status of initialization
8497 * 0 - success
8498 * negative value - failure
8499 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008500static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308501{
8502 int ret;
8503
8504 if (!hdd_ctx->config->probe_req_ie_whitelist)
8505 return 0;
8506
8507 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8508 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8509 hdd_ctx->config->probe_req_ie_whitelist = false;
8510 return -EINVAL;
8511 }
8512
8513 /* parse ini string probe req oui */
8514 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8515 if (ret) {
8516 hdd_err("parsing error: disable ie whitelisting");
8517 hdd_ctx->config->probe_req_ie_whitelist = false;
8518 }
8519
8520 return ret;
8521}
8522
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308523/**
8524 * hdd_iface_change_callback() - Function invoked when stop modules expires
8525 * @priv: pointer to hdd context
8526 *
8527 * This function is invoked when the timer waiting for the interface change
8528 * expires, it shall cut-down the power to wlan and stop all the modules.
8529 *
8530 * Return: void
8531 */
8532static void hdd_iface_change_callback(void *priv)
8533{
8534 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8535 int ret;
8536 int status = wlan_hdd_validate_context(hdd_ctx);
8537
8538 if (status)
8539 return;
8540
Dustin Brown491d54b2018-03-14 12:39:11 -07008541 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308542 hdd_debug("Interface change timer expired close the modules!");
8543 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8544 if (ret)
8545 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008546 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308547}
8548
Nirav Shaheb017be2018-02-15 11:20:58 +05308549#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8550static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8551{
8552 wlan_logging_set_log_to_console(hdd_ctx->config->
8553 wlan_logging_to_console);
8554 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8555}
8556#else
8557static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8558{ }
8559#endif
8560
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308561/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008562 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308563 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008564 *
8565 * Allocate and initialize HDD context. HDD context is allocated as part of
8566 * wiphy allocation and then context is initialized.
8567 *
8568 * Return: HDD context on success and ERR_PTR on failure
8569 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008570static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008571{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308572 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008573 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008574 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008575
Dustin Brown491d54b2018-03-14 12:39:11 -07008576 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008577
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008578 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008579 if (hdd_ctx == NULL) {
8580 ret = -ENOMEM;
8581 goto err_out;
8582 }
8583
Dustin Brown6f427922017-09-19 12:19:00 -07008584 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8585 hdd_iface_change_callback,
8586 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308587
8588 mutex_init(&hdd_ctx->iface_change_lock);
8589
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008590 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308591 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008592
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308593 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008594 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008595 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008596 ret = -ENOMEM;
8597 goto err_free_hdd_context;
8598 }
8599
8600 /* Read and parse the qcom_cfg.ini file */
8601 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308602 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308603 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008604 WLAN_INI_FILE);
8605 ret = -EINVAL;
8606 goto err_free_config;
8607 }
8608
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308609 ie_whitelist_attrs_init(hdd_ctx);
8610
Dustin Brown7f939932017-05-18 15:02:17 -07008611 hdd_debug("setting timer multiplier: %u",
8612 hdd_ctx->config->timer_multiplier);
8613 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8614
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008615
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308616 if (hdd_ctx->config->fhostNSOffload)
8617 hdd_ctx->ns_offload_enable = true;
8618
Abhishek Singh5ea86532016-04-27 14:10:53 +05308619 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8620
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008621 hdd_override_ini_config(hdd_ctx);
8622
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008623 ret = hdd_context_init(hdd_ctx);
8624
8625 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008626 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008627
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008628 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308629 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008630
Anurag Chouhan6d760662016-02-20 16:05:43 +05308631 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008632 goto skip_multicast_logging;
8633
8634 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8635
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008636 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8637 if (ret)
8638 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308639
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008640 ret = hdd_init_netlink_services(hdd_ctx);
8641 if (ret)
8642 goto err_deinit_txrx_histogram;
8643
Nirav Shaheb017be2018-02-15 11:20:58 +05308644 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308645
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008646skip_multicast_logging:
8647 hdd_set_trace_level_for_each(hdd_ctx);
8648
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008649 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8650
Dustin Browne74003f2018-03-14 12:51:58 -07008651 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008652
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008653 return hdd_ctx;
8654
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008655err_deinit_txrx_histogram:
8656 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8657
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008658err_deinit_hdd_context:
8659 hdd_context_deinit(hdd_ctx);
8660
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008661err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308662 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008663
8664err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308665 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008666 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008667
8668err_out:
8669 return ERR_PTR(ret);
8670}
8671
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008672#ifdef WLAN_OPEN_P2P_INTERFACE
8673/**
8674 * hdd_open_p2p_interface - Open P2P interface
8675 * @hdd_ctx: HDD context
8676 * @rtnl_held: True if RTNL lock held
8677 *
8678 * Open P2P interface during probe. This function called to open the P2P
8679 * interface at probe along with STA interface.
8680 *
8681 * Return: 0 on success and errno on failure
8682 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008683static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008684{
Jeff Johnson9d295242017-08-29 14:39:48 -07008685 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008686 uint8_t *p2p_dev_addr;
8687
8688 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8689 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008690 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008691 hdd_ctx->config->intfMacAddr[0].bytes,
8692 sizeof(tSirMacAddr));
8693
8694 /*
8695 * Generate the P2P Device Address. This consists of
8696 * the device's primary MAC address with the locally
8697 * administered bit set.
8698 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008699 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008700 } else {
8701 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8702 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008703 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008704 return -ENOSPC;
8705 }
8706
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008707 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8708 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008709 }
8710
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008711 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008712 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008713 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008714
8715 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008716 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008717 return -ENOSPC;
8718 }
8719
8720 return 0;
8721}
8722#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008723static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008724 bool rtnl_held)
8725{
8726 return 0;
8727}
8728#endif
8729
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008730static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008731{
Jeff Johnson9d295242017-08-29 14:39:48 -07008732 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008733 int ret = 0;
8734
8735 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8736 wlan_hdd_get_intf_addr(hdd_ctx),
8737 NET_NAME_UNKNOWN, rtnl_held);
8738 if (adapter == NULL) {
8739 hdd_err("Failed to open 802.11p interface");
8740 ret = -ENOSPC;
8741 }
8742
8743 return ret;
8744}
8745
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008746/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308747 * hdd_start_station_adapter()- Start the Station Adapter
8748 * @adapter: HDD adapter
8749 *
8750 * This function initializes the adapter for the station mode.
8751 *
8752 * Return: 0 on success or errno on failure.
8753 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008754int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308755{
8756 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008757 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308758
Dustin Brownfdf17c12018-03-14 12:55:34 -07008759 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008760 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8761 hdd_err("session is already opened, %d",
8762 adapter->session_id);
8763 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8764 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308765
Krunal Sonib51eec72017-11-20 21:53:01 -08008766 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8767 if (ret) {
8768 hdd_err("failed to create vdev: %d", ret);
8769 return ret;
8770 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308771 status = hdd_init_station_mode(adapter);
8772
8773 if (QDF_STATUS_SUCCESS != status) {
8774 hdd_err("Error Initializing station mode: %d", status);
8775 return qdf_status_to_os_return(status);
8776 }
8777
Arun Khandavallifae92942016-08-01 13:31:08 +05308778 hdd_register_tx_flow_control(adapter,
8779 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008780 hdd_tx_resume_cb,
8781 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308782
Dustin Browne74003f2018-03-14 12:51:58 -07008783 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308784 return 0;
8785}
8786
8787/**
8788 * hdd_start_ap_adapter()- Start AP Adapter
8789 * @adapter: HDD adapter
8790 *
8791 * This function initializes the adapter for the AP mode.
8792 *
8793 * Return: 0 on success errno on failure.
8794 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008795int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308796{
8797 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008798 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008799 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008800 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308801
Dustin Brown491d54b2018-03-14 12:39:11 -07008802 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308803
Krunal Sonib51eec72017-11-20 21:53:01 -08008804 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8805 hdd_err("session is already opened, %d",
8806 adapter->session_id);
8807 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8808 }
8809 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008810 * In SSR case no need to create new sap context.
8811 * Otherwise create sap context first and then create
8812 * vdev as while creating the vdev, driver needs to
8813 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008814 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008815 if (adapter->session.ap.sap_context) {
8816 is_ssr = true;
8817 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008818 hdd_err("sap creation failed");
8819 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8820 }
8821
8822 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8823 adapter->session.ap.sap_context);
8824 if (ret) {
8825 hdd_err("failed to create vdev, status:%d", ret);
8826 hdd_sap_destroy_ctx(adapter);
8827 return ret;
8828 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008829
8830 if (adapter->device_mode == QDF_SAP_MODE)
8831 sme_cli_set_command(adapter->session_id,
8832 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8833 (bool)(hdd_ctx->config->fine_time_meas_cap &
8834 WMI_FW_AP_RTT_RESPR),
8835 VDEV_CMD);
8836
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008837 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308838
8839 if (QDF_STATUS_SUCCESS != status) {
8840 hdd_err("Error Initializing the AP mode: %d", status);
8841 return qdf_status_to_os_return(status);
8842 }
8843
Arun Khandavallifae92942016-08-01 13:31:08 +05308844 hdd_register_tx_flow_control(adapter,
8845 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008846 hdd_softap_tx_resume_cb,
8847 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308848
Dustin Browne74003f2018-03-14 12:51:58 -07008849 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308850 return 0;
8851}
8852
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308853static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8854 bool rtnl_held)
8855{
8856 struct hdd_adapter *adapter;
8857
8858 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8859 hdd_ctx->config->enableConcurrentSTA,
8860 wlan_hdd_get_intf_addr(hdd_ctx),
8861 NET_NAME_UNKNOWN, rtnl_held);
8862
8863 if (!adapter)
8864 return -ENOSPC;
8865
8866 return 0;
8867}
8868
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308869/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008870 * hdd_open_interfaces - Open all required interfaces
8871 * hdd_ctx: HDD context
8872 * rtnl_held: True if RTNL lock is held
8873 *
8874 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8875 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008876 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008877 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008878static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008879{
Jeff Johnson9d295242017-08-29 14:39:48 -07008880 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008881 int ret;
8882
Ravi Joshia307f632017-07-17 23:41:41 -07008883 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008884 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8885 con_mode == QDF_GLOBAL_FTM_MODE) {
8886 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8887 QDF_MONITOR_MODE : QDF_FTM_MODE;
8888
8889 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8890 wlan_hdd_get_intf_addr(hdd_ctx),
8891 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008892 if (!adapter) {
8893 hdd_err("open adapter failed");
8894 return -ENOSPC;
8895 }
Lin Bai1c678482017-12-18 18:29:11 +08008896
Ravi Joshia307f632017-07-17 23:41:41 -07008897 return 0;
8898 }
8899
Jeff Johnson957bc272017-02-02 08:54:48 -08008900 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308901 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008902 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008903
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008904 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008905 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008906 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008907
8908 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008909 return -ENOSPC;
8910
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308911 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8912 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8913 if (ret)
8914 hdd_err("Cannot create concurrent STA interface");
8915 }
8916
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008917 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8918 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008919 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008920
8921 /* Open 802.11p Interface */
8922 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008923 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8924 if (ret)
8925 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008926 }
8927
Jeff Johnson957bc272017-02-02 08:54:48 -08008928 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008929
Jeff Johnson957bc272017-02-02 08:54:48 -08008930err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008931 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008932 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008933}
8934
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008935
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308936#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8937/**
8938 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8939 * @cds_cfg: CDS Configuration
8940 * @hdd_ctx: Pointer to hdd context
8941 *
8942 * Return: none
8943 */
8944static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8945 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008946 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308947{
8948 cds_cfg->tx_flow_stop_queue_th =
8949 hdd_ctx->config->TxFlowStopQueueThreshold;
8950 cds_cfg->tx_flow_start_queue_offset =
8951 hdd_ctx->config->TxFlowStartQueueOffset;
8952}
8953#else
8954static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8955 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008956 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308957{
8958}
8959#endif
8960
8961#ifdef FEATURE_WLAN_RA_FILTERING
8962/**
8963 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8964 * @cds_cfg: CDS Configuration
8965 * @hdd_ctx: Pointer to hdd context
8966 *
8967 * Return: none
8968 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308969static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008970 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308971{
8972 cds_cfg->ra_ratelimit_interval =
8973 hdd_ctx->config->RArateLimitInterval;
8974 cds_cfg->is_ra_ratelimit_enabled =
8975 hdd_ctx->config->IsRArateLimitEnabled;
8976}
8977#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308978static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008979 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308980{
8981}
8982#endif
8983
8984/**
8985 * hdd_update_cds_config() - API to update cds configuration parameters
8986 * @hdd_ctx: HDD Context
8987 *
8988 * Return: 0 for Success, errno on failure
8989 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008990static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308991{
8992 struct cds_config_info *cds_cfg;
8993
8994 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8995 if (!cds_cfg) {
8996 hdd_err("failed to allocate cds config");
8997 return -ENOMEM;
8998 }
8999
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009000 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009001 if (!hdd_ctx->config->nMaxPsPoll ||
9002 !hdd_ctx->config->enablePowersaveOffload) {
9003 cds_cfg->powersave_offload_enabled =
9004 hdd_ctx->config->enablePowersaveOffload;
9005 } else {
9006 if ((hdd_ctx->config->enablePowersaveOffload ==
9007 PS_QPOWER_NODEEPSLEEP) ||
9008 (hdd_ctx->config->enablePowersaveOffload ==
9009 PS_LEGACY_NODEEPSLEEP))
9010 cds_cfg->powersave_offload_enabled =
9011 PS_LEGACY_NODEEPSLEEP;
9012 else
9013 cds_cfg->powersave_offload_enabled =
9014 PS_LEGACY_DEEPSLEEP;
9015 hdd_info("Qpower disabled in cds config, %d",
9016 cds_cfg->powersave_offload_enabled);
9017 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309018 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9019 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9020 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9021 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309022
9023 /*
9024 * Copy the DFS Phyerr Filtering Offload status.
9025 * This parameter reflects the value of the
9026 * dfs_phyerr_filter_offload flag as set in the ini.
9027 */
9028 cds_cfg->dfs_phyerr_filter_offload =
9029 hdd_ctx->config->fDfsPhyerrFilterOffload;
9030 if (hdd_ctx->config->ssdp)
9031 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9032
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309033 cds_cfg->force_target_assert_enabled =
9034 hdd_ctx->config->crash_inject_enabled;
9035
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309036 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9037 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9038
9039 cds_cfg->ap_maxoffload_reorderbuffs =
9040 hdd_ctx->config->apMaxOffloadReorderBuffs;
9041
9042 cds_cfg->ap_disable_intrabss_fwd =
9043 hdd_ctx->config->apDisableIntraBssFwd;
9044
9045 cds_cfg->dfs_pri_multiplier =
9046 hdd_ctx->config->dfsRadarPriMultiplier;
9047 cds_cfg->reorder_offload =
9048 hdd_ctx->config->reorderOffloadSupport;
9049
9050 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309051 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009052 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9053 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009054 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009055 hdd_ctx->config->IpaUcTxBufCount);
9056 hdd_ctx->config->IpaUcTxBufCount =
9057 rounddown_pow_of_two(
9058 hdd_ctx->config->IpaUcTxBufCount);
9059 if (!hdd_ctx->config->IpaUcTxBufCount) {
9060 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309061 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009062 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009063 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009064 hdd_ctx->config->IpaUcTxBufCount);
9065 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309066 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9067 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009068 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9069 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009070 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009071 hdd_ctx->config->IpaUcRxIndRingCount);
9072 hdd_ctx->config->IpaUcRxIndRingCount =
9073 rounddown_pow_of_two(
9074 hdd_ctx->config->IpaUcRxIndRingCount);
9075 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9076 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309077 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009078 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009079 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009080 hdd_ctx->config->IpaUcRxIndRingCount);
9081 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309082 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009083 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309084 cds_cfg->uc_tx_partition_base =
9085 hdd_ctx->config->IpaUcTxPartitionBase;
9086 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9087
9088 cds_cfg->ip_tcp_udp_checksum_offload =
9089 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009090 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309091 cds_cfg->ce_classify_enabled =
9092 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07009093 cds_cfg->bpf_packet_filter_enable =
9094 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309095 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9096 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9097 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009098 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009099 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009100 cds_cfg->max_msdus_per_rxinorderind =
9101 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009102 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009103 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05309104 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
9105 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309106 cds_cfg->auto_power_save_fail_mode =
9107 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309108
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309109 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009110 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009111 cds_cfg->delay_before_vdev_stop =
9112 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309113
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309114 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9115 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9116 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009117 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309118 cds_init_ini_config(cds_cfg);
9119 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309120
9121exit:
9122 qdf_mem_free(cds_cfg);
9123 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309124}
9125
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009126/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009127 * hdd_update_user_config() - API to update user configuration
9128 * parameters to obj mgr which are used by multiple components
9129 * @hdd_ctx: HDD Context
9130 *
9131 * Return: 0 for Success, errno on failure
9132 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009133static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009134{
9135 struct wlan_objmgr_psoc_user_config *user_config;
9136
9137 user_config = qdf_mem_malloc(sizeof(*user_config));
9138 if (user_config == NULL) {
9139 hdd_alert("Failed to alloc memory for user_config!");
9140 return -ENOMEM;
9141 }
9142
9143 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9144 user_config->dual_mac_feature_disable =
9145 hdd_ctx->config->dual_mac_feature_disable;
9146 user_config->indoor_channel_support =
9147 hdd_ctx->config->indoor_channel_support;
9148 user_config->is_11d_support_enabled =
9149 hdd_ctx->config->Is11dSupportEnabled;
9150 user_config->is_11h_support_enabled =
9151 hdd_ctx->config->Is11hSupportEnabled;
9152 user_config->optimize_chan_avoid_event =
9153 hdd_ctx->config->goptimize_chan_avoid_event;
9154 user_config->skip_dfs_chnl_in_p2p_search =
9155 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009156 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009157 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9158
9159 qdf_mem_free(user_config);
9160 return 0;
9161}
9162
9163/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009164 * hdd_init_thermal_info - Initialize thermal level
9165 * @hdd_ctx: HDD context
9166 *
9167 * Initialize thermal level at SME layer and set the thermal level callback
9168 * which would be called when a configured thermal threshold is hit.
9169 *
9170 * Return: 0 on success and errno on failure
9171 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009172static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009173{
9174 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309175 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009176
9177 thermal_param.smeThermalMgmtEnabled =
9178 hdd_ctx->config->thermalMitigationEnable;
9179 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9180
Poddar, Siddarth83905022016-04-16 17:56:08 -07009181 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9182 hdd_ctx->config->throttle_dutycycle_level0;
9183 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9184 hdd_ctx->config->throttle_dutycycle_level1;
9185 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9186 hdd_ctx->config->throttle_dutycycle_level2;
9187 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9188 hdd_ctx->config->throttle_dutycycle_level3;
9189
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009190 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9191 hdd_ctx->config->thermalTempMinLevel0;
9192 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9193 hdd_ctx->config->thermalTempMaxLevel0;
9194 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9195 hdd_ctx->config->thermalTempMinLevel1;
9196 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9197 hdd_ctx->config->thermalTempMaxLevel1;
9198 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9199 hdd_ctx->config->thermalTempMinLevel2;
9200 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9201 hdd_ctx->config->thermalTempMaxLevel2;
9202 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9203 hdd_ctx->config->thermalTempMinLevel3;
9204 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9205 hdd_ctx->config->thermalTempMaxLevel3;
9206
9207 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9208
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309209 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309210 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009211
9212 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9213 hdd_set_thermal_level_cb);
9214
9215 return 0;
9216
9217}
9218
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009219#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9220/**
9221 * hdd_hold_rtnl_lock - Hold RTNL lock
9222 *
9223 * Hold RTNL lock
9224 *
9225 * Return: True if held and false otherwise
9226 */
9227static inline bool hdd_hold_rtnl_lock(void)
9228{
9229 rtnl_lock();
9230 return true;
9231}
9232
9233/**
9234 * hdd_release_rtnl_lock - Release RTNL lock
9235 *
9236 * Release RTNL lock
9237 *
9238 * Return: None
9239 */
9240static inline void hdd_release_rtnl_lock(void)
9241{
9242 rtnl_unlock();
9243}
9244#else
9245static inline bool hdd_hold_rtnl_lock(void) { return false; }
9246static inline void hdd_release_rtnl_lock(void) { }
9247#endif
9248
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009249#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009250
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309251/* MAX iwpriv command support */
9252#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309253#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309254#define MAX_PKTLOG_SIZE 16
9255
9256/**
9257 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9258 * @hdd_ctx: hdd context
9259 * @set_value2: pktlog buffer size value
9260 *
9261 *
9262 * Return: 0 for success or error.
9263 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009264static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309265{
9266 struct sir_wifi_start_log start_log = { 0 };
9267 QDF_STATUS status;
9268
9269 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9270 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9271 start_log.ini_triggered = cds_is_packet_log_enabled();
9272 start_log.user_triggered = 1;
9273 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309274 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309275
9276 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9277 if (!QDF_IS_STATUS_SUCCESS(status)) {
9278 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009279 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309280 return -EINVAL;
9281 }
9282
9283 return 0;
9284}
9285
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009286/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309287 * hdd_pktlog_clear_buff() - clear pktlog buffer
9288 * @hdd_ctx: hdd context
9289 *
9290 * Return: 0 for success or error.
9291 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009292static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309293{
9294 struct sir_wifi_start_log start_log;
9295 QDF_STATUS status;
9296
9297 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9298 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9299 start_log.ini_triggered = cds_is_packet_log_enabled();
9300 start_log.user_triggered = 1;
9301 start_log.size = 0;
9302 start_log.is_pktlog_buff_clear = true;
9303
9304 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9305 if (!QDF_IS_STATUS_SUCCESS(status)) {
9306 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009307 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309308 return -EINVAL;
9309 }
9310
9311 return 0;
9312}
9313
9314
9315/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009316 * hdd_process_pktlog_command() - process pktlog command
9317 * @hdd_ctx: hdd context
9318 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309319 * @set_value2: pktlog buffer size value
9320 *
9321 * This function process pktlog command.
9322 * set_value2 only matters when set_value is 3 (set buff size)
9323 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009324 *
9325 * Return: 0 for success or error.
9326 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009327int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309328 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009329{
9330 int ret;
9331 bool enable;
9332 uint8_t user_triggered = 0;
9333
9334 ret = wlan_hdd_validate_context(hdd_ctx);
9335 if (0 != ret)
9336 return ret;
9337
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009338 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009339
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309340 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009341 hdd_err("invalid pktlog value %d", set_value);
9342 return -EINVAL;
9343 }
9344
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309345 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9346 if (set_value2 <= 0) {
9347 hdd_err("invalid pktlog size %d", set_value2);
9348 return -EINVAL;
9349 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9350 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9351 return -EINVAL;
9352 }
9353 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309354 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9355 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309356 }
9357
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009358 /*
9359 * set_value = 0 then disable packetlog
9360 * set_value = 1 enable packetlog forcefully
9361 * set_vlaue = 2 then disable packetlog if disabled through ini or
9362 * enable packetlog with AUTO type.
9363 */
9364 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9365 true : false;
9366
9367 if (1 == set_value) {
9368 enable = true;
9369 user_triggered = 1;
9370 }
9371
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309372 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009373}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009374
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009375/**
9376 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9377 * @hdd_ctx: HDD context
9378 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309379 * @user_triggered: triggered through iwpriv
9380 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009381 *
9382 * Return: 0 on success; error number otherwise
9383 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009384int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309385 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009386{
9387 struct sir_wifi_start_log start_log;
9388 QDF_STATUS status;
9389
9390 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9391 start_log.verbose_level =
9392 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009393 start_log.ini_triggered = cds_is_packet_log_enabled();
9394 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309395 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309396 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309397 /*
9398 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9399 * commands. Host uses this flag to decide whether to send pktlog
9400 * disable command to fw without sending pktlog enable command
9401 * previously. For eg, If vendor sends pktlog disable command without
9402 * sending pktlog enable command, then host discards the packet
9403 * but for iwpriv command, host will send it to fw.
9404 */
9405 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009406 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9407 if (!QDF_IS_STATUS_SUCCESS(status)) {
9408 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009409 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009410 return -EINVAL;
9411 }
9412
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309413 if (enable == true)
9414 hdd_ctx->is_pktlog_enabled = 1;
9415 else
9416 hdd_ctx->is_pktlog_enabled = 0;
9417
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009418 return 0;
9419}
9420#endif /* REMOVE_PKT_LOG */
9421
Komal Seelam92fff912016-03-24 11:51:41 +05309422/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009423 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9424 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309425 * @dev: Device Pointer
9426 * @num: Number of Valid Mac address
9427 *
9428 * Return: Pointer to MAC address buffer
9429 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009430static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9431 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309432{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009433 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309434}
Komal Seelam92fff912016-03-24 11:51:41 +05309435
9436/**
9437 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9438 * @hdd_ctx: HDD Context
9439 * @num: Number of random mac addresses needed
9440 *
9441 * Generate random addresses using bit manipulation on the base mac address
9442 *
9443 * Return: None
9444 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009445void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309446{
9447 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9448 uint32_t iter;
9449 struct hdd_config *ini = hdd_ctx->config;
9450 uint8_t *buf = NULL;
9451 uint8_t macaddr_b3, tmp_br3;
9452 uint8_t *src = ini->intfMacAddr[0].bytes;
9453
9454 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9455 buf = ini->intfMacAddr[iter].bytes;
9456 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9457 macaddr_b3 = buf[3];
9458 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9459 INTF_MACADDR_MASK;
9460 macaddr_b3 += tmp_br3;
9461 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9462 buf[0] |= 0x02;
9463 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009464 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309465 }
9466}
9467
9468/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009469 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309470 * @hdd_ctx: HDD Context
9471 *
9472 * API to get mac addresses from platform driver and update the driver
9473 * structures and configure FW with the base mac address.
9474 * Return: int
9475 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009476static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309477{
9478 uint32_t no_of_mac_addr, iter;
9479 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9480 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9481 uint8_t *addr, *buf;
9482 struct device *dev = hdd_ctx->parent_dev;
9483 struct hdd_config *ini = hdd_ctx->config;
9484 tSirMacAddr mac_addr;
9485 QDF_STATUS status;
9486
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009487 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309488
9489 if (no_of_mac_addr == 0 || !addr) {
9490 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9491 return -EINVAL;
9492 }
9493
9494 if (no_of_mac_addr > max_mac_addr)
9495 no_of_mac_addr = max_mac_addr;
9496
9497 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9498
9499 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9500 buf = ini->intfMacAddr[iter].bytes;
9501 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009502 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309503 }
9504
9505 status = sme_set_custom_mac_addr(mac_addr);
9506
9507 if (!QDF_IS_STATUS_SUCCESS(status))
9508 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009509
Komal Seelam92fff912016-03-24 11:51:41 +05309510 if (no_of_mac_addr < max_mac_addr)
9511 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9512 no_of_mac_addr);
9513 return 0;
9514}
9515
9516/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009517 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9518 * @hdd_ctx: HDD Context
9519 *
9520 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9521 * will generate its own MAC and update it to FW.
9522 *
9523 * Return: 0 for success
9524 * Non-zero error code for failure
9525 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009526static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009527{
9528 tSirMacAddr customMacAddr;
9529 QDF_STATUS status;
9530
9531 qdf_mem_copy(&customMacAddr,
9532 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9533 sizeof(tSirMacAddr));
9534 status = sme_set_custom_mac_addr(customMacAddr);
9535 if (!QDF_IS_STATUS_SUCCESS(status))
9536 return -EAGAIN;
9537 return 0;
9538}
9539
9540/**
Komal Seelam92fff912016-03-24 11:51:41 +05309541 * hdd_initialize_mac_address() - API to get wlan mac addresses
9542 * @hdd_ctx: HDD Context
9543 *
9544 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9545 * is provisioned with mac addresses, driver uses it, else it will use
9546 * wlan_mac.bin to update HW MAC addresses.
9547 *
9548 * Return: None
9549 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009550static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309551{
9552 QDF_STATUS status;
9553 int ret;
9554
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009555 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309556 if (ret == 0)
9557 return;
9558
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009559 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9560 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309561
9562 status = hdd_update_mac_config(hdd_ctx);
9563
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009564 if (QDF_IS_STATUS_SUCCESS(status))
9565 return;
9566
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009567 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9568 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009569
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009570 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009571 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009572 if (ret != 0) {
9573 hdd_err("MAC address out-of-sync, ret:%d", ret);
9574 QDF_ASSERT(ret);
9575 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009576 }
Komal Seelam92fff912016-03-24 11:51:41 +05309577}
9578
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009579static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009580{
9581 int vdev_id = 0;
9582 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9583 int value = hdd_ctx->config->smart_chainmask_enabled;
9584 int vpdev = PDEV_CMD;
9585 int ret;
9586
Naveen Rawat247a8682017-06-05 15:00:31 -07009587 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009588 if (ret)
9589 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9590
9591 return ret;
9592}
9593
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009594static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009595{
9596 int vdev_id = 0;
9597 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9598 int value = hdd_ctx->config->alternative_chainmask_enabled;
9599 int vpdev = PDEV_CMD;
9600 int ret;
9601
Naveen Rawat247a8682017-06-05 15:00:31 -07009602 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009603 if (ret)
9604 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9605 ret);
9606
9607 return ret;
9608}
9609
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009610static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009611{
9612 int vdev_id = 0;
9613 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9614 int value = hdd_ctx->config->ani_enabled;
9615 int vpdev = PDEV_CMD;
9616 int ret;
9617
Naveen Rawat247a8682017-06-05 15:00:31 -07009618 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009619 if (ret)
9620 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9621
9622 return ret;
9623}
9624
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009625/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009626 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9627 * @hdd_ctx: HDD context
9628 *
9629 * Pre configurations to be done at lower layer before calling cds enable.
9630 *
9631 * Return: 0 on success and errno on failure.
9632 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009633static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009634{
9635 int ret;
9636 QDF_STATUS status;
9637 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009638 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009639
Leo Changfdb45c32016-10-28 11:09:23 -07009640 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009641 /*
9642 * Set 802.11p config
9643 * TODO-OCB: This has been temporarily added here to ensure this
9644 * parameter is set in CSR when we init the channel list. This should
9645 * be removed once the 5.9 GHz channels are added to the regulatory
9646 * domain.
9647 */
9648 hdd_set_dot11p_config(hdd_ctx);
9649
9650 /*
9651 * Note that the cds_pre_enable() sequence triggers the cfg download.
9652 * The cfg download must occur before we update the SME config
9653 * since the SME config operation must access the cfg database
9654 */
9655 status = hdd_set_sme_config(hdd_ctx);
9656
9657 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009658 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009659 ret = qdf_status_to_os_return(status);
9660 goto out;
9661 }
9662
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009663 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9664 if (QDF_STATUS_SUCCESS != status) {
9665 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9666 ret = qdf_status_to_os_return(status);
9667 goto out;
9668 }
9669
Naveen Rawat247a8682017-06-05 15:00:31 -07009670 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009671 hdd_ctx->config->tx_chain_mask_1ss,
9672 PDEV_CMD);
9673 if (0 != ret) {
9674 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9675 goto out;
9676 }
9677
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009678 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9679 if (ret)
9680 goto out;
9681
9682 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9683 if (ret)
9684 goto out;
9685
Jeff Johnson12a744b2017-04-04 08:19:37 -07009686 ret = hdd_set_ani_enabled(hdd_ctx);
9687 if (ret)
9688 goto out;
9689
Naveen Rawat247a8682017-06-05 15:00:31 -07009690 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009691 hdd_ctx->config->arp_ac_category,
9692 PDEV_CMD);
9693 if (0 != ret) {
9694 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9695 hdd_ctx->config->arp_ac_category, ret);
9696 goto out;
9697 }
9698
Prashanth Bhatta07998752016-04-28 12:35:33 -07009699 status = hdd_set_sme_chan_list(hdd_ctx);
9700 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009701 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009702 ret = qdf_status_to_os_return(status);
9703 goto out;
9704 }
9705
9706 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009707 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009708 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009709 ret = -EINVAL;
9710 goto out;
9711 }
9712
Prashanth Bhatta07998752016-04-28 12:35:33 -07009713 /*
9714 * Set the MAC Address Currently this is used by HAL to add self sta.
9715 * Remove this once self sta is added as part of session open.
9716 */
9717 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9718 hdd_ctx->config->intfMacAddr[0].bytes,
9719 sizeof(hdd_ctx->config->intfMacAddr[0]));
9720
9721 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9722 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9723 hal_status, hal_status);
9724 ret = -EINVAL;
9725 goto out;
9726 }
9727
9728 hdd_init_channel_avoidance(hdd_ctx);
9729
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309730 /* update enable sap mandatory chan list */
9731 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9732 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009733out:
9734 return ret;
9735}
9736
9737/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009738 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9739 * @context_ptr - hdd context pointer
9740 * @event_ptr - event structure pointer
9741 *
9742 * This is the p2p listen offload stop event handler, it sends vendor
9743 * event back to supplicant to notify the stop reason.
9744 *
9745 * Return: None
9746 */
9747static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9748 void *event_ptr)
9749{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009750 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009751 struct sir_p2p_lo_event *evt = event_ptr;
9752 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009753 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009754
Dustin Brown491d54b2018-03-14 12:39:11 -07009755 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009756
9757 if (hdd_ctx == NULL) {
9758 hdd_err("Invalid HDD context pointer");
9759 return;
9760 }
9761
Peng Xu5c682812017-08-06 07:39:13 -07009762 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9763 if (!adapter) {
9764 hdd_err("Cannot find adapter by vdev_id = %d",
9765 evt->vdev_id);
9766 return;
9767 }
9768
Peng Xu8fdaa492016-06-22 10:20:47 -07009769 vendor_event =
9770 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009771 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009772 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9773 GFP_KERNEL);
9774
9775 if (!vendor_event) {
9776 hdd_err("cfg80211_vendor_event_alloc failed");
9777 return;
9778 }
9779
9780 if (nla_put_u32(vendor_event,
9781 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9782 evt->reason_code)) {
9783 hdd_err("nla put failed");
9784 kfree_skb(vendor_event);
9785 return;
9786 }
9787
9788 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009789 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9790 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009791}
9792
9793/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309794 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9795 * @hdd_ctx: HDD context
9796 *
9797 * This function sends the adaptive dwell time config configuration to the
9798 * firmware via WMA
9799 *
9800 * Return: 0 - success, < 0 - failure
9801 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009802static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309803{
9804 QDF_STATUS status;
9805 struct adaptive_dwelltime_params dwelltime_params;
9806
9807 dwelltime_params.is_enabled =
9808 hdd_ctx->config->adaptive_dwell_mode_enabled;
9809 dwelltime_params.dwelltime_mode =
9810 hdd_ctx->config->global_adapt_dwelltime_mode;
9811 dwelltime_params.lpf_weight =
9812 hdd_ctx->config->adapt_dwell_lpf_weight;
9813 dwelltime_params.passive_mon_intval =
9814 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9815 dwelltime_params.wifi_act_threshold =
9816 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9817
9818 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9819 &dwelltime_params);
9820
9821 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9822 if (!QDF_IS_STATUS_SUCCESS(status)) {
9823 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9824 return -EAGAIN;
9825 }
9826 return 0;
9827}
9828
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009829int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309830{
9831 QDF_STATUS status;
9832 struct wmi_dbs_scan_sel_params dbs_scan_params;
9833 uint32_t i = 0;
9834 uint8_t count = 0, numentries = 0;
9835 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9836 * CDS_DBS_SCAN_CLIENTS_MAX];
9837
9838 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +05309839 if ((hdd_ctx->config->dual_mac_feature_disable ==
9840 DISABLE_DBS_CXN_AND_SCAN) ||
9841 (hdd_ctx->config->dual_mac_feature_disable ==
9842 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309843 return -EINVAL;
9844
9845 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9846 dbs_scan_config, &numentries,
9847 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9848 * CDS_DBS_SCAN_CLIENTS_MAX));
9849
9850 hdd_info("numentries %hu", numentries);
9851 if (!numentries) {
9852 hdd_info("Donot send scan_selection_config");
9853 return 0;
9854 }
9855
9856 /* hdd_set_fw_log_params */
9857 dbs_scan_params.num_clients = 0;
9858 while (count < (numentries - 2)) {
9859 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9860 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9861 dbs_scan_params.num_non_dbs_scans[i] =
9862 dbs_scan_config[count + 2];
9863 dbs_scan_params.num_clients++;
9864 hdd_debug("module:%d NDS:%d NNDS:%d",
9865 dbs_scan_params.module_id[i],
9866 dbs_scan_params.num_dbs_scans[i],
9867 dbs_scan_params.num_non_dbs_scans[i]);
9868 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9869 i++;
9870 }
9871
9872 dbs_scan_params.pdev_id = 0;
9873
9874 hdd_debug("clients:%d pdev:%d",
9875 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9876
9877 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9878 &dbs_scan_params);
9879 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9880 if (!QDF_IS_STATUS_SUCCESS(status)) {
9881 hdd_err("Failed to send DBS Scan selection configuration!");
9882 return -EAGAIN;
9883 }
9884 return 0;
9885}
9886
Arun Khandavallid4349a92016-07-25 11:10:43 +05309887#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9888/**
9889 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9890 * @hdd_ctx: HDD context
9891 *
9892 * Set auto shutdown callback to get indications from firmware to indicate
9893 * userspace to shutdown WLAN after a configured amount of inactivity.
9894 *
9895 * Return: 0 on success and errno on failure.
9896 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009897static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309898{
9899 QDF_STATUS status;
9900
9901 if (!hdd_ctx->config->WlanAutoShutdown)
9902 return 0;
9903
9904 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9905 wlan_hdd_auto_shutdown_cb);
9906 if (status != QDF_STATUS_SUCCESS)
9907 hdd_err("Auto shutdown feature could not be enabled: %d",
9908 status);
9909
9910 return qdf_status_to_os_return(status);
9911}
9912#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009913static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309914{
9915 return 0;
9916}
9917#endif
9918
9919/**
9920 * hdd_features_init() - Init features
9921 * @hdd_ctx: HDD context
9922 * @adapter: Primary adapter context
9923 *
9924 * Initialize features and their feature context after WLAN firmware is up.
9925 *
9926 * Return: 0 on success and errno on failure.
9927 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009928static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309929{
9930 tSirTxPowerLimit hddtxlimit;
9931 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309932 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309933 int ret;
9934
Dustin Brown491d54b2018-03-14 12:39:11 -07009935 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309936
Arun Khandavallid4349a92016-07-25 11:10:43 +05309937 /* FW capabilities received, Set the Dot11 mode */
9938 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009939 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9940 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309941
Arun Khandavallid4349a92016-07-25 11:10:43 +05309942
9943 if (hdd_ctx->config->fIsImpsEnabled)
9944 hdd_set_idle_ps_config(hdd_ctx, true);
9945 else
9946 hdd_set_idle_ps_config(hdd_ctx, false);
9947
Poddar, Siddarth37033032017-10-11 15:47:40 +05309948 /* Send Enable/Disable data stall detection cmd to FW */
9949 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9950 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9951
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309952 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009953 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309954
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309955 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9956 hdd_warn("Error in setting Voltage Corner mode config to FW");
9957
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07009958 if (hdd_rx_ol_init(hdd_ctx))
9959 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +05309960
9961 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9962 hdd_err("Unable to send adaptive dwelltime setting to FW");
9963
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309964 if (hdd_dbs_scan_selection_init(hdd_ctx))
9965 hdd_err("Unable to send DBS scan selection setting to FW");
9966
Arun Khandavallid4349a92016-07-25 11:10:43 +05309967 ret = hdd_init_thermal_info(hdd_ctx);
9968 if (ret) {
9969 hdd_err("Error while initializing thermal information");
9970 goto deregister_frames;
9971 }
9972
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309973 /**
9974 * In case of SSR/PDR, if pktlog was enabled manually before
9975 * SSR/PDR, Then enabled it again automatically after Wlan
9976 * device up.
9977 */
9978 if (cds_is_driver_recovering()) {
9979 if (hdd_ctx->is_pktlog_enabled)
9980 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +08009981 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309982
Arun Khandavallid4349a92016-07-25 11:10:43 +05309983 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9984 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9985 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9986 if (!QDF_IS_STATUS_SUCCESS(status))
9987 hdd_err("Error setting txlimit in sme: %d", status);
9988
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009989 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309990
Arun Khandavallid4349a92016-07-25 11:10:43 +05309991 ret = hdd_register_cb(hdd_ctx);
9992 if (ret) {
9993 hdd_err("Failed to register HDD callbacks!");
9994 goto deregister_frames;
9995 }
9996
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309997 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9998 status = sme_enable_disable_chanavoidind_event(
9999 hdd_ctx->hHal, 0);
10000 if (!QDF_IS_STATUS_SUCCESS(status)) {
10001 hdd_err("Failed to disable Chan Avoidance Indication");
10002 goto deregister_cb;
10003 }
10004 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010005
Manjeet Singha9cae432017-02-28 11:58:22 +053010006 if (hdd_ctx->config->enable_5g_band_pref) {
10007 band_pref_params.rssi_boost_threshold_5g =
10008 hdd_ctx->config->rssi_boost_threshold_5g;
10009 band_pref_params.rssi_boost_factor_5g =
10010 hdd_ctx->config->rssi_boost_factor_5g;
10011 band_pref_params.max_rssi_boost_5g =
10012 hdd_ctx->config->max_rssi_boost_5g;
10013 band_pref_params.rssi_penalize_threshold_5g =
10014 hdd_ctx->config->rssi_penalize_threshold_5g;
10015 band_pref_params.rssi_penalize_factor_5g =
10016 hdd_ctx->config->rssi_penalize_factor_5g;
10017 band_pref_params.max_rssi_penalize_5g =
10018 hdd_ctx->config->max_rssi_penalize_5g;
10019 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
10020 }
10021
Arun Khandavallid4349a92016-07-25 11:10:43 +053010022 /* register P2P Listen Offload event callback */
10023 if (wma_is_p2p_lo_capable())
10024 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
10025 wlan_hdd_p2p_lo_event_callback);
10026
10027 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10028
10029 if (ret)
10030 goto deregister_cb;
10031
Dustin Brown11638b72018-01-25 17:37:25 +053010032 wlan_hdd_init_chan_info(hdd_ctx);
10033
Dustin Browne74003f2018-03-14 12:51:58 -070010034 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010035 return 0;
10036
10037deregister_cb:
10038 hdd_deregister_cb(hdd_ctx);
10039deregister_frames:
10040 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010041 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010042}
10043
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010044/**
10045 * hdd_features_deinit() - Deinit features
10046 * @hdd_ctx: HDD context
10047 *
10048 * De-Initialize features and their feature context.
10049 *
10050 * Return: none.
10051 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010052static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010053{
Dustin Brown11638b72018-01-25 17:37:25 +053010054 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010055 wlan_hdd_tsf_deinit(hdd_ctx);
10056}
10057
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010058/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010059 * hdd_register_bcn_cb() - register scan beacon callback
10060 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010061 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010062 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010063 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010064static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010065{
10066 QDF_STATUS status;
10067
10068 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10069 wlan_cfg80211_inform_bss_frame,
10070 SCAN_CB_TYPE_INFORM_BCN);
10071 if (!QDF_IS_STATUS_SUCCESS(status)) {
10072 hdd_err("failed with status code %08d [x%08x]",
10073 status, status);
10074 return status;
10075 }
10076
10077 return QDF_STATUS_SUCCESS;
10078}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010079
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010080/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010081 * hdd_configure_cds() - Configure cds modules
10082 * @hdd_ctx: HDD context
10083 * @adapter: Primary adapter context
10084 *
10085 * Enable Cds modules after WLAN firmware is up.
10086 *
10087 * Return: 0 on success and errno on failure.
10088 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010089int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +053010090{
10091 int ret;
10092 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010093 int set_value;
10094 uint32_t num_abg_tx_chains = 0;
10095 uint32_t num_11b_tx_chains = 0;
10096 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010097 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010098
10099 if (hdd_ctx->config->sifs_burst_duration) {
10100 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
10101 hdd_ctx->config->sifs_burst_duration;
10102
10103 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
10104 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
10105 set_value, PDEV_CMD);
10106 }
10107
10108 if (hdd_ctx->config->is_force_1x1)
10109 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10110 1, PDEV_CMD);
10111 /* set chip power save failure detected callback */
10112 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
10113 hdd_chip_pwr_save_fail_detected_cb);
10114
10115 if (hdd_ctx->config->max_mpdus_inampdu) {
10116 set_value = hdd_ctx->config->max_mpdus_inampdu;
10117 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10118 set_value, PDEV_CMD);
10119 }
10120
10121 if (hdd_ctx->config->enable_rts_sifsbursting) {
10122 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10123 sme_cli_set_command(0,
10124 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10125 set_value, PDEV_CMD);
10126 }
10127
10128 if (hdd_ctx->config->sap_get_peer_info) {
10129 set_value = hdd_ctx->config->sap_get_peer_info;
10130 sme_cli_set_command(0,
10131 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10132 set_value, PDEV_CMD);
10133 }
10134
10135 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10136 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10137 if (!hdd_ctx->config->enable2x2) {
10138 if (num_11b_tx_chains > 1)
10139 num_11b_tx_chains = 1;
10140 if (num_11ag_tx_chains > 1)
10141 num_11ag_tx_chains = 1;
10142 }
10143 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10144 num_11b_tx_chains);
10145 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10146 num_11ag_tx_chains);
10147 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10148 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010149
10150 ret = hdd_pre_enable_configure(hdd_ctx);
10151 if (ret) {
10152 hdd_err("Failed to pre-configure cds");
10153 goto out;
10154 }
10155
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010156 /* Always get latest IPA resources allocated from cds_open and configure
10157 * IPA module before configuring them to FW. Sequence required as crash
10158 * observed otherwise.
10159 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010160 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10161 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010162 hdd_err("Failed to setup pipes");
10163 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010164 }
10165
Arun Khandavallifae92942016-08-01 13:31:08 +053010166 /*
10167 * Start CDS which starts up the SME/MAC/HAL modules and everything
10168 * else
10169 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010170 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010171
10172 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010173 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010174 goto out;
10175 }
10176
10177 status = hdd_post_cds_enable_config(hdd_ctx);
10178 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010179 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010180 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010181 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010182 status = hdd_register_bcn_cb(hdd_ctx);
10183 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010184 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010185 goto cds_disable;
10186 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010187
10188 ret = hdd_features_init(hdd_ctx, adapter);
10189 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010190 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010191
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010192 if (hdd_ctx->ol_enable)
10193 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10194 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010195 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010196 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010197 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10198 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010199 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010200 goto cds_disable;
10201 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010202 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10203 wlan_hdd_send_mode_change_event);
10204 if (!QDF_IS_STATUS_SUCCESS(status)) {
10205 hdd_debug("Failed to register mode change cb with Policy Manager");
10206 goto cds_disable;
10207 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010208
Jeff Johnson8bb61112018-03-31 13:33:54 -070010209 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010210 hdd_debug("enhance green ap is not enabled");
10211
Nachiket Kukadedd302662017-07-13 17:31:44 +053010212 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10213 hdd_debug("Failed to set wow pulse");
10214
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010215 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10216 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010217 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10218 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10219
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010220
10221 if (hdd_ctx->config->enable_phy_reg_retention)
10222 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10223 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10224
Arun Khandavallifae92942016-08-01 13:31:08 +053010225 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010226
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010227cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010228 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010229
Arun Khandavallifae92942016-08-01 13:31:08 +053010230out:
10231 return -EINVAL;
10232}
10233
10234/**
10235 * hdd_deconfigure_cds() -De-Configure cds
10236 * @hdd_ctx: HDD context
10237 *
10238 * Deconfigure Cds modules before WLAN firmware is down.
10239 *
10240 * Return: 0 on success and errno on failure.
10241 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010242static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010243{
10244 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010245 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010246
Dustin Brown491d54b2018-03-14 12:39:11 -070010247 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010248
10249 /* De-init features */
10250 hdd_features_deinit(hdd_ctx);
10251
Arun Khandavallifae92942016-08-01 13:31:08 +053010252 /* De-register the SME callbacks */
10253 hdd_deregister_cb(hdd_ctx);
10254
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010255 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10256 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10257 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10258 }
10259
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010260 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010261 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10262 hdd_err("Failed to Disable the CDS Modules! :%d",
10263 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010264 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010265 }
10266
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010267 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010268 hdd_err("Failed to disconnect pipes");
10269 ret = -EINVAL;
10270 }
10271
Dustin Browne74003f2018-03-14 12:51:58 -070010272 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010273 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010274}
10275
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010276#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10277static void hdd_deregister_policy_manager_callback(
10278 struct wlan_objmgr_psoc *psoc)
10279{
10280 if (QDF_STATUS_SUCCESS !=
10281 policy_mgr_deregister_hdd_cb(psoc)) {
10282 hdd_err("HDD callback deregister with policy manager failed");
10283 }
10284}
10285#else
10286static void hdd_deregister_policy_manager_callback(
10287 struct wlan_objmgr_psoc *psoc)
10288{
10289}
10290#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010291
10292/**
10293 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10294 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010295 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010296 *
10297 * This function maintains the driver state machine it will be invoked from
10298 * exit, shutdown and con_mode change handler. Depending on the driver state
10299 * shall perform the stopping/closing of the modules.
10300 *
10301 * Return: 0 for success; non-zero for failure
10302 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010303int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010304{
10305 void *hif_ctx;
10306 qdf_device_t qdf_ctx;
10307 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010308 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010309 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010310 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10311 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010312 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010313 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010314
Dustin Brown491d54b2018-03-14 12:39:11 -070010315 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010316 hdd_alert("stop WLAN module: entering driver status=%d",
10317 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010318
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010319 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10320
Arun Khandavallifae92942016-08-01 13:31:08 +053010321 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10322 if (!qdf_ctx) {
10323 hdd_err("QDF device context NULL");
10324 return -EINVAL;
10325 }
10326
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010327 mutex_lock(&hdd_ctx->iface_change_lock);
10328 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010329 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010330
Dustin Brown70111822017-03-30 15:31:40 -070010331 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010332 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010333 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010334 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010335
10336 cds_print_external_threads();
10337
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010338 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010339 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010340 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10341 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010342 hdd_prevent_suspend_timeout(
10343 hdd_ctx->config->iface_change_wait_time,
10344 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010345 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010346 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010347 return 0;
10348 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010349 }
10350
Arun Khandavallifae92942016-08-01 13:31:08 +053010351 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10352
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010353 /* free user wowl patterns */
10354 hdd_free_user_wowl_ptrns();
10355
Arun Khandavallifae92942016-08-01 13:31:08 +053010356 switch (hdd_ctx->driver_status) {
10357 case DRIVER_MODULES_UNINITIALIZED:
10358 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010359 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010360 case DRIVER_MODULES_CLOSED:
10361 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010362 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010363 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010364 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10365
Komal Seelamf2136bb2016-09-28 18:30:44 +053010366 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010367 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010368 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010369 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010370 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010371 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010372 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010373
Arun Khandavallifae92942016-08-01 13:31:08 +053010374 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010375 hdd_info("Wlan transitioned (now OPENED)");
10376
10377 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010378 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010379 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010380 break;
10381 default:
10382 hdd_err("Trying to stop wlan in a wrong state: %d",
10383 hdd_ctx->driver_status);
10384 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010385 ret = -EINVAL;
10386 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010387 }
10388
Amar Singhal18081642018-01-26 16:04:13 -080010389 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010390 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010391
Rajeev Kumarbe021242017-02-16 16:12:23 -080010392 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010393 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10394 hdd_err("Failed to process post CDS disable Modules! :%d",
10395 qdf_status);
10396 ret = -EINVAL;
10397 QDF_ASSERT(0);
10398 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010399
psimhadeea0a12017-12-18 14:50:02 -080010400 hdd_runtime_suspend_context_deinit(hdd_ctx);
10401
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010402 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10403 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10404 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10405 ret = -EINVAL;
10406 QDF_ASSERT(0);
10407 }
10408
Jeff Johnsone4b14592017-09-13 14:23:33 -070010409 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010410 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010411 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010412 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010413 QDF_ASSERT(0);
10414 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010415
Amar Singhal410675c2018-01-10 12:14:21 -080010416 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010417 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10418 if (ret) {
10419 hdd_err("Failed to destroy pdev; errno:%d", ret);
10420 QDF_ASSERT(0);
10421 }
10422
10423 /*
10424 * Reset total mac phy during module stop such that during
10425 * next module start same psoc is used to populate new service
10426 * ready data
10427 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010428 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10429 if (tgt_hdl)
10430 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10431
Liangwei Dong50a64a72018-01-11 01:17:00 -050010432
Arun Khandavallifae92942016-08-01 13:31:08 +053010433 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10434 if (!hif_ctx) {
10435 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010436 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010437 }
10438
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010439 if (hdd_ctx->target_hw_name) {
10440 qdf_mem_free(hdd_ctx->target_hw_name);
10441 hdd_ctx->target_hw_name = NULL;
10442 }
10443
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010444 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010445
10446 ol_cds_free();
10447
Dustin Brown70111822017-03-30 15:31:40 -070010448 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010449 ret = pld_power_off(qdf_ctx->dev);
10450 if (ret)
10451 hdd_err("CNSS power down failed put device into Low power mode:%d",
10452 ret);
10453 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010454
Dustin Brown4bc0a622017-12-06 15:56:50 -080010455 /* many adapter resources are not freed by design in SSR case */
10456 if (!is_recovery_stop)
10457 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010458 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010459
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010460 /* Once the firmware sequence is completed reset this flag */
10461 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010462 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010463 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010464
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010465done:
10466 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010467 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010468 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010469 hdd_alert("stop WLAN module: exit driver status=%d",
10470 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010471
Dustin Browne74003f2018-03-14 12:51:58 -070010472 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010473
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010474 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010475}
10476
Arun Khandavallifae92942016-08-01 13:31:08 +053010477
10478/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010479 * hdd_state_info_dump() - prints state information of hdd layer
10480 * @buf: buffer pointer
10481 * @size: size of buffer to be filled
10482 *
10483 * This function is used to dump state information of hdd layer
10484 *
10485 * Return: None
10486 */
10487static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10488{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010489 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010490 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010491 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010492 uint16_t len = 0;
10493 char *buf = *buf_ptr;
10494
10495 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10496 if (!hdd_ctx) {
10497 hdd_err("Failed to get hdd context ");
10498 return;
10499 }
10500
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010501 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010502
10503 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010504 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010505 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010506 "\n is_scheduler_suspended %d",
10507 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010508
Dustin Brown920397d2017-12-13 16:27:50 -080010509 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010510 if (adapter->dev)
10511 len += scnprintf(buf + len, *size - len,
10512 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010513 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010514 "\n device_mode: %d", adapter->device_mode);
10515 switch (adapter->device_mode) {
10516 case QDF_STA_MODE:
10517 case QDF_P2P_CLIENT_MODE:
10518 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10519 len += scnprintf(buf + len, *size - len,
10520 "\n connState: %d",
10521 hdd_sta_ctx->conn_info.connState);
10522 break;
10523
10524 default:
10525 break;
10526 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010527 }
10528
10529 *size -= len;
10530 *buf_ptr += len;
10531}
10532
10533/**
10534 * hdd_register_debug_callback() - registration function for hdd layer
10535 * to print hdd state information
10536 *
10537 * Return: None
10538 */
10539static void hdd_register_debug_callback(void)
10540{
10541 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10542}
10543
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010544/*
10545 * wlan_init_bug_report_lock() - Initialize bug report lock
10546 *
10547 * This function is used to create bug report lock
10548 *
10549 * Return: None
10550 */
10551static void wlan_init_bug_report_lock(void)
10552{
10553 p_cds_contextType p_cds_context;
10554
10555 p_cds_context = cds_get_global_context();
10556 if (!p_cds_context) {
10557 hdd_err("cds context is NULL");
10558 return;
10559 }
10560
10561 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10562}
10563
Mohit Khannaf8f96822017-05-17 17:11:59 -070010564void hdd_dp_trace_init(struct hdd_config *config)
10565{
10566
10567 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10568 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10569 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10570 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10571 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10572 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10573 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010574 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010575
10576 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10577 &num_entries, sizeof(config_params));
10578
10579 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010580 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010581 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010582 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010583 else if (bw_compute_interval > 1000) {
10584 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10585 thresh_time_limit = 1;
10586 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010587 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10588
10589 switch (num_entries) {
10590 case 4:
10591 proto_bitmap = config_params[3];
10592 case 3:
10593 verbosity = config_params[2];
10594 case 2:
10595 thresh = config_params[1];
10596 case 1:
10597 live_mode = config_params[0];
10598 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010599 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010600 live_mode, thresh, thresh_time_limit,
10601 verbosity, proto_bitmap);
10602 };
10603
10604 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10605 verbosity, proto_bitmap);
10606
10607}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010608/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010609 * hdd_wlan_startup() - HDD init function
10610 * @dev: Pointer to the underlying device
10611 *
10612 * This is the driver startup code executed once a WLAN device has been detected
10613 *
10614 * Return: 0 for success, < 0 for failure
10615 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010616int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010617{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010618 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010619 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010620 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010621 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010622
Dustin Brown491d54b2018-03-14 12:39:11 -070010623 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010624
Arun Khandavallifae92942016-08-01 13:31:08 +053010625 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010626
10627 if (IS_ERR(hdd_ctx))
10628 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010629
Abhishek Singhe9068f12017-03-31 14:14:52 +053010630 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10631 DEFAULT_PSOC_ID);
10632 if (ret) {
10633 hdd_err("Psoc creation fails!");
10634 QDF_BUG(0);
10635 goto err_hdd_free_context;
10636 }
10637
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010638 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010639#ifdef FEATURE_WLAN_CH_AVOID
10640 mutex_init(&hdd_ctx->avoid_freq_lock);
10641#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010642
Naveen Rawate02f8f52018-04-05 11:58:04 -070010643 osif_request_manager_init();
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010644 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010645 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010646
Dustin Brown021cecd2017-12-11 13:56:43 -080010647 hdd_driver_memdump_init();
10648
Jeff Johnson957bc272017-02-02 08:54:48 -080010649 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010650 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010651 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010652 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010653 }
10654
Yingying Tang80e15f32016-09-27 18:23:01 +080010655 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010656
Anurag Chouhan6d760662016-02-20 16:05:43 +053010657 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010658
10659 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010660 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010661 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010662 }
10663
Prashanth Bhatta07998752016-04-28 12:35:33 -070010664 ret = hdd_wiphy_init(hdd_ctx);
10665 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010666 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010667 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010668 }
10669
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010670 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010671 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010672
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010673 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010674
Paul Zhangfb02f452017-12-22 11:58:43 +080010675 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10676 if (ret) {
10677 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010678 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080010679 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010680
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010681 ret = register_reboot_notifier(&system_reboot_notifier);
10682 if (ret) {
10683 hdd_err("Failed to register reboot notifier: %d", ret);
10684 goto err_unregister_netdev;
10685 }
10686
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010687 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010688
Jeff Johnson957bc272017-02-02 08:54:48 -080010689 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10690 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010691 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010692 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010693 }
10694
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010695 hdd_release_rtnl_lock();
10696 rtnl_held = false;
10697
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010698 wlan_hdd_update_11n_mode(hdd_ctx->config);
10699
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010700#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010701 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010702 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010703 hdd_skip_acs_scan_timer_handler,
10704 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010705 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010706 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010707 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010708#endif
10709
Prashanth Bhattaab004382016-10-11 16:08:11 -070010710 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010711
Jeff Johnson9afc5012016-09-23 13:56:27 -070010712 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010713
Nirav Shahbd36b062016-07-18 11:12:59 +053010714 if (hdd_ctx->rps)
10715 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010716
Paul Zhangfb02f452017-12-22 11:58:43 +080010717 ret = hdd_register_notifiers(hdd_ctx);
10718 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010719 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010720
Paul Zhangfb02f452017-12-22 11:58:43 +080010721 status = wlansap_global_init();
10722 if (QDF_IS_STATUS_ERROR(status)) {
10723 hdd_unregister_notifiers(hdd_ctx);
10724 goto err_close_adapters;
10725 }
10726
Arun Khandavallifae92942016-08-01 13:31:08 +053010727 if (hdd_ctx->config->fIsImpsEnabled)
10728 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010729 else
10730 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010731
Mukul Sharma07bd8752017-10-10 16:58:14 +053010732 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010733 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10734 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010735 hdd_prevent_suspend_timeout(
10736 hdd_ctx->config->iface_change_wait_time,
10737 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10738 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010739
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740 goto success;
10741
Jeff Johnson957bc272017-02-02 08:54:48 -080010742err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010743 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010744
Jeff Johnson46bde382017-02-01 15:31:16 -080010745err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010746 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010747 if (rtnl_held)
10748 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010749
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010750err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010751 unregister_netdevice_notifier(&hdd_netdev_notifier);
10752
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010753err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010754 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010755
Arun Khandavallifae92942016-08-01 13:31:08 +053010756err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010757 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010758
Dustin Brown021cecd2017-12-11 13:56:43 -080010759err_memdump_deinit:
10760 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010761
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010762 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070010763 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010764 hdd_exit_netlink_services(hdd_ctx);
10765
Dustin Brown20912462017-06-07 13:48:25 -070010766 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10767
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010768err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010769 if (cds_is_fw_down())
10770 hdd_err("Not setting the complete event as fw is down");
10771 else
10772 hdd_start_complete(ret);
10773
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010774 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010775 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010776 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010777
10778success:
Dustin Browne74003f2018-03-14 12:51:58 -070010779 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780 return 0;
10781}
10782
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010783/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010784 * hdd_wlan_update_target_info() - update target type info
10785 * @hdd_ctx: HDD context
10786 * @context: hif context
10787 *
10788 * Update target info received from firmware in hdd context
10789 * Return:None
10790 */
10791
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010792void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010793{
10794 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10795
10796 if (!tgt_info) {
10797 hdd_err("Target info is Null");
10798 return;
10799 }
10800
10801 hdd_ctx->target_type = tgt_info->target_type;
10802}
10803
10804/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010805 * hdd_get_nud_stats_cb() - callback api to update the stats
10806 * received from the firmware
10807 * @data: pointer to adapter.
10808 * @rsp: pointer to data received from FW.
10809 *
10810 * This is called when wlan driver received response event for
10811 * get arp stats to firmware.
10812 *
10813 * Return: None
10814 */
10815static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10816{
10817 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10818 struct hdd_nud_stats_context *context;
10819 int status;
10820 struct hdd_adapter *adapter = NULL;
10821
Dustin Brown491d54b2018-03-14 12:39:11 -070010822 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010823
10824 if (!rsp) {
10825 hdd_err("data is null");
10826 return;
10827 }
10828
10829 status = wlan_hdd_validate_context(hdd_ctx);
10830 if (0 != status)
10831 return;
10832
10833 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10834 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10835 hdd_err("Invalid adapter or adapter has invalid magic");
10836 return;
10837 }
10838
Dustin Brown5e89ef82018-03-14 11:50:23 -070010839 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10840 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10841 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10842 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10843 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10844 rsp->out_of_order_arp_rsp_drop_cnt);
10845 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
10846 hdd_info("rsp->connect_status :%x", rsp->connect_status);
10847 hdd_info("rsp->ba_session_establishment_status :%x",
10848 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010849
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010850 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010851 adapter->dad |= rsp->dad_detected;
10852 adapter->con_status = rsp->connect_status;
10853
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053010854 /* Flag true indicates connectivity check stats present. */
10855 if (rsp->connect_stats_present) {
10856 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
10857 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
10858 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
10859 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
10860 rsp->icmpv4_rsp_recvd;
10861 }
10862
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010863 spin_lock(&hdd_context_lock);
10864 context = &hdd_ctx->nud_stats_context;
10865 complete(&context->response_event);
10866 spin_unlock(&hdd_context_lock);
10867
Dustin Browne74003f2018-03-14 12:51:58 -070010868 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010869}
10870
10871/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010872 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010873 * @hdd_ctx: HDD context
10874 *
10875 * Register the HDD callbacks to CDS/SME.
10876 *
10877 * Return: 0 for success or Error code for failure
10878 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010879int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010880{
10881 QDF_STATUS status;
10882 int ret = 0;
10883
Dustin Brown491d54b2018-03-14 12:39:11 -070010884 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010885
10886 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10887
10888 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10889 hdd_send_oem_data_rsp_msg);
10890
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010891 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10892 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010893 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10894 sme_nan_register_callback(hdd_ctx->hHal,
10895 wlan_hdd_cfg80211_nan_callback);
10896 sme_stats_ext_register_callback(hdd_ctx->hHal,
10897 wlan_hdd_cfg80211_stats_ext_callback);
10898
10899 sme_ext_scan_register_callback(hdd_ctx->hHal,
10900 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010901 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10902 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010903
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010904 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10905 hdd_rssi_threshold_breached);
10906
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010907 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10908
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010909 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10910 wlan_hdd_cfg80211_link_layer_stats_callback);
10911
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010912 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10913
Zhang Qianca38fb12016-12-23 11:10:48 +080010914 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10915 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10916
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010917 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10918 hdd_lost_link_info_cb);
10919 /* print error and not block the startup process */
10920 if (!QDF_IS_STATUS_SUCCESS(status))
10921 hdd_err("set lost link info callback failed");
10922
Poddar, Siddarth34872782017-08-10 14:08:51 +053010923 ret = hdd_register_data_stall_detect_cb();
10924 if (ret) {
10925 hdd_err("Register data stall detect detect callback failed.");
10926 return ret;
10927 }
10928
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010929 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10930
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010931 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010932 hdd_set_connection_in_progress,
10933 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010934
10935 status = sme_congestion_register_callback(hdd_ctx->hHal,
10936 hdd_update_cca_info_cb);
10937 if (!QDF_IS_STATUS_SUCCESS(status))
10938 hdd_err("set congestion callback failed");
10939
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010940 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10941 hdd_bt_activity_cb);
10942 if (!QDF_IS_STATUS_SUCCESS(status))
10943 hdd_err("set bt activity info callback failed");
10944
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010945 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10946 hdd_tx_queue_cb);
10947 if (!QDF_IS_STATUS_SUCCESS(status))
10948 hdd_err("Register tx queue callback failed");
10949
Dustin Browne74003f2018-03-14 12:51:58 -070010950 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010951
10952 return ret;
10953}
10954
10955/**
10956 * hdd_deregister_cb() - De-Register HDD callbacks.
10957 * @hdd_ctx: HDD context
10958 *
10959 * De-Register the HDD callbacks to CDS/SME.
10960 *
10961 * Return: void
10962 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010963void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010964{
10965 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010966 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010967
Dustin Brown491d54b2018-03-14 12:39:11 -070010968 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010969
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010970 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010971 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10972 if (!QDF_IS_STATUS_SUCCESS(status))
10973 hdd_err("De-register of dcc stats callback failed: %d",
10974 status);
10975
10976 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010977 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10978
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010979 sme_stats_ext_register_callback(hdd_ctx->hHal,
10980 wlan_hdd_cfg80211_stats_ext_callback);
10981
10982 sme_nan_deregister_callback(hdd_ctx->hHal);
10983 status = sme_reset_tsfcb(hdd_ctx->hHal);
10984 if (!QDF_IS_STATUS_SUCCESS(status))
10985 hdd_err("Failed to de-register tsfcb the callback:%d",
10986 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010987
Poddar, Siddarth34872782017-08-10 14:08:51 +053010988 ret = hdd_deregister_data_stall_detect_cb();
10989 if (ret)
10990 hdd_err("Failed to de-register data stall detect event callback");
10991
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010992 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10993 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10994
Dustin Browne74003f2018-03-14 12:51:58 -070010995 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010996}
10997
10998/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010999 * hdd_softap_sta_deauth() - handle deauth req from HDD
11000 * @adapter: Pointer to the HDD
11001 * @enable: bool value
11002 *
11003 * This to take counter measure to handle deauth req from HDD
11004 *
11005 * Return: None
11006 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011007QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011008 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011009{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011010 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011011
Dustin Brown491d54b2018-03-14 12:39:11 -070011012 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011013
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011014 /* Ignore request to deauth bcmc station */
11015 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011016 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011017
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011018 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011019 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11020 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011021
Dustin Browne74003f2018-03-14 12:51:58 -070011022 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011023 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011024}
11025
11026/**
11027 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11028 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011029 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011030 *
11031 * This to take counter measure to handle deauth req from HDD
11032 *
11033 * Return: None
11034 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011035void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011036 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011037{
Dustin Brown491d54b2018-03-14 12:39:11 -070011038 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011039
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011040 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011041 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011042 return;
11043
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011044 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011045 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011046}
11047
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011048/**
11049 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11050 * @hdd_ctx: HDD Context
11051 *
11052 * API to find if there is any STA or P2P-Client is connected
11053 *
11054 * Return: true if connected; false otherwise
11055 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011056QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011057{
11058 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
11059}
11060
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011061/**
11062 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
11063 * @adapter: HDD adapter pointer
11064 *
11065 * This function loop through each adapter and disable roaming on each STA
11066 * device mode except the input adapter.
11067 *
11068 * Note: On the input adapter roaming is not enabled yet hence no need to
11069 * disable.
11070 *
11071 * Return: None
11072 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011073void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011074{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011075 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011076 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011077
11078 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011079 hdd_ctx->config->isRoamOffloadScanEnabled &&
11080 QDF_STA_MODE == adapter->device_mode &&
11081 policy_mgr_is_sta_active_connection_exists(
11082 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011083 hdd_debug("Connect received on STA session Id(%d)",
11084 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011085 /*
11086 * Loop through adapter and disable roaming for each STA device
11087 * mode except the input adapter.
11088 */
Dustin Brown920397d2017-12-13 16:27:50 -080011089 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011090 if (QDF_STA_MODE == adapterIdx->device_mode &&
11091 adapter->session_id != adapterIdx->session_id) {
11092 hdd_debug("Disable Roaming on session Id(%d)",
11093 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011094 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
11095 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011096 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011097 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011098 }
11099 }
11100}
11101
11102/**
11103 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
11104 * @adapter: HDD adapter pointer
11105 *
11106 * This function loop through each adapter and enable roaming on each STA
11107 * device mode except the input adapter.
11108 * Note: On the input adapter no need to enable roaming because link got
11109 * disconnected on this.
11110 *
11111 * Return: None
11112 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011113void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011114{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011115 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011116 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011117
11118 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011119 hdd_ctx->config->isRoamOffloadScanEnabled &&
11120 QDF_STA_MODE == adapter->device_mode &&
11121 policy_mgr_is_sta_active_connection_exists(
11122 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011123 hdd_debug("Disconnect received on STA session Id(%d)",
11124 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011125 /*
11126 * Loop through adapter and enable roaming for each STA device
11127 * mode except the input adapter.
11128 */
Dustin Brown920397d2017-12-13 16:27:50 -080011129 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011130 if (QDF_STA_MODE == adapterIdx->device_mode &&
11131 adapter->session_id != adapterIdx->session_id) {
11132 hdd_debug("Enabling Roaming on session Id(%d)",
11133 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011134 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
11135 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011136 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011137 REASON_CONNECT);
11138 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011139 }
11140 }
11141}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011142
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011143/**
11144 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11145 * @skb: sk buffer pointer
11146 *
11147 * Sends the bcast message to SVC multicast group with generic nl socket
11148 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11149 *
11150 * Return: None
11151 */
11152static void nl_srv_bcast_svc(struct sk_buff *skb)
11153{
11154#ifdef CNSS_GENL
11155 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11156#else
11157 nl_srv_bcast(skb);
11158#endif
11159}
11160
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011161void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011162{
11163 struct sk_buff *skb;
11164 struct nlmsghdr *nlh;
11165 tAniMsgHdr *ani_hdr;
11166 void *nl_data = NULL;
11167 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011168 struct radio_index_tlv *radio_info;
11169 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011170
11171 if (in_interrupt() || irqs_disabled() || in_atomic())
11172 flags = GFP_ATOMIC;
11173
11174 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11175
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011176 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011177 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011178
11179 nlh = (struct nlmsghdr *)skb->data;
11180 nlh->nlmsg_pid = 0; /* from kernel */
11181 nlh->nlmsg_flags = 0;
11182 nlh->nlmsg_seq = 0;
11183 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11184
11185 ani_hdr = NLMSG_DATA(nlh);
11186 ani_hdr->type = type;
11187
11188 switch (type) {
11189 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011190 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011191 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011192 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011193 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011194 ani_hdr->length = 0;
11195 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011196 break;
11197 case WLAN_SVC_WLAN_STATUS_IND:
11198 case WLAN_SVC_WLAN_VERSION_IND:
11199 case WLAN_SVC_DFS_CAC_START_IND:
11200 case WLAN_SVC_DFS_CAC_END_IND:
11201 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11202 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11203 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011204 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011205 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011206 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011207 ani_hdr->length = len;
11208 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11209 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11210 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011211 break;
11212
11213 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011214 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011215 type);
11216 kfree_skb(skb);
11217 return;
11218 }
11219
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011220 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011221 * Add radio index at the end of the svc event in TLV format
11222 * to maintain the backward compatibility with userspace
11223 * applications.
11224 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011225
11226 tlv_len = 0;
11227
11228 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11229 < WLAN_NL_MAX_PAYLOAD) {
11230 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11231 sizeof(*ani_hdr) + len);
11232 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11233 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11234 radio_info->radio = radio;
11235 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011236 hdd_debug("Added radio index tlv - radio index %d",
11237 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011238 }
11239
11240 nlh->nlmsg_len += tlv_len;
11241 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11242
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011243 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011244}
11245
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011246#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11247void wlan_hdd_auto_shutdown_cb(void)
11248{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011249 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011250
11251 if (!hdd_ctx)
11252 return;
11253
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011254 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011255 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11256 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011257}
11258
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011259void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011260{
Jeff Johnson9d295242017-08-29 14:39:48 -070011261 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011262 bool ap_connected = false, sta_connected = false;
11263 tHalHandle hal_handle;
11264
11265 hal_handle = hdd_ctx->hHal;
11266 if (hal_handle == NULL)
11267 return;
11268
11269 if (hdd_ctx->config->WlanAutoShutdown == 0)
11270 return;
11271
11272 if (enable == false) {
11273 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011274 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011275 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011276 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011277 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011278 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011279 return;
11280 }
11281
11282 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011283 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11284 hdd_for_each_adapter(hdd_ctx, adapter) {
11285 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011286 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11287 conn_info.connState ==
11288 eConnectionState_Associated) {
11289 sta_connected = true;
11290 break;
11291 }
11292 }
Dustin Brown920397d2017-12-13 16:27:50 -080011293
11294 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011295 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011296 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011297 ap_connected = true;
11298 break;
11299 }
11300 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011301 }
11302 }
11303
11304 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011305 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011306 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011307 }
Jeff Johnson68755312017-02-10 11:46:55 -080011308
11309 if (sme_set_auto_shutdown_timer(hal_handle,
11310 hdd_ctx->config->WlanAutoShutdown)
11311 != QDF_STATUS_SUCCESS)
11312 hdd_err("Failed to start wlan auto shutdown timer");
11313 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011314 hdd_info("Auto Shutdown timer for %d seconds enabled",
11315 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011316}
11317#endif
11318
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011319struct hdd_adapter *
11320hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11321 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011322{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011323 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011324 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011325
11326 con_sap_adapter = NULL;
11327
Dustin Brown920397d2017-12-13 16:27:50 -080011328 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011329 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11330 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011331 adapter != this_sap_adapter) {
11332 if (check_start_bss) {
11333 if (test_bit(SOFTAP_BSS_STARTED,
11334 &adapter->event_flags)) {
11335 con_sap_adapter = adapter;
11336 break;
11337 }
11338 } else {
11339 con_sap_adapter = adapter;
11340 break;
11341 }
11342 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011343 }
11344
11345 return con_sap_adapter;
11346}
11347
11348#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011349static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011350{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011351 return adapter->device_mode == QDF_STA_MODE ||
11352 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011353}
11354
Jeff Johnson9d295242017-08-29 14:39:48 -070011355static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011356{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011357 return adapter->device_mode == QDF_SAP_MODE ||
11358 adapter->device_mode == QDF_P2P_GO_MODE;
11359}
11360
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011361static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011362{
Dustin Brown920397d2017-12-13 16:27:50 -080011363 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011364
Dustin Brown920397d2017-12-13 16:27:50 -080011365 hdd_for_each_adapter(hdd_ctx, adapter) {
11366 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011367 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11368 conn_info.connState == eConnectionState_Associated) {
11369 return true;
11370 }
11371
Dustin Brown920397d2017-12-13 16:27:50 -080011372 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011373 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011374 return true;
11375 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011376 }
11377
11378 return false;
11379}
11380
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011381static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011382{
11383 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011384
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011385 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011386 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011387 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011388
Dustin Brown5ec6b552017-03-31 12:11:40 -070011389 return is_running;
11390}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011391
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011392static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011393{
11394 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11395 hdd_ctx->bus_bw_timer_running = true;
11396 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11397 hdd_ctx->config->busBandwidthComputeInterval);
11398 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11399}
11400
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011401void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011402{
Dustin Brown491d54b2018-03-14 12:39:11 -070011403 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011404
11405 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11406 hdd_debug("Bandwidth compute timer already started");
11407 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011408 }
11409
Dustin Brown5ec6b552017-03-31 12:11:40 -070011410 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11411
Dustin Browne74003f2018-03-14 12:51:58 -070011412 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011413}
11414
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011415void hdd_bus_bw_compute_timer_try_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;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011422 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011423
11424 if (hdd_any_adapter_is_assoc(hdd_ctx))
11425 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11426
Dustin Browne74003f2018-03-14 12:51:58 -070011427 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011428}
11429
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011430static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011431{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011432 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011433
11434 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11435 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11436 hdd_ctx->bus_bw_timer_running = false;
11437 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11438
11439 hdd_reset_tcp_delack(hdd_ctx);
11440}
11441
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011442void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011443{
Dustin Brown491d54b2018-03-14 12:39:11 -070011444 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011445
11446 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11447 hdd_debug("Bandwidth compute timer already stopped");
11448 return;
11449 }
11450
11451 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11452
Dustin Browne74003f2018-03-14 12:51:58 -070011453 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011454}
11455
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011456void hdd_bus_bw_compute_timer_try_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 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11466 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11467
Dustin Browne74003f2018-03-14 12:51:58 -070011468 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011469}
11470#endif
11471
11472/**
11473 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11474 * and sta's operating channel.
11475 * @sta_adapter: Describe the first argument to foobar.
11476 * @ap_adapter: Describe the second argument to foobar.
11477 * @roam_profile: Roam profile of AP to which STA wants to connect.
11478 * @concurrent_chnl_same: If both SAP and STA channels are same then
11479 * set this flag to true else false.
11480 *
11481 * This function checks the sap's operating channel and sta's operating channel.
11482 * if both are same then it will return false else it will restart the sap in
11483 * sta's channel and return true.
11484 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011485 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011486 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011487QDF_STATUS
11488wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11489 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011490 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011491 tScanResultHandle *scan_cache,
11492 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011493{
Jeff Johnson87251032017-08-29 13:31:11 -070011494 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011495 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011496 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011497 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011498 *concurrent_chnl_same = true;
11499
11500 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11501 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011502 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011503 scan_cache,
11504 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011505 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011506 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011507 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011508 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011509 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011510 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011511 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011512 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011513 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011514 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011515 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011516 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011517 }
11518 }
11519 } else {
11520 /*
11521 * Lets handle worst case scenario here, Scan cache lookup is
11522 * failed so we have to stop the SAP to avoid any channel
11523 * discrepancy between SAP's channel and STA's channel.
11524 * Return the status as failure so caller function could know
11525 * that scan look up is failed.
11526 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011527 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011528 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011529 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011530 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011531}
11532
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011533/**
11534 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11535 * @ap_adapter: SAP adapter
11536 *
11537 * This function will process the stopping of sap adapter.
11538 *
11539 * Return: None
11540 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011541void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011542{
Jeff Johnson87251032017-08-29 13:31:11 -070011543 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011544 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011545 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011546 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011547
11548 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011549 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011550 return;
11551 }
11552
11553 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11554 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011555 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011556 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011557
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011558 mutex_lock(&hdd_ctx->sap_lock);
11559 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011560 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011561 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011562 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011563 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011564 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011565 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011566 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011567 qdf_stop_bss_event,
11568 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011569 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011570 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011571 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011572 return;
11573 }
11574 }
11575 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011576 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11577 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011578 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011579 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011580 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011581 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011582 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011583 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011584 }
11585 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011586}
11587
11588/**
11589 * wlan_hdd_start_sap() - this function starts bss of SAP.
11590 * @ap_adapter: SAP adapter
11591 *
11592 * This function will process the starting of sap adapter.
11593 *
11594 * Return: None
11595 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011596void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011597{
Jeff Johnson87251032017-08-29 13:31:11 -070011598 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011599 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011600 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011601 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011602 tsap_Config_t *sap_config;
11603
11604 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011605 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011606 return;
11607 }
11608
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011609 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011610 hdd_err("SoftAp role has not been enabled");
11611 return;
11612 }
11613
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011614 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11615 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11616 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011617 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011618
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011619 mutex_lock(&hdd_ctx->sap_lock);
11620 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11621 goto end;
11622
11623 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011624 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011625 goto end;
11626 }
11627
Wei Song2f76f642016-11-18 16:32:53 +080011628 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011629 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011630 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011631 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011632 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011633 goto end;
11634
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011635 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011636 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011637 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011638 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011639 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011640 goto end;
11641 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011642 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011643 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011644 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011645 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011646 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11647 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011648 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011649 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011650 true);
11651 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011652 mutex_unlock(&hdd_ctx->sap_lock);
11653
11654 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011655end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011656 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011657 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011658 /* SAP context and beacon cleanup will happen during driver unload
11659 * in hdd_stop_adapter
11660 */
11661 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11662
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011663}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011664
11665/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011666 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11667 * mac scan config
11668 * @status: Status of set antenna mode
11669 *
11670 * Callback on setting the dual mac configuration
11671 *
11672 * Return: None
11673 */
11674void wlan_hdd_soc_set_antenna_mode_cb(
11675 enum set_antenna_mode_status status)
11676{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011677 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011678
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011679 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011680
11681 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11682 if (0 != wlan_hdd_validate_context(hdd_ctx))
11683 return;
11684
11685 /* Signal the completion of set dual mac config */
11686 complete(&hdd_ctx->set_antenna_mode_cmpl);
11687}
11688
11689/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011690 * hdd_get_fw_version() - Get FW version
11691 * @hdd_ctx: pointer to HDD context.
11692 * @major_spid: FW version - major spid.
11693 * @minor_spid: FW version - minor spid
11694 * @ssid: FW version - ssid
11695 * @crmid: FW version - crmid
11696 *
11697 * This function is called to get the firmware build version stored
11698 * as part of the HDD context
11699 *
11700 * Return: None
11701 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011702void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011703 uint32_t *major_spid, uint32_t *minor_spid,
11704 uint32_t *siid, uint32_t *crmid)
11705{
11706 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11707 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11708 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11709 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11710}
11711
11712#ifdef QCA_CONFIG_SMP
11713/**
11714 * wlan_hdd_get_cpu() - get cpu_index
11715 *
11716 * Return: cpu_index
11717 */
11718int wlan_hdd_get_cpu(void)
11719{
11720 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011721
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011722 put_cpu();
11723 return cpu_index;
11724}
11725#endif
11726
11727/**
11728 * hdd_get_fwpath() - get framework path
11729 *
11730 * This function is used to get the string written by
11731 * userspace to start the wlan driver
11732 *
11733 * Return: string
11734 */
11735const char *hdd_get_fwpath(void)
11736{
11737 return fwpath.string;
11738}
11739
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011740static int hdd_qdf_print_init(void)
11741{
11742 int qdf_print_idx;
11743 QDF_STATUS status;
11744
11745 status = qdf_print_setup();
11746 if (status != QDF_STATUS_SUCCESS) {
11747 pr_err("qdf_print_setup failed\n");
11748 return -EINVAL;
11749 }
11750
11751 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11752
11753 if (qdf_print_idx < 0) {
11754 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11755 qdf_print_idx);
11756 return -EINVAL;
11757 }
11758
11759 qdf_set_pidx(qdf_print_idx);
11760
11761 return 0;
11762}
11763
11764static void hdd_qdf_print_deinit(void)
11765{
11766 int qdf_print_idx;
11767
11768 qdf_print_idx = qdf_get_pidx();
11769 qdf_print_ctrl_cleanup(qdf_print_idx);
11770}
11771
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011772/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011773 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011774 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011775 * This function initilizes CDS global context with the help of cds_init. This
11776 * has to be the first function called after probe to get a valid global
11777 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011778 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011779 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011780 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011781int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011782{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011783 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011784 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011785
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011786 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011787 if (QDF_IS_STATUS_ERROR(status)) {
11788 hdd_err("Failed to allocate CDS context");
11789 ret = -ENOMEM;
11790 goto err_out;
11791 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011792
11793 wlan_init_bug_report_lock();
11794
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011795#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11796 wlan_logging_sock_init_svc();
11797#endif
11798
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011799 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11800 (void *)hdd_drv_ops_inactivity_handler, NULL,
11801 QDF_TIMER_TYPE_SW);
11802
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011803 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011804 hdd_qdf_print_init();
11805
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011806 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011807
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011808err_out:
11809 return ret;
11810}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011811
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011812/**
11813 * hdd_deinit() - Deinitialize Driver
11814 *
11815 * This function frees CDS global context with the help of cds_deinit. This
11816 * has to be the last function call in remove callback to free the global
11817 * context.
11818 */
11819void hdd_deinit(void)
11820{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011821 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011822
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011823 wlan_destroy_bug_report_lock();
11824 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011825
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011826 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011827#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11828 wlan_logging_sock_deinit_svc();
11829#endif
11830}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011831
Yue Ma6e7b1a02017-04-03 14:17:46 -070011832#ifdef QCA_WIFI_NAPIER_EMULATION
11833#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11834#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011835#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011836#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011837
Sachin Ahujadddd2632017-03-07 19:07:24 +053011838static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11839 struct file *file)
11840{
11841 return 0;
11842}
11843
11844static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11845 const char __user *user_buf,
11846 size_t count,
11847 loff_t *f_pos)
11848{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011849 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011850 static const char wlan_off_str[] = "OFF";
11851 static const char wlan_on_str[] = "ON";
11852 int ret;
11853 unsigned long rc;
11854
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011855 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011856 pr_err("Failed to read buffer\n");
11857 return -EINVAL;
11858 }
11859
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011860 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011861 pr_debug("Wifi turning off from UI\n");
11862 goto exit;
11863 }
11864
Sachin Ahuja16904db2017-12-13 19:56:57 +053011865 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
11866 pr_info("Wifi Turning On from UI\n");
11867 }
11868
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011869 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011870 pr_err("Invalid value received from framework");
11871 goto exit;
11872 }
11873
11874 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011875 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011876 rc = wait_for_completion_timeout(&wlan_start_comp,
11877 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11878 if (!rc) {
11879 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11880 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053011881 return ret;
11882 }
11883
11884 hdd_start_complete(0);
11885 }
11886
11887exit:
11888 return count;
11889}
11890
11891
11892const struct file_operations wlan_hdd_state_fops = {
11893 .owner = THIS_MODULE,
11894 .open = wlan_hdd_state_ctrl_param_open,
11895 .write = wlan_hdd_state_ctrl_param_write,
11896};
11897
11898static int wlan_hdd_state_ctrl_param_create(void)
11899{
11900 unsigned int wlan_hdd_state_major = 0;
11901 int ret;
11902 struct device *dev;
11903
11904 device = MKDEV(wlan_hdd_state_major, 0);
11905
11906 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11907 if (ret) {
11908 pr_err("Failed to register qcwlanstate");
11909 goto dev_alloc_err;
11910 }
11911 wlan_hdd_state_major = MAJOR(device);
11912
11913 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11914 if (IS_ERR(class)) {
11915 pr_err("wlan_hdd_state class_create error");
11916 goto class_err;
11917 }
11918
11919 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11920 if (IS_ERR(dev)) {
11921 pr_err("wlan_hdd_statedevice_create error");
11922 goto err_class_destroy;
11923 }
11924
11925 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11926 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11927 if (ret) {
11928 pr_err("Failed to add cdev error");
11929 goto cdev_add_err;
11930 }
11931
11932 pr_info("wlan_hdd_state %s major(%d) initialized",
11933 WLAN_MODULE_NAME, wlan_hdd_state_major);
11934
11935 return 0;
11936
11937cdev_add_err:
11938 device_destroy(class, device);
11939err_class_destroy:
11940 class_destroy(class);
11941class_err:
11942 unregister_chrdev_region(device, dev_num);
11943dev_alloc_err:
11944 return -ENODEV;
11945}
11946
11947static void wlan_hdd_state_ctrl_param_destroy(void)
11948{
11949 cdev_del(&wlan_hdd_state_cdev);
11950 device_destroy(class, device);
11951 class_destroy(class);
11952 unregister_chrdev_region(device, dev_num);
11953
11954 pr_info("Device node unregistered");
11955}
11956
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011957/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011958 * component_init - API to init cld component's
11959 *
11960 * Return: None
11961 */
11962static void component_init(void)
11963{
11964 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011965 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011966 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011967 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011968}
11969
11970/**
11971 * component_deinit - API to deinit cld component's
11972 *
11973 * Return: None
11974 */
11975static void component_deinit(void)
11976{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011977 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011978 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011979 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011980 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011981}
11982
11983void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11984{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011985 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011986 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011987}
11988
11989void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11990{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011991 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011992 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011993}
11994
11995/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011996 * __hdd_module_init - Module init helper
11997 *
11998 * Module init helper function used by both module and static driver.
11999 *
12000 * Return: 0 for success, errno on failure
12001 */
12002static int __hdd_module_init(void)
12003{
12004 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012005
Dustin Brown96cd9632017-11-13 12:45:04 -080012006 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012007 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012008 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012009 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012010
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012011 pld_init();
12012
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012013 ret = hdd_init();
12014 if (ret) {
12015 pr_err("hdd_init failed %x\n", ret);
12016 goto err_hdd_init;
12017 }
12018
Rajeev Kumar97767a02016-11-30 11:20:40 -080012019 dispatcher_init();
12020
Mukul Sharmad75a6672017-06-22 15:40:53 +053012021 /* Ensure to call post objmgr init */
12022 component_init();
12023
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012024 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012025
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012026 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012027
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012028 ret = wlan_hdd_register_driver();
12029 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012030 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12031 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012032 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012033 }
12034
Sachin Ahuja16904db2017-12-13 19:56:57 +053012035 ret = wlan_hdd_state_ctrl_param_create();
12036 if (ret) {
12037 pr_err("wlan_hdd_state_create:%x\n", ret);
12038 goto out;
12039 }
12040
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012041 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012042
12043 return 0;
12044out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012045 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012046 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012047 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012048 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012049
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012050err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012051 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012052 return ret;
12053}
12054
12055/**
12056 * __hdd_module_exit - Module exit helper
12057 *
12058 * Module exit helper function used by both module and static driver.
12059 */
12060static void __hdd_module_exit(void)
12061{
Will Huang36049722018-04-13 11:48:51 +080012062 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012063
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012064 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12065 QWLAN_VERSIONSTR);
12066
Will Huang36049722018-04-13 11:48:51 +080012067 if (!hdd_ctx) {
12068 hdd_err("hdd context is NULL return!!");
12069 return;
12070 }
12071
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012072 if (!hdd_wait_for_recovery_completion())
12073 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012074
Will Huang36049722018-04-13 11:48:51 +080012075 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
12076
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012077 wlan_hdd_unregister_driver();
12078
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012079 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012080
Mukul Sharmad75a6672017-06-22 15:40:53 +053012081 /* Ensure to call prior to objmgr deinit */
12082 component_deinit();
12083
Rajeev Kumar97767a02016-11-30 11:20:40 -080012084 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012085
12086 hdd_sysfs_destroy_version_interface();
12087
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012088 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012089 pld_deinit();
12090
Sachin Ahujadddd2632017-03-07 19:07:24 +053012091 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012092}
12093
Arun Khandavallifae92942016-08-01 13:31:08 +053012094#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012095/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012096 * wlan_boot_cb() - Wlan boot callback
12097 * @kobj: object whose directory we're creating the link in.
12098 * @attr: attribute the user is interacting with
12099 * @buff: the buffer containing the user data
12100 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012101 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012102 * This callback is invoked when the fs is ready to start the
12103 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012104 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012105 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012106 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012107static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012108 struct kobj_attribute *attr,
12109 const char *buf,
12110 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012111{
Arun Khandavallifae92942016-08-01 13:31:08 +053012112
Arun Khandavallifae92942016-08-01 13:31:08 +053012113 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012114 pr_err("%s: wlan driver already initialized\n", __func__);
12115 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012116 }
12117
Arun Khandavallifae92942016-08-01 13:31:08 +053012118 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012119 pr_err("%s: wlan driver initialization failed\n", __func__);
12120 return -EIO;
12121 }
12122
12123 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012124
12125 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012126}
Arun Khandavallifae92942016-08-01 13:31:08 +053012127
12128/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012129 * hdd_sysfs_cleanup() - cleanup sysfs
12130 *
12131 * Return: None
12132 *
12133 */
12134static void hdd_sysfs_cleanup(void)
12135{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012136 /* remove from group */
12137 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12138 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12139 wlan_loader->attr_group);
12140
12141 /* unlink the object from parent */
12142 kobject_del(wlan_loader->boot_wlan_obj);
12143
12144 /* free the object */
12145 kobject_put(wlan_loader->boot_wlan_obj);
12146
12147 kfree(wlan_loader->attr_group);
12148 kfree(wlan_loader);
12149
12150 wlan_loader = NULL;
12151}
12152
12153/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012154 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12155 * ready
12156 *
12157 * This is creates the syfs entry boot_wlan. Which shall be invoked
12158 * when the filesystem is ready.
12159 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012160 * QDF API cannot be used here since this function is called even before
12161 * initializing WLAN driver.
12162 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012163 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012164 */
12165static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012166{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012167 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012168
12169 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012170 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012171 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012172
12173 wlan_loader->boot_wlan_obj = NULL;
12174 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12175 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012176 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012177 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012178
12179 wlan_loader->loaded_state = 0;
12180 wlan_loader->attr_group->attrs = attrs;
12181
12182 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12183 kernel_kobj);
12184 if (!wlan_loader->boot_wlan_obj) {
12185 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012186 goto error_return;
12187 }
12188
12189 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12190 wlan_loader->attr_group);
12191 if (ret) {
12192 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12193 goto error_return;
12194 }
12195
12196 return 0;
12197
12198error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012199 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012200
12201 return ret;
12202}
12203
12204/**
12205 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12206 *
12207 * Return: 0 on success or errno on failure
12208 */
12209static int wlan_deinit_sysfs(void)
12210{
Arun Khandavallifae92942016-08-01 13:31:08 +053012211 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012212 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012213 return -EINVAL;
12214 }
12215
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012216 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012217 return 0;
12218}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012219
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012220#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012221
12222#ifdef MODULE
12223/**
12224 * __hdd_module_init - Module init helper
12225 *
12226 * Module init helper function used by both module and static driver.
12227 *
12228 * Return: 0 for success, errno on failure
12229 */
12230static int hdd_module_init(void)
12231{
Arun Khandavallifae92942016-08-01 13:31:08 +053012232 if (__hdd_module_init()) {
12233 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012234 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012235 }
12236
Dustin Brownab482ac2017-06-09 17:00:44 -070012237 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012238}
12239#else
12240static int __init hdd_module_init(void)
12241{
12242 int ret = -EINVAL;
12243
12244 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012245 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012246 pr_err("Failed to create sysfs entry for loading wlan");
12247
12248 return ret;
12249}
12250#endif
12251
12252
12253#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012254/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012255 * hdd_module_exit() - Exit function
12256 *
12257 * This is the driver exit point (invoked when module is unloaded using rmmod)
12258 *
12259 * Return: None
12260 */
12261static void __exit hdd_module_exit(void)
12262{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012263 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012264}
Arun Khandavallifae92942016-08-01 13:31:08 +053012265#else
12266static void __exit hdd_module_exit(void)
12267{
12268 __hdd_module_exit();
12269 wlan_deinit_sysfs();
12270}
12271#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012272
Srinivas Girigowda841da292018-02-21 16:33:00 -080012273static int fwpath_changed_handler(const char *kmessage,
12274 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012275{
12276 return param_set_copystring(kmessage, kp);
12277}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012278
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012279/**
12280 * is_con_mode_valid() check con mode is valid or not
12281 * @mode: global con mode
12282 *
12283 * Return: TRUE on success FALSE on failure
12284 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012285static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012286{
12287 switch (mode) {
12288 case QDF_GLOBAL_MONITOR_MODE:
12289 case QDF_GLOBAL_FTM_MODE:
12290 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012291 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012292 return true;
12293 default:
12294 return false;
12295 }
12296}
12297
12298/**
12299 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12300 * @mode: global con mode
12301 *
12302 * Return: adapter mode
12303 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012304static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012305 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012306{
12307
12308 switch (mode) {
12309 case QDF_GLOBAL_MISSION_MODE:
12310 return QDF_STA_MODE;
12311 case QDF_GLOBAL_MONITOR_MODE:
12312 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012313 case QDF_GLOBAL_EPPING_MODE:
12314 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012315 case QDF_GLOBAL_FTM_MODE:
12316 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012317 case QDF_GLOBAL_QVIT_MODE:
12318 return QDF_QVIT_MODE;
12319 default:
12320 return QDF_MAX_NO_OF_MODE;
12321 }
12322}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012323
Dustin Brown27cd9942017-09-27 16:11:44 -070012324static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012325 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012326{
12327 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12328 return;
12329
12330 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012331 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012332 hdd_info("Release wakelock for monitor mode!");
12333 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12334 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012335 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012336 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012337 case QDF_GLOBAL_FTM_MODE:
12338 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012339 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012340 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012341
Dustin Brown27cd9942017-09-27 16:11:44 -070012342 break;
12343 default:
12344 break;
12345 }
12346}
12347
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012348static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012349 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012350{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012351 int driver_status;
12352
12353 driver_status = hdd_ctx->driver_status;
12354
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012355 switch (curr_mode) {
12356 case QDF_GLOBAL_MISSION_MODE:
12357 case QDF_GLOBAL_MONITOR_MODE:
12358 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012359 hdd_deinit_all_adapters(hdd_ctx, false);
12360 hdd_close_all_adapters(hdd_ctx, false);
12361 break;
12362 case QDF_GLOBAL_EPPING_MODE:
12363 epping_disable();
12364 epping_close();
12365 break;
12366 default:
12367 return;
12368 }
12369}
12370
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012371static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012372 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012373{
Jeff Johnson9d295242017-08-29 14:39:48 -070012374 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012375 int ret = 0;
12376 bool rtnl_held;
12377 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12378 QDF_STATUS status;
12379
12380 if (!qdf_dev) {
12381 hdd_err("qdf device context is Null return!");
12382 return -EINVAL;
12383 }
12384
12385 rtnl_held = hdd_hold_rtnl_lock();
12386 switch (mode) {
12387 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012388 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12389 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012390 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012391 break;
12392 case QDF_GLOBAL_FTM_MODE:
12393 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12394 wlan_hdd_get_intf_addr(hdd_ctx),
12395 NET_NAME_UNKNOWN, rtnl_held);
12396 if (adapter == NULL)
12397 ret = -EINVAL;
12398 break;
12399 case QDF_GLOBAL_MONITOR_MODE:
12400 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12401 wlan_hdd_get_intf_addr(hdd_ctx),
12402 NET_NAME_UNKNOWN, rtnl_held);
12403 if (adapter == NULL)
12404 ret = -EINVAL;
12405 break;
12406 case QDF_GLOBAL_EPPING_MODE:
12407 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012408 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012409 hdd_err("Failed to open in eeping mode: %d", status);
12410 ret = -EINVAL;
12411 break;
12412 }
12413 ret = epping_enable(qdf_dev->dev);
12414 if (ret) {
12415 hdd_err("Failed to enable in epping mode : %d", ret);
12416 epping_close();
12417 }
12418 break;
12419 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012420 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012421 ret = -ENOTSUPP;
12422 break;
12423 }
12424 hdd_release_rtnl_lock();
12425 rtnl_held = false;
12426 return ret;
12427}
12428
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012429/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012430 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012431 * @kmessage: con mode name on which driver to be bring up
12432 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012433 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012434 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012435 * This function is invoked when user updates con mode using sys entry,
12436 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012437 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012438 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012439 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012440static int __con_mode_handler(const char *kmessage,
12441 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012442 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012443{
12444 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012445 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012446 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012447 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012448 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012449
Dustin Brownab6029b2017-05-24 13:04:19 -070012450 hdd_info("con_mode handler: %s", kmessage);
12451
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012452 ret = wlan_hdd_validate_context(hdd_ctx);
12453 if (ret)
12454 return ret;
12455
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012456 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012457 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012458
Dustin Brown20024e32018-01-03 12:34:58 -080012459 ret = kstrtoint(kmessage, 0, &new_con_mode);
12460 if (ret) {
12461 hdd_err("Failed to parse con_mode '%s'", kmessage);
12462 goto reset_flags;
12463 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012464 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012465
Dustin Brown20024e32018-01-03 12:34:58 -080012466 if (!is_con_mode_valid(new_con_mode)) {
12467 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012468 ret = -EINVAL;
12469 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012470 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012471
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012472 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012473 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012474 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012475 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012476 ret = 0;
12477 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012478 }
12479
Dustin Brown27cd9942017-09-27 16:11:44 -070012480 /* ensure adapters are stopped */
12481 hdd_stop_present_mode(hdd_ctx, curr_mode);
12482
Frank Liu6666f832018-01-04 10:06:05 +080012483 /* Cleanup present mode before switching to new mode */
12484 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12485
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012486 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012487 if (ret) {
12488 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012489 goto reset_flags;
12490 }
12491
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012492
Dustin Brown20024e32018-01-03 12:34:58 -080012493 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012494
Frank Liu6666f832018-01-04 10:06:05 +080012495 /*
12496 * Set ACTIVE domain before adapters created, otherwise check domain
12497 * match will fail when cleanup adapters.
12498 */
12499 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012500 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012501 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012502 if (ret) {
12503 hdd_err("Failed to register for new mode");
12504 goto reset_flags;
12505 }
12506
Dustin Brown20024e32018-01-03 12:34:58 -080012507 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012508 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12509 hdd_err("invalid adapter");
12510 ret = -EINVAL;
12511 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012512 }
12513
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012514 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012515 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012516 hdd_err("Failed to get adapter:%d", adapter_mode);
12517 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012518 }
12519
12520 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12521 if (ret) {
12522 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012523 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012524 }
12525
Dustin Brown20024e32018-01-03 12:34:58 -080012526 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012527 if (hdd_start_adapter(adapter)) {
12528 hdd_err("Failed to start %s adapter", kmessage);
12529 ret = -EINVAL;
12530 goto reset_flags;
12531 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012532
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012533 hdd_info("Acquire wakelock for monitor mode!");
12534 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12535 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12536 }
12537
Dustin Brown20024e32018-01-03 12:34:58 -080012538 /* con_mode is a global module parameter */
12539 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012540 hdd_info("Mode successfully changed to %s", kmessage);
12541 ret = 0;
12542
12543reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012544 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012545 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012546 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012547 return ret;
12548}
12549
12550
Srinivas Girigowda841da292018-02-21 16:33:00 -080012551static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012552{
12553 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012554 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012555
12556 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12557 ret = wlan_hdd_validate_context(hdd_ctx);
12558 if (ret)
12559 return ret;
12560
12561 cds_ssr_protect(__func__);
12562 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12563 cds_ssr_unprotect(__func__);
12564
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012565 return ret;
12566}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012567
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012568static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012569 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012570{
12571 int ret;
12572
12573 ret = param_set_int(kmessage, kp);
12574
12575 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12576 pr_err("Only FTM mode supported!");
12577 return -ENOTSUPP;
12578 }
12579
12580 hdd_set_conparam(con_mode_ftm);
12581 con_mode = con_mode_ftm;
12582
12583 return ret;
12584}
12585
Ravi Joshia307f632017-07-17 23:41:41 -070012586static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012587 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012588{
12589 int ret;
12590
12591 ret = param_set_int(kmessage, kp);
12592
12593 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12594 pr_err("Only Monitor mode supported!");
12595 return -ENOTSUPP;
12596 }
12597
12598 hdd_set_conparam(con_mode_monitor);
12599 con_mode = con_mode_monitor;
12600
12601 return ret;
12602}
12603
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012604/**
12605 * hdd_get_conparam() - driver exit point
12606 *
12607 * This is the driver exit point (invoked when module is unloaded using rmmod)
12608 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012609 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012610 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012611enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012612{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012613 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012614}
12615
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012616void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012617{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012618 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012619}
12620
Komal Seelamc11bb222016-01-27 18:57:10 +053012621/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012622 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12623 * @hdd_ctx: HDD context
12624 *
12625 * Cleans up the pre cac interface, if it exists
12626 *
12627 * Return: None
12628 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012629void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012630{
12631 uint8_t session_id;
12632 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012633 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012634
12635 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12636 if (QDF_IS_STATUS_ERROR(status)) {
12637 hdd_err("failed to get pre cac vdev id");
12638 return;
12639 }
12640
12641 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12642 if (!precac_adapter) {
12643 hdd_err("invalid pre cac adapater");
12644 return;
12645 }
12646
12647 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12648 wlan_hdd_sap_pre_cac_failure,
12649 (void *)precac_adapter);
12650 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12651
12652}
12653
12654/**
Komal Seelamec702b02016-02-24 18:42:16 +053012655 * hdd_update_ol_config - API to update ol configuration parameters
12656 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012657 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012658 * Return: void
12659 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012660static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012661{
Komal Seelamec702b02016-02-24 18:42:16 +053012662 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012663 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012664
Komal Seelamec702b02016-02-24 18:42:16 +053012665 if (!ol_ctx)
12666 return;
12667
12668 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12669 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12670 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12671 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012672 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012673
12674 ol_init_ini_config(ol_ctx, &cfg);
12675}
12676
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012677#ifdef FEATURE_RUNTIME_PM
12678/**
12679 * hdd_populate_runtime_cfg() - populate runtime configuration
12680 * @hdd_ctx: hdd context
12681 * @cfg: pointer to the configuration memory being populated
12682 *
12683 * Return: void
12684 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012685static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012686 struct hif_config_info *cfg)
12687{
12688 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12689 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12690}
12691#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012692static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012693 struct hif_config_info *cfg)
12694{
12695}
12696#endif
12697
Komal Seelamec702b02016-02-24 18:42:16 +053012698/**
12699 * hdd_update_hif_config - API to update HIF configuration parameters
12700 * @hdd_ctx: HDD Context
12701 *
12702 * Return: void
12703 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012704static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012705{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012706 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012707 struct hif_config_info cfg;
12708
12709 if (!scn)
12710 return;
12711
12712 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012713 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012714 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012715
12716 if (hdd_ctx->config->prevent_link_down)
12717 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012718}
12719
12720/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012721 * hdd_update_dp_config() - Propagate config parameters to Lithium
12722 * datapath
12723 * @hdd_ctx: HDD Context
12724 *
12725 * Return: 0 for success/errno for failure
12726 */
12727static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12728{
12729 struct cdp_config_params params;
12730 QDF_STATUS status;
12731
12732 params.tso_enable = hdd_ctx->config->tso_enable;
12733 params.lro_enable = hdd_ctx->config->lro_enable;
12734#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12735 params.tx_flow_stop_queue_threshold =
12736 hdd_ctx->config->TxFlowStopQueueThreshold;
12737 params.tx_flow_start_queue_offset =
12738 hdd_ctx->config->TxFlowStartQueueOffset;
12739#endif
12740 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12741 params.napi_enable = hdd_ctx->napi_enable;
12742 params.tcp_udp_checksumoffload =
12743 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12744
12745 status = cdp_update_config_parameters(
12746 cds_get_context(QDF_MODULE_ID_SOC),
12747 &params);
12748 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012749 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012750 return status;
12751 }
12752
12753 return 0;
12754}
12755
12756/**
Komal Seelamec702b02016-02-24 18:42:16 +053012757 * hdd_update_config() - Initialize driver per module ini parameters
12758 * @hdd_ctx: HDD Context
12759 *
12760 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012761 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012762 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012763int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012764{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012765 int ret;
12766
Komal Seelamec702b02016-02-24 18:42:16 +053012767 hdd_update_ol_config(hdd_ctx);
12768 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012769 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12770 ret = hdd_update_cds_config_ftm(hdd_ctx);
12771 else
12772 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012773 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012774
12775 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012776}
12777
Mukul Sharma9d797a02017-01-05 20:26:03 +053012778#ifdef FEATURE_WLAN_RA_FILTERING
12779/**
12780 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12781 * @psoc_cfg: pmo psoc Configuration
12782 * @hdd_ctx: Pointer to hdd context
12783 *
12784 * Return: none
12785 */
12786static inline void hdd_ra_populate_pmo_config(
12787 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012788 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012789{
12790 psoc_cfg->ra_ratelimit_interval =
12791 hdd_ctx->config->RArateLimitInterval;
12792 psoc_cfg->ra_ratelimit_enable =
12793 hdd_ctx->config->IsRArateLimitEnabled;
12794}
12795#else
12796static inline void hdd_ra_populate_pmo_config(
12797 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012798 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012799{
12800}
12801#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012802
Mukul Sharma9d797a02017-01-05 20:26:03 +053012803/**
12804 * hdd_update_pmo_config - API to update pmo configuration parameters
12805 * @hdd_ctx: HDD context
12806 *
12807 * Return: void
12808 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012809static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012810{
Mukul Sharma9d797a02017-01-05 20:26:03 +053012811 struct pmo_psoc_cfg psoc_cfg;
12812 QDF_STATUS status;
12813
12814 /*
12815 * Value of hdd_ctx->wowEnable can be,
12816 * 0 - Disable both magic pattern match and pattern byte match.
12817 * 1 - Enable magic pattern match on all interfaces.
12818 * 2 - Enable pattern byte match on all interfaces.
12819 * 3 - Enable both magic patter and pattern byte match on
12820 * all interfaces.
12821 */
12822 psoc_cfg.magic_ptrn_enable =
12823 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12824 psoc_cfg.ptrn_match_enable_all_vdev =
12825 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080012826 psoc_cfg.ptrn_id_per_vdev =
12827 wma_is_service_enabled(wmi_service_unified_wow_capability);
12828 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012829 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012830 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080012831 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012832 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080012833 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012834 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12835 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080012836 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012837 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012838 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053012839 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12840 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12841 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080012842 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012843 psoc_cfg.auto_power_save_fail_mode =
12844 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012845
12846 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012847 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12848 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012849
Dustin Brownb9987af2018-03-01 17:15:11 -080012850 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
12851 if (QDF_IS_STATUS_ERROR(status))
12852 hdd_err("failed pmo psoc configuration; status:%d", status);
12853
12854 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012855}
12856
Abhishek Singhb20db962017-03-03 21:28:46 +053012857#ifdef FEATURE_WLAN_SCAN_PNO
12858static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12859 struct hdd_config *cfg)
12860{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012861 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12862
Abhishek Singhb20db962017-03-03 21:28:46 +053012863 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12864 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12865 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12866 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12867 pno_cfg->channel_prediction_full_scan =
12868 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012869 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12870 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12871 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12872 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012873}
12874#else
12875static inline void
12876hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012877 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012878{
Abhishek Singhb20db962017-03-03 21:28:46 +053012879}
12880#endif
12881
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012882void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12883 struct hdd_config *cfg)
12884{
12885 uint8_t i = 0;
12886
12887 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12888 if (!ie_whitelist->white_list)
12889 return;
12890
12891 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12892 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12893 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12894 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12895 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12896 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12897 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12898 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12899
12900 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12901 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12902 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12903}
12904
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012905uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12906{
12907 uint8_t i, score;
12908
12909 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12910 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12911 if (score > MAX_INDEX_SCORE)
12912 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12913 MAX_INDEX_SCORE, i);
12914 }
12915
12916 return per_index_score;
12917}
12918
12919/**
12920 * hdd_update_score_config - API to update candidate scoring related params
12921 * configuration parameters
12922 * @score_config: score config to update
12923 * @cfg: config params
12924 *
12925 * Return: 0 if success else err
12926 */
12927static void hdd_update_score_config(
12928 struct scoring_config *score_config, struct hdd_config *cfg)
12929{
12930 int total_weight;
12931
12932 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12933 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12934 score_config->weight_cfg.vht_caps_weightage =
12935 cfg->vht_caps_weightage;
12936 score_config->weight_cfg.he_caps_weightage =
12937 cfg->he_caps_weightage;
12938 score_config->weight_cfg.chan_width_weightage =
12939 cfg->chan_width_weightage;
12940 score_config->weight_cfg.chan_band_weightage =
12941 cfg->chan_band_weightage;
12942 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12943 score_config->weight_cfg.beamforming_cap_weightage =
12944 cfg->beamforming_cap_weightage;
12945 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12946 score_config->weight_cfg.channel_congestion_weightage =
12947 cfg->channel_congestion_weightage;
12948 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12949
12950 total_weight = score_config->weight_cfg.rssi_weightage +
12951 score_config->weight_cfg.ht_caps_weightage +
12952 score_config->weight_cfg.vht_caps_weightage +
12953 score_config->weight_cfg.he_caps_weightage +
12954 score_config->weight_cfg.chan_width_weightage +
12955 score_config->weight_cfg.chan_band_weightage +
12956 score_config->weight_cfg.nss_weightage +
12957 score_config->weight_cfg.beamforming_cap_weightage +
12958 score_config->weight_cfg.pcl_weightage +
12959 score_config->weight_cfg.channel_congestion_weightage +
12960 score_config->weight_cfg.oce_wan_weightage;
12961
12962 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12963 hdd_err("total weight is greater than %d fallback to default values",
12964 BEST_CANDIDATE_MAX_WEIGHT);
12965
12966 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12967 score_config->weight_cfg.ht_caps_weightage =
12968 HT_CAPABILITY_WEIGHTAGE;
12969 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12970 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12971 score_config->weight_cfg.chan_width_weightage =
12972 CHAN_WIDTH_WEIGHTAGE;
12973 score_config->weight_cfg.chan_band_weightage =
12974 CHAN_BAND_WEIGHTAGE;
12975 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12976 score_config->weight_cfg.beamforming_cap_weightage =
12977 BEAMFORMING_CAP_WEIGHTAGE;
12978 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12979 score_config->weight_cfg.channel_congestion_weightage =
12980 CHANNEL_CONGESTION_WEIGHTAGE;
12981 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12982 }
12983
12984 score_config->bandwidth_weight_per_index =
12985 hdd_limit_max_per_index_score(
12986 cfg->bandwidth_weight_per_index);
12987 score_config->nss_weight_per_index =
12988 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12989 score_config->band_weight_per_index =
12990 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12991
12992 score_config->rssi_score.best_rssi_threshold =
12993 cfg->best_rssi_threshold;
12994 score_config->rssi_score.good_rssi_threshold =
12995 cfg->good_rssi_threshold;
12996 score_config->rssi_score.bad_rssi_threshold =
12997 cfg->bad_rssi_threshold;
12998 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12999 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13000 score_config->rssi_score.good_rssi_bucket_size =
13001 cfg->good_rssi_bucket_size;
13002 score_config->rssi_score.bad_rssi_bucket_size =
13003 cfg->bad_rssi_bucket_size;
13004 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13005 cfg->rssi_pref_5g_rssi_thresh;
13006
13007 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13008 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13009 hdd_limit_max_per_index_score(
13010 cfg->esp_qbss_score_slots3_to_0);
13011 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13012 hdd_limit_max_per_index_score(
13013 cfg->esp_qbss_score_slots7_to_4);
13014 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13015 hdd_limit_max_per_index_score(
13016 cfg->esp_qbss_score_slots11_to_8);
13017 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13018 hdd_limit_max_per_index_score(
13019 cfg->esp_qbss_score_slots15_to_12);
13020
13021 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13022 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13023 hdd_limit_max_per_index_score(
13024 cfg->oce_wan_score_slots3_to_0);
13025 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13026 hdd_limit_max_per_index_score(
13027 cfg->oce_wan_score_slots7_to_4);
13028 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13029 hdd_limit_max_per_index_score(
13030 cfg->oce_wan_score_slots11_to_8);
13031 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13032 hdd_limit_max_per_index_score(
13033 cfg->oce_wan_score_slots15_to_12);
13034
13035
13036 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13037 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13038 score_config->nss = cfg->enable2x2 ? 2 : 1;
13039
13040 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13041 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13042 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13043 score_config->he_cap = 1;
13044
13045 if (score_config->he_cap ||
13046 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13047 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13048 score_config->vht_cap = 1;
13049
13050 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13051 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13052 score_config->ht_cap = 1;
13053
13054 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13055 score_config->vht_24G_cap = 1;
13056
13057 if (cfg->enableTxBF)
13058 score_config->beamformee_cap = 1;
13059
13060}
13061
Abhishek Singh257a9482017-03-06 16:52:39 +053013062/**
bings81fe50a2017-11-27 14:33:26 +080013063 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13064 * @hdd_ctx: HDD context
13065 *
13066 * Return: 0 if success else err
13067 */
13068static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13069{
13070 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13071 struct hdd_config *cfg = hdd_ctx->config;
13072 struct dfs_user_config dfs_cfg;
13073 QDF_STATUS status;
13074
13075 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13076 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13077 if (QDF_IS_STATUS_ERROR(status)) {
13078 hdd_err("failed dfs psoc configuration");
13079 return -EINVAL;
13080 }
13081
13082 return 0;
13083}
13084
13085/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013086 * hdd_update_scan_config - API to update scan configuration parameters
13087 * @hdd_ctx: HDD context
13088 *
13089 * Return: 0 if success else err
13090 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013091static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013092{
13093 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13094 struct scan_user_cfg scan_cfg;
13095 struct hdd_config *cfg = hdd_ctx->config;
13096 QDF_STATUS status;
13097
13098 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13099 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13100 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13101 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13102 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13103 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13104 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013105 /* convert to ms */
13106 scan_cfg.scan_cache_aging_time =
13107 cfg->scanAgingTimeout * 1000;
13108 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13109 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13110 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13111 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013112 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013113 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013114 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13115 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013116 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013117 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013118 scan_cfg.sta_miracast_mcc_rest_time =
13119 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013120
Abhishek Singhb20db962017-03-03 21:28:46 +053013121 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013122 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013123 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013124
Abhishek Singh257a9482017-03-06 16:52:39 +053013125 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13126 if (status != QDF_STATUS_SUCCESS) {
13127 hdd_err("failed pmo psoc configuration");
13128 return -EINVAL;
13129 }
13130
13131 return 0;
13132}
Abhishek Singh257a9482017-03-06 16:52:39 +053013133
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013134int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013135{
13136 int ret;
13137
13138 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013139 if (ret)
13140 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013141
Abhishek Singh257a9482017-03-06 16:52:39 +053013142 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013143 if (ret)
13144 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013145
Frank Liud4b2fa02017-03-29 11:46:48 +080013146 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013147 if (ret)
13148 return ret;
13149
13150 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013151 if (ret)
13152 return ret;
13153
13154 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013155
13156 return ret;
13157}
13158
Agrawal Ashish65634612016-08-18 13:24:32 +053013159/**
13160 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13161 * @mode : cfg80211 DFS mode
13162 *
13163 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13164 */
13165enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13166{
13167 switch (mode) {
13168 case DFS_MODE_ENABLE:
13169 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013170 case DFS_MODE_DISABLE:
13171 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013172 case DFS_MODE_DEPRIORITIZE:
13173 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013174 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013175 hdd_debug("ACS dfs mode is NONE");
13176 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013177 }
13178}
13179
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013180/**
13181 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13182 * @hddctx: pointer to hdd context
13183 * @set_value: enable/disable
13184 *
13185 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13186 * Host(even though it is duplicate). When Host send vendor command
13187 * disable,FW doesn't perform any action. Whenever any change in
13188 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13189 *
13190 * return - 0 on success, appropriate error values on failure.
13191 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013192int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013193{
13194 QDF_STATUS status;
13195
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013196 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013197 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013198
13199 if (!hddctx->config->goptimize_chan_avoid_event) {
13200 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13201 return -EINVAL;
13202 }
13203
13204 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13205 if (!QDF_IS_STATUS_SUCCESS(status)) {
13206 hdd_err("Failed to send chan avoid command to SME");
13207 return -EINVAL;
13208 }
13209 return 0;
13210}
Agrawal Ashish65634612016-08-18 13:24:32 +053013211
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013212/**
13213 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13214 * @value: value to set
13215 *
13216 * This function will set the passed value to roaming in progress flag.
13217 *
13218 * Return: None
13219 */
13220void hdd_set_roaming_in_progress(bool value)
13221{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013222 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013223
13224 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13225 if (!hdd_ctx) {
13226 hdd_err("HDD context is NULL");
13227 return;
13228 }
13229
13230 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013231 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013232}
13233
13234/**
13235 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013236 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013237 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013238 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013239 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013240bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013241{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013242 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013243 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013244
13245 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13246 if (!hdd_ctx) {
13247 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013248 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013249 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013250 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13251 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013252 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13253 hdd_ctx->roaming_in_progress);
13254
13255 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013256}
13257
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013258/**
13259 * hdd_is_connection_in_progress() - check if connection is in
13260 * progress
13261 * @session_id: session id
13262 * @reason: scan reject reason
13263 *
13264 * Go through each adapter and check if Connection is in progress
13265 *
13266 * Return: true if connection is in progress else false
13267 */
13268bool hdd_is_connection_in_progress(uint8_t *session_id,
13269 enum scan_reject_states *reason)
13270{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013271 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013272 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013273 uint8_t sta_id = 0;
13274 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013275 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013276
13277 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13278 if (!hdd_ctx) {
13279 hdd_err("HDD context is NULL");
13280 return false;
13281 }
13282
Dustin Brown920397d2017-12-13 16:27:50 -080013283 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013284 hdd_info("Adapter with device mode %s(%d) exists",
13285 hdd_device_mode_to_string(adapter->device_mode),
13286 adapter->device_mode);
13287 if (((QDF_STA_MODE == adapter->device_mode)
13288 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13289 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13290 && (eConnectionState_Connecting ==
13291 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13292 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013293 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013294 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013295 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013296 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013297 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013298 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013299 }
13300 return true;
13301 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013302 /*
13303 * sme_neighbor_middle_of_roaming is for LFR2
13304 * hdd_is_roaming_in_progress is for LFR3
13305 */
13306 if (((QDF_STA_MODE == adapter->device_mode) &&
13307 sme_neighbor_middle_of_roaming(
13308 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013309 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013310 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013311 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013312 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013313 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013314 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013315 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013316 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013317 }
13318 return true;
13319 }
13320 if ((QDF_STA_MODE == adapter->device_mode) ||
13321 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13322 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13323 hdd_sta_ctx =
13324 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13325 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013326 hdd_sta_ctx->conn_info.connState)
13327 && sme_is_sta_key_exchange_in_progress(
13328 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013329 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013330 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013331 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013332 " is in middle of WPS/EAPOL exchange.",
13333 MAC_ADDR_ARRAY(sta_mac));
13334 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013335 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013336 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013337 }
13338 return true;
13339 }
13340 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13341 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13342 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13343 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013344 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013345 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013346 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013347 continue;
13348
13349 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013350 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013351 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013352 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013353 " of SAP/GO is in middle of WPS/EAPOL exchange",
13354 MAC_ADDR_ARRAY(sta_mac));
13355 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013356 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013357 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013358 }
13359 return true;
13360 }
13361 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013362 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013363 return true;
13364 }
13365 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013366 }
Dustin Brown920397d2017-12-13 16:27:50 -080013367
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013368 return false;
13369}
13370
13371/**
13372 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013373 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013374 *
13375 * Return: None
13376 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013377void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013378{
Jeff Johnson87251032017-08-29 13:31:11 -070013379 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013380 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013381 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013382 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013383 tsap_Config_t *sap_config;
13384 void *sap_ctx;
13385
13386 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013387 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013388 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013389
13390 mutex_lock(&hdd_ctx->sap_lock);
13391 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13392 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013393 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13394 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13395 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13396 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013397 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013398 qdf_stop_bss_event,
13399 SME_CMD_TIMEOUT_VALUE);
13400
13401 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013402 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013403 goto end;
13404 }
13405 }
13406 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013407 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013408 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013409 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013410 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013411 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013412
13413 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013414 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013415 wlansap_reset_sap_config_add_ie(sap_config,
13416 eUPDATE_IE_ALL);
13417 goto end;
13418 }
13419
13420 qdf_event_reset(&hostapd_state->qdf_event);
13421 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13422 sap_config,
13423 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013424 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013425 wlansap_reset_sap_config_add_ie(sap_config,
13426 eUPDATE_IE_ALL);
13427 goto end;
13428 }
13429
Jeff Johnson6867ec32017-09-29 20:30:20 -070013430 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013431 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013432 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013433 SME_CMD_TIMEOUT_VALUE);
13434 wlansap_reset_sap_config_add_ie(sap_config,
13435 eUPDATE_IE_ALL);
13436 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013437 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013438 goto end;
13439 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013440 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013441 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013442 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013443 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13444 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013445 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013446 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013447 ap_adapter->device_mode,
13448 true);
13449 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013450 }
13451end:
13452 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013453}
13454
13455/**
13456 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13457 * with non dfs acs
13458 *
13459 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13460 *
13461 * Return: None
13462 */
13463void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13464{
Jeff Johnson9d295242017-08-29 14:39:48 -070013465 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013466 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013467 cds_context_type *cds_ctx;
13468
13469 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13470 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013471 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013472 return;
13473 }
13474
13475 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13476 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013477 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013478 return;
13479 }
13480
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013481 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13482 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013483 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013484 return;
13485 }
13486
13487 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013488 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13489 &ap_adapter->event_flags) &&
13490 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013491 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013492
Jeff Johnson6867ec32017-09-29 20:30:20 -070013493 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013494 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013495 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013496 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013497 acs_cfg.acs_mode = true;
13498
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013499 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013500 }
13501}
13502
13503/**
13504 * hdd_set_connection_in_progress() - to set the connection in
13505 * progress flag
13506 * @value: value to set
13507 *
13508 * This function will set the passed value to connection in progress flag.
13509 * If value is previously being set to true then no need to set it again.
13510 *
13511 * Return: true if value is being set correctly and false otherwise.
13512 */
13513bool hdd_set_connection_in_progress(bool value)
13514{
13515 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013516 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013517
13518 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13519 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013520 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013521 return false;
13522 }
13523
13524 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13525 /*
13526 * if the value is set to true previously and if someone is
13527 * trying to make it true again then it could be some race
13528 * condition being triggered. Avoid this situation by returning
13529 * false
13530 */
13531 if (hdd_ctx->connection_in_progress && value)
13532 status = false;
13533 else
13534 hdd_ctx->connection_in_progress = value;
13535 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13536 return status;
13537}
13538
Jeff Johnson9d295242017-08-29 14:39:48 -070013539int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013540{
13541 if (!adapter) {
13542 hdd_err("Invalid adapter");
13543 return -EINVAL;
13544 }
13545 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013546 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013547 WMA_VDEV_MCC_SET_TIME_QUOTA,
13548 set_value, VDEV_CMD);
13549 return 0;
13550
13551}
13552
Jeff Johnson9d295242017-08-29 14:39:48 -070013553int wlan_hdd_send_mcc_latency(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
13560 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013561 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013562 WMA_VDEV_MCC_SET_TIME_LATENCY,
13563 set_value, VDEV_CMD);
13564 return 0;
13565}
13566
Jeff Johnson9d295242017-08-29 14:39:48 -070013567struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013568 *psoc, uint8_t vdev_id)
13569{
Jeff Johnson9d295242017-08-29 14:39:48 -070013570 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013571 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013572
13573 /*
13574 * Currently PSOC is not being used. But this logic will
13575 * change once we have the converged implementation of
13576 * HDD context per PSOC in place. This would break if
13577 * multiple vdev objects reuse the vdev id.
13578 */
13579 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13580 if (!adapter)
13581 hdd_err("Get adapter by vdev id failed");
13582
13583 return adapter;
13584}
13585
Jeff Johnson9d295242017-08-29 14:39:48 -070013586int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013587 int8_t *rssi, int8_t *snr)
13588{
13589 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013590 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013591
Jeff Johnson025618c2018-03-18 14:41:00 -070013592 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013593 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013594 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013595 if (QDF_STATUS_SUCCESS != status) {
13596 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13597 return -EINVAL;
13598 }
13599
13600 return 0;
13601}
13602
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013603/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013604 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13605 * @adapter - HDD adapter
13606 * @tos - type of service
13607 * @status - status of the traffic
13608 *
13609 * Return: 0 on success and non zero value on failure
13610 */
13611
13612int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13613 bool is_tos_active)
13614{
13615 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013616 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013617 uint32_t max_off_chan_time = 0;
13618 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013619 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013620 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013621
13622 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13623 ret = wlan_hdd_validate_context(hdd_ctx);
13624
13625 if (ret < 0) {
13626 hdd_err("failed to set limit off chan params");
13627 return ret;
13628 }
13629
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013630 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13631
13632 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013633 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013634 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013635 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013636
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013637 if (adapter->active_ac) {
13638 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013639 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013640 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13641 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13642 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013643 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013644 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013645 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13646 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13647 PM_LATENCY);
13648 } else {
13649 /*ignore this command if only BE/BK is active */
13650 is_tos_active = false;
13651 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13652 hdd_ctx->config->conc_system_pref);
13653 }
13654 } else {
13655 /* No active tos */
13656 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13657 hdd_ctx->config->conc_system_pref);
13658 }
13659
Jeff Johnson1b780e42017-10-31 14:11:45 -070013660 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013661 is_tos_active, max_off_chan_time,
13662 hdd_ctx->config->nRestTimeConc, true);
13663 if (!QDF_IS_STATUS_SUCCESS(status)) {
13664 hdd_err("failed to set limit off chan params");
13665 ret = -EINVAL;
13666 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013667
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013668 return ret;
13669}
13670
13671/**
13672 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13673 * @adapter - HDD adapter
13674 *
13675 * Return: 0 on success and non zero value on failure
13676 */
13677int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13678{
13679 struct hdd_context *hdd_ctx;
13680 int ret;
13681 QDF_STATUS status;
13682 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13683
13684 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13685 ret = wlan_hdd_validate_context(hdd_ctx);
13686 if (ret < 0)
13687 return ret;
13688
13689 /* set the system preferece to default */
13690 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13691 hdd_ctx->config->conc_system_pref);
13692
13693 /* clear the bitmap */
13694 adapter->active_ac = 0;
13695
13696 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013697 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013698
Jeff Johnson1b780e42017-10-31 14:11:45 -070013699 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013700 false, 0, 0, false);
13701 if (!QDF_IS_STATUS_SUCCESS(status)) {
13702 hdd_err("failed to reset limit off chan params");
13703 ret = -EINVAL;
13704 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013705
13706 return ret;
13707}
13708
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013709/**
13710 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13711 * @drv_op: Enum indicating driver op
13712 *
13713 * Return: none
13714 */
13715void hdd_start_driver_ops_timer(int drv_op)
13716{
13717 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13718 switch (drv_op) {
13719 case eHDD_DRV_OP_PROBE:
13720 memcpy(drv_ops_string, "probe", sizeof("probe"));
13721 break;
13722 case eHDD_DRV_OP_REMOVE:
13723 memcpy(drv_ops_string, "remove", sizeof("remove"));
13724 break;
13725 case eHDD_DRV_OP_SHUTDOWN:
13726 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13727 break;
13728 case eHDD_DRV_OP_REINIT:
13729 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13730 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013731 case eHDD_DRV_OP_IFF_UP:
13732 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13733 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013734 }
13735
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013736 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013737 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13738 HDD_OPS_INACTIVITY_TIMEOUT);
13739}
13740
13741/**
13742 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13743 *
13744 * Return: none
13745 */
13746void hdd_stop_driver_ops_timer(void)
13747{
13748 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13749}
13750
13751/**
13752 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13753 * inactivity timer
13754 *
13755 * Return: None
13756 */
13757void hdd_drv_ops_inactivity_handler(void)
13758{
13759 hdd_err("%s: %d Sec timer expired while in .%s",
13760 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13761
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013762 if (hdd_drv_ops_task) {
13763 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13764 qdf_print_thread_trace(hdd_drv_ops_task);
13765 } else {
13766 hdd_err("hdd_drv_ops_task is null");
13767 }
13768
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013769 /* Driver shutdown is stuck, no recovery possible at this point */
13770 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13771 sizeof("shutdown")))
13772 QDF_BUG(0);
13773
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013774 if (cds_is_fw_down()) {
13775 hdd_err("FW is down");
13776 return;
13777 }
13778
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013779 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013780 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013781 else
13782 QDF_BUG(0);
13783}
13784
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013785void hdd_pld_ipa_uc_shutdown_pipes(void)
13786{
13787 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13788
13789 if (!hdd_ctx)
13790 return;
13791
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053013792 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013793}
13794
Yun Parkff6a16a2017-09-26 16:38:18 -070013795/**
13796 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13797 * @struct hdd_context *hdd_ctx
13798 * @struct hdd_adapter *padapter
13799 * @bool enble
13800 *
13801 * Return: none
13802 */
13803void hdd_set_rx_mode_rps(bool enable)
13804{
13805 struct cds_config_info *cds_cfg = cds_get_ini_config();
13806 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13807 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13808
13809 if (adapter && hdd_ctx &&
13810 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13811 if (enable && !cds_cfg->rps_enabled)
13812 hdd_send_rps_ind(adapter);
13813 else if (!enable && cds_cfg->rps_enabled)
13814 hdd_send_rps_disable_ind(adapter);
13815 }
13816}
13817
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053013818bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
13819{
13820 struct hdd_adapter *adapter = NULL;
13821
13822 hdd_for_each_adapter(hdd_ctx, adapter) {
13823 if ((adapter->device_mode == QDF_STA_MODE ||
13824 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
13825 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
13826 &adapter->event_flags)){
13827 return true;
13828 }
13829 }
13830
13831 return false;
13832}
13833
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013834/* Register the module init/exit functions */
13835module_init(hdd_module_init);
13836module_exit(hdd_module_exit);
13837
13838MODULE_LICENSE("Dual BSD/GPL");
13839MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13840MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13841
Srinivas Girigowda841da292018-02-21 16:33:00 -080013842static const struct kernel_param_ops con_mode_ops = {
13843 .set = con_mode_handler,
13844 .get = param_get_int,
13845};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013846
Srinivas Girigowda841da292018-02-21 16:33:00 -080013847static const struct kernel_param_ops con_mode_ftm_ops = {
13848 .set = con_mode_handler_ftm,
13849 .get = param_get_int,
13850};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013851
Srinivas Girigowda841da292018-02-21 16:33:00 -080013852static const struct kernel_param_ops con_mode_monitor_ops = {
13853 .set = con_mode_handler_monitor,
13854 .get = param_get_int,
13855};
Ravi Joshia307f632017-07-17 23:41:41 -070013856
Srinivas Girigowda841da292018-02-21 16:33:00 -080013857static const struct kernel_param_ops fwpath_ops = {
13858 .set = fwpath_changed_handler,
13859 .get = param_get_string,
13860};
13861
13862module_param_cb(con_mode, &con_mode_ops, &con_mode,
13863 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13864
13865module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
13866 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13867
13868module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
13869 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13870
13871module_param_cb(fwpath, &fwpath_ops, &fwpath,
13872 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013873
13874module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13875
13876module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13877
13878module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);