blob: c2279156abfd134308848c307e9abf340b5556f9 [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>
bings0e03a982018-05-09 08:40:59 +080059#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080060
61#include <net/addrconf.h>
62#include <linux/wireless.h>
63#include <net/cfg80211.h>
64#include <linux/inetdevice.h>
65#include <net/addrconf.h>
66#include "wlan_hdd_cfg80211.h"
67#include "wlan_hdd_ext_scan.h"
68#include "wlan_hdd_p2p.h"
69#include <linux/rtnetlink.h>
70#include "sap_api.h"
71#include <linux/semaphore.h>
72#include <linux/ctype.h>
73#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053074#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080075#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080076#include <soc/qcom/subsystem_restart.h>
77#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080078#include <wlan_hdd_hostapd.h>
79#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070080#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#include "cfg_api.h"
82#include "qwlan_version.h"
83#include "wma_types.h"
84#include "wlan_hdd_tdls.h"
85#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053086#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070088#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070089#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080090#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include "wlan_hdd_nan.h"
92#include "wlan_hdd_debugfs.h"
93#include "wlan_hdd_driver_ops.h"
94#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053095#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080096
97#include <wlan_hdd_ipa.h>
98#include "hif.h"
99#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800100#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700101#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530102#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700103#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700104#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530105#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700106#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530107#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800108#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800109#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530110#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800111#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800112#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530113#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530114#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800115#include "os_if_wifi_pos.h"
116#include "wifi_pos_api.h"
117#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800118#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700119#include "os_if_nan.h"
120#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700121#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800122#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700123#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530124#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530125#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700126#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800127#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530128#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800129#include "wlan_disa_obj_mgmt_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530130#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530131#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530132#include "wlan_hdd_nud_tracking.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530133
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530134#ifdef CNSS_GENL
135#include <net/cnss_nl.h>
136#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800137#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800138#include "wlan_ocb_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530139
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800140#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800141#ifdef MODULE
142#define WLAN_MODULE_NAME module_name(THIS_MODULE)
143#else
144#define WLAN_MODULE_NAME "wlan"
145#endif
146
147#ifdef TIMER_MANAGER
148#define TIMER_MANAGER_STR " +TIMER_MANAGER"
149#else
150#define TIMER_MANAGER_STR ""
151#endif
152
153#ifdef MEMORY_DEBUG
154#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
155#else
156#define MEMORY_DEBUG_STR ""
157#endif
158
Dustin Brownc1034df2018-02-07 14:51:32 -0800159#ifdef PANIC_ON_BUG
160#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
161#else
162#define PANIC_ON_BUG_STR ""
163#endif
164
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530165bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530166int wlan_start_ret_val;
167static DECLARE_COMPLETION(wlan_start_comp);
168static unsigned int dev_num = 1;
169static struct cdev wlan_hdd_state_cdev;
170static struct class *class;
171static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530172#ifndef MODULE
173static struct gwlan_loader *wlan_loader;
174static ssize_t wlan_boot_cb(struct kobject *kobj,
175 struct kobj_attribute *attr,
176 const char *buf, size_t count);
177struct gwlan_loader {
178 bool loaded_state;
179 struct kobject *boot_wlan_obj;
180 struct attribute_group *attr_group;
181};
182
183static struct kobj_attribute wlan_boot_attribute =
184 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
185
186static struct attribute *attrs[] = {
187 &wlan_boot_attribute.attr,
188 NULL,
189};
190
191#define MODULE_INITIALIZED 1
192#endif
193
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530194#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
195#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800196#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530197
198static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800199static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530200static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800202/* the Android framework expects this param even though we don't use it */
203#define BUF_LEN 20
204static char fwpath_buffer[BUF_LEN];
205static struct kparam_string fwpath = {
206 .string = fwpath_buffer,
207 .maxlen = BUF_LEN,
208};
209
210static char *country_code;
211static int enable_11d = -1;
212static int enable_dfs_chan_scan = -1;
213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800214/*
215 * spinlock for synchronizing asynchronous request/response
216 * (full description of use in wlan_hdd_main.h)
217 */
218DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530219DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800220
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800221#define WLAN_NLINK_CESIUM 30
222
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530223static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800224
225#define WOW_MAX_FILTER_LISTS 1
226#define WOW_MAX_FILTERS_PER_LIST 4
227#define WOW_MIN_PATTERN_SIZE 6
228#define WOW_MAX_PATTERN_SIZE 64
229
230#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
231static const struct wiphy_wowlan_support wowlan_support_reg_init = {
232 .flags = WIPHY_WOWLAN_ANY |
233 WIPHY_WOWLAN_MAGIC_PKT |
234 WIPHY_WOWLAN_DISCONNECT |
235 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
236 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
237 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
238 WIPHY_WOWLAN_4WAY_HANDSHAKE |
239 WIPHY_WOWLAN_RFKILL_RELEASE,
240 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
241 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
242 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
243};
244#endif
245
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700246static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
247 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
259 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
260 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
261 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
262 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
263 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700281 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700282 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700283 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530284 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800285 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530286 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700287};
288
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530289int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
290 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
291 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
292 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
293 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
294};
295
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530296struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530297struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800298
299struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800300#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700301static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800302#endif
303
Sachin Ahujadddd2632017-03-07 19:07:24 +0530304void hdd_start_complete(int ret)
305{
306 wlan_start_ret_val = ret;
307
308 complete(&wlan_start_comp);
309}
310
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800311/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530312 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700313 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530314 *
315 * Return: none
316 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700317static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530318{
Jeff Johnson9d295242017-08-29 14:39:48 -0700319 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530320
Dustin Brown920397d2017-12-13 16:27:50 -0800321 hdd_for_each_adapter(hdd_ctx, adapter)
322 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530323}
324
325/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800326 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
327 * @vdev_id: vdev_id
328 * @action: action type
329 * @reason: reason type
330 *
331 * Return: none
332 */
333void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
334 enum netif_action_type action, enum netif_reason_type reason)
335{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700336 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700337 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800338
339 if (!hdd_ctx) {
340 hdd_err("hdd ctx is NULL");
341 return;
342 }
343 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
344
345 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800346}
347
348/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700349 * Store WLAN driver version and timestamp info in global variables such that
350 * crash debugger can extract them from driver debug symbol and crashdump for
351 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800352 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800353#ifdef BUILD_TAG
354uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
355#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800356uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700357#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800358
359/**
360 * hdd_device_mode_to_string() - return string conversion of device mode
361 * @device_mode: device mode
362 *
363 * This utility function helps log string conversion of device mode.
364 *
365 * Return: string conversion of device mode, if match found;
366 * "Unknown" otherwise.
367 */
368const char *hdd_device_mode_to_string(uint8_t device_mode)
369{
370 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800371 CASE_RETURN_STRING(QDF_STA_MODE);
372 CASE_RETURN_STRING(QDF_SAP_MODE);
373 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
374 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
375 CASE_RETURN_STRING(QDF_FTM_MODE);
376 CASE_RETURN_STRING(QDF_IBSS_MODE);
377 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
378 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700379 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800380 default:
381 return "Unknown";
382 }
383}
384
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530385/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500386 * hdd_get_valid_chan() - return current chan list from regulatory.
387 * @hdd_ctx: HDD context
388 * @chan_list: buf hold returned chan list
389 * @chan_num: input buf size and output returned chan num
390 *
391 * This function helps get current available chan list from regulatory
392 * module. It excludes the "disabled" and "invalid" channels.
393 *
394 * Return: 0 for success.
395 */
396static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
397 uint8_t *chan_list,
398 uint32_t *chan_num)
399{
400 int i = 0, j = 0;
401 struct regulatory_channel *cur_chan_list;
402 struct wlan_objmgr_pdev *pdev;
403
404 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
405 return -EINVAL;
406
407 pdev = hdd_ctx->hdd_pdev;
408 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
409 sizeof(struct regulatory_channel));
410 if (!cur_chan_list)
411 return -ENOMEM;
412
413 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
414 QDF_STATUS_SUCCESS) {
415 qdf_mem_free(cur_chan_list);
416 return -EINVAL;
417 }
418
419 for (i = 0; i < NUM_CHANNELS; i++) {
420 uint32_t ch = cur_chan_list[i].chan_num;
421 enum channel_state state = wlan_reg_get_channel_state(pdev,
422 ch);
423
424 if (state != CHANNEL_STATE_DISABLE &&
425 state != CHANNEL_STATE_INVALID &&
426 j < *chan_num) {
427 chan_list[j] = (uint8_t)ch;
428 j++;
429 }
430 }
431 *chan_num = j;
432 qdf_mem_free(cur_chan_list);
433 return 0;
434}
435
436/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530437 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
438 * @adapter: HDD adapter
439 * @chan_number: Channel number
440 * @chan_bw: Bandwidth
441 *
442 * Checks if the given bandwidth is valid for the given channel number.
443 *
444 * Return: 0 for success, non-zero for failure
445 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700446int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530447 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800448 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530449{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500450 uint8_t chan[NUM_CHANNELS];
451 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530452 bool found = false;
453 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500454 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530455
456 hal = WLAN_HDD_GET_HAL_CTX(adapter);
457 if (!hal) {
458 hdd_err("Invalid HAL context");
459 return -EINVAL;
460 }
461
Liangwei Dong17bf2662018-01-05 02:02:05 -0500462 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
463 &len);
464 if (ret) {
465 hdd_err("error %d in getting valid channel list", ret);
466 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530467 }
468
469 for (i = 0; i < len; i++) {
470 if (chan[i] == chan_number) {
471 found = true;
472 break;
473 }
474 }
475
476 if (found == false) {
477 hdd_err("Channel not in driver's valid channel list");
478 return -EOPNOTSUPP;
479 }
480
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700481 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
482 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530483 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
484 return -EINVAL;
485 }
486
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700487 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530488 if (chan_bw == CH_WIDTH_80MHZ) {
489 hdd_err("BW80 not possible in 2.4GHz band");
490 return -EINVAL;
491 }
492 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
493 (chan_bw != CH_WIDTH_MAX)) {
494 hdd_err("Only BW20 possible on channel 14");
495 return -EINVAL;
496 }
497 }
498
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700499 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530500 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
501 (chan_bw != CH_WIDTH_MAX)) {
502 hdd_err("Only BW20 possible on channel 165");
503 return -EINVAL;
504 }
505 }
506
507 return 0;
508}
509
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530510/**
511 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
512 *
513 * Block the unloading of the driver (or) interface up until the
514 * cds recovery is completed
515 *
516 * Return: true for recovery completion else false
517 */
518static bool hdd_wait_for_recovery_completion(void)
519{
520 int retry = 0;
521
522 /* Wait for recovery to complete */
523 while (cds_is_driver_recovering()) {
524 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
525 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530526
527 if (g_is_system_reboot_triggered) {
528 hdd_info("System Reboot happening ignore unload!!");
529 return false;
530 }
531
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530532 msleep(1000);
533 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
534 hdd_err("SSR never completed, error");
535 /*
536 * Trigger the bug_on in the internal builds, in the
537 * customer builds self-recovery will be enabled
538 * in those cases just return error.
539 */
540 if (cds_is_self_recovery_enabled())
541 return false;
542 QDF_BUG(0);
543 }
544 }
545
546 hdd_info("Recovery completed successfully!");
547 return true;
548}
549
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800551static int __hdd_netdev_notifier_call(struct notifier_block *nb,
552 unsigned long state, void *data)
553{
554#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
555 struct netdev_notifier_info *dev_notif_info = data;
556 struct net_device *dev = dev_notif_info->dev;
557#else
558 struct net_device *dev = data;
559#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700560 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700561 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562
Dustin Brownfdf17c12018-03-14 12:55:34 -0700563 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800564
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800565 /* Make sure that this callback corresponds to our device. */
566 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
567 return NOTIFY_DONE;
568
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530569 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800570 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700571 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800572 return NOTIFY_DONE;
573 }
574
575 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700576 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800577 return NOTIFY_DONE;
578 }
579
580 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
581 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800582 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530583 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584 return NOTIFY_DONE;
585 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800586
587 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
588 hdd_err("%s: Driver module is closed", __func__);
589 return NOTIFY_DONE;
590 }
591
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530592 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800593 return NOTIFY_DONE;
594
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800595 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800596 dev->name, state);
597
598 switch (state) {
599 case NETDEV_REGISTER:
600 break;
601
602 case NETDEV_UNREGISTER:
603 break;
604
605 case NETDEV_UP:
606 sme_ch_avoid_update_req(hdd_ctx->hHal);
607 break;
608
609 case NETDEV_DOWN:
610 break;
611
612 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700613 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800614 complete(&adapter->linkup_event_var);
615 break;
616
617 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700618 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
619 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530620 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700621 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800622 } else {
hqueaa33ee2017-05-04 17:56:35 +0800623 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800624 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800625 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530626 /*
627 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
628 * of return status of hdd_stop call, kernel resets the IFF_UP
629 * flag after which driver does not send the cfg80211_scan_done.
630 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
631 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530632 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800633 break;
634
635 default:
636 break;
637 }
638
639 return NOTIFY_DONE;
640}
641
642/**
643 * hdd_netdev_notifier_call() - netdev notifier callback function
644 * @nb: pointer to notifier block
645 * @state: state
646 * @ndev: ndev pointer
647 *
648 * Return: 0 on success, error number otherwise.
649 */
650static int hdd_netdev_notifier_call(struct notifier_block *nb,
651 unsigned long state,
652 void *ndev)
653{
654 int ret;
655
656 cds_ssr_protect(__func__);
657 ret = __hdd_netdev_notifier_call(nb, state, ndev);
658 cds_ssr_unprotect(__func__);
659
660 return ret;
661}
662
663struct notifier_block hdd_netdev_notifier = {
664 .notifier_call = hdd_netdev_notifier_call,
665};
666
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530667static int system_reboot_notifier_call(struct notifier_block *nb,
668 unsigned long msg_type, void *_unused)
669{
670 switch (msg_type) {
671 case SYS_DOWN:
672 case SYS_HALT:
673 case SYS_POWER_OFF:
674 g_is_system_reboot_triggered = true;
675 hdd_info("reboot, reason: %ld", msg_type);
676 break;
677 default:
678 break;
679 }
680
681 return NOTIFY_OK;
682}
683
684struct notifier_block system_reboot_notifier = {
685 .notifier_call = system_reboot_notifier_call,
686};
687
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800688/* variable to hold the insmod parameters */
689static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800690
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530691static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700692int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530693
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800694/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800695static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800696
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530697/**
698 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
699 * @ch_width: NL channel width
700 *
701 * Converts the NL channel width to the driver's internal representation
702 *
703 * Return: Converted channel width. In case of non matching NL channel width,
704 * CH_WIDTH_MAX will be returned.
705 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800706enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530707{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800708 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700709
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800710 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530711 switch (ch_width) {
712 case NL80211_CHAN_WIDTH_20_NOHT:
713 case NL80211_CHAN_WIDTH_20:
714 return CH_WIDTH_20MHZ;
715 case NL80211_CHAN_WIDTH_40:
716 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530717 case NL80211_CHAN_WIDTH_80:
718 return CH_WIDTH_80MHZ;
719 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800720 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
721 return CH_WIDTH_80P80MHZ;
722 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
723 return CH_WIDTH_160MHZ;
724 else
725 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530726 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800727 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
728 return CH_WIDTH_160MHZ;
729 else
730 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530731 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800732 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530733 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800734 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530735 default:
736 hdd_err("Invalid channel width %d, setting to default",
737 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800738 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530739 }
740}
741
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530742/* wlan_hdd_find_opclass() - Find operating class for a channel
743 * @hal: handler to HAL
744 * @channel: channel id
745 * @bw_offset: bandwidth offset
746 *
747 * Function invokes sme api to find the operating class
748 *
749 * Return: operating class
750 */
751uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
752 uint8_t bw_offset)
753{
754 uint8_t opclass = 0;
755
756 sme_get_opclass(hal, channel, bw_offset, &opclass);
757 return opclass;
758}
759
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800760/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530761 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530762 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800763 * @bitmask: Bitmask of log levels to be enabled
764 *
765 * Called immediately after the cfg.ini is read in order to configure
766 * the desired trace levels.
767 *
768 * Return: None
769 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530770int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530772 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530773 int qdf_print_idx = -1;
774 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 /*
776 * if the bitmask is the default value, then a bitmask was not
777 * specified in cfg.ini, so leave the logging level alone (it
778 * will remain at the "compiled in" default value)
779 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700780 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530781 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530783 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800784
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530785 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530786 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530787 QDF_TRACE_LEVEL_NONE, 0);
788
789 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530790 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530792 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793 while (0 != bitmask) {
794 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530795 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530796 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530797 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530798 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800799 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700800
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800801 level++;
802 bitmask >>= 1;
803 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530804 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805}
806
807/**
Chris Guo1751acf2017-07-03 14:09:01 +0800808 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
809 * @hdd_ctx: HDD context pointer
810 *
811 * Return: 0 if the context is valid. Error code otherwise
812 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700813int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800814{
815 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
816 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
817 return -ENODEV;
818 }
819
820 if (cds_is_driver_recovering()) {
821 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
822 (void *)_RET_IP_, cds_get_driver_state());
823 return -EAGAIN;
824 }
825
826 if (hdd_ctx->start_modules_in_progress ||
827 hdd_ctx->stop_modules_in_progress) {
828 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
829 (void *)_RET_IP_);
830 return -EAGAIN;
831 }
832
833 return 0;
834}
835
836
837/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838 * wlan_hdd_validate_context() - check the HDD context
839 * @hdd_ctx: HDD context pointer
840 *
841 * Return: 0 if the context is valid. Error code otherwise
842 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700843int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530846 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 return -ENODEV;
848 }
849
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800850 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800851 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530852 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 return -EAGAIN;
854 }
855
Yue Ma9f275d92017-09-14 16:58:41 -0700856 if (cds_is_load_or_unload_in_progress()) {
857 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
858 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700860 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530861
862 if (hdd_ctx->start_modules_in_progress ||
863 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800864 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530865 (void *)_RET_IP_);
866 return -EAGAIN;
867 }
868
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530869 if (cds_is_driver_in_bad_state()) {
870 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
871 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530872 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530873 }
874
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530875 if (cds_is_fw_down()) {
876 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
877 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530878 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530879 }
880
Liangwei Dong858feb12018-05-21 01:52:46 -0400881 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
882 hdd_debug("con_mode_handler is in progress Ignore!!!");
883 return -EAGAIN;
884 }
885
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 return 0;
887}
888
Jeff Johnson9d295242017-08-29 14:39:48 -0700889int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700890{
891 if (!adapter) {
892 hdd_err("adapter is null");
893 return -EINVAL;
894 }
895
896 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
897 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
898 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
899 return -EINVAL;
900 }
901
902 if (!adapter->dev) {
903 hdd_err("adapter net_device is null");
904 return -EINVAL;
905 }
906
907 if (!(adapter->dev->flags & IFF_UP)) {
908 hdd_info("adapter net_device is not up");
909 return -EAGAIN;
910 }
911
Jeff Johnson1b780e42017-10-31 14:11:45 -0700912 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700913 hdd_info("adapter session is not open");
914 return -EAGAIN;
915 }
916
Jeff Johnson1b780e42017-10-31 14:11:45 -0700917 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
918 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700919 return -EINVAL;
920 }
921
922 return 0;
923}
924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530926 * wlan_hdd_validate_modules_state() - Check modules status
927 * @hdd_ctx: HDD context pointer
928 *
929 * Check's the driver module's state and returns true if the
930 * modules are enabled returns false if modules are closed.
931 *
932 * Return: True if modules are enabled or false.
933 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700934bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530935{
936 mutex_lock(&hdd_ctx->iface_change_lock);
937 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
938 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700939 hdd_info("Modules not enabled, Present status: %d",
940 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530941 return false;
942 }
943 mutex_unlock(&hdd_ctx->iface_change_lock);
944 return true;
945}
946
947/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700949 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 *
951 * This function sets the IBSS power save config parameters to WMA
952 * which will send it to firmware if FW supports IBSS power save
953 * before vdev start.
954 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530955 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 * on failure.
957 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700958QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959{
960 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700961 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800962
963 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700964 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530965 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800966 }
967
Jeff Johnson1b780e42017-10-31 14:11:45 -0700968 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
970 hdd_ctx->config->ibssATIMWinSize,
971 VDEV_CMD);
972 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700973 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530974 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800975 }
976
Jeff Johnson1b780e42017-10-31 14:11:45 -0700977 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800978 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
979 hdd_ctx->config->isIbssPowerSaveAllowed,
980 VDEV_CMD);
981 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700982 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
983 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530984 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800985 }
986
Jeff Johnson1b780e42017-10-31 14:11:45 -0700987 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
989 hdd_ctx->config->
990 isIbssPowerCollapseAllowed, VDEV_CMD);
991 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700992 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
993 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530994 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800995 }
996
Jeff Johnson1b780e42017-10-31 14:11:45 -0700997 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
999 hdd_ctx->config->isIbssAwakeOnTxRx,
1000 VDEV_CMD);
1001 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001002 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301003 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001004 }
1005
Jeff Johnson1b780e42017-10-31 14:11:45 -07001006 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001007 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1008 hdd_ctx->config->ibssInactivityCount,
1009 VDEV_CMD);
1010 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001011 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301012 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013 }
1014
Jeff Johnson1b780e42017-10-31 14:11:45 -07001015 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001016 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1017 hdd_ctx->config->ibssTxSpEndInactivityTime,
1018 VDEV_CMD);
1019 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001020 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
1021 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301022 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001023 }
1024
Jeff Johnson1b780e42017-10-31 14:11:45 -07001025 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1027 hdd_ctx->config->ibssPsWarmupTime,
1028 VDEV_CMD);
1029 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001030 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
1031 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301032 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001033 }
1034
Jeff Johnson1b780e42017-10-31 14:11:45 -07001035 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1037 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1038 VDEV_CMD);
1039 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001040 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1041 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301042 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001043 }
1044
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301045 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046}
1047
Yue Macd359b72017-10-03 15:21:00 -07001048#ifdef FEATURE_RUNTIME_PM
1049/**
1050 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1051 * @hdd_ctx: HDD context
1052 *
1053 * Return: None
1054 */
1055static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1056{
1057 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1058
Yue Macd359b72017-10-03 15:21:00 -07001059 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001060 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001061
1062 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1063}
1064
1065/**
1066 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1067 * @hdd_ctx: HDD Context
1068 *
1069 * Return: None
1070 */
1071static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1072{
1073 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1074
Yue Macd359b72017-10-03 15:21:00 -07001075 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001076 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001077
1078 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1079}
1080
Yue Macd359b72017-10-03 15:21:00 -07001081#else /* FEATURE_RUNTIME_PM */
1082static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1083static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001084#endif /* FEATURE_RUNTIME_PM */
1085
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001086#define INTF_MACADDR_MASK 0x7
1087
1088/**
1089 * hdd_update_macaddr() - update mac address
1090 * @config: hdd configuration
1091 * @hw_macaddr: mac address
1092 *
1093 * Mac address for multiple virtual interface is found as following
1094 * i) The mac address of the first interface is just the actual hw mac address.
1095 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1096 * define the mac address for the remaining interfaces and locally
1097 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1098 * supported virtual interfaces, right now this is 0x07 (meaning 8
1099 * interface).
1100 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1101 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1102 *
1103 * Return: None
1104 */
1105void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301106 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001107{
1108 int8_t i;
1109 uint8_t macaddr_b3, tmp_br3;
1110
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301111 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301112 QDF_MAC_ADDR_SIZE);
1113 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301114 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301115 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001116 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1117 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1118 INTF_MACADDR_MASK;
1119 macaddr_b3 += tmp_br3;
1120
1121 /* XOR-ing bit-24 of the mac address. This will give enough
1122 * mac address range before collision
1123 */
1124 macaddr_b3 ^= (1 << 7);
1125
1126 /* Set locally administered bit */
1127 config->intfMacAddr[i].bytes[0] |= 0x02;
1128 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001129 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001130 MAC_ADDRESS_STR, i,
1131 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1132 }
1133}
1134
Kabilan Kannan44a58372017-12-06 18:16:11 -08001135static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1136{
1137 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1138 struct tdls_start_params tdls_cfg;
1139 struct tdls_user_config *config = &tdls_cfg.config;
1140 struct hdd_config *cfg = hdd_ctx->config;
1141 QDF_STATUS status;
1142
1143 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1144 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1145 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1146 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1147 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1148 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1149 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1150 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1151 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1152 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1153 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1154 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1155 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1156 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1157 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1158 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1159 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1160 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1161 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1162 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1163 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1164 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1165 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1166 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1167 (cfg->fEnableTDLSImplicitTrigger ?
1168 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1169 (cfg->fTDLSExternalControl ?
1170 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1171 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1172 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1173
1174 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1175 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1176 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1177 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1178 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1179 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1180 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1181 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001182 tdls_cfg.tdls_peer_context = hdd_ctx;
1183 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1184 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001185 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1186 tdls_cfg.tdls_wmm_cb_data = psoc;
1187 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1188 tdls_cfg.tdls_rx_cb_data = psoc;
1189 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1190
1191 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1192 if (status != QDF_STATUS_SUCCESS) {
1193 hdd_err("failed pmo psoc configuration");
1194 return -EINVAL;
1195 }
1196
1197 hdd_ctx->tdls_umac_comp_active = true;
1198 /* enable napier specific tdls data path */
1199 hdd_ctx->tdls_nap_active = true;
1200
1201 return 0;
1202}
1203
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001204static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001205 struct wma_tgt_services *cfg)
1206{
1207 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001208
1209 /* Set up UAPSD */
1210 config->apUapsdEnabled &= cfg->uapsd;
1211
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001212 /* 11AX mode support */
1213 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1214 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1215 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1216
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001217 /* 11AC mode support */
1218 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1219 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1220 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001221
1222 /* ARP offload: override user setting if invalid */
1223 config->fhostArpOffload &= cfg->arp_offload;
1224
1225#ifdef FEATURE_WLAN_SCAN_PNO
1226 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001227 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001228 if (cfg->pno_offload)
1229 config->PnoOffload = true;
1230#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001231#ifdef FEATURE_WLAN_TDLS
1232 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301233 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1234 cfg->en_tdls_offchan;
1235 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1236 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001237 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001238 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001239 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1243 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1244#endif
Will Huang496b36c2017-07-11 16:38:50 +08001245 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001246 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001247 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001248 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249
1250}
1251
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001252/**
1253 * hdd_update_vdev_nss() - sets the vdev nss
1254 * @hdd_ctx: HDD context
1255 *
1256 * Sets the Nss per vdev type based on INI
1257 *
1258 * Return: None
1259 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001260static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001261{
1262 struct hdd_config *cfg_ini = hdd_ctx->config;
1263 uint8_t max_supp_nss = 1;
1264
Naveen Rawat10b1c152017-01-18 11:16:06 -08001265 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001266 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001267 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1268 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1269 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001270
1271 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001272 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001273
1274 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001275 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001276}
1277
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301278/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301279 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1280 * @hdd_ctx: HDD context
1281 *
1282 * Updates wiphy vhtcap fields
1283 *
1284 * Return: None
1285 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001286static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301287{
1288 struct ieee80211_supported_band *band_5g =
1289 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1290 uint32_t val;
1291
1292 if (!band_5g) {
1293 hdd_debug("5GHz band disabled, skipping capability population");
1294 return;
1295 }
1296
1297 val = hdd_ctx->config->txBFCsnValue;
1298 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1299
1300 val = NUM_OF_SOUNDING_DIMENSIONS;
1301 band_5g->vht_cap.cap |=
1302 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1303
1304 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1305 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1306}
1307
1308/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301309 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1310 * @hdd_ctx: HDD context
1311 *
1312 * Sets the DBS capability as per INI and firmware capability
1313 *
1314 * Return: None
1315 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001316static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301317{
1318 struct hdd_config *cfg_ini = hdd_ctx->config;
1319 uint8_t hw_dbs_capable = 0;
1320
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001321 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1322 ((cfg_ini->dual_mac_feature_disable ==
1323 ENABLE_DBS_CXN_AND_SCAN) ||
1324 (cfg_ini->dual_mac_feature_disable ==
1325 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301326 hw_dbs_capable = 1;
1327
1328 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1329}
1330
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001331static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001332 struct wma_tgt_ht_cap *cfg)
1333{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301334 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001335 uint32_t value, val32;
1336 uint16_t val16;
1337 struct hdd_config *pconfig = hdd_ctx->config;
1338 tSirMacHTCapabilityInfo *phtCapInfo;
1339 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1340 uint8_t enable_tx_stbc;
1341
1342 /* check and update RX STBC */
1343 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1344 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1345
1346 /* get the MPDU density */
1347 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1348
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301349 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001350 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 value = 0;
1352 }
1353
1354 /*
1355 * MPDU density:
1356 * override user's setting if value is larger
1357 * than the one supported by target
1358 */
1359 if (value > cfg->mpdu_density) {
1360 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1361 cfg->mpdu_density);
1362
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301363 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001364 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 }
1366
1367 /* get the HT capability info */
1368 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301369 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001370 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001371 return;
1372 }
1373 val16 = (uint16_t) val32;
1374 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1375
1376 /* Set the LDPC capability */
1377 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1378
1379 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1380 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1381
1382 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1383 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1384
1385 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1386 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1387
1388 enable_tx_stbc = pconfig->enableTxSTBC;
1389
1390 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1391 pconfig->enable2x2 = 1;
1392 } else {
1393 pconfig->enable2x2 = 0;
1394 enable_tx_stbc = 0;
1395
1396 /* 1x1 */
1397 /* Update Rx Highest Long GI data Rate */
1398 if (sme_cfg_set_int(hdd_ctx->hHal,
1399 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001400 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301401 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001402 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 }
1404
1405 /* Update Tx Highest Long GI data Rate */
1406 if (sme_cfg_set_int
1407 (hdd_ctx->hHal,
1408 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001409 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301410 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001411 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001412 }
1413 }
1414 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1415 enable_tx_stbc = 0;
1416 phtCapInfo->txSTBC = enable_tx_stbc;
1417
1418 val32 = val16;
1419 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301420 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001421 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001422#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1423 value = SIZE_OF_SUPPORTED_MCS_SET;
1424 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301425 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001426 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301427 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1428 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001429 if (pconfig->enable2x2) {
1430 for (value = 0; value < cfg->num_rf_chains; value++)
1431 mcs_set[value] =
1432 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1433
1434 status =
1435 sme_cfg_set_str(hdd_ctx->hHal,
1436 WNI_CFG_SUPPORTED_MCS_SET,
1437 mcs_set,
1438 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301439 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001440 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 }
1442 }
1443#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1444}
1445
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001446static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001447 struct wma_tgt_vht_cap *cfg)
1448{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301449 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450 uint32_t value = 0;
1451 struct hdd_config *pconfig = hdd_ctx->config;
1452 struct wiphy *wiphy = hdd_ctx->wiphy;
1453 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001454 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001455 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001456 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001457 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001458 struct wma_caps_per_phy caps_per_phy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459
Dustin Brown5e06bd32016-10-04 12:49:10 -07001460 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001461 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001462 return;
1463 }
1464
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001465 /* Get the current MPDU length */
1466 status =
1467 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1468 &value);
1469
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301470 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001471 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001472 value = 0;
1473 }
1474
1475 /*
1476 * VHT max MPDU length:
1477 * override if user configured value is too high
1478 * that the target cannot support
1479 */
1480 if (value > cfg->vht_max_mpdu) {
1481 status = sme_cfg_set_int(hdd_ctx->hHal,
1482 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1483 cfg->vht_max_mpdu);
1484
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001485 if (status == QDF_STATUS_E_FAILURE)
1486 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001487 }
1488
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001489 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1490 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1491
1492 if (pconfig->enable2x2)
1493 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1494
1495 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1496 QDF_STATUS_E_FAILURE) {
1497 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1498 }
1499
1500 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1501 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1502 if (pconfig->enable2x2)
1503 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1504
1505 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1506 QDF_STATUS_E_FAILURE) {
1507 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1508 }
1509
1510 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1511 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1512 if (pconfig->enable2x2)
1513 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1514
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001515 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001516 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1517
1518 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1519 QDF_STATUS_E_FAILURE) {
1520 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1521 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001522 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001523 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001524 &value);
1525
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301526 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001527 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001528 value = 0;
1529 }
1530
jiad4a7a33c2017-08-08 15:32:24 +08001531 /* Set HW RX LDPC capability */
1532 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1533 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001534 status = sme_cfg_set_int(hdd_ctx->hHal,
1535 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001536 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001537
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001538 if (status == QDF_STATUS_E_FAILURE)
1539 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001540 }
1541
1542 /* Get current GI 80 value */
1543 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1544 &value);
1545
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301546 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001547 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001548 value = 0;
1549 }
1550
1551 /* set the Guard interval 80MHz */
1552 if (value && !cfg->vht_short_gi_80) {
1553 status = sme_cfg_set_int(hdd_ctx->hHal,
1554 WNI_CFG_VHT_SHORT_GI_80MHZ,
1555 cfg->vht_short_gi_80);
1556
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001557 if (status == QDF_STATUS_E_FAILURE)
1558 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001559 }
1560
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001561 /* Get VHT TX STBC cap */
1562 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1563
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301564 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001565 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001566 value = 0;
1567 }
1568
1569 /* VHT TX STBC cap */
1570 if (value && !cfg->vht_tx_stbc) {
1571 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1572 cfg->vht_tx_stbc);
1573
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001574 if (status == QDF_STATUS_E_FAILURE)
1575 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001576 }
1577
1578 /* Get VHT RX STBC cap */
1579 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1580
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301581 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001582 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001583 value = 0;
1584 }
1585
1586 /* VHT RX STBC cap */
1587 if (value && !cfg->vht_rx_stbc) {
1588 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1589 cfg->vht_rx_stbc);
1590
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001591 if (status == QDF_STATUS_E_FAILURE)
1592 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593 }
1594
1595 /* Get VHT SU Beamformer cap */
1596 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1597 &value);
1598
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301599 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001600 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001601 value = 0;
1602 }
1603
1604 /* set VHT SU Beamformer cap */
1605 if (value && !cfg->vht_su_bformer) {
1606 status = sme_cfg_set_int(hdd_ctx->hHal,
1607 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1608 cfg->vht_su_bformer);
1609
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001610 if (status == QDF_STATUS_E_FAILURE)
1611 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 }
1613
1614 /* check and update SU BEAMFORMEE capabality */
1615 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1616 pconfig->enableTxBF = cfg->vht_su_bformee;
1617
1618 status = sme_cfg_set_int(hdd_ctx->hHal,
1619 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1620 pconfig->enableTxBF);
1621
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001622 if (status == QDF_STATUS_E_FAILURE)
1623 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001624
1625 /* Get VHT MU Beamformer cap */
1626 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1627 &value);
1628
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301629 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001630 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 value = 0;
1632 }
1633
1634 /* set VHT MU Beamformer cap */
1635 if (value && !cfg->vht_mu_bformer) {
1636 status = sme_cfg_set_int(hdd_ctx->hHal,
1637 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1638 cfg->vht_mu_bformer);
1639
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001640 if (status == QDF_STATUS_E_FAILURE)
1641 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642 }
1643
1644 /* Get VHT MU Beamformee cap */
1645 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1646 &value);
1647
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301648 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001649 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001650 value = 0;
1651 }
1652
1653 /* set VHT MU Beamformee cap */
1654 if (value && !cfg->vht_mu_bformee) {
1655 status = sme_cfg_set_int(hdd_ctx->hHal,
1656 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1657 cfg->vht_mu_bformee);
1658
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001659 if (status == QDF_STATUS_E_FAILURE)
1660 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001661 }
1662
1663 /* Get VHT MAX AMPDU Len exp */
1664 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1665 &value);
1666
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301667 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001668 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001669 value = 0;
1670 }
1671
1672 /*
1673 * VHT max AMPDU len exp:
1674 * override if user configured value is too high
1675 * that the target cannot support.
1676 * Even though Rome publish ampdu_len=7, it can
1677 * only support 4 because of some h/w bug.
1678 */
1679
1680 if (value > cfg->vht_max_ampdu_len_exp) {
1681 status = sme_cfg_set_int(hdd_ctx->hHal,
1682 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1683 cfg->vht_max_ampdu_len_exp);
1684
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001685 if (status == QDF_STATUS_E_FAILURE)
1686 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001687 }
1688
1689 /* Get VHT TXOP PS CAP */
1690 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1691
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301692 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001693 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 value = 0;
1695 }
1696
1697 /* set VHT TXOP PS cap */
1698 if (value && !cfg->vht_txop_ps) {
1699 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1700 cfg->vht_txop_ps);
1701
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001702 if (status == QDF_STATUS_E_FAILURE)
1703 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704 }
1705
1706 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1707 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1708 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1709 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1710 else
1711 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1712
1713
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001714 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1715 status = sme_cfg_set_int(hdd_ctx->hHal,
1716 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1717 VHT_CAP_160_AND_80P80_SUPP);
1718 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001719 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001720 band_5g->vht_cap.cap |=
1721 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001722 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1723 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1724 status = sme_cfg_set_int(hdd_ctx->hHal,
1725 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1726 VHT_CAP_160_SUPP);
1727 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001728 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729 band_5g->vht_cap.cap |=
1730 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001731 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1732 }
1733 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1734 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301735 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001736 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301737 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001738 &value);
1739 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301740 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001741 value = 0;
1742 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301743 /* set the Guard interval 160MHz */
1744 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001745 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301746 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1747 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001748
1749 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301750 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001751 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001752
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001753 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001754 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001755 hdd_debug("VHT RxLDPC capability is set");
1756 } else {
1757 /*
1758 * Get the RX LDPC capability for the NON DBS
1759 * hardware mode for 5G band
1760 */
1761 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1762 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1763 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1764 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1765 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1766 hdd_debug("VHT RX LDPC capability is set");
1767 }
1768 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001769
1770 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1771 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1772 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1773 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1774
1775 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1776 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1777
1778 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1779 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1780 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1781 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1782 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1783 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1784
1785 band_5g->vht_cap.cap |=
1786 (cfg->vht_max_ampdu_len_exp <<
1787 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1788
1789 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1790 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1791 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1792 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1793 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1794 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1795 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1796 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1797
1798 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1799 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1800
1801}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001802
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001803/**
1804 * hdd_generate_macaddr_auto() - Auto-generate mac address
1805 * @hdd_ctx: Pointer to the HDD context
1806 *
1807 * Auto-generate mac address using device serial number.
1808 * Keep the first 3 bytes of OUI as before and replace
1809 * the last 3 bytes with the lower 3 bytes of serial number.
1810 *
1811 * Return: 0 for success
1812 * Non zero failure code for errors
1813 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001814static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001815{
1816 unsigned int serialno = 0;
1817 struct qdf_mac_addr mac_addr = {
1818 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1819 };
1820
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001821 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001822 if (serialno == 0)
1823 return -EINVAL;
1824
1825 serialno &= 0x00ffffff;
1826
1827 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1828 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1829 mac_addr.bytes[5] = serialno & 0xff;
1830
1831 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1832 return 0;
1833}
1834
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301835/**
1836 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1837 * configuration to cfg_ini in HDD
1838 * @hdd_ctx: Pointer to hdd_ctx
1839 * @cfg: target configuration
1840 *
1841 * Return: None
1842 */
1843#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001844static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301845 struct wma_tgt_cfg *cfg)
1846{
1847 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1848}
1849#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001850static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301851 struct wma_tgt_cfg *cfg)
1852{
1853}
1854#endif
1855
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856void hdd_update_tgt_cfg(void *context, void *param)
1857{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001858 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001859 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001860 struct wma_tgt_cfg *cfg = param;
1861 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001862 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301863 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001864 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301865
Dustin Brownbd68fe12017-11-21 15:28:52 -08001866 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1867 if (ret) {
1868 hdd_err("Failed to create pdev; errno:%d", ret);
1869 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001870 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001871 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001872 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001873 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1874 hdd_err("dispatcher pdev open failed");
1875 QDF_BUG(0);
1876 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301877 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001878
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001879 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301880
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301881 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1882 cds_get_context(QDF_MODULE_ID_SOC));
1883 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1884 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301885 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1886 hdd_softap_hard_start_xmit);
1887 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1888 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301889
Naveen Rawat64e477e2016-05-20 10:34:56 -07001890 if (cds_cfg) {
1891 if (hdd_ctx->config->enable_sub_20_channel_width !=
1892 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1893 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1894 cds_cfg->sub_20_channel_width =
1895 WLAN_SUB_20_CH_WIDTH_NONE;
1896 } else {
1897 cds_cfg->sub_20_channel_width =
1898 hdd_ctx->config->enable_sub_20_channel_width;
1899 }
1900 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001901
1902 /* first store the INI band capability */
1903 temp_band_cap = hdd_ctx->config->nBandCapability;
1904
1905 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301906 hdd_ctx->is_fils_roaming_supported =
1907 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001908
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301909 hdd_ctx->config->is_11k_offload_supported =
1910 cfg->services.is_11k_offload_supported;
1911
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001912 /*
1913 * now overwrite the target band capability with INI
1914 * setting if INI setting is a subset
1915 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001916
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001917 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1918 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001919 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001920 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1921 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001922 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001923 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001924 }
1925
Amar Singhal58b45ef2017-08-01 13:43:54 -07001926 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1927
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301928 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001929 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1930 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1931 }
1932
1933 /* This can be extended to other configurations like ht, vht cap... */
1934
Anurag Chouhanc5548422016-02-24 18:33:27 +05301935 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001936 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001937 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001938 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001939 static struct qdf_mac_addr default_mac_addr = {
1940 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1941 };
1942 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1943 &default_mac_addr)) {
1944 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1945 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1946 MAC_ADDRESS_STR,
1947 MAC_ADDR_ARRAY(hdd_ctx->config->
1948 intfMacAddr[0].bytes));
1949 } else {
1950 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1951 MAC_ADDRESS_STR,
1952 MAC_ADDR_ARRAY(hdd_ctx->config->
1953 intfMacAddr[0].bytes));
1954 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001955 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001956 }
1957
1958 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001959 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001960
Ryan Hsuc6918552018-05-16 13:29:59 -07001961 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
1962 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
1963 sizeof(cfg->hw_bd_info));
1964
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001965 hdd_ctx->max_intf_count = cfg->max_intf_count;
1966
Jeff Johnsonc875e242016-09-23 18:12:34 -07001967 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001968
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001969 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1970 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1971
1972 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1973
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001974 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001975 if (cfg->services.en_11ax) {
1976 hdd_info("11AX: 11ax is enabled - update HDD config");
1977 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1978 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001979
1980 hdd_update_vdev_nss(hdd_ctx);
1981
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301982 hdd_update_hw_dbs_capable(hdd_ctx);
1983
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001984 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001985 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001986 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001987 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001988
Nitesh Shahe50711f2017-04-26 16:30:45 +05301989 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1990 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1991 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001992 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001993 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001994
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001995 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1996 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301997 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301998 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301999
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302000 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08002001 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
2002 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302003 hdd_ctx->config->txBFCsnValue =
2004 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
2005
Arif Hussainee10f902017-12-27 16:30:17 -08002006 status = sme_cfg_set_int(hdd_ctx->hHal,
2007 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
2008 hdd_ctx->config->txBFCsnValue);
2009 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302010 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2011
2012
2013 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002014 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
2015 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302016
2017 /*
2018 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2019 */
2020 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302021
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302022 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2023
Yue Macd359b72017-10-03 15:21:00 -07002024 /*
2025 * This needs to be done after HDD pdev is created and stored since
2026 * it will access the HDD pdev object lock.
2027 */
2028 hdd_runtime_suspend_context_init(hdd_ctx);
2029
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002030 /* Configure NAN datapath features */
2031 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002032 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002033 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002034 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2035 cfg->obss_detection_offloaded);
2036 if (QDF_IS_STATUS_ERROR(status))
2037 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002038
2039 status = sme_cfg_set_int(hdd_ctx->hHal,
2040 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2041 cfg->obss_color_collision_offloaded);
2042 if (QDF_IS_STATUS_ERROR(status))
2043 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044}
2045
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002046bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002047{
Jeff Johnson9d295242017-08-29 14:39:48 -07002048 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002049 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002050
Jiachao Wuf610d912018-01-23 17:47:32 +08002051 if (!hdd_ctx) {
2052 hdd_info("Couldn't get hdd_ctx");
2053 return true;
2054 }
2055
2056 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002057 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002058 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302059 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002060 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002061
Dustin Brown920397d2017-12-13 16:27:50 -08002062 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002063 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2064
2065 if ((QDF_SAP_MODE == adapter->device_mode ||
2066 QDF_P2P_GO_MODE == adapter->device_mode) &&
bings0e03a982018-05-09 08:40:59 +08002067 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002068 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002069 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2070 true;
2071 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002072 adapter->session_id);
bings0e03a982018-05-09 08:40:59 +08002073 cdp_fc_vdev_flush(cds_get_context(QDF_MODULE_ID_SOC),
2074 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302075 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002076 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302077
2078 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002079}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002080
2081/**
2082 * hdd_is_valid_mac_address() - validate MAC address
2083 * @pMacAddr: Pointer to the input MAC address
2084 *
2085 * This function validates whether the given MAC address is valid or not
2086 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2087 * where X is the hexa decimal digit character and separated by ':'
2088 * This algorithm works even if MAC address is not separated by ':'
2089 *
2090 * This code checks given input string mac contains exactly 12 hexadecimal
2091 * digits and a separator colon : appears in the input string only after
2092 * an even number of hex digits.
2093 *
2094 * Return: 1 for valid and 0 for invalid
2095 */
2096bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2097{
2098 int xdigit = 0;
2099 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002101 while (*pMacAddr) {
2102 if (isxdigit(*pMacAddr)) {
2103 xdigit++;
2104 } else if (':' == *pMacAddr) {
2105 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2106 break;
2107
2108 ++separator;
2109 } else {
2110 /* Invalid MAC found */
2111 return 0;
2112 }
2113 ++pMacAddr;
2114 }
2115 return xdigit == 12 && (separator == 5 || separator == 0);
2116}
2117
2118/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302119 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2120 * @dev: Handle to struct net_device to be updated.
2121 *
2122 * Return: None
2123 */
2124static void hdd_mon_mode_ether_setup(struct net_device *dev)
2125{
2126 dev->header_ops = NULL;
2127 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2128 dev->hard_header_len = ETH_HLEN;
2129 dev->mtu = ETH_DATA_LEN;
2130 dev->addr_len = ETH_ALEN;
2131 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2132 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2133 dev->priv_flags |= IFF_TX_SKB_SHARING;
2134
2135 memset(dev->broadcast, 0xFF, ETH_ALEN);
2136}
2137
2138/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002139 * __hdd__mon_open() - HDD Open function
2140 * @dev: Pointer to net_device structure
2141 *
2142 * This is called in response to ifconfig up
2143 *
2144 * Return: 0 for success; non-zero for failure
2145 */
2146static int __hdd_mon_open(struct net_device *dev)
2147{
2148 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002149 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2150 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002151
Dustin Brownfdf17c12018-03-14 12:55:34 -07002152 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002153
2154 ret = wlan_hdd_validate_context(hdd_ctx);
2155 if (ret)
2156 return ret;
2157
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302158 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002159
2160 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002161 ret = hdd_wlan_start_modules(hdd_ctx, false);
Ravi Joshia307f632017-07-17 23:41:41 -07002162 if (ret) {
2163 hdd_err("Failed to start WLAN modules return");
2164 return ret;
2165 }
2166 hdd_err("hdd_wlan_start_modules() successful !");
2167
2168 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2169 ret = hdd_start_adapter(adapter);
2170 if (ret) {
2171 hdd_err("Failed to start adapter :%d",
2172 adapter->device_mode);
2173 return ret;
2174 }
2175 hdd_err("hdd_start_adapters() successful !");
2176 }
2177 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2178 }
2179
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002180 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002181
2182 if (!ret)
2183 ret = hdd_enable_monitor_mode(dev);
2184
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002185 return ret;
2186}
2187
2188/**
2189 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2190 * @dev: Pointer to net_device structure
2191 *
2192 * This is called in response to ifconfig up
2193 *
2194 * Return: 0 for success; non-zero for failure
2195 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002196static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002197{
2198 int ret;
2199
2200 cds_ssr_protect(__func__);
2201 ret = __hdd_mon_open(dev);
2202 cds_ssr_unprotect(__func__);
2203
2204 return ret;
2205}
2206
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002207static QDF_STATUS
2208wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2209{
2210 struct policy_mgr_dual_mac_config cfg = {0};
2211 QDF_STATUS status;
2212 uint32_t channel_select_logic_conc;
2213 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2214
2215 if (!hdd_ctx) {
2216 hdd_err("HDD context is NULL");
2217 return QDF_STATUS_E_FAILURE;
2218 }
2219
2220
2221 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2222 return QDF_STATUS_SUCCESS;
2223
2224 cfg.scan_config = 0;
2225 cfg.fw_mode_config = 0;
2226 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2227
2228 channel_select_logic_conc = hdd_ctx->config->
2229 channel_select_logic_conc;
2230
2231 if (hdd_ctx->config->dual_mac_feature_disable !=
2232 DISABLE_DBS_CXN_AND_SCAN) {
2233 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2234 hdd_ctx->hdd_psoc, &cfg.scan_config,
2235 &cfg.fw_mode_config,
2236 hdd_ctx->config->dual_mac_feature_disable,
2237 channel_select_logic_conc);
2238
2239 if (status != QDF_STATUS_SUCCESS) {
2240 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2241 status);
2242 return status;
2243 }
2244 }
2245
2246 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2247 cfg.scan_config, cfg.fw_mode_config);
2248
2249 status = sme_soc_set_dual_mac_config(cfg);
2250 if (status != QDF_STATUS_SUCCESS) {
2251 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2252 return status;
2253 }
2254
2255 return QDF_STATUS_SUCCESS;
2256}
2257
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002258/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302259 * hdd_start_adapter() - Wrapper function for device specific adapter
2260 * @adapter: pointer to HDD adapter
2261 *
2262 * This function is called to start the device specific adapter for
2263 * the mode passed in the adapter's device_mode.
2264 *
2265 * Return: 0 for success; non-zero for failure
2266 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002267int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302268{
2269
2270 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002271 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302272
Dustin Brownfdf17c12018-03-14 12:55:34 -07002273 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002274 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302275
2276 switch (device_mode) {
2277 case QDF_P2P_CLIENT_MODE:
2278 case QDF_P2P_DEVICE_MODE:
2279 case QDF_OCB_MODE:
2280 case QDF_STA_MODE:
2281 case QDF_MONITOR_MODE:
2282 ret = hdd_start_station_adapter(adapter);
2283 if (ret)
2284 goto err_start_adapter;
2285 break;
2286 case QDF_P2P_GO_MODE:
2287 case QDF_SAP_MODE:
2288 ret = hdd_start_ap_adapter(adapter);
2289 if (ret)
2290 goto err_start_adapter;
2291 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302292 case QDF_IBSS_MODE:
2293 /*
2294 * For IBSS interface is initialized as part of
2295 * hdd_init_station_mode()
2296 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002297 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302298 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002299 /* vdevs are dynamically managed by firmware in FTM */
2300 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302301 default:
2302 hdd_err("Invalid session type %d", device_mode);
2303 QDF_ASSERT(0);
2304 goto err_start_adapter;
2305 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002306
Arun Khandavallifae92942016-08-01 13:31:08 +05302307 if (hdd_set_fw_params(adapter))
2308 hdd_err("Failed to set the FW params for the adapter!");
2309
Dustin Browne7e71d32018-05-11 16:00:08 -07002310 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2311 ret = wlan_hdd_cfg80211_register_frames(adapter);
2312 if (ret < 0) {
2313 hdd_err("Failed to register frames - ret %d", ret);
2314 goto err_start_adapter;
2315 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302316 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002317
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002318 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302319
Dustin Browndb2a8be2017-12-20 11:49:56 -08002320exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002321 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002322
Arun Khandavallifae92942016-08-01 13:31:08 +05302323 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002324
Arun Khandavallifae92942016-08-01 13:31:08 +05302325err_start_adapter:
2326 return -EINVAL;
2327}
2328
2329/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302330 * hdd_enable_power_management() - API to Enable Power Management
2331 *
2332 * API invokes Bus Interface Layer power management functionality
2333 *
2334 * Return: None
2335 */
2336static void hdd_enable_power_management(void)
2337{
2338 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2339
2340 if (!hif_ctx) {
2341 hdd_err("Bus Interface Context is Invalid");
2342 return;
2343 }
2344
2345 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2346}
2347
2348/**
2349 * hdd_disable_power_management() - API to disable Power Management
2350 *
2351 * API disable Bus Interface Layer Power management functionality
2352 *
2353 * Return: None
2354 */
2355static void hdd_disable_power_management(void)
2356{
2357 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2358
2359 if (!hif_ctx) {
2360 hdd_err("Bus Interface Context is Invalid");
2361 return;
2362 }
2363
2364 hif_disable_power_management(hif_ctx);
2365}
2366
Ryan Hsuaadba072018-04-20 13:01:53 -07002367void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302368{
2369 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002370 size_t target_hw_name_len;
2371 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002372 uint8_t *buf;
2373 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302374
2375 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2376 if (!hif_sc) {
2377 hdd_err("HIF context is NULL");
2378 return;
2379 }
2380
Ryan Hsuaadba072018-04-20 13:01:53 -07002381 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302382 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002383 &target_hw_name);
2384
2385 if (hdd_ctx->target_hw_name)
2386 qdf_mem_free(hdd_ctx->target_hw_name);
2387
2388 target_hw_name_len = strlen(target_hw_name) + 1;
2389 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2390 if (hdd_ctx->target_hw_name)
2391 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2392 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302393
Ryan Hsuaadba072018-04-20 13:01:53 -07002394 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2395 if (buf) {
2396 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2397 hdd_info("%s", buf);
2398 qdf_mem_free(buf);
2399 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302400}
2401
2402/**
gbian62edd7e2017-03-07 13:12:13 +08002403 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2404 * @hdd_ctx: Pointer to hdd context
2405 *
2406 * Return: none
2407 */
2408static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002409hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002410{
2411 uint8_t num_entries = 0;
2412 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2413 uint8_t *tx_sched_wrr_ac;
2414 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002415 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002416
2417 if (NULL == hdd_ctx)
2418 return;
2419
2420 if (NULL == hdd_ctx->config) {
2421 /* Do nothing if hdd_ctx is invalid */
2422 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2423 return;
2424 }
2425
2426 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2427
2428 if (!cds_ctx) {
2429 hdd_err("Invalid CDS Context");
2430 return;
2431 }
2432
2433 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2434 switch (i) {
2435 case OL_TX_WMM_AC_BE:
2436 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2437 break;
2438 case OL_TX_WMM_AC_BK:
2439 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2440 break;
2441 case OL_TX_WMM_AC_VI:
2442 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2443 break;
2444 case OL_TX_WMM_AC_VO:
2445 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2446 break;
2447 default:
2448 tx_sched_wrr_ac = NULL;
2449 break;
2450 }
2451
2452 hdd_string_to_u8_array(tx_sched_wrr_ac,
2453 tx_sched_wrr_param,
2454 &num_entries,
2455 sizeof(tx_sched_wrr_param));
2456
2457 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2458 cds_ctx->ac_specs[i].wrr_skip_weight =
2459 tx_sched_wrr_param[0];
2460 cds_ctx->ac_specs[i].credit_threshold =
2461 tx_sched_wrr_param[1];
2462 cds_ctx->ac_specs[i].send_limit =
2463 tx_sched_wrr_param[2];
2464 cds_ctx->ac_specs[i].credit_reserve =
2465 tx_sched_wrr_param[3];
2466 cds_ctx->ac_specs[i].discard_weight =
2467 tx_sched_wrr_param[4];
2468 }
2469
2470 num_entries = 0;
2471 }
2472}
2473
Ryan Hsuaadba072018-04-20 13:01:53 -07002474uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2475 const size_t version_len, uint8_t *version)
2476{
2477 uint32_t size;
2478 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2479
2480 if (!hdd_ctx) {
2481 hdd_err("Invalid context, HDD context is null");
2482 return 0;
2483 }
2484
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302485 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002486 hdd_err("Invalid buffer pointr or buffer len\n");
2487 return 0;
2488 }
2489
2490 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2491 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2492 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2493 crmid = hdd_ctx->target_fw_version & 0x7fff;
2494 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2495
2496 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002497 "Host SW:%s, FW:%d.%d.%d.%d.%d, HW:%s, Board ver: %x Ref design id: %x, Customer id: %x, Project id: %x, Board Data Rev: %x",
Ryan Hsuaadba072018-04-20 13:01:53 -07002498 QWLAN_VERSIONSTR,
2499 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002500 hdd_ctx->target_hw_name,
2501 hdd_ctx->hw_bd_info.bdf_version,
2502 hdd_ctx->hw_bd_info.ref_design_id,
2503 hdd_ctx->hw_bd_info.customer_id,
2504 hdd_ctx->hw_bd_info.project_id,
2505 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002506
2507 return size;
2508}
2509
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302510#ifdef IPA_OFFLOAD
2511/**
2512 * hdd_update_ipa_component_config() - update ipa config
2513 * @hdd_ctx: Pointer to hdd context
2514 *
2515 * Return: none
2516 */
2517static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2518{
2519 struct hdd_config *cfg = hdd_ctx->config;
2520 struct wlan_ipa_config ipa_cfg;
2521
2522 ipa_cfg.ipa_config = cfg->IpaConfig;
2523 ipa_cfg.desc_size = cfg->IpaDescSize;
2524 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2525 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2526 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2527 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2528 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2529 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2530 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2531
2532 ucfg_ipa_update_config(&ipa_cfg);
2533}
2534#else
2535static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2536{
2537}
2538#endif
2539
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002540#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002541static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2542 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2543{
Jeff Johnson9d295242017-08-29 14:39:48 -07002544 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002545 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002546
2547 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2548 if (!adapter) {
2549 hdd_err("Adapter is NULL");
2550 return PM_MAX_NUM_OF_MODE;
2551 }
2552
2553 return policy_mgr_convert_device_mode_to_qdf_type(
2554 adapter->device_mode);
2555}
2556
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002557static void hdd_register_policy_manager_callback(
2558 struct wlan_objmgr_psoc *psoc)
2559{
2560 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002561
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002562 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002563 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002564 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2565 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002566 hdd_cbacks.get_mode_for_non_connected_vdev =
2567 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302568 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002569
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002570 if (QDF_STATUS_SUCCESS !=
2571 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2572 hdd_err("HDD callback registration with policy manager failed");
2573 }
2574}
2575#else
2576static void hdd_register_policy_manager_callback(
2577 struct wlan_objmgr_psoc *psoc)
2578{
2579}
2580#endif
2581
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002582static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002583{
2584 struct nan_callbacks cb_obj = {0};
2585
2586 cb_obj.ndi_open = hdd_ndi_open;
2587 cb_obj.ndi_close = hdd_ndi_close;
2588 cb_obj.ndi_start = hdd_ndi_start;
2589 cb_obj.ndi_delete = hdd_ndi_delete;
2590 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2591 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2592
Naveen Rawat37f62c82017-03-26 22:24:43 -07002593 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2594 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002595 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002596
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002597 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2598}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002599
Dustin Brown26b3d042017-12-21 11:13:27 -08002600#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002601/**
2602 * hdd_check_for_leaks() - Perform runtime memory leak checks
2603 *
2604 * This API triggers runtime memory leak detection. This feature enforces the
2605 * policy that any memory allocated at runtime must also be released at runtime.
2606 *
2607 * Allocating memory at runtime and releasing it at unload is effectively a
2608 * memory leak for configurations which never unload (e.g. LONU, statically
2609 * compiled driver). Such memory leaks are NOT false positives, and must be
2610 * fixed.
2611 *
2612 * Return: None
2613 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002614static void hdd_check_for_leaks(void)
2615{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002616 /* DO NOT REMOVE these checks; for false positives, read above first */
2617
Dustin Brown677e0862017-10-10 16:30:09 -07002618 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002619 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002620 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002621}
2622
Dustin Brown26b3d042017-12-21 11:13:27 -08002623#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2624#else
2625static inline void hdd_check_for_leaks(void) {}
2626
2627#define hdd_debug_domain_set(domain)
2628#endif /* CONFIG_LEAK_DETECTION */
2629
gbian62edd7e2017-03-07 13:12:13 +08002630/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002631 * hdd_update_country_code - Update country code
2632 * @hdd_ctx: HDD context
2633 *
2634 * Update country code based on module parameter country_code
2635 *
2636 * Return: 0 on success and errno on failure
2637 */
2638static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2639{
2640 if (!country_code)
2641 return 0;
2642
2643 return hdd_reg_set_country(hdd_ctx, country_code);
2644}
2645
2646/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302647 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2648 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05302649 * @reinit: flag to indicate from SSR or normal path
2650 *
2651 * This function maintains the driver state machine it will be invoked from
2652 * startup, reinit and change interface. Depending on the driver state shall
2653 * perform the opening of the modules.
2654 *
2655 * Return: 0 for success; non-zero for failure
2656 */
Dustin Browne7e71d32018-05-11 16:00:08 -07002657int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302658{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002659 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302660 qdf_device_t qdf_dev;
2661 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302662 bool unint = false;
2663 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002664 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302665
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002666 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302667
2668 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2669 if (!qdf_dev) {
2670 hdd_err("QDF Device Context is Invalid return");
2671 return -EINVAL;
2672 }
2673
Dustin Brown6f427922017-09-19 12:19:00 -07002674 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302675
Dustin Brown1fe30a82017-10-03 16:13:36 -07002676 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302677 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2678 mutex_unlock(&hdd_ctx->iface_change_lock);
2679 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002680 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302681 return 0;
2682 }
2683
Dustin Brown1fe30a82017-10-03 16:13:36 -07002684 hdd_ctx->start_modules_in_progress = true;
2685
Arun Khandavallifae92942016-08-01 13:31:08 +05302686 switch (hdd_ctx->driver_status) {
2687 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002688 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302689 unint = true;
2690 /* Fall through dont add break here */
2691 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002692 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2693
Dustin Brown26b3d042017-12-21 11:13:27 -08002694 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002695
Arun Khandavallifae92942016-08-01 13:31:08 +05302696 if (!reinit && !unint) {
2697 ret = pld_power_on(qdf_dev->dev);
2698 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002699 hdd_err("Failed to Powerup the device; errno: %d",
2700 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302701 goto release_lock;
2702 }
2703 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002704
2705 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2706 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302707 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2708 qdf_dev->bus_type,
2709 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2710 HIF_ENABLE_TYPE_PROBE);
2711 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002712 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302713 goto power_down;
2714 }
2715
2716 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302717 if (!hif_ctx) {
2718 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002719 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302720 goto power_down;
2721 }
2722
Arun Khandavallifae92942016-08-01 13:31:08 +05302723 status = ol_cds_init(qdf_dev, hif_ctx);
2724 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002725 hdd_err("No Memory to Create BMI Context; status: %d",
2726 status);
2727 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302728 goto hif_close;
2729 }
2730
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302731 hdd_update_ipa_component_config(hdd_ctx);
2732
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002733 ret = hdd_update_config(hdd_ctx);
2734 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002735 hdd_err("Failed to update configuration; errno: %d",
2736 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002737 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002738 }
2739
gbian62edd7e2017-03-07 13:12:13 +08002740 hdd_update_cds_ac_specs_params(hdd_ctx);
2741
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302742 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002743 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002744 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002745 ret = qdf_status_to_os_return(status);
2746 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302747 }
2748
Jeff Johnson79e36882018-05-06 17:15:33 -07002749 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302750 ret = hdd_update_components_config(hdd_ctx);
2751 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002752 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302753 ret);
2754 goto close;
2755 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002756 status = cds_dp_open(hdd_ctx->hdd_psoc);
2757 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002758 hdd_err("Failed to Open cds post open; status: %d",
2759 status);
2760 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002761 goto close;
2762 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302763
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002764 /*
2765 * NAN compoenet requires certian operations like, open adapter,
2766 * close adapter, etc. to be initiated by HDD, for those
2767 * register HDD callbacks with UMAC's NAN componenet.
2768 */
2769 hdd_nan_register_callbacks(hdd_ctx);
2770
Arun Khandavallifae92942016-08-01 13:31:08 +05302771 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2772
Jeff Johnson3a280122017-09-13 07:42:00 -07002773 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302774 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002775 hdd_err("Failed to pre-enable CDS; status: %d", status);
2776 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002777 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302778 }
2779
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002780 hdd_register_policy_manager_callback(
2781 hdd_ctx->hdd_psoc);
2782
Amar Singhal0928b192017-12-01 10:50:54 -08002783 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2784
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302785 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302786 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002787 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302788
Arun Khandavallifae92942016-08-01 13:31:08 +05302789 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002790 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302791 break;
2792 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302793
Arun Khandavallifae92942016-08-01 13:31:08 +05302794 /* Fall through dont add break here */
2795 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002796 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2797
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302798 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2799 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002800 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302801 break;
2802 }
Dustin Browndca39692017-11-09 15:30:25 -08002803
Dustin Browne7e71d32018-05-11 16:00:08 -07002804 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002805 if (ret) {
2806 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002807 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302808 }
Dustin Browndca39692017-11-09 15:30:25 -08002809
Komal Seelamf2136bb2016-09-28 18:30:44 +05302810 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002811
Arun Khandavallifae92942016-08-01 13:31:08 +05302812 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002813 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302814 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002815
Arun Khandavallifae92942016-08-01 13:31:08 +05302816 default:
2817 hdd_err("WLAN start invoked in wrong state! :%d\n",
2818 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002819 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302820 goto release_lock;
2821 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002822
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302823 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002824 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2825 ret = hdd_update_country_code(hdd_ctx);
2826 if (ret)
2827 hdd_err("Failed to update command line country code!");
2828 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302829 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002830
Dustin Browne74003f2018-03-14 12:51:58 -07002831 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002832
Arun Khandavallifae92942016-08-01 13:31:08 +05302833 return 0;
2834
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002835post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002836 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002837
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002838cds_txrx_free:
Jingxiang Ge95912f82018-04-19 12:01:26 +08002839 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
2840
2841 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2842 hdd_runtime_suspend_context_deinit(hdd_ctx);
2843 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
2844 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2845 }
2846
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002847 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002848
Arun Khandavallifae92942016-08-01 13:31:08 +05302849close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002850 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002851 hdd_info("Wlan transition aborted (now CLOSED)");
2852
Jeff Johnsone4b14592017-09-13 14:23:33 -07002853 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302854
Dustin Brown28b17892017-10-10 13:29:38 -07002855deinit_config:
2856 cds_deinit_ini_config();
2857
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002858cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302859 ol_cds_free();
2860
2861hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002862 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2863 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302864power_down:
2865 if (!reinit && !unint)
2866 pld_power_off(qdf_dev->dev);
2867release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302868 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302869 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05302870 if (hdd_ctx->target_hw_name) {
2871 qdf_mem_free(hdd_ctx->target_hw_name);
2872 hdd_ctx->target_hw_name = NULL;
2873 }
Dustin Brown4bc0a622017-12-06 15:56:50 -08002874 /* many adapter resources are not freed by design in SSR case */
2875 if (!reinit)
2876 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002877 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002878
Dustin Browne74003f2018-03-14 12:51:58 -07002879 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002880
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002881 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302882}
2883
Naveen Rawat910726a2017-03-06 11:42:51 -08002884#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002885static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002886{
2887 int ret = os_if_wifi_pos_register_nl();
2888
2889 if (ret)
2890 hdd_err("os_if_wifi_pos_register_nl failed");
2891
2892 return ret;
2893}
2894
2895static int hdd_deactivate_wifi_pos(void)
2896{
2897 int ret = os_if_wifi_pos_deregister_nl();
2898
2899 if (ret)
2900 hdd_err("os_if_wifi_pos_deregister_nl failed");
2901
2902 return ret;
2903}
2904
2905/**
2906 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2907 * @hdd_ctx: hdd context
2908 *
2909 * Return: status of operation
2910 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002911static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002912{
2913 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2914 struct hdd_config *cfg = hdd_ctx->config;
2915
2916 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2917 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2918 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2919 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2920 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2921 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2922 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2923 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2924}
2925#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002926static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002927{
2928 return oem_activate_service(hdd_ctx);
2929}
2930
2931static int hdd_deactivate_wifi_pos(void)
2932{
2933 return 0;
2934}
2935
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002936static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002937{
2938}
2939#endif
2940
Arun Khandavallifae92942016-08-01 13:31:08 +05302941/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002942 * __hdd_open() - HDD Open function
2943 * @dev: Pointer to net_device structure
2944 *
2945 * This is called in response to ifconfig up
2946 *
2947 * Return: 0 for success; non-zero for failure
2948 */
2949static int __hdd_open(struct net_device *dev)
2950{
Jeff Johnson9d295242017-08-29 14:39:48 -07002951 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002952 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002953 int ret;
2954
Dustin Brownfdf17c12018-03-14 12:55:34 -07002955 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302956 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002957 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002958
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302959 /* Nothing to be done if device is unloading */
2960 if (cds_is_driver_unloading()) {
2961 hdd_err("Driver is unloading can not open the hdd");
2962 return -EBUSY;
2963 }
2964
Dustin Brown01847752017-10-25 13:56:27 -07002965 if (cds_is_driver_recovering()) {
2966 hdd_err("WLAN is currently recovering; Please try again.");
2967 return -EBUSY;
2968 }
2969
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302970 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2971 hdd_err("con_mode_handler is in progress; Please try again.");
2972 return -EBUSY;
2973 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302974
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302975 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302976 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2977
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302978 /*
2979 * This scenario can be hit in cases where in the wlan driver after
2980 * registering the netdevices and there is a failure in driver
2981 * initialization. So return error gracefully because the netdevices
2982 * will be de-registered as part of the load failure.
2983 */
2984
2985 if (!cds_is_driver_loaded()) {
2986 hdd_err("Failed to start the wlan driver!!");
2987 ret = -EIO;
2988 goto err_hdd_hdd_init_deinit_lock;
2989 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302990
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002991
Dustin Browne7e71d32018-05-11 16:00:08 -07002992 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302993 if (ret) {
2994 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302995 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302996 }
2997
2998
2999 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3000 ret = hdd_start_adapter(adapter);
3001 if (ret) {
3002 hdd_err("Failed to start adapter :%d",
3003 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303004 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303005 }
3006 }
3007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003008 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3009 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003010 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011 /* Enable TX queues only when we are connected */
3012 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303013 WLAN_START_ALL_NETIF_QUEUE,
3014 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003015 }
3016
Naveen Rawat286def52016-09-23 15:38:02 -07003017 /* Enable carrier and transmit queues for NDI */
3018 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003019 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003020 wlan_hdd_netif_queue_control(adapter,
3021 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3022 WLAN_CONTROL_PATH);
3023 }
3024
Naveen Rawat910726a2017-03-06 11:42:51 -08003025 hdd_populate_wifi_pos_cfg(hdd_ctx);
3026
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303027err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303028 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303029 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003030 return ret;
3031}
3032
Arun Khandavallifae92942016-08-01 13:31:08 +05303033
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003034/**
3035 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3036 * @dev: Pointer to net_device structure
3037 *
3038 * This is called in response to ifconfig up
3039 *
3040 * Return: 0 for success; non-zero for failure
3041 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003042static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003043{
3044 int ret;
3045
3046 cds_ssr_protect(__func__);
3047 ret = __hdd_open(dev);
3048 cds_ssr_unprotect(__func__);
3049
3050 return ret;
3051}
3052
3053/**
3054 * __hdd_stop() - HDD stop function
3055 * @dev: Pointer to net_device structure
3056 *
3057 * This is called in response to ifconfig down
3058 *
3059 * Return: 0 for success; non-zero for failure
3060 */
3061static int __hdd_stop(struct net_device *dev)
3062{
Jeff Johnson9d295242017-08-29 14:39:48 -07003063 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003064 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003065 int ret;
3066
Dustin Brownfdf17c12018-03-14 12:55:34 -07003067 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003068
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303069 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003070 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003071
3072 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303073 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003074 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003075
3076 /* Nothing to be done if the interface is not opened */
3077 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003078 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003079 return -ENODEV;
3080 }
3081
3082 /* Make sure the interface is marked as closed */
3083 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303084
3085 hdd_debug("Disabling Auto Power save timer");
3086 sme_ps_disable_auto_ps_timer(
3087 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07003088 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303089
3090 /*
3091 * Disable TX on the interface, after this hard_start_xmit() will not
3092 * be called on that interface
3093 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003094 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003095 hdd_device_mode_to_string(adapter->device_mode),
3096 adapter->device_mode);
3097
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303098 wlan_hdd_netif_queue_control(adapter,
3099 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3100 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003101
3102 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003103 * NAN data interface is different in some sense. The traffic on NDI is
3104 * bursty in nature and depends on the need to transfer. The service
3105 * layer may down the interface after the usage and up again when
3106 * required. In some sense, the NDI is expected to be available
3107 * (like SAP) iface until NDI delete request is issued by the service
3108 * layer. Skip BSS termination and adapter deletion for NAN Data
3109 * interface (NDI).
3110 */
3111 if (WLAN_HDD_IS_NDI(adapter))
3112 return 0;
3113
3114 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003115 * The interface is marked as down for outside world (aka kernel)
3116 * But the driver is pretty much alive inside. The driver needs to
3117 * tear down the existing connection on the netdev (session)
3118 * cleanup the data pipes and wait until the control plane is stabilized
3119 * for this interface. The call also needs to wait until the above
3120 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003121 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122 * That is intentional to be able to scan if it is a STA/P2P interface
3123 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003124 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003125
3126 /* DeInit the adapter. This ensures datapath cleanup as well */
3127 hdd_deinit_adapter(hdd_ctx, adapter, true);
3128
Arun Khandavallifae92942016-08-01 13:31:08 +05303129
3130 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303131 * Upon wifi turn off, DUT has to flush the scan results so if
3132 * this is the last cli iface, flush the scan database.
3133 */
3134 if (!hdd_is_cli_iface_up(hdd_ctx))
3135 sme_scan_flush_result(hdd_ctx->hHal);
3136
3137 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303138 * Find if any iface is up. If any iface is up then can't put device to
3139 * sleep/power save mode
3140 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303141 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003142 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003143 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3144 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303145 hdd_prevent_suspend_timeout(
3146 hdd_ctx->config->iface_change_wait_time,
3147 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303148 }
3149
Dustin Browne74003f2018-03-14 12:51:58 -07003150 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003151 return 0;
3152}
3153
3154/**
3155 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3156 * @dev: pointer to net_device structure
3157 *
3158 * This is called in response to ifconfig down
3159 *
3160 * Return: 0 for success and error number for failure
3161 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003162static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003163{
3164 int ret;
3165
3166 cds_ssr_protect(__func__);
3167 ret = __hdd_stop(dev);
3168 cds_ssr_unprotect(__func__);
3169
3170 return ret;
3171}
3172
3173/**
3174 * __hdd_uninit() - HDD uninit function
3175 * @dev: Pointer to net_device structure
3176 *
3177 * This is called during the netdev unregister to uninitialize all data
3178 * associated with the device
3179 *
3180 * Return: None
3181 */
3182static void __hdd_uninit(struct net_device *dev)
3183{
Jeff Johnson9d295242017-08-29 14:39:48 -07003184 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003185 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186
Dustin Brownfdf17c12018-03-14 12:55:34 -07003187 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188
3189 do {
3190 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003191 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192 break;
3193 }
3194
Jeff Johnson399c6272017-08-30 10:51:00 -07003195 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3196 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003197 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198 break;
3199 }
3200
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003201 if (dev != adapter->dev)
3202 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003203
Jeff Johnson399c6272017-08-30 10:51:00 -07003204 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205
3206 /* after uninit our adapter structure will no longer be valid */
3207 adapter->dev = NULL;
3208 adapter->magic = 0;
3209 } while (0);
3210
Dustin Browne74003f2018-03-14 12:51:58 -07003211 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212}
3213
3214/**
3215 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3216 * @dev: pointer to net_device structure
3217 *
3218 * This is called during the netdev unregister to uninitialize all data
3219 * associated with the device
3220 *
3221 * Return: none
3222 */
3223static void hdd_uninit(struct net_device *dev)
3224{
3225 cds_ssr_protect(__func__);
3226 __hdd_uninit(dev);
3227 cds_ssr_unprotect(__func__);
3228}
3229
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003230static int hdd_open_cesium_nl_sock(void)
3231{
3232#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3233 struct netlink_kernel_cfg cfg = {
3234 .groups = WLAN_NLINK_MCAST_GRP_ID,
3235 .input = NULL
3236 };
3237#endif
3238 int ret = 0;
3239
3240#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3241 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3242#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3243 THIS_MODULE,
3244#endif
3245 &cfg);
3246#else
3247 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3248 WLAN_NLINK_MCAST_GRP_ID,
3249 NULL, NULL, THIS_MODULE);
3250#endif
3251
3252 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003253 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003254 ret = -ECONNREFUSED;
3255 }
3256
3257 return ret;
3258}
3259
3260static void hdd_close_cesium_nl_sock(void)
3261{
3262 if (NULL != cesium_nl_srv_sock) {
3263 netlink_kernel_release(cesium_nl_srv_sock);
3264 cesium_nl_srv_sock = NULL;
3265 }
3266}
3267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268/**
3269 * __hdd_set_mac_address() - set the user specified mac address
3270 * @dev: Pointer to the net device.
3271 * @addr: Pointer to the sockaddr.
3272 *
3273 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003274 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003275 *
3276 * Return: 0 for success, non zero for failure
3277 */
3278static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3279{
Jeff Johnson9d295242017-08-29 14:39:48 -07003280 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003281 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003282 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303283 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303285 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286
Dustin Brownfdf17c12018-03-14 12:55:34 -07003287 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303289 if (netif_running(dev)) {
3290 hdd_err("On iface up, set mac address change isn't supported");
3291 return -EBUSY;
3292 }
3293
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003294 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3295 ret = wlan_hdd_validate_context(hdd_ctx);
3296 if (0 != ret)
3297 return ret;
3298
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303299 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
3300
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303301 if (hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes)) {
3302 hdd_err("adapter exist with same mac address " MAC_ADDRESS_STR,
3303 MAC_ADDR_ARRAY(mac_addr.bytes));
3304 return -EINVAL;
3305 }
3306
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303307 if (qdf_is_macaddr_zero(&mac_addr)) {
3308 hdd_err("MAC is all zero");
3309 return -EINVAL;
3310 }
3311
3312 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3313 hdd_err("MAC is Broadcast");
3314 return -EINVAL;
3315 }
3316
3317 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3318 hdd_err("MAC is Multicast");
3319 return -EINVAL;
3320 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303321 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3322 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303323
Jeff Johnson1e851a12017-10-28 14:36:12 -07003324 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003325 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3326
Dustin Browne74003f2018-03-14 12:51:58 -07003327 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303328 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003329}
3330
3331/**
3332 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3333 * function from SSR
3334 * @dev: pointer to net_device structure
3335 * @addr: Pointer to the sockaddr
3336 *
3337 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003338 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339 *
3340 * Return: 0 for success.
3341 */
3342static int hdd_set_mac_address(struct net_device *dev, void *addr)
3343{
3344 int ret;
3345
3346 cds_ssr_protect(__func__);
3347 ret = __hdd_set_mac_address(dev, addr);
3348 cds_ssr_unprotect(__func__);
3349
3350 return ret;
3351}
3352
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003353uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003354{
3355 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003356
Anurag Chouhan6d760662016-02-20 16:05:43 +05303357 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003358 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3359 break;
3360 }
3361
Anurag Chouhan6d760662016-02-20 16:05:43 +05303362 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363 return NULL;
3364
3365 hdd_ctx->config->intfAddrMask |= (1 << i);
3366 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3367}
3368
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003369void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3370 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371{
3372 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003373
Anurag Chouhan6d760662016-02-20 16:05:43 +05303374 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375 if (!memcmp(releaseAddr,
3376 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3377 6)) {
3378 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3379 break;
3380 }
3381 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003382}
3383
3384#ifdef WLAN_FEATURE_PACKET_FILTERING
3385/**
3386 * __hdd_set_multicast_list() - set the multicast address list
3387 * @dev: Pointer to the WLAN device.
3388 * @skb: Pointer to OS packet (sk_buff).
3389 *
3390 * This funciton sets the multicast address list.
3391 *
3392 * Return: None
3393 */
3394static void __hdd_set_multicast_list(struct net_device *dev)
3395{
Jeff Johnson9d295242017-08-29 14:39:48 -07003396 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003397 int i = 0, status;
3398 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003399 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303400 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3401 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3402 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003403
Dustin Brownfdf17c12018-03-14 12:55:34 -07003404 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303405 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303406 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303407
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303409 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303410 goto out;
3411
Dustin Brownc788acb2017-08-01 17:43:51 -07003412 status = hdd_validate_adapter(adapter);
3413 if (status)
3414 goto out;
3415
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303416 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3417 hdd_err("%s: Driver module is closed", __func__);
3418 return;
3419 }
3420
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303421 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3422 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003423 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303424 goto out;
3425 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003426
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303427 /* Delete already configured multicast address list */
3428 if (adapter->mc_addr_list.mc_cnt > 0) {
3429 hdd_info("clear previously configured MC address list");
3430 hdd_disable_and_flush_mc_addr_list(adapter,
3431 pmo_mc_list_change_notify);
3432 }
3433
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003435 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303436 hdd_disable_and_flush_mc_addr_list(adapter,
3437 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003438 } else {
3439 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303440 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003441 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303442 pmo_ucfg_max_mc_addr_supported(psoc));
3443 hdd_disable_and_flush_mc_addr_list(adapter,
3444 pmo_mc_list_change_notify);
3445 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003446 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003447 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003448 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303449 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 if (i == mc_count)
3451 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303452 memset(&(mc_list_request->mc_addr[i].bytes),
3453 0, ETH_ALEN);
3454 memcpy(&(mc_list_request->mc_addr[i].bytes),
3455 ha->addr, ETH_ALEN);
3456 hdd_info("mlist[%d] = %pM", i,
3457 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458 i++;
3459 }
3460 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303461
3462 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003463 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303464 mc_list_request->count = mc_count;
3465 status = hdd_cache_mc_addr_list(mc_list_request);
3466 if (status == 0) {
3467 hdd_enable_mc_addr_filtering(adapter,
3468 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303470 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303472out:
3473 if (mc_list_request)
3474 qdf_mem_free(mc_list_request);
Dustin Browne74003f2018-03-14 12:51:58 -07003475 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476}
3477
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303478
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479/**
3480 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3481 * @dev: pointer to net_device
3482 *
3483 * Return: none
3484 */
3485static void hdd_set_multicast_list(struct net_device *dev)
3486{
3487 cds_ssr_protect(__func__);
3488 __hdd_set_multicast_list(dev);
3489 cds_ssr_unprotect(__func__);
3490}
3491#endif
3492
3493/**
3494 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3495 * @dev: Pointer to the WLAN device.
3496 * @skb: Pointer to OS packet (sk_buff).
3497 *
3498 * This function is registered with the Linux OS for network
3499 * core to decide which queue to use first.
3500 *
3501 * Return: ac, Queue Index/access category corresponding to UP in IP header
3502 */
3503static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3504#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3505 , void *accel_priv
3506#endif
3507#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3508 , select_queue_fallback_t fallback
3509#endif
3510)
3511{
3512 return hdd_wmm_select_queue(dev, skb);
3513}
3514
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003515static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516 .ndo_open = hdd_open,
3517 .ndo_stop = hdd_stop,
3518 .ndo_uninit = hdd_uninit,
3519 .ndo_start_xmit = hdd_hard_start_xmit,
3520 .ndo_tx_timeout = hdd_tx_timeout,
3521 .ndo_get_stats = hdd_get_stats,
3522 .ndo_do_ioctl = hdd_ioctl,
3523 .ndo_set_mac_address = hdd_set_mac_address,
3524 .ndo_select_queue = hdd_select_queue,
3525#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003526 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003527#endif
3528};
3529
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003530/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003531static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003532 .ndo_open = hdd_mon_open,
3533 .ndo_stop = hdd_stop,
3534 .ndo_get_stats = hdd_get_stats,
3535};
3536
3537/**
3538 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003539 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003540 * Return: None
3541 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003542void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003544 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003545 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003546 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003547 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003548}
3549
3550/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003551 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3552 * @hdd_ctx: global hdd context
3553 * @macAddr: mac address to assign to the interface
3554 * @name: User-visible name of the interface
3555 *
3556 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003557 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003558 *
3559 * Return: the pointer to hdd adapter, otherwise NULL
3560 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003561static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003563 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003564 const char *name)
3565{
Jeff Johnson5505db82017-11-02 21:19:23 -07003566 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003567 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003568 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303569 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003570 /*
3571 * cfg80211 initialization and registration....
3572 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003573 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003574#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3575 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003577 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3578 hdd_mon_mode_ether_setup : ether_setup),
3579 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580
Jeff Johnson5505db82017-11-02 21:19:23 -07003581 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003582
3583 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003584 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585
Jeff Johnson9d295242017-08-29 14:39:48 -07003586 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003587 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303588 qdf_mem_set(sta_ctx->conn_info.staId,
3589 sizeof(sta_ctx->conn_info.staId),
3590 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003591 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003592 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003593 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003594 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303596 qdf_status = qdf_event_create(
3597 &adapter->qdf_session_open_event);
3598 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3599 hdd_err("Session open QDF event init failed!");
3600 free_netdev(adapter->dev);
3601 return NULL;
3602 }
3603
3604 qdf_status = qdf_event_create(
3605 &adapter->qdf_session_close_event);
3606 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3607 hdd_err("Session close QDF event init failed!");
3608 free_netdev(adapter->dev);
3609 return NULL;
3610 }
3611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003612 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303613 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003614 init_completion(&adapter->linkup_event_var);
3615 init_completion(&adapter->cancel_rem_on_chan_var);
3616 init_completion(&adapter->rem_on_chan_ready_event);
3617 init_completion(&adapter->sta_authorized_event);
3618 init_completion(&adapter->offchannel_tx_event);
3619 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003620 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303621 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003622
3623 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003624 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303625 adapter->disconnection_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003627 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628
Jeff Johnson5505db82017-11-02 21:19:23 -07003629 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003630 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003631 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003632 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003633 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634
3635 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003636 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003638 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003639
Jeff Johnson5505db82017-11-02 21:19:23 -07003640 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003641
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003642 hdd_set_station_ops(adapter->dev);
3643
Jeff Johnson5505db82017-11-02 21:19:23 -07003644 hdd_dev_setup_destructor(dev);
3645 dev->ieee80211_ptr = &adapter->wdev;
3646 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003647 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003648 adapter->wdev.netdev = dev;
3649 /* set dev's parent to underlying device */
3650 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003651 hdd_wmm_init(adapter);
3652 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303653 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003654 }
3655
3656 return adapter;
3657}
3658
Jeff Johnson9d295242017-08-29 14:39:48 -07003659static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003661 struct net_device *dev = adapter->dev;
3662 int ret;
3663
Dustin Brown491d54b2018-03-14 12:39:11 -07003664 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003666 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003667 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3668
3669 ret = dev_alloc_name(dev, dev->name);
3670 if (ret < 0) {
3671 hdd_err(
3672 "unable to get dev name: %s, err = 0x%x",
3673 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303674 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003675 }
3676 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003677
3678 ret = register_netdevice(dev);
3679 if (ret) {
3680 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3681 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303682 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003683 }
3684 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003685 ret = register_netdev(dev);
3686 if (ret) {
3687 hdd_err("register_netdev(%s) failed, err = 0x%x",
3688 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303689 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003690 }
3691 }
3692 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3693
Dustin Browne74003f2018-03-14 12:51:58 -07003694 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003695
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303696 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697}
3698
Krunal Sonib51eec72017-11-20 21:53:01 -08003699QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700{
Krunal Sonib51eec72017-11-20 21:53:01 -08003701 struct hdd_adapter *adapter;
3702 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003703
Krunal Sonib51eec72017-11-20 21:53:01 -08003704 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3705 if (!hdd_ctx) {
3706 hdd_err("Invalid HDD_CTX");
3707 return QDF_STATUS_E_FAILURE;
3708 }
3709
3710 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3711 if (NULL == adapter) {
3712 hdd_err("NULL adapter");
3713 return QDF_STATUS_E_INVAL;
3714 }
3715 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303716 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003717 hdd_debug("session %d opened", adapter->session_id);
3718
3719 return QDF_STATUS_SUCCESS;
3720}
3721
3722QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3723{
3724 struct hdd_adapter *adapter;
3725 struct hdd_context *hdd_ctx;
3726
3727 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3728 if (!hdd_ctx) {
3729 hdd_err("Invalid HDD_CTX");
3730 return QDF_STATUS_E_FAILURE;
3731 }
3732
3733 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003734 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003735 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303736 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003737 }
3738
3739 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003740 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303741 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003742 }
3743
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003744 /*
3745 * For NAN Data interface, the close session results in the final
3746 * indication to the userspace
3747 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003748 if (adapter->device_mode == QDF_NDI_MODE)
3749 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003750
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003751 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3752
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003753 /*
3754 * We can be blocked while waiting for scheduled work to be
3755 * flushed, and the adapter structure can potentially be freed, in
3756 * which case the magic will have been reset. So make sure the
3757 * magic is still good, and hence the adapter structure is still
3758 * valid, before signaling completion
3759 */
3760 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303761 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003762
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303763 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003764}
3765
Jeff Johnson9d295242017-08-29 14:39:48 -07003766int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003767{
Dustin Brownd28772b2017-03-17 14:16:07 -07003768 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769
Dustin Brownd28772b2017-03-17 14:16:07 -07003770 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003771 if (QDF_IS_STATUS_ERROR(status))
3772 return qdf_status_to_os_return(status);
3773
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003774 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003775 if (QDF_IS_STATUS_ERROR(status))
3776 return qdf_status_to_os_return(status);
3777
3778 if (wma_capability_enhanced_mcast_filter())
3779 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3780 else
3781 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003782
3783 return qdf_status_to_os_return(status);
3784}
3785
Jeff Johnson9d295242017-08-29 14:39:48 -07003786int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003787{
3788 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003789 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003790 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003791 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003792
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003793 vdev_id = adapter->session_id;
3794 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003795
3796 /* vdev created sanity check */
3797 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003798 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003799 return -EINVAL;
3800 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003801 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003802
Dustin Brownd28772b2017-03-17 14:16:07 -07003803 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303804 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003805 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003806 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003807 if (QDF_IS_STATUS_ERROR(status)) {
3808 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003809 errno = qdf_status_to_os_return(status);
3810 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003811 }
3812
3813 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303814 status = qdf_wait_for_event_completion(
3815 &adapter->qdf_session_close_event,
3816 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3817 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003818 if (adapter->device_mode == QDF_NDI_MODE)
3819 hdd_ndp_session_end_handler(adapter);
3820 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303821 adapter->session_id = HDD_SESSION_ID_INVALID;
3822 if (QDF_STATUS_E_TIMEOUT != status) {
3823 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003824 errno = -ETIMEDOUT;
3825 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303826 } else if (adapter->qdf_session_close_event.force_set) {
3827 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003828 errno = -EINVAL;
3829 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303830 } else {
3831 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003832 errno = -EINVAL;
3833 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303834 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003835 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003836
Yue Maf9782842017-05-08 12:49:49 -07003837release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003838 /*
3839 * In SSR or driver unloading case, directly exit may cause objects
3840 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003841 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003842 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003843 return errno;
3844
Sandeep Puligillaef415362017-08-30 16:37:13 -07003845 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003846 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003847 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003848 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003849 return errno;
3850 }
3851
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003852 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003853
3854 return 0;
3855}
3856
Krunal Sonib51eec72017-11-20 21:53:01 -08003857static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3858 struct sme_session_params *session_param,
3859 csr_roam_completeCallback callback,
3860 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003861{
Dustin Brownd28772b2017-03-17 14:16:07 -07003862 uint32_t type;
3863 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003864 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003865
3866 /* determine vdev (sub)type */
3867 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303868 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003869 hdd_err("failed to get vdev type: %d", status);
3870 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003871 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003872 session_param->sme_session_id = adapter->session_id;
3873 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3874 session_param->type_of_persona = type;
3875 session_param->subtype_of_persona = sub_type;
3876 session_param->session_open_cb = hdd_sme_open_session_callback;
3877 session_param->session_close_cb = hdd_sme_close_session_callback;
3878 session_param->callback = callback;
3879 session_param->callback_ctx = callback_ctx;
3880
3881 return 0;
3882}
3883
3884int hdd_vdev_create(struct hdd_adapter *adapter,
3885 csr_roam_completeCallback callback, void *ctx)
3886{
3887 QDF_STATUS status;
3888 int errno;
3889 struct hdd_context *hdd_ctx;
3890 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003891
3892 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003893
3894 /* do vdev create via objmgr */
3895 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003896 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003897 if (errno) {
3898 hdd_err("failed to create objmgr vdev: %d", errno);
3899 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003901
3902 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303903 status = qdf_event_reset(&adapter->qdf_session_open_event);
3904 if (QDF_STATUS_SUCCESS != status) {
3905 hdd_err("failed to reinit session open event");
3906 return -EINVAL;
3907 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003908 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3909 callback, ctx);
3910 if (errno) {
3911 hdd_err("failed to populating SME params");
3912 goto objmgr_vdev_destroy_procedure;
3913 }
3914
3915 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003916 if (QDF_IS_STATUS_ERROR(status)) {
3917 hdd_err("failed to open sme session: %d", status);
3918 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003919 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003920 }
3921
3922 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303923 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3924 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3925 if (QDF_STATUS_SUCCESS != status) {
3926 if (adapter->qdf_session_open_event.force_set) {
3927 /*
3928 * SSR/PDR has caused shutdown, which has forcefully
3929 * set the event. Return without the closing session.
3930 */
3931 adapter->session_id = HDD_SESSION_ID_INVALID;
3932 hdd_err("Session open event forcefully set");
3933 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303934 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003935
3936 if (QDF_STATUS_E_TIMEOUT == status)
3937 hdd_err("Session failed to open within timeout period");
3938 else
3939 hdd_err("Failed to wait for session open event(status-%d)",
3940 status);
3941 errno = -ETIMEDOUT;
3942 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3943 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003944 }
3945
3946 /* firmware ready for component communication, raise vdev_ready event */
3947 errno = hdd_vdev_ready(adapter);
3948 if (errno) {
3949 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003950 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003951 }
3952
Naveen Rawat2b430892018-03-13 13:58:18 -07003953 if (adapter->device_mode == QDF_STA_MODE) {
3954 hdd_debug("setting RTT mac randomization param: %d",
3955 hdd_ctx->config->enable_rtt_mac_randomization);
3956 errno = sme_cli_set_command(adapter->session_id,
3957 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
3958 hdd_ctx->config->enable_rtt_mac_randomization,
3959 VDEV_CMD);
3960 if (0 != errno)
3961 hdd_err("RTT mac randomization param set failed %d",
3962 errno);
3963 }
3964
Jeff Johnson1b780e42017-10-31 14:11:45 -07003965 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003966
3967 return 0;
3968
3969 /*
3970 * Due to legacy constraints, we need to destroy in the same order as
3971 * create. So, split error handling into 2 cases to accommodate.
3972 */
3973
Krunal Soni4a020c72017-10-30 20:58:40 -07003974objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003975 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003976
3977 return errno;
3978
Krunal Soni4a020c72017-10-30 20:58:40 -07003979hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003980 QDF_BUG(!hdd_vdev_destroy(adapter));
3981
3982 return errno;
3983}
3984
Jeff Johnson9d295242017-08-29 14:39:48 -07003985QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003986{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003987 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003988 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003989 QDF_STATUS status;
3990 int ret_val;
3991
Dustin Brownd28772b2017-03-17 14:16:07 -07003992 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3993 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3994 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003995 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003996
Jeff Johnson7f2c5912018-03-23 11:42:28 -07003997 hdd_roam_profile_init(adapter);
3998 hdd_register_wext(adapter->dev);
3999
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004000 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001
Jeff Johnsond377dce2017-10-04 10:32:42 -07004002 qdf_mem_set(sta_ctx->conn_info.staId,
4003 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304004
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004005 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004006 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304007 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004009 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010 hdd_ctx->config->OperatingChannel;
4011
4012 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004013 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004014
4015 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304016 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004017 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 status, status);
4019 goto error_init_txrx;
4020 }
4021
4022 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4023
4024 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304025 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004026 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 status, status);
4028 goto error_wmm_init;
4029 }
4030
4031 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4032
Jeff Johnson1b780e42017-10-31 14:11:45 -07004033 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004034 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304035 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004036 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004037 if (ret_val)
4038 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304040 /*
4041 * In case of USB tethering, LRO is disabled. If SSR happened
4042 * during that time, then as part of SSR init, do not enable
4043 * the LRO again. Keep the LRO state same as before SSR.
4044 */
4045 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004046 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304047
4048 /* rcpi info initialization */
4049 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4050
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304051 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004053error_wmm_init:
4054 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4055 hdd_deinit_tx_rx(adapter);
4056error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004057 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004058 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004059
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004060 return status;
4061}
4062
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304063/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004064 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304065 * @hdd_ctx: global hdd context
4066 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004067 * @rtnl_held: Used to indicate whether or not the caller is holding
4068 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304069 *
4070 * This function De-initializes the STA/P2P/OCB adapter.
4071 *
4072 * Return: None.
4073 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004074static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004075 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004076 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304077{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004078 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304079
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304080 if (adapter->dev) {
4081 if (rtnl_held)
4082 adapter->dev->wireless_handlers = NULL;
4083 else {
4084 rtnl_lock();
4085 adapter->dev->wireless_handlers = NULL;
4086 rtnl_unlock();
4087 }
4088 }
4089
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304090 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4091 hdd_deinit_tx_rx(adapter);
4092 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4093 }
4094
4095 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4096 hdd_wmm_adapter_close(adapter);
4097 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4098 }
4099
Krunal Sonib51eec72017-11-20 21:53:01 -08004100
Dustin Browne74003f2018-03-14 12:51:58 -07004101 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304102}
4103
Krunal Sonib51eec72017-11-20 21:53:01 -08004104void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4105 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004106 bool rtnl_held)
4107{
Dustin Brown491d54b2018-03-14 12:39:11 -07004108 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004111 case QDF_STA_MODE:
4112 case QDF_P2P_CLIENT_MODE:
4113 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004114 case QDF_IBSS_MODE:
4115 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004117 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004118 break;
4119 }
4120
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004121 case QDF_SAP_MODE:
4122 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004124 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004125 break;
4126 }
4127
4128 default:
4129 break;
4130 }
4131
Dustin Browne74003f2018-03-14 12:51:58 -07004132 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004133}
4134
Jeff Johnson9d295242017-08-29 14:39:48 -07004135static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004136 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004137{
Jeff Johnson5505db82017-11-02 21:19:23 -07004138 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139
4140 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004141 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004143 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 return;
4145 }
4146
Alok Kumarb64650c2018-03-23 17:05:11 +05304147 hdd_nud_deinit_tracking(adapter);
4148 qdf_mutex_destroy(&adapter->disconnection_status_lock);
4149
Rajeev Kumardca5f812016-02-04 17:28:06 -08004150 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304151
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152 /*
4153 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4154 * the driver is almost closed and cannot handle either control
4155 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004156 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4157 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004158 * is not right. Setting this flag helps hdd_stop() to recognize that
4159 * the interface is closed and restricts any operations on that
4160 */
4161 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4162
4163 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004164 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004165 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004166 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004167 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168 /*
4169 * Note that the adapter is no longer valid at this point
4170 * since the memory has been reclaimed
4171 */
4172 }
4173}
4174
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004175static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004176 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177{
Jeff Johnson9d295242017-08-29 14:39:48 -07004178 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004179
Dustin Brown920397d2017-12-13 16:27:50 -08004180 hdd_for_each_adapter(hdd_ctx, adapter) {
4181 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4182 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304183 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004184 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004185 }
Dustin Brown920397d2017-12-13 16:27:50 -08004186
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304187 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004189
Arun Khandavalli2358d522016-05-16 18:05:37 +05304190#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4191/**
4192 * hdd_set_fw_log_params() - Set log parameters to FW
4193 * @hdd_ctx: HDD Context
4194 * @adapter: HDD Adapter
4195 *
4196 * This function set the FW Debug log level based on the INI.
4197 *
4198 * Return: None
4199 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004200static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004201 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304202{
4203 uint8_t count = 0, numentries = 0,
4204 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4205 uint32_t value = 0;
4206 int ret;
4207
Arun Khandavallifae92942016-08-01 13:31:08 +05304208 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4209 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004210 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304211 return;
4212 }
4213
Arun Khandavallifae92942016-08-01 13:31:08 +05304214 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304215 hdd_ctx->fw_log_settings.dl_type =
4216 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004217 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304218 WMI_DBGLOG_TYPE,
4219 hdd_ctx->config->enableFwLogType,
4220 DBG_CMD);
4221 if (ret != 0)
4222 hdd_err("Failed to enable FW log type ret %d",
4223 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304224
4225 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304226 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004227 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304228 WMI_DBGLOG_LOG_LEVEL,
4229 hdd_ctx->config->enableFwLogLevel,
4230 DBG_CMD);
4231 if (ret != 0)
4232 hdd_err("Failed to enable FW log level ret %d",
4233 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304234
4235 hdd_string_to_u8_array(
4236 hdd_ctx->config->enableFwModuleLogLevel,
4237 moduleloglevel,
4238 &numentries,
4239 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4240
4241 while (count < numentries) {
4242 /*
4243 * FW module log level input string looks like
4244 * below:
4245 * gFwDebugModuleLoglevel=<FW Module ID>,
4246 * <Log Level>,...
4247 * For example:
4248 * gFwDebugModuleLoglevel=
4249 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4250 * Above input string means :
4251 * For FW module ID 1 enable log level 0
4252 * For FW module ID 2 enable log level 1
4253 * For FW module ID 3 enable log level 2
4254 * For FW module ID 4 enable log level 3
4255 * For FW module ID 5 enable log level 4
4256 * For FW module ID 6 enable log level 5
4257 * For FW module ID 7 enable log level 6
4258 */
4259
Nishank Aggarwale239d962017-03-03 12:26:02 +05304260 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4261 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4262 hdd_err("Module id %d and dbglog level %d input length is more than max",
4263 moduleloglevel[count],
4264 moduleloglevel[count + 1]);
4265 return;
4266 }
4267
4268 value = moduleloglevel[count] << 16;
4269 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004270 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304271 WMI_DBGLOG_MOD_LOG_LEVEL,
4272 value, DBG_CMD);
4273 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304274 hdd_err("Failed to enable FW module log level %d ret %d",
4275 value, ret);
4276
4277 count += 2;
4278 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304279
Arun Khandavalli2358d522016-05-16 18:05:37 +05304280}
4281#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004282static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004283 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304284{
4285}
4286
4287#endif
4288
4289/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004290 * hdd_configure_chain_mask() - programs chain mask to firmware
4291 * @adapter: HDD adapter
4292 *
4293 * Return: 0 on success or errno on failure
4294 */
4295static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4296{
4297 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004298 QDF_STATUS status;
4299 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004300 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4301
4302 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4303 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4304 hdd_ctx->config->txchainmask1x1,
4305 hdd_ctx->config->rxchainmask1x1);
4306 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4307 hdd_ctx->config->dual_mac_feature_disable,
4308 hdd_ctx->config->tx_chain_mask_2g,
4309 hdd_ctx->config->rx_chain_mask_2g);
4310 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4311 hdd_ctx->config->tx_chain_mask_5g,
4312 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004313 hdd_debug("enable_bt_chain_separation %d",
4314 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004315
Naveen Rawat98322472018-03-06 10:29:42 -08004316 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4317 HW_MODE_DBS_NONE,
4318 CDS_BAND_ALL);
4319 if (QDF_IS_STATUS_ERROR(status)) {
4320 hdd_err("couldn't get phy caps. skip chain mask programming");
4321 return qdf_status_to_os_return(status);
4322 }
4323
4324 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4325 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4326 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4327 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
4328 hdd_info("firmware not capable. skip chain mask programming");
4329 return 0;
4330 }
4331
Liangwei Dong22810e82018-03-15 03:42:12 -04004332 if (hdd_ctx->config->enable2x2 &&
4333 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004334 hdd_info("2x2 enabled. skip chain mask programming");
4335 return 0;
4336 }
4337
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004338 if (hdd_ctx->config->dual_mac_feature_disable !=
4339 DISABLE_DBS_CXN_AND_SCAN) {
4340 hdd_info("DBS enabled(%d). skip chain mask programming",
4341 hdd_ctx->config->dual_mac_feature_disable);
4342 return 0;
4343 }
4344
Naveen Rawatdacb5032018-02-08 15:23:24 -08004345 if (hdd_ctx->lte_coex_ant_share) {
4346 hdd_info("lte ant sharing enabled. skip chainmask programming");
4347 return 0;
4348 }
4349
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004350 if (hdd_ctx->config->txchainmask1x1) {
4351 ret_val = sme_cli_set_command(adapter->session_id,
4352 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4353 hdd_ctx->config->txchainmask1x1,
4354 PDEV_CMD);
4355 if (ret_val)
4356 goto error;
4357 }
4358
4359 if (hdd_ctx->config->rxchainmask1x1) {
4360 ret_val = sme_cli_set_command(adapter->session_id,
4361 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4362 hdd_ctx->config->rxchainmask1x1,
4363 PDEV_CMD);
4364 if (ret_val)
4365 goto error;
4366 }
4367
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004368 if (hdd_ctx->config->txchainmask1x1 ||
4369 hdd_ctx->config->rxchainmask1x1) {
4370 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4371 return 0;
4372 }
4373
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004374 if (hdd_ctx->config->tx_chain_mask_2g) {
4375 ret_val = sme_cli_set_command(adapter->session_id,
4376 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4377 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4378 if (0 != ret_val)
4379 goto error;
4380 }
4381
4382 if (hdd_ctx->config->rx_chain_mask_2g) {
4383 ret_val = sme_cli_set_command(adapter->session_id,
4384 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4385 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4386 if (0 != ret_val)
4387 goto error;
4388 }
4389
4390 if (hdd_ctx->config->tx_chain_mask_5g) {
4391 ret_val = sme_cli_set_command(adapter->session_id,
4392 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4393 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4394 if (0 != ret_val)
4395 goto error;
4396 }
4397
4398 if (hdd_ctx->config->rx_chain_mask_5g) {
4399 ret_val = sme_cli_set_command(adapter->session_id,
4400 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4401 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4402 if (0 != ret_val)
4403 goto error;
4404 }
4405
4406 return 0;
4407
4408error:
4409 hdd_err("WMI PDEV set param failed %d", ret_val);
4410 return -EINVAL;
4411}
4412
4413/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304414 * hdd_set_fw_params() - Set parameters to firmware
4415 * @adapter: HDD adapter
4416 *
4417 * This function Sets various parameters to fw once the
4418 * adapter is started.
4419 *
4420 * Return: 0 on success or errno on failure
4421 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004422int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304423{
4424 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004425 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304426
Dustin Brownfdf17c12018-03-14 12:55:34 -07004427 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304428
4429 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4430 if (!hdd_ctx)
4431 return -EINVAL;
4432
Dustin Brown732ab9c2017-06-15 13:24:09 -07004433 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4434 hdd_debug("FTM Mode is active; nothing to do");
4435 return 0;
4436 }
4437
Jeff Johnson1b780e42017-10-31 14:11:45 -07004438 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304439 WMI_PDEV_PARAM_DTIM_SYNTH,
4440 hdd_ctx->config->enable_lprx, PDEV_CMD);
4441 if (ret) {
4442 hdd_err("Failed to set LPRx");
4443 goto error;
4444 }
4445
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304446
4447 ret = sme_cli_set_command(
4448 adapter->session_id,
4449 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4450 hdd_ctx->config->enable_dtim_selection_diversity,
4451 PDEV_CMD);
4452 if (ret) {
4453 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4454 goto error;
4455 }
4456
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304457 ret = sme_cli_set_command(
4458 adapter->session_id,
4459 WMI_PDEV_PARAM_TX_SCH_DELAY,
4460 hdd_ctx->config->enable_tx_sch_delay,
4461 PDEV_CMD);
4462 if (ret) {
4463 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4464 goto error;
4465 }
4466
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304467 ret = sme_cli_set_command(
4468 adapter->session_id,
4469 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4470 hdd_ctx->config->enable_secondary_rate,
4471 PDEV_CMD);
4472 if (ret) {
4473 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4474 goto error;
4475 }
4476
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304477 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004478 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304479 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4480 hdd_ctx->config->upper_brssi_thresh);
4481
Jeff Johnson1b780e42017-10-31 14:11:45 -07004482 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304483 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4484 hdd_ctx->config->lower_brssi_thresh);
4485
Jeff Johnson1b780e42017-10-31 14:11:45 -07004486 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304487 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4488 hdd_ctx->config->enable_dtim_1chrx);
4489 }
4490
Dustin Brown732ab9c2017-06-15 13:24:09 -07004491 if (hdd_ctx->config->enable2x2) {
4492 hdd_debug("configuring 2x2 mode fw params");
4493
Jeff Johnson1b780e42017-10-31 14:11:45 -07004494 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004495 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4496 hdd_ctx->config->enable_cck_tx_fir_override,
4497 PDEV_CMD);
4498 if (ret) {
4499 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4500 ret);
4501 goto error;
4502 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004503
4504 if (hdd_configure_chain_mask(adapter))
4505 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004506 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304507#define HDD_DTIM_1CHAIN_RX_ID 0x5
4508#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004509 hdd_debug("configuring 1x1 mode fw params");
4510
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004511 /*
4512 * Disable DTIM 1 chain Rx when in 1x1,
4513 * we are passing two value
4514 * as param_id << 29 | param_value.
4515 * Below param_value = 0(disable)
4516 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004517 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004518 WMI_STA_SMPS_PARAM_CMDID,
4519 HDD_DTIM_1CHAIN_RX_ID <<
4520 HDD_SMPS_PARAM_VALUE_S,
4521 VDEV_CMD);
4522 if (ret) {
4523 hdd_err("DTIM 1 chain set failed %d", ret);
4524 goto error;
4525 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304526
Arun Khandavalli2358d522016-05-16 18:05:37 +05304527#undef HDD_DTIM_1CHAIN_RX_ID
4528#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004529
4530 if (hdd_configure_chain_mask(adapter))
4531 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004532 }
4533
Jeff Johnson1b780e42017-10-31 14:11:45 -07004534 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004535 WMI_PDEV_PARAM_HYST_EN,
4536 hdd_ctx->config->enableMemDeepSleep,
4537 PDEV_CMD);
4538 if (ret) {
4539 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4540 goto error;
4541 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304542
Jeff Johnson1b780e42017-10-31 14:11:45 -07004543 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004544 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4545 hdd_ctx->config->rts_profile,
4546 VDEV_CMD);
4547 if (ret) {
4548 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4549 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304550 }
4551
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004552 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4553
Jeff Johnson1b780e42017-10-31 14:11:45 -07004554 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004555 GEN_VDEV_PARAM_AMSDU,
4556 hdd_ctx->config->max_amsdu_num,
4557 GEN_CMD);
4558 if (ret != 0) {
4559 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4560 goto error;
4561 }
4562
Arun Khandavalli2358d522016-05-16 18:05:37 +05304563 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004564 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004565
Arun Khandavalli2358d522016-05-16 18:05:37 +05304566 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304567
Arun Khandavalli2358d522016-05-16 18:05:37 +05304568error:
4569 return -EINVAL;
4570}
4571
Ryan Hsu07495ea2016-01-21 15:25:39 -08004572/**
4573 * hdd_open_adapter() - open and setup the hdd adatper
4574 * @hdd_ctx: global hdd context
4575 * @session_type: type of the interface to be created
4576 * @iface_name: User-visible name of the interface
4577 * @macAddr: MAC address to assign to the interface
4578 * @name_assign_type: the name of assign type of the netdev
4579 * @rtnl_held: the rtnl lock hold flag
4580 *
4581 * This function open and setup the hdd adpater according to the device
4582 * type request, assign the name, the mac address assigned, and then prepared
4583 * the hdd related parameters, queue, lock and ready to start.
4584 *
4585 * Return: the pointer of hdd adapter, otherwise NULL.
4586 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004587struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004588 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004589 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004590 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004591{
Jeff Johnson9d295242017-08-29 14:39:48 -07004592 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304593 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004594
4595 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4596 /*
4597 * Max limit reached on the number of vdevs configured by the
4598 * host. Return error
4599 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304600 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4601 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004602 return NULL;
4603 }
4604
4605 if (macAddr == NULL) {
4606 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304607 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004608 return NULL;
4609 }
4610 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304611 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304612 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4613 " already exists",
4614 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004615 return NULL;
4616 }
4617
4618 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004619 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004620 /* Reset locally administered bit if the device mode is STA */
4621 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304622 hdd_info("locally administered bit reset in sta mode: "
4623 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004625 case QDF_P2P_CLIENT_MODE:
4626 case QDF_P2P_DEVICE_MODE:
4627 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004628 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304629 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004630 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4631 name_assign_type,
4632 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004633
4634 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304635 hdd_err("failed to allocate adapter for session %d",
4636 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004637 return NULL;
4638 }
4639
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004640 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004641 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004642 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004643 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304644 else if (QDF_MONITOR_MODE == session_type)
4645 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004646 else
4647 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4648
4649 adapter->device_mode = session_type;
4650
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004652 /*
4653 * Workqueue which gets scheduled in IPv4 notification
4654 * callback
4655 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004656 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004657 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004658
4659#ifdef WLAN_NS_OFFLOAD
4660 /*
4661 * Workqueue which gets scheduled in IPv6
4662 * notification callback.
4663 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004664 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004665 hdd_ipv6_notifier_work_queue);
4666#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004668 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004669 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004670
4671 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004672 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004673 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304674 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4675 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304676
Ravi Joshi1a292562017-05-18 16:28:54 -07004677 /* Initialize NAN Data Interface */
4678 if (QDF_NDI_MODE == session_type) {
4679 status = hdd_init_nan_data_mode(adapter);
4680 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004681 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004682 }
4683
Alok Kumarb64650c2018-03-23 17:05:11 +05304684 hdd_nud_init_tracking(adapter);
4685
4686 qdf_mutex_create(&adapter->disconnection_status_lock);
4687
Ravi Joshi1a292562017-05-18 16:28:54 -07004688 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004689
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004690 case QDF_P2P_GO_MODE:
4691 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004692 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4693 name_assign_type,
4694 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004695 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004696 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304697 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004698 return NULL;
4699 }
4700
4701 adapter->wdev.iftype =
4702 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004703 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004704 NL80211_IFTYPE_P2P_GO;
4705 adapter->device_mode = session_type;
4706
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004707 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004708 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004709 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004710
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004711 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304713 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4714 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304715
4716 /*
4717 * Workqueue which gets scheduled in IPv4 notification
4718 * callback
4719 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004720 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304721 hdd_ipv4_notifier_work_queue);
4722
4723#ifdef WLAN_NS_OFFLOAD
4724 /*
4725 * Workqueue which gets scheduled in IPv6
4726 * notification callback.
4727 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004728 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304729 hdd_ipv6_notifier_work_queue);
4730#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004731 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304732 case QDF_FTM_MODE:
4733 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4734 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004735 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304736 if (NULL == adapter) {
4737 hdd_err("Failed to allocate adapter for FTM mode");
4738 return NULL;
4739 }
4740 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4741 adapter->device_mode = session_type;
4742 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004743 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004744 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004745
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304746 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004747 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304748 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304749 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4750 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304751 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004752 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004753 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304754 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004755 return NULL;
4756 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004757
hqueaa33ee2017-05-04 17:56:35 +08004758 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4759
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304760 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004761 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004762 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004763 }
4764
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304765 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766 if (NULL != adapter) {
4767 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4768 adapter = NULL;
4769 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004771 return NULL;
4772 }
4773
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304774 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004775 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4776 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004778 /* Adapter successfully added. Increment the vdev count */
4779 hdd_ctx->current_intf_count++;
4780
Jeff Johnson5880d792016-08-15 13:32:30 -07004781 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004782 hdd_ctx->current_intf_count);
4783
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004784 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004785 }
4786
Rajeev Kumardca5f812016-02-04 17:28:06 -08004787 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004788 hdd_err("Interface %s wow debug_fs init failed",
4789 netdev_name(adapter->dev));
4790
4791 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4792 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793
4794 return adapter;
4795
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004796err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004797 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304798 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004799
4800 return NULL;
4801}
4802
Nirav Shaheb017be2018-02-15 11:20:58 +05304803#ifdef MSM_PLATFORM
4804static inline
4805void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4806{
4807 cancel_work_sync(&hdd_ctx->bus_bw_work);
4808}
4809#else
4810static inline
4811void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4812{
4813}
4814#endif
4815
Jeff Johnson9d295242017-08-29 14:39:48 -07004816QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004817 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004818{
Dustin Brown920397d2017-12-13 16:27:50 -08004819 /*
4820 * Here we are stopping global bus_bw timer & work per adapter.
4821 *
4822 * The reason is to fix one race condition between
4823 * bus bandwidth work and cleaning up an adapter.
4824 * Under some conditions, it is possible for the bus bandwidth
4825 * work to access a particularly destroyed adapter, leading to
4826 * use-after-free.
4827 */
4828 hdd_debug("wait for bus bw work to flush");
4829 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4830 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004831
Dustin Brown920397d2017-12-13 16:27:50 -08004832 /* cleanup adapter */
4833 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4834 adapter->device_mode);
4835 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4836 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004837
Dustin Brown920397d2017-12-13 16:27:50 -08004838 /* conditionally restart the bw timer */
4839 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004840
Dustin Brown920397d2017-12-13 16:27:50 -08004841 /* Adapter removed. Decrement vdev count */
4842 if (hdd_ctx->current_intf_count != 0)
4843 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004844
Dustin Brown920397d2017-12-13 16:27:50 -08004845 /* Fw will take care incase of concurrency */
4846 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004847}
4848
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004849/**
4850 * hdd_close_all_adapters - Close all open adapters
4851 * @hdd_ctx: Hdd context
4852 * rtnl_held: True if RTNL lock held
4853 *
4854 * Close all open adapters.
4855 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304856 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004857 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004858QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004859{
Dustin Brown920397d2017-12-13 16:27:50 -08004860 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304861 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004862
Dustin Brown491d54b2018-03-14 12:39:11 -07004863 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004864
4865 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004866 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4867 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304868 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004869 adapter->mac_addr.bytes);
4870 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4871
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304872 /* Adapter removed. Decrement vdev count */
4873 if (hdd_ctx->current_intf_count != 0)
4874 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004875 }
Dustin Brown920397d2017-12-13 16:27:50 -08004876 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004877
Dustin Browne74003f2018-03-14 12:51:58 -07004878 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004879
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304880 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004881}
4882
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004883void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004884{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304885 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004886 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004887
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004888 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004889 case QDF_STA_MODE:
4890 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004891 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004892 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004893 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004894 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004895 break;
4896 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004897 case QDF_SAP_MODE:
4898 case QDF_P2P_GO_MODE:
4899 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004901 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004902 break;
4903 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004904 case QDF_FTM_MODE:
4905 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004906 default:
4907 /*
4908 * wlan_hdd_reset_prob_rspies should not have been called
4909 * for these kind of devices
4910 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004911 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004912 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004913 return;
4914 }
4915
Anurag Chouhanc5548422016-02-24 18:33:27 +05304916 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004917 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004918 updateIE.ieBufferlength = 0;
4919 updateIE.pAdditionIEBuffer = NULL;
4920 updateIE.append = true;
4921 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004922 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004923 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304924 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004925 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004926 }
4927}
4928
Dustin Browndb2a8be2017-12-20 11:49:56 -08004929QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4930 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004931{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304932 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07004933 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004934 union iwreq_data wrqu;
4935 tSirUpdateIE updateIE;
4936 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07004937 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004938
Dustin Brown491d54b2018-03-14 12:39:11 -07004939 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004940
Dustin Browne7e71d32018-05-11 16:00:08 -07004941 if (adapter->session_id != HDD_SESSION_ID_INVALID)
4942 wlan_hdd_cfg80211_deregister_frames(adapter);
4943
Alok Kumarb64650c2018-03-23 17:05:11 +05304944 hdd_nud_ignore_tracking(adapter, true);
4945 hdd_nud_reset_tracking(adapter);
4946
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004947 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304948 wlan_hdd_netif_queue_control(adapter,
4949 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4950 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004951 /*
4952 * if this is the last active connection check & stop the
4953 * opportunistic timer first
4954 */
4955 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4956 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4957 policy_mgr_convert_device_mode_to_qdf_type(
4958 adapter->device_mode), NULL) == 1)) ||
4959 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4960 policy_mgr_check_and_stop_opportunistic_timer(
4961 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004962 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004963 case QDF_STA_MODE:
4964 case QDF_P2P_CLIENT_MODE:
4965 case QDF_IBSS_MODE:
4966 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004967 case QDF_NDI_MODE:
4968 if ((QDF_NDI_MODE == adapter->device_mode) ||
4969 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004970 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4971 hdd_is_connecting(
4972 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004973 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07004974 roam_profile = hdd_roam_profile(adapter);
4975 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004976 if (QDF_NDI_MODE == adapter->device_mode)
4977 qdf_ret_status = sme_roam_disconnect(
4978 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004979 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004980 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07004981 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004982 eCSR_BSS_TYPE_START_IBSS)
4983 qdf_ret_status = sme_roam_disconnect(
4984 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004985 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004986 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004987 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004988 qdf_ret_status =
4989 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004990 hdd_debug("Send disconnected event to userspace");
4991 wlan_hdd_cfg80211_indicate_disconnect(
4992 adapter->dev, true,
4993 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08004994 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004995 qdf_ret_status = sme_roam_disconnect(
4996 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004997 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004998 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004999 /* success implies disconnect command got
5000 * queued up successfully
5001 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005002 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
5003 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005004 rc = wait_for_completion_timeout(
5005 &adapter->disconnect_comp_var,
5006 msecs_to_jiffies
5007 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005008 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005009 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005010 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005011 if (qdf_ret_status != QDF_STATUS_SUCCESS)
5012 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005013 memset(&wrqu, '\0', sizeof(wrqu));
5014 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5015 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5016 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5017 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305018 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08005019 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005020
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305021 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305022 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023
5024#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005025 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005026#endif
5027
5028 hdd_deregister_tx_flow_control(adapter);
5029
5030#ifdef WLAN_NS_OFFLOAD
5031#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005032 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005033#endif
5034#endif
5035
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305036 if (adapter->device_mode == QDF_STA_MODE)
5037 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5038 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005039
5040 if (wlan_hdd_try_disconnect(adapter)) {
5041 hdd_err("Error: Can't disconnect adapter");
5042 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005043 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005044
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305045 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005046 break;
5047
Rajeev Kumar3b906202018-02-01 10:55:14 -08005048 case QDF_MONITOR_MODE:
5049 wlan_hdd_scan_abort(adapter);
5050 hdd_deregister_tx_flow_control(adapter);
5051 hdd_vdev_destroy(adapter);
5052 break;
5053
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005054 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08005055 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305056 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305057 sap_config = &adapter->session.ap.sap_config;
5058 if (sap_config)
5059 wlansap_reset_sap_config_add_ie(sap_config,
5060 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305061 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08005062 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005063 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005064
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005065 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07005066 if (QDF_SAP_MODE == adapter->device_mode) {
5067 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5068 cds_flush_delayed_work(
5069 &adapter->acs_pending_work);
5070 clear_bit(ACS_PENDING, &adapter->event_flags);
5071 }
5072 }
Krunal Soni22208392017-09-29 18:10:34 -07005073 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005074
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005075 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305076 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005077 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005078 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5080
5081 hdd_deregister_tx_flow_control(adapter);
5082
Kapil Guptac1224bf2017-06-22 21:22:40 +05305083 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084 mutex_lock(&hdd_ctx->sap_lock);
5085 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305086 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305087 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005088
5089 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005090 status = wlansap_stop_bss(
5091 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005092
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305093 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005094 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005095 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305096 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305097 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305098 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305099 qdf_wait_for_event_completion(
5100 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005101 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005102
Anurag Chouhance0dc992016-02-16 18:18:03 +05305103 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005104 hdd_err("failure waiting for wlansap_stop_bss %d",
5105 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005106 }
5107 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005108 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005109 }
5110 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005111 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5112 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005113 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005114 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305115 adapter->device_mode,
5116 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005117
Anurag Chouhanc5548422016-02-24 18:33:27 +05305118 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005119 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005120 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005121 updateIE.ieBufferlength = 0;
5122 updateIE.pAdditionIEBuffer = NULL;
5123 updateIE.append = false;
5124 updateIE.notify = false;
5125 /* Probe bcn reset */
5126 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5127 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305128 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005129 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130 }
5131 /* Assoc resp reset */
5132 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5133 &updateIE,
5134 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305135 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005136 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005137 }
5138 /* Reset WNI_CFG_PROBE_RSP Flags */
5139 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005140 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005141 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005142 qdf_mem_free(adapter->session.ap.beacon);
5143 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005144
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305145 /*
5146 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5147 */
5148 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5149 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5150
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305151#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005152 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305153#endif
5154
5155#ifdef WLAN_NS_OFFLOAD
5156#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005157 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305158#endif
5159#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005160
5161 hdd_vdev_destroy(adapter);
5162
Krunal Sonib51eec72017-11-20 21:53:01 -08005163 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005164 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005165 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005166 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005167 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005168 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005169 hdd_deregister_tx_flow_control(adapter);
5170 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005171 break;
5172 default:
5173 break;
5174 }
5175
Dustin Brown04348372017-12-14 16:13:39 -08005176 if (adapter->scan_info.default_scan_ies) {
5177 qdf_mem_free(adapter->scan_info.default_scan_ies);
5178 adapter->scan_info.default_scan_ies = NULL;
5179 }
5180
Dustin Browne74003f2018-03-14 12:51:58 -07005181 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005182
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305183 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005184}
5185
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305186/**
5187 * hdd_deinit_all_adapters - deinit all adapters
5188 * @hdd_ctx: HDD context
5189 * @rtnl_held: True if RTNL lock held
5190 *
5191 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005192void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305193{
Jeff Johnson9d295242017-08-29 14:39:48 -07005194 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305195
Dustin Brown491d54b2018-03-14 12:39:11 -07005196 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305197
Dustin Brown920397d2017-12-13 16:27:50 -08005198 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305199 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305200
Dustin Browne74003f2018-03-14 12:51:58 -07005201 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305202}
5203
Dustin Browndb2a8be2017-12-20 11:49:56 -08005204QDF_STATUS hdd_stop_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;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207
Dustin Brown491d54b2018-03-14 12:39:11 -07005208 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305210 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5211
Dustin Brown920397d2017-12-13 16:27:50 -08005212 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005213 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214
Dustin Browne74003f2018-03-14 12:51:58 -07005215 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305217 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218}
5219
Paul Zhang84fa9382017-11-10 21:18:21 +08005220static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5221 struct hdd_adapter *adapter)
5222{
5223 switch (adapter->device_mode) {
5224 case QDF_STA_MODE:
5225 case QDF_P2P_CLIENT_MODE:
5226 case QDF_IBSS_MODE:
5227 case QDF_P2P_DEVICE_MODE:
5228 case QDF_NDI_MODE:
5229 wlan_hdd_scan_abort(adapter);
5230 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5231 if (adapter->device_mode == QDF_STA_MODE)
5232 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5233 adapter->dev);
5234 break;
5235 case QDF_P2P_GO_MODE:
5236 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5237 break;
5238 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305239 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005240 wlan_hdd_undo_acs(adapter);
5241 break;
5242 default:
5243 break;
5244 }
5245}
5246
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005247QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005248{
Jeff Johnson9d295242017-08-29 14:39:48 -07005249 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005250 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005251 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005252 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253
Dustin Brown491d54b2018-03-14 12:39:11 -07005254 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005255
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305256 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5257
Dustin Brown920397d2017-12-13 16:27:50 -08005258 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005259 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5260 hdd_device_mode_to_string(adapter->device_mode),
5261 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305262
5263 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005264 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305265 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005266 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005267 adapter->session.station.hdd_reassoc_scenario = false;
5268 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305269
Arun Khandavallicc544b32017-01-30 19:52:16 +05305270 if (hdd_ctx->config->sap_internal_restart &&
5271 adapter->device_mode == QDF_SAP_MODE) {
5272 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305273 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305274 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005275 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005276 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005277 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005278 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5279 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305280 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305281 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005283 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284
Paul Zhang84fa9382017-11-10 21:18:21 +08005285 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005286
5287 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005288 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005289 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005290 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305291 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005292 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5293 hdd_wmm_adapter_close(adapter);
5294 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5295 }
5296
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305297 if (adapter->device_mode == QDF_STA_MODE)
5298 hdd_clear_fils_connection_info(adapter);
5299
Wu Gao3545e642017-07-14 19:24:41 +08005300 if (adapter->device_mode == QDF_SAP_MODE) {
5301 /*
5302 * If adapter is SAP, set session ID to invalid
5303 * since SAP session will be cleanup during SSR.
5304 */
Wu Gao36717432016-11-21 15:09:48 +08005305 wlansap_set_invalid_session(
5306 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5307
Wu Gao3545e642017-07-14 19:24:41 +08005308 wlansap_cleanup_cac_timer(
5309 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5310 }
5311
Yue Ma42654682018-01-11 16:55:24 -08005312 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005313 if (adapter->device_mode == QDF_STA_MODE ||
5314 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005315 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005316 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005317 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005318
5319 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5320 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005321 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005322 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005323 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5324 if (adapter->sta_info[sta_id].in_use) {
5325 hdd_debug("[SSR] deregister STA with ID %d",
5326 sta_id);
5327 hdd_softap_deregister_sta(adapter,
5328 sta_id);
5329 adapter->sta_info[sta_id].in_use = 0;
5330 }
5331 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005332 }
5333
Alok Kumarb64650c2018-03-23 17:05:11 +05305334 hdd_nud_reset_tracking(adapter);
5335 hdd_nud_ignore_tracking(adapter, true);
5336 hdd_set_disconnect_status(adapter, false);
5337
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005338 hdd_softap_deinit_tx_rx(adapter);
5339
Yue Maf9782842017-05-08 12:49:49 -07005340 /* Destroy vdev which will be recreated during reinit. */
5341 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005342 }
5343
Dustin Browne74003f2018-03-14 12:51:58 -07005344 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005345
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305346 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005347}
5348
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005349bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305350{
Dustin Brown920397d2017-12-13 16:27:50 -08005351 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305352 bool close_modules = true;
5353
Arun Khandavalliba479c42017-07-26 21:29:40 +05305354 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5355 hdd_info("FTM mode, don't close the module");
5356 return false;
5357 }
5358
Dustin Brown920397d2017-12-13 16:27:50 -08005359 hdd_for_each_adapter(hdd_ctx, adapter) {
5360 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5361 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005362 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305363 close_modules = false;
5364 break;
5365 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305366 }
5367
5368 return close_modules;
5369}
5370
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305371bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305372{
5373 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5374 return true;
5375 else
5376 return false;
5377}
5378
Anurag Chouhanc4092922016-09-08 15:56:11 +05305379#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005380 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305381struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5382 struct ieee80211_channel *channel,
5383 const u8 *bssid, const u8 *ssid,
5384 size_t ssid_len)
5385{
5386 return cfg80211_get_bss(wiphy, channel, bssid,
5387 ssid, ssid_len,
5388 WLAN_CAPABILITY_ESS,
5389 WLAN_CAPABILITY_ESS);
5390}
5391#else
5392struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5393 struct ieee80211_channel *channel,
5394 const u8 *bssid, const u8 *ssid,
5395 size_t ssid_len)
5396{
5397 return cfg80211_get_bss(wiphy, channel, bssid,
5398 ssid, ssid_len,
5399 IEEE80211_BSS_TYPE_ESS,
5400 IEEE80211_PRIVACY_ANY);
5401}
5402#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305403
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305404#if defined CFG80211_CONNECT_BSS || \
5405 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305406#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305407 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305408/**
5409 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5410 * @timeout_reason: reason for connect timeout
5411 *
5412 * This function is used to convert host timeout
5413 * reason enum to kernel specific enum.
5414 *
5415 * Return: nl timeout enum
5416 */
5417static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5418 tSirResultCodes timeout_reason)
5419{
5420 switch (timeout_reason) {
5421 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5422 return NL80211_TIMEOUT_SCAN;
5423 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5424 return NL80211_TIMEOUT_AUTH;
5425 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5426 return NL80211_TIMEOUT_ASSOC;
5427 default:
5428 return NL80211_TIMEOUT_UNSPECIFIED;
5429 }
5430}
5431
5432/**
5433 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5434 * @dev: network device
5435 * @bssid: bssid to which we want to associate
5436 * @timeout_reason: reason for connect timeout
5437 *
5438 * This API is used to send connection timeout reason to supplicant
5439 *
5440 * Return: void
5441 */
5442static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5443 const u8 *bssid,
5444 tSirResultCodes timeout_reason)
5445{
5446 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005447
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305448 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5449
5450 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5451 nl_timeout_reason);
5452}
5453
5454/**
5455 * __hdd_connect_bss() - API to send connection status to supplicant
5456 * @dev: network device
5457 * @bssid: bssid to which we want to associate
5458 * @req_ie: Request Information Element
5459 * @req_ie_len: len of the req IE
5460 * @resp_ie: Response IE
5461 * @resp_ie_len: len of ht response IE
5462 * @status: status
5463 * @gfp: Kernel Flag
5464 * @timeout_reason: reason for connect timeout
5465 *
5466 * Return: void
5467 */
5468static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5469 struct cfg80211_bss *bss, const u8 *req_ie,
5470 size_t req_ie_len, const u8 *resp_ie,
5471 size_t resp_ie_len, int status, gfp_t gfp,
5472 tSirResultCodes timeout_reason)
5473{
5474 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005475
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305476 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5477
5478 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5479 resp_ie, resp_ie_len, status, gfp,
5480 nl_timeout_reason);
5481}
5482#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305483#if defined CFG80211_CONNECT_TIMEOUT || \
5484 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305485static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5486 const u8 *bssid,
5487 tSirResultCodes timeout_reason)
5488{
5489 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5490}
5491#endif
5492
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,
5497 tSirResultCodes timeout_reason)
5498{
5499 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5500 resp_ie, resp_ie_len, status, gfp);
5501}
5502#endif
5503
Abhishek Singha84d3952016-09-13 13:45:05 +05305504/**
5505 * hdd_connect_bss() - API to send connection status to supplicant
5506 * @dev: network device
5507 * @bssid: bssid to which we want to associate
5508 * @req_ie: Request Information Element
5509 * @req_ie_len: len of the req IE
5510 * @resp_ie: Response IE
5511 * @resp_ie_len: len of ht response IE
5512 * @status: status
5513 * @gfp: Kernel Flag
5514 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305515 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305516 *
5517 * The API is a wrapper to send connection status to supplicant
5518 *
5519 * Return: Void
5520 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305521#if defined CFG80211_CONNECT_TIMEOUT || \
5522 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305523static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5524 struct cfg80211_bss *bss, const u8 *req_ie,
5525 size_t req_ie_len, const u8 *resp_ie,
5526 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305527 bool connect_timeout,
5528 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305529{
5530 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305531 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305532 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305533 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5534 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305535}
5536#else
5537static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5538 struct cfg80211_bss *bss, const u8 *req_ie,
5539 size_t req_ie_len, const u8 *resp_ie,
5540 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305541 bool connect_timeout,
5542 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305543{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305544 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5545 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305546}
5547#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305548
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305549#if defined(WLAN_FEATURE_FILS_SK)
5550#if defined(CFG80211_CONNECT_DONE) || \
5551 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5552#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5553 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305554/**
5555 * hdd_populate_fils_params() - Populate FILS keys to connect response
5556 * @fils_params: connect response to supplicant
5557 * @fils_kek: FILS kek
5558 * @fils_kek_len: FILS kek length
5559 * @pmk: FILS PMK
5560 * @pmk_len: FILS PMK length
5561 * @pmkid: PMKID
5562 * @fils_seq_num: FILS Seq number
5563 *
5564 * Return: None
5565 */
5566static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5567 *fils_params, const uint8_t *fils_kek,
5568 size_t fils_kek_len, const uint8_t *pmk,
5569 size_t pmk_len, const uint8_t *pmkid,
5570 uint16_t fils_seq_num)
5571{
5572 /* Increament seq number to be used for next FILS */
5573 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5574 fils_params->update_erp_next_seq_num = true;
5575 fils_params->fils_kek = fils_kek;
5576 fils_params->fils_kek_len = fils_kek_len;
5577 fils_params->pmk = pmk;
5578 fils_params->pmk_len = pmk_len;
5579 fils_params->pmkid = pmkid;
5580}
5581#else
5582static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5583 *fils_params, const uint8_t
5584 *fils_kek, size_t fils_kek_len,
5585 const uint8_t *pmk, size_t pmk_len,
5586 const uint8_t *pmkid,
5587 uint16_t fils_seq_num)
5588{ }
5589#endif
5590
Jeff Johnson172237b2017-11-07 15:32:59 -08005591void hdd_update_hlp_info(struct net_device *dev,
5592 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305593{
5594 struct sk_buff *skb;
5595 uint16_t skb_len;
5596 struct llc_snap_hdr_t *llc_hdr;
5597 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305598 uint8_t *hlp_data;
5599 uint16_t hlp_data_len;
5600 struct fils_join_rsp_params *roam_fils_params
5601 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305602 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5603
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305604 if (!roam_fils_params) {
5605 hdd_err("FILS Roam Param NULL");
5606 return;
5607 }
5608
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005609 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305610 hdd_err("FILS HLP Data NULL, len %d",
5611 roam_fils_params->hlp_data_len);
5612 return;
5613 }
5614
5615 hlp_data = roam_fils_params->hlp_data;
5616 hlp_data_len = roam_fils_params->hlp_data_len;
5617
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305618 /* Calculate skb length */
5619 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5620 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5621 if (skb == NULL) {
5622 hdd_err("HLP packet nbuf alloc fails");
5623 return;
5624 }
5625
5626 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5627 QDF_MAC_ADDR_SIZE);
5628 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5629 QDF_MAC_ADDR_SIZE);
5630
5631 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5632 if (IS_SNAP(llc_hdr)) {
5633 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5634 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5635 }
5636
5637 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5638
5639 /*
5640 * This HLP packet is formed from HLP info encapsulated
5641 * in assoc response frame which is AEAD encrypted.
5642 * Hence, this checksum validation can be set unnecessary.
5643 * i.e. network layer need not worry about checksum.
5644 */
5645 skb->ip_summed = CHECKSUM_UNNECESSARY;
5646
5647 status = hdd_rx_packet_cbk(padapter, skb);
5648 if (QDF_IS_STATUS_ERROR(status)) {
5649 hdd_err("Sending HLP packet fails");
5650 return;
5651 }
5652 hdd_debug("send HLP packet to netif successfully");
5653}
5654
5655/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305656 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5657 * @dev: network device
5658 * @bssid: bssid to which we want to associate
5659 * @bss: cfg80211 bss info
5660 * @roam_info: information about connected bss
5661 * @req_ie: Request Information Element
5662 * @req_ie_len: len of the req IE
5663 * @resp_ie: Response IE
5664 * @resp_ie_len: len of ht response IE
5665 * @status: status
5666 * @gfp: allocation flags
5667 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5668 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305669 *
5670 * This API is used as wrapper to send FILS key/sequence number
5671 * params etc. to supplicant in case of FILS connection
5672 *
5673 * Return: None
5674 */
5675static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005676 struct cfg80211_bss *bss,
5677 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305678 const u8 *req_ie, size_t req_ie_len,
5679 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005680 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305681 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305682{
5683 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305684 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5685 struct fils_join_rsp_params *roam_fils_params =
5686 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005687
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305688 qdf_mem_zero(&fils_params, sizeof(fils_params));
5689
5690 if (!roam_fils_params) {
5691 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5692 } else {
5693 fils_params.status = status;
5694 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005695 fils_params.timeout_reason =
5696 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305697 fils_params.req_ie = req_ie;
5698 fils_params.req_ie_len = req_ie_len;
5699 fils_params.resp_ie = resp_ie;
5700 fils_params.resp_ie_len = resp_ie_len;
5701 fils_params.bss = bss;
5702 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5703 roam_fils_params->kek_len,
5704 roam_fils_params->fils_pmk,
5705 roam_fils_params->fils_pmk_len,
5706 roam_fils_params->fils_pmkid,
5707 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305708 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305709 }
5710 hdd_debug("FILS indicate connect status %d seq no %d",
5711 fils_params.status,
5712 fils_params.fils_erp_next_seq_num);
5713
5714 cfg80211_connect_done(dev, &fils_params, gfp);
5715
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305716 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305717 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305718
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305719 /* Clear all the FILS key info */
5720 if (roam_fils_params && roam_fils_params->fils_pmk)
5721 qdf_mem_free(roam_fils_params->fils_pmk);
5722 if (roam_fils_params)
5723 qdf_mem_free(roam_fils_params);
5724 roam_info->fils_join_rsp = NULL;
5725}
5726#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005727static inline void
5728hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005729 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005730 const u8 *req_ie, size_t req_ie_len,
5731 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5732 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305733 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305734{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305735#endif
5736#endif
5737
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305738#if defined(WLAN_FEATURE_FILS_SK) && \
5739 (defined(CFG80211_CONNECT_DONE) || \
5740 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305741/**
5742 * hdd_fils_update_connect_results() - API to send fils connection status to
5743 * supplicant.
5744 * @dev: network device
5745 * @bssid: bssid to which we want to associate
5746 * @bss: cfg80211 bss info
5747 * @roam_info: information about connected bss
5748 * @req_ie: Request Information Element
5749 * @req_ie_len: len of the req IE
5750 * @resp_ie: Response IE
5751 * @resp_ie_len: len of ht response IE
5752 * @status: status
5753 * @gfp: allocation flags
5754 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5755 * @timeout_reason: reason for connect timeout
5756 *
5757 * The API is a wrapper to send connection status to supplicant
5758 *
5759 * Return: 0 if success else failure
5760 */
5761static int hdd_fils_update_connect_results(struct net_device *dev,
5762 const u8 *bssid,
5763 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005764 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305765 size_t req_ie_len, const u8 *resp_ie,
5766 size_t resp_ie_len, u16 status, gfp_t gfp,
5767 bool connect_timeout,
5768 tSirResultCodes timeout_reason)
5769{
Dustin Brown491d54b2018-03-14 12:39:11 -07005770 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305771 if (!roam_info || !roam_info->is_fils_connection)
5772 return -EINVAL;
5773
5774 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5775 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305776 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305777 return 0;
5778}
5779#else
5780static inline int hdd_fils_update_connect_results(struct net_device *dev,
5781 const u8 *bssid,
5782 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005783 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305784 size_t req_ie_len, const u8 *resp_ie,
5785 size_t resp_ie_len, u16 status, gfp_t gfp,
5786 bool connect_timeout,
5787 tSirResultCodes timeout_reason)
5788{
5789 return -EINVAL;
5790}
5791#endif
5792
Anurag Chouhanc4092922016-09-08 15:56:11 +05305793/**
5794 * hdd_connect_result() - API to send connection status to supplicant
5795 * @dev: network device
5796 * @bssid: bssid to which we want to associate
5797 * @roam_info: information about connected bss
5798 * @req_ie: Request Information Element
5799 * @req_ie_len: len of the req IE
5800 * @resp_ie: Response IE
5801 * @resp_ie_len: len of ht response IE
5802 * @status: status
5803 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305804 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305805 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305806 *
5807 * The API is a wrapper to send connection status to supplicant
5808 * and allow runtime suspend
5809 *
5810 * Return: Void
5811 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305812void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005813 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305814 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305815 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305816 bool connect_timeout,
5817 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305818{
Jeff Johnson9d295242017-08-29 14:39:48 -07005819 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305820 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005821 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305822
5823 if (WLAN_STATUS_SUCCESS == status) {
5824 struct ieee80211_channel *chan;
5825 int freq;
5826 int chan_no = roam_info->pBssDesc->channelId;
5827
5828 if (chan_no <= 14)
5829 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005830 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305831 else
5832 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005833 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305834
5835 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5836 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5837 roam_info->u.pConnectedProfile->SSID.ssId,
5838 roam_info->u.pConnectedProfile->SSID.length);
5839 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305840
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305841 if (hdd_fils_update_connect_results(dev, bssid, bss,
5842 roam_info, req_ie, req_ie_len, resp_ie,
5843 resp_ie_len, status, gfp, connect_timeout,
5844 timeout_reason) != 0) {
5845 hdd_connect_bss(dev, bssid, bss, req_ie,
5846 req_ie_len, resp_ie, resp_ie_len,
5847 status, gfp, connect_timeout, timeout_reason);
5848 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305849
Jingxiang Geb49aa302018-01-17 20:54:15 +08005850 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005851 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305852}
5853#else
5854void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005855 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305856 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305857 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305858 bool connect_timeout,
5859 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305860{
Jeff Johnson9d295242017-08-29 14:39:48 -07005861 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005862 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305863
Anurag Chouhanc4092922016-09-08 15:56:11 +05305864 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5865 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005866
Jingxiang Geb49aa302018-01-17 20:54:15 +08005867 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005868 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305869}
5870#endif
5871
Jeff Johnsond9952752018-04-18 12:15:35 -07005872int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
5873 uint32_t bandwidth)
5874{
5875 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5876 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5877 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
5878 QDF_STATUS status;
5879 tHalHandle hal_hdl = hdd_ctx->hHal;
5880 struct qdf_mac_addr bssid;
5881 struct csr_roam_profile roam_profile;
5882 struct ch_params ch_params;
5883
5884 if (QDF_GLOBAL_MONITOR_MODE != hdd_get_conparam()) {
5885 hdd_err("Not supported, device is not in monitor mode");
5886 return -EINVAL;
5887 }
5888
Visweswara Tanuku006313a2018-04-12 12:26:34 +05305889 /* Validate Channel */
5890 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
5891 hdd_err("Channel %d Not supported", chan);
5892 return -EINVAL;
5893 }
5894
5895 if (WLAN_REG_IS_24GHZ_CH(chan)) {
5896 if (bandwidth == CH_WIDTH_80MHZ) {
5897 hdd_err("BW80 not possible in 2.4GHz band");
5898 return -EINVAL;
5899 }
5900 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
5901 (bandwidth != CH_WIDTH_MAX)) {
5902 hdd_err("Only BW20 possible on channel 14");
5903 return -EINVAL;
5904 }
5905 }
5906
5907 if (WLAN_REG_IS_5GHZ_CH(chan)) {
5908 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
5909 (bandwidth != CH_WIDTH_MAX)) {
5910 hdd_err("Only BW20 possible on channel 165");
5911 return -EINVAL;
5912 }
5913 }
5914
Jeff Johnsond9952752018-04-18 12:15:35 -07005915 hdd_debug("Set monitor mode Channel %d", chan);
5916 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
5917 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
5918 roam_profile.ChannelInfo.numOfChannels = 1;
5919 roam_profile.phyMode = ch_info->phy_mode;
5920 roam_profile.ch_params.ch_width = bandwidth;
5921 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
5922
5923 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
5924 QDF_MAC_ADDR_SIZE);
5925
5926 ch_params.ch_width = bandwidth;
5927 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
5928 if (ch_params.ch_width == CH_WIDTH_INVALID) {
5929 hdd_err("Invalid capture channel or bandwidth for a country");
5930 return -EINVAL;
5931 }
5932 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
5933 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
5934 hdd_err("Failed to change hw mode");
5935 return -EINVAL;
5936 }
5937
5938 status = sme_roam_channel_change_req(hal_hdl, bssid, &ch_params,
5939 &roam_profile);
5940 if (status) {
5941 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
5942 status);
5943 }
5944
5945 adapter->mon_chan = chan;
5946 adapter->mon_bandwidth = bandwidth;
5947 return qdf_status_to_os_return(status);
5948}
Anurag Chouhanc4092922016-09-08 15:56:11 +05305949
Wu Gaodf929f12018-05-25 18:12:25 +08005950#ifdef MSM_PLATFORM
5951/**
5952 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
5953 * @adapter: pointer to adapter
5954 *
5955 * This function calls cfg80211 API to stop P2P GO
5956 *
5957 * Return: None
5958 */
5959static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
5960{
5961 hdd_debug("[SSR] send stop ap to supplicant");
5962 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5963}
5964
5965static inline void hdd_delete_sta(struct hdd_adapter *adapter)
5966{
5967}
5968#else
5969static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
5970{
5971}
5972
5973/**
5974 * hdd_delete_sta() - call cfg80211 API to delete STA
5975 * @adapter: pointer to adapter
5976 *
5977 * This function calls cfg80211 API to delete STA
5978 *
5979 * Return: None
5980 */
5981static void hdd_delete_sta(struct hdd_adapter *adapter)
5982{
5983 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
5984
5985 hdd_debug("[SSR] send restart supplicant");
5986 /* event supplicant to restart */
5987 cfg80211_del_sta(adapter->dev,
5988 (const u8 *)&bcast_mac.bytes[0],
5989 GFP_KERNEL);
5990}
5991#endif
5992
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005993QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005994{
Jeff Johnson9d295242017-08-29 14:39:48 -07005995 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005996 eConnectionState connState;
5997
Dustin Brown491d54b2018-03-14 12:39:11 -07005998 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005999
Dustin Brown920397d2017-12-13 16:27:50 -08006000 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306001 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006002 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306003
Yue Ma42654682018-01-11 16:55:24 -08006004 hdd_debug("[SSR] start adapter with device mode %s(%d)",
6005 hdd_device_mode_to_string(adapter->device_mode),
6006 adapter->device_mode);
6007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006008 hdd_wmm_init(adapter);
6009
6010 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006011 case QDF_STA_MODE:
6012 case QDF_P2P_CLIENT_MODE:
6013 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006014
6015 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6016 ->conn_info.connState;
6017
Krunal Sonib51eec72017-11-20 21:53:01 -08006018 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006019 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006020 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006021
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006022 /* Indicate disconnect event to supplicant
6023 * if associated previously
6024 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006025 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006026 eConnectionState_IbssConnected == connState ||
6027 eConnectionState_NotConnected == connState ||
6028 eConnectionState_IbssDisconnected == connState ||
6029 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006030 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006031
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006032 memset(&wrqu, '\0', sizeof(wrqu));
6033 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6034 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6035 wireless_send_event(adapter->dev, SIOCGIWAP,
6036 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006037 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006038 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006039
6040 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306041 wlan_hdd_cfg80211_indicate_disconnect(
6042 adapter->dev, false,
6043 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044 } else if (eConnectionState_Connecting == connState) {
6045 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006046 * Indicate connect failure to supplicant if we
6047 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006048 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306049 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306050 NULL, 0, NULL, 0,
6051 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006052 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006053 }
6054
6055 hdd_register_tx_flow_control(adapter,
6056 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006057 hdd_tx_resume_cb,
6058 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006059
Alok Kumarb64650c2018-03-23 17:05:11 +05306060 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006061 break;
6062
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006063 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006064 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08006065 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306066
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006067 break;
6068
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006069 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006070 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006071 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306072 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006073 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306074 hdd_set_mon_rx_cb(adapter->dev);
6075 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6076 adapter->mon_bandwidth);
6077 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006078 default:
6079 break;
6080 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006081 /*
6082 * Action frame registered in one adapter which will
6083 * applicable to all interfaces
6084 */
6085 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006086 }
6087
Wu Gaodf929f12018-05-25 18:12:25 +08006088 hdd_for_each_adapter(hdd_ctx, adapter) {
6089 if (!hdd_is_interface_up(adapter))
6090 continue;
6091
6092 if (adapter->device_mode == QDF_P2P_GO_MODE)
6093 hdd_stop_p2p_go(adapter);
6094 }
6095
Dustin Browne74003f2018-03-14 12:51:58 -07006096 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006097
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306098 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006099}
6100
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006101QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006102 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006103{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306104 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006105 qdf_list_node_t *node;
6106
6107 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006108
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006109 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006110 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006111 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006112
6113 if (QDF_IS_STATUS_ERROR(status))
6114 return status;
6115
6116 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6117
6118 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006119}
6120
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006121QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006122 struct hdd_adapter *current_adapter,
6123 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006124{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306125 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006126 qdf_list_node_t *node;
6127
6128 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006129
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006130 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006131 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006132 &current_adapter->node,
6133 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006134 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006135
6136 if (QDF_IS_STATUS_ERROR(status))
6137 return status;
6138
6139 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6140
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006141 return status;
6142}
6143
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006144QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006145 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006146{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306147 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006148
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006149 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006150 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006151 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006152
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153 return status;
6154}
6155
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006156QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006157 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006158{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306159 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006160 qdf_list_node_t *node;
6161
6162 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006163
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006164 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006165 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006166 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006167
6168 if (QDF_IS_STATUS_ERROR(status))
6169 return status;
6170
6171 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6172
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173 return status;
6174}
6175
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006176QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006177 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006178{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306179 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006180
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006181 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006182 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006183 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185 return status;
6186}
6187
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006188QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006189 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006190{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306191 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006192
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006193 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006194 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006195 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006196
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006197 return status;
6198}
6199
Jeff Johnson9d295242017-08-29 14:39:48 -07006200struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201 tSirMacAddr macAddr)
6202{
Jeff Johnson9d295242017-08-29 14:39:48 -07006203 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204
Dustin Brown920397d2017-12-13 16:27:50 -08006205 hdd_for_each_adapter(hdd_ctx, adapter) {
6206 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6207 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006208 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209 }
6210
6211 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006212}
6213
Jeff Johnson9d295242017-08-29 14:39:48 -07006214struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215 uint32_t vdev_id)
6216{
Jeff Johnson9d295242017-08-29 14:39:48 -07006217 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006218
Dustin Brown920397d2017-12-13 16:27:50 -08006219 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006220 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006221 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006222 }
6223
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006224 return NULL;
6225}
6226
Abhishek Singh7996eb72015-12-30 17:24:02 +05306227/**
6228 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6229 * the sessionid
6230 * @hdd_ctx: hdd context.
6231 * @sme_session_id: sme session is for the adapter to get.
6232 *
6233 * This function is used to get the adapter with provided session id
6234 *
6235 * Return: adapter pointer if found
6236 *
6237 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006238struct hdd_adapter *
6239hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6240 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306241{
Jeff Johnson9d295242017-08-29 14:39:48 -07006242 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306243
Dustin Brown920397d2017-12-13 16:27:50 -08006244 hdd_for_each_adapter(hdd_ctx, adapter) {
6245 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306246 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306247 }
Dustin Brown920397d2017-12-13 16:27:50 -08006248
Abhishek Singh7996eb72015-12-30 17:24:02 +05306249 return NULL;
6250}
6251
Jeff Johnson9d295242017-08-29 14:39:48 -07006252struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006253 const char *iface_name)
6254{
Jeff Johnson9d295242017-08-29 14:39:48 -07006255 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006256
Dustin Brown920397d2017-12-13 16:27:50 -08006257 hdd_for_each_adapter(hdd_ctx, adapter) {
6258 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006259 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006260 }
Dustin Brown920397d2017-12-13 16:27:50 -08006261
Naveen Rawat4edb6822017-04-12 10:09:17 -07006262 return NULL;
6263}
6264
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006265/**
6266 * hdd_get_adapter() - to get adapter matching the mode
6267 * @hdd_ctx: hdd context
6268 * @mode: adapter mode
6269 *
6270 * This routine will return the pointer to adapter matching
6271 * with the passed mode.
6272 *
6273 * Return: pointer to adapter or null
6274 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006275struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006276 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277{
Jeff Johnson9d295242017-08-29 14:39:48 -07006278 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279
Dustin Brown920397d2017-12-13 16:27:50 -08006280 hdd_for_each_adapter(hdd_ctx, adapter) {
6281 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006282 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006283 }
6284
6285 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006286}
6287
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006288enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306289{
6290 struct hdd_context *hdd_ctx;
6291 struct hdd_adapter *adapter;
6292
6293 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6294 if (!hdd_ctx) {
6295 hdd_err("Invalid HDD context");
6296 return QDF_MAX_NO_OF_MODE;
6297 }
6298
6299 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6300 if (!adapter) {
6301 hdd_err("Invalid HDD adapter");
6302 return QDF_MAX_NO_OF_MODE;
6303 }
6304
6305 return adapter->device_mode;
6306}
6307
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006308/**
6309 * hdd_get_operating_channel() - return operating channel of the device mode
6310 * @hdd_ctx: Pointer to the HDD context.
6311 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006312 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006313 * QDF_STA_MODE,
6314 * QDF_P2P_CLIENT_MODE,
6315 * QDF_SAP_MODE,
6316 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006317 *
6318 * This API returns the operating channel of the requested device mode
6319 *
6320 * Return: channel number. "0" id the requested device is not found OR it is
6321 * not connected.
6322 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006323uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006324 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325{
Jeff Johnson9d295242017-08-29 14:39:48 -07006326 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327 uint8_t operatingChannel = 0;
6328
Dustin Brown920397d2017-12-13 16:27:50 -08006329 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006330 if (mode == adapter->device_mode) {
6331 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006332 case QDF_STA_MODE:
6333 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006334 if (hdd_conn_is_connected
6335 (WLAN_HDD_GET_STATION_CTX_PTR
6336 (adapter))) {
6337 operatingChannel =
6338 (WLAN_HDD_GET_STATION_CTX_PTR
6339 (adapter))->conn_info.
6340 operationChannel;
6341 }
6342 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006343 case QDF_SAP_MODE:
6344 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006345 /* softap connection info */
6346 if (test_bit
6347 (SOFTAP_BSS_STARTED,
6348 &adapter->event_flags))
6349 operatingChannel =
6350 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006351 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006352 break;
6353 default:
6354 break;
6355 }
6356
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006357 /* Found the device of interest. break the loop */
6358 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006359 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006360 }
Dustin Brown920397d2017-12-13 16:27:50 -08006361
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006362 return operatingChannel;
6363}
6364
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006365static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366 hdd_ctx)
6367{
Jeff Johnson9d295242017-08-29 14:39:48 -07006368 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006369
Dustin Brown491d54b2018-03-14 12:39:11 -07006370 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006371
Dustin Brown920397d2017-12-13 16:27:50 -08006372 hdd_for_each_adapter(hdd_ctx, adapter) {
6373 if (adapter->device_mode == QDF_STA_MODE ||
6374 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6375 adapter->device_mode == QDF_IBSS_MODE ||
6376 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6377 adapter->device_mode == QDF_SAP_MODE ||
6378 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006379 hdd_unregister_wext(adapter->dev);
6380 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006381 }
6382
Dustin Browne74003f2018-03-14 12:51:58 -07006383 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006384
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306385 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006386}
6387
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006388QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006389{
Jeff Johnson9d295242017-08-29 14:39:48 -07006390 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006391
Dustin Brown491d54b2018-03-14 12:39:11 -07006392 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006393
Dustin Brown920397d2017-12-13 16:27:50 -08006394 hdd_for_each_adapter(hdd_ctx, adapter) {
6395 if (adapter->device_mode == QDF_STA_MODE ||
6396 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6397 adapter->device_mode == QDF_IBSS_MODE ||
6398 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6399 adapter->device_mode == QDF_SAP_MODE ||
6400 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006401 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006402 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306403 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006404 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006405 }
6406
Dustin Browne74003f2018-03-14 12:51:58 -07006407 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006408
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306409 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410}
6411
Dustin Brownf27bce82016-11-03 12:52:27 -07006412/**
6413 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6414 * adapters
6415 * @hdd_ctx: The HDD context containing the adapters to operate on
6416 *
6417 * return: QDF_STATUS_SUCCESS
6418 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006419static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006420{
Jeff Johnson9d295242017-08-29 14:39:48 -07006421 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006422 int err;
6423
Dustin Brown491d54b2018-03-14 12:39:11 -07006424 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006425
Dustin Brown920397d2017-12-13 16:27:50 -08006426 hdd_for_each_adapter(hdd_ctx, adapter) {
6427 if (adapter->device_mode == QDF_STA_MODE ||
6428 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6429 adapter->device_mode == QDF_IBSS_MODE ||
6430 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6431 adapter->device_mode == QDF_SAP_MODE ||
6432 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006433 err = wlan_hdd_sched_scan_stop(adapter->dev);
6434 if (err)
6435 hdd_err("Unable to stop scheduled scan");
6436 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006437 }
6438
Dustin Browne74003f2018-03-14 12:51:58 -07006439 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006440
6441 return QDF_STATUS_SUCCESS;
6442}
6443
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006444#ifdef WLAN_NS_OFFLOAD
6445/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006446 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006447 * @hdd_ctx: Pointer to hdd context
6448 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006449 * Unregister for IPv6 address change notifications.
6450 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006451 * Return: None
6452 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006453static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006454{
6455 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006456}
6457
6458/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006459 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006460 * @hdd_ctx: Pointer to hdd context
6461 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006462 * Register for IPv6 address change notifications.
6463 *
6464 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006465 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006466static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006467{
6468 int ret;
6469
6470 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6471 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006472 if (ret) {
6473 hdd_err("Failed to register IPv6 notifier: %d", ret);
6474 goto out;
6475 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006476
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006477 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006478out:
6479 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480}
6481#else
6482/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006483 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006484 * @hdd_ctx: Pointer to hdd context
6485 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006486 * Unregister for IPv6 address change notifications.
6487 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006488 * Return: None
6489 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006490static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006491{
6492}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006493
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006494/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006495 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006496 * @hdd_ctx: Pointer to hdd context
6497 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006498 * Register for IPv6 address change notifications.
6499 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006500 * Return: None
6501 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006502static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006503{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006504 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006505}
6506#endif
6507
Alok Kumarb64650c2018-03-23 17:05:11 +05306508void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6509{
6510 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6511 adapter->disconnection_in_progress = status;
6512 qdf_mutex_release(&adapter->disconnection_status_lock);
6513 hdd_debug("setting disconnection status: %d", status);
6514}
6515
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006516/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006517 * hdd_register_notifiers - Register netdev notifiers.
6518 * @hdd_ctx: HDD context
6519 *
6520 * Register netdev notifiers like IPv4 and IPv6.
6521 *
6522 * Return: 0 on success and errno on failure
6523 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006524static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006525{
6526 int ret;
6527
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006528 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6529 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306530 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006531
6532 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6533 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6534 if (ret) {
6535 hdd_err("Failed to register IPv4 notifier: %d", ret);
6536 goto unregister_ip6_notifier;
6537 }
6538
Alok Kumarb64650c2018-03-23 17:05:11 +05306539 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6540 if (ret) {
6541 hdd_err("Failed to register netevent notifier: %d",
6542 ret);
6543 goto unregister_inetaddr_notifier;
6544 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006545 return 0;
6546
Alok Kumarb64650c2018-03-23 17:05:11 +05306547unregister_inetaddr_notifier:
6548 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006549unregister_ip6_notifier:
6550 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006551out:
6552 return ret;
6553
6554}
6555
6556/**
6557 * hdd_unregister_notifiers - Unregister netdev notifiers.
6558 * @hdd_ctx: HDD context
6559 *
6560 * Unregister netdev notifiers like IPv4 and IPv6.
6561 *
6562 * Return: None.
6563 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006564void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006565{
Alok Kumarb64650c2018-03-23 17:05:11 +05306566 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006567 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6568
6569 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006570}
6571
6572/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006573 * hdd_exit_netlink_services - Exit netlink services
6574 * @hdd_ctx: HDD context
6575 *
6576 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6577 * nl service.
6578 *
6579 * Return: None.
6580 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006581static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006582{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006583 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006584 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006585 ptt_sock_deactivate_svc();
6586
6587 nl_srv_exit();
6588}
6589
6590/**
6591 * hdd_init_netlink_services- Init netlink services
6592 * @hdd_ctx: HDD context
6593 *
6594 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6595 * nl service.
6596 *
6597 * Return: 0 on success and errno on failure.
6598 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006599static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006600{
6601 int ret;
6602
Ryan Hsuceddceb2016-04-28 10:20:14 -07006603 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006604 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006605 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006606 goto out;
6607 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006608 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006609
Naveen Rawat910726a2017-03-06 11:42:51 -08006610 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006611 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006612 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006613 goto err_nl_srv;
6614 }
6615
6616 ret = ptt_sock_activate_svc();
6617 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006618 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006619 goto err_nl_srv;
6620 }
6621
6622 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006623 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006624 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006625
6626 ret = cnss_diag_activate_service();
6627 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006628 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006629 goto err_close_cesium;
6630 }
6631
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006632 ret = spectral_scan_activate_service();
6633 if (ret) {
6634 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6635 goto err_close_cesium;
6636 }
6637
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006638 return 0;
6639
6640err_close_cesium:
6641 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006642 ptt_sock_deactivate_svc();
6643err_nl_srv:
6644 nl_srv_exit();
6645out:
6646 return ret;
6647}
6648
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006649/**
6650 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6651 * @hdd_ctx: HDD context.
6652 *
6653 * Destroy RX wakelock.
6654 *
6655 * Return: None.
6656 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006657static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006658{
6659 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6660}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006661
6662/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006663 * hdd_rx_wake_lock_create() - Create RX wakelock
6664 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006665 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006666 * Create RX wakelock.
6667 *
6668 * Return: None.
6669 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006670static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006671{
6672 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6673}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006674
6675/**
Houston Hoffman160db392016-10-10 17:37:51 -07006676 * hdd_context_deinit() - Deinitialize HDD context
6677 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006678 *
Houston Hoffman160db392016-10-10 17:37:51 -07006679 * Deinitialize HDD context along with all the feature specific contexts but
6680 * do not free hdd context itself. Caller of this API is supposed to free
6681 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006682 *
Houston Hoffman160db392016-10-10 17:37:51 -07006683 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006684 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006685static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006686{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306687 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6688
Houston Hoffman160db392016-10-10 17:37:51 -07006689 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006690
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006691 hdd_sap_context_destroy(hdd_ctx);
6692
6693 hdd_rx_wake_lock_destroy(hdd_ctx);
6694
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006695 hdd_scan_context_destroy(hdd_ctx);
6696
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006697 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006698
Houston Hoffman160db392016-10-10 17:37:51 -07006699 return 0;
6700}
6701
6702/**
6703 * hdd_context_destroy() - Destroy HDD context
6704 * @hdd_ctx: HDD context to be destroyed.
6705 *
6706 * Free config and HDD context as well as destroy all the resources.
6707 *
6708 * Return: None
6709 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006710static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006711{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006712 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306713
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306714 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6715
Houston Hoffman160db392016-10-10 17:37:51 -07006716 hdd_context_deinit(hdd_ctx);
6717
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306718 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006719 hdd_ctx->config = NULL;
6720
6721 wiphy_free(hdd_ctx->wiphy);
6722}
6723
6724/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306725 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6726 *
6727 * This function is used to destroy bug report lock
6728 *
6729 * Return: None
6730 */
6731static void wlan_destroy_bug_report_lock(void)
6732{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07006733 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306734
6735 p_cds_context = cds_get_global_context();
6736 if (!p_cds_context) {
6737 hdd_err("cds context is NULL");
6738 return;
6739 }
6740
6741 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6742}
6743
6744/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006745 * hdd_wlan_exit() - HDD WLAN exit function
6746 * @hdd_ctx: Pointer to the HDD Context
6747 *
6748 * This is the driver exit point (invoked during rmmod)
6749 *
6750 * Return: None
6751 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006752static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006753{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006754 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306755 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006756
Dustin Brown491d54b2018-03-14 12:39:11 -07006757 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006758
Arun Khandavallifae92942016-08-01 13:31:08 +05306759 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006760
Prashanth Bhattaab004382016-10-11 16:08:11 -07006761 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006762
6763#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306764 if (QDF_TIMER_STATE_RUNNING ==
6765 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6766 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006767 }
6768
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306769 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306770 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006771 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006772 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006773 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6774 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6775 hdd_ctx->last_acs_channel_list = NULL;
6776 hdd_ctx->num_of_channels = 0;
6777 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779
Arun Khandavallifae92942016-08-01 13:31:08 +05306780 mutex_lock(&hdd_ctx->iface_change_lock);
6781 driver_status = hdd_ctx->driver_status;
6782 mutex_unlock(&hdd_ctx->iface_change_lock);
6783
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006784 /*
6785 * Powersave Offload Case
6786 * Disable Idle Power Save Mode
6787 */
6788 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006789 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306790 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006791
Arun Khandavallifae92942016-08-01 13:31:08 +05306792 if (driver_status != DRIVER_MODULES_CLOSED) {
6793 hdd_unregister_wext_all_adapters(hdd_ctx);
6794 /*
6795 * Cancel any outstanding scan requests. We are about to close
6796 * all of our adapters, but an adapter structure is what SME
6797 * passes back to our callback function. Hence if there
6798 * are any outstanding scan requests then there is a
6799 * race condition between when the adapter is closed and
6800 * when the callback is invoked. We try to resolve that
6801 * race condition here by canceling any outstanding scans
6802 * before we close the adapters.
6803 * Note that the scans may be cancelled in an asynchronous
6804 * manner, so ideally there needs to be some kind of
6805 * synchronization. Rather than introduce a new
6806 * synchronization here, we will utilize the fact that we are
6807 * about to Request Full Power, and since that is synchronized,
6808 * the expectation is that by the time Request Full Power has
6809 * completed, all scans will be cancelled
6810 */
6811 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006812 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006813 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006814 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006815 }
6816
Arunk Khandavalli830c9692018-03-22 12:17:40 +05306817 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306818 unregister_netdevice_notifier(&hdd_netdev_notifier);
6819
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006820 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306821
Dustin Brown021cecd2017-12-11 13:56:43 -08006822 hdd_driver_memdump_deinit();
6823
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306824 qdf_nbuf_deinit_replenish_timer();
6825
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306826 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6827 hdd_info("Release wakelock for monitor mode!");
6828 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6829 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6830 }
6831
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306832 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6833 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6834 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6835
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006836 /*
6837 * Close CDS
6838 * This frees pMac(HAL) context. There should not be any call
6839 * that requires pMac access after this.
6840 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006841
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006842 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -07006843 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006844
Dustin Brownd005ad82018-01-19 10:32:13 -08006845 hdd_close_all_adapters(hdd_ctx, false);
6846
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306847 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306848 /*
6849 * If there is re_init failure wiphy would have already de-registered
6850 * check the wiphy status before un-registering again
6851 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306852 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306853 wiphy_unregister(wiphy);
6854 wlan_hdd_cfg80211_deinit(wiphy);
6855 hdd_lpass_notify_stop(hdd_ctx);
6856 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006857
Arun Khandavallifae92942016-08-01 13:31:08 +05306858 hdd_exit_netlink_services(hdd_ctx);
6859 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306860#ifdef FEATURE_WLAN_CH_AVOID
6861 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6862#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306863
Abhishek Singhe9068f12017-03-31 14:14:52 +05306864 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6865 if (driver_status)
6866 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006867
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006868 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869}
6870
6871void __hdd_wlan_exit(void)
6872{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006873 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006874
Dustin Brown491d54b2018-03-14 12:39:11 -07006875 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006876
Anurag Chouhan6d760662016-02-20 16:05:43 +05306877 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006878 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006879 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07006880 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006881 return;
6882 }
6883
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006884 /* Do all the cleanup before deregistering the driver */
6885 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006886
Dustin Browne74003f2018-03-14 12:51:58 -07006887 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888}
6889
6890#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006891/**
6892 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006893 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006894 *
6895 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6896 * Then new ACS request will do a fresh scan without reusing the cached
6897 * scan information.
6898 *
6899 * Return: void
6900 */
Tang Yingying523322d2017-01-17 23:28:43 +08006901static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006902{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006903 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006904
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006905 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006906 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006907 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6908 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6909 hdd_ctx->last_acs_channel_list = NULL;
6910 hdd_ctx->num_of_channels = 0;
6911 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006912
6913 if (!hdd_ctx->hHal)
6914 return;
6915 sme_scan_flush_result(hdd_ctx->hHal);
6916}
6917#endif
6918
6919#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006920int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6921 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006922{
6923 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306924 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006925 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006926
6927 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6928
6929 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306930 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006931 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306932
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006933 if (!hdd_ctx->hHal)
6934 return -EINVAL;
6935
Jeff Johnsone7672e72017-10-21 15:10:04 -07006936 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006937 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306938 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006939 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006940 return -EINVAL;
6941 }
6942
6943 return 0;
6944}
6945#endif
6946
6947/**
6948 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6949 * @state: state
6950 *
6951 * This function notifies FW with modem power status
6952 *
6953 * Return: 0 if successful, error number otherwise
6954 */
6955int hdd_wlan_notify_modem_power_state(int state)
6956{
6957 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306958 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006959 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006960
Anurag Chouhan6d760662016-02-20 16:05:43 +05306961 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006962 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306963 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006964 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306965
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006966 if (!hdd_ctx->hHal)
6967 return -EINVAL;
6968
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306969 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6970 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006971 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006972 state);
6973 return -EINVAL;
6974 }
6975 return 0;
6976}
6977
6978/**
6979 *
6980 * hdd_post_cds_enable_config() - HDD post cds start config helper
6981 * @adapter - Pointer to the HDD
6982 *
6983 * Return: None
6984 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006985QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006986{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306987 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006988
6989 /*
6990 * Send ready indication to the HDD. This will kick off the MAC
6991 * into a 'running' state and should kick off an initial scan.
6992 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306993 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6994 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006995 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6996 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306997 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006998 }
6999
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307000 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007001}
7002
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307003struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7004{
7005 struct hdd_adapter *adapter;
7006
7007 hdd_for_each_adapter(hdd_ctx, adapter) {
7008 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7009 return adapter;
7010 }
7011
7012 return NULL;
7013}
7014
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007015/* wake lock APIs for HDD */
7016void hdd_prevent_suspend(uint32_t reason)
7017{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307018 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007019}
7020
7021void hdd_allow_suspend(uint32_t reason)
7022{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307023 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007024}
7025
7026void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7027{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307028 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7029 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007030}
7031
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007032/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007033QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007034{
Amar Singhal5cccafe2017-02-15 12:42:58 -08007035
Amar Singhal6f8592b2017-04-26 14:31:58 -07007036 return sme_init_chan_list(hdd_ctx->hHal,
7037 hdd_ctx->reg.alpha2,
7038 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007039}
7040
7041/**
7042 * hdd_is_5g_supported() - check if hardware supports 5GHz
7043 * @hdd_ctx: Pointer to the hdd context
7044 *
7045 * HDD function to know if hardware supports 5GHz
7046 *
7047 * Return: true if hardware supports 5GHz
7048 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007049bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007050{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007051 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007052 return true;
7053
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007054 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007055 return true;
7056 else
7057 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007058}
7059
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007060static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007061{
7062 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007063 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007064
7065 wiphy = hdd_ctx->wiphy;
7066
7067 /*
7068 * The channel information in
7069 * wiphy needs to be initialized before wiphy registration
7070 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007071 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7072 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007073 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007074 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007075 }
7076
7077#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7078 wiphy->wowlan = &wowlan_support_reg_init;
7079#else
7080 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7081 WIPHY_WOWLAN_MAGIC_PKT |
7082 WIPHY_WOWLAN_DISCONNECT |
7083 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7084 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7085 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7086 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7087 WIPHY_WOWLAN_RFKILL_RELEASE;
7088
7089 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7090 WOW_MAX_FILTERS_PER_LIST);
7091 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7092 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7093#endif
7094
7095 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007096 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307097 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007098 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307099 return ret_val;
7100 }
7101
Amar Singhal2d812012018-02-03 15:06:47 +08007102 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007103
Amar Singhale4f28ee2015-10-21 14:36:56 -07007104 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007105}
7106
Mohit Khannaca4173b2017-09-12 21:52:19 -07007107#ifdef MSM_PLATFORM
7108/**
7109 * hdd_display_periodic_stats() - Function to display periodic stats
7110 * @hdd_ctx - handle to hdd context
7111 * @bool data_in_interval - true, if data detected in bw time interval
7112 *
7113 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7114 * Stats show up in wlan driver logs.
7115 *
7116 * Returns: None
7117 */
7118static inline
7119void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7120 bool data_in_interval)
7121{
7122 static u32 counter;
7123 static bool data_in_time_period;
7124 ol_txrx_pdev_handle pdev;
7125
7126 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7127 return;
7128
7129 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7130 if (!pdev) {
7131 hdd_err("pdev is NULL");
7132 return;
7133 }
7134
7135 counter++;
7136 if (data_in_interval)
7137 data_in_time_period = data_in_interval;
7138
7139 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7140 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7141 if (data_in_time_period) {
7142 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7143 CDP_TXRX_PATH_STATS,
7144 QDF_STATS_VERBOSITY_LEVEL_LOW);
7145 wlan_hdd_display_netif_queue_history
7146 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7147 qdf_dp_trace_dump_stats();
7148 }
7149 counter = 0;
7150 data_in_time_period = false;
7151 }
7152}
7153
Ravi Joshie2331e82015-07-01 18:18:54 -07007154/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007155 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7156 * @hdd_ctx: pointer to struct hdd_context
7157 *
7158 * Return: none
7159 */
7160static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7161{
7162 struct hdd_adapter *adapter;
7163
7164 hdd_for_each_adapter(hdd_ctx, adapter)
7165 hdd_send_rps_disable_ind(adapter);
7166}
7167
7168/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007169 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007170 * @hdd_ctx - handle to hdd context
7171 * @tx_packets - transmit packet count
7172 * @rx_packets - receive packet count
7173 *
7174 * The function controls the bus bandwidth and dynamic control of
7175 * tcp delayed ack configuration
7176 *
7177 * Returns: None
7178 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007179
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007180static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007181 const uint64_t tx_packets,
7182 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007183{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007184 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08007185 uint64_t temp_rx = 0;
7186 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007187 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007188 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007189 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007190 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007191 uint16_t index = 0;
7192 bool vote_level_change = false;
7193 bool rx_level_change = false;
7194 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007195
Mohit Khannaca4173b2017-09-12 21:52:19 -07007196 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007197 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007198 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007199 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007200 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007201 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007202 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007203 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007205 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007206 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7207 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007208 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007209 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007210 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007211 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7212 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307213 if (hdd_ctx->hbw_requested) {
7214 pld_remove_pm_qos(hdd_ctx->parent_dev);
7215 hdd_ctx->hbw_requested = false;
7216 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05307217 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007218 hdd_warn("low bandwidth set rx affinity fail");
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007219
7220 if (hdd_ctx->dynamic_rps)
7221 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007222 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307223 if (!hdd_ctx->hbw_requested) {
7224 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7225 hdd_ctx->hbw_requested = true;
7226 }
7227
Nirav Shah3bbfa512016-05-12 16:43:49 +05307228 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007229 hdd_warn("high bandwidth set rx affinity fail");
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007230
7231 if (hdd_ctx->dynamic_rps)
7232 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007233 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07007234 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007235 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007236
Mohit Khannaf8f96822017-05-17 17:11:59 -07007237 qdf_dp_trace_throttle_live_mode(
7238 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
7239
Mohit Khannae71e2262015-11-10 09:37:24 -08007240 /* fine-tuning parameters for RX Flows */
7241 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
7242
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007243 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007244
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307245 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07007246 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307247 else
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07007248 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307249
Ravi Joshifed83572016-10-07 16:20:37 -07007250 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
7251 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7252 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7253 next_rx_level = WLAN_SVC_TP_HIGH;
7254 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007255 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007256 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007257 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007258 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007259
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007260 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007261 struct wlan_rx_tp_data rx_tp_data = {0};
7262
Ravi Joshie2331e82015-07-01 18:18:54 -07007263 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007264 next_rx_level, temp_rx);
7265 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007266 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007267 /* Send throughput indication only if it is enabled.
7268 * Disabling tcp_del_ack will revert the tcp stack behavior
7269 * to default delayed ack. Note that this will disable the
7270 * dynamic delayed ack mechanism across the system
7271 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007272 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007273 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7274
Mohit Khanna6272fb682017-04-13 09:34:36 -07007275 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7276 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7277
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007278 rx_tp_data.level = next_rx_level;
7279 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7280 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7281 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007282 }
7283
Mohit Khannae71e2262015-11-10 09:37:24 -08007284 /* fine-tuning parameters for TX Flows */
7285 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7286 hdd_ctx->prev_tx = tx_packets;
7287 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7288 next_tx_level = WLAN_SVC_TP_HIGH;
7289 else
7290 next_tx_level = WLAN_SVC_TP_LOW;
7291
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007292 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7293 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007294 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7295 next_tx_level, temp_tx);
7296 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007297 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307298 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7299 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007300 &next_tx_level,
7301 sizeof(next_tx_level));
7302 }
7303
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007304 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007305 if (vote_level_change || tx_level_change || rx_level_change) {
7306 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7307 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7308 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7309 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7310 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7311 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7312 hdd_ctx->hdd_txrx_hist_idx++;
7313 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7314 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007315
7316 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007317}
7318
7319#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307320static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007321{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007322 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307323 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307324 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307325 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307326 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7327 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007328 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307329 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007330 bool connected = false;
7331 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7332
Prashanth Bhattaab004382016-10-11 16:08:11 -07007333 if (wlan_hdd_validate_context(hdd_ctx))
7334 return;
7335
Jeff Johnson214671b2017-10-30 19:45:23 -07007336 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007337 goto restart_timer;
7338
Dustin Brown920397d2017-12-13 16:27:50 -08007339 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307340 /*
7341 * Validate magic so we don't end up accessing
7342 * an invalid adapter.
7343 */
7344 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7345 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007346
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007347 if ((adapter->device_mode == QDF_STA_MODE ||
7348 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007349 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7350 != eConnectionState_Associated) {
7351
7352 continue;
7353 }
7354
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007355 if ((adapter->device_mode == QDF_SAP_MODE ||
7356 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007357 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007358
7359 continue;
7360 }
7361
7362 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7363 adapter->prev_tx_packets);
7364 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7365 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307366
7367 if (adapter->device_mode == QDF_SAP_MODE ||
7368 adapter->device_mode == QDF_P2P_GO_MODE ||
7369 adapter->device_mode == QDF_IBSS_MODE) {
7370
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007371 ret = cdp_get_intra_bss_fwd_pkts_count(
7372 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007373 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307374 &fwd_tx_packets, &fwd_rx_packets);
7375 if (ret == A_OK) {
7376 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7377 fwd_tx_packets,
7378 adapter->prev_fwd_tx_packets);
7379 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7380 fwd_tx_packets,
7381 adapter->prev_fwd_rx_packets);
7382 }
7383 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007384
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307385 if (adapter->device_mode == QDF_SAP_MODE)
7386 con_sap_adapter = adapter;
7387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007388 total_rx += adapter->stats.rx_packets;
7389 total_tx += adapter->stats.tx_packets;
7390
7391 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7392 adapter->prev_tx_packets = adapter->stats.tx_packets;
7393 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307394 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7395 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007396 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7397 connected = true;
7398 }
7399
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007400 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007401 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007402 return;
7403 }
7404
Yun Parka29974a2018-04-09 12:05:49 -07007405 /* add intra bss forwarded tx and rx packets */
7406 tx_packets += fwd_tx_packets_diff;
7407 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007408
Yun Parka29974a2018-04-09 12:05:49 -07007409 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7410 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7411 &ipa_rx_packets);
7412 tx_packets += (uint64_t)ipa_tx_packets;
7413 rx_packets += (uint64_t)ipa_rx_packets;
7414
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307415 if (con_sap_adapter) {
7416 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7417 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7418 }
7419
Yun Parka29974a2018-04-09 12:05:49 -07007420 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7421 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7422 }
7423
7424 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007425
Jingxiang Gec64e1932017-08-22 14:38:59 +08007426restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007427 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007428 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007429 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307430 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007431 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007432 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007433}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007434
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307435/**
7436 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7437 * @arg: Argument of timer function
7438 *
7439 * Schedule a workqueue in this function where all the processing is done.
7440 *
7441 * Return: None.
7442 */
7443static void __hdd_bus_bw_cbk(void *arg)
7444{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007445 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307446
7447 if (wlan_hdd_validate_context(hdd_ctx))
7448 return;
7449
7450 schedule_work(&hdd_ctx->bus_bw_work);
7451}
7452
7453/**
7454 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7455 * @arg: Argument of timer function
7456 *
7457 * Return: None.
7458 */
7459static void hdd_bus_bw_cbk(void *arg)
7460{
7461 cds_ssr_protect(__func__);
7462 __hdd_bus_bw_cbk(arg);
7463 cds_ssr_unprotect(__func__);
7464}
7465
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007466int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007467{
7468 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307469 INIT_WORK(&hdd_ctx->bus_bw_work,
7470 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007471 hdd_ctx->bus_bw_timer_running = false;
7472 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307473 qdf_timer_init(NULL,
7474 &hdd_ctx->bus_bw_timer,
7475 hdd_bus_bw_cbk, (void *)hdd_ctx,
7476 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007477
7478 return 0;
7479}
7480
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007481void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007482{
Dustin Brownfce08d12017-01-17 16:29:38 -08007483 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007484 hdd_reset_tcp_delack(hdd_ctx);
7485
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007486 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307487 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307488 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007489 hdd_ctx->bus_bw_timer_running = false;
7490 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007491}
Lin Baic5c06882017-09-21 13:58:43 +08007492
7493void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7494{
7495 if (hdd_ctx)
7496 cancel_work_sync(&hdd_ctx->bus_bw_work);
7497}
jiadcdaf9bd2017-10-26 12:20:21 +08007498
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007499#endif
7500
7501/**
Nirav Shahed34b212016-04-25 10:59:16 +05307502 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7503 * @hdd_ctx: hdd context
7504 *
7505 * Return: 0 for success or error code
7506 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007507static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307508{
7509 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7510 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7511 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007512 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307513 return -ENOMEM;
7514 }
7515 return 0;
7516}
7517
7518/**
7519 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7520 * @hdd_ctx: hdd context
7521 *
7522 * Return: none
7523 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007524void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307525{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307526 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7527 return;
7528
7529 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7530 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307531}
7532
Nirav Shahda008342016-05-17 18:50:40 +05307533static uint8_t *convert_level_to_string(uint32_t level)
7534{
7535 switch (level) {
7536 /* initialize the wlan sub system */
7537 case WLAN_SVC_TP_NONE:
7538 return "NONE";
7539 case WLAN_SVC_TP_LOW:
7540 return "LOW";
7541 case WLAN_SVC_TP_MEDIUM:
7542 return "MED";
7543 case WLAN_SVC_TP_HIGH:
7544 return "HIGH";
7545 default:
7546 return "INVAL";
7547 }
7548}
7549
Nirav Shahed34b212016-04-25 10:59:16 +05307550
7551/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007552 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7553 * @hdd_ctx: hdd context
7554 *
7555 * Return: none
7556 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007557void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007558{
7559 int i;
7560
7561#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007562 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307563 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007564 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007565 hdd_ctx->config->busBandwidthHighThreshold,
7566 hdd_ctx->config->busBandwidthMediumThreshold,
7567 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007568 hdd_debug("Enable TCP DEL ACK: %d",
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007569 hdd_ctx->en_tcp_delack_no_lro);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007570 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571 hdd_ctx->config->tcpDelackThresholdHigh,
7572 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007573 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307574 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007575#endif
7576
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007577 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307578 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7579
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007580 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007581
7582 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007583 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007584 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007585 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7586 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7587 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7588 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7589 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007590 hdd_ctx->hdd_txrx_hist[i].
7591 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007592 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007593 hdd_ctx->hdd_txrx_hist[i].
7594 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007595 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007596 hdd_ctx->hdd_txrx_hist[i].
7597 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007598 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007599}
7600
7601/**
7602 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7603 * @hdd_ctx: hdd context
7604 *
7605 * Return: none
7606 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007607void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007608{
7609 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307610 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7611 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007612}
7613
Mohit Khannaca4173b2017-09-12 21:52:19 -07007614/* length of the netif queue log needed per adapter */
7615#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7616
7617/**
7618 *
7619 * hdd_display_netif_queue_history_compact() - display compact netifq history
7620 * @hdd_ctx: hdd context
7621 *
7622 * Return: none
7623 */
7624static void
7625hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7626{
7627 int adapter_num = 0;
7628 int i;
7629 int bytes_written;
7630 u32 tbytes;
7631 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007632 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007633 char *comb_log_str;
7634 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007635 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007636
jiadbdefb252018-01-03 14:27:06 +08007637 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7638 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7639 if (!comb_log_str) {
7640 hdd_err("failed to alloc comb_log_str");
7641 return;
7642 }
7643
Mohit Khannaca4173b2017-09-12 21:52:19 -07007644 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007645
Dustin Brown920397d2017-12-13 16:27:50 -08007646 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007647 curr_time = qdf_system_ticks();
7648 total = curr_time - adapter->start_time;
7649 delta = curr_time - adapter->last_time;
7650
7651 if (adapter->pause_map) {
7652 pause = adapter->total_pause_time + delta;
7653 unpause = adapter->total_unpause_time;
7654 } else {
7655 unpause = adapter->total_unpause_time + delta;
7656 pause = adapter->total_pause_time;
7657 }
7658
7659 tbytes = 0;
7660 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7661 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7662 if (adapter->queue_oper_stats[i].pause_count == 0)
7663 continue;
7664 tbytes +=
7665 snprintf(
7666 &temp_str[tbytes],
7667 (tbytes >= sizeof(temp_str) ?
7668 0 : sizeof(temp_str) - tbytes),
7669 "%d(%d,%d) ",
7670 i,
7671 adapter->queue_oper_stats[i].
7672 pause_count,
7673 adapter->queue_oper_stats[i].
7674 unpause_count);
7675 }
7676 if (tbytes >= sizeof(temp_str))
7677 hdd_warn("log truncated");
7678
7679 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007680 bytes_written >= comb_log_str_size ? 0 :
7681 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007682 "[%d %d] (%d) %u/%ums %s|",
7683 adapter->session_id, adapter->device_mode,
7684 adapter->pause_map,
7685 qdf_system_ticks_to_msecs(pause),
7686 qdf_system_ticks_to_msecs(total),
7687 temp_str);
7688
Mohit Khannaca4173b2017-09-12 21:52:19 -07007689 adapter_num++;
7690 }
7691
7692 /* using QDF_TRACE to avoid printing function name */
7693 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7694 "STATS |%s", comb_log_str);
7695
jiadbdefb252018-01-03 14:27:06 +08007696 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007697 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007698
7699 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007700}
7701
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007702/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007703 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007704 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007705 *
7706 * Return: none
7707 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007708void
7709wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7710 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007711{
7712
Jeff Johnson9d295242017-08-29 14:39:48 -07007713 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007714 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307715 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007716
Mohit Khannaca4173b2017-09-12 21:52:19 -07007717 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7718 hdd_display_netif_queue_history_compact(hdd_ctx);
7719 return;
7720 }
7721
Dustin Brown920397d2017-12-13 16:27:50 -08007722 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007723 hdd_debug("Netif queue operation statistics:");
7724 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007725 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007726 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307727 curr_time = qdf_system_ticks();
7728 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307729 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307730 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307731 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307732 unpause = adapter->total_unpause_time;
7733 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307734 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307735 pause = adapter->total_pause_time;
7736 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007737 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307738 qdf_system_ticks_to_msecs(total),
7739 qdf_system_ticks_to_msecs(pause),
7740 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007741 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007742
Nirav Shahda008342016-05-17 18:50:40 +05307743 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7744 qdf_time_t pause_delta = 0;
7745
7746 if (adapter->pause_map & (1 << i))
7747 pause_delta = delta;
7748
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007749 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007750 hdd_debug("%s: %d: %d: %ums",
7751 hdd_reason_type_to_string(i),
7752 adapter->queue_oper_stats[i].pause_count,
7753 adapter->queue_oper_stats[i].unpause_count,
7754 qdf_system_ticks_to_msecs(
7755 adapter->queue_oper_stats[i].total_pause_time +
7756 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007757 }
7758
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007759 hdd_debug("Netif queue operation history:");
7760 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307761 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7762
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007763 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007764
7765 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007766 /* using hdd_log to avoid printing function name */
7767 if (adapter->queue_oper_history[i].time == 0)
7768 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007769 hdd_debug("%d: %u: %s: %s: %x",
7770 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007771 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007772 hdd_action_type_to_string(
7773 adapter->queue_oper_history[i].netif_action),
7774 hdd_reason_type_to_string(
7775 adapter->queue_oper_history[i].netif_reason),
7776 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007777 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007778 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007779}
7780
7781/**
7782 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7783 * @hdd_ctx: hdd context
7784 *
7785 * Return: none
7786 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007787void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007788{
Jeff Johnson9d295242017-08-29 14:39:48 -07007789 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007790
Dustin Brown920397d2017-12-13 16:27:50 -08007791 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307792 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007793 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307794 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007795 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307796 adapter->history_index = 0;
7797 adapter->start_time = adapter->last_time = qdf_system_ticks();
7798 adapter->total_pause_time = 0;
7799 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007800 }
7801}
7802
7803/**
7804 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7805 * @halHandle: Hal handle
7806 * @pContext: Pointer to the context
7807 * @sessionId: Session ID
7808 * @scanId: Scan ID
7809 * @status: Status
7810 *
7811 * This is the callback to be executed when 11d scan is completed to flush out
7812 * the scan results
7813 *
7814 * 11d scan is done during driver load and is a passive scan on all
7815 * channels supported by the device, 11d scans may find some APs on
7816 * frequencies which are forbidden to be used in the regulatory domain
7817 * the device is operating in. If these APs are notified to the supplicant
7818 * it may try to connect to these APs, thus flush out all the scan results
7819 * which are present in SME after 11d scan is done.
7820 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307821 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007822 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307823static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007824 uint8_t sessionId, uint32_t scanId,
7825 eCsrScanStatus status)
7826{
Dustin Brown491d54b2018-03-14 12:39:11 -07007827 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007828
7829 sme_scan_flush_result(halHandle);
7830
Dustin Browne74003f2018-03-14 12:51:58 -07007831 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007832
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307833 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007834}
7835
7836#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7837/**
7838 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7839 * @hdd_ctx: hdd global context
7840 *
7841 * Return: none
7842 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007843static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007844{
7845 uint8_t i;
7846
7847 mutex_init(&hdd_ctx->op_ctx.op_lock);
7848 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7849 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7850 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7851 }
7852}
7853#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007854static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007855{
7856}
7857#endif
7858
Yingying Tang95409972016-10-20 15:16:15 +08007859#ifdef WLAN_FEATURE_WOW_PULSE
7860/**
7861 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007862 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007863 * @enable: enable or disable this behaviour
7864 *
7865 * Return: int
7866 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007867static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007868{
7869 struct hdd_config *pcfg_ini = phddctx->config;
7870 struct wow_pulse_mode wow_pulse_set_info;
7871 QDF_STATUS status;
7872
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007873 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007874
7875 if (false == phddctx->config->wow_pulse_support)
7876 return 0;
7877
7878 /* prepare the request to send to SME */
7879 if (enable == true) {
7880 wow_pulse_set_info.wow_pulse_enable = true;
7881 wow_pulse_set_info.wow_pulse_pin =
7882 pcfg_ini->wow_pulse_pin;
7883 wow_pulse_set_info.wow_pulse_interval_low =
7884 pcfg_ini->wow_pulse_interval_low;
7885 wow_pulse_set_info.wow_pulse_interval_high =
7886 pcfg_ini->wow_pulse_interval_high;
7887 } else {
7888 wow_pulse_set_info.wow_pulse_enable = false;
7889 wow_pulse_set_info.wow_pulse_pin = 0;
7890 wow_pulse_set_info.wow_pulse_interval_low = 0;
7891 wow_pulse_set_info.wow_pulse_interval_high = 0;
7892 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007893 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007894 wow_pulse_set_info.wow_pulse_enable,
7895 wow_pulse_set_info.wow_pulse_pin,
7896 wow_pulse_set_info.wow_pulse_interval_low,
7897 wow_pulse_set_info.wow_pulse_interval_high);
7898
7899 status = sme_set_wow_pulse(&wow_pulse_set_info);
7900 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007901 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007902 return -EIO;
7903 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007904 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007905 return 0;
7906}
7907#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007908static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007909{
7910 return 0;
7911}
7912#endif
7913
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007914#ifdef WLAN_FEATURE_FASTPATH
7915/**
7916 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7917 * @hdd_cfg: hdd config
7918 * @context: lower layer context
7919 *
7920 * Return: none
7921 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307922void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007923 void *context)
7924{
7925 if (hdd_cfg->fastpath_enable)
7926 hif_enable_fastpath(context);
7927}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007928#endif
7929
Yuanyuan Liu13738502016-04-06 17:41:37 -07007930#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007931/**
7932 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007933 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007934 * @level: thermal level
7935 *
7936 * Change IPA data path to SW path when the thermal throttle level greater
7937 * than 0, and restore the original data path when throttle level is 0
7938 *
7939 * Return: none
7940 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007941static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007942{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007943 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007945 /* Change IPA to SW path when throttle level greater than 0 */
7946 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307947 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007948 else
7949 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307950 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007951}
7952
7953/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307954 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7955 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307956 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007957 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307958 * Get a safe channel to restart SAP. PCL already takes into account the
7959 * unsafe channels. So, the PCL is validated with the ACS range to provide
7960 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007961 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307962 * Return: Channel number to restart SAP in case of success. In case of any
7963 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007964 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307965static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007966 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007967{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307968 struct sir_pcl_list pcl;
7969 QDF_STATUS status;
7970 uint32_t i, j;
7971 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007972 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307973 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007974 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007975
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307976 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7977 if (!hdd_ctx) {
7978 hdd_err("invalid HDD context");
7979 return INVALID_CHANNEL_ID;
7980 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007981
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307982 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7983 if (!hal_handle) {
7984 hdd_err("invalid HAL handle");
7985 return INVALID_CHANNEL_ID;
7986 }
7987
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007988 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7989 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007990 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7991 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307992 if (QDF_IS_STATUS_ERROR(status)) {
7993 hdd_err("Get PCL failed");
7994 return INVALID_CHANNEL_ID;
7995 }
7996
Frank Liudc2cefb2017-06-21 15:38:18 +08007997 /*
7998 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7999 * channel is unsafe channel, the pcl may be empty, instead of return,
8000 * try to choose a safe channel from acs range.
8001 */
8002 if (!pcl.pcl_len)
8003 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308004
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008005 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008006 adapter->session.ap.sap_config.acs_cfg.start_ch,
8007 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308008
8009 /* PCL already takes unsafe channel into account */
8010 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008011 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308012 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008013 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308014 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008015 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008016 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308017 return pcl.pcl_list[i];
8018 }
8019 }
8020
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008021 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308022
8023 /* Try for safe channel from all valid channel */
8024 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05008025 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8026 &pcl.pcl_len);
8027 if (ret) {
8028 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308029 return INVALID_CHANNEL_ID;
8030 }
8031
8032 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008033 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308034 found = false;
8035 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07008036 if (pcl.pcl_list[i] ==
8037 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008038 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308039 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008040 break;
8041 }
8042 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308043
8044 if (found)
8045 continue;
8046
8047 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008048 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308049 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008050 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008051 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308052 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008053 }
8054 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308055
8056 return INVALID_CHANNEL_ID;
8057}
Nirav Shaheb017be2018-02-15 11:20:58 +05308058#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308059
8060/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008061 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308062 * @adapter: AP adapter
8063 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008064 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308065 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008066 * Moves the SAP interface by invoking the function which
8067 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308068 *
8069 * Return: None
8070 */
Min Liu2fef5792018-01-19 17:59:42 +08008071void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8072 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308073{
Jeff Johnson87251032017-08-29 13:31:11 -07008074 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308075 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008076 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308077
8078 if (!adapter) {
8079 hdd_err("invalid adapter");
8080 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008081 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308082
8083 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8084
8085 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
8086 if (!hal_handle) {
8087 hdd_err("invalid HAL handle");
8088 return;
8089 }
8090
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008091 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8092
Jeff Johnson91df29d2017-10-27 19:29:50 -07008093 hdd_ap_ctx->sap_config.channel = channel;
8094 hdd_ap_ctx->sap_config.ch_params.ch_width =
8095 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308096
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008097 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008098 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308099
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07008100 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07008101 hdd_ap_ctx->sap_config.channel,
8102 hdd_ap_ctx->sap_config.sec_ch,
8103 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308104
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008105 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008106 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008107 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008108}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308109
Jeff Johnson9d295242017-08-29 14:39:48 -07008110int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308111{
8112 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308113 int status;
8114 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308115
8116 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8117
8118 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008119 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308120 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008121 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308122 }
8123 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008124 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308125 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308126 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008127 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308128 WLAN_VENDOR_ACS_WAIT_TIME);
8129 if (qdf_status != QDF_STATUS_SUCCESS) {
8130 hdd_err("failed to start external acs timer");
8131 return -ENOSPC;
8132 }
8133 /* Update config to application */
8134 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008135 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308136
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308137 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308138}
8139
Nirav Shaheb017be2018-02-15 11:20:58 +05308140#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308141/**
8142 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8143 * @hdd_ctx: hdd context pointer
8144 *
8145 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8146 * and if ACS is enabled, driver will ask userspace to restart the
8147 * sap. User space on LTE coex indication restart driver.
8148 *
8149 * Return - none
8150 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008151void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308152{
Dustin Brown920397d2017-12-13 16:27:50 -08008153 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308154 uint32_t i;
8155 bool found = false;
8156 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008157
Dustin Brown920397d2017-12-13 16:27:50 -08008158 hdd_for_each_adapter(hdd_ctxt, adapter) {
8159 if (!(adapter->device_mode == QDF_SAP_MODE &&
8160 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008161 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008162 adapter->device_mode,
8163 adapter->session.ap.sap_config.
8164 acs_cfg.acs_mode);
8165 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308166 }
8167
8168 found = false;
8169 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08008170 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05308171 hdd_ctxt->unsafe_channel_list[i]) {
8172 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008173 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08008174 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308175 break;
8176 }
8177 }
8178
8179 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008180 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008181 adapter->session.ap.operating_channel);
8182 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308183 }
8184
Kapil Gupta8878ad92017-02-13 11:56:04 +05308185 if (hdd_ctxt->config->vendor_acs_support &&
8186 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008187 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308188 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008189 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308190 } else
8191 restart_chan =
8192 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008193 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308194 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008195 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308196 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008197 /*
8198 * SAP restart due to unsafe channel. While
8199 * restarting the SAP, make sure to clear
8200 * acs_channel, channel to reset to
8201 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308202 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008203 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308204 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008205 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308206 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008207 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308208 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8209 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008210 hdd_debug("driver to start sap: %d",
8211 hdd_ctxt->config->sap_internal_restart);
8212 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008213 hdd_switch_sap_channel(adapter, restart_chan,
8214 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008215 else
8216 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308217 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308218 }
8219}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308220
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008221/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008222 * hdd_init_channel_avoidance() - Initialize channel avoidance
8223 * @hdd_ctx: HDD global context
8224 *
8225 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008226 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008227 * down to the lower layers. Then subscribe to subsequent channel
8228 * avoidance events.
8229 *
8230 * Return: None
8231 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008232static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008233{
8234 uint16_t unsafe_channel_count;
8235 int index;
8236
Yuanyuan Liu13738502016-04-06 17:41:37 -07008237 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8238 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008239 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008240 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008241
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008242 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008243 hdd_ctx->unsafe_channel_count);
8244
Anurag Chouhan6d760662016-02-20 16:05:43 +05308245 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008246 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008247
8248 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008249 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008250 hdd_ctx->unsafe_channel_list[index]);
8251
8252 }
8253
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008254}
Dustin Brown676a2322017-08-15 13:16:13 -07008255
Jeff Johnson9d295242017-08-29 14:39:48 -07008256static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008257 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008258{
8259 uint8_t restart_chan;
8260
8261 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8262 if (!restart_chan) {
8263 hdd_alert("fail to restart SAP");
8264 return;
8265 }
8266
8267 /* SAP restart due to unsafe channel. While restarting
8268 * the SAP, make sure to clear acs_channel, channel to
8269 * reset to 0. Otherwise these settings will override
8270 * the ACS while restart.
8271 */
8272 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008273 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008274
8275 hdd_debug("sending coex indication");
8276
8277 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8278 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008279 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008280}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008281
8282int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8283 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8284{
8285 uint32_t size;
8286 uint16_t *unsafe_list;
8287 uint16_t chan_count;
8288
8289 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8290 return -EINVAL;
8291
8292 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8293 NUM_CHANNELS);
8294 if (chan_count) {
8295 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8296 unsafe_list = qdf_mem_malloc(size);
8297 if (!unsafe_list) {
8298 hdd_err("No memory for unsafe chan list size%d",
8299 size);
8300 return -ENOMEM;
8301 }
8302 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8303 } else {
8304 unsafe_list = NULL;
8305 }
8306
8307 *local_unsafe_list = unsafe_list;
8308 *local_unsafe_list_count = chan_count;
8309
8310 return 0;
8311}
8312
8313bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8314 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8315{
8316 int i, j;
8317
8318 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8319 return true;
8320 if (local_unsafe_list_count == 0)
8321 return false;
8322 for (i = 0; i < local_unsafe_list_count; i++) {
8323 for (j = 0; j < local_unsafe_list_count; j++)
8324 if (local_unsafe_list[i] ==
8325 hdd_ctx->unsafe_channel_list[j])
8326 break;
8327 if (j >= local_unsafe_list_count)
8328 break;
8329 }
8330 if (i >= local_unsafe_list_count) {
8331 hdd_info("unsafe chan list same");
8332 return false;
8333 }
8334
8335 return true;
8336}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008337#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008338static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008339{
8340}
Dustin Brown676a2322017-08-15 13:16:13 -07008341
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008342static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008343{
8344}
Dustin Brown676a2322017-08-15 13:16:13 -07008345
Jeff Johnson9d295242017-08-29 14:39:48 -07008346static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008347 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008348{
8349 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8350}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008351#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008352
8353/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008354 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8355 * user space
8356 * @frame_ind: Management frame data to be informed.
8357 *
8358 * This function is used to indicate management frame to
8359 * user space
8360 *
8361 * Return: None
8362 *
8363 */
8364void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8365{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008366 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008367 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008368 int i;
8369
Dustin Browne7e71d32018-05-11 16:00:08 -07008370 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8371 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008372 return;
8373
8374 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8375 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8376 adapter =
8377 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8378 if (adapter)
8379 break;
8380 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008381 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8382 hdd_for_each_adapter(hdd_ctx, adapter) {
8383 if ((NULL != adapter) &&
8384 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8385 __hdd_indicate_mgmt_frame(adapter,
8386 frame_ind->frame_len,
8387 frame_ind->frameBuf,
8388 frame_ind->frameType,
8389 frame_ind->rxChan,
8390 frame_ind->rxRssi);
8391 }
8392 }
8393 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008394 } else {
8395 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8396 frame_ind->sessionId);
8397 }
8398
8399 if ((NULL != adapter) &&
8400 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8401 __hdd_indicate_mgmt_frame(adapter,
8402 frame_ind->frame_len,
8403 frame_ind->frameBuf,
8404 frame_ind->frameType,
8405 frame_ind->rxChan,
8406 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008407}
8408
Kapil Gupta8878ad92017-02-13 11:56:04 +05308409void hdd_acs_response_timeout_handler(void *context)
8410{
8411 struct hdd_external_acs_timer_context *timer_context =
8412 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008413 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008414 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308415 uint8_t reason;
8416
Dustin Brown491d54b2018-03-14 12:39:11 -07008417 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308418 if (!timer_context) {
8419 hdd_err("invlaid timer context");
8420 return;
8421 }
8422 adapter = timer_context->adapter;
8423 reason = timer_context->reason;
8424
8425
8426 if ((!adapter) ||
8427 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8428 hdd_err("invalid adapter or adapter has invalid magic");
8429 return;
8430 }
8431 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8432 if (wlan_hdd_validate_context(hdd_ctx))
8433 return;
8434
8435 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8436 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8437 else
8438 return;
8439
8440 hdd_err("ACS timeout happened for %s reason %d",
8441 adapter->dev->name, reason);
8442 switch (reason) {
8443 /* SAP init case */
8444 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8445 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8446 false);
8447 wlan_hdd_cfg80211_start_acs(adapter);
8448 break;
8449 /* DFS detected on current channel */
8450 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8451 wlan_sap_update_next_channel(
8452 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8453 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008454 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308455 break;
8456 /* LTE coex event on current channel */
8457 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8458 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8459 break;
8460 default:
8461 hdd_info("invalid reason for timer invoke");
8462
8463 }
8464}
8465
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008466/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008467 * hdd_override_ini_config - Override INI config
8468 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008469 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008470 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008471 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008472 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008473 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008474static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008475{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008476
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008477 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8478 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008479 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008480 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008481 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008482 if (0 == enable_11d || 1 == enable_11d) {
8483 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008484 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008485 }
Leo Chang11545d62016-10-17 14:53:50 -07008486
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308487 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008488 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008489 hdd_debug("IpaConfig override to %d",
8490 hdd_ctx->config->IpaConfig);
8491 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308492
8493 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8494 !hdd_ctx->config->enable_bcast_probe_rsp) {
8495 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8496 hdd_ctx->config->rssi_assoc_reject_enabled,
8497 hdd_ctx->config->enable_bcast_probe_rsp);
8498 hdd_ctx->config->oce_sta_enabled = 0;
8499 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008500}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008501
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008502/**
8503 * hdd_set_trace_level_for_each - Set trace level for each INI config
8504 * @hdd_ctx - HDD context
8505 *
8506 * Set trace level for each module based on INI config.
8507 *
8508 * Return: None
8509 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008510static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008511{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308512 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8513 hdd_ctx->config->qdf_trace_enable_wdi);
8514 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8515 hdd_ctx->config->qdf_trace_enable_hdd);
8516 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8517 hdd_ctx->config->qdf_trace_enable_sme);
8518 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8519 hdd_ctx->config->qdf_trace_enable_pe);
8520 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8521 hdd_ctx->config->qdf_trace_enable_wma);
8522 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8523 hdd_ctx->config->qdf_trace_enable_sys);
8524 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8525 hdd_ctx->config->qdf_trace_enable_qdf);
8526 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8527 hdd_ctx->config->qdf_trace_enable_sap);
8528 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8529 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8530 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8531 hdd_ctx->config->qdf_trace_enable_bmi);
8532 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8533 hdd_ctx->config->qdf_trace_enable_cfg);
8534 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8535 hdd_ctx->config->qdf_trace_enable_epping);
8536 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8537 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8538 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008539 hdd_ctx->config->qdf_trace_enable_txrx);
8540 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8541 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308542 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8543 hdd_ctx->config->qdf_trace_enable_htc);
8544 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8545 hdd_ctx->config->qdf_trace_enable_hif);
8546 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8547 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8548 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8549 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008550 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8551 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008552 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8553 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008554 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8555 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008556 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8557 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008558
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008559 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008560}
8561
8562/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008563 * hdd_context_init() - Initialize HDD context
8564 * @hdd_ctx: HDD context.
8565 *
8566 * Initialize HDD context along with all the feature specific contexts.
8567 *
8568 * return: 0 on success and errno on failure.
8569 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008570static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008571{
8572 int ret;
8573
8574 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8575 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8576
8577 hdd_init_ll_stats_ctx();
8578
8579 init_completion(&hdd_ctx->mc_sus_event_var);
8580 init_completion(&hdd_ctx->ready_to_suspend);
8581
8582 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308583 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008584 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308585
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008586 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008587
8588 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8589
8590 ret = hdd_scan_context_init(hdd_ctx);
8591 if (ret)
8592 goto list_destroy;
8593
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008594 hdd_rx_wake_lock_create(hdd_ctx);
8595
8596 ret = hdd_sap_context_init(hdd_ctx);
8597 if (ret)
8598 goto scan_destroy;
8599
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008600 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8601
8602 hdd_init_offloaded_packets_ctx(hdd_ctx);
8603
8604 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8605 hdd_ctx->config);
8606 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008607 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008608
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308609 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8610 "monitor_mode_wakelock");
8611
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008612 return 0;
8613
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008614sap_destroy:
8615 hdd_sap_context_destroy(hdd_ctx);
8616
8617scan_destroy:
8618 hdd_scan_context_destroy(hdd_ctx);
8619 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008620list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008621 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008622
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008623 return ret;
8624}
8625
8626/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308627 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8628 * @hdd_ctx: pointer to hdd context
8629 *
8630 * Return: status of initialization
8631 * 0 - success
8632 * negative value - failure
8633 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008634static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308635{
8636 int ret;
8637
8638 if (!hdd_ctx->config->probe_req_ie_whitelist)
8639 return 0;
8640
8641 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8642 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8643 hdd_ctx->config->probe_req_ie_whitelist = false;
8644 return -EINVAL;
8645 }
8646
8647 /* parse ini string probe req oui */
8648 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8649 if (ret) {
8650 hdd_err("parsing error: disable ie whitelisting");
8651 hdd_ctx->config->probe_req_ie_whitelist = false;
8652 }
8653
8654 return ret;
8655}
8656
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308657/**
8658 * hdd_iface_change_callback() - Function invoked when stop modules expires
8659 * @priv: pointer to hdd context
8660 *
8661 * This function is invoked when the timer waiting for the interface change
8662 * expires, it shall cut-down the power to wlan and stop all the modules.
8663 *
8664 * Return: void
8665 */
8666static void hdd_iface_change_callback(void *priv)
8667{
8668 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8669 int ret;
8670 int status = wlan_hdd_validate_context(hdd_ctx);
8671
8672 if (status)
8673 return;
8674
Dustin Brown491d54b2018-03-14 12:39:11 -07008675 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308676 hdd_debug("Interface change timer expired close the modules!");
8677 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8678 if (ret)
8679 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008680 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308681}
8682
Nirav Shaheb017be2018-02-15 11:20:58 +05308683#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8684static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8685{
8686 wlan_logging_set_log_to_console(hdd_ctx->config->
8687 wlan_logging_to_console);
8688 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8689}
8690#else
8691static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8692{ }
8693#endif
8694
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308695/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008696 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308697 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008698 *
8699 * Allocate and initialize HDD context. HDD context is allocated as part of
8700 * wiphy allocation and then context is initialized.
8701 *
8702 * Return: HDD context on success and ERR_PTR on failure
8703 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008704static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008705{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308706 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008707 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008708 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008709
Dustin Brown491d54b2018-03-14 12:39:11 -07008710 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008711
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008712 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008713 if (hdd_ctx == NULL) {
8714 ret = -ENOMEM;
8715 goto err_out;
8716 }
8717
Dustin Brown6f427922017-09-19 12:19:00 -07008718 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8719 hdd_iface_change_callback,
8720 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308721
8722 mutex_init(&hdd_ctx->iface_change_lock);
8723
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008724 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308725 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008726
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308727 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008728 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008729 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008730 ret = -ENOMEM;
8731 goto err_free_hdd_context;
8732 }
8733
8734 /* Read and parse the qcom_cfg.ini file */
8735 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308736 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308737 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008738 WLAN_INI_FILE);
8739 ret = -EINVAL;
8740 goto err_free_config;
8741 }
8742
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308743 ie_whitelist_attrs_init(hdd_ctx);
8744
Dustin Brown7f939932017-05-18 15:02:17 -07008745 hdd_debug("setting timer multiplier: %u",
8746 hdd_ctx->config->timer_multiplier);
8747 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8748
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008749
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308750 if (hdd_ctx->config->fhostNSOffload)
8751 hdd_ctx->ns_offload_enable = true;
8752
Abhishek Singh5ea86532016-04-27 14:10:53 +05308753 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8754
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008755 hdd_override_ini_config(hdd_ctx);
8756
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008757 ret = hdd_context_init(hdd_ctx);
8758
8759 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008760 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008761
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008762 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308763 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008764
Anurag Chouhan6d760662016-02-20 16:05:43 +05308765 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008766 goto skip_multicast_logging;
8767
8768 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8769
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008770 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8771 if (ret)
8772 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308773
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008774 ret = hdd_init_netlink_services(hdd_ctx);
8775 if (ret)
8776 goto err_deinit_txrx_histogram;
8777
Nirav Shaheb017be2018-02-15 11:20:58 +05308778 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308779
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008780skip_multicast_logging:
8781 hdd_set_trace_level_for_each(hdd_ctx);
8782
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008783 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8784
Dustin Browne74003f2018-03-14 12:51:58 -07008785 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008786
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008787 return hdd_ctx;
8788
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008789err_deinit_txrx_histogram:
8790 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8791
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008792err_deinit_hdd_context:
8793 hdd_context_deinit(hdd_ctx);
8794
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008795err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308796 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008797
8798err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308799 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008800 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008801
8802err_out:
8803 return ERR_PTR(ret);
8804}
8805
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008806#ifdef WLAN_OPEN_P2P_INTERFACE
8807/**
8808 * hdd_open_p2p_interface - Open P2P interface
8809 * @hdd_ctx: HDD context
8810 * @rtnl_held: True if RTNL lock held
8811 *
8812 * Open P2P interface during probe. This function called to open the P2P
8813 * interface at probe along with STA interface.
8814 *
8815 * Return: 0 on success and errno on failure
8816 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008817static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008818{
Jeff Johnson9d295242017-08-29 14:39:48 -07008819 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008820 uint8_t *p2p_dev_addr;
8821
8822 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8823 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008824 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008825 hdd_ctx->config->intfMacAddr[0].bytes,
8826 sizeof(tSirMacAddr));
8827
8828 /*
8829 * Generate the P2P Device Address. This consists of
8830 * the device's primary MAC address with the locally
8831 * administered bit set.
8832 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008833 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008834 } else {
8835 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8836 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008837 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008838 return -ENOSPC;
8839 }
8840
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008841 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8842 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008843 }
8844
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008845 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008846 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008847 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008848
8849 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008850 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008851 return -ENOSPC;
8852 }
8853
8854 return 0;
8855}
8856#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008857static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008858 bool rtnl_held)
8859{
8860 return 0;
8861}
8862#endif
8863
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008864static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008865{
Jeff Johnson9d295242017-08-29 14:39:48 -07008866 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008867 int ret = 0;
8868
8869 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8870 wlan_hdd_get_intf_addr(hdd_ctx),
8871 NET_NAME_UNKNOWN, rtnl_held);
8872 if (adapter == NULL) {
8873 hdd_err("Failed to open 802.11p interface");
8874 ret = -ENOSPC;
8875 }
8876
8877 return ret;
8878}
8879
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008880/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308881 * hdd_start_station_adapter()- Start the Station Adapter
8882 * @adapter: HDD adapter
8883 *
8884 * This function initializes the adapter for the station mode.
8885 *
8886 * Return: 0 on success or errno on failure.
8887 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008888int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308889{
8890 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008891 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308892
Dustin Brownfdf17c12018-03-14 12:55:34 -07008893 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008894 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8895 hdd_err("session is already opened, %d",
8896 adapter->session_id);
8897 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8898 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308899
Krunal Sonib51eec72017-11-20 21:53:01 -08008900 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8901 if (ret) {
8902 hdd_err("failed to create vdev: %d", ret);
8903 return ret;
8904 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308905 status = hdd_init_station_mode(adapter);
8906
8907 if (QDF_STATUS_SUCCESS != status) {
8908 hdd_err("Error Initializing station mode: %d", status);
8909 return qdf_status_to_os_return(status);
8910 }
8911
Arun Khandavallifae92942016-08-01 13:31:08 +05308912 hdd_register_tx_flow_control(adapter,
8913 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008914 hdd_tx_resume_cb,
8915 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308916
Dustin Browne74003f2018-03-14 12:51:58 -07008917 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308918 return 0;
8919}
8920
8921/**
8922 * hdd_start_ap_adapter()- Start AP Adapter
8923 * @adapter: HDD adapter
8924 *
8925 * This function initializes the adapter for the AP mode.
8926 *
8927 * Return: 0 on success errno on failure.
8928 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008929int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308930{
8931 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008932 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008933 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008934 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308935
Dustin Brown491d54b2018-03-14 12:39:11 -07008936 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308937
Krunal Sonib51eec72017-11-20 21:53:01 -08008938 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8939 hdd_err("session is already opened, %d",
8940 adapter->session_id);
8941 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8942 }
8943 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008944 * In SSR case no need to create new sap context.
8945 * Otherwise create sap context first and then create
8946 * vdev as while creating the vdev, driver needs to
8947 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008948 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008949 if (adapter->session.ap.sap_context) {
8950 is_ssr = true;
8951 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008952 hdd_err("sap creation failed");
8953 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8954 }
8955
8956 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8957 adapter->session.ap.sap_context);
8958 if (ret) {
8959 hdd_err("failed to create vdev, status:%d", ret);
8960 hdd_sap_destroy_ctx(adapter);
8961 return ret;
8962 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008963
8964 if (adapter->device_mode == QDF_SAP_MODE)
8965 sme_cli_set_command(adapter->session_id,
8966 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8967 (bool)(hdd_ctx->config->fine_time_meas_cap &
8968 WMI_FW_AP_RTT_RESPR),
8969 VDEV_CMD);
8970
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008971 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308972
8973 if (QDF_STATUS_SUCCESS != status) {
8974 hdd_err("Error Initializing the AP mode: %d", status);
8975 return qdf_status_to_os_return(status);
8976 }
8977
Arun Khandavallifae92942016-08-01 13:31:08 +05308978 hdd_register_tx_flow_control(adapter,
8979 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008980 hdd_softap_tx_resume_cb,
8981 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308982
Dustin Browne74003f2018-03-14 12:51:58 -07008983 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308984 return 0;
8985}
8986
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308987static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8988 bool rtnl_held)
8989{
8990 struct hdd_adapter *adapter;
8991
8992 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8993 hdd_ctx->config->enableConcurrentSTA,
8994 wlan_hdd_get_intf_addr(hdd_ctx),
8995 NET_NAME_UNKNOWN, rtnl_held);
8996
8997 if (!adapter)
8998 return -ENOSPC;
8999
9000 return 0;
9001}
9002
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309003/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009004 * hdd_open_interfaces - Open all required interfaces
9005 * hdd_ctx: HDD context
9006 * rtnl_held: True if RTNL lock is held
9007 *
9008 * Open all the interfaces like STA, P2P and OCB based on the configuration.
9009 *
Jeff Johnson957bc272017-02-02 08:54:48 -08009010 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009011 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009012static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009013{
Jeff Johnson9d295242017-08-29 14:39:48 -07009014 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009015 int ret;
9016
Ravi Joshia307f632017-07-17 23:41:41 -07009017 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08009018 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
9019 con_mode == QDF_GLOBAL_FTM_MODE) {
9020 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
9021 QDF_MONITOR_MODE : QDF_FTM_MODE;
9022
9023 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
9024 wlan_hdd_get_intf_addr(hdd_ctx),
9025 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07009026 if (!adapter) {
9027 hdd_err("open adapter failed");
9028 return -ENOSPC;
9029 }
Lin Bai1c678482017-12-18 18:29:11 +08009030
Ravi Joshia307f632017-07-17 23:41:41 -07009031 return 0;
9032 }
9033
Jeff Johnson957bc272017-02-02 08:54:48 -08009034 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05309035 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08009036 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009037
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009038 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009039 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08009040 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009041
9042 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08009043 return -ENOSPC;
9044
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309045 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
9046 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
9047 if (ret)
9048 hdd_err("Cannot create concurrent STA interface");
9049 }
9050
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009051 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
9052 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009053 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009054
9055 /* Open 802.11p Interface */
9056 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009057 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
9058 if (ret)
9059 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009060 }
9061
Jeff Johnson957bc272017-02-02 08:54:48 -08009062 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009063
Jeff Johnson957bc272017-02-02 08:54:48 -08009064err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009065 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08009066 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009067}
9068
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009069
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309070#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9071/**
9072 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9073 * @cds_cfg: CDS Configuration
9074 * @hdd_ctx: Pointer to hdd context
9075 *
9076 * Return: none
9077 */
9078static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9079 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009080 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309081{
9082 cds_cfg->tx_flow_stop_queue_th =
9083 hdd_ctx->config->TxFlowStopQueueThreshold;
9084 cds_cfg->tx_flow_start_queue_offset =
9085 hdd_ctx->config->TxFlowStartQueueOffset;
9086}
9087#else
9088static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9089 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009090 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309091{
9092}
9093#endif
9094
9095#ifdef FEATURE_WLAN_RA_FILTERING
9096/**
9097 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9098 * @cds_cfg: CDS Configuration
9099 * @hdd_ctx: Pointer to hdd context
9100 *
9101 * Return: none
9102 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309103static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009104 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309105{
9106 cds_cfg->ra_ratelimit_interval =
9107 hdd_ctx->config->RArateLimitInterval;
9108 cds_cfg->is_ra_ratelimit_enabled =
9109 hdd_ctx->config->IsRArateLimitEnabled;
9110}
9111#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309112static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009113 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309114{
9115}
9116#endif
9117
9118/**
9119 * hdd_update_cds_config() - API to update cds configuration parameters
9120 * @hdd_ctx: HDD Context
9121 *
9122 * Return: 0 for Success, errno on failure
9123 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009124static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309125{
9126 struct cds_config_info *cds_cfg;
9127
9128 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9129 if (!cds_cfg) {
9130 hdd_err("failed to allocate cds config");
9131 return -ENOMEM;
9132 }
9133
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009134 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009135 if (!hdd_ctx->config->nMaxPsPoll ||
9136 !hdd_ctx->config->enablePowersaveOffload) {
9137 cds_cfg->powersave_offload_enabled =
9138 hdd_ctx->config->enablePowersaveOffload;
9139 } else {
9140 if ((hdd_ctx->config->enablePowersaveOffload ==
9141 PS_QPOWER_NODEEPSLEEP) ||
9142 (hdd_ctx->config->enablePowersaveOffload ==
9143 PS_LEGACY_NODEEPSLEEP))
9144 cds_cfg->powersave_offload_enabled =
9145 PS_LEGACY_NODEEPSLEEP;
9146 else
9147 cds_cfg->powersave_offload_enabled =
9148 PS_LEGACY_DEEPSLEEP;
9149 hdd_info("Qpower disabled in cds config, %d",
9150 cds_cfg->powersave_offload_enabled);
9151 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309152 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9153 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9154 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9155 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309156
9157 /*
9158 * Copy the DFS Phyerr Filtering Offload status.
9159 * This parameter reflects the value of the
9160 * dfs_phyerr_filter_offload flag as set in the ini.
9161 */
9162 cds_cfg->dfs_phyerr_filter_offload =
9163 hdd_ctx->config->fDfsPhyerrFilterOffload;
9164 if (hdd_ctx->config->ssdp)
9165 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9166
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309167 cds_cfg->force_target_assert_enabled =
9168 hdd_ctx->config->crash_inject_enabled;
9169
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309170 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9171 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9172
9173 cds_cfg->ap_maxoffload_reorderbuffs =
9174 hdd_ctx->config->apMaxOffloadReorderBuffs;
9175
9176 cds_cfg->ap_disable_intrabss_fwd =
9177 hdd_ctx->config->apDisableIntraBssFwd;
9178
9179 cds_cfg->dfs_pri_multiplier =
9180 hdd_ctx->config->dfsRadarPriMultiplier;
9181 cds_cfg->reorder_offload =
9182 hdd_ctx->config->reorderOffloadSupport;
9183
9184 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309185 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009186 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9187 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009188 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009189 hdd_ctx->config->IpaUcTxBufCount);
9190 hdd_ctx->config->IpaUcTxBufCount =
9191 rounddown_pow_of_two(
9192 hdd_ctx->config->IpaUcTxBufCount);
9193 if (!hdd_ctx->config->IpaUcTxBufCount) {
9194 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309195 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009196 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009197 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009198 hdd_ctx->config->IpaUcTxBufCount);
9199 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309200 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9201 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009202 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9203 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009204 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009205 hdd_ctx->config->IpaUcRxIndRingCount);
9206 hdd_ctx->config->IpaUcRxIndRingCount =
9207 rounddown_pow_of_two(
9208 hdd_ctx->config->IpaUcRxIndRingCount);
9209 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9210 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309211 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009212 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009213 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009214 hdd_ctx->config->IpaUcRxIndRingCount);
9215 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309216 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009217 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309218 cds_cfg->uc_tx_partition_base =
9219 hdd_ctx->config->IpaUcTxPartitionBase;
9220 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9221
9222 cds_cfg->ip_tcp_udp_checksum_offload =
9223 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009224 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309225 cds_cfg->ce_classify_enabled =
9226 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07009227 cds_cfg->bpf_packet_filter_enable =
9228 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309229 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9230 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9231 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009232 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009233 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009234 cds_cfg->max_msdus_per_rxinorderind =
9235 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009236 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009237 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05309238 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
9239 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309240 cds_cfg->auto_power_save_fail_mode =
9241 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309242
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309243 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009244 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009245 cds_cfg->delay_before_vdev_stop =
9246 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309247
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309248 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9249 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9250 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009251 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309252 cds_init_ini_config(cds_cfg);
9253 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309254
9255exit:
9256 qdf_mem_free(cds_cfg);
9257 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309258}
9259
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009260/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009261 * hdd_update_user_config() - API to update user configuration
9262 * parameters to obj mgr which are used by multiple components
9263 * @hdd_ctx: HDD Context
9264 *
9265 * Return: 0 for Success, errno on failure
9266 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009267static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009268{
9269 struct wlan_objmgr_psoc_user_config *user_config;
9270
9271 user_config = qdf_mem_malloc(sizeof(*user_config));
9272 if (user_config == NULL) {
9273 hdd_alert("Failed to alloc memory for user_config!");
9274 return -ENOMEM;
9275 }
9276
9277 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9278 user_config->dual_mac_feature_disable =
9279 hdd_ctx->config->dual_mac_feature_disable;
9280 user_config->indoor_channel_support =
9281 hdd_ctx->config->indoor_channel_support;
9282 user_config->is_11d_support_enabled =
9283 hdd_ctx->config->Is11dSupportEnabled;
9284 user_config->is_11h_support_enabled =
9285 hdd_ctx->config->Is11hSupportEnabled;
9286 user_config->optimize_chan_avoid_event =
9287 hdd_ctx->config->goptimize_chan_avoid_event;
9288 user_config->skip_dfs_chnl_in_p2p_search =
9289 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009290 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009291 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9292
9293 qdf_mem_free(user_config);
9294 return 0;
9295}
9296
9297/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009298 * hdd_init_thermal_info - Initialize thermal level
9299 * @hdd_ctx: HDD context
9300 *
9301 * Initialize thermal level at SME layer and set the thermal level callback
9302 * which would be called when a configured thermal threshold is hit.
9303 *
9304 * Return: 0 on success and errno on failure
9305 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009306static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009307{
9308 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309309 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009310
9311 thermal_param.smeThermalMgmtEnabled =
9312 hdd_ctx->config->thermalMitigationEnable;
9313 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9314
Poddar, Siddarth83905022016-04-16 17:56:08 -07009315 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9316 hdd_ctx->config->throttle_dutycycle_level0;
9317 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9318 hdd_ctx->config->throttle_dutycycle_level1;
9319 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9320 hdd_ctx->config->throttle_dutycycle_level2;
9321 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9322 hdd_ctx->config->throttle_dutycycle_level3;
9323
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009324 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9325 hdd_ctx->config->thermalTempMinLevel0;
9326 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9327 hdd_ctx->config->thermalTempMaxLevel0;
9328 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9329 hdd_ctx->config->thermalTempMinLevel1;
9330 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9331 hdd_ctx->config->thermalTempMaxLevel1;
9332 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9333 hdd_ctx->config->thermalTempMinLevel2;
9334 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9335 hdd_ctx->config->thermalTempMaxLevel2;
9336 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9337 hdd_ctx->config->thermalTempMinLevel3;
9338 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9339 hdd_ctx->config->thermalTempMaxLevel3;
9340
9341 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9342
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309343 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309344 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009345
9346 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9347 hdd_set_thermal_level_cb);
9348
9349 return 0;
9350
9351}
9352
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009353#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9354/**
9355 * hdd_hold_rtnl_lock - Hold RTNL lock
9356 *
9357 * Hold RTNL lock
9358 *
9359 * Return: True if held and false otherwise
9360 */
9361static inline bool hdd_hold_rtnl_lock(void)
9362{
9363 rtnl_lock();
9364 return true;
9365}
9366
9367/**
9368 * hdd_release_rtnl_lock - Release RTNL lock
9369 *
9370 * Release RTNL lock
9371 *
9372 * Return: None
9373 */
9374static inline void hdd_release_rtnl_lock(void)
9375{
9376 rtnl_unlock();
9377}
9378#else
9379static inline bool hdd_hold_rtnl_lock(void) { return false; }
9380static inline void hdd_release_rtnl_lock(void) { }
9381#endif
9382
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009383#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009384
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309385/* MAX iwpriv command support */
9386#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309387#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309388#define MAX_PKTLOG_SIZE 16
9389
9390/**
9391 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9392 * @hdd_ctx: hdd context
9393 * @set_value2: pktlog buffer size value
9394 *
9395 *
9396 * Return: 0 for success or error.
9397 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009398static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309399{
9400 struct sir_wifi_start_log start_log = { 0 };
9401 QDF_STATUS status;
9402
9403 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9404 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9405 start_log.ini_triggered = cds_is_packet_log_enabled();
9406 start_log.user_triggered = 1;
9407 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309408 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309409
9410 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9411 if (!QDF_IS_STATUS_SUCCESS(status)) {
9412 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009413 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309414 return -EINVAL;
9415 }
9416
9417 return 0;
9418}
9419
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009420/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309421 * hdd_pktlog_clear_buff() - clear pktlog buffer
9422 * @hdd_ctx: hdd context
9423 *
9424 * Return: 0 for success or error.
9425 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009426static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309427{
9428 struct sir_wifi_start_log start_log;
9429 QDF_STATUS status;
9430
9431 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9432 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9433 start_log.ini_triggered = cds_is_packet_log_enabled();
9434 start_log.user_triggered = 1;
9435 start_log.size = 0;
9436 start_log.is_pktlog_buff_clear = true;
9437
9438 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9439 if (!QDF_IS_STATUS_SUCCESS(status)) {
9440 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009441 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309442 return -EINVAL;
9443 }
9444
9445 return 0;
9446}
9447
9448
9449/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009450 * hdd_process_pktlog_command() - process pktlog command
9451 * @hdd_ctx: hdd context
9452 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309453 * @set_value2: pktlog buffer size value
9454 *
9455 * This function process pktlog command.
9456 * set_value2 only matters when set_value is 3 (set buff size)
9457 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009458 *
9459 * Return: 0 for success or error.
9460 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009461int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309462 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009463{
9464 int ret;
9465 bool enable;
9466 uint8_t user_triggered = 0;
9467
9468 ret = wlan_hdd_validate_context(hdd_ctx);
9469 if (0 != ret)
9470 return ret;
9471
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009472 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009473
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309474 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009475 hdd_err("invalid pktlog value %d", set_value);
9476 return -EINVAL;
9477 }
9478
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309479 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9480 if (set_value2 <= 0) {
9481 hdd_err("invalid pktlog size %d", set_value2);
9482 return -EINVAL;
9483 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9484 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9485 return -EINVAL;
9486 }
9487 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309488 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9489 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309490 }
9491
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009492 /*
9493 * set_value = 0 then disable packetlog
9494 * set_value = 1 enable packetlog forcefully
9495 * set_vlaue = 2 then disable packetlog if disabled through ini or
9496 * enable packetlog with AUTO type.
9497 */
9498 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9499 true : false;
9500
9501 if (1 == set_value) {
9502 enable = true;
9503 user_triggered = 1;
9504 }
9505
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309506 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009507}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009508
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009509/**
9510 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9511 * @hdd_ctx: HDD context
9512 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309513 * @user_triggered: triggered through iwpriv
9514 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009515 *
9516 * Return: 0 on success; error number otherwise
9517 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009518int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309519 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009520{
9521 struct sir_wifi_start_log start_log;
9522 QDF_STATUS status;
9523
9524 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9525 start_log.verbose_level =
9526 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009527 start_log.ini_triggered = cds_is_packet_log_enabled();
9528 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309529 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309530 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309531 /*
9532 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9533 * commands. Host uses this flag to decide whether to send pktlog
9534 * disable command to fw without sending pktlog enable command
9535 * previously. For eg, If vendor sends pktlog disable command without
9536 * sending pktlog enable command, then host discards the packet
9537 * but for iwpriv command, host will send it to fw.
9538 */
9539 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009540 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9541 if (!QDF_IS_STATUS_SUCCESS(status)) {
9542 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009543 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009544 return -EINVAL;
9545 }
9546
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309547 if (enable == true)
9548 hdd_ctx->is_pktlog_enabled = 1;
9549 else
9550 hdd_ctx->is_pktlog_enabled = 0;
9551
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009552 return 0;
9553}
9554#endif /* REMOVE_PKT_LOG */
9555
Komal Seelam92fff912016-03-24 11:51:41 +05309556/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009557 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9558 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309559 * @dev: Device Pointer
9560 * @num: Number of Valid Mac address
9561 *
9562 * Return: Pointer to MAC address buffer
9563 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009564static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9565 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309566{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009567 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309568}
Komal Seelam92fff912016-03-24 11:51:41 +05309569
9570/**
9571 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9572 * @hdd_ctx: HDD Context
9573 * @num: Number of random mac addresses needed
9574 *
9575 * Generate random addresses using bit manipulation on the base mac address
9576 *
9577 * Return: None
9578 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009579void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309580{
9581 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9582 uint32_t iter;
9583 struct hdd_config *ini = hdd_ctx->config;
9584 uint8_t *buf = NULL;
9585 uint8_t macaddr_b3, tmp_br3;
9586 uint8_t *src = ini->intfMacAddr[0].bytes;
9587
9588 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9589 buf = ini->intfMacAddr[iter].bytes;
9590 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9591 macaddr_b3 = buf[3];
9592 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9593 INTF_MACADDR_MASK;
9594 macaddr_b3 += tmp_br3;
9595 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9596 buf[0] |= 0x02;
9597 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009598 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309599 }
9600}
9601
9602/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009603 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309604 * @hdd_ctx: HDD Context
9605 *
9606 * API to get mac addresses from platform driver and update the driver
9607 * structures and configure FW with the base mac address.
9608 * Return: int
9609 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009610static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309611{
9612 uint32_t no_of_mac_addr, iter;
9613 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9614 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9615 uint8_t *addr, *buf;
9616 struct device *dev = hdd_ctx->parent_dev;
9617 struct hdd_config *ini = hdd_ctx->config;
9618 tSirMacAddr mac_addr;
9619 QDF_STATUS status;
9620
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009621 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309622
9623 if (no_of_mac_addr == 0 || !addr) {
9624 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9625 return -EINVAL;
9626 }
9627
9628 if (no_of_mac_addr > max_mac_addr)
9629 no_of_mac_addr = max_mac_addr;
9630
9631 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9632
9633 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9634 buf = ini->intfMacAddr[iter].bytes;
9635 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009636 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309637 }
9638
9639 status = sme_set_custom_mac_addr(mac_addr);
9640
9641 if (!QDF_IS_STATUS_SUCCESS(status))
9642 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009643
Komal Seelam92fff912016-03-24 11:51:41 +05309644 if (no_of_mac_addr < max_mac_addr)
9645 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9646 no_of_mac_addr);
9647 return 0;
9648}
9649
9650/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009651 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9652 * @hdd_ctx: HDD Context
9653 *
9654 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9655 * will generate its own MAC and update it to FW.
9656 *
9657 * Return: 0 for success
9658 * Non-zero error code for failure
9659 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009660static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009661{
9662 tSirMacAddr customMacAddr;
9663 QDF_STATUS status;
9664
9665 qdf_mem_copy(&customMacAddr,
9666 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9667 sizeof(tSirMacAddr));
9668 status = sme_set_custom_mac_addr(customMacAddr);
9669 if (!QDF_IS_STATUS_SUCCESS(status))
9670 return -EAGAIN;
9671 return 0;
9672}
9673
9674/**
Komal Seelam92fff912016-03-24 11:51:41 +05309675 * hdd_initialize_mac_address() - API to get wlan mac addresses
9676 * @hdd_ctx: HDD Context
9677 *
9678 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9679 * is provisioned with mac addresses, driver uses it, else it will use
9680 * wlan_mac.bin to update HW MAC addresses.
9681 *
9682 * Return: None
9683 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009684static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309685{
9686 QDF_STATUS status;
9687 int ret;
9688
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009689 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309690 if (ret == 0)
9691 return;
9692
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009693 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9694 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309695
9696 status = hdd_update_mac_config(hdd_ctx);
9697
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009698 if (QDF_IS_STATUS_SUCCESS(status))
9699 return;
9700
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009701 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9702 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009703
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009704 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009705 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009706 if (ret != 0) {
9707 hdd_err("MAC address out-of-sync, ret:%d", ret);
9708 QDF_ASSERT(ret);
9709 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009710 }
Komal Seelam92fff912016-03-24 11:51:41 +05309711}
9712
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009713static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009714{
9715 int vdev_id = 0;
9716 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9717 int value = hdd_ctx->config->smart_chainmask_enabled;
9718 int vpdev = PDEV_CMD;
9719 int ret;
9720
Naveen Rawat247a8682017-06-05 15:00:31 -07009721 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009722 if (ret)
9723 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9724
9725 return ret;
9726}
9727
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009728static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009729{
9730 int vdev_id = 0;
9731 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9732 int value = hdd_ctx->config->alternative_chainmask_enabled;
9733 int vpdev = PDEV_CMD;
9734 int ret;
9735
Naveen Rawat247a8682017-06-05 15:00:31 -07009736 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009737 if (ret)
9738 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9739 ret);
9740
9741 return ret;
9742}
9743
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009744static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009745{
9746 int vdev_id = 0;
9747 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9748 int value = hdd_ctx->config->ani_enabled;
9749 int vpdev = PDEV_CMD;
9750 int ret;
9751
Naveen Rawat247a8682017-06-05 15:00:31 -07009752 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009753 if (ret)
9754 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9755
9756 return ret;
9757}
9758
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009759/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009760 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9761 * @hdd_ctx: HDD context
9762 *
9763 * Pre configurations to be done at lower layer before calling cds enable.
9764 *
9765 * Return: 0 on success and errno on failure.
9766 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009767static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009768{
9769 int ret;
9770 QDF_STATUS status;
9771 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009772 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009773
Leo Changfdb45c32016-10-28 11:09:23 -07009774 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009775 /*
9776 * Set 802.11p config
9777 * TODO-OCB: This has been temporarily added here to ensure this
9778 * parameter is set in CSR when we init the channel list. This should
9779 * be removed once the 5.9 GHz channels are added to the regulatory
9780 * domain.
9781 */
9782 hdd_set_dot11p_config(hdd_ctx);
9783
9784 /*
9785 * Note that the cds_pre_enable() sequence triggers the cfg download.
9786 * The cfg download must occur before we update the SME config
9787 * since the SME config operation must access the cfg database
9788 */
9789 status = hdd_set_sme_config(hdd_ctx);
9790
9791 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009792 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009793 ret = qdf_status_to_os_return(status);
9794 goto out;
9795 }
9796
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009797 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9798 if (QDF_STATUS_SUCCESS != status) {
9799 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9800 ret = qdf_status_to_os_return(status);
9801 goto out;
9802 }
9803
Naveen Rawat247a8682017-06-05 15:00:31 -07009804 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009805 hdd_ctx->config->tx_chain_mask_1ss,
9806 PDEV_CMD);
9807 if (0 != ret) {
9808 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9809 goto out;
9810 }
9811
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009812 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9813 if (ret)
9814 goto out;
9815
9816 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9817 if (ret)
9818 goto out;
9819
Jeff Johnson12a744b2017-04-04 08:19:37 -07009820 ret = hdd_set_ani_enabled(hdd_ctx);
9821 if (ret)
9822 goto out;
9823
Naveen Rawat247a8682017-06-05 15:00:31 -07009824 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009825 hdd_ctx->config->arp_ac_category,
9826 PDEV_CMD);
9827 if (0 != ret) {
9828 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9829 hdd_ctx->config->arp_ac_category, ret);
9830 goto out;
9831 }
9832
Prashanth Bhatta07998752016-04-28 12:35:33 -07009833 status = hdd_set_sme_chan_list(hdd_ctx);
9834 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009835 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009836 ret = qdf_status_to_os_return(status);
9837 goto out;
9838 }
9839
9840 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009841 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009842 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009843 ret = -EINVAL;
9844 goto out;
9845 }
9846
Prashanth Bhatta07998752016-04-28 12:35:33 -07009847 /*
9848 * Set the MAC Address Currently this is used by HAL to add self sta.
9849 * Remove this once self sta is added as part of session open.
9850 */
9851 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9852 hdd_ctx->config->intfMacAddr[0].bytes,
9853 sizeof(hdd_ctx->config->intfMacAddr[0]));
9854
9855 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9856 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9857 hal_status, hal_status);
9858 ret = -EINVAL;
9859 goto out;
9860 }
9861
9862 hdd_init_channel_avoidance(hdd_ctx);
9863
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309864 /* update enable sap mandatory chan list */
9865 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9866 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009867out:
9868 return ret;
9869}
9870
9871/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009872 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9873 * @context_ptr - hdd context pointer
9874 * @event_ptr - event structure pointer
9875 *
9876 * This is the p2p listen offload stop event handler, it sends vendor
9877 * event back to supplicant to notify the stop reason.
9878 *
9879 * Return: None
9880 */
9881static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9882 void *event_ptr)
9883{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009884 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009885 struct sir_p2p_lo_event *evt = event_ptr;
9886 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009887 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009888
Dustin Brown491d54b2018-03-14 12:39:11 -07009889 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009890
9891 if (hdd_ctx == NULL) {
9892 hdd_err("Invalid HDD context pointer");
9893 return;
9894 }
9895
Peng Xu5c682812017-08-06 07:39:13 -07009896 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9897 if (!adapter) {
9898 hdd_err("Cannot find adapter by vdev_id = %d",
9899 evt->vdev_id);
9900 return;
9901 }
9902
Peng Xu8fdaa492016-06-22 10:20:47 -07009903 vendor_event =
9904 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009905 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009906 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9907 GFP_KERNEL);
9908
9909 if (!vendor_event) {
9910 hdd_err("cfg80211_vendor_event_alloc failed");
9911 return;
9912 }
9913
9914 if (nla_put_u32(vendor_event,
9915 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9916 evt->reason_code)) {
9917 hdd_err("nla put failed");
9918 kfree_skb(vendor_event);
9919 return;
9920 }
9921
9922 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009923 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9924 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009925}
9926
9927/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309928 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9929 * @hdd_ctx: HDD context
9930 *
9931 * This function sends the adaptive dwell time config configuration to the
9932 * firmware via WMA
9933 *
9934 * Return: 0 - success, < 0 - failure
9935 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009936static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309937{
9938 QDF_STATUS status;
9939 struct adaptive_dwelltime_params dwelltime_params;
9940
9941 dwelltime_params.is_enabled =
9942 hdd_ctx->config->adaptive_dwell_mode_enabled;
9943 dwelltime_params.dwelltime_mode =
9944 hdd_ctx->config->global_adapt_dwelltime_mode;
9945 dwelltime_params.lpf_weight =
9946 hdd_ctx->config->adapt_dwell_lpf_weight;
9947 dwelltime_params.passive_mon_intval =
9948 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9949 dwelltime_params.wifi_act_threshold =
9950 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9951
9952 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9953 &dwelltime_params);
9954
9955 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9956 if (!QDF_IS_STATUS_SUCCESS(status)) {
9957 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9958 return -EAGAIN;
9959 }
9960 return 0;
9961}
9962
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009963int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309964{
9965 QDF_STATUS status;
9966 struct wmi_dbs_scan_sel_params dbs_scan_params;
9967 uint32_t i = 0;
9968 uint8_t count = 0, numentries = 0;
9969 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9970 * CDS_DBS_SCAN_CLIENTS_MAX];
9971
9972 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +05309973 if ((hdd_ctx->config->dual_mac_feature_disable ==
9974 DISABLE_DBS_CXN_AND_SCAN) ||
9975 (hdd_ctx->config->dual_mac_feature_disable ==
9976 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309977 return -EINVAL;
9978
9979 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9980 dbs_scan_config, &numentries,
9981 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9982 * CDS_DBS_SCAN_CLIENTS_MAX));
9983
9984 hdd_info("numentries %hu", numentries);
9985 if (!numentries) {
9986 hdd_info("Donot send scan_selection_config");
9987 return 0;
9988 }
9989
9990 /* hdd_set_fw_log_params */
9991 dbs_scan_params.num_clients = 0;
9992 while (count < (numentries - 2)) {
9993 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9994 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9995 dbs_scan_params.num_non_dbs_scans[i] =
9996 dbs_scan_config[count + 2];
9997 dbs_scan_params.num_clients++;
9998 hdd_debug("module:%d NDS:%d NNDS:%d",
9999 dbs_scan_params.module_id[i],
10000 dbs_scan_params.num_dbs_scans[i],
10001 dbs_scan_params.num_non_dbs_scans[i]);
10002 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10003 i++;
10004 }
10005
10006 dbs_scan_params.pdev_id = 0;
10007
10008 hdd_debug("clients:%d pdev:%d",
10009 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10010
10011 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
10012 &dbs_scan_params);
10013 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10014 if (!QDF_IS_STATUS_SUCCESS(status)) {
10015 hdd_err("Failed to send DBS Scan selection configuration!");
10016 return -EAGAIN;
10017 }
10018 return 0;
10019}
10020
Arun Khandavallid4349a92016-07-25 11:10:43 +053010021#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10022/**
10023 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10024 * @hdd_ctx: HDD context
10025 *
10026 * Set auto shutdown callback to get indications from firmware to indicate
10027 * userspace to shutdown WLAN after a configured amount of inactivity.
10028 *
10029 * Return: 0 on success and errno on failure.
10030 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010031static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010032{
10033 QDF_STATUS status;
10034
10035 if (!hdd_ctx->config->WlanAutoShutdown)
10036 return 0;
10037
10038 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
10039 wlan_hdd_auto_shutdown_cb);
10040 if (status != QDF_STATUS_SUCCESS)
10041 hdd_err("Auto shutdown feature could not be enabled: %d",
10042 status);
10043
10044 return qdf_status_to_os_return(status);
10045}
10046#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010047static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010048{
10049 return 0;
10050}
10051#endif
10052
10053/**
10054 * hdd_features_init() - Init features
10055 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010056 *
10057 * Initialize features and their feature context after WLAN firmware is up.
10058 *
10059 * Return: 0 on success and errno on failure.
10060 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010061static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010062{
10063 tSirTxPowerLimit hddtxlimit;
10064 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +053010065 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010066 int ret;
10067
Dustin Brown491d54b2018-03-14 12:39:11 -070010068 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010069
Arun Khandavallid4349a92016-07-25 11:10:43 +053010070 /* FW capabilities received, Set the Dot11 mode */
10071 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -070010072 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
10073 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010074
Arun Khandavallid4349a92016-07-25 11:10:43 +053010075
10076 if (hdd_ctx->config->fIsImpsEnabled)
10077 hdd_set_idle_ps_config(hdd_ctx, true);
10078 else
10079 hdd_set_idle_ps_config(hdd_ctx, false);
10080
Poddar, Siddarth37033032017-10-11 15:47:40 +053010081 /* Send Enable/Disable data stall detection cmd to FW */
10082 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10083 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10084
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010085 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010086 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010087
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010088 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
10089 hdd_warn("Error in setting Voltage Corner mode config to FW");
10090
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010091 if (hdd_rx_ol_init(hdd_ctx))
10092 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010093
10094 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10095 hdd_err("Unable to send adaptive dwelltime setting to FW");
10096
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010097 if (hdd_dbs_scan_selection_init(hdd_ctx))
10098 hdd_err("Unable to send DBS scan selection setting to FW");
10099
Arun Khandavallid4349a92016-07-25 11:10:43 +053010100 ret = hdd_init_thermal_info(hdd_ctx);
10101 if (ret) {
10102 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010103 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010104 }
10105
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010106 /**
10107 * In case of SSR/PDR, if pktlog was enabled manually before
10108 * SSR/PDR, Then enabled it again automatically after Wlan
10109 * device up.
10110 */
10111 if (cds_is_driver_recovering()) {
10112 if (hdd_ctx->is_pktlog_enabled)
10113 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +080010114 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010115
Arun Khandavallid4349a92016-07-25 11:10:43 +053010116 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10117 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
10118 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
10119 if (!QDF_IS_STATUS_SUCCESS(status))
10120 hdd_err("Error setting txlimit in sme: %d", status);
10121
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010122 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010123
Arun Khandavallid4349a92016-07-25 11:10:43 +053010124 ret = hdd_register_cb(hdd_ctx);
10125 if (ret) {
10126 hdd_err("Failed to register HDD callbacks!");
Dustin Browne7e71d32018-05-11 16:00:08 -070010127 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010128 }
10129
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010130 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10131 status = sme_enable_disable_chanavoidind_event(
10132 hdd_ctx->hHal, 0);
10133 if (!QDF_IS_STATUS_SUCCESS(status)) {
10134 hdd_err("Failed to disable Chan Avoidance Indication");
10135 goto deregister_cb;
10136 }
10137 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010138
Manjeet Singha9cae432017-02-28 11:58:22 +053010139 if (hdd_ctx->config->enable_5g_band_pref) {
10140 band_pref_params.rssi_boost_threshold_5g =
10141 hdd_ctx->config->rssi_boost_threshold_5g;
10142 band_pref_params.rssi_boost_factor_5g =
10143 hdd_ctx->config->rssi_boost_factor_5g;
10144 band_pref_params.max_rssi_boost_5g =
10145 hdd_ctx->config->max_rssi_boost_5g;
10146 band_pref_params.rssi_penalize_threshold_5g =
10147 hdd_ctx->config->rssi_penalize_threshold_5g;
10148 band_pref_params.rssi_penalize_factor_5g =
10149 hdd_ctx->config->rssi_penalize_factor_5g;
10150 band_pref_params.max_rssi_penalize_5g =
10151 hdd_ctx->config->max_rssi_penalize_5g;
10152 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
10153 }
10154
Arun Khandavallid4349a92016-07-25 11:10:43 +053010155 /* register P2P Listen Offload event callback */
10156 if (wma_is_p2p_lo_capable())
10157 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
10158 wlan_hdd_p2p_lo_event_callback);
10159
10160 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10161
10162 if (ret)
10163 goto deregister_cb;
10164
Dustin Brown11638b72018-01-25 17:37:25 +053010165 wlan_hdd_init_chan_info(hdd_ctx);
10166
Dustin Browne74003f2018-03-14 12:51:58 -070010167 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010168 return 0;
10169
10170deregister_cb:
10171 hdd_deregister_cb(hdd_ctx);
Dustin Browne7e71d32018-05-11 16:00:08 -070010172
Arun Khandavallid4349a92016-07-25 11:10:43 +053010173 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010174}
10175
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010176/**
10177 * hdd_features_deinit() - Deinit features
10178 * @hdd_ctx: HDD context
10179 *
10180 * De-Initialize features and their feature context.
10181 *
10182 * Return: none.
10183 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010184static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010185{
Dustin Brown11638b72018-01-25 17:37:25 +053010186 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010187 wlan_hdd_tsf_deinit(hdd_ctx);
10188}
10189
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010190/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010191 * hdd_register_bcn_cb() - register scan beacon callback
10192 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010193 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010194 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010195 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010196static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010197{
10198 QDF_STATUS status;
10199
10200 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10201 wlan_cfg80211_inform_bss_frame,
10202 SCAN_CB_TYPE_INFORM_BCN);
10203 if (!QDF_IS_STATUS_SUCCESS(status)) {
10204 hdd_err("failed with status code %08d [x%08x]",
10205 status, status);
10206 return status;
10207 }
10208
10209 return QDF_STATUS_SUCCESS;
10210}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010211
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010212/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010213 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10214 * @vdev_id: vdev_id, corresponds to flow_pool
10215 *
10216 * Return: none.
10217 */
10218static void hdd_v2_flow_pool_map(int vdev_id)
10219{
10220 QDF_STATUS status;
10221
10222 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10223 cds_get_context(QDF_MODULE_ID_TXRX),
10224 vdev_id);
10225 /*
10226 * For Adrastea flow control v2 is based on FW MAP events,
10227 * so this above callback is not implemented.
10228 * Hence this is not actual failure. Dont return failure
10229 */
10230 if ((status != QDF_STATUS_SUCCESS) &&
10231 (status != QDF_STATUS_E_INVAL)) {
10232 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10233 vdev_id, status);
10234 }
10235}
10236
10237/**
10238 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10239 * @vdev_id: vdev_id, corresponds to flow_pool
10240 *
10241 * Return: none.
10242 */
10243static void hdd_v2_flow_pool_unmap(int vdev_id)
10244{
10245 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10246 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10247}
10248
10249/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010250 * hdd_configure_cds() - Configure cds modules
10251 * @hdd_ctx: HDD context
10252 * @adapter: Primary adapter context
10253 *
10254 * Enable Cds modules after WLAN firmware is up.
10255 *
10256 * Return: 0 on success and errno on failure.
10257 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010258int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010259{
10260 int ret;
10261 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010262 int set_value;
10263 uint32_t num_abg_tx_chains = 0;
10264 uint32_t num_11b_tx_chains = 0;
10265 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010266 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010267
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010268 if (hdd_ctx->config->is_force_1x1)
10269 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10270 1, PDEV_CMD);
10271 /* set chip power save failure detected callback */
10272 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
10273 hdd_chip_pwr_save_fail_detected_cb);
10274
10275 if (hdd_ctx->config->max_mpdus_inampdu) {
10276 set_value = hdd_ctx->config->max_mpdus_inampdu;
10277 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10278 set_value, PDEV_CMD);
10279 }
10280
10281 if (hdd_ctx->config->enable_rts_sifsbursting) {
10282 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10283 sme_cli_set_command(0,
10284 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10285 set_value, PDEV_CMD);
10286 }
10287
10288 if (hdd_ctx->config->sap_get_peer_info) {
10289 set_value = hdd_ctx->config->sap_get_peer_info;
10290 sme_cli_set_command(0,
10291 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10292 set_value, PDEV_CMD);
10293 }
10294
10295 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10296 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10297 if (!hdd_ctx->config->enable2x2) {
10298 if (num_11b_tx_chains > 1)
10299 num_11b_tx_chains = 1;
10300 if (num_11ag_tx_chains > 1)
10301 num_11ag_tx_chains = 1;
10302 }
10303 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10304 num_11b_tx_chains);
10305 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10306 num_11ag_tx_chains);
10307 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10308 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010309
10310 ret = hdd_pre_enable_configure(hdd_ctx);
10311 if (ret) {
10312 hdd_err("Failed to pre-configure cds");
10313 goto out;
10314 }
10315
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010316 /* Always get latest IPA resources allocated from cds_open and configure
10317 * IPA module before configuring them to FW. Sequence required as crash
10318 * observed otherwise.
10319 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010320 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10321 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010322 hdd_err("Failed to setup pipes");
10323 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010324 }
10325
Arun Khandavallifae92942016-08-01 13:31:08 +053010326 /*
10327 * Start CDS which starts up the SME/MAC/HAL modules and everything
10328 * else
10329 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010330 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010331
10332 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010333 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010334 goto out;
10335 }
10336
10337 status = hdd_post_cds_enable_config(hdd_ctx);
10338 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010339 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010340 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010341 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010342 status = hdd_register_bcn_cb(hdd_ctx);
10343 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010344 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010345 goto cds_disable;
10346 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010347
Dustin Browne7e71d32018-05-11 16:00:08 -070010348 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010349 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010350 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010351
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010352 if (hdd_ctx->ol_enable)
10353 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10354 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010355 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010356 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010357 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10358 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010359 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10360 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010361 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010362 goto cds_disable;
10363 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010364 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10365 wlan_hdd_send_mode_change_event);
10366 if (!QDF_IS_STATUS_SUCCESS(status)) {
10367 hdd_debug("Failed to register mode change cb with Policy Manager");
10368 goto cds_disable;
10369 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010370
Jeff Johnson8bb61112018-03-31 13:33:54 -070010371 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010372 hdd_debug("enhance green ap is not enabled");
10373
Nachiket Kukadedd302662017-07-13 17:31:44 +053010374 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10375 hdd_debug("Failed to set wow pulse");
10376
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010377 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10378 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010379 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10380 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10381
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010382
10383 if (hdd_ctx->config->enable_phy_reg_retention)
10384 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10385 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10386
Arun Khandavallifae92942016-08-01 13:31:08 +053010387 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010388
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010389cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010390 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010391
Arun Khandavallifae92942016-08-01 13:31:08 +053010392out:
10393 return -EINVAL;
10394}
10395
10396/**
10397 * hdd_deconfigure_cds() -De-Configure cds
10398 * @hdd_ctx: HDD context
10399 *
10400 * Deconfigure Cds modules before WLAN firmware is down.
10401 *
10402 * Return: 0 on success and errno on failure.
10403 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010404static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010405{
10406 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010407 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010408
Dustin Brown491d54b2018-03-14 12:39:11 -070010409 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010410
10411 /* De-init features */
10412 hdd_features_deinit(hdd_ctx);
10413
Arun Khandavallifae92942016-08-01 13:31:08 +053010414 /* De-register the SME callbacks */
10415 hdd_deregister_cb(hdd_ctx);
10416
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010417 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10418 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10419 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10420 }
10421
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010422 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010423 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10424 hdd_err("Failed to Disable the CDS Modules! :%d",
10425 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010426 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010427 }
10428
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010429 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010430 hdd_err("Failed to disconnect pipes");
10431 ret = -EINVAL;
10432 }
10433
Dustin Browne74003f2018-03-14 12:51:58 -070010434 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010435 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010436}
10437
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010438#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10439static void hdd_deregister_policy_manager_callback(
10440 struct wlan_objmgr_psoc *psoc)
10441{
10442 if (QDF_STATUS_SUCCESS !=
10443 policy_mgr_deregister_hdd_cb(psoc)) {
10444 hdd_err("HDD callback deregister with policy manager failed");
10445 }
10446}
10447#else
10448static void hdd_deregister_policy_manager_callback(
10449 struct wlan_objmgr_psoc *psoc)
10450{
10451}
10452#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010453
10454/**
10455 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10456 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010457 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010458 *
10459 * This function maintains the driver state machine it will be invoked from
10460 * exit, shutdown and con_mode change handler. Depending on the driver state
10461 * shall perform the stopping/closing of the modules.
10462 *
10463 * Return: 0 for success; non-zero for failure
10464 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010465int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010466{
10467 void *hif_ctx;
10468 qdf_device_t qdf_ctx;
10469 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010470 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010471 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010472 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10473 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010474 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010475 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010476
Dustin Brown491d54b2018-03-14 12:39:11 -070010477 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010478 hdd_alert("stop WLAN module: entering driver status=%d",
10479 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010480
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010481 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10482
Arun Khandavallifae92942016-08-01 13:31:08 +053010483 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10484 if (!qdf_ctx) {
10485 hdd_err("QDF device context NULL");
10486 return -EINVAL;
10487 }
10488
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010489 mutex_lock(&hdd_ctx->iface_change_lock);
10490 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010491 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010492
Dustin Brown70111822017-03-30 15:31:40 -070010493 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010494 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010495 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010496 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010497
10498 cds_print_external_threads();
10499
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010500 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010501 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010502 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10503 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010504 hdd_prevent_suspend_timeout(
10505 hdd_ctx->config->iface_change_wait_time,
10506 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010507 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010508 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010509 return 0;
10510 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010511 }
10512
Arun Khandavallifae92942016-08-01 13:31:08 +053010513 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10514
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010515 /* free user wowl patterns */
10516 hdd_free_user_wowl_ptrns();
10517
Arun Khandavallifae92942016-08-01 13:31:08 +053010518 switch (hdd_ctx->driver_status) {
10519 case DRIVER_MODULES_UNINITIALIZED:
10520 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010521 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010522 case DRIVER_MODULES_CLOSED:
10523 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010524 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010525 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010526 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10527
Komal Seelamf2136bb2016-09-28 18:30:44 +053010528 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010529 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010530 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010531 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010532 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010533 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010534 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010535
Arun Khandavallifae92942016-08-01 13:31:08 +053010536 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010537 hdd_info("Wlan transitioned (now OPENED)");
10538
10539 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010540 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010541 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010542 break;
10543 default:
10544 hdd_err("Trying to stop wlan in a wrong state: %d",
10545 hdd_ctx->driver_status);
10546 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010547 ret = -EINVAL;
10548 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010549 }
10550
Amar Singhal18081642018-01-26 16:04:13 -080010551 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010552 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010553
Rajeev Kumarbe021242017-02-16 16:12:23 -080010554 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010555 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10556 hdd_err("Failed to process post CDS disable Modules! :%d",
10557 qdf_status);
10558 ret = -EINVAL;
10559 QDF_ASSERT(0);
10560 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010561
psimhadeea0a12017-12-18 14:50:02 -080010562 hdd_runtime_suspend_context_deinit(hdd_ctx);
10563
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010564 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10565 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10566 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10567 ret = -EINVAL;
10568 QDF_ASSERT(0);
10569 }
10570
Jeff Johnsone4b14592017-09-13 14:23:33 -070010571 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010572 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010573 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010574 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010575 QDF_ASSERT(0);
10576 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010577
Amar Singhal410675c2018-01-10 12:14:21 -080010578 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010579 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10580 if (ret) {
10581 hdd_err("Failed to destroy pdev; errno:%d", ret);
10582 QDF_ASSERT(0);
10583 }
10584
10585 /*
10586 * Reset total mac phy during module stop such that during
10587 * next module start same psoc is used to populate new service
10588 * ready data
10589 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010590 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10591 if (tgt_hdl)
10592 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10593
Liangwei Dong50a64a72018-01-11 01:17:00 -050010594
Arun Khandavallifae92942016-08-01 13:31:08 +053010595 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10596 if (!hif_ctx) {
10597 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010598 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010599 }
10600
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010601 if (hdd_ctx->target_hw_name) {
10602 qdf_mem_free(hdd_ctx->target_hw_name);
10603 hdd_ctx->target_hw_name = NULL;
10604 }
10605
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010606 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010607
10608 ol_cds_free();
10609
Dustin Brown70111822017-03-30 15:31:40 -070010610 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010611 ret = pld_power_off(qdf_ctx->dev);
10612 if (ret)
10613 hdd_err("CNSS power down failed put device into Low power mode:%d",
10614 ret);
10615 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010616
Dustin Brown4bc0a622017-12-06 15:56:50 -080010617 /* many adapter resources are not freed by design in SSR case */
10618 if (!is_recovery_stop)
10619 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010620 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010621
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010622 /* Once the firmware sequence is completed reset this flag */
10623 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010624 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010625 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010626
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010627done:
10628 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010629 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010630 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010631 hdd_alert("stop WLAN module: exit driver status=%d",
10632 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010633
Dustin Browne74003f2018-03-14 12:51:58 -070010634 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010635
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010636 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010637}
10638
Arun Khandavallifae92942016-08-01 13:31:08 +053010639
Wen Gong3f003382018-05-14 14:26:37 +080010640#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053010641/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010642 * hdd_state_info_dump() - prints state information of hdd layer
10643 * @buf: buffer pointer
10644 * @size: size of buffer to be filled
10645 *
10646 * This function is used to dump state information of hdd layer
10647 *
10648 * Return: None
10649 */
10650static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10651{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010652 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010653 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010654 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010655 uint16_t len = 0;
10656 char *buf = *buf_ptr;
10657
10658 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10659 if (!hdd_ctx) {
10660 hdd_err("Failed to get hdd context ");
10661 return;
10662 }
10663
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010664 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010665
10666 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010667 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010668 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010669 "\n is_scheduler_suspended %d",
10670 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010671
Dustin Brown920397d2017-12-13 16:27:50 -080010672 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010673 if (adapter->dev)
10674 len += scnprintf(buf + len, *size - len,
10675 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010676 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010677 "\n device_mode: %d", adapter->device_mode);
10678 switch (adapter->device_mode) {
10679 case QDF_STA_MODE:
10680 case QDF_P2P_CLIENT_MODE:
10681 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10682 len += scnprintf(buf + len, *size - len,
10683 "\n connState: %d",
10684 hdd_sta_ctx->conn_info.connState);
10685 break;
10686
10687 default:
10688 break;
10689 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010690 }
10691
10692 *size -= len;
10693 *buf_ptr += len;
10694}
10695
10696/**
10697 * hdd_register_debug_callback() - registration function for hdd layer
10698 * to print hdd state information
10699 *
10700 * Return: None
10701 */
10702static void hdd_register_debug_callback(void)
10703{
10704 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10705}
Wen Gong3f003382018-05-14 14:26:37 +080010706#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080010707static void hdd_register_debug_callback(void)
10708{
10709}
Wen Gong3f003382018-05-14 14:26:37 +080010710#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010711
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010712/*
10713 * wlan_init_bug_report_lock() - Initialize bug report lock
10714 *
10715 * This function is used to create bug report lock
10716 *
10717 * Return: None
10718 */
10719static void wlan_init_bug_report_lock(void)
10720{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070010721 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010722
10723 p_cds_context = cds_get_global_context();
10724 if (!p_cds_context) {
10725 hdd_err("cds context is NULL");
10726 return;
10727 }
10728
10729 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10730}
10731
Nirav Shahd21a2e32018-04-20 16:34:43 +053010732#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070010733void hdd_dp_trace_init(struct hdd_config *config)
10734{
10735
10736 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10737 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10738 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10739 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10740 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10741 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10742 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010743 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010744
Nirav Shahd21a2e32018-04-20 16:34:43 +053010745 if (!config->enable_dp_trace) {
10746 hdd_err("dp trace is disabled from ini");
10747 return;
10748 }
10749
Mohit Khannaf8f96822017-05-17 17:11:59 -070010750 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10751 &num_entries, sizeof(config_params));
10752
10753 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010754 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010755 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010756 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010757 else if (bw_compute_interval > 1000) {
10758 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10759 thresh_time_limit = 1;
10760 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010761 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10762
10763 switch (num_entries) {
10764 case 4:
10765 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010766 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010767 case 3:
10768 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010769 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010770 case 2:
10771 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010772 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010773 case 1:
10774 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010775 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010776 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010777 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010778 live_mode, thresh, thresh_time_limit,
10779 verbosity, proto_bitmap);
10780 };
10781
10782 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10783 verbosity, proto_bitmap);
10784
10785}
Nirav Shahd21a2e32018-04-20 16:34:43 +053010786#endif
10787
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010788/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010789 * hdd_wlan_startup() - HDD init function
10790 * @dev: Pointer to the underlying device
10791 *
10792 * This is the driver startup code executed once a WLAN device has been detected
10793 *
10794 * Return: 0 for success, < 0 for failure
10795 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010796int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010797{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010798 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010799 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010800 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010801 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010802
Dustin Brown491d54b2018-03-14 12:39:11 -070010803 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010804
Arun Khandavallifae92942016-08-01 13:31:08 +053010805 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010806
10807 if (IS_ERR(hdd_ctx))
10808 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010809
Abhishek Singhe9068f12017-03-31 14:14:52 +053010810 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10811 DEFAULT_PSOC_ID);
10812 if (ret) {
10813 hdd_err("Psoc creation fails!");
10814 QDF_BUG(0);
10815 goto err_hdd_free_context;
10816 }
10817
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010818 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010819#ifdef FEATURE_WLAN_CH_AVOID
10820 mutex_init(&hdd_ctx->avoid_freq_lock);
10821#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010822
Naveen Rawate02f8f52018-04-05 11:58:04 -070010823 osif_request_manager_init();
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010824 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010825 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010826
Dustin Brown021cecd2017-12-11 13:56:43 -080010827 hdd_driver_memdump_init();
10828
Dustin Browne7e71d32018-05-11 16:00:08 -070010829 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010830 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010831 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010832 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010833 }
10834
Yingying Tang80e15f32016-09-27 18:23:01 +080010835 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010836
Anurag Chouhan6d760662016-02-20 16:05:43 +053010837 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010838
10839 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010840 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010841 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010842 }
10843
Prashanth Bhatta07998752016-04-28 12:35:33 -070010844 ret = hdd_wiphy_init(hdd_ctx);
10845 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010846 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010847 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010848 }
10849
Nirav Shahd21a2e32018-04-20 16:34:43 +053010850 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010851
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010852 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010853
Paul Zhangfb02f452017-12-22 11:58:43 +080010854 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10855 if (ret) {
10856 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010857 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080010858 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010859
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010860 ret = register_reboot_notifier(&system_reboot_notifier);
10861 if (ret) {
10862 hdd_err("Failed to register reboot notifier: %d", ret);
10863 goto err_unregister_netdev;
10864 }
10865
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010866 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010867
Jeff Johnson957bc272017-02-02 08:54:48 -080010868 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10869 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010870 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010871 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010872 }
10873
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010874 hdd_release_rtnl_lock();
10875 rtnl_held = false;
10876
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010877 wlan_hdd_update_11n_mode(hdd_ctx->config);
10878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010879#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010880 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010881 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010882 hdd_skip_acs_scan_timer_handler,
10883 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010884 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010885 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010886 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010887#endif
10888
Prashanth Bhattaab004382016-10-11 16:08:11 -070010889 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010890
Jeff Johnson9afc5012016-09-23 13:56:27 -070010891 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010892
Nirav Shahbd36b062016-07-18 11:12:59 +053010893 if (hdd_ctx->rps)
10894 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010895
Paul Zhangfb02f452017-12-22 11:58:43 +080010896 ret = hdd_register_notifiers(hdd_ctx);
10897 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010898 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010899
Paul Zhangfb02f452017-12-22 11:58:43 +080010900 status = wlansap_global_init();
10901 if (QDF_IS_STATUS_ERROR(status)) {
10902 hdd_unregister_notifiers(hdd_ctx);
10903 goto err_close_adapters;
10904 }
10905
Arun Khandavallifae92942016-08-01 13:31:08 +053010906 if (hdd_ctx->config->fIsImpsEnabled)
10907 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010908 else
10909 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010910
Mukul Sharma07bd8752017-10-10 16:58:14 +053010911 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010912 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10913 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010914 hdd_prevent_suspend_timeout(
10915 hdd_ctx->config->iface_change_wait_time,
10916 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10917 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010918
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010919 goto success;
10920
Jeff Johnson957bc272017-02-02 08:54:48 -080010921err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010922 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010923
Jeff Johnson46bde382017-02-01 15:31:16 -080010924err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010925 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010926 if (rtnl_held)
10927 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010928
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010929err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010930 unregister_netdevice_notifier(&hdd_netdev_notifier);
10931
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010932err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010933 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010934
Arun Khandavallifae92942016-08-01 13:31:08 +053010935err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010936 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010937
Dustin Brown021cecd2017-12-11 13:56:43 -080010938err_memdump_deinit:
10939 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010940
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010941 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070010942 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010943 hdd_exit_netlink_services(hdd_ctx);
10944
Dustin Brown20912462017-06-07 13:48:25 -070010945 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10946
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010947err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010948 if (cds_is_fw_down())
10949 hdd_err("Not setting the complete event as fw is down");
10950 else
10951 hdd_start_complete(ret);
10952
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010953 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010954 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010955 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010956
10957success:
Dustin Browne74003f2018-03-14 12:51:58 -070010958 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010959 return 0;
10960}
10961
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010962/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010963 * hdd_wlan_update_target_info() - update target type info
10964 * @hdd_ctx: HDD context
10965 * @context: hif context
10966 *
10967 * Update target info received from firmware in hdd context
10968 * Return:None
10969 */
10970
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010971void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010972{
10973 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10974
10975 if (!tgt_info) {
10976 hdd_err("Target info is Null");
10977 return;
10978 }
10979
10980 hdd_ctx->target_type = tgt_info->target_type;
10981}
10982
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053010983void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010984{
10985 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010986 int status;
10987 struct hdd_adapter *adapter = NULL;
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053010988 struct hdd_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010989
Dustin Brown491d54b2018-03-14 12:39:11 -070010990 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010991
10992 if (!rsp) {
10993 hdd_err("data is null");
10994 return;
10995 }
10996
10997 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053010998 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010999 return;
11000
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011001 request = hdd_request_get(context);
11002 if (!request) {
11003 hdd_err("obselete request");
11004 return;
11005 }
11006
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011007 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11008 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11009 hdd_err("Invalid adapter or adapter has invalid magic");
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011010 hdd_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011011 return;
11012 }
11013
Dustin Brown5e89ef82018-03-14 11:50:23 -070011014 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11015 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11016 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11017 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11018 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11019 rsp->out_of_order_arp_rsp_drop_cnt);
11020 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
11021 hdd_info("rsp->connect_status :%x", rsp->connect_status);
11022 hdd_info("rsp->ba_session_establishment_status :%x",
11023 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011024
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011025 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011026 adapter->dad |= rsp->dad_detected;
11027 adapter->con_status = rsp->connect_status;
11028
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011029 /* Flag true indicates connectivity check stats present. */
11030 if (rsp->connect_stats_present) {
11031 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11032 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
11033 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11034 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11035 rsp->icmpv4_rsp_recvd;
11036 }
11037
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011038 hdd_request_complete(request);
11039 hdd_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011040
Dustin Browne74003f2018-03-14 12:51:58 -070011041 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011042}
11043
11044/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011045 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011046 * @hdd_ctx: HDD context
11047 *
11048 * Register the HDD callbacks to CDS/SME.
11049 *
11050 * Return: 0 for success or Error code for failure
11051 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011052int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011053{
11054 QDF_STATUS status;
11055 int ret = 0;
11056
Dustin Brown491d54b2018-03-14 12:39:11 -070011057 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011058
11059 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
11060
11061 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
11062 hdd_send_oem_data_rsp_msg);
11063
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011064 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
11065 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011066 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
11067 sme_nan_register_callback(hdd_ctx->hHal,
11068 wlan_hdd_cfg80211_nan_callback);
11069 sme_stats_ext_register_callback(hdd_ctx->hHal,
11070 wlan_hdd_cfg80211_stats_ext_callback);
11071
11072 sme_ext_scan_register_callback(hdd_ctx->hHal,
11073 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080011074 sme_stats_ext2_register_callback(hdd_ctx->hHal,
11075 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011076
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011077 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
11078 hdd_rssi_threshold_breached);
11079
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011080 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
11081 wlan_hdd_cfg80211_link_layer_stats_callback);
11082
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011083 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
11084
Zhang Qianca38fb12016-12-23 11:10:48 +080011085 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
11086 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11087
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011088 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
11089 hdd_lost_link_info_cb);
11090 /* print error and not block the startup process */
11091 if (!QDF_IS_STATUS_SUCCESS(status))
11092 hdd_err("set lost link info callback failed");
11093
Poddar, Siddarth34872782017-08-10 14:08:51 +053011094 ret = hdd_register_data_stall_detect_cb();
11095 if (ret) {
11096 hdd_err("Register data stall detect detect callback failed.");
11097 return ret;
11098 }
11099
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011100 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11101
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011102 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011103 hdd_set_connection_in_progress,
11104 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011105
11106 status = sme_congestion_register_callback(hdd_ctx->hHal,
11107 hdd_update_cca_info_cb);
11108 if (!QDF_IS_STATUS_SUCCESS(status))
11109 hdd_err("set congestion callback failed");
11110
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011111 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
11112 hdd_bt_activity_cb);
11113 if (!QDF_IS_STATUS_SUCCESS(status))
11114 hdd_err("set bt activity info callback failed");
11115
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011116 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
11117 hdd_tx_queue_cb);
11118 if (!QDF_IS_STATUS_SUCCESS(status))
11119 hdd_err("Register tx queue callback failed");
11120
Dustin Browne74003f2018-03-14 12:51:58 -070011121 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011122
11123 return ret;
11124}
11125
11126/**
11127 * hdd_deregister_cb() - De-Register HDD callbacks.
11128 * @hdd_ctx: HDD context
11129 *
11130 * De-Register the HDD callbacks to CDS/SME.
11131 *
11132 * Return: void
11133 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011134void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011135{
11136 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011137 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011138
Dustin Brown491d54b2018-03-14 12:39:11 -070011139 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011140
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011141 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011142 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
11143 if (!QDF_IS_STATUS_SUCCESS(status))
11144 hdd_err("De-register of dcc stats callback failed: %d",
11145 status);
11146
11147 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011148 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
11149
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011150 sme_stats_ext_register_callback(hdd_ctx->hHal,
11151 wlan_hdd_cfg80211_stats_ext_callback);
11152
11153 sme_nan_deregister_callback(hdd_ctx->hHal);
11154 status = sme_reset_tsfcb(hdd_ctx->hHal);
11155 if (!QDF_IS_STATUS_SUCCESS(status))
11156 hdd_err("Failed to de-register tsfcb the callback:%d",
11157 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011158
Poddar, Siddarth34872782017-08-10 14:08:51 +053011159 ret = hdd_deregister_data_stall_detect_cb();
11160 if (ret)
11161 hdd_err("Failed to de-register data stall detect event callback");
11162
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011163 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
11164 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
11165
Dustin Browne74003f2018-03-14 12:51:58 -070011166 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011167}
11168
11169/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011170 * hdd_softap_sta_deauth() - handle deauth req from HDD
11171 * @adapter: Pointer to the HDD
11172 * @enable: bool value
11173 *
11174 * This to take counter measure to handle deauth req from HDD
11175 *
11176 * Return: None
11177 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011178QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011179 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011180{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011181 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011182
Dustin Brown491d54b2018-03-14 12:39:11 -070011183 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011185 /* Ignore request to deauth bcmc station */
11186 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011187 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011188
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011189 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011190 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11191 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011192
Dustin Browne74003f2018-03-14 12:51:58 -070011193 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011194 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011195}
11196
11197/**
11198 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11199 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011200 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011201 *
11202 * This to take counter measure to handle deauth req from HDD
11203 *
11204 * Return: None
11205 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011206void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011207 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011208{
Dustin Brown491d54b2018-03-14 12:39:11 -070011209 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011210
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011211 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011212 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011213 return;
11214
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011215 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011216 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011217}
11218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011219/**
11220 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11221 * @hdd_ctx: HDD Context
11222 *
11223 * API to find if there is any STA or P2P-Client is connected
11224 *
11225 * Return: true if connected; false otherwise
11226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011227QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011228{
11229 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
11230}
11231
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011232/**
11233 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
11234 * @adapter: HDD adapter pointer
11235 *
11236 * This function loop through each adapter and disable roaming on each STA
11237 * device mode except the input adapter.
11238 *
11239 * Note: On the input adapter roaming is not enabled yet hence no need to
11240 * disable.
11241 *
11242 * Return: None
11243 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011244void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011245{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011246 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011247 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011248
11249 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011250 hdd_ctx->config->isRoamOffloadScanEnabled &&
11251 QDF_STA_MODE == adapter->device_mode &&
11252 policy_mgr_is_sta_active_connection_exists(
11253 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011254 hdd_debug("Connect received on STA session Id(%d)",
11255 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011256 /*
11257 * Loop through adapter and disable roaming for each STA device
11258 * mode except the input adapter.
11259 */
Dustin Brown920397d2017-12-13 16:27:50 -080011260 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011261 if (QDF_STA_MODE == adapterIdx->device_mode &&
11262 adapter->session_id != adapterIdx->session_id) {
11263 hdd_debug("Disable Roaming on session Id(%d)",
11264 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011265 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
11266 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011267 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011268 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011269 }
11270 }
11271}
11272
11273/**
11274 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
11275 * @adapter: HDD adapter pointer
11276 *
11277 * This function loop through each adapter and enable roaming on each STA
11278 * device mode except the input adapter.
11279 * Note: On the input adapter no need to enable roaming because link got
11280 * disconnected on this.
11281 *
11282 * Return: None
11283 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011284void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011285{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011286 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011287 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011288
11289 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011290 hdd_ctx->config->isRoamOffloadScanEnabled &&
11291 QDF_STA_MODE == adapter->device_mode &&
11292 policy_mgr_is_sta_active_connection_exists(
11293 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011294 hdd_debug("Disconnect received on STA session Id(%d)",
11295 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011296 /*
11297 * Loop through adapter and enable roaming for each STA device
11298 * mode except the input adapter.
11299 */
Dustin Brown920397d2017-12-13 16:27:50 -080011300 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011301 if (QDF_STA_MODE == adapterIdx->device_mode &&
11302 adapter->session_id != adapterIdx->session_id) {
11303 hdd_debug("Enabling Roaming on session Id(%d)",
11304 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011305 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
11306 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011307 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011308 REASON_CONNECT);
11309 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011310 }
11311 }
11312}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011313
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011314/**
11315 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11316 * @skb: sk buffer pointer
11317 *
11318 * Sends the bcast message to SVC multicast group with generic nl socket
11319 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11320 *
11321 * Return: None
11322 */
11323static void nl_srv_bcast_svc(struct sk_buff *skb)
11324{
11325#ifdef CNSS_GENL
11326 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11327#else
11328 nl_srv_bcast(skb);
11329#endif
11330}
11331
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011332void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011333{
11334 struct sk_buff *skb;
11335 struct nlmsghdr *nlh;
11336 tAniMsgHdr *ani_hdr;
11337 void *nl_data = NULL;
11338 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011339 struct radio_index_tlv *radio_info;
11340 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011341
11342 if (in_interrupt() || irqs_disabled() || in_atomic())
11343 flags = GFP_ATOMIC;
11344
11345 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11346
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011347 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011348 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011349
11350 nlh = (struct nlmsghdr *)skb->data;
11351 nlh->nlmsg_pid = 0; /* from kernel */
11352 nlh->nlmsg_flags = 0;
11353 nlh->nlmsg_seq = 0;
11354 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11355
11356 ani_hdr = NLMSG_DATA(nlh);
11357 ani_hdr->type = type;
11358
11359 switch (type) {
11360 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011361 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011362 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011363 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011364 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011365 ani_hdr->length = 0;
11366 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011367 break;
11368 case WLAN_SVC_WLAN_STATUS_IND:
11369 case WLAN_SVC_WLAN_VERSION_IND:
11370 case WLAN_SVC_DFS_CAC_START_IND:
11371 case WLAN_SVC_DFS_CAC_END_IND:
11372 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11373 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11374 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011375 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011376 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011377 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011378 ani_hdr->length = len;
11379 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11380 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11381 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011382 break;
11383
11384 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011385 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011386 type);
11387 kfree_skb(skb);
11388 return;
11389 }
11390
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011391 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011392 * Add radio index at the end of the svc event in TLV format
11393 * to maintain the backward compatibility with userspace
11394 * applications.
11395 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011396
11397 tlv_len = 0;
11398
11399 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11400 < WLAN_NL_MAX_PAYLOAD) {
11401 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11402 sizeof(*ani_hdr) + len);
11403 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11404 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11405 radio_info->radio = radio;
11406 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011407 hdd_debug("Added radio index tlv - radio index %d",
11408 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011409 }
11410
11411 nlh->nlmsg_len += tlv_len;
11412 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11413
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011414 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011415}
11416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011417#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11418void wlan_hdd_auto_shutdown_cb(void)
11419{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011420 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011421
11422 if (!hdd_ctx)
11423 return;
11424
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011425 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011426 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11427 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011428}
11429
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011430void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011431{
Jeff Johnson9d295242017-08-29 14:39:48 -070011432 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011433 bool ap_connected = false, sta_connected = false;
11434 tHalHandle hal_handle;
11435
11436 hal_handle = hdd_ctx->hHal;
11437 if (hal_handle == NULL)
11438 return;
11439
11440 if (hdd_ctx->config->WlanAutoShutdown == 0)
11441 return;
11442
11443 if (enable == false) {
11444 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011445 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011446 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011447 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011448 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011449 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011450 return;
11451 }
11452
11453 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011454 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11455 hdd_for_each_adapter(hdd_ctx, adapter) {
11456 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011457 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11458 conn_info.connState ==
11459 eConnectionState_Associated) {
11460 sta_connected = true;
11461 break;
11462 }
11463 }
Dustin Brown920397d2017-12-13 16:27:50 -080011464
11465 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011466 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011467 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011468 ap_connected = true;
11469 break;
11470 }
11471 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011472 }
11473 }
11474
11475 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011476 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011477 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011478 }
Jeff Johnson68755312017-02-10 11:46:55 -080011479
11480 if (sme_set_auto_shutdown_timer(hal_handle,
11481 hdd_ctx->config->WlanAutoShutdown)
11482 != QDF_STATUS_SUCCESS)
11483 hdd_err("Failed to start wlan auto shutdown timer");
11484 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011485 hdd_info("Auto Shutdown timer for %d seconds enabled",
11486 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011487}
11488#endif
11489
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011490struct hdd_adapter *
11491hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11492 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011493{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011494 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011495 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011496
11497 con_sap_adapter = NULL;
11498
Dustin Brown920397d2017-12-13 16:27:50 -080011499 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011500 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11501 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011502 adapter != this_sap_adapter) {
11503 if (check_start_bss) {
11504 if (test_bit(SOFTAP_BSS_STARTED,
11505 &adapter->event_flags)) {
11506 con_sap_adapter = adapter;
11507 break;
11508 }
11509 } else {
11510 con_sap_adapter = adapter;
11511 break;
11512 }
11513 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011514 }
11515
11516 return con_sap_adapter;
11517}
11518
11519#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011520static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011521{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011522 return adapter->device_mode == QDF_STA_MODE ||
11523 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011524}
11525
Jeff Johnson9d295242017-08-29 14:39:48 -070011526static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011527{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011528 return adapter->device_mode == QDF_SAP_MODE ||
11529 adapter->device_mode == QDF_P2P_GO_MODE;
11530}
11531
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011532static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011533{
Dustin Brown920397d2017-12-13 16:27:50 -080011534 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011535
Dustin Brown920397d2017-12-13 16:27:50 -080011536 hdd_for_each_adapter(hdd_ctx, adapter) {
11537 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011538 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11539 conn_info.connState == eConnectionState_Associated) {
11540 return true;
11541 }
11542
Dustin Brown920397d2017-12-13 16:27:50 -080011543 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011544 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011545 return true;
11546 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011547 }
11548
11549 return false;
11550}
11551
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011552static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011553{
11554 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011555
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011556 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011557 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011558 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011559
Dustin Brown5ec6b552017-03-31 12:11:40 -070011560 return is_running;
11561}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011562
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011563static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011564{
11565 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11566 hdd_ctx->bus_bw_timer_running = true;
11567 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11568 hdd_ctx->config->busBandwidthComputeInterval);
11569 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11570}
11571
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011572void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011573{
Dustin Brown491d54b2018-03-14 12:39:11 -070011574 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011575
11576 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11577 hdd_debug("Bandwidth compute timer already started");
11578 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011579 }
11580
Dustin Brown5ec6b552017-03-31 12:11:40 -070011581 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11582
Dustin Browne74003f2018-03-14 12:51:58 -070011583 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011584}
11585
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011586void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011587{
Dustin Brown491d54b2018-03-14 12:39:11 -070011588 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011589
11590 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11591 hdd_debug("Bandwidth compute timer already started");
11592 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011593 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011594
11595 if (hdd_any_adapter_is_assoc(hdd_ctx))
11596 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11597
Dustin Browne74003f2018-03-14 12:51:58 -070011598 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011599}
11600
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011601static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011602{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011603 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011604
11605 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11606 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11607 hdd_ctx->bus_bw_timer_running = false;
11608 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11609
11610 hdd_reset_tcp_delack(hdd_ctx);
11611}
11612
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011613void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011614{
Dustin Brown491d54b2018-03-14 12:39:11 -070011615 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011616
11617 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11618 hdd_debug("Bandwidth compute timer already stopped");
11619 return;
11620 }
11621
11622 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11623
Dustin Browne74003f2018-03-14 12:51:58 -070011624 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011625}
11626
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011627void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011628{
Dustin Brown491d54b2018-03-14 12:39:11 -070011629 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011630
11631 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11632 hdd_debug("Bandwidth compute timer already stopped");
11633 return;
11634 }
11635
11636 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11637 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11638
Dustin Browne74003f2018-03-14 12:51:58 -070011639 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011640}
11641#endif
11642
11643/**
11644 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11645 * and sta's operating channel.
11646 * @sta_adapter: Describe the first argument to foobar.
11647 * @ap_adapter: Describe the second argument to foobar.
11648 * @roam_profile: Roam profile of AP to which STA wants to connect.
11649 * @concurrent_chnl_same: If both SAP and STA channels are same then
11650 * set this flag to true else false.
11651 *
11652 * This function checks the sap's operating channel and sta's operating channel.
11653 * if both are same then it will return false else it will restart the sap in
11654 * sta's channel and return true.
11655 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011656 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011657 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011658QDF_STATUS
11659wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11660 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011661 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011662 tScanResultHandle *scan_cache,
11663 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011664{
Jeff Johnson87251032017-08-29 13:31:11 -070011665 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011666 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011667 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011668 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011669 *concurrent_chnl_same = true;
11670
11671 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11672 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011673 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011674 scan_cache,
11675 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011676 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011677 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011678 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011679 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011680 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011681 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011682 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011683 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011684 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011685 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011686 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011687 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011688 }
11689 }
11690 } else {
11691 /*
11692 * Lets handle worst case scenario here, Scan cache lookup is
11693 * failed so we have to stop the SAP to avoid any channel
11694 * discrepancy between SAP's channel and STA's channel.
11695 * Return the status as failure so caller function could know
11696 * that scan look up is failed.
11697 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011698 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011699 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011700 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011701 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011702}
11703
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011704/**
11705 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11706 * @ap_adapter: SAP adapter
11707 *
11708 * This function will process the stopping of sap adapter.
11709 *
11710 * Return: None
11711 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011712void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011713{
Jeff Johnson87251032017-08-29 13:31:11 -070011714 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011715 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011716 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011717 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011718
11719 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011720 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011721 return;
11722 }
11723
11724 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11725 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011726 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011727 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011728
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011729 mutex_lock(&hdd_ctx->sap_lock);
11730 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011731 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011732 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011733 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011734 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011735 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011736 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011737 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011738 qdf_stop_bss_event,
11739 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011740 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011741 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011742 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011743 return;
11744 }
11745 }
11746 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011747 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11748 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011749 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011750 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011751 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011752 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011753 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011754 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011755 }
11756 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011757}
11758
11759/**
11760 * wlan_hdd_start_sap() - this function starts bss of SAP.
11761 * @ap_adapter: SAP adapter
11762 *
11763 * This function will process the starting of sap adapter.
11764 *
11765 * Return: None
11766 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011767void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011768{
Jeff Johnson87251032017-08-29 13:31:11 -070011769 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011770 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011771 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011772 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070011773 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011774
11775 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011776 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011777 return;
11778 }
11779
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011780 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011781 hdd_err("SoftAp role has not been enabled");
11782 return;
11783 }
11784
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011785 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11786 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11787 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011788 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011789
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011790 mutex_lock(&hdd_ctx->sap_lock);
11791 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11792 goto end;
11793
11794 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011795 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011796 goto end;
11797 }
11798
Wei Song2f76f642016-11-18 16:32:53 +080011799 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011800 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011801 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011802 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011803 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011804 goto end;
11805
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011806 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011807 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011808 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011809 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011810 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011811 goto end;
11812 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011813 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011814 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011815 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011816 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011817 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11818 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011819 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011820 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011821 true);
11822 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011823 mutex_unlock(&hdd_ctx->sap_lock);
11824
11825 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011826end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011827 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011828 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011829 /* SAP context and beacon cleanup will happen during driver unload
11830 * in hdd_stop_adapter
11831 */
11832 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11833
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011834}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011835
11836/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011837 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11838 * mac scan config
11839 * @status: Status of set antenna mode
11840 *
11841 * Callback on setting the dual mac configuration
11842 *
11843 * Return: None
11844 */
11845void wlan_hdd_soc_set_antenna_mode_cb(
11846 enum set_antenna_mode_status status)
11847{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011848 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011849
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011850 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011851
11852 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11853 if (0 != wlan_hdd_validate_context(hdd_ctx))
11854 return;
11855
11856 /* Signal the completion of set dual mac config */
11857 complete(&hdd_ctx->set_antenna_mode_cmpl);
11858}
11859
11860/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011861 * hdd_get_fw_version() - Get FW version
11862 * @hdd_ctx: pointer to HDD context.
11863 * @major_spid: FW version - major spid.
11864 * @minor_spid: FW version - minor spid
11865 * @ssid: FW version - ssid
11866 * @crmid: FW version - crmid
11867 *
11868 * This function is called to get the firmware build version stored
11869 * as part of the HDD context
11870 *
11871 * Return: None
11872 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011873void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011874 uint32_t *major_spid, uint32_t *minor_spid,
11875 uint32_t *siid, uint32_t *crmid)
11876{
11877 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11878 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11879 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11880 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11881}
11882
11883#ifdef QCA_CONFIG_SMP
11884/**
11885 * wlan_hdd_get_cpu() - get cpu_index
11886 *
11887 * Return: cpu_index
11888 */
11889int wlan_hdd_get_cpu(void)
11890{
11891 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011892
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011893 put_cpu();
11894 return cpu_index;
11895}
11896#endif
11897
11898/**
11899 * hdd_get_fwpath() - get framework path
11900 *
11901 * This function is used to get the string written by
11902 * userspace to start the wlan driver
11903 *
11904 * Return: string
11905 */
11906const char *hdd_get_fwpath(void)
11907{
11908 return fwpath.string;
11909}
11910
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011911static int hdd_qdf_print_init(void)
11912{
11913 int qdf_print_idx;
11914 QDF_STATUS status;
11915
11916 status = qdf_print_setup();
11917 if (status != QDF_STATUS_SUCCESS) {
11918 pr_err("qdf_print_setup failed\n");
11919 return -EINVAL;
11920 }
11921
11922 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11923
11924 if (qdf_print_idx < 0) {
11925 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11926 qdf_print_idx);
11927 return -EINVAL;
11928 }
11929
11930 qdf_set_pidx(qdf_print_idx);
11931
11932 return 0;
11933}
11934
11935static void hdd_qdf_print_deinit(void)
11936{
11937 int qdf_print_idx;
11938
11939 qdf_print_idx = qdf_get_pidx();
11940 qdf_print_ctrl_cleanup(qdf_print_idx);
11941}
11942
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011943/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011944 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011945 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011946 * This function initilizes CDS global context with the help of cds_init. This
11947 * has to be the first function called after probe to get a valid global
11948 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011949 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011950 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011951 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011952int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011953{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011954 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011955 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011956
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011957 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011958 if (QDF_IS_STATUS_ERROR(status)) {
11959 hdd_err("Failed to allocate CDS context");
11960 ret = -ENOMEM;
11961 goto err_out;
11962 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011963
11964 wlan_init_bug_report_lock();
11965
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011966#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11967 wlan_logging_sock_init_svc();
11968#endif
11969
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011970 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11971 (void *)hdd_drv_ops_inactivity_handler, NULL,
11972 QDF_TIMER_TYPE_SW);
11973
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011974 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011975 hdd_qdf_print_init();
11976
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011977 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011978
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011979err_out:
11980 return ret;
11981}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011982
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011983/**
11984 * hdd_deinit() - Deinitialize Driver
11985 *
11986 * This function frees CDS global context with the help of cds_deinit. This
11987 * has to be the last function call in remove callback to free the global
11988 * context.
11989 */
11990void hdd_deinit(void)
11991{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011992 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011993
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011994 wlan_destroy_bug_report_lock();
11995 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011996
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011997 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011998#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11999 wlan_logging_sock_deinit_svc();
12000#endif
12001}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012002
Yue Ma6e7b1a02017-04-03 14:17:46 -070012003#ifdef QCA_WIFI_NAPIER_EMULATION
12004#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12005#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012006#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012007#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012008
Sachin Ahujadddd2632017-03-07 19:07:24 +053012009static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12010 struct file *file)
12011{
12012 return 0;
12013}
12014
12015static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12016 const char __user *user_buf,
12017 size_t count,
12018 loff_t *f_pos)
12019{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012020 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012021 static const char wlan_off_str[] = "OFF";
12022 static const char wlan_on_str[] = "ON";
12023 int ret;
12024 unsigned long rc;
12025
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012026 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012027 pr_err("Failed to read buffer\n");
12028 return -EINVAL;
12029 }
12030
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012031 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012032 pr_debug("Wifi turning off from UI\n");
12033 goto exit;
12034 }
12035
Sachin Ahuja16904db2017-12-13 19:56:57 +053012036 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
12037 pr_info("Wifi Turning On from UI\n");
12038 }
12039
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012040 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012041 pr_err("Invalid value received from framework");
12042 goto exit;
12043 }
12044
12045 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012046 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012047 rc = wait_for_completion_timeout(&wlan_start_comp,
12048 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12049 if (!rc) {
12050 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
12051 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012052 return ret;
12053 }
12054
12055 hdd_start_complete(0);
12056 }
12057
12058exit:
12059 return count;
12060}
12061
12062
12063const struct file_operations wlan_hdd_state_fops = {
12064 .owner = THIS_MODULE,
12065 .open = wlan_hdd_state_ctrl_param_open,
12066 .write = wlan_hdd_state_ctrl_param_write,
12067};
12068
12069static int wlan_hdd_state_ctrl_param_create(void)
12070{
12071 unsigned int wlan_hdd_state_major = 0;
12072 int ret;
12073 struct device *dev;
12074
12075 device = MKDEV(wlan_hdd_state_major, 0);
12076
12077 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12078 if (ret) {
12079 pr_err("Failed to register qcwlanstate");
12080 goto dev_alloc_err;
12081 }
12082 wlan_hdd_state_major = MAJOR(device);
12083
12084 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12085 if (IS_ERR(class)) {
12086 pr_err("wlan_hdd_state class_create error");
12087 goto class_err;
12088 }
12089
12090 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12091 if (IS_ERR(dev)) {
12092 pr_err("wlan_hdd_statedevice_create error");
12093 goto err_class_destroy;
12094 }
12095
12096 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12097 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12098 if (ret) {
12099 pr_err("Failed to add cdev error");
12100 goto cdev_add_err;
12101 }
12102
12103 pr_info("wlan_hdd_state %s major(%d) initialized",
12104 WLAN_MODULE_NAME, wlan_hdd_state_major);
12105
12106 return 0;
12107
12108cdev_add_err:
12109 device_destroy(class, device);
12110err_class_destroy:
12111 class_destroy(class);
12112class_err:
12113 unregister_chrdev_region(device, dev_num);
12114dev_alloc_err:
12115 return -ENODEV;
12116}
12117
12118static void wlan_hdd_state_ctrl_param_destroy(void)
12119{
12120 cdev_del(&wlan_hdd_state_cdev);
12121 device_destroy(class, device);
12122 class_destroy(class);
12123 unregister_chrdev_region(device, dev_num);
12124
12125 pr_info("Device node unregistered");
12126}
12127
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012128/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053012129 * component_init - API to init cld component's
12130 *
12131 * Return: None
12132 */
12133static void component_init(void)
12134{
12135 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012136 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012137 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012138 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012139}
12140
12141/**
12142 * component_deinit - API to deinit cld component's
12143 *
12144 * Return: None
12145 */
12146static void component_deinit(void)
12147{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012148 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012149 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012150 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012151 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012152}
12153
12154void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12155{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012156 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012157 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012158}
12159
12160void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12161{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012162 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012163 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012164}
12165
12166/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012167 * __hdd_module_init - Module init helper
12168 *
12169 * Module init helper function used by both module and static driver.
12170 *
12171 * Return: 0 for success, errno on failure
12172 */
12173static int __hdd_module_init(void)
12174{
12175 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012176
Dustin Brown96cd9632017-11-13 12:45:04 -080012177 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012178 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012179 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012180 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012181
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012182 pld_init();
12183
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012184 ret = hdd_init();
12185 if (ret) {
12186 pr_err("hdd_init failed %x\n", ret);
12187 goto err_hdd_init;
12188 }
12189
Rajeev Kumar97767a02016-11-30 11:20:40 -080012190 dispatcher_init();
12191
Mukul Sharmad75a6672017-06-22 15:40:53 +053012192 /* Ensure to call post objmgr init */
12193 component_init();
12194
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012195 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012196
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012197 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012198
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012199 ret = wlan_hdd_register_driver();
12200 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012201 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12202 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012203 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012204 }
12205
Sachin Ahuja16904db2017-12-13 19:56:57 +053012206 ret = wlan_hdd_state_ctrl_param_create();
12207 if (ret) {
12208 pr_err("wlan_hdd_state_create:%x\n", ret);
12209 goto out;
12210 }
12211
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012212 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012213
12214 return 0;
12215out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012216 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012217 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012218 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012219 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012220
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012221err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012222 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012223 return ret;
12224}
12225
12226/**
12227 * __hdd_module_exit - Module exit helper
12228 *
12229 * Module exit helper function used by both module and static driver.
12230 */
12231static void __hdd_module_exit(void)
12232{
Will Huang36049722018-04-13 11:48:51 +080012233 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012234
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012235 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12236 QWLAN_VERSIONSTR);
12237
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012238 if (!hdd_wait_for_recovery_completion())
12239 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012240
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012241 if (hdd_ctx)
12242 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012243
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012244 wlan_hdd_unregister_driver();
12245
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012246 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012247
Mukul Sharmad75a6672017-06-22 15:40:53 +053012248 /* Ensure to call prior to objmgr deinit */
12249 component_deinit();
12250
Rajeev Kumar97767a02016-11-30 11:20:40 -080012251 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012252
12253 hdd_sysfs_destroy_version_interface();
12254
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012255 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012256 pld_deinit();
12257
Sachin Ahujadddd2632017-03-07 19:07:24 +053012258 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012259}
12260
Arun Khandavallifae92942016-08-01 13:31:08 +053012261#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012262/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012263 * wlan_boot_cb() - Wlan boot callback
12264 * @kobj: object whose directory we're creating the link in.
12265 * @attr: attribute the user is interacting with
12266 * @buff: the buffer containing the user data
12267 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012268 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012269 * This callback is invoked when the fs is ready to start the
12270 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012271 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012272 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012273 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012274static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012275 struct kobj_attribute *attr,
12276 const char *buf,
12277 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012278{
Arun Khandavallifae92942016-08-01 13:31:08 +053012279
Arun Khandavallifae92942016-08-01 13:31:08 +053012280 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012281 pr_err("%s: wlan driver already initialized\n", __func__);
12282 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012283 }
12284
Arun Khandavallifae92942016-08-01 13:31:08 +053012285 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012286 pr_err("%s: wlan driver initialization failed\n", __func__);
12287 return -EIO;
12288 }
12289
12290 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012291
12292 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012293}
Arun Khandavallifae92942016-08-01 13:31:08 +053012294
12295/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012296 * hdd_sysfs_cleanup() - cleanup sysfs
12297 *
12298 * Return: None
12299 *
12300 */
12301static void hdd_sysfs_cleanup(void)
12302{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012303 /* remove from group */
12304 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12305 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12306 wlan_loader->attr_group);
12307
12308 /* unlink the object from parent */
12309 kobject_del(wlan_loader->boot_wlan_obj);
12310
12311 /* free the object */
12312 kobject_put(wlan_loader->boot_wlan_obj);
12313
12314 kfree(wlan_loader->attr_group);
12315 kfree(wlan_loader);
12316
12317 wlan_loader = NULL;
12318}
12319
12320/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012321 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12322 * ready
12323 *
12324 * This is creates the syfs entry boot_wlan. Which shall be invoked
12325 * when the filesystem is ready.
12326 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012327 * QDF API cannot be used here since this function is called even before
12328 * initializing WLAN driver.
12329 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012330 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012331 */
12332static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012333{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012334 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012335
12336 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012337 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012338 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012339
12340 wlan_loader->boot_wlan_obj = NULL;
12341 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12342 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012343 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012344 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012345
12346 wlan_loader->loaded_state = 0;
12347 wlan_loader->attr_group->attrs = attrs;
12348
12349 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12350 kernel_kobj);
12351 if (!wlan_loader->boot_wlan_obj) {
12352 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012353 goto error_return;
12354 }
12355
12356 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12357 wlan_loader->attr_group);
12358 if (ret) {
12359 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12360 goto error_return;
12361 }
12362
12363 return 0;
12364
12365error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012366 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012367
12368 return ret;
12369}
12370
12371/**
12372 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12373 *
12374 * Return: 0 on success or errno on failure
12375 */
12376static int wlan_deinit_sysfs(void)
12377{
Arun Khandavallifae92942016-08-01 13:31:08 +053012378 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012379 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012380 return -EINVAL;
12381 }
12382
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012383 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012384 return 0;
12385}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012386
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012387#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012388
12389#ifdef MODULE
12390/**
12391 * __hdd_module_init - Module init helper
12392 *
12393 * Module init helper function used by both module and static driver.
12394 *
12395 * Return: 0 for success, errno on failure
12396 */
12397static int hdd_module_init(void)
12398{
Arun Khandavallifae92942016-08-01 13:31:08 +053012399 if (__hdd_module_init()) {
12400 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012401 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012402 }
12403
Dustin Brownab482ac2017-06-09 17:00:44 -070012404 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012405}
12406#else
12407static int __init hdd_module_init(void)
12408{
12409 int ret = -EINVAL;
12410
12411 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012412 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012413 pr_err("Failed to create sysfs entry for loading wlan");
12414
12415 return ret;
12416}
12417#endif
12418
12419
12420#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012421/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012422 * hdd_module_exit() - Exit function
12423 *
12424 * This is the driver exit point (invoked when module is unloaded using rmmod)
12425 *
12426 * Return: None
12427 */
12428static void __exit hdd_module_exit(void)
12429{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012430 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012431}
Arun Khandavallifae92942016-08-01 13:31:08 +053012432#else
12433static void __exit hdd_module_exit(void)
12434{
12435 __hdd_module_exit();
12436 wlan_deinit_sysfs();
12437}
12438#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012439
Srinivas Girigowda841da292018-02-21 16:33:00 -080012440static int fwpath_changed_handler(const char *kmessage,
12441 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012442{
12443 return param_set_copystring(kmessage, kp);
12444}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012445
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012446/**
12447 * is_con_mode_valid() check con mode is valid or not
12448 * @mode: global con mode
12449 *
12450 * Return: TRUE on success FALSE on failure
12451 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012452static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012453{
12454 switch (mode) {
12455 case QDF_GLOBAL_MONITOR_MODE:
12456 case QDF_GLOBAL_FTM_MODE:
12457 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012458 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012459 return true;
12460 default:
12461 return false;
12462 }
12463}
12464
12465/**
12466 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12467 * @mode: global con mode
12468 *
12469 * Return: adapter mode
12470 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012471static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012472 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012473{
12474
12475 switch (mode) {
12476 case QDF_GLOBAL_MISSION_MODE:
12477 return QDF_STA_MODE;
12478 case QDF_GLOBAL_MONITOR_MODE:
12479 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012480 case QDF_GLOBAL_EPPING_MODE:
12481 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012482 case QDF_GLOBAL_FTM_MODE:
12483 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012484 case QDF_GLOBAL_QVIT_MODE:
12485 return QDF_QVIT_MODE;
12486 default:
12487 return QDF_MAX_NO_OF_MODE;
12488 }
12489}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012490
Dustin Brown27cd9942017-09-27 16:11:44 -070012491static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012492 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012493{
12494 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12495 return;
12496
12497 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012498 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012499 hdd_info("Release wakelock for monitor mode!");
12500 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12501 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012502 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012503 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012504 case QDF_GLOBAL_FTM_MODE:
12505 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012506 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012507 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012508
Dustin Brown27cd9942017-09-27 16:11:44 -070012509 break;
12510 default:
12511 break;
12512 }
12513}
12514
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012515static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012516 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012517{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012518 int driver_status;
12519
12520 driver_status = hdd_ctx->driver_status;
12521
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012522 switch (curr_mode) {
12523 case QDF_GLOBAL_MISSION_MODE:
12524 case QDF_GLOBAL_MONITOR_MODE:
12525 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012526 hdd_deinit_all_adapters(hdd_ctx, false);
12527 hdd_close_all_adapters(hdd_ctx, false);
12528 break;
12529 case QDF_GLOBAL_EPPING_MODE:
12530 epping_disable();
12531 epping_close();
12532 break;
12533 default:
12534 return;
12535 }
12536}
12537
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012538static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012539 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012540{
Jeff Johnson9d295242017-08-29 14:39:48 -070012541 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012542 int ret = 0;
12543 bool rtnl_held;
12544 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12545 QDF_STATUS status;
12546
12547 if (!qdf_dev) {
12548 hdd_err("qdf device context is Null return!");
12549 return -EINVAL;
12550 }
12551
12552 rtnl_held = hdd_hold_rtnl_lock();
12553 switch (mode) {
12554 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012555 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12556 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012557 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012558 break;
12559 case QDF_GLOBAL_FTM_MODE:
12560 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12561 wlan_hdd_get_intf_addr(hdd_ctx),
12562 NET_NAME_UNKNOWN, rtnl_held);
12563 if (adapter == NULL)
12564 ret = -EINVAL;
12565 break;
12566 case QDF_GLOBAL_MONITOR_MODE:
12567 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12568 wlan_hdd_get_intf_addr(hdd_ctx),
12569 NET_NAME_UNKNOWN, rtnl_held);
12570 if (adapter == NULL)
12571 ret = -EINVAL;
12572 break;
12573 case QDF_GLOBAL_EPPING_MODE:
12574 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012575 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012576 hdd_err("Failed to open in eeping mode: %d", status);
12577 ret = -EINVAL;
12578 break;
12579 }
12580 ret = epping_enable(qdf_dev->dev);
12581 if (ret) {
12582 hdd_err("Failed to enable in epping mode : %d", ret);
12583 epping_close();
12584 }
12585 break;
12586 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012587 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012588 ret = -ENOTSUPP;
12589 break;
12590 }
12591 hdd_release_rtnl_lock();
12592 rtnl_held = false;
12593 return ret;
12594}
12595
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012596/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012597 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012598 * @kmessage: con mode name on which driver to be bring up
12599 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012600 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012601 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012602 * This function is invoked when user updates con mode using sys entry,
12603 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012604 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012605 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012606 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012607static int __con_mode_handler(const char *kmessage,
12608 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012609 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012610{
12611 int ret;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012612 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012613 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012614 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012615
Dustin Brownab6029b2017-05-24 13:04:19 -070012616 hdd_info("con_mode handler: %s", kmessage);
12617
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012618 ret = wlan_hdd_validate_context(hdd_ctx);
12619 if (ret)
12620 return ret;
12621
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012622 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012623
Dustin Brown20024e32018-01-03 12:34:58 -080012624 ret = kstrtoint(kmessage, 0, &new_con_mode);
12625 if (ret) {
12626 hdd_err("Failed to parse con_mode '%s'", kmessage);
12627 goto reset_flags;
12628 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012629 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012630
Dustin Brown20024e32018-01-03 12:34:58 -080012631 if (!is_con_mode_valid(new_con_mode)) {
12632 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012633 ret = -EINVAL;
12634 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012635 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012636
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012637 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012638 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012639 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012640 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012641 ret = 0;
12642 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012643 }
12644
Dustin Brown27cd9942017-09-27 16:11:44 -070012645 /* ensure adapters are stopped */
12646 hdd_stop_present_mode(hdd_ctx, curr_mode);
12647
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012648 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012649 if (ret) {
12650 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012651 goto reset_flags;
12652 }
12653
Dustin Browndd4e50f2018-05-24 15:43:42 -070012654 /* Cleanup present mode before switching to new mode */
12655 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012656
Dustin Brown20024e32018-01-03 12:34:58 -080012657 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012658
12659 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012660 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012661 if (ret) {
12662 hdd_err("Failed to register for new mode");
12663 goto reset_flags;
12664 }
12665
Dustin Brown20024e32018-01-03 12:34:58 -080012666 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012667 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12668 hdd_err("invalid adapter");
12669 ret = -EINVAL;
12670 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012671 }
12672
Dustin Browne7e71d32018-05-11 16:00:08 -070012673 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053012674 if (ret) {
12675 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012676 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012677 }
12678
Dustin Brown20024e32018-01-03 12:34:58 -080012679 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070012680 struct hdd_adapter *adapter =
12681 hdd_get_adapter(hdd_ctx, adapter_mode);
12682
12683 if (!adapter) {
12684 hdd_err("Failed to get adapter:%d", adapter_mode);
12685 goto reset_flags;
12686 }
12687
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012688 if (hdd_start_adapter(adapter)) {
12689 hdd_err("Failed to start %s adapter", kmessage);
12690 ret = -EINVAL;
12691 goto reset_flags;
12692 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012693
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012694 hdd_info("Acquire wakelock for monitor mode!");
12695 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12696 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12697 }
12698
Dustin Brown20024e32018-01-03 12:34:58 -080012699 /* con_mode is a global module parameter */
12700 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012701 hdd_info("Mode successfully changed to %s", kmessage);
12702 ret = 0;
12703
12704reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012705 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012706 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012707 return ret;
12708}
12709
12710
Srinivas Girigowda841da292018-02-21 16:33:00 -080012711static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012712{
12713 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012714 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012715
12716 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12717 ret = wlan_hdd_validate_context(hdd_ctx);
12718 if (ret)
12719 return ret;
12720
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053012721 if (!cds_wait_for_external_threads_completion(__func__)) {
12722 hdd_warn("External threads are still active, can not change mode");
12723 return -EAGAIN;
12724 }
12725
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012726 cds_ssr_protect(__func__);
12727 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12728 cds_ssr_unprotect(__func__);
12729
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012730 return ret;
12731}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012732
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012733static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012734 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012735{
12736 int ret;
12737
12738 ret = param_set_int(kmessage, kp);
12739
12740 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12741 pr_err("Only FTM mode supported!");
12742 return -ENOTSUPP;
12743 }
12744
12745 hdd_set_conparam(con_mode_ftm);
12746 con_mode = con_mode_ftm;
12747
12748 return ret;
12749}
12750
Ravi Joshia307f632017-07-17 23:41:41 -070012751static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012752 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012753{
12754 int ret;
12755
12756 ret = param_set_int(kmessage, kp);
12757
12758 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12759 pr_err("Only Monitor mode supported!");
12760 return -ENOTSUPP;
12761 }
12762
12763 hdd_set_conparam(con_mode_monitor);
12764 con_mode = con_mode_monitor;
12765
12766 return ret;
12767}
12768
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012769/**
12770 * hdd_get_conparam() - driver exit point
12771 *
12772 * This is the driver exit point (invoked when module is unloaded using rmmod)
12773 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012774 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012775 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012776enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012777{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012778 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012779}
12780
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012781void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012782{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012783 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012784}
12785
Komal Seelamc11bb222016-01-27 18:57:10 +053012786/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012787 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12788 * @hdd_ctx: HDD context
12789 *
12790 * Cleans up the pre cac interface, if it exists
12791 *
12792 * Return: None
12793 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012794void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012795{
12796 uint8_t session_id;
12797 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012798 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012799
12800 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12801 if (QDF_IS_STATUS_ERROR(status)) {
12802 hdd_err("failed to get pre cac vdev id");
12803 return;
12804 }
12805
12806 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12807 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070012808 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012809 return;
12810 }
12811
12812 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12813 wlan_hdd_sap_pre_cac_failure,
12814 (void *)precac_adapter);
12815 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12816
12817}
12818
12819/**
Komal Seelamec702b02016-02-24 18:42:16 +053012820 * hdd_update_ol_config - API to update ol configuration parameters
12821 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012822 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012823 * Return: void
12824 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012825static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012826{
Komal Seelamec702b02016-02-24 18:42:16 +053012827 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012828 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012829
Komal Seelamec702b02016-02-24 18:42:16 +053012830 if (!ol_ctx)
12831 return;
12832
12833 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12834 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12835 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12836 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012837 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012838
12839 ol_init_ini_config(ol_ctx, &cfg);
12840}
12841
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012842#ifdef FEATURE_RUNTIME_PM
12843/**
12844 * hdd_populate_runtime_cfg() - populate runtime configuration
12845 * @hdd_ctx: hdd context
12846 * @cfg: pointer to the configuration memory being populated
12847 *
12848 * Return: void
12849 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012850static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012851 struct hif_config_info *cfg)
12852{
12853 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12854 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12855}
12856#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012857static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012858 struct hif_config_info *cfg)
12859{
12860}
12861#endif
12862
Komal Seelamec702b02016-02-24 18:42:16 +053012863/**
12864 * hdd_update_hif_config - API to update HIF configuration parameters
12865 * @hdd_ctx: HDD Context
12866 *
12867 * Return: void
12868 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012869static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012870{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012871 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012872 struct hif_config_info cfg;
12873
12874 if (!scn)
12875 return;
12876
12877 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012878 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012879 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012880
12881 if (hdd_ctx->config->prevent_link_down)
12882 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012883}
12884
12885/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012886 * hdd_update_dp_config() - Propagate config parameters to Lithium
12887 * datapath
12888 * @hdd_ctx: HDD Context
12889 *
12890 * Return: 0 for success/errno for failure
12891 */
12892static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12893{
12894 struct cdp_config_params params;
12895 QDF_STATUS status;
12896
12897 params.tso_enable = hdd_ctx->config->tso_enable;
12898 params.lro_enable = hdd_ctx->config->lro_enable;
12899#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12900 params.tx_flow_stop_queue_threshold =
12901 hdd_ctx->config->TxFlowStopQueueThreshold;
12902 params.tx_flow_start_queue_offset =
12903 hdd_ctx->config->TxFlowStartQueueOffset;
12904#endif
12905 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12906 params.napi_enable = hdd_ctx->napi_enable;
12907 params.tcp_udp_checksumoffload =
12908 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12909
12910 status = cdp_update_config_parameters(
12911 cds_get_context(QDF_MODULE_ID_SOC),
12912 &params);
12913 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012914 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012915 return status;
12916 }
12917
12918 return 0;
12919}
12920
12921/**
Komal Seelamec702b02016-02-24 18:42:16 +053012922 * hdd_update_config() - Initialize driver per module ini parameters
12923 * @hdd_ctx: HDD Context
12924 *
12925 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012926 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012927 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012928int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012929{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012930 int ret;
12931
Komal Seelamec702b02016-02-24 18:42:16 +053012932 hdd_update_ol_config(hdd_ctx);
12933 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012934 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12935 ret = hdd_update_cds_config_ftm(hdd_ctx);
12936 else
12937 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012938 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012939
12940 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012941}
12942
Mukul Sharma9d797a02017-01-05 20:26:03 +053012943#ifdef FEATURE_WLAN_RA_FILTERING
12944/**
12945 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12946 * @psoc_cfg: pmo psoc Configuration
12947 * @hdd_ctx: Pointer to hdd context
12948 *
12949 * Return: none
12950 */
12951static inline void hdd_ra_populate_pmo_config(
12952 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012953 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012954{
12955 psoc_cfg->ra_ratelimit_interval =
12956 hdd_ctx->config->RArateLimitInterval;
12957 psoc_cfg->ra_ratelimit_enable =
12958 hdd_ctx->config->IsRArateLimitEnabled;
12959}
12960#else
12961static inline void hdd_ra_populate_pmo_config(
12962 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012963 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012964{
12965}
12966#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012967
Mukul Sharma9d797a02017-01-05 20:26:03 +053012968/**
12969 * hdd_update_pmo_config - API to update pmo configuration parameters
12970 * @hdd_ctx: HDD context
12971 *
12972 * Return: void
12973 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012974static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012975{
Mukul Sharma9d797a02017-01-05 20:26:03 +053012976 struct pmo_psoc_cfg psoc_cfg;
12977 QDF_STATUS status;
12978
12979 /*
12980 * Value of hdd_ctx->wowEnable can be,
12981 * 0 - Disable both magic pattern match and pattern byte match.
12982 * 1 - Enable magic pattern match on all interfaces.
12983 * 2 - Enable pattern byte match on all interfaces.
12984 * 3 - Enable both magic patter and pattern byte match on
12985 * all interfaces.
12986 */
12987 psoc_cfg.magic_ptrn_enable =
12988 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12989 psoc_cfg.ptrn_match_enable_all_vdev =
12990 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080012991 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012992 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012993 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080012994 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012995 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080012996 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012997 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12998 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080012999 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013000 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013001 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013002 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
13003 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
13004 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080013005 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053013006 psoc_cfg.auto_power_save_fail_mode =
13007 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013008
13009 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013010 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
13011 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013012
Dustin Brownb9987af2018-03-01 17:15:11 -080013013 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
13014 if (QDF_IS_STATUS_ERROR(status))
13015 hdd_err("failed pmo psoc configuration; status:%d", status);
13016
13017 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013018}
13019
Abhishek Singhb20db962017-03-03 21:28:46 +053013020#ifdef FEATURE_WLAN_SCAN_PNO
13021static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13022 struct hdd_config *cfg)
13023{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013024 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13025
Abhishek Singhb20db962017-03-03 21:28:46 +053013026 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13027 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13028 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13029 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13030 pno_cfg->channel_prediction_full_scan =
13031 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013032 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13033 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13034 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13035 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013036}
13037#else
13038static inline void
13039hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013040 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013041{
Abhishek Singhb20db962017-03-03 21:28:46 +053013042}
13043#endif
13044
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013045void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
13046 struct hdd_config *cfg)
13047{
13048 uint8_t i = 0;
13049
13050 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
13051 if (!ie_whitelist->white_list)
13052 return;
13053
13054 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
13055 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
13056 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
13057 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
13058 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
13059 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
13060 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
13061 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
13062
13063 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
13064 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
13065 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
13066}
13067
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013068uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
13069{
13070 uint8_t i, score;
13071
13072 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
13073 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
13074 if (score > MAX_INDEX_SCORE)
13075 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
13076 MAX_INDEX_SCORE, i);
13077 }
13078
13079 return per_index_score;
13080}
13081
13082/**
13083 * hdd_update_score_config - API to update candidate scoring related params
13084 * configuration parameters
13085 * @score_config: score config to update
13086 * @cfg: config params
13087 *
13088 * Return: 0 if success else err
13089 */
13090static void hdd_update_score_config(
13091 struct scoring_config *score_config, struct hdd_config *cfg)
13092{
13093 int total_weight;
13094
13095 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
13096 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
13097 score_config->weight_cfg.vht_caps_weightage =
13098 cfg->vht_caps_weightage;
13099 score_config->weight_cfg.he_caps_weightage =
13100 cfg->he_caps_weightage;
13101 score_config->weight_cfg.chan_width_weightage =
13102 cfg->chan_width_weightage;
13103 score_config->weight_cfg.chan_band_weightage =
13104 cfg->chan_band_weightage;
13105 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
13106 score_config->weight_cfg.beamforming_cap_weightage =
13107 cfg->beamforming_cap_weightage;
13108 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
13109 score_config->weight_cfg.channel_congestion_weightage =
13110 cfg->channel_congestion_weightage;
13111 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
13112
13113 total_weight = score_config->weight_cfg.rssi_weightage +
13114 score_config->weight_cfg.ht_caps_weightage +
13115 score_config->weight_cfg.vht_caps_weightage +
13116 score_config->weight_cfg.he_caps_weightage +
13117 score_config->weight_cfg.chan_width_weightage +
13118 score_config->weight_cfg.chan_band_weightage +
13119 score_config->weight_cfg.nss_weightage +
13120 score_config->weight_cfg.beamforming_cap_weightage +
13121 score_config->weight_cfg.pcl_weightage +
13122 score_config->weight_cfg.channel_congestion_weightage +
13123 score_config->weight_cfg.oce_wan_weightage;
13124
13125 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
13126 hdd_err("total weight is greater than %d fallback to default values",
13127 BEST_CANDIDATE_MAX_WEIGHT);
13128
13129 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
13130 score_config->weight_cfg.ht_caps_weightage =
13131 HT_CAPABILITY_WEIGHTAGE;
13132 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
13133 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
13134 score_config->weight_cfg.chan_width_weightage =
13135 CHAN_WIDTH_WEIGHTAGE;
13136 score_config->weight_cfg.chan_band_weightage =
13137 CHAN_BAND_WEIGHTAGE;
13138 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
13139 score_config->weight_cfg.beamforming_cap_weightage =
13140 BEAMFORMING_CAP_WEIGHTAGE;
13141 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
13142 score_config->weight_cfg.channel_congestion_weightage =
13143 CHANNEL_CONGESTION_WEIGHTAGE;
13144 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
13145 }
13146
13147 score_config->bandwidth_weight_per_index =
13148 hdd_limit_max_per_index_score(
13149 cfg->bandwidth_weight_per_index);
13150 score_config->nss_weight_per_index =
13151 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13152 score_config->band_weight_per_index =
13153 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13154
13155 score_config->rssi_score.best_rssi_threshold =
13156 cfg->best_rssi_threshold;
13157 score_config->rssi_score.good_rssi_threshold =
13158 cfg->good_rssi_threshold;
13159 score_config->rssi_score.bad_rssi_threshold =
13160 cfg->bad_rssi_threshold;
13161 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13162 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13163 score_config->rssi_score.good_rssi_bucket_size =
13164 cfg->good_rssi_bucket_size;
13165 score_config->rssi_score.bad_rssi_bucket_size =
13166 cfg->bad_rssi_bucket_size;
13167 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13168 cfg->rssi_pref_5g_rssi_thresh;
13169
13170 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13171 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13172 hdd_limit_max_per_index_score(
13173 cfg->esp_qbss_score_slots3_to_0);
13174 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13175 hdd_limit_max_per_index_score(
13176 cfg->esp_qbss_score_slots7_to_4);
13177 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13178 hdd_limit_max_per_index_score(
13179 cfg->esp_qbss_score_slots11_to_8);
13180 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13181 hdd_limit_max_per_index_score(
13182 cfg->esp_qbss_score_slots15_to_12);
13183
13184 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13185 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13186 hdd_limit_max_per_index_score(
13187 cfg->oce_wan_score_slots3_to_0);
13188 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13189 hdd_limit_max_per_index_score(
13190 cfg->oce_wan_score_slots7_to_4);
13191 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13192 hdd_limit_max_per_index_score(
13193 cfg->oce_wan_score_slots11_to_8);
13194 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13195 hdd_limit_max_per_index_score(
13196 cfg->oce_wan_score_slots15_to_12);
13197
13198
13199 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13200 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13201 score_config->nss = cfg->enable2x2 ? 2 : 1;
13202
13203 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13204 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13205 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13206 score_config->he_cap = 1;
13207
13208 if (score_config->he_cap ||
13209 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13210 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13211 score_config->vht_cap = 1;
13212
13213 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13214 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13215 score_config->ht_cap = 1;
13216
13217 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13218 score_config->vht_24G_cap = 1;
13219
13220 if (cfg->enableTxBF)
13221 score_config->beamformee_cap = 1;
13222
13223}
13224
Abhishek Singh257a9482017-03-06 16:52:39 +053013225/**
bings81fe50a2017-11-27 14:33:26 +080013226 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13227 * @hdd_ctx: HDD context
13228 *
13229 * Return: 0 if success else err
13230 */
13231static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13232{
13233 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13234 struct hdd_config *cfg = hdd_ctx->config;
13235 struct dfs_user_config dfs_cfg;
13236 QDF_STATUS status;
13237
13238 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13239 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13240 if (QDF_IS_STATUS_ERROR(status)) {
13241 hdd_err("failed dfs psoc configuration");
13242 return -EINVAL;
13243 }
13244
13245 return 0;
13246}
13247
13248/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013249 * hdd_update_scan_config - API to update scan configuration parameters
13250 * @hdd_ctx: HDD context
13251 *
13252 * Return: 0 if success else err
13253 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013254static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013255{
13256 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13257 struct scan_user_cfg scan_cfg;
13258 struct hdd_config *cfg = hdd_ctx->config;
13259 QDF_STATUS status;
13260
13261 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13262 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13263 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13264 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13265 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13266 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13267 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013268 /* convert to ms */
13269 scan_cfg.scan_cache_aging_time =
13270 cfg->scanAgingTimeout * 1000;
13271 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13272 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13273 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13274 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013275 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013276 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013277 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13278 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013279 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013280 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013281 scan_cfg.sta_miracast_mcc_rest_time =
13282 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013283
Abhishek Singhb20db962017-03-03 21:28:46 +053013284 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013285 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013286 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013287
Abhishek Singh257a9482017-03-06 16:52:39 +053013288 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13289 if (status != QDF_STATUS_SUCCESS) {
13290 hdd_err("failed pmo psoc configuration");
13291 return -EINVAL;
13292 }
13293
13294 return 0;
13295}
Abhishek Singh257a9482017-03-06 16:52:39 +053013296
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013297int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013298{
13299 int ret;
13300
13301 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013302 if (ret)
13303 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013304
Abhishek Singh257a9482017-03-06 16:52:39 +053013305 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013306 if (ret)
13307 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013308
Frank Liud4b2fa02017-03-29 11:46:48 +080013309 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013310 if (ret)
13311 return ret;
13312
13313 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013314 if (ret)
13315 return ret;
13316
13317 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013318
13319 return ret;
13320}
13321
Agrawal Ashish65634612016-08-18 13:24:32 +053013322/**
13323 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13324 * @mode : cfg80211 DFS mode
13325 *
13326 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13327 */
13328enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13329{
13330 switch (mode) {
13331 case DFS_MODE_ENABLE:
13332 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013333 case DFS_MODE_DISABLE:
13334 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013335 case DFS_MODE_DEPRIORITIZE:
13336 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013337 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013338 hdd_debug("ACS dfs mode is NONE");
13339 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013340 }
13341}
13342
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013343/**
13344 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13345 * @hddctx: pointer to hdd context
13346 * @set_value: enable/disable
13347 *
13348 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13349 * Host(even though it is duplicate). When Host send vendor command
13350 * disable,FW doesn't perform any action. Whenever any change in
13351 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13352 *
13353 * return - 0 on success, appropriate error values on failure.
13354 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013355int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013356{
13357 QDF_STATUS status;
13358
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013359 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013360 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013361
13362 if (!hddctx->config->goptimize_chan_avoid_event) {
13363 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13364 return -EINVAL;
13365 }
13366
13367 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13368 if (!QDF_IS_STATUS_SUCCESS(status)) {
13369 hdd_err("Failed to send chan avoid command to SME");
13370 return -EINVAL;
13371 }
13372 return 0;
13373}
Agrawal Ashish65634612016-08-18 13:24:32 +053013374
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013375/**
13376 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13377 * @value: value to set
13378 *
13379 * This function will set the passed value to roaming in progress flag.
13380 *
13381 * Return: None
13382 */
13383void hdd_set_roaming_in_progress(bool value)
13384{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013385 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013386
13387 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13388 if (!hdd_ctx) {
13389 hdd_err("HDD context is NULL");
13390 return;
13391 }
13392
13393 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013394 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013395}
13396
13397/**
13398 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013399 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013400 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013401 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013402 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013403bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013404{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013405 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013406 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013407
13408 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13409 if (!hdd_ctx) {
13410 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013411 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013412 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013413 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13414 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013415 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13416 hdd_ctx->roaming_in_progress);
13417
13418 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013419}
13420
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013421/**
13422 * hdd_is_connection_in_progress() - check if connection is in
13423 * progress
13424 * @session_id: session id
13425 * @reason: scan reject reason
13426 *
13427 * Go through each adapter and check if Connection is in progress
13428 *
13429 * Return: true if connection is in progress else false
13430 */
13431bool hdd_is_connection_in_progress(uint8_t *session_id,
13432 enum scan_reject_states *reason)
13433{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013434 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013435 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013436 uint8_t sta_id = 0;
13437 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013438 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013439
13440 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13441 if (!hdd_ctx) {
13442 hdd_err("HDD context is NULL");
13443 return false;
13444 }
13445
Dustin Brown920397d2017-12-13 16:27:50 -080013446 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070013447 hdd_debug("Adapter with device mode %s(%d) exists",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013448 hdd_device_mode_to_string(adapter->device_mode),
13449 adapter->device_mode);
13450 if (((QDF_STA_MODE == adapter->device_mode)
13451 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13452 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13453 && (eConnectionState_Connecting ==
13454 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13455 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013456 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013457 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013458 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013459 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013460 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013461 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013462 }
13463 return true;
13464 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013465 /*
13466 * sme_neighbor_middle_of_roaming is for LFR2
13467 * hdd_is_roaming_in_progress is for LFR3
13468 */
13469 if (((QDF_STA_MODE == adapter->device_mode) &&
13470 sme_neighbor_middle_of_roaming(
13471 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013472 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013473 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013474 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013475 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013476 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013477 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013478 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013479 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013480 }
13481 return true;
13482 }
13483 if ((QDF_STA_MODE == adapter->device_mode) ||
13484 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13485 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13486 hdd_sta_ctx =
13487 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13488 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013489 hdd_sta_ctx->conn_info.connState)
13490 && sme_is_sta_key_exchange_in_progress(
13491 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013492 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013493 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013494 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013495 " is in middle of WPS/EAPOL exchange.",
13496 MAC_ADDR_ARRAY(sta_mac));
13497 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013498 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013499 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013500 }
13501 return true;
13502 }
13503 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13504 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13505 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13506 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013507 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013508 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013509 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013510 continue;
13511
13512 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013513 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013514 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013515 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013516 " of SAP/GO is in middle of WPS/EAPOL exchange",
13517 MAC_ADDR_ARRAY(sta_mac));
13518 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013519 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013520 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013521 }
13522 return true;
13523 }
13524 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013525 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013526 return true;
13527 }
13528 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013529 }
Dustin Brown920397d2017-12-13 16:27:50 -080013530
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013531 return false;
13532}
13533
13534/**
13535 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013536 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013537 *
13538 * Return: None
13539 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013540void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013541{
Jeff Johnson87251032017-08-29 13:31:11 -070013542 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013543 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013544 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013545 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070013546 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013547 void *sap_ctx;
13548
13549 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013550 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013551 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013552
13553 mutex_lock(&hdd_ctx->sap_lock);
13554 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13555 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013556 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13557 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13558 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13559 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013560 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013561 qdf_stop_bss_event,
13562 SME_CMD_TIMEOUT_VALUE);
13563
13564 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013565 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013566 goto end;
13567 }
13568 }
13569 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013570 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013571 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013572 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013573 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013574 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013575
13576 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013577 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013578 wlansap_reset_sap_config_add_ie(sap_config,
13579 eUPDATE_IE_ALL);
13580 goto end;
13581 }
13582
13583 qdf_event_reset(&hostapd_state->qdf_event);
13584 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13585 sap_config,
13586 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013587 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013588 wlansap_reset_sap_config_add_ie(sap_config,
13589 eUPDATE_IE_ALL);
13590 goto end;
13591 }
13592
Jeff Johnson6867ec32017-09-29 20:30:20 -070013593 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013594 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013595 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013596 SME_CMD_TIMEOUT_VALUE);
13597 wlansap_reset_sap_config_add_ie(sap_config,
13598 eUPDATE_IE_ALL);
13599 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013600 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013601 goto end;
13602 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013603 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013604 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013605 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013606 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13607 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013608 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013609 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013610 ap_adapter->device_mode,
13611 true);
13612 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013613 }
13614end:
13615 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013616}
13617
13618/**
13619 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13620 * with non dfs acs
13621 *
13622 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13623 *
13624 * Return: None
13625 */
13626void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13627{
Jeff Johnson9d295242017-08-29 14:39:48 -070013628 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013629 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070013630 struct cds_context *cds_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013631
13632 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13633 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013634 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013635 return;
13636 }
13637
13638 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13639 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013640 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013641 return;
13642 }
13643
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013644 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13645 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013646 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013647 return;
13648 }
13649
13650 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013651 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13652 &ap_adapter->event_flags) &&
13653 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013654 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013655
Jeff Johnson6867ec32017-09-29 20:30:20 -070013656 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013657 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013658 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013659 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013660 acs_cfg.acs_mode = true;
13661
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013662 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013663 }
13664}
13665
13666/**
13667 * hdd_set_connection_in_progress() - to set the connection in
13668 * progress flag
13669 * @value: value to set
13670 *
13671 * This function will set the passed value to connection in progress flag.
13672 * If value is previously being set to true then no need to set it again.
13673 *
13674 * Return: true if value is being set correctly and false otherwise.
13675 */
13676bool hdd_set_connection_in_progress(bool value)
13677{
13678 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013679 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013680
13681 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13682 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013683 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013684 return false;
13685 }
13686
13687 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13688 /*
13689 * if the value is set to true previously and if someone is
13690 * trying to make it true again then it could be some race
13691 * condition being triggered. Avoid this situation by returning
13692 * false
13693 */
13694 if (hdd_ctx->connection_in_progress && value)
13695 status = false;
13696 else
13697 hdd_ctx->connection_in_progress = value;
13698 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13699 return status;
13700}
13701
Jeff Johnson9d295242017-08-29 14:39:48 -070013702int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013703{
13704 if (!adapter) {
13705 hdd_err("Invalid adapter");
13706 return -EINVAL;
13707 }
13708 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013709 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013710 WMA_VDEV_MCC_SET_TIME_QUOTA,
13711 set_value, VDEV_CMD);
13712 return 0;
13713
13714}
13715
Jeff Johnson9d295242017-08-29 14:39:48 -070013716int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013717{
13718 if (!adapter) {
13719 hdd_err("Invalid adapter");
13720 return -EINVAL;
13721 }
13722
13723 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013724 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013725 WMA_VDEV_MCC_SET_TIME_LATENCY,
13726 set_value, VDEV_CMD);
13727 return 0;
13728}
13729
Jeff Johnson9d295242017-08-29 14:39:48 -070013730struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013731 *psoc, uint8_t vdev_id)
13732{
Jeff Johnson9d295242017-08-29 14:39:48 -070013733 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013734 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013735
13736 /*
13737 * Currently PSOC is not being used. But this logic will
13738 * change once we have the converged implementation of
13739 * HDD context per PSOC in place. This would break if
13740 * multiple vdev objects reuse the vdev id.
13741 */
13742 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13743 if (!adapter)
13744 hdd_err("Get adapter by vdev id failed");
13745
13746 return adapter;
13747}
13748
Jeff Johnson9d295242017-08-29 14:39:48 -070013749int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013750 int8_t *rssi, int8_t *snr)
13751{
13752 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013753 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013754
Jeff Johnson025618c2018-03-18 14:41:00 -070013755 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013756 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013757 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013758 if (QDF_STATUS_SUCCESS != status) {
13759 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13760 return -EINVAL;
13761 }
13762
13763 return 0;
13764}
13765
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013766/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013767 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13768 * @adapter - HDD adapter
13769 * @tos - type of service
13770 * @status - status of the traffic
13771 *
13772 * Return: 0 on success and non zero value on failure
13773 */
13774
13775int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13776 bool is_tos_active)
13777{
13778 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013779 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013780 uint32_t max_off_chan_time = 0;
13781 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013782 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013783 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013784
13785 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13786 ret = wlan_hdd_validate_context(hdd_ctx);
13787
13788 if (ret < 0) {
13789 hdd_err("failed to set limit off chan params");
13790 return ret;
13791 }
13792
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013793 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13794
13795 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013796 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013797 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013798 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013799
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013800 if (adapter->active_ac) {
13801 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013802 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013803 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13804 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13805 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013806 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013807 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013808 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13809 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13810 PM_LATENCY);
13811 } else {
13812 /*ignore this command if only BE/BK is active */
13813 is_tos_active = false;
13814 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13815 hdd_ctx->config->conc_system_pref);
13816 }
13817 } else {
13818 /* No active tos */
13819 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13820 hdd_ctx->config->conc_system_pref);
13821 }
13822
Jeff Johnson1b780e42017-10-31 14:11:45 -070013823 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013824 is_tos_active, max_off_chan_time,
13825 hdd_ctx->config->nRestTimeConc, true);
13826 if (!QDF_IS_STATUS_SUCCESS(status)) {
13827 hdd_err("failed to set limit off chan params");
13828 ret = -EINVAL;
13829 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013830
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013831 return ret;
13832}
13833
13834/**
13835 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13836 * @adapter - HDD adapter
13837 *
13838 * Return: 0 on success and non zero value on failure
13839 */
13840int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13841{
13842 struct hdd_context *hdd_ctx;
13843 int ret;
13844 QDF_STATUS status;
13845 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13846
13847 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13848 ret = wlan_hdd_validate_context(hdd_ctx);
13849 if (ret < 0)
13850 return ret;
13851
13852 /* set the system preferece to default */
13853 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13854 hdd_ctx->config->conc_system_pref);
13855
13856 /* clear the bitmap */
13857 adapter->active_ac = 0;
13858
13859 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013860 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013861
Jeff Johnson1b780e42017-10-31 14:11:45 -070013862 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013863 false, 0, 0, false);
13864 if (!QDF_IS_STATUS_SUCCESS(status)) {
13865 hdd_err("failed to reset limit off chan params");
13866 ret = -EINVAL;
13867 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013868
13869 return ret;
13870}
13871
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013872/**
13873 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13874 * @drv_op: Enum indicating driver op
13875 *
13876 * Return: none
13877 */
13878void hdd_start_driver_ops_timer(int drv_op)
13879{
13880 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13881 switch (drv_op) {
13882 case eHDD_DRV_OP_PROBE:
13883 memcpy(drv_ops_string, "probe", sizeof("probe"));
13884 break;
13885 case eHDD_DRV_OP_REMOVE:
13886 memcpy(drv_ops_string, "remove", sizeof("remove"));
13887 break;
13888 case eHDD_DRV_OP_SHUTDOWN:
13889 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13890 break;
13891 case eHDD_DRV_OP_REINIT:
13892 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13893 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013894 case eHDD_DRV_OP_IFF_UP:
13895 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13896 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013897 }
13898
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013899 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013900 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13901 HDD_OPS_INACTIVITY_TIMEOUT);
13902}
13903
13904/**
13905 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13906 *
13907 * Return: none
13908 */
13909void hdd_stop_driver_ops_timer(void)
13910{
13911 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13912}
13913
13914/**
13915 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13916 * inactivity timer
13917 *
13918 * Return: None
13919 */
13920void hdd_drv_ops_inactivity_handler(void)
13921{
13922 hdd_err("%s: %d Sec timer expired while in .%s",
13923 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13924
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013925 if (hdd_drv_ops_task) {
13926 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13927 qdf_print_thread_trace(hdd_drv_ops_task);
13928 } else {
13929 hdd_err("hdd_drv_ops_task is null");
13930 }
13931
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013932 /* Driver shutdown is stuck, no recovery possible at this point */
13933 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13934 sizeof("shutdown")))
13935 QDF_BUG(0);
13936
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013937 if (cds_is_fw_down()) {
13938 hdd_err("FW is down");
13939 return;
13940 }
13941
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013942 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013943 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013944 else
13945 QDF_BUG(0);
13946}
13947
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013948void hdd_pld_ipa_uc_shutdown_pipes(void)
13949{
13950 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13951
13952 if (!hdd_ctx)
13953 return;
13954
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053013955 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013956}
13957
Yun Parkff6a16a2017-09-26 16:38:18 -070013958/**
13959 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13960 * @struct hdd_context *hdd_ctx
13961 * @struct hdd_adapter *padapter
13962 * @bool enble
13963 *
13964 * Return: none
13965 */
13966void hdd_set_rx_mode_rps(bool enable)
13967{
13968 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070013969 struct hdd_context *hdd_ctx;
13970 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070013971
Ryan Hsu0e878fa2018-05-04 15:22:09 -070013972 if (!cds_cfg)
13973 return;
13974
13975 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13976 if (!hdd_ctx)
13977 return;
13978
13979 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13980 if (!adapter)
13981 return;
13982
13983 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070013984 if (enable && !cds_cfg->rps_enabled)
13985 hdd_send_rps_ind(adapter);
13986 else if (!enable && cds_cfg->rps_enabled)
13987 hdd_send_rps_disable_ind(adapter);
13988 }
13989}
13990
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053013991bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
13992{
13993 struct hdd_adapter *adapter = NULL;
13994
13995 hdd_for_each_adapter(hdd_ctx, adapter) {
13996 if ((adapter->device_mode == QDF_STA_MODE ||
13997 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
13998 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
13999 &adapter->event_flags)){
14000 return true;
14001 }
14002 }
14003
14004 return false;
14005}
14006
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014007/* Register the module init/exit functions */
14008module_init(hdd_module_init);
14009module_exit(hdd_module_exit);
14010
14011MODULE_LICENSE("Dual BSD/GPL");
14012MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14013MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14014
Srinivas Girigowda841da292018-02-21 16:33:00 -080014015static const struct kernel_param_ops con_mode_ops = {
14016 .set = con_mode_handler,
14017 .get = param_get_int,
14018};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014019
Srinivas Girigowda841da292018-02-21 16:33:00 -080014020static const struct kernel_param_ops con_mode_ftm_ops = {
14021 .set = con_mode_handler_ftm,
14022 .get = param_get_int,
14023};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014024
Srinivas Girigowda841da292018-02-21 16:33:00 -080014025static const struct kernel_param_ops con_mode_monitor_ops = {
14026 .set = con_mode_handler_monitor,
14027 .get = param_get_int,
14028};
Ravi Joshia307f632017-07-17 23:41:41 -070014029
Srinivas Girigowda841da292018-02-21 16:33:00 -080014030static const struct kernel_param_ops fwpath_ops = {
14031 .set = fwpath_changed_handler,
14032 .get = param_get_string,
14033};
14034
14035module_param_cb(con_mode, &con_mode_ops, &con_mode,
14036 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14037
14038module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14039 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14040
14041module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14042 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14043
14044module_param_cb(fwpath, &fwpath_ops, &fwpath,
14045 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014046
14047module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14048
14049module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14050
14051module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);