blob: b5f7eac17ac0cfad42e43dfe4ccd74d75a72962e [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"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800139#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800140#ifdef MODULE
141#define WLAN_MODULE_NAME module_name(THIS_MODULE)
142#else
143#define WLAN_MODULE_NAME "wlan"
144#endif
145
146#ifdef TIMER_MANAGER
147#define TIMER_MANAGER_STR " +TIMER_MANAGER"
148#else
149#define TIMER_MANAGER_STR ""
150#endif
151
152#ifdef MEMORY_DEBUG
153#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
154#else
155#define MEMORY_DEBUG_STR ""
156#endif
157
Dustin Brownc1034df2018-02-07 14:51:32 -0800158#ifdef PANIC_ON_BUG
159#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
160#else
161#define PANIC_ON_BUG_STR ""
162#endif
163
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530164bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530165int wlan_start_ret_val;
166static DECLARE_COMPLETION(wlan_start_comp);
167static unsigned int dev_num = 1;
168static struct cdev wlan_hdd_state_cdev;
169static struct class *class;
170static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530171#ifndef MODULE
172static struct gwlan_loader *wlan_loader;
173static ssize_t wlan_boot_cb(struct kobject *kobj,
174 struct kobj_attribute *attr,
175 const char *buf, size_t count);
176struct gwlan_loader {
177 bool loaded_state;
178 struct kobject *boot_wlan_obj;
179 struct attribute_group *attr_group;
180};
181
182static struct kobj_attribute wlan_boot_attribute =
183 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
184
185static struct attribute *attrs[] = {
186 &wlan_boot_attribute.attr,
187 NULL,
188};
189
190#define MODULE_INITIALIZED 1
191#endif
192
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530193#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
194#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800195#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530196
197static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800198static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530199static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
200
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800201/* the Android framework expects this param even though we don't use it */
202#define BUF_LEN 20
203static char fwpath_buffer[BUF_LEN];
204static struct kparam_string fwpath = {
205 .string = fwpath_buffer,
206 .maxlen = BUF_LEN,
207};
208
209static char *country_code;
210static int enable_11d = -1;
211static int enable_dfs_chan_scan = -1;
212
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800213/*
214 * spinlock for synchronizing asynchronous request/response
215 * (full description of use in wlan_hdd_main.h)
216 */
217DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530218DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800219
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800220#define WLAN_NLINK_CESIUM 30
221
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530222static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800223
224#define WOW_MAX_FILTER_LISTS 1
225#define WOW_MAX_FILTERS_PER_LIST 4
226#define WOW_MIN_PATTERN_SIZE 6
227#define WOW_MAX_PATTERN_SIZE 64
228
229#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
230static const struct wiphy_wowlan_support wowlan_support_reg_init = {
231 .flags = WIPHY_WOWLAN_ANY |
232 WIPHY_WOWLAN_MAGIC_PKT |
233 WIPHY_WOWLAN_DISCONNECT |
234 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
235 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
236 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
237 WIPHY_WOWLAN_4WAY_HANDSHAKE |
238 WIPHY_WOWLAN_RFKILL_RELEASE,
239 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
240 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
241 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
242};
243#endif
244
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700245static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
246 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
258 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
259 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
260 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
261 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
262 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700280 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700281 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700282 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530283 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800284 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530285 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700286};
287
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530288int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
289 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
290 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
291 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
292 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
293};
294
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530295struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530296struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800297
298struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800299#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700300static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800301#endif
302
Sachin Ahujadddd2632017-03-07 19:07:24 +0530303void hdd_start_complete(int ret)
304{
305 wlan_start_ret_val = ret;
306
307 complete(&wlan_start_comp);
308}
309
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800310/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530311 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700312 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530313 *
314 * Return: none
315 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700316static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530317{
Jeff Johnson9d295242017-08-29 14:39:48 -0700318 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530319
Dustin Brown920397d2017-12-13 16:27:50 -0800320 hdd_for_each_adapter(hdd_ctx, adapter)
321 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530322}
323
324/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800325 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
326 * @vdev_id: vdev_id
327 * @action: action type
328 * @reason: reason type
329 *
330 * Return: none
331 */
332void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
333 enum netif_action_type action, enum netif_reason_type reason)
334{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700335 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700336 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800337
338 if (!hdd_ctx) {
339 hdd_err("hdd ctx is NULL");
340 return;
341 }
342 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
343
344 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800345}
346
347/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700348 * Store WLAN driver version and timestamp info in global variables such that
349 * crash debugger can extract them from driver debug symbol and crashdump for
350 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800351 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800352#ifdef BUILD_TAG
353uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
354#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800355uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700356#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800357
358/**
359 * hdd_device_mode_to_string() - return string conversion of device mode
360 * @device_mode: device mode
361 *
362 * This utility function helps log string conversion of device mode.
363 *
364 * Return: string conversion of device mode, if match found;
365 * "Unknown" otherwise.
366 */
367const char *hdd_device_mode_to_string(uint8_t device_mode)
368{
369 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800370 CASE_RETURN_STRING(QDF_STA_MODE);
371 CASE_RETURN_STRING(QDF_SAP_MODE);
372 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
373 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
374 CASE_RETURN_STRING(QDF_FTM_MODE);
375 CASE_RETURN_STRING(QDF_IBSS_MODE);
376 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
377 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700378 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800379 default:
380 return "Unknown";
381 }
382}
383
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530384/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500385 * hdd_get_valid_chan() - return current chan list from regulatory.
386 * @hdd_ctx: HDD context
387 * @chan_list: buf hold returned chan list
388 * @chan_num: input buf size and output returned chan num
389 *
390 * This function helps get current available chan list from regulatory
391 * module. It excludes the "disabled" and "invalid" channels.
392 *
393 * Return: 0 for success.
394 */
395static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
396 uint8_t *chan_list,
397 uint32_t *chan_num)
398{
399 int i = 0, j = 0;
400 struct regulatory_channel *cur_chan_list;
401 struct wlan_objmgr_pdev *pdev;
402
403 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
404 return -EINVAL;
405
406 pdev = hdd_ctx->hdd_pdev;
407 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
408 sizeof(struct regulatory_channel));
409 if (!cur_chan_list)
410 return -ENOMEM;
411
412 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
413 QDF_STATUS_SUCCESS) {
414 qdf_mem_free(cur_chan_list);
415 return -EINVAL;
416 }
417
418 for (i = 0; i < NUM_CHANNELS; i++) {
419 uint32_t ch = cur_chan_list[i].chan_num;
420 enum channel_state state = wlan_reg_get_channel_state(pdev,
421 ch);
422
423 if (state != CHANNEL_STATE_DISABLE &&
424 state != CHANNEL_STATE_INVALID &&
425 j < *chan_num) {
426 chan_list[j] = (uint8_t)ch;
427 j++;
428 }
429 }
430 *chan_num = j;
431 qdf_mem_free(cur_chan_list);
432 return 0;
433}
434
435/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530436 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
437 * @adapter: HDD adapter
438 * @chan_number: Channel number
439 * @chan_bw: Bandwidth
440 *
441 * Checks if the given bandwidth is valid for the given channel number.
442 *
443 * Return: 0 for success, non-zero for failure
444 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700445int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530446 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800447 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530448{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500449 uint8_t chan[NUM_CHANNELS];
450 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530451 bool found = false;
452 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500453 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530454
455 hal = WLAN_HDD_GET_HAL_CTX(adapter);
456 if (!hal) {
457 hdd_err("Invalid HAL context");
458 return -EINVAL;
459 }
460
Liangwei Dong17bf2662018-01-05 02:02:05 -0500461 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
462 &len);
463 if (ret) {
464 hdd_err("error %d in getting valid channel list", ret);
465 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530466 }
467
468 for (i = 0; i < len; i++) {
469 if (chan[i] == chan_number) {
470 found = true;
471 break;
472 }
473 }
474
475 if (found == false) {
476 hdd_err("Channel not in driver's valid channel list");
477 return -EOPNOTSUPP;
478 }
479
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700480 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
481 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530482 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
483 return -EINVAL;
484 }
485
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700486 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530487 if (chan_bw == CH_WIDTH_80MHZ) {
488 hdd_err("BW80 not possible in 2.4GHz band");
489 return -EINVAL;
490 }
491 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
492 (chan_bw != CH_WIDTH_MAX)) {
493 hdd_err("Only BW20 possible on channel 14");
494 return -EINVAL;
495 }
496 }
497
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700498 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530499 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
500 (chan_bw != CH_WIDTH_MAX)) {
501 hdd_err("Only BW20 possible on channel 165");
502 return -EINVAL;
503 }
504 }
505
506 return 0;
507}
508
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530509/**
510 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
511 *
512 * Block the unloading of the driver (or) interface up until the
513 * cds recovery is completed
514 *
515 * Return: true for recovery completion else false
516 */
517static bool hdd_wait_for_recovery_completion(void)
518{
519 int retry = 0;
520
521 /* Wait for recovery to complete */
522 while (cds_is_driver_recovering()) {
523 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
524 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530525
526 if (g_is_system_reboot_triggered) {
527 hdd_info("System Reboot happening ignore unload!!");
528 return false;
529 }
530
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530531 msleep(1000);
532 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
533 hdd_err("SSR never completed, error");
534 /*
535 * Trigger the bug_on in the internal builds, in the
536 * customer builds self-recovery will be enabled
537 * in those cases just return error.
538 */
539 if (cds_is_self_recovery_enabled())
540 return false;
541 QDF_BUG(0);
542 }
543 }
544
545 hdd_info("Recovery completed successfully!");
546 return true;
547}
548
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530549
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800550static int __hdd_netdev_notifier_call(struct notifier_block *nb,
551 unsigned long state, void *data)
552{
553#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
554 struct netdev_notifier_info *dev_notif_info = data;
555 struct net_device *dev = dev_notif_info->dev;
556#else
557 struct net_device *dev = data;
558#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700559 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700560 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800561
Dustin Brownfdf17c12018-03-14 12:55:34 -0700562 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800563
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800564 /* Make sure that this callback corresponds to our device. */
565 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
566 return NOTIFY_DONE;
567
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530568 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800569 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700570 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800571 return NOTIFY_DONE;
572 }
573
574 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700575 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800576 return NOTIFY_DONE;
577 }
578
579 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
580 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800581 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530582 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800583 return NOTIFY_DONE;
584 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800585
586 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
587 hdd_err("%s: Driver module is closed", __func__);
588 return NOTIFY_DONE;
589 }
590
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530591 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800592 return NOTIFY_DONE;
593
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800594 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800595 dev->name, state);
596
597 switch (state) {
598 case NETDEV_REGISTER:
599 break;
600
601 case NETDEV_UNREGISTER:
602 break;
603
604 case NETDEV_UP:
605 sme_ch_avoid_update_req(hdd_ctx->hHal);
606 break;
607
608 case NETDEV_DOWN:
609 break;
610
611 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700612 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800613 complete(&adapter->linkup_event_var);
614 break;
615
616 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700617 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
618 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530619 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700620 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800621 } else {
hqueaa33ee2017-05-04 17:56:35 +0800622 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800623 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800624 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530625 /*
626 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
627 * of return status of hdd_stop call, kernel resets the IFF_UP
628 * flag after which driver does not send the cfg80211_scan_done.
629 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
630 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530631 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800632 break;
633
634 default:
635 break;
636 }
637
638 return NOTIFY_DONE;
639}
640
641/**
642 * hdd_netdev_notifier_call() - netdev notifier callback function
643 * @nb: pointer to notifier block
644 * @state: state
645 * @ndev: ndev pointer
646 *
647 * Return: 0 on success, error number otherwise.
648 */
649static int hdd_netdev_notifier_call(struct notifier_block *nb,
650 unsigned long state,
651 void *ndev)
652{
653 int ret;
654
655 cds_ssr_protect(__func__);
656 ret = __hdd_netdev_notifier_call(nb, state, ndev);
657 cds_ssr_unprotect(__func__);
658
659 return ret;
660}
661
662struct notifier_block hdd_netdev_notifier = {
663 .notifier_call = hdd_netdev_notifier_call,
664};
665
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530666static int system_reboot_notifier_call(struct notifier_block *nb,
667 unsigned long msg_type, void *_unused)
668{
669 switch (msg_type) {
670 case SYS_DOWN:
671 case SYS_HALT:
672 case SYS_POWER_OFF:
673 g_is_system_reboot_triggered = true;
674 hdd_info("reboot, reason: %ld", msg_type);
675 break;
676 default:
677 break;
678 }
679
680 return NOTIFY_OK;
681}
682
683struct notifier_block system_reboot_notifier = {
684 .notifier_call = system_reboot_notifier_call,
685};
686
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800687/* variable to hold the insmod parameters */
688static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800689
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530690static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700691int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530692
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800693/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800694static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800695
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530696/**
697 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
698 * @ch_width: NL channel width
699 *
700 * Converts the NL channel width to the driver's internal representation
701 *
702 * Return: Converted channel width. In case of non matching NL channel width,
703 * CH_WIDTH_MAX will be returned.
704 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800705enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530706{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800707 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700708
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800709 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530710 switch (ch_width) {
711 case NL80211_CHAN_WIDTH_20_NOHT:
712 case NL80211_CHAN_WIDTH_20:
713 return CH_WIDTH_20MHZ;
714 case NL80211_CHAN_WIDTH_40:
715 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530716 case NL80211_CHAN_WIDTH_80:
717 return CH_WIDTH_80MHZ;
718 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800719 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
720 return CH_WIDTH_80P80MHZ;
721 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
722 return CH_WIDTH_160MHZ;
723 else
724 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530725 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800726 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
727 return CH_WIDTH_160MHZ;
728 else
729 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530730 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800731 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530732 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800733 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530734 default:
735 hdd_err("Invalid channel width %d, setting to default",
736 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800737 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530738 }
739}
740
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530741/* wlan_hdd_find_opclass() - Find operating class for a channel
742 * @hal: handler to HAL
743 * @channel: channel id
744 * @bw_offset: bandwidth offset
745 *
746 * Function invokes sme api to find the operating class
747 *
748 * Return: operating class
749 */
750uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
751 uint8_t bw_offset)
752{
753 uint8_t opclass = 0;
754
755 sme_get_opclass(hal, channel, bw_offset, &opclass);
756 return opclass;
757}
758
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530760 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530761 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800762 * @bitmask: Bitmask of log levels to be enabled
763 *
764 * Called immediately after the cfg.ini is read in order to configure
765 * the desired trace levels.
766 *
767 * Return: None
768 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530769int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800770{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530771 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530772 int qdf_print_idx = -1;
773 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 /*
775 * if the bitmask is the default value, then a bitmask was not
776 * specified in cfg.ini, so leave the logging level alone (it
777 * will remain at the "compiled in" default value)
778 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700779 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530780 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800781
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530782 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530784 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530785 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530786 QDF_TRACE_LEVEL_NONE, 0);
787
788 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530789 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800790 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530791 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792 while (0 != bitmask) {
793 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530794 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530795 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530796 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530797 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800798 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700799
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800 level++;
801 bitmask >>= 1;
802 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530803 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800804}
805
806/**
Chris Guo1751acf2017-07-03 14:09:01 +0800807 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
808 * @hdd_ctx: HDD context pointer
809 *
810 * Return: 0 if the context is valid. Error code otherwise
811 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700812int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800813{
814 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
815 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
816 return -ENODEV;
817 }
818
819 if (cds_is_driver_recovering()) {
820 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
821 (void *)_RET_IP_, cds_get_driver_state());
822 return -EAGAIN;
823 }
824
825 if (hdd_ctx->start_modules_in_progress ||
826 hdd_ctx->stop_modules_in_progress) {
827 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
828 (void *)_RET_IP_);
829 return -EAGAIN;
830 }
831
832 return 0;
833}
834
835
836/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 * wlan_hdd_validate_context() - check the HDD context
838 * @hdd_ctx: HDD context pointer
839 *
840 * Return: 0 if the context is valid. Error code otherwise
841 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700842int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800843{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530845 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800846 return -ENODEV;
847 }
848
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800849 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800850 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530851 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800852 return -EAGAIN;
853 }
854
Yue Ma9f275d92017-09-14 16:58:41 -0700855 if (cds_is_load_or_unload_in_progress()) {
856 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
857 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800858 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700859 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530860
861 if (hdd_ctx->start_modules_in_progress ||
862 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800863 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530864 (void *)_RET_IP_);
865 return -EAGAIN;
866 }
867
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530868 if (cds_is_driver_in_bad_state()) {
869 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
870 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530871 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530872 }
873
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530874 if (cds_is_fw_down()) {
875 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
876 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530877 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530878 }
879
Liangwei Dong858feb12018-05-21 01:52:46 -0400880 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
881 hdd_debug("con_mode_handler is in progress Ignore!!!");
882 return -EAGAIN;
883 }
884
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885 return 0;
886}
887
Jeff Johnson9d295242017-08-29 14:39:48 -0700888int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700889{
890 if (!adapter) {
891 hdd_err("adapter is null");
892 return -EINVAL;
893 }
894
895 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
896 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
897 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
898 return -EINVAL;
899 }
900
901 if (!adapter->dev) {
902 hdd_err("adapter net_device is null");
903 return -EINVAL;
904 }
905
906 if (!(adapter->dev->flags & IFF_UP)) {
907 hdd_info("adapter net_device is not up");
908 return -EAGAIN;
909 }
910
Jeff Johnson1b780e42017-10-31 14:11:45 -0700911 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700912 hdd_info("adapter session is not open");
913 return -EAGAIN;
914 }
915
Jeff Johnson1b780e42017-10-31 14:11:45 -0700916 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
917 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700918 return -EINVAL;
919 }
920
921 return 0;
922}
923
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530925 * wlan_hdd_validate_modules_state() - Check modules status
926 * @hdd_ctx: HDD context pointer
927 *
928 * Check's the driver module's state and returns true if the
929 * modules are enabled returns false if modules are closed.
930 *
931 * Return: True if modules are enabled or false.
932 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700933bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530934{
935 mutex_lock(&hdd_ctx->iface_change_lock);
936 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
937 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700938 hdd_info("Modules not enabled, Present status: %d",
939 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530940 return false;
941 }
942 mutex_unlock(&hdd_ctx->iface_change_lock);
943 return true;
944}
945
946/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800947 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700948 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949 *
950 * This function sets the IBSS power save config parameters to WMA
951 * which will send it to firmware if FW supports IBSS power save
952 * before vdev start.
953 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530954 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955 * on failure.
956 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700957QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958{
959 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700960 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961
962 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700963 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530964 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800965 }
966
Jeff Johnson1b780e42017-10-31 14:11:45 -0700967 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
969 hdd_ctx->config->ibssATIMWinSize,
970 VDEV_CMD);
971 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700972 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530973 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974 }
975
Jeff Johnson1b780e42017-10-31 14:11:45 -0700976 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
978 hdd_ctx->config->isIbssPowerSaveAllowed,
979 VDEV_CMD);
980 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700981 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
982 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530983 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 }
985
Jeff Johnson1b780e42017-10-31 14:11:45 -0700986 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
988 hdd_ctx->config->
989 isIbssPowerCollapseAllowed, VDEV_CMD);
990 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700991 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
992 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530993 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994 }
995
Jeff Johnson1b780e42017-10-31 14:11:45 -0700996 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
998 hdd_ctx->config->isIbssAwakeOnTxRx,
999 VDEV_CMD);
1000 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001001 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301002 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003 }
1004
Jeff Johnson1b780e42017-10-31 14:11:45 -07001005 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001006 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1007 hdd_ctx->config->ibssInactivityCount,
1008 VDEV_CMD);
1009 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001010 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301011 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012 }
1013
Jeff Johnson1b780e42017-10-31 14:11:45 -07001014 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001015 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1016 hdd_ctx->config->ibssTxSpEndInactivityTime,
1017 VDEV_CMD);
1018 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001019 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
1020 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301021 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 }
1023
Jeff Johnson1b780e42017-10-31 14:11:45 -07001024 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001025 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1026 hdd_ctx->config->ibssPsWarmupTime,
1027 VDEV_CMD);
1028 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001029 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
1030 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301031 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032 }
1033
Jeff Johnson1b780e42017-10-31 14:11:45 -07001034 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001035 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1036 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1037 VDEV_CMD);
1038 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001039 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1040 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301041 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001042 }
1043
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301044 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001045}
1046
Yue Macd359b72017-10-03 15:21:00 -07001047#ifdef FEATURE_RUNTIME_PM
1048/**
1049 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1050 * @hdd_ctx: HDD context
1051 *
1052 * Return: None
1053 */
1054static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1055{
1056 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1057
Yue Macd359b72017-10-03 15:21:00 -07001058 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001059 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001060
1061 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1062}
1063
1064/**
1065 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1066 * @hdd_ctx: HDD Context
1067 *
1068 * Return: None
1069 */
1070static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1071{
1072 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1073
Yue Macd359b72017-10-03 15:21:00 -07001074 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001075 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001076
1077 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1078}
1079
Yue Macd359b72017-10-03 15:21:00 -07001080#else /* FEATURE_RUNTIME_PM */
1081static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1082static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001083#endif /* FEATURE_RUNTIME_PM */
1084
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085#define INTF_MACADDR_MASK 0x7
1086
1087/**
1088 * hdd_update_macaddr() - update mac address
1089 * @config: hdd configuration
1090 * @hw_macaddr: mac address
1091 *
1092 * Mac address for multiple virtual interface is found as following
1093 * i) The mac address of the first interface is just the actual hw mac address.
1094 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1095 * define the mac address for the remaining interfaces and locally
1096 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1097 * supported virtual interfaces, right now this is 0x07 (meaning 8
1098 * interface).
1099 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1100 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1101 *
1102 * Return: None
1103 */
1104void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301105 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001106{
1107 int8_t i;
1108 uint8_t macaddr_b3, tmp_br3;
1109
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301110 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301111 QDF_MAC_ADDR_SIZE);
1112 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301113 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301114 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1116 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1117 INTF_MACADDR_MASK;
1118 macaddr_b3 += tmp_br3;
1119
1120 /* XOR-ing bit-24 of the mac address. This will give enough
1121 * mac address range before collision
1122 */
1123 macaddr_b3 ^= (1 << 7);
1124
1125 /* Set locally administered bit */
1126 config->intfMacAddr[i].bytes[0] |= 0x02;
1127 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001128 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 MAC_ADDRESS_STR, i,
1130 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1131 }
1132}
1133
Kabilan Kannan44a58372017-12-06 18:16:11 -08001134static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1135{
1136 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1137 struct tdls_start_params tdls_cfg;
1138 struct tdls_user_config *config = &tdls_cfg.config;
1139 struct hdd_config *cfg = hdd_ctx->config;
1140 QDF_STATUS status;
1141
1142 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1143 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1144 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1145 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1146 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1147 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1148 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1149 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1150 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1151 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1152 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1153 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1154 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1155 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1156 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1157 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1158 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1159 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1160 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1161 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1162 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1163 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1164 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1165 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1166 (cfg->fEnableTDLSImplicitTrigger ?
1167 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1168 (cfg->fTDLSExternalControl ?
1169 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1170 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1171 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1172
1173 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1174 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1175 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1176 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1177 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1178 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1179 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1180 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001181 tdls_cfg.tdls_peer_context = hdd_ctx;
1182 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1183 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001184 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1185 tdls_cfg.tdls_wmm_cb_data = psoc;
1186 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1187 tdls_cfg.tdls_rx_cb_data = psoc;
1188 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1189
1190 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1191 if (status != QDF_STATUS_SUCCESS) {
1192 hdd_err("failed pmo psoc configuration");
1193 return -EINVAL;
1194 }
1195
1196 hdd_ctx->tdls_umac_comp_active = true;
1197 /* enable napier specific tdls data path */
1198 hdd_ctx->tdls_nap_active = true;
1199
1200 return 0;
1201}
1202
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001203static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204 struct wma_tgt_services *cfg)
1205{
1206 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001207
1208 /* Set up UAPSD */
1209 config->apUapsdEnabled &= cfg->uapsd;
1210
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001211 /* 11AX mode support */
1212 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1213 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1214 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1215
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001216 /* 11AC mode support */
1217 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1218 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1219 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001220
1221 /* ARP offload: override user setting if invalid */
1222 config->fhostArpOffload &= cfg->arp_offload;
1223
1224#ifdef FEATURE_WLAN_SCAN_PNO
1225 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001226 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001227 if (cfg->pno_offload)
1228 config->PnoOffload = true;
1229#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001230#ifdef FEATURE_WLAN_TDLS
1231 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301232 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1233 cfg->en_tdls_offchan;
1234 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1235 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001236 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001238 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001239 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1242 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1243#endif
Will Huang496b36c2017-07-11 16:38:50 +08001244 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001245 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001246 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001247 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248
1249}
1250
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001251/**
1252 * hdd_update_vdev_nss() - sets the vdev nss
1253 * @hdd_ctx: HDD context
1254 *
1255 * Sets the Nss per vdev type based on INI
1256 *
1257 * Return: None
1258 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001259static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001260{
1261 struct hdd_config *cfg_ini = hdd_ctx->config;
1262 uint8_t max_supp_nss = 1;
1263
Naveen Rawat10b1c152017-01-18 11:16:06 -08001264 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001265 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001266 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1267 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1268 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001269
1270 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001271 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001272
1273 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001274 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001275}
1276
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301277/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301278 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1279 * @hdd_ctx: HDD context
1280 *
1281 * Updates wiphy vhtcap fields
1282 *
1283 * Return: None
1284 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001285static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301286{
1287 struct ieee80211_supported_band *band_5g =
1288 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1289 uint32_t val;
1290
1291 if (!band_5g) {
1292 hdd_debug("5GHz band disabled, skipping capability population");
1293 return;
1294 }
1295
1296 val = hdd_ctx->config->txBFCsnValue;
1297 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1298
1299 val = NUM_OF_SOUNDING_DIMENSIONS;
1300 band_5g->vht_cap.cap |=
1301 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1302
1303 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1304 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1305}
1306
1307/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301308 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1309 * @hdd_ctx: HDD context
1310 *
1311 * Sets the DBS capability as per INI and firmware capability
1312 *
1313 * Return: None
1314 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001315static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301316{
1317 struct hdd_config *cfg_ini = hdd_ctx->config;
1318 uint8_t hw_dbs_capable = 0;
1319
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001320 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1321 ((cfg_ini->dual_mac_feature_disable ==
1322 ENABLE_DBS_CXN_AND_SCAN) ||
1323 (cfg_ini->dual_mac_feature_disable ==
1324 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301325 hw_dbs_capable = 1;
1326
1327 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1328}
1329
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001330static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001331 struct wma_tgt_ht_cap *cfg)
1332{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301333 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001334 uint32_t value, val32;
1335 uint16_t val16;
1336 struct hdd_config *pconfig = hdd_ctx->config;
1337 tSirMacHTCapabilityInfo *phtCapInfo;
1338 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1339 uint8_t enable_tx_stbc;
1340
1341 /* check and update RX STBC */
1342 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1343 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1344
1345 /* get the MPDU density */
1346 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1347
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301348 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001349 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001350 value = 0;
1351 }
1352
1353 /*
1354 * MPDU density:
1355 * override user's setting if value is larger
1356 * than the one supported by target
1357 */
1358 if (value > cfg->mpdu_density) {
1359 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1360 cfg->mpdu_density);
1361
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301362 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001363 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364 }
1365
1366 /* get the HT capability info */
1367 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301368 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001369 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370 return;
1371 }
1372 val16 = (uint16_t) val32;
1373 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1374
1375 /* Set the LDPC capability */
1376 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1377
1378 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1379 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1380
1381 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1382 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1383
1384 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1385 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1386
1387 enable_tx_stbc = pconfig->enableTxSTBC;
1388
1389 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1390 pconfig->enable2x2 = 1;
1391 } else {
1392 pconfig->enable2x2 = 0;
1393 enable_tx_stbc = 0;
1394
1395 /* 1x1 */
1396 /* Update Rx Highest Long GI data Rate */
1397 if (sme_cfg_set_int(hdd_ctx->hHal,
1398 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001399 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301400 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001401 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402 }
1403
1404 /* Update Tx Highest Long GI data Rate */
1405 if (sme_cfg_set_int
1406 (hdd_ctx->hHal,
1407 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001408 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301409 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001410 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001411 }
1412 }
1413 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1414 enable_tx_stbc = 0;
1415 phtCapInfo->txSTBC = enable_tx_stbc;
1416
1417 val32 = val16;
1418 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301419 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001420 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001421#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1422 value = SIZE_OF_SUPPORTED_MCS_SET;
1423 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301424 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001425 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301426 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1427 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 if (pconfig->enable2x2) {
1429 for (value = 0; value < cfg->num_rf_chains; value++)
1430 mcs_set[value] =
1431 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1432
1433 status =
1434 sme_cfg_set_str(hdd_ctx->hHal,
1435 WNI_CFG_SUPPORTED_MCS_SET,
1436 mcs_set,
1437 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301438 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001439 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 }
1441 }
1442#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1443}
1444
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001445static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001446 struct wma_tgt_vht_cap *cfg)
1447{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301448 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001449 uint32_t value = 0;
1450 struct hdd_config *pconfig = hdd_ctx->config;
1451 struct wiphy *wiphy = hdd_ctx->wiphy;
1452 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001453 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001454 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001455 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001456 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001457 struct wma_caps_per_phy caps_per_phy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458
Dustin Brown5e06bd32016-10-04 12:49:10 -07001459 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001460 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001461 return;
1462 }
1463
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464 /* Get the current MPDU length */
1465 status =
1466 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1467 &value);
1468
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301469 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001470 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001471 value = 0;
1472 }
1473
1474 /*
1475 * VHT max MPDU length:
1476 * override if user configured value is too high
1477 * that the target cannot support
1478 */
1479 if (value > cfg->vht_max_mpdu) {
1480 status = sme_cfg_set_int(hdd_ctx->hHal,
1481 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1482 cfg->vht_max_mpdu);
1483
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001484 if (status == QDF_STATUS_E_FAILURE)
1485 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001486 }
1487
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001488 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1489 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1490
1491 if (pconfig->enable2x2)
1492 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1493
1494 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1495 QDF_STATUS_E_FAILURE) {
1496 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1497 }
1498
1499 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1500 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1501 if (pconfig->enable2x2)
1502 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1503
1504 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1505 QDF_STATUS_E_FAILURE) {
1506 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1507 }
1508
1509 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1510 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1511 if (pconfig->enable2x2)
1512 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1513
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001514 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001515 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1516
1517 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1518 QDF_STATUS_E_FAILURE) {
1519 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1520 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001521 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001522 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001523 &value);
1524
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301525 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001526 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001527 value = 0;
1528 }
1529
jiad4a7a33c2017-08-08 15:32:24 +08001530 /* Set HW RX LDPC capability */
1531 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1532 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001533 status = sme_cfg_set_int(hdd_ctx->hHal,
1534 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001535 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001536
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001537 if (status == QDF_STATUS_E_FAILURE)
1538 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001539 }
1540
1541 /* Get current GI 80 value */
1542 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1543 &value);
1544
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301545 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001546 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001547 value = 0;
1548 }
1549
1550 /* set the Guard interval 80MHz */
1551 if (value && !cfg->vht_short_gi_80) {
1552 status = sme_cfg_set_int(hdd_ctx->hHal,
1553 WNI_CFG_VHT_SHORT_GI_80MHZ,
1554 cfg->vht_short_gi_80);
1555
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001556 if (status == QDF_STATUS_E_FAILURE)
1557 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001558 }
1559
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 /* Get VHT TX STBC cap */
1561 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1562
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301563 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001564 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001565 value = 0;
1566 }
1567
1568 /* VHT TX STBC cap */
1569 if (value && !cfg->vht_tx_stbc) {
1570 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1571 cfg->vht_tx_stbc);
1572
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001573 if (status == QDF_STATUS_E_FAILURE)
1574 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001575 }
1576
1577 /* Get VHT RX STBC cap */
1578 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1579
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301580 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001581 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001582 value = 0;
1583 }
1584
1585 /* VHT RX STBC cap */
1586 if (value && !cfg->vht_rx_stbc) {
1587 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1588 cfg->vht_rx_stbc);
1589
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001590 if (status == QDF_STATUS_E_FAILURE)
1591 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001592 }
1593
1594 /* Get VHT SU Beamformer cap */
1595 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1596 &value);
1597
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301598 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001599 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 value = 0;
1601 }
1602
1603 /* set VHT SU Beamformer cap */
1604 if (value && !cfg->vht_su_bformer) {
1605 status = sme_cfg_set_int(hdd_ctx->hHal,
1606 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1607 cfg->vht_su_bformer);
1608
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001609 if (status == QDF_STATUS_E_FAILURE)
1610 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 }
1612
1613 /* check and update SU BEAMFORMEE capabality */
1614 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1615 pconfig->enableTxBF = cfg->vht_su_bformee;
1616
1617 status = sme_cfg_set_int(hdd_ctx->hHal,
1618 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1619 pconfig->enableTxBF);
1620
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001621 if (status == QDF_STATUS_E_FAILURE)
1622 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623
1624 /* Get VHT MU Beamformer cap */
1625 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1626 &value);
1627
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301628 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001629 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001630 value = 0;
1631 }
1632
1633 /* set VHT MU Beamformer cap */
1634 if (value && !cfg->vht_mu_bformer) {
1635 status = sme_cfg_set_int(hdd_ctx->hHal,
1636 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1637 cfg->vht_mu_bformer);
1638
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001639 if (status == QDF_STATUS_E_FAILURE)
1640 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641 }
1642
1643 /* Get VHT MU Beamformee cap */
1644 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1645 &value);
1646
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301647 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001648 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649 value = 0;
1650 }
1651
1652 /* set VHT MU Beamformee cap */
1653 if (value && !cfg->vht_mu_bformee) {
1654 status = sme_cfg_set_int(hdd_ctx->hHal,
1655 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1656 cfg->vht_mu_bformee);
1657
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001658 if (status == QDF_STATUS_E_FAILURE)
1659 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001660 }
1661
1662 /* Get VHT MAX AMPDU Len exp */
1663 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1664 &value);
1665
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301666 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001667 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001668 value = 0;
1669 }
1670
1671 /*
1672 * VHT max AMPDU len exp:
1673 * override if user configured value is too high
1674 * that the target cannot support.
1675 * Even though Rome publish ampdu_len=7, it can
1676 * only support 4 because of some h/w bug.
1677 */
1678
1679 if (value > cfg->vht_max_ampdu_len_exp) {
1680 status = sme_cfg_set_int(hdd_ctx->hHal,
1681 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1682 cfg->vht_max_ampdu_len_exp);
1683
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001684 if (status == QDF_STATUS_E_FAILURE)
1685 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001686 }
1687
1688 /* Get VHT TXOP PS CAP */
1689 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1690
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301691 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001692 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693 value = 0;
1694 }
1695
1696 /* set VHT TXOP PS cap */
1697 if (value && !cfg->vht_txop_ps) {
1698 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1699 cfg->vht_txop_ps);
1700
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001701 if (status == QDF_STATUS_E_FAILURE)
1702 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001703 }
1704
1705 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1706 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1707 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1708 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1709 else
1710 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1711
1712
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001713 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1714 status = sme_cfg_set_int(hdd_ctx->hHal,
1715 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1716 VHT_CAP_160_AND_80P80_SUPP);
1717 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001718 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719 band_5g->vht_cap.cap |=
1720 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001721 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1722 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1723 status = sme_cfg_set_int(hdd_ctx->hHal,
1724 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1725 VHT_CAP_160_SUPP);
1726 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001727 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001728 band_5g->vht_cap.cap |=
1729 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001730 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1731 }
1732 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1733 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301734 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001735 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301736 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001737 &value);
1738 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301739 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001740 value = 0;
1741 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301742 /* set the Guard interval 160MHz */
1743 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001744 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301745 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1746 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001747
1748 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301749 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001750 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001751
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001752 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001753 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001754 hdd_debug("VHT RxLDPC capability is set");
1755 } else {
1756 /*
1757 * Get the RX LDPC capability for the NON DBS
1758 * hardware mode for 5G band
1759 */
1760 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1761 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1762 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1763 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1764 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1765 hdd_debug("VHT RX LDPC capability is set");
1766 }
1767 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768
1769 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1770 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1771 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1772 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1773
1774 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1775 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1776
1777 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1778 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1779 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1780 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1781 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1782 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1783
1784 band_5g->vht_cap.cap |=
1785 (cfg->vht_max_ampdu_len_exp <<
1786 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1787
1788 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1789 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1790 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1791 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1792 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1793 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1794 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1795 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1796
1797 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1798 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1799
1800}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001801
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001802/**
1803 * hdd_generate_macaddr_auto() - Auto-generate mac address
1804 * @hdd_ctx: Pointer to the HDD context
1805 *
1806 * Auto-generate mac address using device serial number.
1807 * Keep the first 3 bytes of OUI as before and replace
1808 * the last 3 bytes with the lower 3 bytes of serial number.
1809 *
1810 * Return: 0 for success
1811 * Non zero failure code for errors
1812 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001813static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001814{
1815 unsigned int serialno = 0;
1816 struct qdf_mac_addr mac_addr = {
1817 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1818 };
1819
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001820 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001821 if (serialno == 0)
1822 return -EINVAL;
1823
1824 serialno &= 0x00ffffff;
1825
1826 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1827 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1828 mac_addr.bytes[5] = serialno & 0xff;
1829
1830 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1831 return 0;
1832}
1833
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301834/**
1835 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1836 * configuration to cfg_ini in HDD
1837 * @hdd_ctx: Pointer to hdd_ctx
1838 * @cfg: target configuration
1839 *
1840 * Return: None
1841 */
1842#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001843static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301844 struct wma_tgt_cfg *cfg)
1845{
1846 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1847}
1848#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001849static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301850 struct wma_tgt_cfg *cfg)
1851{
1852}
1853#endif
1854
Jeff Johnson8abc5932018-06-02 22:51:37 -07001855void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001857 int ret;
Jeff Johnson8abc5932018-06-02 22:51:37 -07001858 struct hdd_context *hdd_ctx = (struct hdd_context *)hdd_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001859 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001860 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301861 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001862 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301863
Dustin Brownbd68fe12017-11-21 15:28:52 -08001864 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1865 if (ret) {
1866 hdd_err("Failed to create pdev; errno:%d", ret);
1867 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001868 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001869 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001870 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001871 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1872 hdd_err("dispatcher pdev open failed");
1873 QDF_BUG(0);
1874 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301875 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001876
Will Huang07244172018-05-14 14:23:30 +08001877 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1878
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
Nirav Shah73713f72018-05-17 14:50:41 +05302138#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302139/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002140 * __hdd__mon_open() - HDD Open function
2141 * @dev: Pointer to net_device structure
2142 *
2143 * This is called in response to ifconfig up
2144 *
2145 * Return: 0 for success; non-zero for failure
2146 */
2147static int __hdd_mon_open(struct net_device *dev)
2148{
2149 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002150 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2151 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002152
Dustin Brownfdf17c12018-03-14 12:55:34 -07002153 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002154
2155 ret = wlan_hdd_validate_context(hdd_ctx);
2156 if (ret)
2157 return ret;
2158
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302159 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002160
2161 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002162 ret = hdd_wlan_start_modules(hdd_ctx, false);
Ravi Joshia307f632017-07-17 23:41:41 -07002163 if (ret) {
2164 hdd_err("Failed to start WLAN modules return");
2165 return ret;
2166 }
2167 hdd_err("hdd_wlan_start_modules() successful !");
2168
2169 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2170 ret = hdd_start_adapter(adapter);
2171 if (ret) {
2172 hdd_err("Failed to start adapter :%d",
2173 adapter->device_mode);
2174 return ret;
2175 }
2176 hdd_err("hdd_start_adapters() successful !");
2177 }
2178 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2179 }
2180
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002181 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002182
2183 if (!ret)
2184 ret = hdd_enable_monitor_mode(dev);
2185
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002186 return ret;
2187}
2188
2189/**
2190 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2191 * @dev: Pointer to net_device structure
2192 *
2193 * This is called in response to ifconfig up
2194 *
2195 * Return: 0 for success; non-zero for failure
2196 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002197static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002198{
2199 int ret;
2200
2201 cds_ssr_protect(__func__);
2202 ret = __hdd_mon_open(dev);
2203 cds_ssr_unprotect(__func__);
2204
2205 return ret;
2206}
Nirav Shah73713f72018-05-17 14:50:41 +05302207#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002208
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002209static QDF_STATUS
2210wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2211{
2212 struct policy_mgr_dual_mac_config cfg = {0};
2213 QDF_STATUS status;
2214 uint32_t channel_select_logic_conc;
2215 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2216
2217 if (!hdd_ctx) {
2218 hdd_err("HDD context is NULL");
2219 return QDF_STATUS_E_FAILURE;
2220 }
2221
2222
2223 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2224 return QDF_STATUS_SUCCESS;
2225
2226 cfg.scan_config = 0;
2227 cfg.fw_mode_config = 0;
2228 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2229
2230 channel_select_logic_conc = hdd_ctx->config->
2231 channel_select_logic_conc;
2232
2233 if (hdd_ctx->config->dual_mac_feature_disable !=
2234 DISABLE_DBS_CXN_AND_SCAN) {
2235 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2236 hdd_ctx->hdd_psoc, &cfg.scan_config,
2237 &cfg.fw_mode_config,
2238 hdd_ctx->config->dual_mac_feature_disable,
2239 channel_select_logic_conc);
2240
2241 if (status != QDF_STATUS_SUCCESS) {
2242 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2243 status);
2244 return status;
2245 }
2246 }
2247
2248 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2249 cfg.scan_config, cfg.fw_mode_config);
2250
2251 status = sme_soc_set_dual_mac_config(cfg);
2252 if (status != QDF_STATUS_SUCCESS) {
2253 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2254 return status;
2255 }
2256
2257 return QDF_STATUS_SUCCESS;
2258}
2259
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002260/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302261 * hdd_start_adapter() - Wrapper function for device specific adapter
2262 * @adapter: pointer to HDD adapter
2263 *
2264 * This function is called to start the device specific adapter for
2265 * the mode passed in the adapter's device_mode.
2266 *
2267 * Return: 0 for success; non-zero for failure
2268 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002269int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302270{
2271
2272 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002273 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302274
Dustin Brownfdf17c12018-03-14 12:55:34 -07002275 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002276 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302277
2278 switch (device_mode) {
2279 case QDF_P2P_CLIENT_MODE:
2280 case QDF_P2P_DEVICE_MODE:
2281 case QDF_OCB_MODE:
2282 case QDF_STA_MODE:
2283 case QDF_MONITOR_MODE:
2284 ret = hdd_start_station_adapter(adapter);
2285 if (ret)
2286 goto err_start_adapter;
2287 break;
2288 case QDF_P2P_GO_MODE:
2289 case QDF_SAP_MODE:
2290 ret = hdd_start_ap_adapter(adapter);
2291 if (ret)
2292 goto err_start_adapter;
2293 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302294 case QDF_IBSS_MODE:
2295 /*
2296 * For IBSS interface is initialized as part of
2297 * hdd_init_station_mode()
2298 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002299 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302300 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002301 /* vdevs are dynamically managed by firmware in FTM */
2302 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302303 default:
2304 hdd_err("Invalid session type %d", device_mode);
2305 QDF_ASSERT(0);
2306 goto err_start_adapter;
2307 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002308
Arun Khandavallifae92942016-08-01 13:31:08 +05302309 if (hdd_set_fw_params(adapter))
2310 hdd_err("Failed to set the FW params for the adapter!");
2311
Dustin Browne7e71d32018-05-11 16:00:08 -07002312 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2313 ret = wlan_hdd_cfg80211_register_frames(adapter);
2314 if (ret < 0) {
2315 hdd_err("Failed to register frames - ret %d", ret);
2316 goto err_start_adapter;
2317 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302318 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002319
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002320 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302321
Dustin Browndb2a8be2017-12-20 11:49:56 -08002322exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002323 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002324
Arun Khandavallifae92942016-08-01 13:31:08 +05302325 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002326
Arun Khandavallifae92942016-08-01 13:31:08 +05302327err_start_adapter:
2328 return -EINVAL;
2329}
2330
2331/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302332 * hdd_enable_power_management() - API to Enable Power Management
2333 *
2334 * API invokes Bus Interface Layer power management functionality
2335 *
2336 * Return: None
2337 */
2338static void hdd_enable_power_management(void)
2339{
2340 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2341
2342 if (!hif_ctx) {
2343 hdd_err("Bus Interface Context is Invalid");
2344 return;
2345 }
2346
2347 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2348}
2349
2350/**
2351 * hdd_disable_power_management() - API to disable Power Management
2352 *
2353 * API disable Bus Interface Layer Power management functionality
2354 *
2355 * Return: None
2356 */
2357static void hdd_disable_power_management(void)
2358{
2359 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2360
2361 if (!hif_ctx) {
2362 hdd_err("Bus Interface Context is Invalid");
2363 return;
2364 }
2365
2366 hif_disable_power_management(hif_ctx);
2367}
2368
Ryan Hsuaadba072018-04-20 13:01:53 -07002369void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302370{
2371 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002372 size_t target_hw_name_len;
2373 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002374 uint8_t *buf;
2375 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302376
2377 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2378 if (!hif_sc) {
2379 hdd_err("HIF context is NULL");
2380 return;
2381 }
2382
Ryan Hsuaadba072018-04-20 13:01:53 -07002383 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302384 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002385 &target_hw_name);
2386
2387 if (hdd_ctx->target_hw_name)
2388 qdf_mem_free(hdd_ctx->target_hw_name);
2389
2390 target_hw_name_len = strlen(target_hw_name) + 1;
2391 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2392 if (hdd_ctx->target_hw_name)
2393 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2394 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302395
Ryan Hsuaadba072018-04-20 13:01:53 -07002396 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2397 if (buf) {
2398 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2399 hdd_info("%s", buf);
2400 qdf_mem_free(buf);
2401 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302402}
2403
2404/**
gbian62edd7e2017-03-07 13:12:13 +08002405 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2406 * @hdd_ctx: Pointer to hdd context
2407 *
2408 * Return: none
2409 */
2410static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002411hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002412{
2413 uint8_t num_entries = 0;
2414 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2415 uint8_t *tx_sched_wrr_ac;
2416 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002417 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002418
2419 if (NULL == hdd_ctx)
2420 return;
2421
2422 if (NULL == hdd_ctx->config) {
2423 /* Do nothing if hdd_ctx is invalid */
2424 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2425 return;
2426 }
2427
2428 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2429
2430 if (!cds_ctx) {
2431 hdd_err("Invalid CDS Context");
2432 return;
2433 }
2434
2435 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2436 switch (i) {
2437 case OL_TX_WMM_AC_BE:
2438 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2439 break;
2440 case OL_TX_WMM_AC_BK:
2441 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2442 break;
2443 case OL_TX_WMM_AC_VI:
2444 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2445 break;
2446 case OL_TX_WMM_AC_VO:
2447 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2448 break;
2449 default:
2450 tx_sched_wrr_ac = NULL;
2451 break;
2452 }
2453
2454 hdd_string_to_u8_array(tx_sched_wrr_ac,
2455 tx_sched_wrr_param,
2456 &num_entries,
2457 sizeof(tx_sched_wrr_param));
2458
2459 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2460 cds_ctx->ac_specs[i].wrr_skip_weight =
2461 tx_sched_wrr_param[0];
2462 cds_ctx->ac_specs[i].credit_threshold =
2463 tx_sched_wrr_param[1];
2464 cds_ctx->ac_specs[i].send_limit =
2465 tx_sched_wrr_param[2];
2466 cds_ctx->ac_specs[i].credit_reserve =
2467 tx_sched_wrr_param[3];
2468 cds_ctx->ac_specs[i].discard_weight =
2469 tx_sched_wrr_param[4];
2470 }
2471
2472 num_entries = 0;
2473 }
2474}
2475
Ryan Hsuaadba072018-04-20 13:01:53 -07002476uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2477 const size_t version_len, uint8_t *version)
2478{
2479 uint32_t size;
2480 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2481
2482 if (!hdd_ctx) {
2483 hdd_err("Invalid context, HDD context is null");
2484 return 0;
2485 }
2486
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302487 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002488 hdd_err("Invalid buffer pointr or buffer len\n");
2489 return 0;
2490 }
2491
2492 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2493 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2494 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2495 crmid = hdd_ctx->target_fw_version & 0x7fff;
2496 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2497
2498 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002499 "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 -07002500 QWLAN_VERSIONSTR,
2501 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002502 hdd_ctx->target_hw_name,
2503 hdd_ctx->hw_bd_info.bdf_version,
2504 hdd_ctx->hw_bd_info.ref_design_id,
2505 hdd_ctx->hw_bd_info.customer_id,
2506 hdd_ctx->hw_bd_info.project_id,
2507 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002508
2509 return size;
2510}
2511
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302512#ifdef IPA_OFFLOAD
2513/**
2514 * hdd_update_ipa_component_config() - update ipa config
2515 * @hdd_ctx: Pointer to hdd context
2516 *
2517 * Return: none
2518 */
2519static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2520{
2521 struct hdd_config *cfg = hdd_ctx->config;
2522 struct wlan_ipa_config ipa_cfg;
2523
2524 ipa_cfg.ipa_config = cfg->IpaConfig;
2525 ipa_cfg.desc_size = cfg->IpaDescSize;
2526 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2527 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2528 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2529 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2530 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2531 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2532 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2533
2534 ucfg_ipa_update_config(&ipa_cfg);
2535}
2536#else
2537static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2538{
2539}
2540#endif
2541
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002542#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002543static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2544 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2545{
Jeff Johnson9d295242017-08-29 14:39:48 -07002546 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002547 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002548
2549 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2550 if (!adapter) {
2551 hdd_err("Adapter is NULL");
2552 return PM_MAX_NUM_OF_MODE;
2553 }
2554
2555 return policy_mgr_convert_device_mode_to_qdf_type(
2556 adapter->device_mode);
2557}
2558
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002559static void hdd_register_policy_manager_callback(
2560 struct wlan_objmgr_psoc *psoc)
2561{
2562 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002563
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002564 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002565 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002566 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2567 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002568 hdd_cbacks.get_mode_for_non_connected_vdev =
2569 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302570 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002571
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002572 if (QDF_STATUS_SUCCESS !=
2573 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2574 hdd_err("HDD callback registration with policy manager failed");
2575 }
2576}
2577#else
2578static void hdd_register_policy_manager_callback(
2579 struct wlan_objmgr_psoc *psoc)
2580{
2581}
2582#endif
2583
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002584static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002585{
2586 struct nan_callbacks cb_obj = {0};
2587
2588 cb_obj.ndi_open = hdd_ndi_open;
2589 cb_obj.ndi_close = hdd_ndi_close;
2590 cb_obj.ndi_start = hdd_ndi_start;
2591 cb_obj.ndi_delete = hdd_ndi_delete;
2592 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2593 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2594
Naveen Rawat37f62c82017-03-26 22:24:43 -07002595 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2596 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002597 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002598
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002599 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2600}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002601
Dustin Brown26b3d042017-12-21 11:13:27 -08002602#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002603/**
2604 * hdd_check_for_leaks() - Perform runtime memory leak checks
2605 *
2606 * This API triggers runtime memory leak detection. This feature enforces the
2607 * policy that any memory allocated at runtime must also be released at runtime.
2608 *
2609 * Allocating memory at runtime and releasing it at unload is effectively a
2610 * memory leak for configurations which never unload (e.g. LONU, statically
2611 * compiled driver). Such memory leaks are NOT false positives, and must be
2612 * fixed.
2613 *
2614 * Return: None
2615 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002616static void hdd_check_for_leaks(void)
2617{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002618 /* DO NOT REMOVE these checks; for false positives, read above first */
2619
Dustin Brown677e0862017-10-10 16:30:09 -07002620 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002621 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002622 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002623}
2624
Dustin Brown26b3d042017-12-21 11:13:27 -08002625#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2626#else
2627static inline void hdd_check_for_leaks(void) {}
2628
2629#define hdd_debug_domain_set(domain)
2630#endif /* CONFIG_LEAK_DETECTION */
2631
gbian62edd7e2017-03-07 13:12:13 +08002632/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002633 * hdd_update_country_code - Update country code
2634 * @hdd_ctx: HDD context
2635 *
2636 * Update country code based on module parameter country_code
2637 *
2638 * Return: 0 on success and errno on failure
2639 */
2640static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2641{
2642 if (!country_code)
2643 return 0;
2644
2645 return hdd_reg_set_country(hdd_ctx, country_code);
2646}
2647
2648/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302649 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2650 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05302651 * @reinit: flag to indicate from SSR or normal path
2652 *
2653 * This function maintains the driver state machine it will be invoked from
2654 * startup, reinit and change interface. Depending on the driver state shall
2655 * perform the opening of the modules.
2656 *
2657 * Return: 0 for success; non-zero for failure
2658 */
Dustin Browne7e71d32018-05-11 16:00:08 -07002659int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302660{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002661 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302662 qdf_device_t qdf_dev;
2663 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302664 bool unint = false;
2665 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002666 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302667
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002668 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302669
2670 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2671 if (!qdf_dev) {
2672 hdd_err("QDF Device Context is Invalid return");
2673 return -EINVAL;
2674 }
2675
Dustin Brown6f427922017-09-19 12:19:00 -07002676 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302677
Dustin Brown1fe30a82017-10-03 16:13:36 -07002678 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302679 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2680 mutex_unlock(&hdd_ctx->iface_change_lock);
2681 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002682 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302683 return 0;
2684 }
2685
Dustin Brown1fe30a82017-10-03 16:13:36 -07002686 hdd_ctx->start_modules_in_progress = true;
2687
Arun Khandavallifae92942016-08-01 13:31:08 +05302688 switch (hdd_ctx->driver_status) {
2689 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002690 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302691 unint = true;
2692 /* Fall through dont add break here */
2693 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002694 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2695
Dustin Brown26b3d042017-12-21 11:13:27 -08002696 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002697
Arun Khandavallifae92942016-08-01 13:31:08 +05302698 if (!reinit && !unint) {
2699 ret = pld_power_on(qdf_dev->dev);
2700 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002701 hdd_err("Failed to Powerup the device; errno: %d",
2702 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302703 goto release_lock;
2704 }
2705 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002706
2707 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2708 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302709 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2710 qdf_dev->bus_type,
2711 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2712 HIF_ENABLE_TYPE_PROBE);
2713 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002714 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302715 goto power_down;
2716 }
2717
2718 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302719 if (!hif_ctx) {
2720 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002721 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302722 goto power_down;
2723 }
2724
Arun Khandavallifae92942016-08-01 13:31:08 +05302725 status = ol_cds_init(qdf_dev, hif_ctx);
2726 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002727 hdd_err("No Memory to Create BMI Context; status: %d",
2728 status);
2729 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302730 goto hif_close;
2731 }
2732
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302733 hdd_update_ipa_component_config(hdd_ctx);
2734
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002735 ret = hdd_update_config(hdd_ctx);
2736 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002737 hdd_err("Failed to update configuration; errno: %d",
2738 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002739 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002740 }
2741
gbian62edd7e2017-03-07 13:12:13 +08002742 hdd_update_cds_ac_specs_params(hdd_ctx);
2743
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302744 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002745 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002746 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002747 ret = qdf_status_to_os_return(status);
2748 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302749 }
2750
Jeff Johnson79e36882018-05-06 17:15:33 -07002751 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302752 ret = hdd_update_components_config(hdd_ctx);
2753 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002754 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302755 ret);
2756 goto close;
2757 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002758 status = cds_dp_open(hdd_ctx->hdd_psoc);
2759 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002760 hdd_err("Failed to Open cds post open; status: %d",
2761 status);
2762 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002763 goto close;
2764 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302765
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002766 /*
2767 * NAN compoenet requires certian operations like, open adapter,
2768 * close adapter, etc. to be initiated by HDD, for those
2769 * register HDD callbacks with UMAC's NAN componenet.
2770 */
2771 hdd_nan_register_callbacks(hdd_ctx);
2772
Arun Khandavallifae92942016-08-01 13:31:08 +05302773 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2774
Jeff Johnson3a280122017-09-13 07:42:00 -07002775 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302776 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002777 hdd_err("Failed to pre-enable CDS; status: %d", status);
2778 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002779 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302780 }
2781
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002782 hdd_register_policy_manager_callback(
2783 hdd_ctx->hdd_psoc);
2784
Amar Singhal0928b192017-12-01 10:50:54 -08002785 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2786
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302787 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302788 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002789 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302790
Arun Khandavallifae92942016-08-01 13:31:08 +05302791 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002792 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302793 break;
2794 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302795
Arun Khandavallifae92942016-08-01 13:31:08 +05302796 /* Fall through dont add break here */
2797 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002798 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2799
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302800 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2801 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002802 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302803 break;
2804 }
Dustin Browndca39692017-11-09 15:30:25 -08002805
Dustin Browne7e71d32018-05-11 16:00:08 -07002806 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002807 if (ret) {
2808 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002809 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302810 }
Dustin Browndca39692017-11-09 15:30:25 -08002811
Komal Seelamf2136bb2016-09-28 18:30:44 +05302812 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002813
Arun Khandavallifae92942016-08-01 13:31:08 +05302814 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002815 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302816 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002817
Arun Khandavallifae92942016-08-01 13:31:08 +05302818 default:
2819 hdd_err("WLAN start invoked in wrong state! :%d\n",
2820 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002821 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302822 goto release_lock;
2823 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002824
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302825 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002826 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2827 ret = hdd_update_country_code(hdd_ctx);
2828 if (ret)
2829 hdd_err("Failed to update command line country code!");
2830 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302831 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002832
Dustin Browne74003f2018-03-14 12:51:58 -07002833 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002834
Arun Khandavallifae92942016-08-01 13:31:08 +05302835 return 0;
2836
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002837post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002838 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002839
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002840cds_txrx_free:
Jingxiang Ge95912f82018-04-19 12:01:26 +08002841 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
2842
2843 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2844 hdd_runtime_suspend_context_deinit(hdd_ctx);
2845 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
2846 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2847 }
2848
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002849 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002850
Arun Khandavallifae92942016-08-01 13:31:08 +05302851close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002852 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002853 hdd_info("Wlan transition aborted (now CLOSED)");
2854
Jeff Johnsone4b14592017-09-13 14:23:33 -07002855 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302856
Dustin Brown28b17892017-10-10 13:29:38 -07002857deinit_config:
2858 cds_deinit_ini_config();
2859
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002860cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302861 ol_cds_free();
2862
2863hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002864 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2865 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302866power_down:
2867 if (!reinit && !unint)
2868 pld_power_off(qdf_dev->dev);
2869release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302870 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302871 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05302872 if (hdd_ctx->target_hw_name) {
2873 qdf_mem_free(hdd_ctx->target_hw_name);
2874 hdd_ctx->target_hw_name = NULL;
2875 }
Dustin Brown4bc0a622017-12-06 15:56:50 -08002876 /* many adapter resources are not freed by design in SSR case */
2877 if (!reinit)
2878 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002879 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002880
Dustin Browne74003f2018-03-14 12:51:58 -07002881 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002882
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002883 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302884}
2885
Naveen Rawat910726a2017-03-06 11:42:51 -08002886#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002887static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002888{
2889 int ret = os_if_wifi_pos_register_nl();
2890
2891 if (ret)
2892 hdd_err("os_if_wifi_pos_register_nl failed");
2893
2894 return ret;
2895}
2896
2897static int hdd_deactivate_wifi_pos(void)
2898{
2899 int ret = os_if_wifi_pos_deregister_nl();
2900
2901 if (ret)
2902 hdd_err("os_if_wifi_pos_deregister_nl failed");
2903
2904 return ret;
2905}
2906
2907/**
2908 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2909 * @hdd_ctx: hdd context
2910 *
2911 * Return: status of operation
2912 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002913static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002914{
2915 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2916 struct hdd_config *cfg = hdd_ctx->config;
2917
2918 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2919 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2920 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2921 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2922 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2923 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2924 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2925 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2926}
2927#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002928static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002929{
2930 return oem_activate_service(hdd_ctx);
2931}
2932
2933static int hdd_deactivate_wifi_pos(void)
2934{
2935 return 0;
2936}
2937
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002938static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002939{
2940}
2941#endif
2942
Arun Khandavallifae92942016-08-01 13:31:08 +05302943/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002944 * __hdd_open() - HDD Open function
2945 * @dev: Pointer to net_device structure
2946 *
2947 * This is called in response to ifconfig up
2948 *
2949 * Return: 0 for success; non-zero for failure
2950 */
2951static int __hdd_open(struct net_device *dev)
2952{
Jeff Johnson9d295242017-08-29 14:39:48 -07002953 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002954 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002955 int ret;
2956
Dustin Brownfdf17c12018-03-14 12:55:34 -07002957 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302958 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002959 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002960
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302961 /* Nothing to be done if device is unloading */
2962 if (cds_is_driver_unloading()) {
2963 hdd_err("Driver is unloading can not open the hdd");
2964 return -EBUSY;
2965 }
2966
Dustin Brown01847752017-10-25 13:56:27 -07002967 if (cds_is_driver_recovering()) {
2968 hdd_err("WLAN is currently recovering; Please try again.");
2969 return -EBUSY;
2970 }
2971
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302972 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2973 hdd_err("con_mode_handler is in progress; Please try again.");
2974 return -EBUSY;
2975 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302976
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302977 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302978 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2979
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302980 /*
2981 * This scenario can be hit in cases where in the wlan driver after
2982 * registering the netdevices and there is a failure in driver
2983 * initialization. So return error gracefully because the netdevices
2984 * will be de-registered as part of the load failure.
2985 */
2986
2987 if (!cds_is_driver_loaded()) {
2988 hdd_err("Failed to start the wlan driver!!");
2989 ret = -EIO;
2990 goto err_hdd_hdd_init_deinit_lock;
2991 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302992
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993
Dustin Browne7e71d32018-05-11 16:00:08 -07002994 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302995 if (ret) {
2996 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302997 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302998 }
2999
3000
3001 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3002 ret = hdd_start_adapter(adapter);
3003 if (ret) {
3004 hdd_err("Failed to start adapter :%d",
3005 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303006 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303007 }
3008 }
3009
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003010 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3011 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003012 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013 /* Enable TX queues only when we are connected */
3014 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303015 WLAN_START_ALL_NETIF_QUEUE,
3016 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003017 }
3018
Naveen Rawat286def52016-09-23 15:38:02 -07003019 /* Enable carrier and transmit queues for NDI */
3020 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003021 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003022 wlan_hdd_netif_queue_control(adapter,
3023 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3024 WLAN_CONTROL_PATH);
3025 }
3026
Naveen Rawat910726a2017-03-06 11:42:51 -08003027 hdd_populate_wifi_pos_cfg(hdd_ctx);
3028
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303029err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303030 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303031 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003032 return ret;
3033}
3034
Arun Khandavallifae92942016-08-01 13:31:08 +05303035
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003036/**
3037 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3038 * @dev: Pointer to net_device structure
3039 *
3040 * This is called in response to ifconfig up
3041 *
3042 * Return: 0 for success; non-zero for failure
3043 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003044static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003045{
3046 int ret;
3047
3048 cds_ssr_protect(__func__);
3049 ret = __hdd_open(dev);
3050 cds_ssr_unprotect(__func__);
3051
3052 return ret;
3053}
3054
3055/**
3056 * __hdd_stop() - HDD stop function
3057 * @dev: Pointer to net_device structure
3058 *
3059 * This is called in response to ifconfig down
3060 *
3061 * Return: 0 for success; non-zero for failure
3062 */
3063static int __hdd_stop(struct net_device *dev)
3064{
Jeff Johnson9d295242017-08-29 14:39:48 -07003065 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003066 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003067 int ret;
3068
Dustin Brownfdf17c12018-03-14 12:55:34 -07003069 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003070
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303071 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003072 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003073
3074 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303075 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003076 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003077
3078 /* Nothing to be done if the interface is not opened */
3079 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003080 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003081 return -ENODEV;
3082 }
3083
3084 /* Make sure the interface is marked as closed */
3085 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303086
3087 hdd_debug("Disabling Auto Power save timer");
3088 sme_ps_disable_auto_ps_timer(
3089 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07003090 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303091
3092 /*
3093 * Disable TX on the interface, after this hard_start_xmit() will not
3094 * be called on that interface
3095 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003096 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003097 hdd_device_mode_to_string(adapter->device_mode),
3098 adapter->device_mode);
3099
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303100 wlan_hdd_netif_queue_control(adapter,
3101 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3102 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003103
3104 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003105 * NAN data interface is different in some sense. The traffic on NDI is
3106 * bursty in nature and depends on the need to transfer. The service
3107 * layer may down the interface after the usage and up again when
3108 * required. In some sense, the NDI is expected to be available
3109 * (like SAP) iface until NDI delete request is issued by the service
3110 * layer. Skip BSS termination and adapter deletion for NAN Data
3111 * interface (NDI).
3112 */
3113 if (WLAN_HDD_IS_NDI(adapter))
3114 return 0;
3115
3116 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003117 * The interface is marked as down for outside world (aka kernel)
3118 * But the driver is pretty much alive inside. The driver needs to
3119 * tear down the existing connection on the netdev (session)
3120 * cleanup the data pipes and wait until the control plane is stabilized
3121 * for this interface. The call also needs to wait until the above
3122 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003123 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124 * That is intentional to be able to scan if it is a STA/P2P interface
3125 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003126 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127
3128 /* DeInit the adapter. This ensures datapath cleanup as well */
3129 hdd_deinit_adapter(hdd_ctx, adapter, true);
3130
Arun Khandavallifae92942016-08-01 13:31:08 +05303131
3132 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303133 * Upon wifi turn off, DUT has to flush the scan results so if
3134 * this is the last cli iface, flush the scan database.
3135 */
3136 if (!hdd_is_cli_iface_up(hdd_ctx))
3137 sme_scan_flush_result(hdd_ctx->hHal);
3138
3139 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303140 * Find if any iface is up. If any iface is up then can't put device to
3141 * sleep/power save mode
3142 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303143 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003144 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003145 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3146 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303147 hdd_prevent_suspend_timeout(
3148 hdd_ctx->config->iface_change_wait_time,
3149 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303150 }
3151
Dustin Browne74003f2018-03-14 12:51:58 -07003152 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153 return 0;
3154}
3155
3156/**
3157 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3158 * @dev: pointer to net_device structure
3159 *
3160 * This is called in response to ifconfig down
3161 *
3162 * Return: 0 for success and error number for failure
3163 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003164static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003165{
3166 int ret;
3167
3168 cds_ssr_protect(__func__);
3169 ret = __hdd_stop(dev);
3170 cds_ssr_unprotect(__func__);
3171
3172 return ret;
3173}
3174
3175/**
3176 * __hdd_uninit() - HDD uninit function
3177 * @dev: Pointer to net_device structure
3178 *
3179 * This is called during the netdev unregister to uninitialize all data
3180 * associated with the device
3181 *
3182 * Return: None
3183 */
3184static void __hdd_uninit(struct net_device *dev)
3185{
Jeff Johnson9d295242017-08-29 14:39:48 -07003186 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003187 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188
Dustin Brownfdf17c12018-03-14 12:55:34 -07003189 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190
3191 do {
3192 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003193 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194 break;
3195 }
3196
Jeff Johnson399c6272017-08-30 10:51:00 -07003197 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3198 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003199 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200 break;
3201 }
3202
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003203 if (dev != adapter->dev)
3204 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205
Jeff Johnson399c6272017-08-30 10:51:00 -07003206 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003207
3208 /* after uninit our adapter structure will no longer be valid */
3209 adapter->dev = NULL;
3210 adapter->magic = 0;
3211 } while (0);
3212
Dustin Browne74003f2018-03-14 12:51:58 -07003213 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003214}
3215
3216/**
3217 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3218 * @dev: pointer to net_device structure
3219 *
3220 * This is called during the netdev unregister to uninitialize all data
3221 * associated with the device
3222 *
3223 * Return: none
3224 */
3225static void hdd_uninit(struct net_device *dev)
3226{
3227 cds_ssr_protect(__func__);
3228 __hdd_uninit(dev);
3229 cds_ssr_unprotect(__func__);
3230}
3231
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003232static int hdd_open_cesium_nl_sock(void)
3233{
3234#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3235 struct netlink_kernel_cfg cfg = {
3236 .groups = WLAN_NLINK_MCAST_GRP_ID,
3237 .input = NULL
3238 };
3239#endif
3240 int ret = 0;
3241
3242#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3243 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3244#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3245 THIS_MODULE,
3246#endif
3247 &cfg);
3248#else
3249 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3250 WLAN_NLINK_MCAST_GRP_ID,
3251 NULL, NULL, THIS_MODULE);
3252#endif
3253
3254 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003255 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003256 ret = -ECONNREFUSED;
3257 }
3258
3259 return ret;
3260}
3261
3262static void hdd_close_cesium_nl_sock(void)
3263{
3264 if (NULL != cesium_nl_srv_sock) {
3265 netlink_kernel_release(cesium_nl_srv_sock);
3266 cesium_nl_srv_sock = NULL;
3267 }
3268}
3269
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270/**
3271 * __hdd_set_mac_address() - set the user specified mac address
3272 * @dev: Pointer to the net device.
3273 * @addr: Pointer to the sockaddr.
3274 *
3275 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003276 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003277 *
3278 * Return: 0 for success, non zero for failure
3279 */
3280static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3281{
Jeff Johnson9d295242017-08-29 14:39:48 -07003282 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003283 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303285 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303287 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288
Dustin Brownfdf17c12018-03-14 12:55:34 -07003289 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003290
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303291 if (netif_running(dev)) {
3292 hdd_err("On iface up, set mac address change isn't supported");
3293 return -EBUSY;
3294 }
3295
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003296 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3297 ret = wlan_hdd_validate_context(hdd_ctx);
3298 if (0 != ret)
3299 return ret;
3300
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303301 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
3302
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303303 if (hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes)) {
3304 hdd_err("adapter exist with same mac address " MAC_ADDRESS_STR,
3305 MAC_ADDR_ARRAY(mac_addr.bytes));
3306 return -EINVAL;
3307 }
3308
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303309 if (qdf_is_macaddr_zero(&mac_addr)) {
3310 hdd_err("MAC is all zero");
3311 return -EINVAL;
3312 }
3313
3314 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3315 hdd_err("MAC is Broadcast");
3316 return -EINVAL;
3317 }
3318
3319 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3320 hdd_err("MAC is Multicast");
3321 return -EINVAL;
3322 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303323 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3324 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303325
Jeff Johnson1e851a12017-10-28 14:36:12 -07003326 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003327 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3328
Dustin Browne74003f2018-03-14 12:51:58 -07003329 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303330 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003331}
3332
3333/**
3334 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3335 * function from SSR
3336 * @dev: pointer to net_device structure
3337 * @addr: Pointer to the sockaddr
3338 *
3339 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003340 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341 *
3342 * Return: 0 for success.
3343 */
3344static int hdd_set_mac_address(struct net_device *dev, void *addr)
3345{
3346 int ret;
3347
3348 cds_ssr_protect(__func__);
3349 ret = __hdd_set_mac_address(dev, addr);
3350 cds_ssr_unprotect(__func__);
3351
3352 return ret;
3353}
3354
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003355uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356{
3357 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003358
Anurag Chouhan6d760662016-02-20 16:05:43 +05303359 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3361 break;
3362 }
3363
Anurag Chouhan6d760662016-02-20 16:05:43 +05303364 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003365 return NULL;
3366
3367 hdd_ctx->config->intfAddrMask |= (1 << i);
3368 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3369}
3370
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003371void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3372 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373{
3374 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003375
Anurag Chouhan6d760662016-02-20 16:05:43 +05303376 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003377 if (!memcmp(releaseAddr,
3378 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3379 6)) {
3380 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3381 break;
3382 }
3383 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003384}
3385
3386#ifdef WLAN_FEATURE_PACKET_FILTERING
3387/**
3388 * __hdd_set_multicast_list() - set the multicast address list
3389 * @dev: Pointer to the WLAN device.
3390 * @skb: Pointer to OS packet (sk_buff).
3391 *
3392 * This funciton sets the multicast address list.
3393 *
3394 * Return: None
3395 */
3396static void __hdd_set_multicast_list(struct net_device *dev)
3397{
Jeff Johnson9d295242017-08-29 14:39:48 -07003398 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003399 int i = 0, status;
3400 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003401 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303402 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3403 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3404 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405
Dustin Brownfdf17c12018-03-14 12:55:34 -07003406 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303407 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303408 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303409
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303411 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303412 goto out;
3413
Dustin Brownc788acb2017-08-01 17:43:51 -07003414 status = hdd_validate_adapter(adapter);
3415 if (status)
3416 goto out;
3417
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303418 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3419 hdd_err("%s: Driver module is closed", __func__);
3420 return;
3421 }
3422
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303423 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3424 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003425 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303426 goto out;
3427 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003428
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303429 /* Delete already configured multicast address list */
3430 if (adapter->mc_addr_list.mc_cnt > 0) {
3431 hdd_info("clear previously configured MC address list");
3432 hdd_disable_and_flush_mc_addr_list(adapter,
3433 pmo_mc_list_change_notify);
3434 }
3435
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003437 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303438 hdd_disable_and_flush_mc_addr_list(adapter,
3439 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440 } else {
3441 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303442 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003443 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303444 pmo_ucfg_max_mc_addr_supported(psoc));
3445 hdd_disable_and_flush_mc_addr_list(adapter,
3446 pmo_mc_list_change_notify);
3447 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003448 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003450 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303451 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 if (i == mc_count)
3453 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303454 memset(&(mc_list_request->mc_addr[i].bytes),
3455 0, ETH_ALEN);
3456 memcpy(&(mc_list_request->mc_addr[i].bytes),
3457 ha->addr, ETH_ALEN);
3458 hdd_info("mlist[%d] = %pM", i,
3459 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 i++;
3461 }
3462 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303463
3464 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003465 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303466 mc_list_request->count = mc_count;
3467 status = hdd_cache_mc_addr_list(mc_list_request);
3468 if (status == 0) {
3469 hdd_enable_mc_addr_filtering(adapter,
3470 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303472 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303474out:
3475 if (mc_list_request)
3476 qdf_mem_free(mc_list_request);
Dustin Browne74003f2018-03-14 12:51:58 -07003477 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478}
3479
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303480
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003481/**
3482 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3483 * @dev: pointer to net_device
3484 *
3485 * Return: none
3486 */
3487static void hdd_set_multicast_list(struct net_device *dev)
3488{
3489 cds_ssr_protect(__func__);
3490 __hdd_set_multicast_list(dev);
3491 cds_ssr_unprotect(__func__);
3492}
3493#endif
3494
3495/**
3496 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3497 * @dev: Pointer to the WLAN device.
3498 * @skb: Pointer to OS packet (sk_buff).
3499 *
3500 * This function is registered with the Linux OS for network
3501 * core to decide which queue to use first.
3502 *
3503 * Return: ac, Queue Index/access category corresponding to UP in IP header
3504 */
3505static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3506#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3507 , void *accel_priv
3508#endif
3509#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3510 , select_queue_fallback_t fallback
3511#endif
3512)
3513{
3514 return hdd_wmm_select_queue(dev, skb);
3515}
3516
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003517static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 .ndo_open = hdd_open,
3519 .ndo_stop = hdd_stop,
3520 .ndo_uninit = hdd_uninit,
3521 .ndo_start_xmit = hdd_hard_start_xmit,
3522 .ndo_tx_timeout = hdd_tx_timeout,
3523 .ndo_get_stats = hdd_get_stats,
3524 .ndo_do_ioctl = hdd_ioctl,
3525 .ndo_set_mac_address = hdd_set_mac_address,
3526 .ndo_select_queue = hdd_select_queue,
3527#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003529#endif
3530};
3531
Nirav Shah73713f72018-05-17 14:50:41 +05303532#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003533/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003534static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003535 .ndo_open = hdd_mon_open,
3536 .ndo_stop = hdd_stop,
3537 .ndo_get_stats = hdd_get_stats,
3538};
3539
3540/**
3541 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003542 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003543 * Return: None
3544 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003545void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003546{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003547 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003548 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003549 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003550 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003551}
Nirav Shah73713f72018-05-17 14:50:41 +05303552#else
3553void hdd_set_station_ops(struct net_device *dev)
3554{
3555 dev->netdev_ops = &wlan_drv_ops;
3556}
3557#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003558
3559/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003560 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3561 * @hdd_ctx: global hdd context
3562 * @macAddr: mac address to assign to the interface
3563 * @name: User-visible name of the interface
3564 *
3565 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003566 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003567 *
3568 * Return: the pointer to hdd adapter, otherwise NULL
3569 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003570static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003571 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003572 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003573 const char *name)
3574{
Jeff Johnson5505db82017-11-02 21:19:23 -07003575 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003576 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003577 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303578 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003579 /*
3580 * cfg80211 initialization and registration....
3581 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003582 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003583#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3584 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003586 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3587 hdd_mon_mode_ether_setup : ether_setup),
3588 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589
Jeff Johnson5505db82017-11-02 21:19:23 -07003590 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591
3592 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003593 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594
Jeff Johnson9d295242017-08-29 14:39:48 -07003595 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003596 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303597 qdf_mem_set(sta_ctx->conn_info.staId,
3598 sizeof(sta_ctx->conn_info.staId),
3599 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003600 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003601 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003603 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303605 qdf_status = qdf_event_create(
3606 &adapter->qdf_session_open_event);
3607 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3608 hdd_err("Session open QDF event init failed!");
3609 free_netdev(adapter->dev);
3610 return NULL;
3611 }
3612
3613 qdf_status = qdf_event_create(
3614 &adapter->qdf_session_close_event);
3615 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3616 hdd_err("Session close QDF event init failed!");
3617 free_netdev(adapter->dev);
3618 return NULL;
3619 }
3620
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303622 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003623 init_completion(&adapter->linkup_event_var);
3624 init_completion(&adapter->cancel_rem_on_chan_var);
3625 init_completion(&adapter->rem_on_chan_ready_event);
3626 init_completion(&adapter->sta_authorized_event);
3627 init_completion(&adapter->offchannel_tx_event);
3628 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003629 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303630 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003631
3632 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003633 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303634 adapter->disconnection_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003636 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637
Jeff Johnson5505db82017-11-02 21:19:23 -07003638 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003639 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003640 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003642 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003643
3644 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003645 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003646 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003647 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003648
Jeff Johnson5505db82017-11-02 21:19:23 -07003649 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003650
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003651 hdd_set_station_ops(adapter->dev);
3652
Jeff Johnson5505db82017-11-02 21:19:23 -07003653 hdd_dev_setup_destructor(dev);
3654 dev->ieee80211_ptr = &adapter->wdev;
3655 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003657 adapter->wdev.netdev = dev;
3658 /* set dev's parent to underlying device */
3659 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 hdd_wmm_init(adapter);
3661 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303662 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003663 }
3664
3665 return adapter;
3666}
3667
Jeff Johnson9d295242017-08-29 14:39:48 -07003668static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003669{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003670 struct net_device *dev = adapter->dev;
3671 int ret;
3672
Dustin Brown491d54b2018-03-14 12:39:11 -07003673 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003675 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003676 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3677
3678 ret = dev_alloc_name(dev, dev->name);
3679 if (ret < 0) {
3680 hdd_err(
3681 "unable to get dev name: %s, err = 0x%x",
3682 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303683 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003684 }
3685 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003686
3687 ret = register_netdevice(dev);
3688 if (ret) {
3689 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3690 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303691 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692 }
3693 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003694 ret = register_netdev(dev);
3695 if (ret) {
3696 hdd_err("register_netdev(%s) failed, err = 0x%x",
3697 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303698 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003699 }
3700 }
3701 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3702
Dustin Browne74003f2018-03-14 12:51:58 -07003703 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003704
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303705 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706}
3707
Krunal Sonib51eec72017-11-20 21:53:01 -08003708QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709{
Krunal Sonib51eec72017-11-20 21:53:01 -08003710 struct hdd_adapter *adapter;
3711 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712
Krunal Sonib51eec72017-11-20 21:53:01 -08003713 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3714 if (!hdd_ctx) {
3715 hdd_err("Invalid HDD_CTX");
3716 return QDF_STATUS_E_FAILURE;
3717 }
3718
3719 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3720 if (NULL == adapter) {
3721 hdd_err("NULL adapter");
3722 return QDF_STATUS_E_INVAL;
3723 }
3724 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303725 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003726 hdd_debug("session %d opened", adapter->session_id);
3727
3728 return QDF_STATUS_SUCCESS;
3729}
3730
3731QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3732{
3733 struct hdd_adapter *adapter;
3734 struct hdd_context *hdd_ctx;
3735
3736 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3737 if (!hdd_ctx) {
3738 hdd_err("Invalid HDD_CTX");
3739 return QDF_STATUS_E_FAILURE;
3740 }
3741
3742 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003743 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003744 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303745 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003746 }
3747
3748 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003749 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303750 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003751 }
3752
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003753 /*
3754 * For NAN Data interface, the close session results in the final
3755 * indication to the userspace
3756 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003757 if (adapter->device_mode == QDF_NDI_MODE)
3758 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003759
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003760 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3761
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003762 /*
3763 * We can be blocked while waiting for scheduled work to be
3764 * flushed, and the adapter structure can potentially be freed, in
3765 * which case the magic will have been reset. So make sure the
3766 * magic is still good, and hence the adapter structure is still
3767 * valid, before signaling completion
3768 */
3769 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303770 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303772 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003773}
3774
Jeff Johnson9d295242017-08-29 14:39:48 -07003775int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776{
Dustin Brownd28772b2017-03-17 14:16:07 -07003777 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778
Dustin Brownd28772b2017-03-17 14:16:07 -07003779 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003780 if (QDF_IS_STATUS_ERROR(status))
3781 return qdf_status_to_os_return(status);
3782
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003783 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003784 if (QDF_IS_STATUS_ERROR(status))
3785 return qdf_status_to_os_return(status);
3786
3787 if (wma_capability_enhanced_mcast_filter())
3788 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3789 else
3790 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003791
3792 return qdf_status_to_os_return(status);
3793}
3794
Jeff Johnson9d295242017-08-29 14:39:48 -07003795int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003796{
3797 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003798 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003799 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003800 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003801
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003802 vdev_id = adapter->session_id;
3803 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003804
3805 /* vdev created sanity check */
3806 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003807 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003808 return -EINVAL;
3809 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003810 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003811
Dustin Brownd28772b2017-03-17 14:16:07 -07003812 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303813 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003814 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003815 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003816 if (QDF_IS_STATUS_ERROR(status)) {
3817 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003818 errno = qdf_status_to_os_return(status);
3819 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003820 }
3821
3822 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303823 status = qdf_wait_for_event_completion(
3824 &adapter->qdf_session_close_event,
3825 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3826 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003827 if (adapter->device_mode == QDF_NDI_MODE)
3828 hdd_ndp_session_end_handler(adapter);
3829 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303830 adapter->session_id = HDD_SESSION_ID_INVALID;
3831 if (QDF_STATUS_E_TIMEOUT != status) {
3832 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003833 errno = -ETIMEDOUT;
3834 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303835 } else if (adapter->qdf_session_close_event.force_set) {
3836 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003837 errno = -EINVAL;
3838 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303839 } else {
3840 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003841 errno = -EINVAL;
3842 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303843 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003844 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003845
Yue Maf9782842017-05-08 12:49:49 -07003846release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003847 /*
3848 * In SSR or driver unloading case, directly exit may cause objects
3849 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003850 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003851 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003852 return errno;
3853
Sandeep Puligillaef415362017-08-30 16:37:13 -07003854 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003855 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003856 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003857 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003858 return errno;
3859 }
3860
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003861 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003862
3863 return 0;
3864}
3865
Krunal Sonib51eec72017-11-20 21:53:01 -08003866static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3867 struct sme_session_params *session_param,
3868 csr_roam_completeCallback callback,
3869 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003870{
Dustin Brownd28772b2017-03-17 14:16:07 -07003871 uint32_t type;
3872 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003873 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003874
3875 /* determine vdev (sub)type */
3876 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303877 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003878 hdd_err("failed to get vdev type: %d", status);
3879 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003880 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003881 session_param->sme_session_id = adapter->session_id;
3882 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3883 session_param->type_of_persona = type;
3884 session_param->subtype_of_persona = sub_type;
3885 session_param->session_open_cb = hdd_sme_open_session_callback;
3886 session_param->session_close_cb = hdd_sme_close_session_callback;
3887 session_param->callback = callback;
3888 session_param->callback_ctx = callback_ctx;
3889
3890 return 0;
3891}
3892
3893int hdd_vdev_create(struct hdd_adapter *adapter,
3894 csr_roam_completeCallback callback, void *ctx)
3895{
3896 QDF_STATUS status;
3897 int errno;
3898 struct hdd_context *hdd_ctx;
3899 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003900
3901 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003902
3903 /* do vdev create via objmgr */
3904 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003905 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003906 if (errno) {
3907 hdd_err("failed to create objmgr vdev: %d", errno);
3908 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003910
3911 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303912 status = qdf_event_reset(&adapter->qdf_session_open_event);
3913 if (QDF_STATUS_SUCCESS != status) {
3914 hdd_err("failed to reinit session open event");
3915 return -EINVAL;
3916 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003917 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3918 callback, ctx);
3919 if (errno) {
3920 hdd_err("failed to populating SME params");
3921 goto objmgr_vdev_destroy_procedure;
3922 }
3923
3924 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003925 if (QDF_IS_STATUS_ERROR(status)) {
3926 hdd_err("failed to open sme session: %d", status);
3927 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003928 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003929 }
3930
3931 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303932 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3933 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3934 if (QDF_STATUS_SUCCESS != status) {
3935 if (adapter->qdf_session_open_event.force_set) {
3936 /*
3937 * SSR/PDR has caused shutdown, which has forcefully
3938 * set the event. Return without the closing session.
3939 */
3940 adapter->session_id = HDD_SESSION_ID_INVALID;
3941 hdd_err("Session open event forcefully set");
3942 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303943 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003944
3945 if (QDF_STATUS_E_TIMEOUT == status)
3946 hdd_err("Session failed to open within timeout period");
3947 else
3948 hdd_err("Failed to wait for session open event(status-%d)",
3949 status);
3950 errno = -ETIMEDOUT;
3951 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3952 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003953 }
3954
3955 /* firmware ready for component communication, raise vdev_ready event */
3956 errno = hdd_vdev_ready(adapter);
3957 if (errno) {
3958 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003959 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003960 }
3961
Naveen Rawat2b430892018-03-13 13:58:18 -07003962 if (adapter->device_mode == QDF_STA_MODE) {
3963 hdd_debug("setting RTT mac randomization param: %d",
3964 hdd_ctx->config->enable_rtt_mac_randomization);
3965 errno = sme_cli_set_command(adapter->session_id,
3966 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
3967 hdd_ctx->config->enable_rtt_mac_randomization,
3968 VDEV_CMD);
3969 if (0 != errno)
3970 hdd_err("RTT mac randomization param set failed %d",
3971 errno);
3972 }
3973
Jeff Johnson1b780e42017-10-31 14:11:45 -07003974 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003975
3976 return 0;
3977
3978 /*
3979 * Due to legacy constraints, we need to destroy in the same order as
3980 * create. So, split error handling into 2 cases to accommodate.
3981 */
3982
Krunal Soni4a020c72017-10-30 20:58:40 -07003983objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003984 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003985
3986 return errno;
3987
Krunal Soni4a020c72017-10-30 20:58:40 -07003988hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003989 QDF_BUG(!hdd_vdev_destroy(adapter));
3990
3991 return errno;
3992}
3993
Jeff Johnson9d295242017-08-29 14:39:48 -07003994QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003995{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003996 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003997 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003998 QDF_STATUS status;
3999 int ret_val;
4000
Dustin Brownd28772b2017-03-17 14:16:07 -07004001 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4002 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
4003 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004004 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004005
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004006 hdd_roam_profile_init(adapter);
4007 hdd_register_wext(adapter->dev);
4008
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004009 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010
Jeff Johnsond377dce2017-10-04 10:32:42 -07004011 qdf_mem_set(sta_ctx->conn_info.staId,
4012 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304013
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004014 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004015 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304016 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004018 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 hdd_ctx->config->OperatingChannel;
4020
4021 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004022 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023
4024 status = hdd_init_tx_rx(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_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 status, status);
4028 goto error_init_txrx;
4029 }
4030
4031 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4032
4033 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304034 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004035 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004036 status, status);
4037 goto error_wmm_init;
4038 }
4039
4040 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4041
Jeff Johnson1b780e42017-10-31 14:11:45 -07004042 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304044 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004046 if (ret_val)
4047 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004048
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304049 /*
4050 * In case of USB tethering, LRO is disabled. If SSR happened
4051 * during that time, then as part of SSR init, do not enable
4052 * the LRO again. Keep the LRO state same as before SSR.
4053 */
4054 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004055 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304056
4057 /* rcpi info initialization */
4058 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4059
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304060 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062error_wmm_init:
4063 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4064 hdd_deinit_tx_rx(adapter);
4065error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004066 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004067 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069 return status;
4070}
4071
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304072/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004073 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304074 * @hdd_ctx: global hdd context
4075 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004076 * @rtnl_held: Used to indicate whether or not the caller is holding
4077 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304078 *
4079 * This function De-initializes the STA/P2P/OCB adapter.
4080 *
4081 * Return: None.
4082 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004083static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004084 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004085 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304086{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004087 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304088
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304089 if (adapter->dev) {
4090 if (rtnl_held)
4091 adapter->dev->wireless_handlers = NULL;
4092 else {
4093 rtnl_lock();
4094 adapter->dev->wireless_handlers = NULL;
4095 rtnl_unlock();
4096 }
4097 }
4098
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304099 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4100 hdd_deinit_tx_rx(adapter);
4101 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4102 }
4103
4104 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4105 hdd_wmm_adapter_close(adapter);
4106 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4107 }
4108
Krunal Sonib51eec72017-11-20 21:53:01 -08004109
Dustin Browne74003f2018-03-14 12:51:58 -07004110 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304111}
4112
Krunal Sonib51eec72017-11-20 21:53:01 -08004113void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4114 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115 bool rtnl_held)
4116{
Dustin Brown491d54b2018-03-14 12:39:11 -07004117 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304118
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004119 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004120 case QDF_STA_MODE:
4121 case QDF_P2P_CLIENT_MODE:
4122 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004123 case QDF_IBSS_MODE:
4124 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004125 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004126 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004127 break;
4128 }
4129
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004130 case QDF_SAP_MODE:
4131 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004133 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134 break;
4135 }
4136
4137 default:
4138 break;
4139 }
4140
Dustin Browne74003f2018-03-14 12:51:58 -07004141 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142}
4143
Jeff Johnson9d295242017-08-29 14:39:48 -07004144static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004145 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146{
Jeff Johnson5505db82017-11-02 21:19:23 -07004147 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004148
4149 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004150 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004151 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004152 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153 return;
4154 }
4155
Alok Kumarb64650c2018-03-23 17:05:11 +05304156 hdd_nud_deinit_tracking(adapter);
4157 qdf_mutex_destroy(&adapter->disconnection_status_lock);
4158
Rajeev Kumardca5f812016-02-04 17:28:06 -08004159 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304160
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161 /*
4162 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4163 * the driver is almost closed and cannot handle either control
4164 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004165 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4166 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004167 * is not right. Setting this flag helps hdd_stop() to recognize that
4168 * the interface is closed and restricts any operations on that
4169 */
4170 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4171
4172 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004173 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004174 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004175 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004176 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 /*
4178 * Note that the adapter is no longer valid at this point
4179 * since the memory has been reclaimed
4180 */
4181 }
4182}
4183
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004184static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004185 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186{
Jeff Johnson9d295242017-08-29 14:39:48 -07004187 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004188
Dustin Brown920397d2017-12-13 16:27:50 -08004189 hdd_for_each_adapter(hdd_ctx, adapter) {
4190 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4191 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304192 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004194 }
Dustin Brown920397d2017-12-13 16:27:50 -08004195
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304196 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004197}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004198
Arun Khandavalli2358d522016-05-16 18:05:37 +05304199#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4200/**
4201 * hdd_set_fw_log_params() - Set log parameters to FW
4202 * @hdd_ctx: HDD Context
4203 * @adapter: HDD Adapter
4204 *
4205 * This function set the FW Debug log level based on the INI.
4206 *
4207 * Return: None
4208 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004209static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004210 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304211{
4212 uint8_t count = 0, numentries = 0,
4213 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4214 uint32_t value = 0;
4215 int ret;
4216
Arun Khandavallifae92942016-08-01 13:31:08 +05304217 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4218 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004219 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304220 return;
4221 }
4222
Arun Khandavallifae92942016-08-01 13:31:08 +05304223 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304224 hdd_ctx->fw_log_settings.dl_type =
4225 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004226 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304227 WMI_DBGLOG_TYPE,
4228 hdd_ctx->config->enableFwLogType,
4229 DBG_CMD);
4230 if (ret != 0)
4231 hdd_err("Failed to enable FW log type ret %d",
4232 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304233
4234 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304235 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004236 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304237 WMI_DBGLOG_LOG_LEVEL,
4238 hdd_ctx->config->enableFwLogLevel,
4239 DBG_CMD);
4240 if (ret != 0)
4241 hdd_err("Failed to enable FW log level ret %d",
4242 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304243
4244 hdd_string_to_u8_array(
4245 hdd_ctx->config->enableFwModuleLogLevel,
4246 moduleloglevel,
4247 &numentries,
4248 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4249
4250 while (count < numentries) {
4251 /*
4252 * FW module log level input string looks like
4253 * below:
4254 * gFwDebugModuleLoglevel=<FW Module ID>,
4255 * <Log Level>,...
4256 * For example:
4257 * gFwDebugModuleLoglevel=
4258 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4259 * Above input string means :
4260 * For FW module ID 1 enable log level 0
4261 * For FW module ID 2 enable log level 1
4262 * For FW module ID 3 enable log level 2
4263 * For FW module ID 4 enable log level 3
4264 * For FW module ID 5 enable log level 4
4265 * For FW module ID 6 enable log level 5
4266 * For FW module ID 7 enable log level 6
4267 */
4268
Nishank Aggarwale239d962017-03-03 12:26:02 +05304269 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4270 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4271 hdd_err("Module id %d and dbglog level %d input length is more than max",
4272 moduleloglevel[count],
4273 moduleloglevel[count + 1]);
4274 return;
4275 }
4276
4277 value = moduleloglevel[count] << 16;
4278 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004279 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304280 WMI_DBGLOG_MOD_LOG_LEVEL,
4281 value, DBG_CMD);
4282 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304283 hdd_err("Failed to enable FW module log level %d ret %d",
4284 value, ret);
4285
4286 count += 2;
4287 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304288
Arun Khandavalli2358d522016-05-16 18:05:37 +05304289}
4290#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004291static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004292 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304293{
4294}
4295
4296#endif
4297
4298/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004299 * hdd_configure_chain_mask() - programs chain mask to firmware
4300 * @adapter: HDD adapter
4301 *
4302 * Return: 0 on success or errno on failure
4303 */
4304static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4305{
4306 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004307 QDF_STATUS status;
4308 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004309 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4310
4311 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4312 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4313 hdd_ctx->config->txchainmask1x1,
4314 hdd_ctx->config->rxchainmask1x1);
4315 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4316 hdd_ctx->config->dual_mac_feature_disable,
4317 hdd_ctx->config->tx_chain_mask_2g,
4318 hdd_ctx->config->rx_chain_mask_2g);
4319 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4320 hdd_ctx->config->tx_chain_mask_5g,
4321 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004322 hdd_debug("enable_bt_chain_separation %d",
4323 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004324
Naveen Rawat98322472018-03-06 10:29:42 -08004325 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4326 HW_MODE_DBS_NONE,
4327 CDS_BAND_ALL);
4328 if (QDF_IS_STATUS_ERROR(status)) {
4329 hdd_err("couldn't get phy caps. skip chain mask programming");
4330 return qdf_status_to_os_return(status);
4331 }
4332
4333 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4334 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4335 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4336 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
4337 hdd_info("firmware not capable. skip chain mask programming");
4338 return 0;
4339 }
4340
Liangwei Dong22810e82018-03-15 03:42:12 -04004341 if (hdd_ctx->config->enable2x2 &&
4342 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004343 hdd_info("2x2 enabled. skip chain mask programming");
4344 return 0;
4345 }
4346
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004347 if (hdd_ctx->config->dual_mac_feature_disable !=
4348 DISABLE_DBS_CXN_AND_SCAN) {
4349 hdd_info("DBS enabled(%d). skip chain mask programming",
4350 hdd_ctx->config->dual_mac_feature_disable);
4351 return 0;
4352 }
4353
Naveen Rawatdacb5032018-02-08 15:23:24 -08004354 if (hdd_ctx->lte_coex_ant_share) {
4355 hdd_info("lte ant sharing enabled. skip chainmask programming");
4356 return 0;
4357 }
4358
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004359 if (hdd_ctx->config->txchainmask1x1) {
4360 ret_val = sme_cli_set_command(adapter->session_id,
4361 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4362 hdd_ctx->config->txchainmask1x1,
4363 PDEV_CMD);
4364 if (ret_val)
4365 goto error;
4366 }
4367
4368 if (hdd_ctx->config->rxchainmask1x1) {
4369 ret_val = sme_cli_set_command(adapter->session_id,
4370 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4371 hdd_ctx->config->rxchainmask1x1,
4372 PDEV_CMD);
4373 if (ret_val)
4374 goto error;
4375 }
4376
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004377 if (hdd_ctx->config->txchainmask1x1 ||
4378 hdd_ctx->config->rxchainmask1x1) {
4379 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4380 return 0;
4381 }
4382
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004383 if (hdd_ctx->config->tx_chain_mask_2g) {
4384 ret_val = sme_cli_set_command(adapter->session_id,
4385 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4386 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4387 if (0 != ret_val)
4388 goto error;
4389 }
4390
4391 if (hdd_ctx->config->rx_chain_mask_2g) {
4392 ret_val = sme_cli_set_command(adapter->session_id,
4393 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4394 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4395 if (0 != ret_val)
4396 goto error;
4397 }
4398
4399 if (hdd_ctx->config->tx_chain_mask_5g) {
4400 ret_val = sme_cli_set_command(adapter->session_id,
4401 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4402 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4403 if (0 != ret_val)
4404 goto error;
4405 }
4406
4407 if (hdd_ctx->config->rx_chain_mask_5g) {
4408 ret_val = sme_cli_set_command(adapter->session_id,
4409 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4410 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4411 if (0 != ret_val)
4412 goto error;
4413 }
4414
4415 return 0;
4416
4417error:
4418 hdd_err("WMI PDEV set param failed %d", ret_val);
4419 return -EINVAL;
4420}
4421
4422/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304423 * hdd_set_fw_params() - Set parameters to firmware
4424 * @adapter: HDD adapter
4425 *
4426 * This function Sets various parameters to fw once the
4427 * adapter is started.
4428 *
4429 * Return: 0 on success or errno on failure
4430 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004431int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304432{
4433 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004434 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304435
Dustin Brownfdf17c12018-03-14 12:55:34 -07004436 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304437
4438 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4439 if (!hdd_ctx)
4440 return -EINVAL;
4441
Dustin Brown732ab9c2017-06-15 13:24:09 -07004442 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4443 hdd_debug("FTM Mode is active; nothing to do");
4444 return 0;
4445 }
4446
Jeff Johnson1b780e42017-10-31 14:11:45 -07004447 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304448 WMI_PDEV_PARAM_DTIM_SYNTH,
4449 hdd_ctx->config->enable_lprx, PDEV_CMD);
4450 if (ret) {
4451 hdd_err("Failed to set LPRx");
4452 goto error;
4453 }
4454
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304455
4456 ret = sme_cli_set_command(
4457 adapter->session_id,
4458 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4459 hdd_ctx->config->enable_dtim_selection_diversity,
4460 PDEV_CMD);
4461 if (ret) {
4462 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4463 goto error;
4464 }
4465
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304466 ret = sme_cli_set_command(
4467 adapter->session_id,
4468 WMI_PDEV_PARAM_TX_SCH_DELAY,
4469 hdd_ctx->config->enable_tx_sch_delay,
4470 PDEV_CMD);
4471 if (ret) {
4472 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4473 goto error;
4474 }
4475
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304476 ret = sme_cli_set_command(
4477 adapter->session_id,
4478 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4479 hdd_ctx->config->enable_secondary_rate,
4480 PDEV_CMD);
4481 if (ret) {
4482 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4483 goto error;
4484 }
4485
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304486 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004487 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304488 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4489 hdd_ctx->config->upper_brssi_thresh);
4490
Jeff Johnson1b780e42017-10-31 14:11:45 -07004491 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304492 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4493 hdd_ctx->config->lower_brssi_thresh);
4494
Jeff Johnson1b780e42017-10-31 14:11:45 -07004495 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304496 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4497 hdd_ctx->config->enable_dtim_1chrx);
4498 }
4499
Dustin Brown732ab9c2017-06-15 13:24:09 -07004500 if (hdd_ctx->config->enable2x2) {
4501 hdd_debug("configuring 2x2 mode fw params");
4502
Jeff Johnson1b780e42017-10-31 14:11:45 -07004503 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004504 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4505 hdd_ctx->config->enable_cck_tx_fir_override,
4506 PDEV_CMD);
4507 if (ret) {
4508 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4509 ret);
4510 goto error;
4511 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004512
4513 if (hdd_configure_chain_mask(adapter))
4514 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004515 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304516#define HDD_DTIM_1CHAIN_RX_ID 0x5
4517#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004518 hdd_debug("configuring 1x1 mode fw params");
4519
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004520 /*
4521 * Disable DTIM 1 chain Rx when in 1x1,
4522 * we are passing two value
4523 * as param_id << 29 | param_value.
4524 * Below param_value = 0(disable)
4525 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004526 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004527 WMI_STA_SMPS_PARAM_CMDID,
4528 HDD_DTIM_1CHAIN_RX_ID <<
4529 HDD_SMPS_PARAM_VALUE_S,
4530 VDEV_CMD);
4531 if (ret) {
4532 hdd_err("DTIM 1 chain set failed %d", ret);
4533 goto error;
4534 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304535
Arun Khandavalli2358d522016-05-16 18:05:37 +05304536#undef HDD_DTIM_1CHAIN_RX_ID
4537#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004538
4539 if (hdd_configure_chain_mask(adapter))
4540 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004541 }
4542
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_PDEV_PARAM_HYST_EN,
4545 hdd_ctx->config->enableMemDeepSleep,
4546 PDEV_CMD);
4547 if (ret) {
4548 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4549 goto error;
4550 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304551
Jeff Johnson1b780e42017-10-31 14:11:45 -07004552 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004553 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4554 hdd_ctx->config->rts_profile,
4555 VDEV_CMD);
4556 if (ret) {
4557 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4558 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304559 }
4560
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004561 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4562
Jeff Johnson1b780e42017-10-31 14:11:45 -07004563 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004564 GEN_VDEV_PARAM_AMSDU,
4565 hdd_ctx->config->max_amsdu_num,
4566 GEN_CMD);
4567 if (ret != 0) {
4568 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4569 goto error;
4570 }
4571
Arun Khandavalli2358d522016-05-16 18:05:37 +05304572 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004573 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004574
Arun Khandavalli2358d522016-05-16 18:05:37 +05304575 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304576
Arun Khandavalli2358d522016-05-16 18:05:37 +05304577error:
4578 return -EINVAL;
4579}
4580
Ryan Hsu07495ea2016-01-21 15:25:39 -08004581/**
4582 * hdd_open_adapter() - open and setup the hdd adatper
4583 * @hdd_ctx: global hdd context
4584 * @session_type: type of the interface to be created
4585 * @iface_name: User-visible name of the interface
4586 * @macAddr: MAC address to assign to the interface
4587 * @name_assign_type: the name of assign type of the netdev
4588 * @rtnl_held: the rtnl lock hold flag
4589 *
4590 * This function open and setup the hdd adpater according to the device
4591 * type request, assign the name, the mac address assigned, and then prepared
4592 * the hdd related parameters, queue, lock and ready to start.
4593 *
4594 * Return: the pointer of hdd adapter, otherwise NULL.
4595 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004596struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004597 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004598 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004599 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004600{
Jeff Johnson9d295242017-08-29 14:39:48 -07004601 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304602 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004603
4604 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4605 /*
4606 * Max limit reached on the number of vdevs configured by the
4607 * host. Return error
4608 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304609 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4610 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004611 return NULL;
4612 }
4613
4614 if (macAddr == NULL) {
4615 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304616 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004617 return NULL;
4618 }
4619 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304620 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304621 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4622 " already exists",
4623 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624 return NULL;
4625 }
4626
4627 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004628 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004629 /* Reset locally administered bit if the device mode is STA */
4630 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304631 hdd_info("locally administered bit reset in sta mode: "
4632 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004633 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004634 case QDF_P2P_CLIENT_MODE:
4635 case QDF_P2P_DEVICE_MODE:
4636 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004637 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304638 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004639 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4640 name_assign_type,
4641 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004642
4643 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304644 hdd_err("failed to allocate adapter for session %d",
4645 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004646 return NULL;
4647 }
4648
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004649 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004650 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004651 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004652 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304653 else if (QDF_MONITOR_MODE == session_type)
4654 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655 else
4656 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4657
4658 adapter->device_mode = session_type;
4659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004661 /*
4662 * Workqueue which gets scheduled in IPv4 notification
4663 * callback
4664 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004665 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004666 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667
4668#ifdef WLAN_NS_OFFLOAD
4669 /*
4670 * Workqueue which gets scheduled in IPv6
4671 * notification callback.
4672 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004673 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004674 hdd_ipv6_notifier_work_queue);
4675#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004676 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004677 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004678 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004679
4680 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004681 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004682 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304683 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4684 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304685
Ravi Joshi1a292562017-05-18 16:28:54 -07004686 /* Initialize NAN Data Interface */
4687 if (QDF_NDI_MODE == session_type) {
4688 status = hdd_init_nan_data_mode(adapter);
4689 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004690 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004691 }
4692
Alok Kumarb64650c2018-03-23 17:05:11 +05304693 hdd_nud_init_tracking(adapter);
4694
4695 qdf_mutex_create(&adapter->disconnection_status_lock);
4696
Ravi Joshi1a292562017-05-18 16:28:54 -07004697 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004698
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004699 case QDF_P2P_GO_MODE:
4700 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004701 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4702 name_assign_type,
4703 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004704 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004705 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304706 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004707 return NULL;
4708 }
4709
4710 adapter->wdev.iftype =
4711 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004712 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004713 NL80211_IFTYPE_P2P_GO;
4714 adapter->device_mode = session_type;
4715
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004716 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004717 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004718 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004719
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004720 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004721 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304722 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4723 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304724
4725 /*
4726 * Workqueue which gets scheduled in IPv4 notification
4727 * callback
4728 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004729 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304730 hdd_ipv4_notifier_work_queue);
4731
4732#ifdef WLAN_NS_OFFLOAD
4733 /*
4734 * Workqueue which gets scheduled in IPv6
4735 * notification callback.
4736 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004737 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304738 hdd_ipv6_notifier_work_queue);
4739#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004740 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304741 case QDF_FTM_MODE:
4742 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4743 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004744 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304745 if (NULL == adapter) {
4746 hdd_err("Failed to allocate adapter for FTM mode");
4747 return NULL;
4748 }
4749 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4750 adapter->device_mode = session_type;
4751 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004752 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004753 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004754
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304755 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004756 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304757 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304758 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4759 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304760 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004761 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004762 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304763 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004764 return NULL;
4765 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766
hqueaa33ee2017-05-04 17:56:35 +08004767 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4768
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304769 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004770 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004771 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004772 }
4773
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304774 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004775 if (NULL != adapter) {
4776 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4777 adapter = NULL;
4778 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004779
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004780 return NULL;
4781 }
4782
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304783 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004784 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4785 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004786
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004787 /* Adapter successfully added. Increment the vdev count */
4788 hdd_ctx->current_intf_count++;
4789
Jeff Johnson5880d792016-08-15 13:32:30 -07004790 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791 hdd_ctx->current_intf_count);
4792
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004793 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004794 }
4795
Rajeev Kumardca5f812016-02-04 17:28:06 -08004796 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004797 hdd_err("Interface %s wow debug_fs init failed",
4798 netdev_name(adapter->dev));
4799
4800 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4801 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004802
4803 return adapter;
4804
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004805err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004806 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304807 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808
4809 return NULL;
4810}
4811
Nirav Shaheb017be2018-02-15 11:20:58 +05304812#ifdef MSM_PLATFORM
4813static inline
4814void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4815{
4816 cancel_work_sync(&hdd_ctx->bus_bw_work);
4817}
4818#else
4819static inline
4820void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4821{
4822}
4823#endif
4824
Jeff Johnson9d295242017-08-29 14:39:48 -07004825QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004826 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004827{
Dustin Brown920397d2017-12-13 16:27:50 -08004828 /*
4829 * Here we are stopping global bus_bw timer & work per adapter.
4830 *
4831 * The reason is to fix one race condition between
4832 * bus bandwidth work and cleaning up an adapter.
4833 * Under some conditions, it is possible for the bus bandwidth
4834 * work to access a particularly destroyed adapter, leading to
4835 * use-after-free.
4836 */
4837 hdd_debug("wait for bus bw work to flush");
4838 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4839 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004840
Dustin Brown920397d2017-12-13 16:27:50 -08004841 /* cleanup adapter */
4842 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4843 adapter->device_mode);
Dustin Brown920397d2017-12-13 16:27:50 -08004844 hdd_remove_adapter(hdd_ctx, adapter);
Liangwei Dongad89c762018-06-01 01:56:23 -04004845 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846
Dustin Brown920397d2017-12-13 16:27:50 -08004847 /* conditionally restart the bw timer */
4848 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004849
Dustin Brown920397d2017-12-13 16:27:50 -08004850 /* Adapter removed. Decrement vdev count */
4851 if (hdd_ctx->current_intf_count != 0)
4852 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004853
Dustin Brown920397d2017-12-13 16:27:50 -08004854 /* Fw will take care incase of concurrency */
4855 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004856}
4857
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004858/**
4859 * hdd_close_all_adapters - Close all open adapters
4860 * @hdd_ctx: Hdd context
4861 * rtnl_held: True if RTNL lock held
4862 *
4863 * Close all open adapters.
4864 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304865 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004866 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004867QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868{
Dustin Brown920397d2017-12-13 16:27:50 -08004869 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304870 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871
Dustin Brown491d54b2018-03-14 12:39:11 -07004872 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873
4874 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004875 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4876 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304877 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004878 adapter->mac_addr.bytes);
4879 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4880
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304881 /* Adapter removed. Decrement vdev count */
4882 if (hdd_ctx->current_intf_count != 0)
4883 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004884 }
Dustin Brown920397d2017-12-13 16:27:50 -08004885 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004886
Dustin Browne74003f2018-03-14 12:51:58 -07004887 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004888
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304889 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004890}
4891
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004892void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304894 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004895 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004896
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004897 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004898 case QDF_STA_MODE:
4899 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004901 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004902 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004903 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004904 break;
4905 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004906 case QDF_SAP_MODE:
4907 case QDF_P2P_GO_MODE:
4908 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004909 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004910 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004911 break;
4912 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004913 case QDF_FTM_MODE:
4914 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004915 default:
4916 /*
4917 * wlan_hdd_reset_prob_rspies should not have been called
4918 * for these kind of devices
4919 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004920 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004921 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004922 return;
4923 }
4924
Anurag Chouhanc5548422016-02-24 18:33:27 +05304925 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004926 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004927 updateIE.ieBufferlength = 0;
4928 updateIE.pAdditionIEBuffer = NULL;
4929 updateIE.append = true;
4930 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004931 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004932 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304933 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004934 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004935 }
4936}
4937
Dustin Browndb2a8be2017-12-20 11:49:56 -08004938QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4939 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004940{
Liangwei Dongad89c762018-06-01 01:56:23 -04004941 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
4942}
4943
4944QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
4945 struct hdd_adapter *adapter,
4946 enum hdd_adapter_stop_flag_t flag)
4947{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304948 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07004949 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004950 union iwreq_data wrqu;
4951 tSirUpdateIE updateIE;
4952 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07004953 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004954
Dustin Brown491d54b2018-03-14 12:39:11 -07004955 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004956
Dustin Browne7e71d32018-05-11 16:00:08 -07004957 if (adapter->session_id != HDD_SESSION_ID_INVALID)
4958 wlan_hdd_cfg80211_deregister_frames(adapter);
4959
Alok Kumarb64650c2018-03-23 17:05:11 +05304960 hdd_nud_ignore_tracking(adapter, true);
4961 hdd_nud_reset_tracking(adapter);
4962
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004963 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304964 wlan_hdd_netif_queue_control(adapter,
4965 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4966 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004967 /*
4968 * if this is the last active connection check & stop the
4969 * opportunistic timer first
4970 */
4971 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4972 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4973 policy_mgr_convert_device_mode_to_qdf_type(
4974 adapter->device_mode), NULL) == 1)) ||
4975 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4976 policy_mgr_check_and_stop_opportunistic_timer(
4977 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004978 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004979 case QDF_STA_MODE:
4980 case QDF_P2P_CLIENT_MODE:
4981 case QDF_IBSS_MODE:
4982 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004983 case QDF_NDI_MODE:
4984 if ((QDF_NDI_MODE == adapter->device_mode) ||
4985 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004986 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4987 hdd_is_connecting(
4988 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004989 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07004990 roam_profile = hdd_roam_profile(adapter);
4991 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004992 if (QDF_NDI_MODE == adapter->device_mode)
4993 qdf_ret_status = sme_roam_disconnect(
4994 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004995 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004996 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07004997 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004998 eCSR_BSS_TYPE_START_IBSS)
4999 qdf_ret_status = sme_roam_disconnect(
5000 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005001 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005002 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08005003 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005004 qdf_ret_status =
5005 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08005006 hdd_debug("Send disconnected event to userspace");
5007 wlan_hdd_cfg80211_indicate_disconnect(
5008 adapter->dev, true,
5009 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08005010 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005011 qdf_ret_status = sme_roam_disconnect(
5012 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005013 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005014 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005015 /* success implies disconnect command got
5016 * queued up successfully
5017 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005018 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
5019 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005020 rc = wait_for_completion_timeout(
5021 &adapter->disconnect_comp_var,
5022 msecs_to_jiffies
5023 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005024 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005025 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005026 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005027 if (qdf_ret_status != QDF_STATUS_SUCCESS)
5028 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005029 memset(&wrqu, '\0', sizeof(wrqu));
5030 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5031 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5032 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5033 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305034 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08005035 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005036
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305037 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305038 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005039
5040#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005041 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042#endif
5043
5044 hdd_deregister_tx_flow_control(adapter);
5045
5046#ifdef WLAN_NS_OFFLOAD
5047#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005048 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049#endif
5050#endif
5051
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305052 if (adapter->device_mode == QDF_STA_MODE)
5053 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5054 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005055
5056 if (wlan_hdd_try_disconnect(adapter)) {
5057 hdd_err("Error: Can't disconnect adapter");
5058 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005059 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005060
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305061 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005062 break;
5063
Rajeev Kumar3b906202018-02-01 10:55:14 -08005064 case QDF_MONITOR_MODE:
5065 wlan_hdd_scan_abort(adapter);
5066 hdd_deregister_tx_flow_control(adapter);
5067 hdd_vdev_destroy(adapter);
5068 break;
5069
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005070 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08005071 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305072 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305073 sap_config = &adapter->session.ap.sap_config;
5074 if (sap_config)
5075 wlansap_reset_sap_config_add_ie(sap_config,
5076 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305077 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Liangwei Dongad89c762018-06-01 01:56:23 -04005078 if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
5079 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005080 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005081
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005082 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07005083 if (QDF_SAP_MODE == adapter->device_mode) {
5084 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5085 cds_flush_delayed_work(
5086 &adapter->acs_pending_work);
5087 clear_bit(ACS_PENDING, &adapter->event_flags);
5088 }
5089 }
Krunal Soni22208392017-09-29 18:10:34 -07005090 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005091
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005092 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305093 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005094 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005095 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5097
5098 hdd_deregister_tx_flow_control(adapter);
5099
Kapil Guptac1224bf2017-06-22 21:22:40 +05305100 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101 mutex_lock(&hdd_ctx->sap_lock);
5102 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305103 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305104 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005105
5106 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005107 status = wlansap_stop_bss(
5108 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005109
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305110 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005111 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005112 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305113 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305114 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305115 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305116 qdf_wait_for_event_completion(
5117 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005118 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005119
Anurag Chouhance0dc992016-02-16 18:18:03 +05305120 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005121 hdd_err("failure waiting for wlansap_stop_bss %d",
5122 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005123 }
5124 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005125 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005126 }
5127 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005128 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5129 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005130 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005131 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305132 adapter->device_mode,
5133 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005134
Anurag Chouhanc5548422016-02-24 18:33:27 +05305135 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005136 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005137 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138 updateIE.ieBufferlength = 0;
5139 updateIE.pAdditionIEBuffer = NULL;
5140 updateIE.append = false;
5141 updateIE.notify = false;
5142 /* Probe bcn reset */
5143 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5144 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305145 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005146 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147 }
5148 /* Assoc resp reset */
5149 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5150 &updateIE,
5151 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305152 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005153 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005154 }
5155 /* Reset WNI_CFG_PROBE_RSP Flags */
5156 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005158 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005159 qdf_mem_free(adapter->session.ap.beacon);
5160 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005161
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305162 /*
5163 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5164 */
5165 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5166 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5167
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305168#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005169 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305170#endif
5171
5172#ifdef WLAN_NS_OFFLOAD
5173#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005174 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305175#endif
5176#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005177
5178 hdd_vdev_destroy(adapter);
5179
Krunal Sonib51eec72017-11-20 21:53:01 -08005180 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005182 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005183 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005184 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005185 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005186 hdd_deregister_tx_flow_control(adapter);
5187 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 break;
5189 default:
5190 break;
5191 }
5192
Dustin Brown04348372017-12-14 16:13:39 -08005193 if (adapter->scan_info.default_scan_ies) {
5194 qdf_mem_free(adapter->scan_info.default_scan_ies);
5195 adapter->scan_info.default_scan_ies = NULL;
5196 }
5197
Dustin Browne74003f2018-03-14 12:51:58 -07005198 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005199
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305200 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005201}
5202
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305203/**
5204 * hdd_deinit_all_adapters - deinit all adapters
5205 * @hdd_ctx: HDD context
5206 * @rtnl_held: True if RTNL lock held
5207 *
5208 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005209void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305210{
Jeff Johnson9d295242017-08-29 14:39:48 -07005211 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305212
Dustin Brown491d54b2018-03-14 12:39:11 -07005213 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305214
Dustin Brown920397d2017-12-13 16:27:50 -08005215 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305216 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305217
Dustin Browne74003f2018-03-14 12:51:58 -07005218 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305219}
5220
Dustin Browndb2a8be2017-12-20 11:49:56 -08005221QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005222{
Jeff Johnson9d295242017-08-29 14:39:48 -07005223 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005224
Dustin Brown491d54b2018-03-14 12:39:11 -07005225 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005226
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305227 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5228
Dustin Brown920397d2017-12-13 16:27:50 -08005229 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005230 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231
Dustin Browne74003f2018-03-14 12:51:58 -07005232 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305234 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005235}
5236
Paul Zhang84fa9382017-11-10 21:18:21 +08005237static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5238 struct hdd_adapter *adapter)
5239{
5240 switch (adapter->device_mode) {
5241 case QDF_STA_MODE:
5242 case QDF_P2P_CLIENT_MODE:
5243 case QDF_IBSS_MODE:
5244 case QDF_P2P_DEVICE_MODE:
5245 case QDF_NDI_MODE:
5246 wlan_hdd_scan_abort(adapter);
5247 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5248 if (adapter->device_mode == QDF_STA_MODE)
5249 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5250 adapter->dev);
5251 break;
5252 case QDF_P2P_GO_MODE:
5253 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5254 break;
5255 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305256 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005257 wlan_hdd_undo_acs(adapter);
5258 break;
5259 default:
5260 break;
5261 }
5262}
5263
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005264QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265{
Jeff Johnson9d295242017-08-29 14:39:48 -07005266 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005267 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005268 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005269 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270
Dustin Brown491d54b2018-03-14 12:39:11 -07005271 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005272
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305273 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5274
Dustin Brown920397d2017-12-13 16:27:50 -08005275 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005276 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5277 hdd_device_mode_to_string(adapter->device_mode),
5278 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305279
5280 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005281 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305282 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005283 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005284 adapter->session.station.hdd_reassoc_scenario = false;
5285 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305286
Arun Khandavallicc544b32017-01-30 19:52:16 +05305287 if (hdd_ctx->config->sap_internal_restart &&
5288 adapter->device_mode == QDF_SAP_MODE) {
5289 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305290 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305291 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005292 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005293 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005294 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005295 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5296 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305297 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305298 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005300 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005301
Paul Zhang84fa9382017-11-10 21:18:21 +08005302 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303
5304 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005305 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005306 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005307 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305308 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005309 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5310 hdd_wmm_adapter_close(adapter);
5311 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5312 }
5313
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305314 if (adapter->device_mode == QDF_STA_MODE)
5315 hdd_clear_fils_connection_info(adapter);
5316
Wu Gao3545e642017-07-14 19:24:41 +08005317 if (adapter->device_mode == QDF_SAP_MODE) {
5318 /*
5319 * If adapter is SAP, set session ID to invalid
5320 * since SAP session will be cleanup during SSR.
5321 */
Wu Gao36717432016-11-21 15:09:48 +08005322 wlansap_set_invalid_session(
5323 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5324
Wu Gao3545e642017-07-14 19:24:41 +08005325 wlansap_cleanup_cac_timer(
5326 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5327 }
5328
Yue Ma42654682018-01-11 16:55:24 -08005329 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005330 if (adapter->device_mode == QDF_STA_MODE ||
5331 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005332 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005333 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005334 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005335
5336 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5337 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005338 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005339 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005340 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5341 if (adapter->sta_info[sta_id].in_use) {
5342 hdd_debug("[SSR] deregister STA with ID %d",
5343 sta_id);
5344 hdd_softap_deregister_sta(adapter,
5345 sta_id);
5346 adapter->sta_info[sta_id].in_use = 0;
5347 }
5348 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005349 }
5350
Alok Kumarb64650c2018-03-23 17:05:11 +05305351 hdd_nud_reset_tracking(adapter);
5352 hdd_nud_ignore_tracking(adapter, true);
5353 hdd_set_disconnect_status(adapter, false);
5354
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005355 hdd_softap_deinit_tx_rx(adapter);
5356
Yue Maf9782842017-05-08 12:49:49 -07005357 /* Destroy vdev which will be recreated during reinit. */
5358 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359 }
5360
Dustin Browne74003f2018-03-14 12:51:58 -07005361 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005362
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305363 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005364}
5365
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005366bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305367{
Dustin Brown920397d2017-12-13 16:27:50 -08005368 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305369 bool close_modules = true;
5370
Arun Khandavalliba479c42017-07-26 21:29:40 +05305371 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5372 hdd_info("FTM mode, don't close the module");
5373 return false;
5374 }
5375
Dustin Brown920397d2017-12-13 16:27:50 -08005376 hdd_for_each_adapter(hdd_ctx, adapter) {
5377 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5378 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005379 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305380 close_modules = false;
5381 break;
5382 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305383 }
5384
5385 return close_modules;
5386}
5387
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305388bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305389{
5390 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5391 return true;
5392 else
5393 return false;
5394}
5395
Anurag Chouhanc4092922016-09-08 15:56:11 +05305396#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005397 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305398struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5399 struct ieee80211_channel *channel,
5400 const u8 *bssid, const u8 *ssid,
5401 size_t ssid_len)
5402{
5403 return cfg80211_get_bss(wiphy, channel, bssid,
5404 ssid, ssid_len,
5405 WLAN_CAPABILITY_ESS,
5406 WLAN_CAPABILITY_ESS);
5407}
5408#else
5409struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5410 struct ieee80211_channel *channel,
5411 const u8 *bssid, const u8 *ssid,
5412 size_t ssid_len)
5413{
5414 return cfg80211_get_bss(wiphy, channel, bssid,
5415 ssid, ssid_len,
5416 IEEE80211_BSS_TYPE_ESS,
5417 IEEE80211_PRIVACY_ANY);
5418}
5419#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305420
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305421#if defined CFG80211_CONNECT_BSS || \
5422 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305423#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305424 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305425/**
5426 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5427 * @timeout_reason: reason for connect timeout
5428 *
5429 * This function is used to convert host timeout
5430 * reason enum to kernel specific enum.
5431 *
5432 * Return: nl timeout enum
5433 */
5434static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5435 tSirResultCodes timeout_reason)
5436{
5437 switch (timeout_reason) {
5438 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5439 return NL80211_TIMEOUT_SCAN;
5440 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5441 return NL80211_TIMEOUT_AUTH;
5442 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5443 return NL80211_TIMEOUT_ASSOC;
5444 default:
5445 return NL80211_TIMEOUT_UNSPECIFIED;
5446 }
5447}
5448
5449/**
5450 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5451 * @dev: network device
5452 * @bssid: bssid to which we want to associate
5453 * @timeout_reason: reason for connect timeout
5454 *
5455 * This API is used to send connection timeout reason to supplicant
5456 *
5457 * Return: void
5458 */
5459static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5460 const u8 *bssid,
5461 tSirResultCodes timeout_reason)
5462{
5463 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005464
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305465 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5466
5467 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5468 nl_timeout_reason);
5469}
5470
5471/**
5472 * __hdd_connect_bss() - API to send connection status to supplicant
5473 * @dev: network device
5474 * @bssid: bssid to which we want to associate
5475 * @req_ie: Request Information Element
5476 * @req_ie_len: len of the req IE
5477 * @resp_ie: Response IE
5478 * @resp_ie_len: len of ht response IE
5479 * @status: status
5480 * @gfp: Kernel Flag
5481 * @timeout_reason: reason for connect timeout
5482 *
5483 * Return: void
5484 */
5485static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5486 struct cfg80211_bss *bss, const u8 *req_ie,
5487 size_t req_ie_len, const u8 *resp_ie,
5488 size_t resp_ie_len, int status, gfp_t gfp,
5489 tSirResultCodes timeout_reason)
5490{
5491 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005492
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305493 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5494
5495 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5496 resp_ie, resp_ie_len, status, gfp,
5497 nl_timeout_reason);
5498}
5499#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305500#if defined CFG80211_CONNECT_TIMEOUT || \
5501 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305502static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5503 const u8 *bssid,
5504 tSirResultCodes timeout_reason)
5505{
5506 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5507}
5508#endif
5509
5510static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5511 struct cfg80211_bss *bss, const u8 *req_ie,
5512 size_t req_ie_len, const u8 *resp_ie,
5513 size_t resp_ie_len, int status, gfp_t gfp,
5514 tSirResultCodes timeout_reason)
5515{
5516 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5517 resp_ie, resp_ie_len, status, gfp);
5518}
5519#endif
5520
Abhishek Singha84d3952016-09-13 13:45:05 +05305521/**
5522 * hdd_connect_bss() - API to send connection status to supplicant
5523 * @dev: network device
5524 * @bssid: bssid to which we want to associate
5525 * @req_ie: Request Information Element
5526 * @req_ie_len: len of the req IE
5527 * @resp_ie: Response IE
5528 * @resp_ie_len: len of ht response IE
5529 * @status: status
5530 * @gfp: Kernel Flag
5531 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305532 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305533 *
5534 * The API is a wrapper to send connection status to supplicant
5535 *
5536 * Return: Void
5537 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305538#if defined CFG80211_CONNECT_TIMEOUT || \
5539 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305540static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5541 struct cfg80211_bss *bss, const u8 *req_ie,
5542 size_t req_ie_len, const u8 *resp_ie,
5543 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305544 bool connect_timeout,
5545 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305546{
5547 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305548 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305549 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305550 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5551 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305552}
5553#else
5554static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5555 struct cfg80211_bss *bss, const u8 *req_ie,
5556 size_t req_ie_len, const u8 *resp_ie,
5557 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305558 bool connect_timeout,
5559 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305560{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305561 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5562 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305563}
5564#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305565
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305566#if defined(WLAN_FEATURE_FILS_SK)
5567#if defined(CFG80211_CONNECT_DONE) || \
5568 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5569#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5570 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305571/**
5572 * hdd_populate_fils_params() - Populate FILS keys to connect response
5573 * @fils_params: connect response to supplicant
5574 * @fils_kek: FILS kek
5575 * @fils_kek_len: FILS kek length
5576 * @pmk: FILS PMK
5577 * @pmk_len: FILS PMK length
5578 * @pmkid: PMKID
5579 * @fils_seq_num: FILS Seq number
5580 *
5581 * Return: None
5582 */
5583static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5584 *fils_params, const uint8_t *fils_kek,
5585 size_t fils_kek_len, const uint8_t *pmk,
5586 size_t pmk_len, const uint8_t *pmkid,
5587 uint16_t fils_seq_num)
5588{
5589 /* Increament seq number to be used for next FILS */
5590 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5591 fils_params->update_erp_next_seq_num = true;
5592 fils_params->fils_kek = fils_kek;
5593 fils_params->fils_kek_len = fils_kek_len;
5594 fils_params->pmk = pmk;
5595 fils_params->pmk_len = pmk_len;
5596 fils_params->pmkid = pmkid;
5597}
5598#else
5599static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5600 *fils_params, const uint8_t
5601 *fils_kek, size_t fils_kek_len,
5602 const uint8_t *pmk, size_t pmk_len,
5603 const uint8_t *pmkid,
5604 uint16_t fils_seq_num)
5605{ }
5606#endif
5607
Jeff Johnson172237b2017-11-07 15:32:59 -08005608void hdd_update_hlp_info(struct net_device *dev,
5609 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305610{
5611 struct sk_buff *skb;
5612 uint16_t skb_len;
5613 struct llc_snap_hdr_t *llc_hdr;
5614 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305615 uint8_t *hlp_data;
5616 uint16_t hlp_data_len;
5617 struct fils_join_rsp_params *roam_fils_params
5618 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305619 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5620
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305621 if (!roam_fils_params) {
5622 hdd_err("FILS Roam Param NULL");
5623 return;
5624 }
5625
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005626 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305627 hdd_err("FILS HLP Data NULL, len %d",
5628 roam_fils_params->hlp_data_len);
5629 return;
5630 }
5631
5632 hlp_data = roam_fils_params->hlp_data;
5633 hlp_data_len = roam_fils_params->hlp_data_len;
5634
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305635 /* Calculate skb length */
5636 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5637 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5638 if (skb == NULL) {
5639 hdd_err("HLP packet nbuf alloc fails");
5640 return;
5641 }
5642
5643 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5644 QDF_MAC_ADDR_SIZE);
5645 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5646 QDF_MAC_ADDR_SIZE);
5647
5648 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5649 if (IS_SNAP(llc_hdr)) {
5650 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5651 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5652 }
5653
5654 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5655
5656 /*
5657 * This HLP packet is formed from HLP info encapsulated
5658 * in assoc response frame which is AEAD encrypted.
5659 * Hence, this checksum validation can be set unnecessary.
5660 * i.e. network layer need not worry about checksum.
5661 */
5662 skb->ip_summed = CHECKSUM_UNNECESSARY;
5663
5664 status = hdd_rx_packet_cbk(padapter, skb);
5665 if (QDF_IS_STATUS_ERROR(status)) {
5666 hdd_err("Sending HLP packet fails");
5667 return;
5668 }
5669 hdd_debug("send HLP packet to netif successfully");
5670}
5671
5672/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305673 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5674 * @dev: network device
5675 * @bssid: bssid to which we want to associate
5676 * @bss: cfg80211 bss info
5677 * @roam_info: information about connected bss
5678 * @req_ie: Request Information Element
5679 * @req_ie_len: len of the req IE
5680 * @resp_ie: Response IE
5681 * @resp_ie_len: len of ht response IE
5682 * @status: status
5683 * @gfp: allocation flags
5684 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5685 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305686 *
5687 * This API is used as wrapper to send FILS key/sequence number
5688 * params etc. to supplicant in case of FILS connection
5689 *
5690 * Return: None
5691 */
5692static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005693 struct cfg80211_bss *bss,
5694 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305695 const u8 *req_ie, size_t req_ie_len,
5696 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005697 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305698 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305699{
5700 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305701 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5702 struct fils_join_rsp_params *roam_fils_params =
5703 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005704
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305705 qdf_mem_zero(&fils_params, sizeof(fils_params));
5706
5707 if (!roam_fils_params) {
5708 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5709 } else {
5710 fils_params.status = status;
5711 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005712 fils_params.timeout_reason =
5713 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305714 fils_params.req_ie = req_ie;
5715 fils_params.req_ie_len = req_ie_len;
5716 fils_params.resp_ie = resp_ie;
5717 fils_params.resp_ie_len = resp_ie_len;
5718 fils_params.bss = bss;
5719 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5720 roam_fils_params->kek_len,
5721 roam_fils_params->fils_pmk,
5722 roam_fils_params->fils_pmk_len,
5723 roam_fils_params->fils_pmkid,
5724 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305725 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305726 }
5727 hdd_debug("FILS indicate connect status %d seq no %d",
5728 fils_params.status,
5729 fils_params.fils_erp_next_seq_num);
5730
5731 cfg80211_connect_done(dev, &fils_params, gfp);
5732
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305733 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305734 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305735
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305736 /* Clear all the FILS key info */
5737 if (roam_fils_params && roam_fils_params->fils_pmk)
5738 qdf_mem_free(roam_fils_params->fils_pmk);
5739 if (roam_fils_params)
5740 qdf_mem_free(roam_fils_params);
5741 roam_info->fils_join_rsp = NULL;
5742}
5743#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005744static inline void
5745hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005746 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005747 const u8 *req_ie, size_t req_ie_len,
5748 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5749 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305750 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305751{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305752#endif
5753#endif
5754
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305755#if defined(WLAN_FEATURE_FILS_SK) && \
5756 (defined(CFG80211_CONNECT_DONE) || \
5757 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305758/**
5759 * hdd_fils_update_connect_results() - API to send fils connection status to
5760 * supplicant.
5761 * @dev: network device
5762 * @bssid: bssid to which we want to associate
5763 * @bss: cfg80211 bss info
5764 * @roam_info: information about connected bss
5765 * @req_ie: Request Information Element
5766 * @req_ie_len: len of the req IE
5767 * @resp_ie: Response IE
5768 * @resp_ie_len: len of ht response IE
5769 * @status: status
5770 * @gfp: allocation flags
5771 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5772 * @timeout_reason: reason for connect timeout
5773 *
5774 * The API is a wrapper to send connection status to supplicant
5775 *
5776 * Return: 0 if success else failure
5777 */
5778static int hdd_fils_update_connect_results(struct net_device *dev,
5779 const u8 *bssid,
5780 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005781 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305782 size_t req_ie_len, const u8 *resp_ie,
5783 size_t resp_ie_len, u16 status, gfp_t gfp,
5784 bool connect_timeout,
5785 tSirResultCodes timeout_reason)
5786{
Dustin Brown491d54b2018-03-14 12:39:11 -07005787 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305788 if (!roam_info || !roam_info->is_fils_connection)
5789 return -EINVAL;
5790
5791 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5792 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305793 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305794 return 0;
5795}
5796#else
5797static inline int hdd_fils_update_connect_results(struct net_device *dev,
5798 const u8 *bssid,
5799 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005800 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305801 size_t req_ie_len, const u8 *resp_ie,
5802 size_t resp_ie_len, u16 status, gfp_t gfp,
5803 bool connect_timeout,
5804 tSirResultCodes timeout_reason)
5805{
5806 return -EINVAL;
5807}
5808#endif
5809
Anurag Chouhanc4092922016-09-08 15:56:11 +05305810/**
5811 * hdd_connect_result() - API to send connection status to supplicant
5812 * @dev: network device
5813 * @bssid: bssid to which we want to associate
5814 * @roam_info: information about connected bss
5815 * @req_ie: Request Information Element
5816 * @req_ie_len: len of the req IE
5817 * @resp_ie: Response IE
5818 * @resp_ie_len: len of ht response IE
5819 * @status: status
5820 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305821 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305822 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305823 *
5824 * The API is a wrapper to send connection status to supplicant
5825 * and allow runtime suspend
5826 *
5827 * Return: Void
5828 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305829void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005830 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305831 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305832 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305833 bool connect_timeout,
5834 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305835{
Jeff Johnson9d295242017-08-29 14:39:48 -07005836 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305837 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005838 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305839
5840 if (WLAN_STATUS_SUCCESS == status) {
5841 struct ieee80211_channel *chan;
5842 int freq;
5843 int chan_no = roam_info->pBssDesc->channelId;
5844
5845 if (chan_no <= 14)
5846 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005847 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305848 else
5849 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005850 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305851
5852 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5853 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5854 roam_info->u.pConnectedProfile->SSID.ssId,
5855 roam_info->u.pConnectedProfile->SSID.length);
5856 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305857
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305858 if (hdd_fils_update_connect_results(dev, bssid, bss,
5859 roam_info, req_ie, req_ie_len, resp_ie,
5860 resp_ie_len, status, gfp, connect_timeout,
5861 timeout_reason) != 0) {
5862 hdd_connect_bss(dev, bssid, bss, req_ie,
5863 req_ie_len, resp_ie, resp_ie_len,
5864 status, gfp, connect_timeout, timeout_reason);
5865 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305866
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#else
5871void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005872 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305873 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305874 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305875 bool connect_timeout,
5876 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305877{
Jeff Johnson9d295242017-08-29 14:39:48 -07005878 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005879 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305880
Anurag Chouhanc4092922016-09-08 15:56:11 +05305881 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5882 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005883
Jingxiang Geb49aa302018-01-17 20:54:15 +08005884 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005885 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305886}
5887#endif
5888
Nirav Shah73713f72018-05-17 14:50:41 +05305889#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07005890int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
5891 uint32_t bandwidth)
5892{
5893 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5894 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5895 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
5896 QDF_STATUS status;
5897 tHalHandle hal_hdl = hdd_ctx->hHal;
5898 struct qdf_mac_addr bssid;
5899 struct csr_roam_profile roam_profile;
5900 struct ch_params ch_params;
5901
5902 if (QDF_GLOBAL_MONITOR_MODE != hdd_get_conparam()) {
5903 hdd_err("Not supported, device is not in monitor mode");
5904 return -EINVAL;
5905 }
5906
Visweswara Tanuku006313a2018-04-12 12:26:34 +05305907 /* Validate Channel */
5908 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
5909 hdd_err("Channel %d Not supported", chan);
5910 return -EINVAL;
5911 }
5912
5913 if (WLAN_REG_IS_24GHZ_CH(chan)) {
5914 if (bandwidth == CH_WIDTH_80MHZ) {
5915 hdd_err("BW80 not possible in 2.4GHz band");
5916 return -EINVAL;
5917 }
5918 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
5919 (bandwidth != CH_WIDTH_MAX)) {
5920 hdd_err("Only BW20 possible on channel 14");
5921 return -EINVAL;
5922 }
5923 }
5924
5925 if (WLAN_REG_IS_5GHZ_CH(chan)) {
5926 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
5927 (bandwidth != CH_WIDTH_MAX)) {
5928 hdd_err("Only BW20 possible on channel 165");
5929 return -EINVAL;
5930 }
5931 }
5932
Jeff Johnsond9952752018-04-18 12:15:35 -07005933 hdd_debug("Set monitor mode Channel %d", chan);
5934 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
5935 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
5936 roam_profile.ChannelInfo.numOfChannels = 1;
5937 roam_profile.phyMode = ch_info->phy_mode;
5938 roam_profile.ch_params.ch_width = bandwidth;
5939 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
5940
5941 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
5942 QDF_MAC_ADDR_SIZE);
5943
5944 ch_params.ch_width = bandwidth;
5945 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
5946 if (ch_params.ch_width == CH_WIDTH_INVALID) {
5947 hdd_err("Invalid capture channel or bandwidth for a country");
5948 return -EINVAL;
5949 }
5950 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
5951 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
5952 hdd_err("Failed to change hw mode");
5953 return -EINVAL;
5954 }
5955
5956 status = sme_roam_channel_change_req(hal_hdl, bssid, &ch_params,
5957 &roam_profile);
5958 if (status) {
5959 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
5960 status);
5961 }
5962
5963 adapter->mon_chan = chan;
5964 adapter->mon_bandwidth = bandwidth;
5965 return qdf_status_to_os_return(status);
5966}
Nirav Shah73713f72018-05-17 14:50:41 +05305967#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305968
Wu Gaodf929f12018-05-25 18:12:25 +08005969#ifdef MSM_PLATFORM
5970/**
5971 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
5972 * @adapter: pointer to adapter
5973 *
5974 * This function calls cfg80211 API to stop P2P GO
5975 *
5976 * Return: None
5977 */
5978static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
5979{
5980 hdd_debug("[SSR] send stop ap to supplicant");
5981 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5982}
5983
5984static inline void hdd_delete_sta(struct hdd_adapter *adapter)
5985{
5986}
5987#else
5988static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
5989{
5990}
5991
5992/**
5993 * hdd_delete_sta() - call cfg80211 API to delete STA
5994 * @adapter: pointer to adapter
5995 *
5996 * This function calls cfg80211 API to delete STA
5997 *
5998 * Return: None
5999 */
6000static void hdd_delete_sta(struct hdd_adapter *adapter)
6001{
6002 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6003
6004 hdd_debug("[SSR] send restart supplicant");
6005 /* event supplicant to restart */
6006 cfg80211_del_sta(adapter->dev,
6007 (const u8 *)&bcast_mac.bytes[0],
6008 GFP_KERNEL);
6009}
6010#endif
6011
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006012QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006013{
Jeff Johnson9d295242017-08-29 14:39:48 -07006014 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015 eConnectionState connState;
6016
Dustin Brown491d54b2018-03-14 12:39:11 -07006017 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006018
Dustin Brown920397d2017-12-13 16:27:50 -08006019 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306020 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006021 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306022
Yue Ma42654682018-01-11 16:55:24 -08006023 hdd_debug("[SSR] start adapter with device mode %s(%d)",
6024 hdd_device_mode_to_string(adapter->device_mode),
6025 adapter->device_mode);
6026
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006027 hdd_wmm_init(adapter);
6028
6029 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006030 case QDF_STA_MODE:
6031 case QDF_P2P_CLIENT_MODE:
6032 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006033
6034 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6035 ->conn_info.connState;
6036
Krunal Sonib51eec72017-11-20 21:53:01 -08006037 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006038 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006039 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006040
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006041 /* Indicate disconnect event to supplicant
6042 * if associated previously
6043 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006045 eConnectionState_IbssConnected == connState ||
6046 eConnectionState_NotConnected == connState ||
6047 eConnectionState_IbssDisconnected == connState ||
6048 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006049 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006050
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006051 memset(&wrqu, '\0', sizeof(wrqu));
6052 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6053 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6054 wireless_send_event(adapter->dev, SIOCGIWAP,
6055 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006056 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006057 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006058
6059 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306060 wlan_hdd_cfg80211_indicate_disconnect(
6061 adapter->dev, false,
6062 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006063 } else if (eConnectionState_Connecting == connState) {
6064 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006065 * Indicate connect failure to supplicant if we
6066 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006067 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306068 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306069 NULL, 0, NULL, 0,
6070 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006071 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006072 }
6073
6074 hdd_register_tx_flow_control(adapter,
6075 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006076 hdd_tx_resume_cb,
6077 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006078
Alok Kumarb64650c2018-03-23 17:05:11 +05306079 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006080 break;
6081
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006082 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006083 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08006084 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306085
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006086 break;
6087
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006088 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006089 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006090 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306091 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006092 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306093 hdd_set_mon_rx_cb(adapter->dev);
6094 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6095 adapter->mon_bandwidth);
6096 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006097 default:
6098 break;
6099 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006100 /*
6101 * Action frame registered in one adapter which will
6102 * applicable to all interfaces
6103 */
6104 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006105 }
6106
Wu Gaodf929f12018-05-25 18:12:25 +08006107 hdd_for_each_adapter(hdd_ctx, adapter) {
6108 if (!hdd_is_interface_up(adapter))
6109 continue;
6110
6111 if (adapter->device_mode == QDF_P2P_GO_MODE)
6112 hdd_stop_p2p_go(adapter);
6113 }
6114
Dustin Browne74003f2018-03-14 12:51:58 -07006115 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006116
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306117 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006118}
6119
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006120QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006121 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006122{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306123 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006124 qdf_list_node_t *node;
6125
6126 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006127
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006128 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006129 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006130 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006131
6132 if (QDF_IS_STATUS_ERROR(status))
6133 return status;
6134
6135 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6136
6137 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006138}
6139
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006140QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006141 struct hdd_adapter *current_adapter,
6142 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006143{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306144 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006145 qdf_list_node_t *node;
6146
6147 *out_adapter = NULL;
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);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006150 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006151 &current_adapter->node,
6152 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006153 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006154
6155 if (QDF_IS_STATUS_ERROR(status))
6156 return status;
6157
6158 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6159
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006160 return status;
6161}
6162
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006163QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006164 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006165{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306166 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006167
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006168 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006169 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006170 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006171
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006172 return status;
6173}
6174
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006175QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006176 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006177{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306178 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006179 qdf_list_node_t *node;
6180
6181 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006182
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006183 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006184 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006185 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006186
6187 if (QDF_IS_STATUS_ERROR(status))
6188 return status;
6189
6190 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6191
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006192 return status;
6193}
6194
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006195QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006196 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006197{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306198 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006199
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006200 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006201 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006202 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006203
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204 return status;
6205}
6206
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006207QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006208 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306210 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006211
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006212 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006213 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006214 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006215
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006216 return status;
6217}
6218
Jeff Johnson9d295242017-08-29 14:39:48 -07006219struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220 tSirMacAddr macAddr)
6221{
Jeff Johnson9d295242017-08-29 14:39:48 -07006222 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006223
Dustin Brown920397d2017-12-13 16:27:50 -08006224 hdd_for_each_adapter(hdd_ctx, adapter) {
6225 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6226 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006227 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006228 }
6229
6230 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006231}
6232
Jeff Johnson9d295242017-08-29 14:39:48 -07006233struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234 uint32_t vdev_id)
6235{
Jeff Johnson9d295242017-08-29 14:39:48 -07006236 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006237
Dustin Brown920397d2017-12-13 16:27:50 -08006238 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006239 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241 }
6242
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006243 return NULL;
6244}
6245
Abhishek Singh7996eb72015-12-30 17:24:02 +05306246/**
6247 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6248 * the sessionid
6249 * @hdd_ctx: hdd context.
6250 * @sme_session_id: sme session is for the adapter to get.
6251 *
6252 * This function is used to get the adapter with provided session id
6253 *
6254 * Return: adapter pointer if found
6255 *
6256 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006257struct hdd_adapter *
6258hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6259 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306260{
Jeff Johnson9d295242017-08-29 14:39:48 -07006261 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306262
Dustin Brown920397d2017-12-13 16:27:50 -08006263 hdd_for_each_adapter(hdd_ctx, adapter) {
6264 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306265 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306266 }
Dustin Brown920397d2017-12-13 16:27:50 -08006267
Abhishek Singh7996eb72015-12-30 17:24:02 +05306268 return NULL;
6269}
6270
Jeff Johnson9d295242017-08-29 14:39:48 -07006271struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006272 const char *iface_name)
6273{
Jeff Johnson9d295242017-08-29 14:39:48 -07006274 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006275
Dustin Brown920397d2017-12-13 16:27:50 -08006276 hdd_for_each_adapter(hdd_ctx, adapter) {
6277 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006278 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006279 }
Dustin Brown920397d2017-12-13 16:27:50 -08006280
Naveen Rawat4edb6822017-04-12 10:09:17 -07006281 return NULL;
6282}
6283
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006284/**
6285 * hdd_get_adapter() - to get adapter matching the mode
6286 * @hdd_ctx: hdd context
6287 * @mode: adapter mode
6288 *
6289 * This routine will return the pointer to adapter matching
6290 * with the passed mode.
6291 *
6292 * Return: pointer to adapter or null
6293 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006294struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006295 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006296{
Jeff Johnson9d295242017-08-29 14:39:48 -07006297 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006298
Dustin Brown920397d2017-12-13 16:27:50 -08006299 hdd_for_each_adapter(hdd_ctx, adapter) {
6300 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006302 }
6303
6304 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006305}
6306
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006307enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306308{
6309 struct hdd_context *hdd_ctx;
6310 struct hdd_adapter *adapter;
6311
6312 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6313 if (!hdd_ctx) {
6314 hdd_err("Invalid HDD context");
6315 return QDF_MAX_NO_OF_MODE;
6316 }
6317
6318 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6319 if (!adapter) {
6320 hdd_err("Invalid HDD adapter");
6321 return QDF_MAX_NO_OF_MODE;
6322 }
6323
6324 return adapter->device_mode;
6325}
6326
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327/**
6328 * hdd_get_operating_channel() - return operating channel of the device mode
6329 * @hdd_ctx: Pointer to the HDD context.
6330 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006331 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006332 * QDF_STA_MODE,
6333 * QDF_P2P_CLIENT_MODE,
6334 * QDF_SAP_MODE,
6335 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006336 *
6337 * This API returns the operating channel of the requested device mode
6338 *
6339 * Return: channel number. "0" id the requested device is not found OR it is
6340 * not connected.
6341 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006342uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006343 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006344{
Jeff Johnson9d295242017-08-29 14:39:48 -07006345 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346 uint8_t operatingChannel = 0;
6347
Dustin Brown920397d2017-12-13 16:27:50 -08006348 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006349 if (mode == adapter->device_mode) {
6350 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006351 case QDF_STA_MODE:
6352 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006353 if (hdd_conn_is_connected
6354 (WLAN_HDD_GET_STATION_CTX_PTR
6355 (adapter))) {
6356 operatingChannel =
6357 (WLAN_HDD_GET_STATION_CTX_PTR
6358 (adapter))->conn_info.
6359 operationChannel;
6360 }
6361 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006362 case QDF_SAP_MODE:
6363 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006364 /* softap connection info */
6365 if (test_bit
6366 (SOFTAP_BSS_STARTED,
6367 &adapter->event_flags))
6368 operatingChannel =
6369 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006370 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006371 break;
6372 default:
6373 break;
6374 }
6375
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006376 /* Found the device of interest. break the loop */
6377 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006379 }
Dustin Brown920397d2017-12-13 16:27:50 -08006380
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006381 return operatingChannel;
6382}
6383
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006384static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006385 hdd_ctx)
6386{
Jeff Johnson9d295242017-08-29 14:39:48 -07006387 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006388
Dustin Brown491d54b2018-03-14 12:39:11 -07006389 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006390
Dustin Brown920397d2017-12-13 16:27:50 -08006391 hdd_for_each_adapter(hdd_ctx, adapter) {
6392 if (adapter->device_mode == QDF_STA_MODE ||
6393 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6394 adapter->device_mode == QDF_IBSS_MODE ||
6395 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6396 adapter->device_mode == QDF_SAP_MODE ||
6397 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006398 hdd_unregister_wext(adapter->dev);
6399 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006400 }
6401
Dustin Browne74003f2018-03-14 12:51:58 -07006402 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006403
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306404 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006405}
6406
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006407QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006408{
Jeff Johnson9d295242017-08-29 14:39:48 -07006409 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410
Dustin Brown491d54b2018-03-14 12:39:11 -07006411 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006412
Dustin Brown920397d2017-12-13 16:27:50 -08006413 hdd_for_each_adapter(hdd_ctx, adapter) {
6414 if (adapter->device_mode == QDF_STA_MODE ||
6415 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6416 adapter->device_mode == QDF_IBSS_MODE ||
6417 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6418 adapter->device_mode == QDF_SAP_MODE ||
6419 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006420 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006421 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306422 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006423 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006424 }
6425
Dustin Browne74003f2018-03-14 12:51:58 -07006426 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006427
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306428 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006429}
6430
Dustin Brownf27bce82016-11-03 12:52:27 -07006431/**
6432 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6433 * adapters
6434 * @hdd_ctx: The HDD context containing the adapters to operate on
6435 *
6436 * return: QDF_STATUS_SUCCESS
6437 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006438static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006439{
Jeff Johnson9d295242017-08-29 14:39:48 -07006440 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006441 int err;
6442
Dustin Brown491d54b2018-03-14 12:39:11 -07006443 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006444
Dustin Brown920397d2017-12-13 16:27:50 -08006445 hdd_for_each_adapter(hdd_ctx, adapter) {
6446 if (adapter->device_mode == QDF_STA_MODE ||
6447 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6448 adapter->device_mode == QDF_IBSS_MODE ||
6449 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6450 adapter->device_mode == QDF_SAP_MODE ||
6451 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006452 err = wlan_hdd_sched_scan_stop(adapter->dev);
6453 if (err)
6454 hdd_err("Unable to stop scheduled scan");
6455 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006456 }
6457
Dustin Browne74003f2018-03-14 12:51:58 -07006458 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006459
6460 return QDF_STATUS_SUCCESS;
6461}
6462
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006463#ifdef WLAN_NS_OFFLOAD
6464/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006465 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006466 * @hdd_ctx: Pointer to hdd context
6467 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006468 * Unregister for IPv6 address change notifications.
6469 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006470 * Return: None
6471 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006472static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006473{
6474 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006475}
6476
6477/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006478 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006479 * @hdd_ctx: Pointer to hdd context
6480 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006481 * Register for IPv6 address change notifications.
6482 *
6483 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006484 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006485static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006486{
6487 int ret;
6488
6489 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6490 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006491 if (ret) {
6492 hdd_err("Failed to register IPv6 notifier: %d", ret);
6493 goto out;
6494 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006495
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006496 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006497out:
6498 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006499}
6500#else
6501/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006502 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006503 * @hdd_ctx: Pointer to hdd context
6504 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006505 * Unregister for IPv6 address change notifications.
6506 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006507 * Return: None
6508 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006509static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006510{
6511}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006512
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006513/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006514 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006515 * @hdd_ctx: Pointer to hdd context
6516 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006517 * Register for IPv6 address change notifications.
6518 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006519 * Return: None
6520 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006521static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006523 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006524}
6525#endif
6526
Alok Kumarb64650c2018-03-23 17:05:11 +05306527void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6528{
6529 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6530 adapter->disconnection_in_progress = status;
6531 qdf_mutex_release(&adapter->disconnection_status_lock);
6532 hdd_debug("setting disconnection status: %d", status);
6533}
6534
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006535/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006536 * hdd_register_notifiers - Register netdev notifiers.
6537 * @hdd_ctx: HDD context
6538 *
6539 * Register netdev notifiers like IPv4 and IPv6.
6540 *
6541 * Return: 0 on success and errno on failure
6542 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006543static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006544{
6545 int ret;
6546
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006547 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6548 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306549 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006550
6551 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6552 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6553 if (ret) {
6554 hdd_err("Failed to register IPv4 notifier: %d", ret);
6555 goto unregister_ip6_notifier;
6556 }
6557
Alok Kumarb64650c2018-03-23 17:05:11 +05306558 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6559 if (ret) {
6560 hdd_err("Failed to register netevent notifier: %d",
6561 ret);
6562 goto unregister_inetaddr_notifier;
6563 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006564 return 0;
6565
Alok Kumarb64650c2018-03-23 17:05:11 +05306566unregister_inetaddr_notifier:
6567 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006568unregister_ip6_notifier:
6569 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006570out:
6571 return ret;
6572
6573}
6574
6575/**
6576 * hdd_unregister_notifiers - Unregister netdev notifiers.
6577 * @hdd_ctx: HDD context
6578 *
6579 * Unregister netdev notifiers like IPv4 and IPv6.
6580 *
6581 * Return: None.
6582 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006583void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006584{
Alok Kumarb64650c2018-03-23 17:05:11 +05306585 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006586 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6587
6588 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006589}
6590
6591/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006592 * hdd_exit_netlink_services - Exit netlink services
6593 * @hdd_ctx: HDD context
6594 *
6595 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6596 * nl service.
6597 *
6598 * Return: None.
6599 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006600static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006601{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006602 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006603 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006604 ptt_sock_deactivate_svc();
6605
6606 nl_srv_exit();
6607}
6608
6609/**
6610 * hdd_init_netlink_services- Init netlink services
6611 * @hdd_ctx: HDD context
6612 *
6613 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6614 * nl service.
6615 *
6616 * Return: 0 on success and errno on failure.
6617 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006618static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006619{
6620 int ret;
6621
Ryan Hsuceddceb2016-04-28 10:20:14 -07006622 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006623 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006624 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006625 goto out;
6626 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006627 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006628
Naveen Rawat910726a2017-03-06 11:42:51 -08006629 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006630 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006631 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006632 goto err_nl_srv;
6633 }
6634
6635 ret = ptt_sock_activate_svc();
6636 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006637 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006638 goto err_nl_srv;
6639 }
6640
6641 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006642 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006643 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006644
6645 ret = cnss_diag_activate_service();
6646 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006647 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006648 goto err_close_cesium;
6649 }
6650
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006651 ret = spectral_scan_activate_service();
6652 if (ret) {
Sandeep Puligilla8e89d572018-04-02 18:07:45 -07006653 hdd_err("spectral service initialization failed: %d", ret);
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006654 goto err_close_cesium;
6655 }
6656
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006657 return 0;
6658
6659err_close_cesium:
6660 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006661 ptt_sock_deactivate_svc();
6662err_nl_srv:
6663 nl_srv_exit();
6664out:
6665 return ret;
6666}
6667
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006668/**
6669 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6670 * @hdd_ctx: HDD context.
6671 *
6672 * Destroy RX wakelock.
6673 *
6674 * Return: None.
6675 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006676static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006677{
6678 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6679}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006680
6681/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006682 * hdd_rx_wake_lock_create() - Create RX wakelock
6683 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006684 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006685 * Create RX wakelock.
6686 *
6687 * Return: None.
6688 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006689static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006690{
6691 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6692}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006693
6694/**
Houston Hoffman160db392016-10-10 17:37:51 -07006695 * hdd_context_deinit() - Deinitialize HDD context
6696 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006697 *
Houston Hoffman160db392016-10-10 17:37:51 -07006698 * Deinitialize HDD context along with all the feature specific contexts but
6699 * do not free hdd context itself. Caller of this API is supposed to free
6700 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006701 *
Houston Hoffman160db392016-10-10 17:37:51 -07006702 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006703 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006704static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006705{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306706 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6707
Houston Hoffman160db392016-10-10 17:37:51 -07006708 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006709
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006710 hdd_sap_context_destroy(hdd_ctx);
6711
6712 hdd_rx_wake_lock_destroy(hdd_ctx);
6713
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006714 hdd_scan_context_destroy(hdd_ctx);
6715
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006716 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006717
Houston Hoffman160db392016-10-10 17:37:51 -07006718 return 0;
6719}
6720
6721/**
6722 * hdd_context_destroy() - Destroy HDD context
6723 * @hdd_ctx: HDD context to be destroyed.
6724 *
6725 * Free config and HDD context as well as destroy all the resources.
6726 *
6727 * Return: None
6728 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006729static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006730{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006731 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306732
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306733 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6734
Houston Hoffman160db392016-10-10 17:37:51 -07006735 hdd_context_deinit(hdd_ctx);
6736
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306737 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006738 hdd_ctx->config = NULL;
6739
6740 wiphy_free(hdd_ctx->wiphy);
6741}
6742
6743/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306744 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6745 *
6746 * This function is used to destroy bug report lock
6747 *
6748 * Return: None
6749 */
6750static void wlan_destroy_bug_report_lock(void)
6751{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07006752 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306753
6754 p_cds_context = cds_get_global_context();
6755 if (!p_cds_context) {
6756 hdd_err("cds context is NULL");
6757 return;
6758 }
6759
6760 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6761}
6762
6763/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006764 * hdd_wlan_exit() - HDD WLAN exit function
6765 * @hdd_ctx: Pointer to the HDD Context
6766 *
6767 * This is the driver exit point (invoked during rmmod)
6768 *
6769 * Return: None
6770 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006771static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006772{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306774 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775
Dustin Brown491d54b2018-03-14 12:39:11 -07006776 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006777
Arun Khandavallifae92942016-08-01 13:31:08 +05306778 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779
Prashanth Bhattaab004382016-10-11 16:08:11 -07006780 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006781
6782#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306783 if (QDF_TIMER_STATE_RUNNING ==
6784 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6785 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006786 }
6787
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306788 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306789 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006790 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006791 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006792 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6793 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6794 hdd_ctx->last_acs_channel_list = NULL;
6795 hdd_ctx->num_of_channels = 0;
6796 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006797#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798
Arun Khandavallifae92942016-08-01 13:31:08 +05306799 mutex_lock(&hdd_ctx->iface_change_lock);
6800 driver_status = hdd_ctx->driver_status;
6801 mutex_unlock(&hdd_ctx->iface_change_lock);
6802
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006803 /*
6804 * Powersave Offload Case
6805 * Disable Idle Power Save Mode
6806 */
6807 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006808 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306809 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006810
Arun Khandavallifae92942016-08-01 13:31:08 +05306811 if (driver_status != DRIVER_MODULES_CLOSED) {
6812 hdd_unregister_wext_all_adapters(hdd_ctx);
6813 /*
6814 * Cancel any outstanding scan requests. We are about to close
6815 * all of our adapters, but an adapter structure is what SME
6816 * passes back to our callback function. Hence if there
6817 * are any outstanding scan requests then there is a
6818 * race condition between when the adapter is closed and
6819 * when the callback is invoked. We try to resolve that
6820 * race condition here by canceling any outstanding scans
6821 * before we close the adapters.
6822 * Note that the scans may be cancelled in an asynchronous
6823 * manner, so ideally there needs to be some kind of
6824 * synchronization. Rather than introduce a new
6825 * synchronization here, we will utilize the fact that we are
6826 * about to Request Full Power, and since that is synchronized,
6827 * the expectation is that by the time Request Full Power has
6828 * completed, all scans will be cancelled
6829 */
6830 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006831 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006832 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006833 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006834 }
6835
Arunk Khandavalli830c9692018-03-22 12:17:40 +05306836 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306837 unregister_netdevice_notifier(&hdd_netdev_notifier);
6838
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006839 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306840
Dustin Brown021cecd2017-12-11 13:56:43 -08006841 hdd_driver_memdump_deinit();
6842
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306843 qdf_nbuf_deinit_replenish_timer();
6844
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306845 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6846 hdd_info("Release wakelock for monitor mode!");
6847 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6848 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6849 }
6850
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306851 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6852 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6853 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6854
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006855 /*
6856 * Close CDS
6857 * This frees pMac(HAL) context. There should not be any call
6858 * that requires pMac access after this.
6859 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006860
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006861 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -07006862 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006863
Dustin Brownd005ad82018-01-19 10:32:13 -08006864 hdd_close_all_adapters(hdd_ctx, false);
6865
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306866 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306867 /*
6868 * If there is re_init failure wiphy would have already de-registered
6869 * check the wiphy status before un-registering again
6870 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306871 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306872 wiphy_unregister(wiphy);
6873 wlan_hdd_cfg80211_deinit(wiphy);
6874 hdd_lpass_notify_stop(hdd_ctx);
6875 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006876
Arun Khandavallifae92942016-08-01 13:31:08 +05306877 hdd_exit_netlink_services(hdd_ctx);
6878 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306879#ifdef FEATURE_WLAN_CH_AVOID
6880 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6881#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306882
Abhishek Singhe9068f12017-03-31 14:14:52 +05306883 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6884 if (driver_status)
6885 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006886
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006887 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888}
6889
6890void __hdd_wlan_exit(void)
6891{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006892 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006893
Dustin Brown491d54b2018-03-14 12:39:11 -07006894 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006895
Anurag Chouhan6d760662016-02-20 16:05:43 +05306896 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006897 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006898 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07006899 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006900 return;
6901 }
6902
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006903 /* Do all the cleanup before deregistering the driver */
6904 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006905
Dustin Browne74003f2018-03-14 12:51:58 -07006906 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006907}
6908
6909#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006910/**
6911 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006912 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006913 *
6914 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6915 * Then new ACS request will do a fresh scan without reusing the cached
6916 * scan information.
6917 *
6918 * Return: void
6919 */
Tang Yingying523322d2017-01-17 23:28:43 +08006920static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006921{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006922 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006924 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006925 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006926 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6927 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6928 hdd_ctx->last_acs_channel_list = NULL;
6929 hdd_ctx->num_of_channels = 0;
6930 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006931
6932 if (!hdd_ctx->hHal)
6933 return;
6934 sme_scan_flush_result(hdd_ctx->hHal);
6935}
6936#endif
6937
6938#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006939int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6940 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006941{
6942 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306943 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006944 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006945
6946 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6947
6948 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306949 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006950 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006952 if (!hdd_ctx->hHal)
6953 return -EINVAL;
6954
Jeff Johnsone7672e72017-10-21 15:10:04 -07006955 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006956 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306957 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006958 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006959 return -EINVAL;
6960 }
6961
6962 return 0;
6963}
6964#endif
6965
6966/**
6967 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6968 * @state: state
6969 *
6970 * This function notifies FW with modem power status
6971 *
6972 * Return: 0 if successful, error number otherwise
6973 */
6974int hdd_wlan_notify_modem_power_state(int state)
6975{
6976 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306977 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006978 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006979
Anurag Chouhan6d760662016-02-20 16:05:43 +05306980 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006981 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306982 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006983 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306984
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006985 if (!hdd_ctx->hHal)
6986 return -EINVAL;
6987
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306988 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6989 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006990 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006991 state);
6992 return -EINVAL;
6993 }
6994 return 0;
6995}
6996
6997/**
6998 *
6999 * hdd_post_cds_enable_config() - HDD post cds start config helper
7000 * @adapter - Pointer to the HDD
7001 *
7002 * Return: None
7003 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007004QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007005{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307006 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007
7008 /*
7009 * Send ready indication to the HDD. This will kick off the MAC
7010 * into a 'running' state and should kick off an initial scan.
7011 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307012 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
7013 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007014 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7015 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307016 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007017 }
7018
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307019 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007020}
7021
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307022struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7023{
7024 struct hdd_adapter *adapter;
7025
7026 hdd_for_each_adapter(hdd_ctx, adapter) {
7027 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7028 return adapter;
7029 }
7030
7031 return NULL;
7032}
7033
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007034/* wake lock APIs for HDD */
7035void hdd_prevent_suspend(uint32_t reason)
7036{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307037 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007038}
7039
7040void hdd_allow_suspend(uint32_t reason)
7041{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307042 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007043}
7044
7045void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7046{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307047 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7048 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007049}
7050
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007051/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007052QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007053{
Amar Singhal5cccafe2017-02-15 12:42:58 -08007054
Amar Singhal6f8592b2017-04-26 14:31:58 -07007055 return sme_init_chan_list(hdd_ctx->hHal,
7056 hdd_ctx->reg.alpha2,
7057 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007058}
7059
7060/**
7061 * hdd_is_5g_supported() - check if hardware supports 5GHz
7062 * @hdd_ctx: Pointer to the hdd context
7063 *
7064 * HDD function to know if hardware supports 5GHz
7065 *
7066 * Return: true if hardware supports 5GHz
7067 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007068bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007069{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007070 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007071 return true;
7072
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007073 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007074 return true;
7075 else
7076 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007077}
7078
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007079static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007080{
7081 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007082 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007083
7084 wiphy = hdd_ctx->wiphy;
7085
7086 /*
7087 * The channel information in
7088 * wiphy needs to be initialized before wiphy registration
7089 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007090 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7091 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007092 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007093 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007094 }
7095
7096#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7097 wiphy->wowlan = &wowlan_support_reg_init;
7098#else
7099 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7100 WIPHY_WOWLAN_MAGIC_PKT |
7101 WIPHY_WOWLAN_DISCONNECT |
7102 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7103 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7104 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7105 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7106 WIPHY_WOWLAN_RFKILL_RELEASE;
7107
7108 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7109 WOW_MAX_FILTERS_PER_LIST);
7110 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7111 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7112#endif
7113
7114 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007115 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307116 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007117 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307118 return ret_val;
7119 }
7120
Amar Singhal2d812012018-02-03 15:06:47 +08007121 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007122
Amar Singhale4f28ee2015-10-21 14:36:56 -07007123 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007124}
7125
Mohit Khannaca4173b2017-09-12 21:52:19 -07007126#ifdef MSM_PLATFORM
7127/**
7128 * hdd_display_periodic_stats() - Function to display periodic stats
7129 * @hdd_ctx - handle to hdd context
7130 * @bool data_in_interval - true, if data detected in bw time interval
7131 *
7132 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7133 * Stats show up in wlan driver logs.
7134 *
7135 * Returns: None
7136 */
7137static inline
7138void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7139 bool data_in_interval)
7140{
7141 static u32 counter;
7142 static bool data_in_time_period;
7143 ol_txrx_pdev_handle pdev;
7144
7145 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7146 return;
7147
7148 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7149 if (!pdev) {
7150 hdd_err("pdev is NULL");
7151 return;
7152 }
7153
7154 counter++;
7155 if (data_in_interval)
7156 data_in_time_period = data_in_interval;
7157
7158 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7159 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7160 if (data_in_time_period) {
7161 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7162 CDP_TXRX_PATH_STATS,
7163 QDF_STATS_VERBOSITY_LEVEL_LOW);
7164 wlan_hdd_display_netif_queue_history
7165 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7166 qdf_dp_trace_dump_stats();
7167 }
7168 counter = 0;
7169 data_in_time_period = false;
7170 }
7171}
7172
Ravi Joshie2331e82015-07-01 18:18:54 -07007173/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007174 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7175 * @hdd_ctx: pointer to struct hdd_context
7176 *
7177 * Return: none
7178 */
7179static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7180{
7181 struct hdd_adapter *adapter;
7182
7183 hdd_for_each_adapter(hdd_ctx, adapter)
7184 hdd_send_rps_disable_ind(adapter);
7185}
7186
7187/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007188 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007189 * @hdd_ctx - handle to hdd context
7190 * @tx_packets - transmit packet count
7191 * @rx_packets - receive packet count
7192 *
7193 * The function controls the bus bandwidth and dynamic control of
7194 * tcp delayed ack configuration
7195 *
7196 * Returns: None
7197 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007198
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007199static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007200 const uint64_t tx_packets,
7201 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007202{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007203 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08007204 uint64_t temp_rx = 0;
7205 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007206 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007207 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007208 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007209 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007210 uint16_t index = 0;
7211 bool vote_level_change = false;
7212 bool rx_level_change = false;
7213 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007214
Mohit Khannaca4173b2017-09-12 21:52:19 -07007215 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007216 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007217 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007218 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007219 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007220 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007221 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007222 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007223
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007224 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007225 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7226 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007227 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007228 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007229 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007230 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7231 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307232 if (hdd_ctx->hbw_requested) {
7233 pld_remove_pm_qos(hdd_ctx->parent_dev);
7234 hdd_ctx->hbw_requested = false;
7235 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05307236 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007237 hdd_warn("low bandwidth set rx affinity fail");
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007238
7239 if (hdd_ctx->dynamic_rps)
7240 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007241 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307242 if (!hdd_ctx->hbw_requested) {
7243 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7244 hdd_ctx->hbw_requested = true;
7245 }
7246
Nirav Shah3bbfa512016-05-12 16:43:49 +05307247 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007248 hdd_warn("high bandwidth set rx affinity fail");
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007249
7250 if (hdd_ctx->dynamic_rps)
7251 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007252 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07007253 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007254 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007255
Mohit Khannaf8f96822017-05-17 17:11:59 -07007256 qdf_dp_trace_throttle_live_mode(
7257 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
7258
Mohit Khannae71e2262015-11-10 09:37:24 -08007259 /* fine-tuning parameters for RX Flows */
7260 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
7261
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007262 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007263
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307264 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07007265 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307266 else
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07007267 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307268
Ravi Joshifed83572016-10-07 16:20:37 -07007269 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
7270 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7271 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7272 next_rx_level = WLAN_SVC_TP_HIGH;
7273 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007274 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007275 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007276 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007277 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007278
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007279 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007280 struct wlan_rx_tp_data rx_tp_data = {0};
7281
Ravi Joshie2331e82015-07-01 18:18:54 -07007282 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007283 next_rx_level, temp_rx);
7284 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007285 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007286 /* Send throughput indication only if it is enabled.
7287 * Disabling tcp_del_ack will revert the tcp stack behavior
7288 * to default delayed ack. Note that this will disable the
7289 * dynamic delayed ack mechanism across the system
7290 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007291 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007292 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7293
Mohit Khanna6272fb682017-04-13 09:34:36 -07007294 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7295 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7296
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007297 rx_tp_data.level = next_rx_level;
7298 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7299 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7300 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007301 }
7302
Mohit Khannae71e2262015-11-10 09:37:24 -08007303 /* fine-tuning parameters for TX Flows */
7304 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7305 hdd_ctx->prev_tx = tx_packets;
7306 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7307 next_tx_level = WLAN_SVC_TP_HIGH;
7308 else
7309 next_tx_level = WLAN_SVC_TP_LOW;
7310
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007311 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7312 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007313 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7314 next_tx_level, temp_tx);
7315 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007316 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307317 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7318 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007319 &next_tx_level,
7320 sizeof(next_tx_level));
7321 }
7322
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007323 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007324 if (vote_level_change || tx_level_change || rx_level_change) {
7325 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7326 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7327 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7328 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7329 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7330 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7331 hdd_ctx->hdd_txrx_hist_idx++;
7332 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7333 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007334
7335 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007336}
7337
7338#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307339static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007340{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007341 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307342 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307343 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307344 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307345 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7346 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007347 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307348 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007349 bool connected = false;
7350 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7351
Prashanth Bhattaab004382016-10-11 16:08:11 -07007352 if (wlan_hdd_validate_context(hdd_ctx))
7353 return;
7354
Jeff Johnson214671b2017-10-30 19:45:23 -07007355 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007356 goto restart_timer;
7357
Dustin Brown920397d2017-12-13 16:27:50 -08007358 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307359 /*
7360 * Validate magic so we don't end up accessing
7361 * an invalid adapter.
7362 */
7363 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7364 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007365
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007366 if ((adapter->device_mode == QDF_STA_MODE ||
7367 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007368 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7369 != eConnectionState_Associated) {
7370
7371 continue;
7372 }
7373
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007374 if ((adapter->device_mode == QDF_SAP_MODE ||
7375 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007376 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007377
7378 continue;
7379 }
7380
7381 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7382 adapter->prev_tx_packets);
7383 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7384 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307385
7386 if (adapter->device_mode == QDF_SAP_MODE ||
7387 adapter->device_mode == QDF_P2P_GO_MODE ||
7388 adapter->device_mode == QDF_IBSS_MODE) {
7389
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007390 ret = cdp_get_intra_bss_fwd_pkts_count(
7391 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007392 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307393 &fwd_tx_packets, &fwd_rx_packets);
7394 if (ret == A_OK) {
7395 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7396 fwd_tx_packets,
7397 adapter->prev_fwd_tx_packets);
7398 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7399 fwd_tx_packets,
7400 adapter->prev_fwd_rx_packets);
7401 }
7402 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007403
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307404 if (adapter->device_mode == QDF_SAP_MODE)
7405 con_sap_adapter = adapter;
7406
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007407 total_rx += adapter->stats.rx_packets;
7408 total_tx += adapter->stats.tx_packets;
7409
7410 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7411 adapter->prev_tx_packets = adapter->stats.tx_packets;
7412 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307413 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7414 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007415 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7416 connected = true;
7417 }
7418
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007419 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007420 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007421 return;
7422 }
7423
Yun Parka29974a2018-04-09 12:05:49 -07007424 /* add intra bss forwarded tx and rx packets */
7425 tx_packets += fwd_tx_packets_diff;
7426 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007427
Yun Parka29974a2018-04-09 12:05:49 -07007428 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7429 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7430 &ipa_rx_packets);
7431 tx_packets += (uint64_t)ipa_tx_packets;
7432 rx_packets += (uint64_t)ipa_rx_packets;
7433
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307434 if (con_sap_adapter) {
7435 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7436 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7437 }
7438
Yun Parka29974a2018-04-09 12:05:49 -07007439 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7440 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7441 }
7442
7443 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007444
Jingxiang Gec64e1932017-08-22 14:38:59 +08007445restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007446 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007447 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007448 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307449 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007450 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007451 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007452}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007453
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307454/**
7455 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7456 * @arg: Argument of timer function
7457 *
7458 * Schedule a workqueue in this function where all the processing is done.
7459 *
7460 * Return: None.
7461 */
7462static void __hdd_bus_bw_cbk(void *arg)
7463{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007464 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307465
7466 if (wlan_hdd_validate_context(hdd_ctx))
7467 return;
7468
7469 schedule_work(&hdd_ctx->bus_bw_work);
7470}
7471
7472/**
7473 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7474 * @arg: Argument of timer function
7475 *
7476 * Return: None.
7477 */
7478static void hdd_bus_bw_cbk(void *arg)
7479{
7480 cds_ssr_protect(__func__);
7481 __hdd_bus_bw_cbk(arg);
7482 cds_ssr_unprotect(__func__);
7483}
7484
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007485int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007486{
7487 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307488 INIT_WORK(&hdd_ctx->bus_bw_work,
7489 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007490 hdd_ctx->bus_bw_timer_running = false;
7491 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307492 qdf_timer_init(NULL,
7493 &hdd_ctx->bus_bw_timer,
7494 hdd_bus_bw_cbk, (void *)hdd_ctx,
7495 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007496
7497 return 0;
7498}
7499
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007500void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007501{
Dustin Brownfce08d12017-01-17 16:29:38 -08007502 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007503 hdd_reset_tcp_delack(hdd_ctx);
7504
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007505 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307506 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307507 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007508 hdd_ctx->bus_bw_timer_running = false;
7509 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007510}
Lin Baic5c06882017-09-21 13:58:43 +08007511
7512void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7513{
7514 if (hdd_ctx)
7515 cancel_work_sync(&hdd_ctx->bus_bw_work);
7516}
jiadcdaf9bd2017-10-26 12:20:21 +08007517
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007518#endif
7519
7520/**
Nirav Shahed34b212016-04-25 10:59:16 +05307521 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7522 * @hdd_ctx: hdd context
7523 *
7524 * Return: 0 for success or error code
7525 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007526static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307527{
7528 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7529 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7530 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007531 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307532 return -ENOMEM;
7533 }
7534 return 0;
7535}
7536
7537/**
7538 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7539 * @hdd_ctx: hdd context
7540 *
7541 * Return: none
7542 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007543void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307544{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307545 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7546 return;
7547
7548 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7549 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307550}
7551
Nirav Shahda008342016-05-17 18:50:40 +05307552static uint8_t *convert_level_to_string(uint32_t level)
7553{
7554 switch (level) {
7555 /* initialize the wlan sub system */
7556 case WLAN_SVC_TP_NONE:
7557 return "NONE";
7558 case WLAN_SVC_TP_LOW:
7559 return "LOW";
7560 case WLAN_SVC_TP_MEDIUM:
7561 return "MED";
7562 case WLAN_SVC_TP_HIGH:
7563 return "HIGH";
7564 default:
7565 return "INVAL";
7566 }
7567}
7568
Nirav Shahed34b212016-04-25 10:59:16 +05307569
7570/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7572 * @hdd_ctx: hdd context
7573 *
7574 * Return: none
7575 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007576void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007577{
7578 int i;
7579
7580#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007581 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307582 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007583 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007584 hdd_ctx->config->busBandwidthHighThreshold,
7585 hdd_ctx->config->busBandwidthMediumThreshold,
7586 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007587 hdd_debug("Enable TCP DEL ACK: %d",
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007588 hdd_ctx->en_tcp_delack_no_lro);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007589 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007590 hdd_ctx->config->tcpDelackThresholdHigh,
7591 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007592 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307593 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007594#endif
7595
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007596 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307597 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7598
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007599 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007600
7601 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007602 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007603 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007604 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7605 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7606 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7607 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7608 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007609 hdd_ctx->hdd_txrx_hist[i].
7610 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007611 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007612 hdd_ctx->hdd_txrx_hist[i].
7613 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007614 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007615 hdd_ctx->hdd_txrx_hist[i].
7616 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007617 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007618}
7619
7620/**
7621 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7622 * @hdd_ctx: hdd context
7623 *
7624 * Return: none
7625 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007626void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627{
7628 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307629 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7630 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631}
7632
Mohit Khannaca4173b2017-09-12 21:52:19 -07007633/* length of the netif queue log needed per adapter */
7634#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7635
7636/**
7637 *
7638 * hdd_display_netif_queue_history_compact() - display compact netifq history
7639 * @hdd_ctx: hdd context
7640 *
7641 * Return: none
7642 */
7643static void
7644hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7645{
7646 int adapter_num = 0;
7647 int i;
7648 int bytes_written;
7649 u32 tbytes;
7650 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007651 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007652 char *comb_log_str;
7653 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007654 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007655
jiadbdefb252018-01-03 14:27:06 +08007656 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7657 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7658 if (!comb_log_str) {
7659 hdd_err("failed to alloc comb_log_str");
7660 return;
7661 }
7662
Mohit Khannaca4173b2017-09-12 21:52:19 -07007663 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007664
Dustin Brown920397d2017-12-13 16:27:50 -08007665 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007666 curr_time = qdf_system_ticks();
7667 total = curr_time - adapter->start_time;
7668 delta = curr_time - adapter->last_time;
7669
7670 if (adapter->pause_map) {
7671 pause = adapter->total_pause_time + delta;
7672 unpause = adapter->total_unpause_time;
7673 } else {
7674 unpause = adapter->total_unpause_time + delta;
7675 pause = adapter->total_pause_time;
7676 }
7677
7678 tbytes = 0;
7679 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7680 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7681 if (adapter->queue_oper_stats[i].pause_count == 0)
7682 continue;
7683 tbytes +=
7684 snprintf(
7685 &temp_str[tbytes],
7686 (tbytes >= sizeof(temp_str) ?
7687 0 : sizeof(temp_str) - tbytes),
7688 "%d(%d,%d) ",
7689 i,
7690 adapter->queue_oper_stats[i].
7691 pause_count,
7692 adapter->queue_oper_stats[i].
7693 unpause_count);
7694 }
7695 if (tbytes >= sizeof(temp_str))
7696 hdd_warn("log truncated");
7697
7698 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007699 bytes_written >= comb_log_str_size ? 0 :
7700 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007701 "[%d %d] (%d) %u/%ums %s|",
7702 adapter->session_id, adapter->device_mode,
7703 adapter->pause_map,
7704 qdf_system_ticks_to_msecs(pause),
7705 qdf_system_ticks_to_msecs(total),
7706 temp_str);
7707
Mohit Khannaca4173b2017-09-12 21:52:19 -07007708 adapter_num++;
7709 }
7710
7711 /* using QDF_TRACE to avoid printing function name */
7712 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7713 "STATS |%s", comb_log_str);
7714
jiadbdefb252018-01-03 14:27:06 +08007715 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007716 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007717
7718 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007719}
7720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007721/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007722 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007723 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007724 *
7725 * Return: none
7726 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007727void
7728wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7729 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007730{
7731
Jeff Johnson9d295242017-08-29 14:39:48 -07007732 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007733 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307734 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007735
Mohit Khannaca4173b2017-09-12 21:52:19 -07007736 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7737 hdd_display_netif_queue_history_compact(hdd_ctx);
7738 return;
7739 }
7740
Dustin Brown920397d2017-12-13 16:27:50 -08007741 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007742 hdd_debug("Netif queue operation statistics:");
7743 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007744 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007745 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307746 curr_time = qdf_system_ticks();
7747 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307748 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307749 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307750 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307751 unpause = adapter->total_unpause_time;
7752 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307753 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307754 pause = adapter->total_pause_time;
7755 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007756 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307757 qdf_system_ticks_to_msecs(total),
7758 qdf_system_ticks_to_msecs(pause),
7759 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007760 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007761
Nirav Shahda008342016-05-17 18:50:40 +05307762 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7763 qdf_time_t pause_delta = 0;
7764
7765 if (adapter->pause_map & (1 << i))
7766 pause_delta = delta;
7767
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007768 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007769 hdd_debug("%s: %d: %d: %ums",
7770 hdd_reason_type_to_string(i),
7771 adapter->queue_oper_stats[i].pause_count,
7772 adapter->queue_oper_stats[i].unpause_count,
7773 qdf_system_ticks_to_msecs(
7774 adapter->queue_oper_stats[i].total_pause_time +
7775 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007776 }
7777
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007778 hdd_debug("Netif queue operation history:");
7779 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307780 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7781
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007782 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007783
7784 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007785 /* using hdd_log to avoid printing function name */
7786 if (adapter->queue_oper_history[i].time == 0)
7787 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007788 hdd_debug("%d: %u: %s: %s: %x",
7789 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007790 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007791 hdd_action_type_to_string(
7792 adapter->queue_oper_history[i].netif_action),
7793 hdd_reason_type_to_string(
7794 adapter->queue_oper_history[i].netif_reason),
7795 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007796 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007797 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007798}
7799
7800/**
7801 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7802 * @hdd_ctx: hdd context
7803 *
7804 * Return: none
7805 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007806void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007807{
Jeff Johnson9d295242017-08-29 14:39:48 -07007808 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007809
Dustin Brown920397d2017-12-13 16:27:50 -08007810 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307811 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007812 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307813 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007814 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307815 adapter->history_index = 0;
7816 adapter->start_time = adapter->last_time = qdf_system_ticks();
7817 adapter->total_pause_time = 0;
7818 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007819 }
7820}
7821
7822/**
7823 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7824 * @halHandle: Hal handle
7825 * @pContext: Pointer to the context
7826 * @sessionId: Session ID
7827 * @scanId: Scan ID
7828 * @status: Status
7829 *
7830 * This is the callback to be executed when 11d scan is completed to flush out
7831 * the scan results
7832 *
7833 * 11d scan is done during driver load and is a passive scan on all
7834 * channels supported by the device, 11d scans may find some APs on
7835 * frequencies which are forbidden to be used in the regulatory domain
7836 * the device is operating in. If these APs are notified to the supplicant
7837 * it may try to connect to these APs, thus flush out all the scan results
7838 * which are present in SME after 11d scan is done.
7839 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307840 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007841 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307842static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007843 uint8_t sessionId, uint32_t scanId,
7844 eCsrScanStatus status)
7845{
Dustin Brown491d54b2018-03-14 12:39:11 -07007846 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007847
7848 sme_scan_flush_result(halHandle);
7849
Dustin Browne74003f2018-03-14 12:51:58 -07007850 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007851
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307852 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007853}
7854
7855#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7856/**
7857 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7858 * @hdd_ctx: hdd global context
7859 *
7860 * Return: none
7861 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007862static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007863{
7864 uint8_t i;
7865
7866 mutex_init(&hdd_ctx->op_ctx.op_lock);
7867 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7868 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7869 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7870 }
7871}
7872#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007873static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007874{
7875}
7876#endif
7877
Yingying Tang95409972016-10-20 15:16:15 +08007878#ifdef WLAN_FEATURE_WOW_PULSE
7879/**
7880 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007881 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007882 * @enable: enable or disable this behaviour
7883 *
7884 * Return: int
7885 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007886static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007887{
7888 struct hdd_config *pcfg_ini = phddctx->config;
7889 struct wow_pulse_mode wow_pulse_set_info;
7890 QDF_STATUS status;
7891
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007892 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007893
7894 if (false == phddctx->config->wow_pulse_support)
7895 return 0;
7896
7897 /* prepare the request to send to SME */
7898 if (enable == true) {
7899 wow_pulse_set_info.wow_pulse_enable = true;
7900 wow_pulse_set_info.wow_pulse_pin =
7901 pcfg_ini->wow_pulse_pin;
7902 wow_pulse_set_info.wow_pulse_interval_low =
7903 pcfg_ini->wow_pulse_interval_low;
7904 wow_pulse_set_info.wow_pulse_interval_high =
7905 pcfg_ini->wow_pulse_interval_high;
7906 } else {
7907 wow_pulse_set_info.wow_pulse_enable = false;
7908 wow_pulse_set_info.wow_pulse_pin = 0;
7909 wow_pulse_set_info.wow_pulse_interval_low = 0;
7910 wow_pulse_set_info.wow_pulse_interval_high = 0;
7911 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007912 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007913 wow_pulse_set_info.wow_pulse_enable,
7914 wow_pulse_set_info.wow_pulse_pin,
7915 wow_pulse_set_info.wow_pulse_interval_low,
7916 wow_pulse_set_info.wow_pulse_interval_high);
7917
7918 status = sme_set_wow_pulse(&wow_pulse_set_info);
7919 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007920 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007921 return -EIO;
7922 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007923 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007924 return 0;
7925}
7926#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007927static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007928{
7929 return 0;
7930}
7931#endif
7932
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007933#ifdef WLAN_FEATURE_FASTPATH
7934/**
7935 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7936 * @hdd_cfg: hdd config
7937 * @context: lower layer context
7938 *
7939 * Return: none
7940 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307941void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007942 void *context)
7943{
7944 if (hdd_cfg->fastpath_enable)
7945 hif_enable_fastpath(context);
7946}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007947#endif
7948
Yuanyuan Liu13738502016-04-06 17:41:37 -07007949#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007950/**
7951 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007952 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007953 * @level: thermal level
7954 *
7955 * Change IPA data path to SW path when the thermal throttle level greater
7956 * than 0, and restore the original data path when throttle level is 0
7957 *
7958 * Return: none
7959 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007960static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007961{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007962 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007963
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007964 /* Change IPA to SW path when throttle level greater than 0 */
7965 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307966 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007967 else
7968 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307969 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007970}
7971
7972/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307973 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7974 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307975 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007976 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307977 * Get a safe channel to restart SAP. PCL already takes into account the
7978 * unsafe channels. So, the PCL is validated with the ACS range to provide
7979 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007980 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307981 * Return: Channel number to restart SAP in case of success. In case of any
7982 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007983 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307984static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007985 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007986{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307987 struct sir_pcl_list pcl;
7988 QDF_STATUS status;
7989 uint32_t i, j;
Jeff Johnson796b9a72018-06-01 17:12:32 -07007990 tHalHandle hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007991 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307992 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007993 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007994
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307995 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7996 if (!hdd_ctx) {
7997 hdd_err("invalid HDD context");
7998 return INVALID_CHANNEL_ID;
7999 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008000
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308001 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
8002 if (!hal_handle) {
8003 hdd_err("invalid HAL handle");
8004 return INVALID_CHANNEL_ID;
8005 }
8006
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008007 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
8008 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008009 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8010 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308011 if (QDF_IS_STATUS_ERROR(status)) {
8012 hdd_err("Get PCL failed");
8013 return INVALID_CHANNEL_ID;
8014 }
8015
Frank Liudc2cefb2017-06-21 15:38:18 +08008016 /*
8017 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8018 * channel is unsafe channel, the pcl may be empty, instead of return,
8019 * try to choose a safe channel from acs range.
8020 */
8021 if (!pcl.pcl_len)
8022 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308023
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008024 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008025 adapter->session.ap.sap_config.acs_cfg.start_ch,
8026 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308027
8028 /* PCL already takes unsafe channel into account */
8029 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008030 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308031 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008032 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308033 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008034 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008035 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308036 return pcl.pcl_list[i];
8037 }
8038 }
8039
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008040 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308041
8042 /* Try for safe channel from all valid channel */
8043 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05008044 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8045 &pcl.pcl_len);
8046 if (ret) {
8047 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308048 return INVALID_CHANNEL_ID;
8049 }
8050
8051 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008052 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308053 found = false;
8054 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07008055 if (pcl.pcl_list[i] ==
8056 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008057 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308058 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008059 break;
8060 }
8061 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308062
8063 if (found)
8064 continue;
8065
8066 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008067 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308068 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008069 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008070 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308071 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008072 }
8073 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308074
8075 return INVALID_CHANNEL_ID;
8076}
Nirav Shaheb017be2018-02-15 11:20:58 +05308077#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308078
8079/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008080 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308081 * @adapter: AP adapter
8082 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008083 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308084 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008085 * Moves the SAP interface by invoking the function which
8086 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308087 *
8088 * Return: None
8089 */
Min Liu2fef5792018-01-19 17:59:42 +08008090void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8091 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308092{
Jeff Johnson87251032017-08-29 13:31:11 -07008093 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnson796b9a72018-06-01 17:12:32 -07008094 tHalHandle hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008095 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308096
8097 if (!adapter) {
8098 hdd_err("invalid adapter");
8099 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008100 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308101
8102 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8103
8104 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
8105 if (!hal_handle) {
8106 hdd_err("invalid HAL handle");
8107 return;
8108 }
8109
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008110 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8111
Jeff Johnson91df29d2017-10-27 19:29:50 -07008112 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308113 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308114
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008115 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008116 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308117
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07008118 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07008119 hdd_ap_ctx->sap_config.channel,
8120 hdd_ap_ctx->sap_config.sec_ch,
8121 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308122
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008123 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008124 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008125 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008126}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308127
Jeff Johnson9d295242017-08-29 14:39:48 -07008128int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308129{
8130 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308131 int status;
8132 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308133
8134 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8135
8136 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008137 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308138 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008139 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308140 }
8141 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008142 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308143 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308144 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008145 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308146 WLAN_VENDOR_ACS_WAIT_TIME);
8147 if (qdf_status != QDF_STATUS_SUCCESS) {
8148 hdd_err("failed to start external acs timer");
8149 return -ENOSPC;
8150 }
8151 /* Update config to application */
8152 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008153 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308154
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308155 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308156}
8157
Nirav Shaheb017be2018-02-15 11:20:58 +05308158#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308159/**
8160 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8161 * @hdd_ctx: hdd context pointer
8162 *
8163 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8164 * and if ACS is enabled, driver will ask userspace to restart the
8165 * sap. User space on LTE coex indication restart driver.
8166 *
8167 * Return - none
8168 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008169void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308170{
Dustin Brown920397d2017-12-13 16:27:50 -08008171 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308172 uint32_t i;
8173 bool found = false;
8174 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008175
Dustin Brown920397d2017-12-13 16:27:50 -08008176 hdd_for_each_adapter(hdd_ctxt, adapter) {
8177 if (!(adapter->device_mode == QDF_SAP_MODE &&
8178 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008179 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008180 adapter->device_mode,
8181 adapter->session.ap.sap_config.
8182 acs_cfg.acs_mode);
8183 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308184 }
8185
8186 found = false;
8187 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08008188 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05308189 hdd_ctxt->unsafe_channel_list[i]) {
8190 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008191 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08008192 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308193 break;
8194 }
8195 }
8196
8197 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008198 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008199 adapter->session.ap.operating_channel);
8200 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308201 }
8202
Kapil Gupta8878ad92017-02-13 11:56:04 +05308203 if (hdd_ctxt->config->vendor_acs_support &&
8204 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008205 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308206 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008207 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308208 } else
8209 restart_chan =
8210 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008211 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308212 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008213 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308214 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008215 /*
8216 * SAP restart due to unsafe channel. While
8217 * restarting the SAP, make sure to clear
8218 * acs_channel, channel to reset to
8219 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308220 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008221 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308222 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008223 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308224 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008225 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308226 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8227 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008228 hdd_debug("driver to start sap: %d",
8229 hdd_ctxt->config->sap_internal_restart);
8230 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008231 hdd_switch_sap_channel(adapter, restart_chan,
8232 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008233 else
8234 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308235 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308236 }
8237}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308238
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008239/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008240 * hdd_init_channel_avoidance() - Initialize channel avoidance
8241 * @hdd_ctx: HDD global context
8242 *
8243 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008244 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008245 * down to the lower layers. Then subscribe to subsequent channel
8246 * avoidance events.
8247 *
8248 * Return: None
8249 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008250static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008251{
8252 uint16_t unsafe_channel_count;
8253 int index;
8254
Yuanyuan Liu13738502016-04-06 17:41:37 -07008255 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8256 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008257 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008258 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008259
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008260 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008261 hdd_ctx->unsafe_channel_count);
8262
Anurag Chouhan6d760662016-02-20 16:05:43 +05308263 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008264 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008265
8266 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008267 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008268 hdd_ctx->unsafe_channel_list[index]);
8269
8270 }
8271
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008272}
Dustin Brown676a2322017-08-15 13:16:13 -07008273
Jeff Johnson9d295242017-08-29 14:39:48 -07008274static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008275 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008276{
8277 uint8_t restart_chan;
8278
8279 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8280 if (!restart_chan) {
8281 hdd_alert("fail to restart SAP");
8282 return;
8283 }
8284
8285 /* SAP restart due to unsafe channel. While restarting
8286 * the SAP, make sure to clear acs_channel, channel to
8287 * reset to 0. Otherwise these settings will override
8288 * the ACS while restart.
8289 */
8290 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008291 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008292
8293 hdd_debug("sending coex indication");
8294
8295 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8296 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008297 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008298}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008299
8300int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8301 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8302{
8303 uint32_t size;
8304 uint16_t *unsafe_list;
8305 uint16_t chan_count;
8306
8307 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8308 return -EINVAL;
8309
8310 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8311 NUM_CHANNELS);
8312 if (chan_count) {
8313 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8314 unsafe_list = qdf_mem_malloc(size);
8315 if (!unsafe_list) {
8316 hdd_err("No memory for unsafe chan list size%d",
8317 size);
8318 return -ENOMEM;
8319 }
8320 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8321 } else {
8322 unsafe_list = NULL;
8323 }
8324
8325 *local_unsafe_list = unsafe_list;
8326 *local_unsafe_list_count = chan_count;
8327
8328 return 0;
8329}
8330
8331bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8332 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8333{
8334 int i, j;
8335
8336 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8337 return true;
8338 if (local_unsafe_list_count == 0)
8339 return false;
8340 for (i = 0; i < local_unsafe_list_count; i++) {
8341 for (j = 0; j < local_unsafe_list_count; j++)
8342 if (local_unsafe_list[i] ==
8343 hdd_ctx->unsafe_channel_list[j])
8344 break;
8345 if (j >= local_unsafe_list_count)
8346 break;
8347 }
8348 if (i >= local_unsafe_list_count) {
8349 hdd_info("unsafe chan list same");
8350 return false;
8351 }
8352
8353 return true;
8354}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008355#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008356static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008357{
8358}
Dustin Brown676a2322017-08-15 13:16:13 -07008359
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008360static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008361{
8362}
Dustin Brown676a2322017-08-15 13:16:13 -07008363
Jeff Johnson9d295242017-08-29 14:39:48 -07008364static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008365 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008366{
8367 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8368}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008369#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008370
8371/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008372 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8373 * user space
8374 * @frame_ind: Management frame data to be informed.
8375 *
8376 * This function is used to indicate management frame to
8377 * user space
8378 *
8379 * Return: None
8380 *
8381 */
8382void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8383{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008384 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008385 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008386 int i;
8387
Dustin Browne7e71d32018-05-11 16:00:08 -07008388 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8389 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008390 return;
8391
8392 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8393 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8394 adapter =
8395 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8396 if (adapter)
8397 break;
8398 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008399 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8400 hdd_for_each_adapter(hdd_ctx, adapter) {
8401 if ((NULL != adapter) &&
8402 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8403 __hdd_indicate_mgmt_frame(adapter,
8404 frame_ind->frame_len,
8405 frame_ind->frameBuf,
8406 frame_ind->frameType,
8407 frame_ind->rxChan,
8408 frame_ind->rxRssi);
8409 }
8410 }
8411 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008412 } else {
8413 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8414 frame_ind->sessionId);
8415 }
8416
8417 if ((NULL != adapter) &&
8418 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8419 __hdd_indicate_mgmt_frame(adapter,
8420 frame_ind->frame_len,
8421 frame_ind->frameBuf,
8422 frame_ind->frameType,
8423 frame_ind->rxChan,
8424 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008425}
8426
Kapil Gupta8878ad92017-02-13 11:56:04 +05308427void hdd_acs_response_timeout_handler(void *context)
8428{
8429 struct hdd_external_acs_timer_context *timer_context =
8430 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008431 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008432 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308433 uint8_t reason;
8434
Dustin Brown491d54b2018-03-14 12:39:11 -07008435 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308436 if (!timer_context) {
8437 hdd_err("invlaid timer context");
8438 return;
8439 }
8440 adapter = timer_context->adapter;
8441 reason = timer_context->reason;
8442
8443
8444 if ((!adapter) ||
8445 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8446 hdd_err("invalid adapter or adapter has invalid magic");
8447 return;
8448 }
8449 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8450 if (wlan_hdd_validate_context(hdd_ctx))
8451 return;
8452
8453 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8454 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8455 else
8456 return;
8457
8458 hdd_err("ACS timeout happened for %s reason %d",
8459 adapter->dev->name, reason);
8460 switch (reason) {
8461 /* SAP init case */
8462 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8463 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8464 false);
8465 wlan_hdd_cfg80211_start_acs(adapter);
8466 break;
8467 /* DFS detected on current channel */
8468 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8469 wlan_sap_update_next_channel(
8470 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8471 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008472 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308473 break;
8474 /* LTE coex event on current channel */
8475 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8476 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8477 break;
8478 default:
8479 hdd_info("invalid reason for timer invoke");
8480
8481 }
8482}
8483
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008484/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008485 * hdd_override_ini_config - Override INI config
8486 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008487 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008488 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008489 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008490 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008491 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008492static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008493{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008494
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008495 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8496 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008497 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008498 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008499 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008500 if (0 == enable_11d || 1 == enable_11d) {
8501 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008502 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008503 }
Leo Chang11545d62016-10-17 14:53:50 -07008504
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308505 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008506 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008507 hdd_debug("IpaConfig override to %d",
8508 hdd_ctx->config->IpaConfig);
8509 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308510
8511 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8512 !hdd_ctx->config->enable_bcast_probe_rsp) {
8513 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8514 hdd_ctx->config->rssi_assoc_reject_enabled,
8515 hdd_ctx->config->enable_bcast_probe_rsp);
8516 hdd_ctx->config->oce_sta_enabled = 0;
8517 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008518}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008519
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008520/**
8521 * hdd_set_trace_level_for_each - Set trace level for each INI config
8522 * @hdd_ctx - HDD context
8523 *
8524 * Set trace level for each module based on INI config.
8525 *
8526 * Return: None
8527 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008528static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008529{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308530 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8531 hdd_ctx->config->qdf_trace_enable_wdi);
8532 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8533 hdd_ctx->config->qdf_trace_enable_hdd);
8534 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8535 hdd_ctx->config->qdf_trace_enable_sme);
8536 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8537 hdd_ctx->config->qdf_trace_enable_pe);
8538 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8539 hdd_ctx->config->qdf_trace_enable_wma);
8540 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8541 hdd_ctx->config->qdf_trace_enable_sys);
8542 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8543 hdd_ctx->config->qdf_trace_enable_qdf);
8544 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8545 hdd_ctx->config->qdf_trace_enable_sap);
8546 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8547 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8548 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8549 hdd_ctx->config->qdf_trace_enable_bmi);
8550 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8551 hdd_ctx->config->qdf_trace_enable_cfg);
8552 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8553 hdd_ctx->config->qdf_trace_enable_epping);
8554 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8555 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8556 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008557 hdd_ctx->config->qdf_trace_enable_txrx);
8558 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8559 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308560 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8561 hdd_ctx->config->qdf_trace_enable_htc);
8562 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8563 hdd_ctx->config->qdf_trace_enable_hif);
8564 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8565 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8566 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8567 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008568 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8569 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008570 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8571 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008572 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8573 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008574 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8575 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008576
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008577 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008578}
8579
8580/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008581 * hdd_context_init() - Initialize HDD context
8582 * @hdd_ctx: HDD context.
8583 *
8584 * Initialize HDD context along with all the feature specific contexts.
8585 *
8586 * return: 0 on success and errno on failure.
8587 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008588static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008589{
8590 int ret;
8591
8592 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8593 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8594
8595 hdd_init_ll_stats_ctx();
8596
8597 init_completion(&hdd_ctx->mc_sus_event_var);
8598 init_completion(&hdd_ctx->ready_to_suspend);
8599
8600 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308601 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008602 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308603
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008604 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008605
8606 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8607
8608 ret = hdd_scan_context_init(hdd_ctx);
8609 if (ret)
8610 goto list_destroy;
8611
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008612 hdd_rx_wake_lock_create(hdd_ctx);
8613
8614 ret = hdd_sap_context_init(hdd_ctx);
8615 if (ret)
8616 goto scan_destroy;
8617
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008618 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8619
8620 hdd_init_offloaded_packets_ctx(hdd_ctx);
8621
8622 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8623 hdd_ctx->config);
8624 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008625 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008626
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308627 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8628 "monitor_mode_wakelock");
8629
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008630 return 0;
8631
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008632sap_destroy:
8633 hdd_sap_context_destroy(hdd_ctx);
8634
8635scan_destroy:
8636 hdd_scan_context_destroy(hdd_ctx);
8637 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008638list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008639 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008640
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008641 return ret;
8642}
8643
8644/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308645 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8646 * @hdd_ctx: pointer to hdd context
8647 *
8648 * Return: status of initialization
8649 * 0 - success
8650 * negative value - failure
8651 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008652static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308653{
8654 int ret;
8655
8656 if (!hdd_ctx->config->probe_req_ie_whitelist)
8657 return 0;
8658
8659 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8660 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8661 hdd_ctx->config->probe_req_ie_whitelist = false;
8662 return -EINVAL;
8663 }
8664
8665 /* parse ini string probe req oui */
8666 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8667 if (ret) {
8668 hdd_err("parsing error: disable ie whitelisting");
8669 hdd_ctx->config->probe_req_ie_whitelist = false;
8670 }
8671
8672 return ret;
8673}
8674
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308675/**
8676 * hdd_iface_change_callback() - Function invoked when stop modules expires
8677 * @priv: pointer to hdd context
8678 *
8679 * This function is invoked when the timer waiting for the interface change
8680 * expires, it shall cut-down the power to wlan and stop all the modules.
8681 *
8682 * Return: void
8683 */
8684static void hdd_iface_change_callback(void *priv)
8685{
8686 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8687 int ret;
8688 int status = wlan_hdd_validate_context(hdd_ctx);
8689
8690 if (status)
8691 return;
8692
Dustin Brown491d54b2018-03-14 12:39:11 -07008693 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308694 hdd_debug("Interface change timer expired close the modules!");
8695 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8696 if (ret)
8697 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008698 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308699}
8700
Nirav Shaheb017be2018-02-15 11:20:58 +05308701#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8702static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8703{
8704 wlan_logging_set_log_to_console(hdd_ctx->config->
8705 wlan_logging_to_console);
8706 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8707}
8708#else
8709static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8710{ }
8711#endif
8712
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308713/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008714 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308715 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008716 *
8717 * Allocate and initialize HDD context. HDD context is allocated as part of
8718 * wiphy allocation and then context is initialized.
8719 *
8720 * Return: HDD context on success and ERR_PTR on failure
8721 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008722static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008723{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308724 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008725 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008726 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008727
Dustin Brown491d54b2018-03-14 12:39:11 -07008728 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008729
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008730 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008731 if (hdd_ctx == NULL) {
8732 ret = -ENOMEM;
8733 goto err_out;
8734 }
8735
Dustin Brown6f427922017-09-19 12:19:00 -07008736 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8737 hdd_iface_change_callback,
8738 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308739
8740 mutex_init(&hdd_ctx->iface_change_lock);
8741
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008742 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308743 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008744
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308745 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008746 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008747 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008748 ret = -ENOMEM;
8749 goto err_free_hdd_context;
8750 }
8751
8752 /* Read and parse the qcom_cfg.ini file */
8753 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308754 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308755 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008756 WLAN_INI_FILE);
8757 ret = -EINVAL;
8758 goto err_free_config;
8759 }
8760
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308761 ie_whitelist_attrs_init(hdd_ctx);
8762
Dustin Brown7f939932017-05-18 15:02:17 -07008763 hdd_debug("setting timer multiplier: %u",
8764 hdd_ctx->config->timer_multiplier);
8765 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8766
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008767
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308768 if (hdd_ctx->config->fhostNSOffload)
8769 hdd_ctx->ns_offload_enable = true;
8770
Abhishek Singh5ea86532016-04-27 14:10:53 +05308771 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8772
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008773 hdd_override_ini_config(hdd_ctx);
8774
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008775 ret = hdd_context_init(hdd_ctx);
8776
8777 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008778 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008779
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008780 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308781 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008782
Anurag Chouhan6d760662016-02-20 16:05:43 +05308783 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008784 goto skip_multicast_logging;
8785
8786 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8787
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008788 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8789 if (ret)
8790 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308791
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008792 ret = hdd_init_netlink_services(hdd_ctx);
8793 if (ret)
8794 goto err_deinit_txrx_histogram;
8795
Nirav Shaheb017be2018-02-15 11:20:58 +05308796 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308797
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008798skip_multicast_logging:
8799 hdd_set_trace_level_for_each(hdd_ctx);
8800
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008801 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8802
Dustin Browne74003f2018-03-14 12:51:58 -07008803 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008804
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008805 return hdd_ctx;
8806
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008807err_deinit_txrx_histogram:
8808 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8809
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008810err_deinit_hdd_context:
8811 hdd_context_deinit(hdd_ctx);
8812
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008813err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308814 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008815
8816err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308817 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008818 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008819
8820err_out:
8821 return ERR_PTR(ret);
8822}
8823
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008824#ifdef WLAN_OPEN_P2P_INTERFACE
8825/**
8826 * hdd_open_p2p_interface - Open P2P interface
8827 * @hdd_ctx: HDD context
8828 * @rtnl_held: True if RTNL lock held
8829 *
8830 * Open P2P interface during probe. This function called to open the P2P
8831 * interface at probe along with STA interface.
8832 *
8833 * Return: 0 on success and errno on failure
8834 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008835static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008836{
Jeff Johnson9d295242017-08-29 14:39:48 -07008837 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008838 uint8_t *p2p_dev_addr;
8839
8840 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8841 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008842 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008843 hdd_ctx->config->intfMacAddr[0].bytes,
8844 sizeof(tSirMacAddr));
8845
8846 /*
8847 * Generate the P2P Device Address. This consists of
8848 * the device's primary MAC address with the locally
8849 * administered bit set.
8850 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008851 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008852 } else {
8853 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8854 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008855 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008856 return -ENOSPC;
8857 }
8858
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008859 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8860 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008861 }
8862
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008863 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008864 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008865 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008866
8867 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008868 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008869 return -ENOSPC;
8870 }
8871
8872 return 0;
8873}
8874#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008875static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008876 bool rtnl_held)
8877{
8878 return 0;
8879}
8880#endif
8881
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008882static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008883{
Jeff Johnson9d295242017-08-29 14:39:48 -07008884 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008885 int ret = 0;
8886
8887 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8888 wlan_hdd_get_intf_addr(hdd_ctx),
8889 NET_NAME_UNKNOWN, rtnl_held);
8890 if (adapter == NULL) {
8891 hdd_err("Failed to open 802.11p interface");
8892 ret = -ENOSPC;
8893 }
8894
8895 return ret;
8896}
8897
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008898/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308899 * hdd_start_station_adapter()- Start the Station Adapter
8900 * @adapter: HDD adapter
8901 *
8902 * This function initializes the adapter for the station mode.
8903 *
8904 * Return: 0 on success or errno on failure.
8905 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008906int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308907{
8908 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008909 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308910
Dustin Brownfdf17c12018-03-14 12:55:34 -07008911 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008912 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8913 hdd_err("session is already opened, %d",
8914 adapter->session_id);
8915 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8916 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308917
Krunal Sonib51eec72017-11-20 21:53:01 -08008918 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8919 if (ret) {
8920 hdd_err("failed to create vdev: %d", ret);
8921 return ret;
8922 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308923 status = hdd_init_station_mode(adapter);
8924
8925 if (QDF_STATUS_SUCCESS != status) {
8926 hdd_err("Error Initializing station mode: %d", status);
8927 return qdf_status_to_os_return(status);
8928 }
8929
Arun Khandavallifae92942016-08-01 13:31:08 +05308930 hdd_register_tx_flow_control(adapter,
8931 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008932 hdd_tx_resume_cb,
8933 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308934
Dustin Browne74003f2018-03-14 12:51:58 -07008935 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308936 return 0;
8937}
8938
8939/**
8940 * hdd_start_ap_adapter()- Start AP Adapter
8941 * @adapter: HDD adapter
8942 *
8943 * This function initializes the adapter for the AP mode.
8944 *
8945 * Return: 0 on success errno on failure.
8946 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008947int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308948{
8949 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008950 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008951 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008952 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308953
Dustin Brown491d54b2018-03-14 12:39:11 -07008954 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308955
Krunal Sonib51eec72017-11-20 21:53:01 -08008956 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8957 hdd_err("session is already opened, %d",
8958 adapter->session_id);
8959 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8960 }
8961 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008962 * In SSR case no need to create new sap context.
8963 * Otherwise create sap context first and then create
8964 * vdev as while creating the vdev, driver needs to
8965 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008966 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008967 if (adapter->session.ap.sap_context) {
8968 is_ssr = true;
8969 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008970 hdd_err("sap creation failed");
8971 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8972 }
8973
8974 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8975 adapter->session.ap.sap_context);
8976 if (ret) {
8977 hdd_err("failed to create vdev, status:%d", ret);
8978 hdd_sap_destroy_ctx(adapter);
8979 return ret;
8980 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008981
8982 if (adapter->device_mode == QDF_SAP_MODE)
8983 sme_cli_set_command(adapter->session_id,
8984 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8985 (bool)(hdd_ctx->config->fine_time_meas_cap &
8986 WMI_FW_AP_RTT_RESPR),
8987 VDEV_CMD);
8988
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008989 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308990
8991 if (QDF_STATUS_SUCCESS != status) {
8992 hdd_err("Error Initializing the AP mode: %d", status);
8993 return qdf_status_to_os_return(status);
8994 }
8995
Arun Khandavallifae92942016-08-01 13:31:08 +05308996 hdd_register_tx_flow_control(adapter,
8997 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008998 hdd_softap_tx_resume_cb,
8999 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309000
Dustin Browne74003f2018-03-14 12:51:58 -07009001 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309002 return 0;
9003}
9004
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309005static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
9006 bool rtnl_held)
9007{
9008 struct hdd_adapter *adapter;
9009
9010 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
9011 hdd_ctx->config->enableConcurrentSTA,
9012 wlan_hdd_get_intf_addr(hdd_ctx),
9013 NET_NAME_UNKNOWN, rtnl_held);
9014
9015 if (!adapter)
9016 return -ENOSPC;
9017
9018 return 0;
9019}
9020
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309021/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009022 * hdd_open_interfaces - Open all required interfaces
9023 * hdd_ctx: HDD context
9024 * rtnl_held: True if RTNL lock is held
9025 *
9026 * Open all the interfaces like STA, P2P and OCB based on the configuration.
9027 *
Jeff Johnson957bc272017-02-02 08:54:48 -08009028 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009029 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009030static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009031{
Jeff Johnson9d295242017-08-29 14:39:48 -07009032 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009033 int ret;
9034
Ravi Joshia307f632017-07-17 23:41:41 -07009035 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08009036 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
9037 con_mode == QDF_GLOBAL_FTM_MODE) {
9038 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
9039 QDF_MONITOR_MODE : QDF_FTM_MODE;
9040
9041 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
9042 wlan_hdd_get_intf_addr(hdd_ctx),
9043 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07009044 if (!adapter) {
9045 hdd_err("open adapter failed");
9046 return -ENOSPC;
9047 }
Lin Bai1c678482017-12-18 18:29:11 +08009048
Ravi Joshia307f632017-07-17 23:41:41 -07009049 return 0;
9050 }
9051
Jeff Johnson957bc272017-02-02 08:54:48 -08009052 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05309053 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08009054 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009055
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009056 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009057 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08009058 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009059
9060 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08009061 return -ENOSPC;
9062
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309063 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
9064 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
9065 if (ret)
9066 hdd_err("Cannot create concurrent STA interface");
9067 }
9068
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009069 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
9070 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009071 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009072
9073 /* Open 802.11p Interface */
9074 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009075 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
9076 if (ret)
9077 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009078 }
9079
Jeff Johnson957bc272017-02-02 08:54:48 -08009080 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009081
Jeff Johnson957bc272017-02-02 08:54:48 -08009082err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009083 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08009084 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009085}
9086
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009087
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309088#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9089/**
9090 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9091 * @cds_cfg: CDS Configuration
9092 * @hdd_ctx: Pointer to hdd context
9093 *
9094 * Return: none
9095 */
9096static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9097 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009098 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309099{
9100 cds_cfg->tx_flow_stop_queue_th =
9101 hdd_ctx->config->TxFlowStopQueueThreshold;
9102 cds_cfg->tx_flow_start_queue_offset =
9103 hdd_ctx->config->TxFlowStartQueueOffset;
9104}
9105#else
9106static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9107 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009108 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309109{
9110}
9111#endif
9112
9113#ifdef FEATURE_WLAN_RA_FILTERING
9114/**
9115 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9116 * @cds_cfg: CDS Configuration
9117 * @hdd_ctx: Pointer to hdd context
9118 *
9119 * Return: none
9120 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309121static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009122 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309123{
9124 cds_cfg->ra_ratelimit_interval =
9125 hdd_ctx->config->RArateLimitInterval;
9126 cds_cfg->is_ra_ratelimit_enabled =
9127 hdd_ctx->config->IsRArateLimitEnabled;
9128}
9129#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309130static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009131 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309132{
9133}
9134#endif
9135
9136/**
9137 * hdd_update_cds_config() - API to update cds configuration parameters
9138 * @hdd_ctx: HDD Context
9139 *
9140 * Return: 0 for Success, errno on failure
9141 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009142static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309143{
9144 struct cds_config_info *cds_cfg;
9145
9146 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9147 if (!cds_cfg) {
9148 hdd_err("failed to allocate cds config");
9149 return -ENOMEM;
9150 }
9151
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009152 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009153 if (!hdd_ctx->config->nMaxPsPoll ||
9154 !hdd_ctx->config->enablePowersaveOffload) {
9155 cds_cfg->powersave_offload_enabled =
9156 hdd_ctx->config->enablePowersaveOffload;
9157 } else {
9158 if ((hdd_ctx->config->enablePowersaveOffload ==
9159 PS_QPOWER_NODEEPSLEEP) ||
9160 (hdd_ctx->config->enablePowersaveOffload ==
9161 PS_LEGACY_NODEEPSLEEP))
9162 cds_cfg->powersave_offload_enabled =
9163 PS_LEGACY_NODEEPSLEEP;
9164 else
9165 cds_cfg->powersave_offload_enabled =
9166 PS_LEGACY_DEEPSLEEP;
9167 hdd_info("Qpower disabled in cds config, %d",
9168 cds_cfg->powersave_offload_enabled);
9169 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309170 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9171 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9172 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9173 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309174
9175 /*
9176 * Copy the DFS Phyerr Filtering Offload status.
9177 * This parameter reflects the value of the
9178 * dfs_phyerr_filter_offload flag as set in the ini.
9179 */
9180 cds_cfg->dfs_phyerr_filter_offload =
9181 hdd_ctx->config->fDfsPhyerrFilterOffload;
9182 if (hdd_ctx->config->ssdp)
9183 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9184
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309185 cds_cfg->force_target_assert_enabled =
9186 hdd_ctx->config->crash_inject_enabled;
9187
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309188 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9189 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9190
9191 cds_cfg->ap_maxoffload_reorderbuffs =
9192 hdd_ctx->config->apMaxOffloadReorderBuffs;
9193
9194 cds_cfg->ap_disable_intrabss_fwd =
9195 hdd_ctx->config->apDisableIntraBssFwd;
9196
9197 cds_cfg->dfs_pri_multiplier =
9198 hdd_ctx->config->dfsRadarPriMultiplier;
9199 cds_cfg->reorder_offload =
9200 hdd_ctx->config->reorderOffloadSupport;
9201
9202 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309203 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009204 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9205 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009206 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009207 hdd_ctx->config->IpaUcTxBufCount);
9208 hdd_ctx->config->IpaUcTxBufCount =
9209 rounddown_pow_of_two(
9210 hdd_ctx->config->IpaUcTxBufCount);
9211 if (!hdd_ctx->config->IpaUcTxBufCount) {
9212 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309213 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009214 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009215 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009216 hdd_ctx->config->IpaUcTxBufCount);
9217 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309218 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9219 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009220 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9221 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009222 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009223 hdd_ctx->config->IpaUcRxIndRingCount);
9224 hdd_ctx->config->IpaUcRxIndRingCount =
9225 rounddown_pow_of_two(
9226 hdd_ctx->config->IpaUcRxIndRingCount);
9227 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9228 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309229 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009230 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009231 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009232 hdd_ctx->config->IpaUcRxIndRingCount);
9233 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309234 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009235 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309236 cds_cfg->uc_tx_partition_base =
9237 hdd_ctx->config->IpaUcTxPartitionBase;
9238 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9239
9240 cds_cfg->ip_tcp_udp_checksum_offload =
9241 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009242 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309243 cds_cfg->ce_classify_enabled =
9244 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07009245 cds_cfg->bpf_packet_filter_enable =
9246 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309247 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9248 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9249 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009250 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009251 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009252 cds_cfg->max_msdus_per_rxinorderind =
9253 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009254 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009255 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05309256 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
9257 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309258 cds_cfg->auto_power_save_fail_mode =
9259 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309260
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309261 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009262 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009263 cds_cfg->delay_before_vdev_stop =
9264 hdd_ctx->config->delay_before_vdev_stop;
Rachit Kankane0106e382018-05-16 18:59:28 +05309265 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309266
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309267 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9268 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9269 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009270 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309271 cds_init_ini_config(cds_cfg);
9272 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309273
9274exit:
9275 qdf_mem_free(cds_cfg);
9276 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309277}
9278
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009279/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009280 * hdd_update_user_config() - API to update user configuration
9281 * parameters to obj mgr which are used by multiple components
9282 * @hdd_ctx: HDD Context
9283 *
9284 * Return: 0 for Success, errno on failure
9285 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009286static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009287{
9288 struct wlan_objmgr_psoc_user_config *user_config;
9289
9290 user_config = qdf_mem_malloc(sizeof(*user_config));
9291 if (user_config == NULL) {
9292 hdd_alert("Failed to alloc memory for user_config!");
9293 return -ENOMEM;
9294 }
9295
9296 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9297 user_config->dual_mac_feature_disable =
9298 hdd_ctx->config->dual_mac_feature_disable;
9299 user_config->indoor_channel_support =
9300 hdd_ctx->config->indoor_channel_support;
9301 user_config->is_11d_support_enabled =
9302 hdd_ctx->config->Is11dSupportEnabled;
9303 user_config->is_11h_support_enabled =
9304 hdd_ctx->config->Is11hSupportEnabled;
9305 user_config->optimize_chan_avoid_event =
9306 hdd_ctx->config->goptimize_chan_avoid_event;
9307 user_config->skip_dfs_chnl_in_p2p_search =
9308 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009309 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009310 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9311
9312 qdf_mem_free(user_config);
9313 return 0;
9314}
9315
9316/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009317 * hdd_init_thermal_info - Initialize thermal level
9318 * @hdd_ctx: HDD context
9319 *
9320 * Initialize thermal level at SME layer and set the thermal level callback
9321 * which would be called when a configured thermal threshold is hit.
9322 *
9323 * Return: 0 on success and errno on failure
9324 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009325static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009326{
9327 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309328 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009329
9330 thermal_param.smeThermalMgmtEnabled =
9331 hdd_ctx->config->thermalMitigationEnable;
9332 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9333
Poddar, Siddarth83905022016-04-16 17:56:08 -07009334 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9335 hdd_ctx->config->throttle_dutycycle_level0;
9336 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9337 hdd_ctx->config->throttle_dutycycle_level1;
9338 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9339 hdd_ctx->config->throttle_dutycycle_level2;
9340 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9341 hdd_ctx->config->throttle_dutycycle_level3;
9342
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009343 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9344 hdd_ctx->config->thermalTempMinLevel0;
9345 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9346 hdd_ctx->config->thermalTempMaxLevel0;
9347 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9348 hdd_ctx->config->thermalTempMinLevel1;
9349 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9350 hdd_ctx->config->thermalTempMaxLevel1;
9351 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9352 hdd_ctx->config->thermalTempMinLevel2;
9353 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9354 hdd_ctx->config->thermalTempMaxLevel2;
9355 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9356 hdd_ctx->config->thermalTempMinLevel3;
9357 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9358 hdd_ctx->config->thermalTempMaxLevel3;
9359
9360 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9361
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309362 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309363 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009364
9365 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9366 hdd_set_thermal_level_cb);
9367
9368 return 0;
9369
9370}
9371
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009372#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9373/**
9374 * hdd_hold_rtnl_lock - Hold RTNL lock
9375 *
9376 * Hold RTNL lock
9377 *
9378 * Return: True if held and false otherwise
9379 */
9380static inline bool hdd_hold_rtnl_lock(void)
9381{
9382 rtnl_lock();
9383 return true;
9384}
9385
9386/**
9387 * hdd_release_rtnl_lock - Release RTNL lock
9388 *
9389 * Release RTNL lock
9390 *
9391 * Return: None
9392 */
9393static inline void hdd_release_rtnl_lock(void)
9394{
9395 rtnl_unlock();
9396}
9397#else
9398static inline bool hdd_hold_rtnl_lock(void) { return false; }
9399static inline void hdd_release_rtnl_lock(void) { }
9400#endif
9401
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009402#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009403
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309404/* MAX iwpriv command support */
9405#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309406#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309407#define MAX_PKTLOG_SIZE 16
9408
9409/**
9410 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9411 * @hdd_ctx: hdd context
9412 * @set_value2: pktlog buffer size value
9413 *
9414 *
9415 * Return: 0 for success or error.
9416 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009417static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309418{
9419 struct sir_wifi_start_log start_log = { 0 };
9420 QDF_STATUS status;
9421
9422 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9423 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9424 start_log.ini_triggered = cds_is_packet_log_enabled();
9425 start_log.user_triggered = 1;
9426 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309427 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309428
9429 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9430 if (!QDF_IS_STATUS_SUCCESS(status)) {
9431 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009432 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309433 return -EINVAL;
9434 }
9435
9436 return 0;
9437}
9438
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009439/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309440 * hdd_pktlog_clear_buff() - clear pktlog buffer
9441 * @hdd_ctx: hdd context
9442 *
9443 * Return: 0 for success or error.
9444 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009445static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309446{
9447 struct sir_wifi_start_log start_log;
9448 QDF_STATUS status;
9449
9450 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9451 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9452 start_log.ini_triggered = cds_is_packet_log_enabled();
9453 start_log.user_triggered = 1;
9454 start_log.size = 0;
9455 start_log.is_pktlog_buff_clear = true;
9456
9457 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9458 if (!QDF_IS_STATUS_SUCCESS(status)) {
9459 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009460 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309461 return -EINVAL;
9462 }
9463
9464 return 0;
9465}
9466
9467
9468/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009469 * hdd_process_pktlog_command() - process pktlog command
9470 * @hdd_ctx: hdd context
9471 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309472 * @set_value2: pktlog buffer size value
9473 *
9474 * This function process pktlog command.
9475 * set_value2 only matters when set_value is 3 (set buff size)
9476 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009477 *
9478 * Return: 0 for success or error.
9479 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009480int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309481 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009482{
9483 int ret;
9484 bool enable;
9485 uint8_t user_triggered = 0;
9486
9487 ret = wlan_hdd_validate_context(hdd_ctx);
9488 if (0 != ret)
9489 return ret;
9490
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009491 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009492
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309493 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009494 hdd_err("invalid pktlog value %d", set_value);
9495 return -EINVAL;
9496 }
9497
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309498 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9499 if (set_value2 <= 0) {
9500 hdd_err("invalid pktlog size %d", set_value2);
9501 return -EINVAL;
9502 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9503 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9504 return -EINVAL;
9505 }
9506 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309507 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9508 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309509 }
9510
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009511 /*
9512 * set_value = 0 then disable packetlog
9513 * set_value = 1 enable packetlog forcefully
9514 * set_vlaue = 2 then disable packetlog if disabled through ini or
9515 * enable packetlog with AUTO type.
9516 */
9517 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9518 true : false;
9519
9520 if (1 == set_value) {
9521 enable = true;
9522 user_triggered = 1;
9523 }
9524
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309525 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009526}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009527
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009528/**
9529 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9530 * @hdd_ctx: HDD context
9531 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309532 * @user_triggered: triggered through iwpriv
9533 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009534 *
9535 * Return: 0 on success; error number otherwise
9536 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009537int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309538 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009539{
9540 struct sir_wifi_start_log start_log;
9541 QDF_STATUS status;
9542
9543 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9544 start_log.verbose_level =
9545 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009546 start_log.ini_triggered = cds_is_packet_log_enabled();
9547 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309548 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309549 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309550 /*
9551 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9552 * commands. Host uses this flag to decide whether to send pktlog
9553 * disable command to fw without sending pktlog enable command
9554 * previously. For eg, If vendor sends pktlog disable command without
9555 * sending pktlog enable command, then host discards the packet
9556 * but for iwpriv command, host will send it to fw.
9557 */
9558 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009559 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9560 if (!QDF_IS_STATUS_SUCCESS(status)) {
9561 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009562 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009563 return -EINVAL;
9564 }
9565
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309566 if (enable == true)
9567 hdd_ctx->is_pktlog_enabled = 1;
9568 else
9569 hdd_ctx->is_pktlog_enabled = 0;
9570
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009571 return 0;
9572}
9573#endif /* REMOVE_PKT_LOG */
9574
Komal Seelam92fff912016-03-24 11:51:41 +05309575/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009576 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9577 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309578 * @dev: Device Pointer
9579 * @num: Number of Valid Mac address
9580 *
9581 * Return: Pointer to MAC address buffer
9582 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009583static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9584 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309585{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009586 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309587}
Komal Seelam92fff912016-03-24 11:51:41 +05309588
9589/**
9590 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9591 * @hdd_ctx: HDD Context
9592 * @num: Number of random mac addresses needed
9593 *
9594 * Generate random addresses using bit manipulation on the base mac address
9595 *
9596 * Return: None
9597 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009598void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309599{
9600 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9601 uint32_t iter;
9602 struct hdd_config *ini = hdd_ctx->config;
9603 uint8_t *buf = NULL;
9604 uint8_t macaddr_b3, tmp_br3;
9605 uint8_t *src = ini->intfMacAddr[0].bytes;
9606
9607 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9608 buf = ini->intfMacAddr[iter].bytes;
9609 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9610 macaddr_b3 = buf[3];
9611 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9612 INTF_MACADDR_MASK;
9613 macaddr_b3 += tmp_br3;
9614 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9615 buf[0] |= 0x02;
9616 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009617 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309618 }
9619}
9620
9621/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009622 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309623 * @hdd_ctx: HDD Context
9624 *
9625 * API to get mac addresses from platform driver and update the driver
9626 * structures and configure FW with the base mac address.
9627 * Return: int
9628 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009629static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309630{
9631 uint32_t no_of_mac_addr, iter;
9632 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9633 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9634 uint8_t *addr, *buf;
9635 struct device *dev = hdd_ctx->parent_dev;
9636 struct hdd_config *ini = hdd_ctx->config;
9637 tSirMacAddr mac_addr;
9638 QDF_STATUS status;
9639
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009640 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309641
9642 if (no_of_mac_addr == 0 || !addr) {
9643 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9644 return -EINVAL;
9645 }
9646
9647 if (no_of_mac_addr > max_mac_addr)
9648 no_of_mac_addr = max_mac_addr;
9649
9650 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9651
9652 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9653 buf = ini->intfMacAddr[iter].bytes;
9654 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009655 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309656 }
9657
9658 status = sme_set_custom_mac_addr(mac_addr);
9659
9660 if (!QDF_IS_STATUS_SUCCESS(status))
9661 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009662
Komal Seelam92fff912016-03-24 11:51:41 +05309663 if (no_of_mac_addr < max_mac_addr)
9664 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9665 no_of_mac_addr);
9666 return 0;
9667}
9668
9669/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009670 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9671 * @hdd_ctx: HDD Context
9672 *
9673 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9674 * will generate its own MAC and update it to FW.
9675 *
9676 * Return: 0 for success
9677 * Non-zero error code for failure
9678 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009679static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009680{
9681 tSirMacAddr customMacAddr;
9682 QDF_STATUS status;
9683
9684 qdf_mem_copy(&customMacAddr,
9685 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9686 sizeof(tSirMacAddr));
9687 status = sme_set_custom_mac_addr(customMacAddr);
9688 if (!QDF_IS_STATUS_SUCCESS(status))
9689 return -EAGAIN;
9690 return 0;
9691}
9692
9693/**
Komal Seelam92fff912016-03-24 11:51:41 +05309694 * hdd_initialize_mac_address() - API to get wlan mac addresses
9695 * @hdd_ctx: HDD Context
9696 *
9697 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9698 * is provisioned with mac addresses, driver uses it, else it will use
9699 * wlan_mac.bin to update HW MAC addresses.
9700 *
9701 * Return: None
9702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009703static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309704{
9705 QDF_STATUS status;
9706 int ret;
9707
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009708 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309709 if (ret == 0)
9710 return;
9711
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009712 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9713 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309714
9715 status = hdd_update_mac_config(hdd_ctx);
9716
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009717 if (QDF_IS_STATUS_SUCCESS(status))
9718 return;
9719
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009720 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9721 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009722
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009723 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009724 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009725 if (ret != 0) {
9726 hdd_err("MAC address out-of-sync, ret:%d", ret);
9727 QDF_ASSERT(ret);
9728 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009729 }
Komal Seelam92fff912016-03-24 11:51:41 +05309730}
9731
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009732static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009733{
9734 int vdev_id = 0;
9735 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9736 int value = hdd_ctx->config->smart_chainmask_enabled;
9737 int vpdev = PDEV_CMD;
9738 int ret;
9739
Naveen Rawat247a8682017-06-05 15:00:31 -07009740 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009741 if (ret)
9742 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9743
9744 return ret;
9745}
9746
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009747static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009748{
9749 int vdev_id = 0;
9750 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9751 int value = hdd_ctx->config->alternative_chainmask_enabled;
9752 int vpdev = PDEV_CMD;
9753 int ret;
9754
Naveen Rawat247a8682017-06-05 15:00:31 -07009755 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009756 if (ret)
9757 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9758 ret);
9759
9760 return ret;
9761}
9762
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009763static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009764{
9765 int vdev_id = 0;
9766 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9767 int value = hdd_ctx->config->ani_enabled;
9768 int vpdev = PDEV_CMD;
9769 int ret;
9770
Naveen Rawat247a8682017-06-05 15:00:31 -07009771 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009772 if (ret)
9773 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9774
9775 return ret;
9776}
9777
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009778/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009779 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9780 * @hdd_ctx: HDD context
9781 *
9782 * Pre configurations to be done at lower layer before calling cds enable.
9783 *
9784 * Return: 0 on success and errno on failure.
9785 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009786static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009787{
9788 int ret;
9789 QDF_STATUS status;
Leo Changfdb45c32016-10-28 11:09:23 -07009790 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009791
Leo Changfdb45c32016-10-28 11:09:23 -07009792 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009793 /*
9794 * Set 802.11p config
9795 * TODO-OCB: This has been temporarily added here to ensure this
9796 * parameter is set in CSR when we init the channel list. This should
9797 * be removed once the 5.9 GHz channels are added to the regulatory
9798 * domain.
9799 */
9800 hdd_set_dot11p_config(hdd_ctx);
9801
9802 /*
9803 * Note that the cds_pre_enable() sequence triggers the cfg download.
9804 * The cfg download must occur before we update the SME config
9805 * since the SME config operation must access the cfg database
9806 */
9807 status = hdd_set_sme_config(hdd_ctx);
9808
9809 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009810 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009811 ret = qdf_status_to_os_return(status);
9812 goto out;
9813 }
9814
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009815 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9816 if (QDF_STATUS_SUCCESS != status) {
9817 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9818 ret = qdf_status_to_os_return(status);
9819 goto out;
9820 }
9821
Naveen Rawat247a8682017-06-05 15:00:31 -07009822 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009823 hdd_ctx->config->tx_chain_mask_1ss,
9824 PDEV_CMD);
9825 if (0 != ret) {
9826 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9827 goto out;
9828 }
9829
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009830 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9831 if (ret)
9832 goto out;
9833
9834 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9835 if (ret)
9836 goto out;
9837
Jeff Johnson12a744b2017-04-04 08:19:37 -07009838 ret = hdd_set_ani_enabled(hdd_ctx);
9839 if (ret)
9840 goto out;
9841
Naveen Rawat247a8682017-06-05 15:00:31 -07009842 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009843 hdd_ctx->config->arp_ac_category,
9844 PDEV_CMD);
9845 if (0 != ret) {
9846 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9847 hdd_ctx->config->arp_ac_category, ret);
9848 goto out;
9849 }
9850
Prashanth Bhatta07998752016-04-28 12:35:33 -07009851 status = hdd_set_sme_chan_list(hdd_ctx);
9852 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009853 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009854 ret = qdf_status_to_os_return(status);
9855 goto out;
9856 }
9857
9858 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009859 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009860 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009861 ret = -EINVAL;
9862 goto out;
9863 }
9864
Prashanth Bhatta07998752016-04-28 12:35:33 -07009865 /*
9866 * Set the MAC Address Currently this is used by HAL to add self sta.
9867 * Remove this once self sta is added as part of session open.
9868 */
Jeff Johnsonbae59f92018-06-01 17:05:43 -07009869 status = sme_cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9870 hdd_ctx->config->intfMacAddr[0].bytes,
9871 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -07009872
Jeff Johnsonbae59f92018-06-01 17:05:43 -07009873 if (QDF_IS_STATUS_ERROR(status)) {
9874 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009875 ret = -EINVAL;
9876 goto out;
9877 }
9878
9879 hdd_init_channel_avoidance(hdd_ctx);
9880
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309881 /* update enable sap mandatory chan list */
9882 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9883 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009884out:
9885 return ret;
9886}
9887
9888/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009889 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9890 * @context_ptr - hdd context pointer
9891 * @event_ptr - event structure pointer
9892 *
9893 * This is the p2p listen offload stop event handler, it sends vendor
9894 * event back to supplicant to notify the stop reason.
9895 *
9896 * Return: None
9897 */
9898static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9899 void *event_ptr)
9900{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009901 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009902 struct sir_p2p_lo_event *evt = event_ptr;
9903 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009904 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009905
Dustin Brown491d54b2018-03-14 12:39:11 -07009906 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009907
9908 if (hdd_ctx == NULL) {
9909 hdd_err("Invalid HDD context pointer");
9910 return;
9911 }
9912
Peng Xu5c682812017-08-06 07:39:13 -07009913 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9914 if (!adapter) {
9915 hdd_err("Cannot find adapter by vdev_id = %d",
9916 evt->vdev_id);
9917 return;
9918 }
9919
Peng Xu8fdaa492016-06-22 10:20:47 -07009920 vendor_event =
9921 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009922 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009923 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9924 GFP_KERNEL);
9925
9926 if (!vendor_event) {
9927 hdd_err("cfg80211_vendor_event_alloc failed");
9928 return;
9929 }
9930
9931 if (nla_put_u32(vendor_event,
9932 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9933 evt->reason_code)) {
9934 hdd_err("nla put failed");
9935 kfree_skb(vendor_event);
9936 return;
9937 }
9938
9939 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009940 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9941 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009942}
9943
9944/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309945 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9946 * @hdd_ctx: HDD context
9947 *
9948 * This function sends the adaptive dwell time config configuration to the
9949 * firmware via WMA
9950 *
9951 * Return: 0 - success, < 0 - failure
9952 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009953static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309954{
9955 QDF_STATUS status;
9956 struct adaptive_dwelltime_params dwelltime_params;
9957
9958 dwelltime_params.is_enabled =
9959 hdd_ctx->config->adaptive_dwell_mode_enabled;
9960 dwelltime_params.dwelltime_mode =
9961 hdd_ctx->config->global_adapt_dwelltime_mode;
9962 dwelltime_params.lpf_weight =
9963 hdd_ctx->config->adapt_dwell_lpf_weight;
9964 dwelltime_params.passive_mon_intval =
9965 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9966 dwelltime_params.wifi_act_threshold =
9967 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9968
9969 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9970 &dwelltime_params);
9971
9972 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9973 if (!QDF_IS_STATUS_SUCCESS(status)) {
9974 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9975 return -EAGAIN;
9976 }
9977 return 0;
9978}
9979
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009980int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309981{
9982 QDF_STATUS status;
9983 struct wmi_dbs_scan_sel_params dbs_scan_params;
9984 uint32_t i = 0;
9985 uint8_t count = 0, numentries = 0;
9986 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9987 * CDS_DBS_SCAN_CLIENTS_MAX];
9988
9989 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +05309990 if ((hdd_ctx->config->dual_mac_feature_disable ==
9991 DISABLE_DBS_CXN_AND_SCAN) ||
9992 (hdd_ctx->config->dual_mac_feature_disable ==
9993 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309994 return -EINVAL;
9995
9996 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9997 dbs_scan_config, &numentries,
9998 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9999 * CDS_DBS_SCAN_CLIENTS_MAX));
10000
10001 hdd_info("numentries %hu", numentries);
10002 if (!numentries) {
10003 hdd_info("Donot send scan_selection_config");
10004 return 0;
10005 }
10006
10007 /* hdd_set_fw_log_params */
10008 dbs_scan_params.num_clients = 0;
10009 while (count < (numentries - 2)) {
10010 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10011 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10012 dbs_scan_params.num_non_dbs_scans[i] =
10013 dbs_scan_config[count + 2];
10014 dbs_scan_params.num_clients++;
10015 hdd_debug("module:%d NDS:%d NNDS:%d",
10016 dbs_scan_params.module_id[i],
10017 dbs_scan_params.num_dbs_scans[i],
10018 dbs_scan_params.num_non_dbs_scans[i]);
10019 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10020 i++;
10021 }
10022
10023 dbs_scan_params.pdev_id = 0;
10024
10025 hdd_debug("clients:%d pdev:%d",
10026 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10027
10028 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
10029 &dbs_scan_params);
10030 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10031 if (!QDF_IS_STATUS_SUCCESS(status)) {
10032 hdd_err("Failed to send DBS Scan selection configuration!");
10033 return -EAGAIN;
10034 }
10035 return 0;
10036}
10037
Arun Khandavallid4349a92016-07-25 11:10:43 +053010038#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10039/**
10040 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10041 * @hdd_ctx: HDD context
10042 *
10043 * Set auto shutdown callback to get indications from firmware to indicate
10044 * userspace to shutdown WLAN after a configured amount of inactivity.
10045 *
10046 * Return: 0 on success and errno on failure.
10047 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010048static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010049{
10050 QDF_STATUS status;
10051
10052 if (!hdd_ctx->config->WlanAutoShutdown)
10053 return 0;
10054
10055 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
10056 wlan_hdd_auto_shutdown_cb);
10057 if (status != QDF_STATUS_SUCCESS)
10058 hdd_err("Auto shutdown feature could not be enabled: %d",
10059 status);
10060
10061 return qdf_status_to_os_return(status);
10062}
10063#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010064static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010065{
10066 return 0;
10067}
10068#endif
10069
10070/**
10071 * hdd_features_init() - Init features
10072 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010073 *
10074 * Initialize features and their feature context after WLAN firmware is up.
10075 *
10076 * Return: 0 on success and errno on failure.
10077 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010078static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010079{
10080 tSirTxPowerLimit hddtxlimit;
10081 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +053010082 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010083 int ret;
10084
Dustin Brown491d54b2018-03-14 12:39:11 -070010085 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010086
Arun Khandavallid4349a92016-07-25 11:10:43 +053010087 /* FW capabilities received, Set the Dot11 mode */
10088 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -070010089 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
10090 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010091
Arun Khandavallid4349a92016-07-25 11:10:43 +053010092
10093 if (hdd_ctx->config->fIsImpsEnabled)
10094 hdd_set_idle_ps_config(hdd_ctx, true);
10095 else
10096 hdd_set_idle_ps_config(hdd_ctx, false);
10097
Poddar, Siddarth37033032017-10-11 15:47:40 +053010098 /* Send Enable/Disable data stall detection cmd to FW */
10099 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10100 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10101
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010102 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010103 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010104
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010105 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
10106 hdd_warn("Error in setting Voltage Corner mode config to FW");
10107
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010108 if (hdd_rx_ol_init(hdd_ctx))
10109 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010110
10111 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10112 hdd_err("Unable to send adaptive dwelltime setting to FW");
10113
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010114 if (hdd_dbs_scan_selection_init(hdd_ctx))
10115 hdd_err("Unable to send DBS scan selection setting to FW");
10116
Arun Khandavallid4349a92016-07-25 11:10:43 +053010117 ret = hdd_init_thermal_info(hdd_ctx);
10118 if (ret) {
10119 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010120 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010121 }
10122
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010123 /**
10124 * In case of SSR/PDR, if pktlog was enabled manually before
10125 * SSR/PDR, Then enabled it again automatically after Wlan
10126 * device up.
10127 */
10128 if (cds_is_driver_recovering()) {
10129 if (hdd_ctx->is_pktlog_enabled)
10130 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +080010131 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010132
Arun Khandavallid4349a92016-07-25 11:10:43 +053010133 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10134 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
10135 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
10136 if (!QDF_IS_STATUS_SUCCESS(status))
10137 hdd_err("Error setting txlimit in sme: %d", status);
10138
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010139 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010140
Arun Khandavallid4349a92016-07-25 11:10:43 +053010141 ret = hdd_register_cb(hdd_ctx);
10142 if (ret) {
10143 hdd_err("Failed to register HDD callbacks!");
Dustin Browne7e71d32018-05-11 16:00:08 -070010144 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010145 }
10146
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010147 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10148 status = sme_enable_disable_chanavoidind_event(
10149 hdd_ctx->hHal, 0);
10150 if (!QDF_IS_STATUS_SUCCESS(status)) {
10151 hdd_err("Failed to disable Chan Avoidance Indication");
10152 goto deregister_cb;
10153 }
10154 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010155
Manjeet Singha9cae432017-02-28 11:58:22 +053010156 if (hdd_ctx->config->enable_5g_band_pref) {
10157 band_pref_params.rssi_boost_threshold_5g =
10158 hdd_ctx->config->rssi_boost_threshold_5g;
10159 band_pref_params.rssi_boost_factor_5g =
10160 hdd_ctx->config->rssi_boost_factor_5g;
10161 band_pref_params.max_rssi_boost_5g =
10162 hdd_ctx->config->max_rssi_boost_5g;
10163 band_pref_params.rssi_penalize_threshold_5g =
10164 hdd_ctx->config->rssi_penalize_threshold_5g;
10165 band_pref_params.rssi_penalize_factor_5g =
10166 hdd_ctx->config->rssi_penalize_factor_5g;
10167 band_pref_params.max_rssi_penalize_5g =
10168 hdd_ctx->config->max_rssi_penalize_5g;
10169 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
10170 }
10171
Arun Khandavallid4349a92016-07-25 11:10:43 +053010172 /* register P2P Listen Offload event callback */
10173 if (wma_is_p2p_lo_capable())
10174 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
10175 wlan_hdd_p2p_lo_event_callback);
10176
10177 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10178
10179 if (ret)
10180 goto deregister_cb;
10181
Dustin Brown11638b72018-01-25 17:37:25 +053010182 wlan_hdd_init_chan_info(hdd_ctx);
10183
Dustin Browne74003f2018-03-14 12:51:58 -070010184 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010185 return 0;
10186
10187deregister_cb:
10188 hdd_deregister_cb(hdd_ctx);
Dustin Browne7e71d32018-05-11 16:00:08 -070010189
Arun Khandavallid4349a92016-07-25 11:10:43 +053010190 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010191}
10192
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010193/**
10194 * hdd_features_deinit() - Deinit features
10195 * @hdd_ctx: HDD context
10196 *
10197 * De-Initialize features and their feature context.
10198 *
10199 * Return: none.
10200 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010201static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010202{
Dustin Brown11638b72018-01-25 17:37:25 +053010203 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010204 wlan_hdd_tsf_deinit(hdd_ctx);
10205}
10206
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010207/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010208 * hdd_register_bcn_cb() - register scan beacon callback
10209 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010210 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010211 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010212 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010213static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010214{
10215 QDF_STATUS status;
10216
10217 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10218 wlan_cfg80211_inform_bss_frame,
10219 SCAN_CB_TYPE_INFORM_BCN);
10220 if (!QDF_IS_STATUS_SUCCESS(status)) {
10221 hdd_err("failed with status code %08d [x%08x]",
10222 status, status);
10223 return status;
10224 }
10225
10226 return QDF_STATUS_SUCCESS;
10227}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010228
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010229/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010230 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10231 * @vdev_id: vdev_id, corresponds to flow_pool
10232 *
10233 * Return: none.
10234 */
10235static void hdd_v2_flow_pool_map(int vdev_id)
10236{
10237 QDF_STATUS status;
10238
10239 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10240 cds_get_context(QDF_MODULE_ID_TXRX),
10241 vdev_id);
10242 /*
10243 * For Adrastea flow control v2 is based on FW MAP events,
10244 * so this above callback is not implemented.
10245 * Hence this is not actual failure. Dont return failure
10246 */
10247 if ((status != QDF_STATUS_SUCCESS) &&
10248 (status != QDF_STATUS_E_INVAL)) {
10249 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10250 vdev_id, status);
10251 }
10252}
10253
10254/**
10255 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10256 * @vdev_id: vdev_id, corresponds to flow_pool
10257 *
10258 * Return: none.
10259 */
10260static void hdd_v2_flow_pool_unmap(int vdev_id)
10261{
10262 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10263 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10264}
10265
10266/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010267 * hdd_configure_cds() - Configure cds modules
10268 * @hdd_ctx: HDD context
10269 * @adapter: Primary adapter context
10270 *
10271 * Enable Cds modules after WLAN firmware is up.
10272 *
10273 * Return: 0 on success and errno on failure.
10274 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010275int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010276{
10277 int ret;
10278 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010279 int set_value;
10280 uint32_t num_abg_tx_chains = 0;
10281 uint32_t num_11b_tx_chains = 0;
10282 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010283 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010284
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010285 if (hdd_ctx->config->is_force_1x1)
10286 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10287 1, PDEV_CMD);
10288 /* set chip power save failure detected callback */
10289 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
10290 hdd_chip_pwr_save_fail_detected_cb);
10291
10292 if (hdd_ctx->config->max_mpdus_inampdu) {
10293 set_value = hdd_ctx->config->max_mpdus_inampdu;
10294 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10295 set_value, PDEV_CMD);
10296 }
10297
10298 if (hdd_ctx->config->enable_rts_sifsbursting) {
10299 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10300 sme_cli_set_command(0,
10301 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10302 set_value, PDEV_CMD);
10303 }
10304
10305 if (hdd_ctx->config->sap_get_peer_info) {
10306 set_value = hdd_ctx->config->sap_get_peer_info;
10307 sme_cli_set_command(0,
10308 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10309 set_value, PDEV_CMD);
10310 }
10311
10312 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10313 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10314 if (!hdd_ctx->config->enable2x2) {
10315 if (num_11b_tx_chains > 1)
10316 num_11b_tx_chains = 1;
10317 if (num_11ag_tx_chains > 1)
10318 num_11ag_tx_chains = 1;
10319 }
10320 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10321 num_11b_tx_chains);
10322 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10323 num_11ag_tx_chains);
10324 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10325 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010326
10327 ret = hdd_pre_enable_configure(hdd_ctx);
10328 if (ret) {
10329 hdd_err("Failed to pre-configure cds");
10330 goto out;
10331 }
10332
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010333 /* Always get latest IPA resources allocated from cds_open and configure
10334 * IPA module before configuring them to FW. Sequence required as crash
10335 * observed otherwise.
10336 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010337 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10338 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010339 hdd_err("Failed to setup pipes");
10340 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010341 }
10342
Arun Khandavallifae92942016-08-01 13:31:08 +053010343 /*
10344 * Start CDS which starts up the SME/MAC/HAL modules and everything
10345 * else
10346 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010347 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010348
10349 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010350 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010351 goto out;
10352 }
10353
10354 status = hdd_post_cds_enable_config(hdd_ctx);
10355 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010356 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010357 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010358 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010359 status = hdd_register_bcn_cb(hdd_ctx);
10360 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010361 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010362 goto cds_disable;
10363 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010364
Dustin Browne7e71d32018-05-11 16:00:08 -070010365 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010366 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010367 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010368
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010369 if (hdd_ctx->ol_enable)
10370 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10371 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010372 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010373 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010374 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10375 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010376 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10377 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010378 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010379 goto cds_disable;
10380 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010381 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10382 wlan_hdd_send_mode_change_event);
10383 if (!QDF_IS_STATUS_SUCCESS(status)) {
10384 hdd_debug("Failed to register mode change cb with Policy Manager");
10385 goto cds_disable;
10386 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010387
Jeff Johnson8bb61112018-03-31 13:33:54 -070010388 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010389 hdd_debug("enhance green ap is not enabled");
10390
Nachiket Kukadedd302662017-07-13 17:31:44 +053010391 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10392 hdd_debug("Failed to set wow pulse");
10393
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010394 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10395 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010396 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10397 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10398
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010399
10400 if (hdd_ctx->config->enable_phy_reg_retention)
10401 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10402 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10403
Arun Khandavallifae92942016-08-01 13:31:08 +053010404 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010405
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010406cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010407 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010408
Arun Khandavallifae92942016-08-01 13:31:08 +053010409out:
10410 return -EINVAL;
10411}
10412
10413/**
10414 * hdd_deconfigure_cds() -De-Configure cds
10415 * @hdd_ctx: HDD context
10416 *
10417 * Deconfigure Cds modules before WLAN firmware is down.
10418 *
10419 * Return: 0 on success and errno on failure.
10420 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010421static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010422{
10423 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010424 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010425
Dustin Brown491d54b2018-03-14 12:39:11 -070010426 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010427
10428 /* De-init features */
10429 hdd_features_deinit(hdd_ctx);
10430
Arun Khandavallifae92942016-08-01 13:31:08 +053010431 /* De-register the SME callbacks */
10432 hdd_deregister_cb(hdd_ctx);
10433
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010434 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10435 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10436 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10437 }
10438
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010439 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010440 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10441 hdd_err("Failed to Disable the CDS Modules! :%d",
10442 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010443 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010444 }
10445
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010446 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010447 hdd_err("Failed to disconnect pipes");
10448 ret = -EINVAL;
10449 }
10450
Dustin Browne74003f2018-03-14 12:51:58 -070010451 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010452 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010453}
10454
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010455#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10456static void hdd_deregister_policy_manager_callback(
10457 struct wlan_objmgr_psoc *psoc)
10458{
10459 if (QDF_STATUS_SUCCESS !=
10460 policy_mgr_deregister_hdd_cb(psoc)) {
10461 hdd_err("HDD callback deregister with policy manager failed");
10462 }
10463}
10464#else
10465static void hdd_deregister_policy_manager_callback(
10466 struct wlan_objmgr_psoc *psoc)
10467{
10468}
10469#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010470
10471/**
10472 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10473 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010474 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010475 *
10476 * This function maintains the driver state machine it will be invoked from
10477 * exit, shutdown and con_mode change handler. Depending on the driver state
10478 * shall perform the stopping/closing of the modules.
10479 *
10480 * Return: 0 for success; non-zero for failure
10481 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010482int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010483{
10484 void *hif_ctx;
10485 qdf_device_t qdf_ctx;
10486 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010487 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010488 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010489 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10490 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010491 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010492 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010493
Dustin Brown491d54b2018-03-14 12:39:11 -070010494 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010495 hdd_alert("stop WLAN module: entering driver status=%d",
10496 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010497
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010498 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10499
Arun Khandavallifae92942016-08-01 13:31:08 +053010500 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10501 if (!qdf_ctx) {
10502 hdd_err("QDF device context NULL");
10503 return -EINVAL;
10504 }
10505
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010506 mutex_lock(&hdd_ctx->iface_change_lock);
10507 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010508 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010509
Dustin Brown70111822017-03-30 15:31:40 -070010510 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010511 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010512 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010513 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010514
10515 cds_print_external_threads();
10516
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010517 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010518 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010519 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10520 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010521 hdd_prevent_suspend_timeout(
10522 hdd_ctx->config->iface_change_wait_time,
10523 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010524 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010525 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010526 return 0;
10527 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010528 }
10529
Arun Khandavallifae92942016-08-01 13:31:08 +053010530 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10531
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010532 /* free user wowl patterns */
10533 hdd_free_user_wowl_ptrns();
10534
Arun Khandavallifae92942016-08-01 13:31:08 +053010535 switch (hdd_ctx->driver_status) {
10536 case DRIVER_MODULES_UNINITIALIZED:
10537 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010538 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010539 case DRIVER_MODULES_CLOSED:
10540 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010541 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010542 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010543 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10544
Komal Seelamf2136bb2016-09-28 18:30:44 +053010545 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010546 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010547 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010548 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010549 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010550 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010551 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010552
Arun Khandavallifae92942016-08-01 13:31:08 +053010553 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010554 hdd_info("Wlan transitioned (now OPENED)");
10555
10556 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010557 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010558 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010559 break;
10560 default:
10561 hdd_err("Trying to stop wlan in a wrong state: %d",
10562 hdd_ctx->driver_status);
10563 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010564 ret = -EINVAL;
10565 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010566 }
10567
Amar Singhal18081642018-01-26 16:04:13 -080010568 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010569 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010570
Rajeev Kumarbe021242017-02-16 16:12:23 -080010571 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010572 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10573 hdd_err("Failed to process post CDS disable Modules! :%d",
10574 qdf_status);
10575 ret = -EINVAL;
10576 QDF_ASSERT(0);
10577 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010578
psimhadeea0a12017-12-18 14:50:02 -080010579 hdd_runtime_suspend_context_deinit(hdd_ctx);
10580
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010581 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10582 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10583 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10584 ret = -EINVAL;
10585 QDF_ASSERT(0);
10586 }
10587
Jeff Johnsone4b14592017-09-13 14:23:33 -070010588 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010589 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010590 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010591 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010592 QDF_ASSERT(0);
10593 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010594
Amar Singhal410675c2018-01-10 12:14:21 -080010595 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010596 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10597 if (ret) {
10598 hdd_err("Failed to destroy pdev; errno:%d", ret);
10599 QDF_ASSERT(0);
10600 }
10601
10602 /*
10603 * Reset total mac phy during module stop such that during
10604 * next module start same psoc is used to populate new service
10605 * ready data
10606 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010607 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10608 if (tgt_hdl)
10609 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10610
Liangwei Dong50a64a72018-01-11 01:17:00 -050010611
Arun Khandavallifae92942016-08-01 13:31:08 +053010612 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10613 if (!hif_ctx) {
10614 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010615 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010616 }
10617
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010618 if (hdd_ctx->target_hw_name) {
10619 qdf_mem_free(hdd_ctx->target_hw_name);
10620 hdd_ctx->target_hw_name = NULL;
10621 }
10622
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010623 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010624
10625 ol_cds_free();
10626
Dustin Brown70111822017-03-30 15:31:40 -070010627 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010628 ret = pld_power_off(qdf_ctx->dev);
10629 if (ret)
10630 hdd_err("CNSS power down failed put device into Low power mode:%d",
10631 ret);
10632 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010633
Dustin Brown4bc0a622017-12-06 15:56:50 -080010634 /* many adapter resources are not freed by design in SSR case */
10635 if (!is_recovery_stop)
10636 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010637 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010638
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010639 /* Once the firmware sequence is completed reset this flag */
10640 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010641 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010642 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010643
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010644done:
10645 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010646 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010647 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010648 hdd_alert("stop WLAN module: exit driver status=%d",
10649 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010650
Dustin Browne74003f2018-03-14 12:51:58 -070010651 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010652
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010653 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010654}
10655
Arun Khandavallifae92942016-08-01 13:31:08 +053010656
Wen Gong3f003382018-05-14 14:26:37 +080010657#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053010658/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010659 * hdd_state_info_dump() - prints state information of hdd layer
10660 * @buf: buffer pointer
10661 * @size: size of buffer to be filled
10662 *
10663 * This function is used to dump state information of hdd layer
10664 *
10665 * Return: None
10666 */
10667static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10668{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010669 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010670 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010671 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010672 uint16_t len = 0;
10673 char *buf = *buf_ptr;
10674
10675 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10676 if (!hdd_ctx) {
10677 hdd_err("Failed to get hdd context ");
10678 return;
10679 }
10680
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010681 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010682
10683 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010684 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010685 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010686 "\n is_scheduler_suspended %d",
10687 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010688
Dustin Brown920397d2017-12-13 16:27:50 -080010689 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010690 if (adapter->dev)
10691 len += scnprintf(buf + len, *size - len,
10692 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010693 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010694 "\n device_mode: %d", adapter->device_mode);
10695 switch (adapter->device_mode) {
10696 case QDF_STA_MODE:
10697 case QDF_P2P_CLIENT_MODE:
10698 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10699 len += scnprintf(buf + len, *size - len,
10700 "\n connState: %d",
10701 hdd_sta_ctx->conn_info.connState);
10702 break;
10703
10704 default:
10705 break;
10706 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010707 }
10708
10709 *size -= len;
10710 *buf_ptr += len;
10711}
10712
10713/**
10714 * hdd_register_debug_callback() - registration function for hdd layer
10715 * to print hdd state information
10716 *
10717 * Return: None
10718 */
10719static void hdd_register_debug_callback(void)
10720{
10721 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10722}
Wen Gong3f003382018-05-14 14:26:37 +080010723#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080010724static void hdd_register_debug_callback(void)
10725{
10726}
Wen Gong3f003382018-05-14 14:26:37 +080010727#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010728
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010729/*
10730 * wlan_init_bug_report_lock() - Initialize bug report lock
10731 *
10732 * This function is used to create bug report lock
10733 *
10734 * Return: None
10735 */
10736static void wlan_init_bug_report_lock(void)
10737{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070010738 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010739
10740 p_cds_context = cds_get_global_context();
10741 if (!p_cds_context) {
10742 hdd_err("cds context is NULL");
10743 return;
10744 }
10745
10746 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10747}
10748
Nirav Shahd21a2e32018-04-20 16:34:43 +053010749#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070010750void hdd_dp_trace_init(struct hdd_config *config)
10751{
10752
10753 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10754 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10755 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10756 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10757 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10758 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10759 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010760 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010761
Nirav Shahd21a2e32018-04-20 16:34:43 +053010762 if (!config->enable_dp_trace) {
10763 hdd_err("dp trace is disabled from ini");
10764 return;
10765 }
10766
Mohit Khannaf8f96822017-05-17 17:11:59 -070010767 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10768 &num_entries, sizeof(config_params));
10769
10770 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010771 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010772 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010773 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010774 else if (bw_compute_interval > 1000) {
10775 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10776 thresh_time_limit = 1;
10777 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010778 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10779
10780 switch (num_entries) {
10781 case 4:
10782 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010783 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010784 case 3:
10785 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010786 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010787 case 2:
10788 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010789 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010790 case 1:
10791 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010792 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010793 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010794 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010795 live_mode, thresh, thresh_time_limit,
10796 verbosity, proto_bitmap);
10797 };
10798
10799 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10800 verbosity, proto_bitmap);
10801
10802}
Nirav Shahd21a2e32018-04-20 16:34:43 +053010803#endif
10804
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010805/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010806 * hdd_wlan_startup() - HDD init function
10807 * @dev: Pointer to the underlying device
10808 *
10809 * This is the driver startup code executed once a WLAN device has been detected
10810 *
10811 * Return: 0 for success, < 0 for failure
10812 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010813int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010814{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010815 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010816 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010817 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010818 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010819
Dustin Brown491d54b2018-03-14 12:39:11 -070010820 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010821
Arun Khandavallifae92942016-08-01 13:31:08 +053010822 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010823
10824 if (IS_ERR(hdd_ctx))
10825 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010826
Abhishek Singhe9068f12017-03-31 14:14:52 +053010827 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10828 DEFAULT_PSOC_ID);
10829 if (ret) {
10830 hdd_err("Psoc creation fails!");
10831 QDF_BUG(0);
10832 goto err_hdd_free_context;
10833 }
10834
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010835 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010836#ifdef FEATURE_WLAN_CH_AVOID
10837 mutex_init(&hdd_ctx->avoid_freq_lock);
10838#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010839
Naveen Rawate02f8f52018-04-05 11:58:04 -070010840 osif_request_manager_init();
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010841 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010842 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010843
Dustin Brown021cecd2017-12-11 13:56:43 -080010844 hdd_driver_memdump_init();
10845
Dustin Browne7e71d32018-05-11 16:00:08 -070010846 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010847 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010848 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010849 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010850 }
10851
Yingying Tang80e15f32016-09-27 18:23:01 +080010852 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010853
Anurag Chouhan6d760662016-02-20 16:05:43 +053010854 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010855
10856 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010857 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010858 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010859 }
10860
Prashanth Bhatta07998752016-04-28 12:35:33 -070010861 ret = hdd_wiphy_init(hdd_ctx);
10862 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010863 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010864 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010865 }
10866
Nirav Shahd21a2e32018-04-20 16:34:43 +053010867 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010868
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010869 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010870
Paul Zhangfb02f452017-12-22 11:58:43 +080010871 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10872 if (ret) {
10873 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010874 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080010875 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010876
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010877 ret = register_reboot_notifier(&system_reboot_notifier);
10878 if (ret) {
10879 hdd_err("Failed to register reboot notifier: %d", ret);
10880 goto err_unregister_netdev;
10881 }
10882
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010883 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010884
Jeff Johnson957bc272017-02-02 08:54:48 -080010885 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10886 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010887 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010888 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010889 }
10890
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010891 hdd_release_rtnl_lock();
10892 rtnl_held = false;
10893
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010894 wlan_hdd_update_11n_mode(hdd_ctx->config);
10895
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010896#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010897 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010898 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010899 hdd_skip_acs_scan_timer_handler,
10900 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010901 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010902 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010903 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010904#endif
10905
Prashanth Bhattaab004382016-10-11 16:08:11 -070010906 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010907
Jeff Johnson9afc5012016-09-23 13:56:27 -070010908 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010909
Nirav Shahbd36b062016-07-18 11:12:59 +053010910 if (hdd_ctx->rps)
10911 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010912
Paul Zhangfb02f452017-12-22 11:58:43 +080010913 ret = hdd_register_notifiers(hdd_ctx);
10914 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010915 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010916
Paul Zhangfb02f452017-12-22 11:58:43 +080010917 status = wlansap_global_init();
10918 if (QDF_IS_STATUS_ERROR(status)) {
10919 hdd_unregister_notifiers(hdd_ctx);
10920 goto err_close_adapters;
10921 }
10922
Arun Khandavallifae92942016-08-01 13:31:08 +053010923 if (hdd_ctx->config->fIsImpsEnabled)
10924 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010925 else
10926 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010927
Mukul Sharma07bd8752017-10-10 16:58:14 +053010928 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010929 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10930 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010931 hdd_prevent_suspend_timeout(
10932 hdd_ctx->config->iface_change_wait_time,
10933 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10934 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010936 goto success;
10937
Jeff Johnson957bc272017-02-02 08:54:48 -080010938err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010939 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010940
Jeff Johnson46bde382017-02-01 15:31:16 -080010941err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010942 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010943 if (rtnl_held)
10944 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010945
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010946err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010947 unregister_netdevice_notifier(&hdd_netdev_notifier);
10948
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010949err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010950 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010951
Arun Khandavallifae92942016-08-01 13:31:08 +053010952err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010953 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010954
Dustin Brown021cecd2017-12-11 13:56:43 -080010955err_memdump_deinit:
10956 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010957
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010958 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070010959 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010960 hdd_exit_netlink_services(hdd_ctx);
10961
Dustin Brown20912462017-06-07 13:48:25 -070010962 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10963
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010964err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010965 if (cds_is_fw_down())
10966 hdd_err("Not setting the complete event as fw is down");
10967 else
10968 hdd_start_complete(ret);
10969
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010970 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010971 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010972 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010973
10974success:
Dustin Browne74003f2018-03-14 12:51:58 -070010975 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010976 return 0;
10977}
10978
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010979/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010980 * hdd_wlan_update_target_info() - update target type info
10981 * @hdd_ctx: HDD context
10982 * @context: hif context
10983 *
10984 * Update target info received from firmware in hdd context
10985 * Return:None
10986 */
10987
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010988void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010989{
10990 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10991
10992 if (!tgt_info) {
10993 hdd_err("Target info is Null");
10994 return;
10995 }
10996
10997 hdd_ctx->target_type = tgt_info->target_type;
10998}
10999
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011000void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011001{
11002 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011003 int status;
11004 struct hdd_adapter *adapter = NULL;
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011005 struct hdd_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011006
Dustin Brown491d54b2018-03-14 12:39:11 -070011007 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011008
11009 if (!rsp) {
11010 hdd_err("data is null");
11011 return;
11012 }
11013
11014 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011015 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011016 return;
11017
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011018 request = hdd_request_get(context);
11019 if (!request) {
11020 hdd_err("obselete request");
11021 return;
11022 }
11023
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011024 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11025 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11026 hdd_err("Invalid adapter or adapter has invalid magic");
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011027 hdd_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011028 return;
11029 }
11030
Dustin Brown5e89ef82018-03-14 11:50:23 -070011031 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11032 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11033 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11034 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11035 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11036 rsp->out_of_order_arp_rsp_drop_cnt);
11037 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
11038 hdd_info("rsp->connect_status :%x", rsp->connect_status);
11039 hdd_info("rsp->ba_session_establishment_status :%x",
11040 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011041
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011042 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011043 adapter->dad |= rsp->dad_detected;
11044 adapter->con_status = rsp->connect_status;
11045
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011046 /* Flag true indicates connectivity check stats present. */
11047 if (rsp->connect_stats_present) {
11048 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11049 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
11050 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11051 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11052 rsp->icmpv4_rsp_recvd;
11053 }
11054
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011055 hdd_request_complete(request);
11056 hdd_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011057
Dustin Browne74003f2018-03-14 12:51:58 -070011058 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011059}
11060
11061/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011062 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011063 * @hdd_ctx: HDD context
11064 *
11065 * Register the HDD callbacks to CDS/SME.
11066 *
11067 * Return: 0 for success or Error code for failure
11068 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011069int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011070{
11071 QDF_STATUS status;
11072 int ret = 0;
11073
Dustin Brown491d54b2018-03-14 12:39:11 -070011074 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011075
11076 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
11077
11078 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
11079 hdd_send_oem_data_rsp_msg);
11080
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011081 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
11082 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011083 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
11084 sme_nan_register_callback(hdd_ctx->hHal,
11085 wlan_hdd_cfg80211_nan_callback);
11086 sme_stats_ext_register_callback(hdd_ctx->hHal,
11087 wlan_hdd_cfg80211_stats_ext_callback);
11088
11089 sme_ext_scan_register_callback(hdd_ctx->hHal,
11090 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080011091 sme_stats_ext2_register_callback(hdd_ctx->hHal,
11092 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011093
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011094 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
11095 hdd_rssi_threshold_breached);
11096
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011097 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
11098 wlan_hdd_cfg80211_link_layer_stats_callback);
11099
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011100 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
11101
Zhang Qianca38fb12016-12-23 11:10:48 +080011102 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
11103 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11104
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011105 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
11106 hdd_lost_link_info_cb);
11107 /* print error and not block the startup process */
11108 if (!QDF_IS_STATUS_SUCCESS(status))
11109 hdd_err("set lost link info callback failed");
11110
Poddar, Siddarth34872782017-08-10 14:08:51 +053011111 ret = hdd_register_data_stall_detect_cb();
11112 if (ret) {
11113 hdd_err("Register data stall detect detect callback failed.");
11114 return ret;
11115 }
11116
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011117 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11118
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011119 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011120 hdd_set_connection_in_progress,
11121 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011122
11123 status = sme_congestion_register_callback(hdd_ctx->hHal,
11124 hdd_update_cca_info_cb);
11125 if (!QDF_IS_STATUS_SUCCESS(status))
11126 hdd_err("set congestion callback failed");
11127
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011128 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
11129 hdd_bt_activity_cb);
11130 if (!QDF_IS_STATUS_SUCCESS(status))
11131 hdd_err("set bt activity info callback failed");
11132
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011133 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
11134 hdd_tx_queue_cb);
11135 if (!QDF_IS_STATUS_SUCCESS(status))
11136 hdd_err("Register tx queue callback failed");
11137
Dustin Browne74003f2018-03-14 12:51:58 -070011138 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011139
11140 return ret;
11141}
11142
11143/**
11144 * hdd_deregister_cb() - De-Register HDD callbacks.
11145 * @hdd_ctx: HDD context
11146 *
11147 * De-Register the HDD callbacks to CDS/SME.
11148 *
11149 * Return: void
11150 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011151void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011152{
11153 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011154 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011155
Dustin Brown491d54b2018-03-14 12:39:11 -070011156 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011157
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011158 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011159 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
11160 if (!QDF_IS_STATUS_SUCCESS(status))
11161 hdd_err("De-register of dcc stats callback failed: %d",
11162 status);
11163
11164 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011165 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
11166
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011167 sme_stats_ext_register_callback(hdd_ctx->hHal,
11168 wlan_hdd_cfg80211_stats_ext_callback);
11169
11170 sme_nan_deregister_callback(hdd_ctx->hHal);
11171 status = sme_reset_tsfcb(hdd_ctx->hHal);
11172 if (!QDF_IS_STATUS_SUCCESS(status))
11173 hdd_err("Failed to de-register tsfcb the callback:%d",
11174 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011175
Poddar, Siddarth34872782017-08-10 14:08:51 +053011176 ret = hdd_deregister_data_stall_detect_cb();
11177 if (ret)
11178 hdd_err("Failed to de-register data stall detect event callback");
11179
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011180 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
11181 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
11182
Dustin Browne74003f2018-03-14 12:51:58 -070011183 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011184}
11185
11186/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011187 * hdd_softap_sta_deauth() - handle deauth req from HDD
11188 * @adapter: Pointer to the HDD
11189 * @enable: bool value
11190 *
11191 * This to take counter measure to handle deauth req from HDD
11192 *
11193 * Return: None
11194 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011195QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011196 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011197{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011198 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011199
Dustin Brown491d54b2018-03-14 12:39:11 -070011200 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011202 /* Ignore request to deauth bcmc station */
11203 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011204 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011205
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011206 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011207 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11208 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011209
Dustin Browne74003f2018-03-14 12:51:58 -070011210 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011211 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011212}
11213
11214/**
11215 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11216 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011217 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011218 *
11219 * This to take counter measure to handle deauth req from HDD
11220 *
11221 * Return: None
11222 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011223void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011224 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011225{
Dustin Brown491d54b2018-03-14 12:39:11 -070011226 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011227
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011228 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011229 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011230 return;
11231
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011232 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011233 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011234}
11235
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011236/**
11237 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11238 * @hdd_ctx: HDD Context
11239 *
11240 * API to find if there is any STA or P2P-Client is connected
11241 *
11242 * Return: true if connected; false otherwise
11243 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011244QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011245{
11246 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
11247}
11248
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011249/**
11250 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
11251 * @adapter: HDD adapter pointer
11252 *
11253 * This function loop through each adapter and disable roaming on each STA
11254 * device mode except the input adapter.
11255 *
11256 * Note: On the input adapter roaming is not enabled yet hence no need to
11257 * disable.
11258 *
11259 * Return: None
11260 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011261void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011262{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011263 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011264 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011265
11266 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011267 hdd_ctx->config->isRoamOffloadScanEnabled &&
11268 QDF_STA_MODE == adapter->device_mode &&
11269 policy_mgr_is_sta_active_connection_exists(
11270 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011271 hdd_debug("Connect received on STA session Id(%d)",
11272 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011273 /*
11274 * Loop through adapter and disable roaming for each STA device
11275 * mode except the input adapter.
11276 */
Dustin Brown920397d2017-12-13 16:27:50 -080011277 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011278 if (QDF_STA_MODE == adapterIdx->device_mode &&
11279 adapter->session_id != adapterIdx->session_id) {
11280 hdd_debug("Disable Roaming on session Id(%d)",
11281 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011282 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
11283 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011284 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011285 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011286 }
11287 }
11288}
11289
11290/**
11291 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
11292 * @adapter: HDD adapter pointer
11293 *
11294 * This function loop through each adapter and enable roaming on each STA
11295 * device mode except the input adapter.
11296 * Note: On the input adapter no need to enable roaming because link got
11297 * disconnected on this.
11298 *
11299 * Return: None
11300 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011301void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011302{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011303 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011304 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011305
11306 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011307 hdd_ctx->config->isRoamOffloadScanEnabled &&
11308 QDF_STA_MODE == adapter->device_mode &&
11309 policy_mgr_is_sta_active_connection_exists(
11310 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011311 hdd_debug("Disconnect received on STA session Id(%d)",
11312 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011313 /*
11314 * Loop through adapter and enable roaming for each STA device
11315 * mode except the input adapter.
11316 */
Dustin Brown920397d2017-12-13 16:27:50 -080011317 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011318 if (QDF_STA_MODE == adapterIdx->device_mode &&
11319 adapter->session_id != adapterIdx->session_id) {
11320 hdd_debug("Enabling Roaming on session Id(%d)",
11321 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011322 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
11323 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011324 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011325 REASON_CONNECT);
11326 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011327 }
11328 }
11329}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011330
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011331/**
11332 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11333 * @skb: sk buffer pointer
11334 *
11335 * Sends the bcast message to SVC multicast group with generic nl socket
11336 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11337 *
11338 * Return: None
11339 */
11340static void nl_srv_bcast_svc(struct sk_buff *skb)
11341{
11342#ifdef CNSS_GENL
11343 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11344#else
11345 nl_srv_bcast(skb);
11346#endif
11347}
11348
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011349void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011350{
11351 struct sk_buff *skb;
11352 struct nlmsghdr *nlh;
11353 tAniMsgHdr *ani_hdr;
11354 void *nl_data = NULL;
11355 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011356 struct radio_index_tlv *radio_info;
11357 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011358
11359 if (in_interrupt() || irqs_disabled() || in_atomic())
11360 flags = GFP_ATOMIC;
11361
11362 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11363
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011364 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011365 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011366
11367 nlh = (struct nlmsghdr *)skb->data;
11368 nlh->nlmsg_pid = 0; /* from kernel */
11369 nlh->nlmsg_flags = 0;
11370 nlh->nlmsg_seq = 0;
11371 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11372
11373 ani_hdr = NLMSG_DATA(nlh);
11374 ani_hdr->type = type;
11375
11376 switch (type) {
11377 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011378 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011379 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011380 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011381 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011382 ani_hdr->length = 0;
11383 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011384 break;
11385 case WLAN_SVC_WLAN_STATUS_IND:
11386 case WLAN_SVC_WLAN_VERSION_IND:
11387 case WLAN_SVC_DFS_CAC_START_IND:
11388 case WLAN_SVC_DFS_CAC_END_IND:
11389 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11390 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11391 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011392 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011393 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011394 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011395 ani_hdr->length = len;
11396 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11397 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11398 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011399 break;
11400
11401 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011402 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011403 type);
11404 kfree_skb(skb);
11405 return;
11406 }
11407
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011408 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011409 * Add radio index at the end of the svc event in TLV format
11410 * to maintain the backward compatibility with userspace
11411 * applications.
11412 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011413
11414 tlv_len = 0;
11415
11416 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11417 < WLAN_NL_MAX_PAYLOAD) {
11418 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11419 sizeof(*ani_hdr) + len);
11420 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11421 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11422 radio_info->radio = radio;
11423 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011424 hdd_debug("Added radio index tlv - radio index %d",
11425 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011426 }
11427
11428 nlh->nlmsg_len += tlv_len;
11429 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11430
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011431 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011432}
11433
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011434#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11435void wlan_hdd_auto_shutdown_cb(void)
11436{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011437 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011438
11439 if (!hdd_ctx)
11440 return;
11441
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011442 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011443 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11444 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011445}
11446
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011447void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011448{
Jeff Johnson9d295242017-08-29 14:39:48 -070011449 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011450 bool ap_connected = false, sta_connected = false;
11451 tHalHandle hal_handle;
11452
11453 hal_handle = hdd_ctx->hHal;
11454 if (hal_handle == NULL)
11455 return;
11456
11457 if (hdd_ctx->config->WlanAutoShutdown == 0)
11458 return;
11459
11460 if (enable == false) {
11461 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011462 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011463 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011464 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011465 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011466 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011467 return;
11468 }
11469
11470 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011471 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11472 hdd_for_each_adapter(hdd_ctx, adapter) {
11473 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011474 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11475 conn_info.connState ==
11476 eConnectionState_Associated) {
11477 sta_connected = true;
11478 break;
11479 }
11480 }
Dustin Brown920397d2017-12-13 16:27:50 -080011481
11482 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011483 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011484 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011485 ap_connected = true;
11486 break;
11487 }
11488 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011489 }
11490 }
11491
11492 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011493 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011494 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011495 }
Jeff Johnson68755312017-02-10 11:46:55 -080011496
11497 if (sme_set_auto_shutdown_timer(hal_handle,
11498 hdd_ctx->config->WlanAutoShutdown)
11499 != QDF_STATUS_SUCCESS)
11500 hdd_err("Failed to start wlan auto shutdown timer");
11501 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011502 hdd_info("Auto Shutdown timer for %d seconds enabled",
11503 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011504}
11505#endif
11506
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011507struct hdd_adapter *
11508hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11509 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011510{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011511 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011512 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011513
11514 con_sap_adapter = NULL;
11515
Dustin Brown920397d2017-12-13 16:27:50 -080011516 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011517 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11518 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011519 adapter != this_sap_adapter) {
11520 if (check_start_bss) {
11521 if (test_bit(SOFTAP_BSS_STARTED,
11522 &adapter->event_flags)) {
11523 con_sap_adapter = adapter;
11524 break;
11525 }
11526 } else {
11527 con_sap_adapter = adapter;
11528 break;
11529 }
11530 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011531 }
11532
11533 return con_sap_adapter;
11534}
11535
11536#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011537static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011538{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011539 return adapter->device_mode == QDF_STA_MODE ||
11540 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011541}
11542
Jeff Johnson9d295242017-08-29 14:39:48 -070011543static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011544{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011545 return adapter->device_mode == QDF_SAP_MODE ||
11546 adapter->device_mode == QDF_P2P_GO_MODE;
11547}
11548
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011549static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011550{
Dustin Brown920397d2017-12-13 16:27:50 -080011551 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011552
Dustin Brown920397d2017-12-13 16:27:50 -080011553 hdd_for_each_adapter(hdd_ctx, adapter) {
11554 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011555 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11556 conn_info.connState == eConnectionState_Associated) {
11557 return true;
11558 }
11559
Dustin Brown920397d2017-12-13 16:27:50 -080011560 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011561 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011562 return true;
11563 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011564 }
11565
11566 return false;
11567}
11568
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011569static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011570{
11571 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011572
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011573 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011574 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011575 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011576
Dustin Brown5ec6b552017-03-31 12:11:40 -070011577 return is_running;
11578}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011579
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011580static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011581{
11582 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11583 hdd_ctx->bus_bw_timer_running = true;
11584 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11585 hdd_ctx->config->busBandwidthComputeInterval);
11586 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11587}
11588
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011589void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011590{
Dustin Brown491d54b2018-03-14 12:39:11 -070011591 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011592
11593 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11594 hdd_debug("Bandwidth compute timer already started");
11595 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011596 }
11597
Dustin Brown5ec6b552017-03-31 12:11:40 -070011598 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11599
Dustin Browne74003f2018-03-14 12:51:58 -070011600 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011601}
11602
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011603void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011604{
Dustin Brown491d54b2018-03-14 12:39:11 -070011605 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011606
11607 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11608 hdd_debug("Bandwidth compute timer already started");
11609 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011610 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011611
11612 if (hdd_any_adapter_is_assoc(hdd_ctx))
11613 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11614
Dustin Browne74003f2018-03-14 12:51:58 -070011615 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011616}
11617
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011618static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011619{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011620 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011621
11622 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11623 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11624 hdd_ctx->bus_bw_timer_running = false;
11625 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11626
11627 hdd_reset_tcp_delack(hdd_ctx);
11628}
11629
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011630void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011631{
Dustin Brown491d54b2018-03-14 12:39:11 -070011632 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011633
11634 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11635 hdd_debug("Bandwidth compute timer already stopped");
11636 return;
11637 }
11638
11639 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11640
Dustin Browne74003f2018-03-14 12:51:58 -070011641 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011642}
11643
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011644void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011645{
Dustin Brown491d54b2018-03-14 12:39:11 -070011646 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011647
11648 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11649 hdd_debug("Bandwidth compute timer already stopped");
11650 return;
11651 }
11652
11653 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11654 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11655
Dustin Browne74003f2018-03-14 12:51:58 -070011656 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011657}
11658#endif
11659
11660/**
11661 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11662 * and sta's operating channel.
11663 * @sta_adapter: Describe the first argument to foobar.
11664 * @ap_adapter: Describe the second argument to foobar.
11665 * @roam_profile: Roam profile of AP to which STA wants to connect.
11666 * @concurrent_chnl_same: If both SAP and STA channels are same then
11667 * set this flag to true else false.
11668 *
11669 * This function checks the sap's operating channel and sta's operating channel.
11670 * if both are same then it will return false else it will restart the sap in
11671 * sta's channel and return true.
11672 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011673 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011674 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011675QDF_STATUS
11676wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11677 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011678 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011679 tScanResultHandle *scan_cache,
11680 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011681{
Jeff Johnson87251032017-08-29 13:31:11 -070011682 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011683 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011684 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011685 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011686 *concurrent_chnl_same = true;
11687
11688 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11689 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011690 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011691 scan_cache,
11692 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011693 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011694 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011695 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011696 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011697 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011698 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011699 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011700 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011701 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011702 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011703 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011704 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011705 }
11706 }
11707 } else {
11708 /*
11709 * Lets handle worst case scenario here, Scan cache lookup is
11710 * failed so we have to stop the SAP to avoid any channel
11711 * discrepancy between SAP's channel and STA's channel.
11712 * Return the status as failure so caller function could know
11713 * that scan look up is failed.
11714 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011715 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011716 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011717 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011718 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011719}
11720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011721/**
11722 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11723 * @ap_adapter: SAP adapter
11724 *
11725 * This function will process the stopping of sap adapter.
11726 *
11727 * Return: None
11728 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011729void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011730{
Jeff Johnson87251032017-08-29 13:31:11 -070011731 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011732 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011733 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011734 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011735
11736 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011737 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011738 return;
11739 }
11740
11741 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11742 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011743 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011744 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011745
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011746 mutex_lock(&hdd_ctx->sap_lock);
11747 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011748 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011749 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011750 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011751 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011752 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011753 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011754 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011755 qdf_stop_bss_event,
11756 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011757 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011758 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011759 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011760 return;
11761 }
11762 }
11763 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011764 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11765 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011766 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011767 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011768 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011769 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011770 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011771 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011772 }
11773 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011774}
11775
11776/**
11777 * wlan_hdd_start_sap() - this function starts bss of SAP.
11778 * @ap_adapter: SAP adapter
11779 *
11780 * This function will process the starting of sap adapter.
11781 *
11782 * Return: None
11783 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011784void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011785{
Jeff Johnson87251032017-08-29 13:31:11 -070011786 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011787 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011788 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011789 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070011790 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011791
11792 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011793 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011794 return;
11795 }
11796
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011797 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011798 hdd_err("SoftAp role has not been enabled");
11799 return;
11800 }
11801
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011802 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11803 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11804 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011805 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011807 mutex_lock(&hdd_ctx->sap_lock);
11808 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11809 goto end;
11810
11811 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011812 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011813 goto end;
11814 }
11815
Wei Song2f76f642016-11-18 16:32:53 +080011816 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011817 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011818 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011819 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011820 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011821 goto end;
11822
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011823 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011824 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011825 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011826 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011827 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011828 goto end;
11829 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011830 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011831 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011832 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011833 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011834 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11835 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011836 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011837 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011838 true);
11839 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011840 mutex_unlock(&hdd_ctx->sap_lock);
11841
11842 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011843end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011844 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011845 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011846 /* SAP context and beacon cleanup will happen during driver unload
11847 * in hdd_stop_adapter
11848 */
11849 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11850
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011851}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011852
11853/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011854 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11855 * mac scan config
11856 * @status: Status of set antenna mode
11857 *
11858 * Callback on setting the dual mac configuration
11859 *
11860 * Return: None
11861 */
11862void wlan_hdd_soc_set_antenna_mode_cb(
11863 enum set_antenna_mode_status status)
11864{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011865 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011866
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011867 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011868
11869 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11870 if (0 != wlan_hdd_validate_context(hdd_ctx))
11871 return;
11872
11873 /* Signal the completion of set dual mac config */
11874 complete(&hdd_ctx->set_antenna_mode_cmpl);
11875}
11876
11877/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011878 * hdd_get_fw_version() - Get FW version
11879 * @hdd_ctx: pointer to HDD context.
11880 * @major_spid: FW version - major spid.
11881 * @minor_spid: FW version - minor spid
11882 * @ssid: FW version - ssid
11883 * @crmid: FW version - crmid
11884 *
11885 * This function is called to get the firmware build version stored
11886 * as part of the HDD context
11887 *
11888 * Return: None
11889 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011890void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011891 uint32_t *major_spid, uint32_t *minor_spid,
11892 uint32_t *siid, uint32_t *crmid)
11893{
11894 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11895 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11896 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11897 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11898}
11899
11900#ifdef QCA_CONFIG_SMP
11901/**
11902 * wlan_hdd_get_cpu() - get cpu_index
11903 *
11904 * Return: cpu_index
11905 */
11906int wlan_hdd_get_cpu(void)
11907{
11908 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011909
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011910 put_cpu();
11911 return cpu_index;
11912}
11913#endif
11914
11915/**
11916 * hdd_get_fwpath() - get framework path
11917 *
11918 * This function is used to get the string written by
11919 * userspace to start the wlan driver
11920 *
11921 * Return: string
11922 */
11923const char *hdd_get_fwpath(void)
11924{
11925 return fwpath.string;
11926}
11927
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011928static int hdd_qdf_print_init(void)
11929{
11930 int qdf_print_idx;
11931 QDF_STATUS status;
11932
11933 status = qdf_print_setup();
11934 if (status != QDF_STATUS_SUCCESS) {
11935 pr_err("qdf_print_setup failed\n");
11936 return -EINVAL;
11937 }
11938
11939 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11940
11941 if (qdf_print_idx < 0) {
11942 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11943 qdf_print_idx);
11944 return -EINVAL;
11945 }
11946
11947 qdf_set_pidx(qdf_print_idx);
11948
11949 return 0;
11950}
11951
11952static void hdd_qdf_print_deinit(void)
11953{
11954 int qdf_print_idx;
11955
11956 qdf_print_idx = qdf_get_pidx();
11957 qdf_print_ctrl_cleanup(qdf_print_idx);
11958}
11959
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011960/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011961 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011962 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011963 * This function initilizes CDS global context with the help of cds_init. This
11964 * has to be the first function called after probe to get a valid global
11965 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011966 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011967 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011968 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011969int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011970{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011971 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011972 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011973
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011974 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011975 if (QDF_IS_STATUS_ERROR(status)) {
11976 hdd_err("Failed to allocate CDS context");
11977 ret = -ENOMEM;
11978 goto err_out;
11979 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011980
11981 wlan_init_bug_report_lock();
11982
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011983#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11984 wlan_logging_sock_init_svc();
11985#endif
11986
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011987 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11988 (void *)hdd_drv_ops_inactivity_handler, NULL,
11989 QDF_TIMER_TYPE_SW);
11990
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011991 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011992 hdd_qdf_print_init();
11993
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011994 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011995
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011996err_out:
11997 return ret;
11998}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011999
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012000/**
12001 * hdd_deinit() - Deinitialize Driver
12002 *
12003 * This function frees CDS global context with the help of cds_deinit. This
12004 * has to be the last function call in remove callback to free the global
12005 * context.
12006 */
12007void hdd_deinit(void)
12008{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012009 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012010
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070012011 wlan_destroy_bug_report_lock();
12012 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012013
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070012014 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012015#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12016 wlan_logging_sock_deinit_svc();
12017#endif
12018}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012019
Yue Ma6e7b1a02017-04-03 14:17:46 -070012020#ifdef QCA_WIFI_NAPIER_EMULATION
12021#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12022#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012023#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012024#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012025
Sachin Ahujadddd2632017-03-07 19:07:24 +053012026static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12027 struct file *file)
12028{
12029 return 0;
12030}
12031
12032static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12033 const char __user *user_buf,
12034 size_t count,
12035 loff_t *f_pos)
12036{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012037 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012038 static const char wlan_off_str[] = "OFF";
12039 static const char wlan_on_str[] = "ON";
12040 int ret;
12041 unsigned long rc;
12042
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012043 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012044 pr_err("Failed to read buffer\n");
12045 return -EINVAL;
12046 }
12047
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012048 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012049 pr_debug("Wifi turning off from UI\n");
12050 goto exit;
12051 }
12052
Sachin Ahuja16904db2017-12-13 19:56:57 +053012053 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
12054 pr_info("Wifi Turning On from UI\n");
12055 }
12056
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012057 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012058 pr_err("Invalid value received from framework");
12059 goto exit;
12060 }
12061
12062 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012063 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012064 rc = wait_for_completion_timeout(&wlan_start_comp,
12065 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12066 if (!rc) {
12067 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
12068 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012069 return ret;
12070 }
12071
12072 hdd_start_complete(0);
12073 }
12074
12075exit:
12076 return count;
12077}
12078
12079
12080const struct file_operations wlan_hdd_state_fops = {
12081 .owner = THIS_MODULE,
12082 .open = wlan_hdd_state_ctrl_param_open,
12083 .write = wlan_hdd_state_ctrl_param_write,
12084};
12085
12086static int wlan_hdd_state_ctrl_param_create(void)
12087{
12088 unsigned int wlan_hdd_state_major = 0;
12089 int ret;
12090 struct device *dev;
12091
12092 device = MKDEV(wlan_hdd_state_major, 0);
12093
12094 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12095 if (ret) {
12096 pr_err("Failed to register qcwlanstate");
12097 goto dev_alloc_err;
12098 }
12099 wlan_hdd_state_major = MAJOR(device);
12100
12101 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12102 if (IS_ERR(class)) {
12103 pr_err("wlan_hdd_state class_create error");
12104 goto class_err;
12105 }
12106
12107 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12108 if (IS_ERR(dev)) {
12109 pr_err("wlan_hdd_statedevice_create error");
12110 goto err_class_destroy;
12111 }
12112
12113 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12114 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12115 if (ret) {
12116 pr_err("Failed to add cdev error");
12117 goto cdev_add_err;
12118 }
12119
12120 pr_info("wlan_hdd_state %s major(%d) initialized",
12121 WLAN_MODULE_NAME, wlan_hdd_state_major);
12122
12123 return 0;
12124
12125cdev_add_err:
12126 device_destroy(class, device);
12127err_class_destroy:
12128 class_destroy(class);
12129class_err:
12130 unregister_chrdev_region(device, dev_num);
12131dev_alloc_err:
12132 return -ENODEV;
12133}
12134
12135static void wlan_hdd_state_ctrl_param_destroy(void)
12136{
12137 cdev_del(&wlan_hdd_state_cdev);
12138 device_destroy(class, device);
12139 class_destroy(class);
12140 unregister_chrdev_region(device, dev_num);
12141
12142 pr_info("Device node unregistered");
12143}
12144
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012145/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053012146 * component_init - API to init cld component's
12147 *
12148 * Return: None
12149 */
12150static void component_init(void)
12151{
12152 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012153 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012154 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012155 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012156}
12157
12158/**
12159 * component_deinit - API to deinit cld component's
12160 *
12161 * Return: None
12162 */
12163static void component_deinit(void)
12164{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012165 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012166 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012167 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012168 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012169}
12170
12171void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12172{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012173 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012174 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012175}
12176
12177void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12178{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012179 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012180 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012181}
12182
12183/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012184 * __hdd_module_init - Module init helper
12185 *
12186 * Module init helper function used by both module and static driver.
12187 *
12188 * Return: 0 for success, errno on failure
12189 */
12190static int __hdd_module_init(void)
12191{
12192 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012193
Dustin Brown96cd9632017-11-13 12:45:04 -080012194 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012195 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012196 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012197 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012198
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012199 pld_init();
12200
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012201 ret = hdd_init();
12202 if (ret) {
12203 pr_err("hdd_init failed %x\n", ret);
12204 goto err_hdd_init;
12205 }
12206
Rajeev Kumar97767a02016-11-30 11:20:40 -080012207 dispatcher_init();
12208
Mukul Sharmad75a6672017-06-22 15:40:53 +053012209 /* Ensure to call post objmgr init */
12210 component_init();
12211
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012212 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012213
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012214 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012215
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012216 ret = wlan_hdd_register_driver();
12217 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012218 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12219 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012220 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012221 }
12222
Sachin Ahuja16904db2017-12-13 19:56:57 +053012223 ret = wlan_hdd_state_ctrl_param_create();
12224 if (ret) {
12225 pr_err("wlan_hdd_state_create:%x\n", ret);
12226 goto out;
12227 }
12228
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012229 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012230
12231 return 0;
12232out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012233 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012234 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012235 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012236 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012237
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012238err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012239 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012240 return ret;
12241}
12242
12243/**
12244 * __hdd_module_exit - Module exit helper
12245 *
12246 * Module exit helper function used by both module and static driver.
12247 */
12248static void __hdd_module_exit(void)
12249{
Will Huang36049722018-04-13 11:48:51 +080012250 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012251
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012252 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12253 QWLAN_VERSIONSTR);
12254
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012255 if (!hdd_wait_for_recovery_completion())
12256 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012257
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012258 if (hdd_ctx)
12259 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012260
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012261 wlan_hdd_unregister_driver();
12262
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012263 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012264
Mukul Sharmad75a6672017-06-22 15:40:53 +053012265 /* Ensure to call prior to objmgr deinit */
12266 component_deinit();
12267
Rajeev Kumar97767a02016-11-30 11:20:40 -080012268 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012269
12270 hdd_sysfs_destroy_version_interface();
12271
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012272 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012273 pld_deinit();
12274
Sachin Ahujadddd2632017-03-07 19:07:24 +053012275 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012276}
12277
Arun Khandavallifae92942016-08-01 13:31:08 +053012278#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012279/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012280 * wlan_boot_cb() - Wlan boot callback
12281 * @kobj: object whose directory we're creating the link in.
12282 * @attr: attribute the user is interacting with
12283 * @buff: the buffer containing the user data
12284 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012285 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012286 * This callback is invoked when the fs is ready to start the
12287 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012288 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012289 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012290 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012291static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012292 struct kobj_attribute *attr,
12293 const char *buf,
12294 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012295{
Arun Khandavallifae92942016-08-01 13:31:08 +053012296
Arun Khandavallifae92942016-08-01 13:31:08 +053012297 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012298 pr_err("%s: wlan driver already initialized\n", __func__);
12299 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012300 }
12301
Arun Khandavallifae92942016-08-01 13:31:08 +053012302 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012303 pr_err("%s: wlan driver initialization failed\n", __func__);
12304 return -EIO;
12305 }
12306
12307 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012308
12309 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012310}
Arun Khandavallifae92942016-08-01 13:31:08 +053012311
12312/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012313 * hdd_sysfs_cleanup() - cleanup sysfs
12314 *
12315 * Return: None
12316 *
12317 */
12318static void hdd_sysfs_cleanup(void)
12319{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012320 /* remove from group */
12321 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12322 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12323 wlan_loader->attr_group);
12324
12325 /* unlink the object from parent */
12326 kobject_del(wlan_loader->boot_wlan_obj);
12327
12328 /* free the object */
12329 kobject_put(wlan_loader->boot_wlan_obj);
12330
12331 kfree(wlan_loader->attr_group);
12332 kfree(wlan_loader);
12333
12334 wlan_loader = NULL;
12335}
12336
12337/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012338 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12339 * ready
12340 *
12341 * This is creates the syfs entry boot_wlan. Which shall be invoked
12342 * when the filesystem is ready.
12343 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012344 * QDF API cannot be used here since this function is called even before
12345 * initializing WLAN driver.
12346 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012347 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012348 */
12349static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012350{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012351 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012352
12353 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012354 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012355 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012356
12357 wlan_loader->boot_wlan_obj = NULL;
12358 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12359 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012360 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012361 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012362
12363 wlan_loader->loaded_state = 0;
12364 wlan_loader->attr_group->attrs = attrs;
12365
12366 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12367 kernel_kobj);
12368 if (!wlan_loader->boot_wlan_obj) {
12369 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012370 goto error_return;
12371 }
12372
12373 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12374 wlan_loader->attr_group);
12375 if (ret) {
12376 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12377 goto error_return;
12378 }
12379
12380 return 0;
12381
12382error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012383 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012384
12385 return ret;
12386}
12387
12388/**
12389 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12390 *
12391 * Return: 0 on success or errno on failure
12392 */
12393static int wlan_deinit_sysfs(void)
12394{
Arun Khandavallifae92942016-08-01 13:31:08 +053012395 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012396 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012397 return -EINVAL;
12398 }
12399
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012400 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012401 return 0;
12402}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012403
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012404#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012405
12406#ifdef MODULE
12407/**
12408 * __hdd_module_init - Module init helper
12409 *
12410 * Module init helper function used by both module and static driver.
12411 *
12412 * Return: 0 for success, errno on failure
12413 */
12414static int hdd_module_init(void)
12415{
Arun Khandavallifae92942016-08-01 13:31:08 +053012416 if (__hdd_module_init()) {
12417 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012418 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012419 }
12420
Dustin Brownab482ac2017-06-09 17:00:44 -070012421 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012422}
12423#else
12424static int __init hdd_module_init(void)
12425{
12426 int ret = -EINVAL;
12427
12428 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012429 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012430 pr_err("Failed to create sysfs entry for loading wlan");
12431
12432 return ret;
12433}
12434#endif
12435
12436
12437#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012438/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012439 * hdd_module_exit() - Exit function
12440 *
12441 * This is the driver exit point (invoked when module is unloaded using rmmod)
12442 *
12443 * Return: None
12444 */
12445static void __exit hdd_module_exit(void)
12446{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012447 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012448}
Arun Khandavallifae92942016-08-01 13:31:08 +053012449#else
12450static void __exit hdd_module_exit(void)
12451{
12452 __hdd_module_exit();
12453 wlan_deinit_sysfs();
12454}
12455#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012456
Srinivas Girigowda841da292018-02-21 16:33:00 -080012457static int fwpath_changed_handler(const char *kmessage,
12458 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012459{
12460 return param_set_copystring(kmessage, kp);
12461}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012462
Nirav Shah73713f72018-05-17 14:50:41 +053012463#ifdef FEATURE_MONITOR_MODE_SUPPORT
12464static bool is_monitor_mode_supported(void)
12465{
12466 return true;
12467}
12468#else
12469static bool is_monitor_mode_supported(void)
12470{
12471 pr_err("Monitor mode not supported!");
12472 return false;
12473}
12474#endif
12475
12476#ifdef WLAN_FEATURE_EPPING
12477static bool is_epping_mode_supported(void)
12478{
12479 return true;
12480}
12481#else
12482static bool is_epping_mode_supported(void)
12483{
12484 pr_err("Epping mode not supported!");
12485 return false;
12486}
12487#endif
12488
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012489/**
12490 * is_con_mode_valid() check con mode is valid or not
12491 * @mode: global con mode
12492 *
12493 * Return: TRUE on success FALSE on failure
12494 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012495static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012496{
12497 switch (mode) {
12498 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012499 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012500 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012501 return is_epping_mode_supported();
12502 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012503 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012504 return true;
12505 default:
12506 return false;
12507 }
12508}
12509
12510/**
12511 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12512 * @mode: global con mode
12513 *
12514 * Return: adapter mode
12515 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012516static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012517 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012518{
12519
12520 switch (mode) {
12521 case QDF_GLOBAL_MISSION_MODE:
12522 return QDF_STA_MODE;
12523 case QDF_GLOBAL_MONITOR_MODE:
12524 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012525 case QDF_GLOBAL_EPPING_MODE:
12526 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012527 case QDF_GLOBAL_FTM_MODE:
12528 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012529 case QDF_GLOBAL_QVIT_MODE:
12530 return QDF_QVIT_MODE;
12531 default:
12532 return QDF_MAX_NO_OF_MODE;
12533 }
12534}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012535
Dustin Brown27cd9942017-09-27 16:11:44 -070012536static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012537 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012538{
12539 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12540 return;
12541
12542 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012543 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012544 hdd_info("Release wakelock for monitor mode!");
12545 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12546 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012547 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012548 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012549 case QDF_GLOBAL_FTM_MODE:
12550 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012551 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012552 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012553
Dustin Brown27cd9942017-09-27 16:11:44 -070012554 break;
12555 default:
12556 break;
12557 }
12558}
12559
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012560static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012561 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012562{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012563 int driver_status;
12564
12565 driver_status = hdd_ctx->driver_status;
12566
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012567 switch (curr_mode) {
12568 case QDF_GLOBAL_MISSION_MODE:
12569 case QDF_GLOBAL_MONITOR_MODE:
12570 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012571 hdd_deinit_all_adapters(hdd_ctx, false);
12572 hdd_close_all_adapters(hdd_ctx, false);
12573 break;
12574 case QDF_GLOBAL_EPPING_MODE:
12575 epping_disable();
12576 epping_close();
12577 break;
12578 default:
12579 return;
12580 }
12581}
12582
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012583static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012584 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012585{
Jeff Johnson9d295242017-08-29 14:39:48 -070012586 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012587 int ret = 0;
12588 bool rtnl_held;
12589 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12590 QDF_STATUS status;
12591
12592 if (!qdf_dev) {
12593 hdd_err("qdf device context is Null return!");
12594 return -EINVAL;
12595 }
12596
12597 rtnl_held = hdd_hold_rtnl_lock();
12598 switch (mode) {
12599 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012600 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12601 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012602 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012603 break;
12604 case QDF_GLOBAL_FTM_MODE:
12605 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12606 wlan_hdd_get_intf_addr(hdd_ctx),
12607 NET_NAME_UNKNOWN, rtnl_held);
12608 if (adapter == NULL)
12609 ret = -EINVAL;
12610 break;
12611 case QDF_GLOBAL_MONITOR_MODE:
12612 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12613 wlan_hdd_get_intf_addr(hdd_ctx),
12614 NET_NAME_UNKNOWN, rtnl_held);
12615 if (adapter == NULL)
12616 ret = -EINVAL;
12617 break;
12618 case QDF_GLOBAL_EPPING_MODE:
12619 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012620 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012621 hdd_err("Failed to open in eeping mode: %d", status);
12622 ret = -EINVAL;
12623 break;
12624 }
12625 ret = epping_enable(qdf_dev->dev);
12626 if (ret) {
12627 hdd_err("Failed to enable in epping mode : %d", ret);
12628 epping_close();
12629 }
12630 break;
12631 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012632 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012633 ret = -ENOTSUPP;
12634 break;
12635 }
12636 hdd_release_rtnl_lock();
12637 rtnl_held = false;
12638 return ret;
12639}
12640
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012641/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012642 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012643 * @kmessage: con mode name on which driver to be bring up
12644 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012645 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012646 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012647 * This function is invoked when user updates con mode using sys entry,
12648 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012649 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012650 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012651 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012652static int __con_mode_handler(const char *kmessage,
12653 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012654 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012655{
12656 int ret;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012657 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012658 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012659 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012660
Dustin Brownab6029b2017-05-24 13:04:19 -070012661 hdd_info("con_mode handler: %s", kmessage);
12662
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012663 ret = wlan_hdd_validate_context(hdd_ctx);
12664 if (ret)
12665 return ret;
12666
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012667 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012668
Dustin Brown20024e32018-01-03 12:34:58 -080012669 ret = kstrtoint(kmessage, 0, &new_con_mode);
12670 if (ret) {
12671 hdd_err("Failed to parse con_mode '%s'", kmessage);
12672 goto reset_flags;
12673 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012674 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012675
Dustin Brown20024e32018-01-03 12:34:58 -080012676 if (!is_con_mode_valid(new_con_mode)) {
12677 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012678 ret = -EINVAL;
12679 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012680 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012681
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012682 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012683 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012684 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012685 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012686 ret = 0;
12687 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012688 }
12689
Dustin Brown27cd9942017-09-27 16:11:44 -070012690 /* ensure adapters are stopped */
12691 hdd_stop_present_mode(hdd_ctx, curr_mode);
12692
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012693 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012694 if (ret) {
12695 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012696 goto reset_flags;
12697 }
12698
Dustin Browndd4e50f2018-05-24 15:43:42 -070012699 /* Cleanup present mode before switching to new mode */
12700 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012701
Dustin Brown20024e32018-01-03 12:34:58 -080012702 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012703
12704 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012705 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012706 if (ret) {
12707 hdd_err("Failed to register for new mode");
12708 goto reset_flags;
12709 }
12710
Dustin Brown20024e32018-01-03 12:34:58 -080012711 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012712 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12713 hdd_err("invalid adapter");
12714 ret = -EINVAL;
12715 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012716 }
12717
Dustin Browne7e71d32018-05-11 16:00:08 -070012718 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053012719 if (ret) {
12720 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012721 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012722 }
12723
Dustin Brown20024e32018-01-03 12:34:58 -080012724 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070012725 struct hdd_adapter *adapter =
12726 hdd_get_adapter(hdd_ctx, adapter_mode);
12727
12728 if (!adapter) {
12729 hdd_err("Failed to get adapter:%d", adapter_mode);
12730 goto reset_flags;
12731 }
12732
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012733 if (hdd_start_adapter(adapter)) {
12734 hdd_err("Failed to start %s adapter", kmessage);
12735 ret = -EINVAL;
12736 goto reset_flags;
12737 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012738
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012739 hdd_info("Acquire wakelock for monitor mode!");
12740 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12741 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12742 }
12743
Dustin Brown20024e32018-01-03 12:34:58 -080012744 /* con_mode is a global module parameter */
12745 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012746 hdd_info("Mode successfully changed to %s", kmessage);
12747 ret = 0;
12748
12749reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012750 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012751 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012752 return ret;
12753}
12754
12755
Srinivas Girigowda841da292018-02-21 16:33:00 -080012756static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012757{
12758 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012759 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012760
12761 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12762 ret = wlan_hdd_validate_context(hdd_ctx);
12763 if (ret)
12764 return ret;
12765
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053012766 if (!cds_wait_for_external_threads_completion(__func__)) {
12767 hdd_warn("External threads are still active, can not change mode");
12768 return -EAGAIN;
12769 }
12770
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012771 cds_ssr_protect(__func__);
12772 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12773 cds_ssr_unprotect(__func__);
12774
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012775 return ret;
12776}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012777
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012778static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012779 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012780{
12781 int ret;
12782
12783 ret = param_set_int(kmessage, kp);
12784
12785 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12786 pr_err("Only FTM mode supported!");
12787 return -ENOTSUPP;
12788 }
12789
12790 hdd_set_conparam(con_mode_ftm);
12791 con_mode = con_mode_ftm;
12792
12793 return ret;
12794}
12795
Nirav Shah73713f72018-05-17 14:50:41 +053012796#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070012797static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012798 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012799{
12800 int ret;
12801
12802 ret = param_set_int(kmessage, kp);
12803
12804 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12805 pr_err("Only Monitor mode supported!");
12806 return -ENOTSUPP;
12807 }
12808
12809 hdd_set_conparam(con_mode_monitor);
12810 con_mode = con_mode_monitor;
12811
12812 return ret;
12813}
Nirav Shah73713f72018-05-17 14:50:41 +053012814#endif
Ravi Joshia307f632017-07-17 23:41:41 -070012815
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012816/**
12817 * hdd_get_conparam() - driver exit point
12818 *
12819 * This is the driver exit point (invoked when module is unloaded using rmmod)
12820 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012821 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012822 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012823enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012824{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012825 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012826}
12827
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012828void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012829{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012830 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012831}
12832
Komal Seelamc11bb222016-01-27 18:57:10 +053012833/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012834 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12835 * @hdd_ctx: HDD context
12836 *
12837 * Cleans up the pre cac interface, if it exists
12838 *
12839 * Return: None
12840 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012841void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012842{
12843 uint8_t session_id;
12844 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012845 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012846
12847 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12848 if (QDF_IS_STATUS_ERROR(status)) {
12849 hdd_err("failed to get pre cac vdev id");
12850 return;
12851 }
12852
12853 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12854 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070012855 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012856 return;
12857 }
12858
12859 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12860 wlan_hdd_sap_pre_cac_failure,
12861 (void *)precac_adapter);
12862 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12863
12864}
12865
12866/**
Komal Seelamec702b02016-02-24 18:42:16 +053012867 * hdd_update_ol_config - API to update ol configuration parameters
12868 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012869 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012870 * Return: void
12871 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012872static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012873{
Komal Seelamec702b02016-02-24 18:42:16 +053012874 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012875 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012876
Komal Seelamec702b02016-02-24 18:42:16 +053012877 if (!ol_ctx)
12878 return;
12879
12880 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12881 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12882 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12883 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012884 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012885
12886 ol_init_ini_config(ol_ctx, &cfg);
12887}
12888
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012889#ifdef FEATURE_RUNTIME_PM
12890/**
12891 * hdd_populate_runtime_cfg() - populate runtime configuration
12892 * @hdd_ctx: hdd context
12893 * @cfg: pointer to the configuration memory being populated
12894 *
12895 * Return: void
12896 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012897static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012898 struct hif_config_info *cfg)
12899{
12900 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12901 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12902}
12903#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012904static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012905 struct hif_config_info *cfg)
12906{
12907}
12908#endif
12909
Komal Seelamec702b02016-02-24 18:42:16 +053012910/**
12911 * hdd_update_hif_config - API to update HIF configuration parameters
12912 * @hdd_ctx: HDD Context
12913 *
12914 * Return: void
12915 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012916static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012917{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012918 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012919 struct hif_config_info cfg;
12920
12921 if (!scn)
12922 return;
12923
12924 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012925 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012926 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012927
12928 if (hdd_ctx->config->prevent_link_down)
12929 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012930}
12931
12932/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012933 * hdd_update_dp_config() - Propagate config parameters to Lithium
12934 * datapath
12935 * @hdd_ctx: HDD Context
12936 *
12937 * Return: 0 for success/errno for failure
12938 */
12939static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12940{
12941 struct cdp_config_params params;
12942 QDF_STATUS status;
12943
12944 params.tso_enable = hdd_ctx->config->tso_enable;
12945 params.lro_enable = hdd_ctx->config->lro_enable;
12946#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12947 params.tx_flow_stop_queue_threshold =
12948 hdd_ctx->config->TxFlowStopQueueThreshold;
12949 params.tx_flow_start_queue_offset =
12950 hdd_ctx->config->TxFlowStartQueueOffset;
12951#endif
12952 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12953 params.napi_enable = hdd_ctx->napi_enable;
12954 params.tcp_udp_checksumoffload =
12955 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12956
12957 status = cdp_update_config_parameters(
12958 cds_get_context(QDF_MODULE_ID_SOC),
12959 &params);
12960 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012961 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012962 return status;
12963 }
12964
12965 return 0;
12966}
12967
12968/**
Komal Seelamec702b02016-02-24 18:42:16 +053012969 * hdd_update_config() - Initialize driver per module ini parameters
12970 * @hdd_ctx: HDD Context
12971 *
12972 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012973 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012974 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012975int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012976{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012977 int ret;
12978
Komal Seelamec702b02016-02-24 18:42:16 +053012979 hdd_update_ol_config(hdd_ctx);
12980 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012981 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12982 ret = hdd_update_cds_config_ftm(hdd_ctx);
12983 else
12984 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012985 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012986
12987 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012988}
12989
Mukul Sharma9d797a02017-01-05 20:26:03 +053012990#ifdef FEATURE_WLAN_RA_FILTERING
12991/**
12992 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12993 * @psoc_cfg: pmo psoc Configuration
12994 * @hdd_ctx: Pointer to hdd context
12995 *
12996 * Return: none
12997 */
12998static inline void hdd_ra_populate_pmo_config(
12999 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013000 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013001{
13002 psoc_cfg->ra_ratelimit_interval =
13003 hdd_ctx->config->RArateLimitInterval;
13004 psoc_cfg->ra_ratelimit_enable =
13005 hdd_ctx->config->IsRArateLimitEnabled;
13006}
13007#else
13008static inline void hdd_ra_populate_pmo_config(
13009 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013010 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013011{
13012}
13013#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080013014
Mukul Sharma9d797a02017-01-05 20:26:03 +053013015/**
13016 * hdd_update_pmo_config - API to update pmo configuration parameters
13017 * @hdd_ctx: HDD context
13018 *
13019 * Return: void
13020 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013021static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013022{
Mukul Sharma9d797a02017-01-05 20:26:03 +053013023 struct pmo_psoc_cfg psoc_cfg;
13024 QDF_STATUS status;
13025
13026 /*
13027 * Value of hdd_ctx->wowEnable can be,
13028 * 0 - Disable both magic pattern match and pattern byte match.
13029 * 1 - Enable magic pattern match on all interfaces.
13030 * 2 - Enable pattern byte match on all interfaces.
13031 * 3 - Enable both magic patter and pattern byte match on
13032 * all interfaces.
13033 */
13034 psoc_cfg.magic_ptrn_enable =
13035 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
13036 psoc_cfg.ptrn_match_enable_all_vdev =
13037 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080013038 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013039 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070013040 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080013041 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013042 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080013043 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013044 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
13045 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080013046 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013047 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013048 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013049 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
13050 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
13051 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080013052 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053013053 psoc_cfg.auto_power_save_fail_mode =
13054 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013055
13056 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013057 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
13058 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013059
Dustin Brownb9987af2018-03-01 17:15:11 -080013060 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
13061 if (QDF_IS_STATUS_ERROR(status))
13062 hdd_err("failed pmo psoc configuration; status:%d", status);
13063
13064 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013065}
13066
Abhishek Singhb20db962017-03-03 21:28:46 +053013067#ifdef FEATURE_WLAN_SCAN_PNO
13068static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13069 struct hdd_config *cfg)
13070{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013071 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13072
Abhishek Singhb20db962017-03-03 21:28:46 +053013073 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13074 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13075 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13076 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13077 pno_cfg->channel_prediction_full_scan =
13078 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013079 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13080 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13081 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13082 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013083}
13084#else
13085static inline void
13086hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013087 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013088{
Abhishek Singhb20db962017-03-03 21:28:46 +053013089}
13090#endif
13091
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013092void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
13093 struct hdd_config *cfg)
13094{
13095 uint8_t i = 0;
13096
13097 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
13098 if (!ie_whitelist->white_list)
13099 return;
13100
13101 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
13102 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
13103 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
13104 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
13105 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
13106 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
13107 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
13108 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
13109
13110 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
13111 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
13112 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
13113}
13114
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013115uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
13116{
13117 uint8_t i, score;
13118
13119 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
13120 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
13121 if (score > MAX_INDEX_SCORE)
13122 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
13123 MAX_INDEX_SCORE, i);
13124 }
13125
13126 return per_index_score;
13127}
13128
13129/**
13130 * hdd_update_score_config - API to update candidate scoring related params
13131 * configuration parameters
13132 * @score_config: score config to update
13133 * @cfg: config params
13134 *
13135 * Return: 0 if success else err
13136 */
13137static void hdd_update_score_config(
13138 struct scoring_config *score_config, struct hdd_config *cfg)
13139{
13140 int total_weight;
13141
13142 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
13143 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
13144 score_config->weight_cfg.vht_caps_weightage =
13145 cfg->vht_caps_weightage;
13146 score_config->weight_cfg.he_caps_weightage =
13147 cfg->he_caps_weightage;
13148 score_config->weight_cfg.chan_width_weightage =
13149 cfg->chan_width_weightage;
13150 score_config->weight_cfg.chan_band_weightage =
13151 cfg->chan_band_weightage;
13152 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
13153 score_config->weight_cfg.beamforming_cap_weightage =
13154 cfg->beamforming_cap_weightage;
13155 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
13156 score_config->weight_cfg.channel_congestion_weightage =
13157 cfg->channel_congestion_weightage;
13158 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
13159
13160 total_weight = score_config->weight_cfg.rssi_weightage +
13161 score_config->weight_cfg.ht_caps_weightage +
13162 score_config->weight_cfg.vht_caps_weightage +
13163 score_config->weight_cfg.he_caps_weightage +
13164 score_config->weight_cfg.chan_width_weightage +
13165 score_config->weight_cfg.chan_band_weightage +
13166 score_config->weight_cfg.nss_weightage +
13167 score_config->weight_cfg.beamforming_cap_weightage +
13168 score_config->weight_cfg.pcl_weightage +
13169 score_config->weight_cfg.channel_congestion_weightage +
13170 score_config->weight_cfg.oce_wan_weightage;
13171
13172 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
13173 hdd_err("total weight is greater than %d fallback to default values",
13174 BEST_CANDIDATE_MAX_WEIGHT);
13175
13176 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
13177 score_config->weight_cfg.ht_caps_weightage =
13178 HT_CAPABILITY_WEIGHTAGE;
13179 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
13180 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
13181 score_config->weight_cfg.chan_width_weightage =
13182 CHAN_WIDTH_WEIGHTAGE;
13183 score_config->weight_cfg.chan_band_weightage =
13184 CHAN_BAND_WEIGHTAGE;
13185 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
13186 score_config->weight_cfg.beamforming_cap_weightage =
13187 BEAMFORMING_CAP_WEIGHTAGE;
13188 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
13189 score_config->weight_cfg.channel_congestion_weightage =
13190 CHANNEL_CONGESTION_WEIGHTAGE;
13191 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
13192 }
13193
13194 score_config->bandwidth_weight_per_index =
13195 hdd_limit_max_per_index_score(
13196 cfg->bandwidth_weight_per_index);
13197 score_config->nss_weight_per_index =
13198 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13199 score_config->band_weight_per_index =
13200 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13201
13202 score_config->rssi_score.best_rssi_threshold =
13203 cfg->best_rssi_threshold;
13204 score_config->rssi_score.good_rssi_threshold =
13205 cfg->good_rssi_threshold;
13206 score_config->rssi_score.bad_rssi_threshold =
13207 cfg->bad_rssi_threshold;
13208 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13209 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13210 score_config->rssi_score.good_rssi_bucket_size =
13211 cfg->good_rssi_bucket_size;
13212 score_config->rssi_score.bad_rssi_bucket_size =
13213 cfg->bad_rssi_bucket_size;
13214 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13215 cfg->rssi_pref_5g_rssi_thresh;
13216
13217 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13218 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13219 hdd_limit_max_per_index_score(
13220 cfg->esp_qbss_score_slots3_to_0);
13221 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13222 hdd_limit_max_per_index_score(
13223 cfg->esp_qbss_score_slots7_to_4);
13224 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13225 hdd_limit_max_per_index_score(
13226 cfg->esp_qbss_score_slots11_to_8);
13227 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13228 hdd_limit_max_per_index_score(
13229 cfg->esp_qbss_score_slots15_to_12);
13230
13231 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13232 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13233 hdd_limit_max_per_index_score(
13234 cfg->oce_wan_score_slots3_to_0);
13235 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13236 hdd_limit_max_per_index_score(
13237 cfg->oce_wan_score_slots7_to_4);
13238 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13239 hdd_limit_max_per_index_score(
13240 cfg->oce_wan_score_slots11_to_8);
13241 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13242 hdd_limit_max_per_index_score(
13243 cfg->oce_wan_score_slots15_to_12);
13244
13245
13246 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13247 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13248 score_config->nss = cfg->enable2x2 ? 2 : 1;
13249
13250 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13251 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13252 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13253 score_config->he_cap = 1;
13254
13255 if (score_config->he_cap ||
13256 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13257 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13258 score_config->vht_cap = 1;
13259
13260 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13261 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13262 score_config->ht_cap = 1;
13263
13264 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13265 score_config->vht_24G_cap = 1;
13266
13267 if (cfg->enableTxBF)
13268 score_config->beamformee_cap = 1;
13269
13270}
13271
Abhishek Singh257a9482017-03-06 16:52:39 +053013272/**
bings81fe50a2017-11-27 14:33:26 +080013273 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13274 * @hdd_ctx: HDD context
13275 *
13276 * Return: 0 if success else err
13277 */
13278static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13279{
13280 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13281 struct hdd_config *cfg = hdd_ctx->config;
13282 struct dfs_user_config dfs_cfg;
13283 QDF_STATUS status;
13284
13285 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13286 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13287 if (QDF_IS_STATUS_ERROR(status)) {
13288 hdd_err("failed dfs psoc configuration");
13289 return -EINVAL;
13290 }
13291
13292 return 0;
13293}
13294
13295/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013296 * hdd_update_scan_config - API to update scan configuration parameters
13297 * @hdd_ctx: HDD context
13298 *
13299 * Return: 0 if success else err
13300 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013301static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013302{
13303 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13304 struct scan_user_cfg scan_cfg;
13305 struct hdd_config *cfg = hdd_ctx->config;
13306 QDF_STATUS status;
13307
13308 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13309 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13310 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13311 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13312 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13313 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13314 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013315 /* convert to ms */
13316 scan_cfg.scan_cache_aging_time =
13317 cfg->scanAgingTimeout * 1000;
13318 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13319 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13320 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13321 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013322 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013323 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013324 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13325 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013326 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013327 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013328 scan_cfg.sta_miracast_mcc_rest_time =
13329 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013330
Abhishek Singhb20db962017-03-03 21:28:46 +053013331 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013332 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013333 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013334
Abhishek Singh257a9482017-03-06 16:52:39 +053013335 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13336 if (status != QDF_STATUS_SUCCESS) {
13337 hdd_err("failed pmo psoc configuration");
13338 return -EINVAL;
13339 }
13340
13341 return 0;
13342}
Abhishek Singh257a9482017-03-06 16:52:39 +053013343
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013344int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013345{
13346 int ret;
13347
13348 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013349 if (ret)
13350 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013351
Abhishek Singh257a9482017-03-06 16:52:39 +053013352 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013353 if (ret)
13354 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013355
Frank Liud4b2fa02017-03-29 11:46:48 +080013356 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013357 if (ret)
13358 return ret;
13359
13360 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013361 if (ret)
13362 return ret;
13363
13364 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013365
13366 return ret;
13367}
13368
Agrawal Ashish65634612016-08-18 13:24:32 +053013369/**
13370 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13371 * @mode : cfg80211 DFS mode
13372 *
13373 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13374 */
13375enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13376{
13377 switch (mode) {
13378 case DFS_MODE_ENABLE:
13379 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013380 case DFS_MODE_DISABLE:
13381 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013382 case DFS_MODE_DEPRIORITIZE:
13383 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013384 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013385 hdd_debug("ACS dfs mode is NONE");
13386 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013387 }
13388}
13389
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013390/**
13391 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13392 * @hddctx: pointer to hdd context
13393 * @set_value: enable/disable
13394 *
13395 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13396 * Host(even though it is duplicate). When Host send vendor command
13397 * disable,FW doesn't perform any action. Whenever any change in
13398 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13399 *
13400 * return - 0 on success, appropriate error values on failure.
13401 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013402int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013403{
13404 QDF_STATUS status;
13405
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013406 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013407 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013408
13409 if (!hddctx->config->goptimize_chan_avoid_event) {
13410 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13411 return -EINVAL;
13412 }
13413
13414 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13415 if (!QDF_IS_STATUS_SUCCESS(status)) {
13416 hdd_err("Failed to send chan avoid command to SME");
13417 return -EINVAL;
13418 }
13419 return 0;
13420}
Agrawal Ashish65634612016-08-18 13:24:32 +053013421
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013422/**
13423 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13424 * @value: value to set
13425 *
13426 * This function will set the passed value to roaming in progress flag.
13427 *
13428 * Return: None
13429 */
13430void hdd_set_roaming_in_progress(bool value)
13431{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013432 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013433
13434 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13435 if (!hdd_ctx) {
13436 hdd_err("HDD context is NULL");
13437 return;
13438 }
13439
13440 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013441 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013442}
13443
13444/**
13445 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013446 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013447 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013448 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013449 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013450bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013451{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013452 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013453 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013454
13455 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13456 if (!hdd_ctx) {
13457 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013458 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013459 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013460 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13461 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013462 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13463 hdd_ctx->roaming_in_progress);
13464
13465 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013466}
13467
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013468/**
13469 * hdd_is_connection_in_progress() - check if connection is in
13470 * progress
13471 * @session_id: session id
13472 * @reason: scan reject reason
13473 *
13474 * Go through each adapter and check if Connection is in progress
13475 *
13476 * Return: true if connection is in progress else false
13477 */
13478bool hdd_is_connection_in_progress(uint8_t *session_id,
13479 enum scan_reject_states *reason)
13480{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013481 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013482 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013483 uint8_t sta_id = 0;
13484 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013485 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013486
13487 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13488 if (!hdd_ctx) {
13489 hdd_err("HDD context is NULL");
13490 return false;
13491 }
13492
Dustin Brown920397d2017-12-13 16:27:50 -080013493 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070013494 hdd_debug("Adapter with device mode %s(%d) exists",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013495 hdd_device_mode_to_string(adapter->device_mode),
13496 adapter->device_mode);
13497 if (((QDF_STA_MODE == adapter->device_mode)
13498 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13499 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13500 && (eConnectionState_Connecting ==
13501 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13502 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013503 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013504 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013505 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013506 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013507 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013508 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013509 }
13510 return true;
13511 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013512 /*
13513 * sme_neighbor_middle_of_roaming is for LFR2
13514 * hdd_is_roaming_in_progress is for LFR3
13515 */
13516 if (((QDF_STA_MODE == adapter->device_mode) &&
13517 sme_neighbor_middle_of_roaming(
13518 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013519 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013520 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013521 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013522 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013523 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013524 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013525 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013526 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013527 }
13528 return true;
13529 }
13530 if ((QDF_STA_MODE == adapter->device_mode) ||
13531 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13532 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13533 hdd_sta_ctx =
13534 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13535 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013536 hdd_sta_ctx->conn_info.connState)
13537 && sme_is_sta_key_exchange_in_progress(
13538 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013539 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013540 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013541 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013542 " is in middle of WPS/EAPOL exchange.",
13543 MAC_ADDR_ARRAY(sta_mac));
13544 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013545 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013546 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013547 }
13548 return true;
13549 }
13550 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13551 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13552 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13553 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013554 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013555 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013556 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013557 continue;
13558
13559 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013560 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013561 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013562 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013563 " of SAP/GO is in middle of WPS/EAPOL exchange",
13564 MAC_ADDR_ARRAY(sta_mac));
13565 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013566 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013567 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013568 }
13569 return true;
13570 }
13571 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013572 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013573 return true;
13574 }
13575 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013576 }
Dustin Brown920397d2017-12-13 16:27:50 -080013577
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013578 return false;
13579}
13580
13581/**
13582 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013583 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013584 *
13585 * Return: None
13586 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013587void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013588{
Jeff Johnson87251032017-08-29 13:31:11 -070013589 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013590 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013591 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013592 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070013593 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013594 void *sap_ctx;
13595
13596 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013597 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013598 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013599
13600 mutex_lock(&hdd_ctx->sap_lock);
13601 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13602 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013603 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13604 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13605 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13606 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013607 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013608 qdf_stop_bss_event,
13609 SME_CMD_TIMEOUT_VALUE);
13610
13611 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013612 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013613 goto end;
13614 }
13615 }
13616 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013617 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013618 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013619 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013620 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013621 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013622
13623 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013624 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013625 wlansap_reset_sap_config_add_ie(sap_config,
13626 eUPDATE_IE_ALL);
13627 goto end;
13628 }
13629
13630 qdf_event_reset(&hostapd_state->qdf_event);
13631 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13632 sap_config,
13633 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013634 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013635 wlansap_reset_sap_config_add_ie(sap_config,
13636 eUPDATE_IE_ALL);
13637 goto end;
13638 }
13639
Jeff Johnson6867ec32017-09-29 20:30:20 -070013640 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013641 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013642 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013643 SME_CMD_TIMEOUT_VALUE);
13644 wlansap_reset_sap_config_add_ie(sap_config,
13645 eUPDATE_IE_ALL);
13646 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013647 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013648 goto end;
13649 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013650 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013651 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013652 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013653 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13654 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013655 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013656 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013657 ap_adapter->device_mode,
13658 true);
13659 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013660 }
13661end:
13662 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013663}
13664
13665/**
13666 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13667 * with non dfs acs
13668 *
13669 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13670 *
13671 * Return: None
13672 */
13673void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13674{
Jeff Johnson9d295242017-08-29 14:39:48 -070013675 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013676 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070013677 struct cds_context *cds_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013678
13679 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13680 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013681 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013682 return;
13683 }
13684
13685 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13686 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013687 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013688 return;
13689 }
13690
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013691 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13692 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013693 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013694 return;
13695 }
13696
13697 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013698 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13699 &ap_adapter->event_flags) &&
13700 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013701 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013702
Jeff Johnson6867ec32017-09-29 20:30:20 -070013703 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013704 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013705 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013706 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013707 acs_cfg.acs_mode = true;
13708
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013709 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013710 }
13711}
13712
13713/**
13714 * hdd_set_connection_in_progress() - to set the connection in
13715 * progress flag
13716 * @value: value to set
13717 *
13718 * This function will set the passed value to connection in progress flag.
13719 * If value is previously being set to true then no need to set it again.
13720 *
13721 * Return: true if value is being set correctly and false otherwise.
13722 */
13723bool hdd_set_connection_in_progress(bool value)
13724{
13725 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013726 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013727
13728 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13729 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013730 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013731 return false;
13732 }
13733
13734 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13735 /*
13736 * if the value is set to true previously and if someone is
13737 * trying to make it true again then it could be some race
13738 * condition being triggered. Avoid this situation by returning
13739 * false
13740 */
13741 if (hdd_ctx->connection_in_progress && value)
13742 status = false;
13743 else
13744 hdd_ctx->connection_in_progress = value;
13745 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13746 return status;
13747}
13748
Jeff Johnson9d295242017-08-29 14:39:48 -070013749int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013750{
13751 if (!adapter) {
13752 hdd_err("Invalid adapter");
13753 return -EINVAL;
13754 }
13755 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013756 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013757 WMA_VDEV_MCC_SET_TIME_QUOTA,
13758 set_value, VDEV_CMD);
13759 return 0;
13760
13761}
13762
Jeff Johnson9d295242017-08-29 14:39:48 -070013763int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013764{
13765 if (!adapter) {
13766 hdd_err("Invalid adapter");
13767 return -EINVAL;
13768 }
13769
13770 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013771 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013772 WMA_VDEV_MCC_SET_TIME_LATENCY,
13773 set_value, VDEV_CMD);
13774 return 0;
13775}
13776
Jeff Johnson9d295242017-08-29 14:39:48 -070013777struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013778 *psoc, uint8_t vdev_id)
13779{
Jeff Johnson9d295242017-08-29 14:39:48 -070013780 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013781 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013782
13783 /*
13784 * Currently PSOC is not being used. But this logic will
13785 * change once we have the converged implementation of
13786 * HDD context per PSOC in place. This would break if
13787 * multiple vdev objects reuse the vdev id.
13788 */
13789 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13790 if (!adapter)
13791 hdd_err("Get adapter by vdev id failed");
13792
13793 return adapter;
13794}
13795
Jeff Johnson9d295242017-08-29 14:39:48 -070013796int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013797 int8_t *rssi, int8_t *snr)
13798{
13799 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013800 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013801
Jeff Johnson025618c2018-03-18 14:41:00 -070013802 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013803 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013804 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013805 if (QDF_STATUS_SUCCESS != status) {
13806 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13807 return -EINVAL;
13808 }
13809
13810 return 0;
13811}
13812
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013813/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013814 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13815 * @adapter - HDD adapter
13816 * @tos - type of service
13817 * @status - status of the traffic
13818 *
13819 * Return: 0 on success and non zero value on failure
13820 */
13821
13822int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13823 bool is_tos_active)
13824{
13825 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013826 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013827 uint32_t max_off_chan_time = 0;
13828 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013829 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013830 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013831
13832 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13833 ret = wlan_hdd_validate_context(hdd_ctx);
13834
13835 if (ret < 0) {
13836 hdd_err("failed to set limit off chan params");
13837 return ret;
13838 }
13839
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013840 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13841
13842 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013843 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013844 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013845 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013846
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013847 if (adapter->active_ac) {
13848 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013849 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013850 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13851 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13852 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013853 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013854 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013855 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13856 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13857 PM_LATENCY);
13858 } else {
13859 /*ignore this command if only BE/BK is active */
13860 is_tos_active = false;
13861 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13862 hdd_ctx->config->conc_system_pref);
13863 }
13864 } else {
13865 /* No active tos */
13866 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13867 hdd_ctx->config->conc_system_pref);
13868 }
13869
Jeff Johnson1b780e42017-10-31 14:11:45 -070013870 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013871 is_tos_active, max_off_chan_time,
13872 hdd_ctx->config->nRestTimeConc, true);
13873 if (!QDF_IS_STATUS_SUCCESS(status)) {
13874 hdd_err("failed to set limit off chan params");
13875 ret = -EINVAL;
13876 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013877
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013878 return ret;
13879}
13880
13881/**
13882 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13883 * @adapter - HDD adapter
13884 *
13885 * Return: 0 on success and non zero value on failure
13886 */
13887int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13888{
13889 struct hdd_context *hdd_ctx;
13890 int ret;
13891 QDF_STATUS status;
13892 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13893
13894 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13895 ret = wlan_hdd_validate_context(hdd_ctx);
13896 if (ret < 0)
13897 return ret;
13898
13899 /* set the system preferece to default */
13900 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13901 hdd_ctx->config->conc_system_pref);
13902
13903 /* clear the bitmap */
13904 adapter->active_ac = 0;
13905
13906 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013907 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013908
Jeff Johnson1b780e42017-10-31 14:11:45 -070013909 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013910 false, 0, 0, false);
13911 if (!QDF_IS_STATUS_SUCCESS(status)) {
13912 hdd_err("failed to reset limit off chan params");
13913 ret = -EINVAL;
13914 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013915
13916 return ret;
13917}
13918
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013919/**
13920 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13921 * @drv_op: Enum indicating driver op
13922 *
13923 * Return: none
13924 */
13925void hdd_start_driver_ops_timer(int drv_op)
13926{
13927 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13928 switch (drv_op) {
13929 case eHDD_DRV_OP_PROBE:
13930 memcpy(drv_ops_string, "probe", sizeof("probe"));
13931 break;
13932 case eHDD_DRV_OP_REMOVE:
13933 memcpy(drv_ops_string, "remove", sizeof("remove"));
13934 break;
13935 case eHDD_DRV_OP_SHUTDOWN:
13936 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13937 break;
13938 case eHDD_DRV_OP_REINIT:
13939 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13940 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013941 case eHDD_DRV_OP_IFF_UP:
13942 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13943 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013944 }
13945
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013946 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013947 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13948 HDD_OPS_INACTIVITY_TIMEOUT);
13949}
13950
13951/**
13952 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13953 *
13954 * Return: none
13955 */
13956void hdd_stop_driver_ops_timer(void)
13957{
13958 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13959}
13960
13961/**
13962 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13963 * inactivity timer
13964 *
13965 * Return: None
13966 */
13967void hdd_drv_ops_inactivity_handler(void)
13968{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070013969 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013970 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13971
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013972 if (hdd_drv_ops_task) {
13973 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13974 qdf_print_thread_trace(hdd_drv_ops_task);
13975 } else {
13976 hdd_err("hdd_drv_ops_task is null");
13977 }
13978
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013979 /* Driver shutdown is stuck, no recovery possible at this point */
13980 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13981 sizeof("shutdown")))
13982 QDF_BUG(0);
13983
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013984 if (cds_is_fw_down()) {
13985 hdd_err("FW is down");
13986 return;
13987 }
13988
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013989 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013990 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013991 else
13992 QDF_BUG(0);
13993}
13994
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013995void hdd_pld_ipa_uc_shutdown_pipes(void)
13996{
13997 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13998
13999 if (!hdd_ctx)
14000 return;
14001
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053014002 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014003}
14004
Yun Parkff6a16a2017-09-26 16:38:18 -070014005/**
14006 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14007 * @struct hdd_context *hdd_ctx
14008 * @struct hdd_adapter *padapter
14009 * @bool enble
14010 *
14011 * Return: none
14012 */
14013void hdd_set_rx_mode_rps(bool enable)
14014{
14015 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014016 struct hdd_context *hdd_ctx;
14017 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014018
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014019 if (!cds_cfg)
14020 return;
14021
14022 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14023 if (!hdd_ctx)
14024 return;
14025
14026 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14027 if (!adapter)
14028 return;
14029
14030 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014031 if (enable && !cds_cfg->rps_enabled)
14032 hdd_send_rps_ind(adapter);
14033 else if (!enable && cds_cfg->rps_enabled)
14034 hdd_send_rps_disable_ind(adapter);
14035 }
14036}
14037
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014038bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14039{
14040 struct hdd_adapter *adapter = NULL;
14041
14042 hdd_for_each_adapter(hdd_ctx, adapter) {
14043 if ((adapter->device_mode == QDF_STA_MODE ||
14044 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14045 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14046 &adapter->event_flags)){
14047 return true;
14048 }
14049 }
14050
14051 return false;
14052}
14053
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014054/* Register the module init/exit functions */
14055module_init(hdd_module_init);
14056module_exit(hdd_module_exit);
14057
14058MODULE_LICENSE("Dual BSD/GPL");
14059MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14060MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14061
Srinivas Girigowda841da292018-02-21 16:33:00 -080014062static const struct kernel_param_ops con_mode_ops = {
14063 .set = con_mode_handler,
14064 .get = param_get_int,
14065};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014066
Srinivas Girigowda841da292018-02-21 16:33:00 -080014067static const struct kernel_param_ops con_mode_ftm_ops = {
14068 .set = con_mode_handler_ftm,
14069 .get = param_get_int,
14070};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014071
Nirav Shah73713f72018-05-17 14:50:41 +053014072#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014073static const struct kernel_param_ops con_mode_monitor_ops = {
14074 .set = con_mode_handler_monitor,
14075 .get = param_get_int,
14076};
Nirav Shah73713f72018-05-17 14:50:41 +053014077#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014078
Srinivas Girigowda841da292018-02-21 16:33:00 -080014079static const struct kernel_param_ops fwpath_ops = {
14080 .set = fwpath_changed_handler,
14081 .get = param_get_string,
14082};
14083
14084module_param_cb(con_mode, &con_mode_ops, &con_mode,
14085 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14086
14087module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14088 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14089
Nirav Shah73713f72018-05-17 14:50:41 +053014090#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014091module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14092 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014093#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014094
14095module_param_cb(fwpath, &fwpath_ops, &fwpath,
14096 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014097
14098module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14099
14100module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14101
14102module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);