blob: d18b6d4e1b0ca2e8bcd0a173a636aaf69b14c8fa [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"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530129#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530130#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530131#include "wlan_hdd_nud_tracking.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530132
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530133#ifdef CNSS_GENL
134#include <net/cnss_nl.h>
135#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800136#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800137#include "wlan_ocb_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530138
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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800880 return 0;
881}
882
Jeff Johnson9d295242017-08-29 14:39:48 -0700883int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700884{
885 if (!adapter) {
886 hdd_err("adapter is null");
887 return -EINVAL;
888 }
889
890 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
891 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
892 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
893 return -EINVAL;
894 }
895
896 if (!adapter->dev) {
897 hdd_err("adapter net_device is null");
898 return -EINVAL;
899 }
900
901 if (!(adapter->dev->flags & IFF_UP)) {
902 hdd_info("adapter net_device is not up");
903 return -EAGAIN;
904 }
905
Jeff Johnson1b780e42017-10-31 14:11:45 -0700906 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700907 hdd_info("adapter session is not open");
908 return -EAGAIN;
909 }
910
Jeff Johnson1b780e42017-10-31 14:11:45 -0700911 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
912 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700913 return -EINVAL;
914 }
915
916 return 0;
917}
918
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800919/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530920 * wlan_hdd_validate_modules_state() - Check modules status
921 * @hdd_ctx: HDD context pointer
922 *
923 * Check's the driver module's state and returns true if the
924 * modules are enabled returns false if modules are closed.
925 *
926 * Return: True if modules are enabled or false.
927 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700928bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530929{
930 mutex_lock(&hdd_ctx->iface_change_lock);
931 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
932 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700933 hdd_info("Modules not enabled, Present status: %d",
934 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530935 return false;
936 }
937 mutex_unlock(&hdd_ctx->iface_change_lock);
938 return true;
939}
940
941/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800942 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700943 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800944 *
945 * This function sets the IBSS power save config parameters to WMA
946 * which will send it to firmware if FW supports IBSS power save
947 * before vdev start.
948 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530949 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 * on failure.
951 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700952QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800953{
954 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700955 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956
957 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700958 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530959 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960 }
961
Jeff Johnson1b780e42017-10-31 14:11:45 -0700962 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800963 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
964 hdd_ctx->config->ibssATIMWinSize,
965 VDEV_CMD);
966 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700967 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530968 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 }
970
Jeff Johnson1b780e42017-10-31 14:11:45 -0700971 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800972 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
973 hdd_ctx->config->isIbssPowerSaveAllowed,
974 VDEV_CMD);
975 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700976 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
977 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530978 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800979 }
980
Jeff Johnson1b780e42017-10-31 14:11:45 -0700981 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800982 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
983 hdd_ctx->config->
984 isIbssPowerCollapseAllowed, VDEV_CMD);
985 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700986 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
987 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530988 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 }
990
Jeff Johnson1b780e42017-10-31 14:11:45 -0700991 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
993 hdd_ctx->config->isIbssAwakeOnTxRx,
994 VDEV_CMD);
995 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700996 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530997 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998 }
999
Jeff Johnson1b780e42017-10-31 14:11:45 -07001000 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1002 hdd_ctx->config->ibssInactivityCount,
1003 VDEV_CMD);
1004 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001005 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301006 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001007 }
1008
Jeff Johnson1b780e42017-10-31 14:11:45 -07001009 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001010 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1011 hdd_ctx->config->ibssTxSpEndInactivityTime,
1012 VDEV_CMD);
1013 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001014 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
1015 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301016 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017 }
1018
Jeff Johnson1b780e42017-10-31 14:11:45 -07001019 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001020 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1021 hdd_ctx->config->ibssPsWarmupTime,
1022 VDEV_CMD);
1023 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001024 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
1025 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301026 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027 }
1028
Jeff Johnson1b780e42017-10-31 14:11:45 -07001029 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001030 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1031 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1032 VDEV_CMD);
1033 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001034 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1035 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301036 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 }
1038
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301039 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040}
1041
Yue Macd359b72017-10-03 15:21:00 -07001042#ifdef FEATURE_RUNTIME_PM
1043/**
1044 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1045 * @hdd_ctx: HDD context
1046 *
1047 * Return: None
1048 */
1049static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1050{
1051 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1052
Yue Macd359b72017-10-03 15:21:00 -07001053 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001054 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001055
1056 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1057}
1058
1059/**
1060 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1061 * @hdd_ctx: HDD Context
1062 *
1063 * Return: None
1064 */
1065static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1066{
1067 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1068
Yue Macd359b72017-10-03 15:21:00 -07001069 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001070 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001071
1072 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1073}
1074
Yue Macd359b72017-10-03 15:21:00 -07001075#else /* FEATURE_RUNTIME_PM */
1076static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1077static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001078#endif /* FEATURE_RUNTIME_PM */
1079
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080#define INTF_MACADDR_MASK 0x7
1081
1082/**
1083 * hdd_update_macaddr() - update mac address
1084 * @config: hdd configuration
1085 * @hw_macaddr: mac address
1086 *
1087 * Mac address for multiple virtual interface is found as following
1088 * i) The mac address of the first interface is just the actual hw mac address.
1089 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1090 * define the mac address for the remaining interfaces and locally
1091 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1092 * supported virtual interfaces, right now this is 0x07 (meaning 8
1093 * interface).
1094 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1095 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1096 *
1097 * Return: None
1098 */
1099void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301100 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001101{
1102 int8_t i;
1103 uint8_t macaddr_b3, tmp_br3;
1104
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301105 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301106 QDF_MAC_ADDR_SIZE);
1107 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301108 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301109 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001110 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1111 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1112 INTF_MACADDR_MASK;
1113 macaddr_b3 += tmp_br3;
1114
1115 /* XOR-ing bit-24 of the mac address. This will give enough
1116 * mac address range before collision
1117 */
1118 macaddr_b3 ^= (1 << 7);
1119
1120 /* Set locally administered bit */
1121 config->intfMacAddr[i].bytes[0] |= 0x02;
1122 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001123 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001124 MAC_ADDRESS_STR, i,
1125 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1126 }
1127}
1128
Kabilan Kannan44a58372017-12-06 18:16:11 -08001129static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1130{
1131 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1132 struct tdls_start_params tdls_cfg;
1133 struct tdls_user_config *config = &tdls_cfg.config;
1134 struct hdd_config *cfg = hdd_ctx->config;
1135 QDF_STATUS status;
1136
1137 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1138 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1139 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1140 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1141 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1142 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1143 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1144 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1145 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1146 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1147 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1148 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1149 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1150 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1151 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1152 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1153 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1154 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1155 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1156 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1157 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1158 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1159 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1160 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1161 (cfg->fEnableTDLSImplicitTrigger ?
1162 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1163 (cfg->fTDLSExternalControl ?
1164 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1165 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1166 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1167
1168 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1169 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1170 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1171 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1172 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1173 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1174 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1175 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001176 tdls_cfg.tdls_peer_context = hdd_ctx;
1177 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1178 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001179 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1180 tdls_cfg.tdls_wmm_cb_data = psoc;
1181 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1182 tdls_cfg.tdls_rx_cb_data = psoc;
1183 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1184
1185 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1186 if (status != QDF_STATUS_SUCCESS) {
1187 hdd_err("failed pmo psoc configuration");
1188 return -EINVAL;
1189 }
1190
1191 hdd_ctx->tdls_umac_comp_active = true;
1192 /* enable napier specific tdls data path */
1193 hdd_ctx->tdls_nap_active = true;
1194
1195 return 0;
1196}
1197
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001198static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 struct wma_tgt_services *cfg)
1200{
1201 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202
1203 /* Set up UAPSD */
1204 config->apUapsdEnabled &= cfg->uapsd;
1205
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001206 /* 11AX mode support */
1207 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1208 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1209 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1210
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001211 /* 11AC mode support */
1212 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1213 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1214 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001215
1216 /* ARP offload: override user setting if invalid */
1217 config->fhostArpOffload &= cfg->arp_offload;
1218
1219#ifdef FEATURE_WLAN_SCAN_PNO
1220 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001221 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001222 if (cfg->pno_offload)
1223 config->PnoOffload = true;
1224#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001225#ifdef FEATURE_WLAN_TDLS
1226 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301227 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1228 cfg->en_tdls_offchan;
1229 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1230 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001231 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001232 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001233 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001235#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1237 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1238#endif
Will Huang496b36c2017-07-11 16:38:50 +08001239 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001240 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001241 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001242 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243
1244}
1245
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001246/**
1247 * hdd_update_vdev_nss() - sets the vdev nss
1248 * @hdd_ctx: HDD context
1249 *
1250 * Sets the Nss per vdev type based on INI
1251 *
1252 * Return: None
1253 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001254static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001255{
1256 struct hdd_config *cfg_ini = hdd_ctx->config;
1257 uint8_t max_supp_nss = 1;
1258
Naveen Rawat10b1c152017-01-18 11:16:06 -08001259 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001260 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001261 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1262 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1263 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001264
1265 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001266 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001267
1268 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001269 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001270}
1271
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301272/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301273 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1274 * @hdd_ctx: HDD context
1275 *
1276 * Updates wiphy vhtcap fields
1277 *
1278 * Return: None
1279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001280static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301281{
1282 struct ieee80211_supported_band *band_5g =
1283 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1284 uint32_t val;
1285
1286 if (!band_5g) {
1287 hdd_debug("5GHz band disabled, skipping capability population");
1288 return;
1289 }
1290
1291 val = hdd_ctx->config->txBFCsnValue;
1292 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1293
1294 val = NUM_OF_SOUNDING_DIMENSIONS;
1295 band_5g->vht_cap.cap |=
1296 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1297
1298 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1299 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1300}
1301
1302/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301303 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1304 * @hdd_ctx: HDD context
1305 *
1306 * Sets the DBS capability as per INI and firmware capability
1307 *
1308 * Return: None
1309 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001310static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301311{
1312 struct hdd_config *cfg_ini = hdd_ctx->config;
1313 uint8_t hw_dbs_capable = 0;
1314
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001315 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1316 ((cfg_ini->dual_mac_feature_disable ==
1317 ENABLE_DBS_CXN_AND_SCAN) ||
1318 (cfg_ini->dual_mac_feature_disable ==
1319 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301320 hw_dbs_capable = 1;
1321
1322 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1323}
1324
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001325static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001326 struct wma_tgt_ht_cap *cfg)
1327{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301328 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329 uint32_t value, val32;
1330 uint16_t val16;
1331 struct hdd_config *pconfig = hdd_ctx->config;
1332 tSirMacHTCapabilityInfo *phtCapInfo;
1333 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1334 uint8_t enable_tx_stbc;
1335
1336 /* check and update RX STBC */
1337 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1338 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1339
1340 /* get the MPDU density */
1341 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1342
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301343 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001344 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001345 value = 0;
1346 }
1347
1348 /*
1349 * MPDU density:
1350 * override user's setting if value is larger
1351 * than the one supported by target
1352 */
1353 if (value > cfg->mpdu_density) {
1354 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1355 cfg->mpdu_density);
1356
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301357 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001358 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001359 }
1360
1361 /* get the HT capability info */
1362 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301363 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001364 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 return;
1366 }
1367 val16 = (uint16_t) val32;
1368 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1369
1370 /* Set the LDPC capability */
1371 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1372
1373 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1374 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1375
1376 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1377 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1378
1379 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1380 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1381
1382 enable_tx_stbc = pconfig->enableTxSTBC;
1383
1384 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1385 pconfig->enable2x2 = 1;
1386 } else {
1387 pconfig->enable2x2 = 0;
1388 enable_tx_stbc = 0;
1389
1390 /* 1x1 */
1391 /* Update Rx Highest Long GI data Rate */
1392 if (sme_cfg_set_int(hdd_ctx->hHal,
1393 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001394 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301395 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001396 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001397 }
1398
1399 /* Update Tx Highest Long GI data Rate */
1400 if (sme_cfg_set_int
1401 (hdd_ctx->hHal,
1402 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001403 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301404 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001405 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406 }
1407 }
1408 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1409 enable_tx_stbc = 0;
1410 phtCapInfo->txSTBC = enable_tx_stbc;
1411
1412 val32 = val16;
1413 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301414 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001415 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001416#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1417 value = SIZE_OF_SUPPORTED_MCS_SET;
1418 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301419 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001420 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301421 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1422 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001423 if (pconfig->enable2x2) {
1424 for (value = 0; value < cfg->num_rf_chains; value++)
1425 mcs_set[value] =
1426 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1427
1428 status =
1429 sme_cfg_set_str(hdd_ctx->hHal,
1430 WNI_CFG_SUPPORTED_MCS_SET,
1431 mcs_set,
1432 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301433 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001434 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001435 }
1436 }
1437#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1438}
1439
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001440static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 struct wma_tgt_vht_cap *cfg)
1442{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301443 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001444 uint32_t value = 0;
1445 struct hdd_config *pconfig = hdd_ctx->config;
1446 struct wiphy *wiphy = hdd_ctx->wiphy;
1447 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001448 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001449 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001450 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001451 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001452 struct wma_caps_per_phy caps_per_phy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001453
Dustin Brown5e06bd32016-10-04 12:49:10 -07001454 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001455 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001456 return;
1457 }
1458
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459 /* Get the current MPDU length */
1460 status =
1461 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1462 &value);
1463
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301464 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001465 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466 value = 0;
1467 }
1468
1469 /*
1470 * VHT max MPDU length:
1471 * override if user configured value is too high
1472 * that the target cannot support
1473 */
1474 if (value > cfg->vht_max_mpdu) {
1475 status = sme_cfg_set_int(hdd_ctx->hHal,
1476 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1477 cfg->vht_max_mpdu);
1478
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001479 if (status == QDF_STATUS_E_FAILURE)
1480 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481 }
1482
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001483 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1484 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1485
1486 if (pconfig->enable2x2)
1487 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1488
1489 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1490 QDF_STATUS_E_FAILURE) {
1491 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1492 }
1493
1494 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1495 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1496 if (pconfig->enable2x2)
1497 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1498
1499 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1500 QDF_STATUS_E_FAILURE) {
1501 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1502 }
1503
1504 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1505 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1506 if (pconfig->enable2x2)
1507 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1508
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001509 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001510 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1511
1512 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1513 QDF_STATUS_E_FAILURE) {
1514 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1515 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001517 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001518 &value);
1519
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301520 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001521 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001522 value = 0;
1523 }
1524
jiad4a7a33c2017-08-08 15:32:24 +08001525 /* Set HW RX LDPC capability */
1526 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1527 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001528 status = sme_cfg_set_int(hdd_ctx->hHal,
1529 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001530 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001531
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001532 if (status == QDF_STATUS_E_FAILURE)
1533 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001534 }
1535
1536 /* Get current GI 80 value */
1537 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1538 &value);
1539
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301540 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001541 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 value = 0;
1543 }
1544
1545 /* set the Guard interval 80MHz */
1546 if (value && !cfg->vht_short_gi_80) {
1547 status = sme_cfg_set_int(hdd_ctx->hHal,
1548 WNI_CFG_VHT_SHORT_GI_80MHZ,
1549 cfg->vht_short_gi_80);
1550
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001551 if (status == QDF_STATUS_E_FAILURE)
1552 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553 }
1554
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555 /* Get VHT TX STBC cap */
1556 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1557
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301558 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001559 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 value = 0;
1561 }
1562
1563 /* VHT TX STBC cap */
1564 if (value && !cfg->vht_tx_stbc) {
1565 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1566 cfg->vht_tx_stbc);
1567
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001568 if (status == QDF_STATUS_E_FAILURE)
1569 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001570 }
1571
1572 /* Get VHT RX STBC cap */
1573 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1574
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301575 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001576 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577 value = 0;
1578 }
1579
1580 /* VHT RX STBC cap */
1581 if (value && !cfg->vht_rx_stbc) {
1582 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1583 cfg->vht_rx_stbc);
1584
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001585 if (status == QDF_STATUS_E_FAILURE)
1586 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001587 }
1588
1589 /* Get VHT SU Beamformer cap */
1590 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1591 &value);
1592
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301593 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001594 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001595 value = 0;
1596 }
1597
1598 /* set VHT SU Beamformer cap */
1599 if (value && !cfg->vht_su_bformer) {
1600 status = sme_cfg_set_int(hdd_ctx->hHal,
1601 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1602 cfg->vht_su_bformer);
1603
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001604 if (status == QDF_STATUS_E_FAILURE)
1605 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606 }
1607
1608 /* check and update SU BEAMFORMEE capabality */
1609 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1610 pconfig->enableTxBF = cfg->vht_su_bformee;
1611
1612 status = sme_cfg_set_int(hdd_ctx->hHal,
1613 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1614 pconfig->enableTxBF);
1615
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001616 if (status == QDF_STATUS_E_FAILURE)
1617 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618
1619 /* Get VHT MU Beamformer cap */
1620 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1621 &value);
1622
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301623 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001624 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625 value = 0;
1626 }
1627
1628 /* set VHT MU Beamformer cap */
1629 if (value && !cfg->vht_mu_bformer) {
1630 status = sme_cfg_set_int(hdd_ctx->hHal,
1631 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1632 cfg->vht_mu_bformer);
1633
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001634 if (status == QDF_STATUS_E_FAILURE)
1635 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 }
1637
1638 /* Get VHT MU Beamformee cap */
1639 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1640 &value);
1641
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301642 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001643 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644 value = 0;
1645 }
1646
1647 /* set VHT MU Beamformee cap */
1648 if (value && !cfg->vht_mu_bformee) {
1649 status = sme_cfg_set_int(hdd_ctx->hHal,
1650 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1651 cfg->vht_mu_bformee);
1652
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001653 if (status == QDF_STATUS_E_FAILURE)
1654 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001655 }
1656
1657 /* Get VHT MAX AMPDU Len exp */
1658 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1659 &value);
1660
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301661 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001662 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 value = 0;
1664 }
1665
1666 /*
1667 * VHT max AMPDU len exp:
1668 * override if user configured value is too high
1669 * that the target cannot support.
1670 * Even though Rome publish ampdu_len=7, it can
1671 * only support 4 because of some h/w bug.
1672 */
1673
1674 if (value > cfg->vht_max_ampdu_len_exp) {
1675 status = sme_cfg_set_int(hdd_ctx->hHal,
1676 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1677 cfg->vht_max_ampdu_len_exp);
1678
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001679 if (status == QDF_STATUS_E_FAILURE)
1680 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001681 }
1682
1683 /* Get VHT TXOP PS CAP */
1684 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1685
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301686 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001687 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688 value = 0;
1689 }
1690
1691 /* set VHT TXOP PS cap */
1692 if (value && !cfg->vht_txop_ps) {
1693 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1694 cfg->vht_txop_ps);
1695
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001696 if (status == QDF_STATUS_E_FAILURE)
1697 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001698 }
1699
1700 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1701 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1702 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1703 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1704 else
1705 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1706
1707
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001708 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1709 status = sme_cfg_set_int(hdd_ctx->hHal,
1710 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1711 VHT_CAP_160_AND_80P80_SUPP);
1712 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001713 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714 band_5g->vht_cap.cap |=
1715 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001716 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1717 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1718 status = sme_cfg_set_int(hdd_ctx->hHal,
1719 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1720 VHT_CAP_160_SUPP);
1721 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001722 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001723 band_5g->vht_cap.cap |=
1724 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001725 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1726 }
1727 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1728 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301729 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001730 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301731 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001732 &value);
1733 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301734 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001735 value = 0;
1736 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301737 /* set the Guard interval 160MHz */
1738 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001739 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301740 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1741 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001742
1743 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301744 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001745 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001746
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001747 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001748 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001749 hdd_debug("VHT RxLDPC capability is set");
1750 } else {
1751 /*
1752 * Get the RX LDPC capability for the NON DBS
1753 * hardware mode for 5G band
1754 */
1755 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1756 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1757 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1758 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1759 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1760 hdd_debug("VHT RX LDPC capability is set");
1761 }
1762 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001763
1764 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1765 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1766 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1767 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1768
1769 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1770 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1771
1772 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1773 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1774 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1775 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1776 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1777 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1778
1779 band_5g->vht_cap.cap |=
1780 (cfg->vht_max_ampdu_len_exp <<
1781 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1782
1783 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1784 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1785 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1786 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1787 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1788 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1789 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1790 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1791
1792 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1793 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1794
1795}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001796
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001797/**
1798 * hdd_generate_macaddr_auto() - Auto-generate mac address
1799 * @hdd_ctx: Pointer to the HDD context
1800 *
1801 * Auto-generate mac address using device serial number.
1802 * Keep the first 3 bytes of OUI as before and replace
1803 * the last 3 bytes with the lower 3 bytes of serial number.
1804 *
1805 * Return: 0 for success
1806 * Non zero failure code for errors
1807 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001808static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001809{
1810 unsigned int serialno = 0;
1811 struct qdf_mac_addr mac_addr = {
1812 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1813 };
1814
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001815 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001816 if (serialno == 0)
1817 return -EINVAL;
1818
1819 serialno &= 0x00ffffff;
1820
1821 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1822 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1823 mac_addr.bytes[5] = serialno & 0xff;
1824
1825 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1826 return 0;
1827}
1828
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301829/**
1830 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1831 * configuration to cfg_ini in HDD
1832 * @hdd_ctx: Pointer to hdd_ctx
1833 * @cfg: target configuration
1834 *
1835 * Return: None
1836 */
1837#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001838static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301839 struct wma_tgt_cfg *cfg)
1840{
1841 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1842}
1843#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001844static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301845 struct wma_tgt_cfg *cfg)
1846{
1847}
1848#endif
1849
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001850void hdd_update_tgt_cfg(void *context, void *param)
1851{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001852 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001853 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001854 struct wma_tgt_cfg *cfg = param;
1855 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001856 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301857 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001858 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301859
Dustin Brownbd68fe12017-11-21 15:28:52 -08001860 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1861 if (ret) {
1862 hdd_err("Failed to create pdev; errno:%d", ret);
1863 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001864 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001865 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001866 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001867 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1868 hdd_err("dispatcher pdev open failed");
1869 QDF_BUG(0);
1870 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301871 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001872
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001873 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301874
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301875 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1876 cds_get_context(QDF_MODULE_ID_SOC));
1877 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1878 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301879 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1880 hdd_softap_hard_start_xmit);
1881 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1882 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301883
Naveen Rawat64e477e2016-05-20 10:34:56 -07001884 if (cds_cfg) {
1885 if (hdd_ctx->config->enable_sub_20_channel_width !=
1886 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1887 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1888 cds_cfg->sub_20_channel_width =
1889 WLAN_SUB_20_CH_WIDTH_NONE;
1890 } else {
1891 cds_cfg->sub_20_channel_width =
1892 hdd_ctx->config->enable_sub_20_channel_width;
1893 }
1894 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001895
1896 /* first store the INI band capability */
1897 temp_band_cap = hdd_ctx->config->nBandCapability;
1898
1899 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301900 hdd_ctx->is_fils_roaming_supported =
1901 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001902
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301903 hdd_ctx->config->is_11k_offload_supported =
1904 cfg->services.is_11k_offload_supported;
1905
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001906 /*
1907 * now overwrite the target band capability with INI
1908 * setting if INI setting is a subset
1909 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001911 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1912 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001914 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1915 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001916 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001917 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001918 }
1919
Amar Singhal58b45ef2017-08-01 13:43:54 -07001920 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1921
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301922 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001923 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1924 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1925 }
1926
1927 /* This can be extended to other configurations like ht, vht cap... */
1928
Anurag Chouhanc5548422016-02-24 18:33:27 +05301929 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001931 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001932 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001933 static struct qdf_mac_addr default_mac_addr = {
1934 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1935 };
1936 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1937 &default_mac_addr)) {
1938 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1939 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1940 MAC_ADDRESS_STR,
1941 MAC_ADDR_ARRAY(hdd_ctx->config->
1942 intfMacAddr[0].bytes));
1943 } else {
1944 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1945 MAC_ADDRESS_STR,
1946 MAC_ADDR_ARRAY(hdd_ctx->config->
1947 intfMacAddr[0].bytes));
1948 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001949 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950 }
1951
1952 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001953 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954
1955 hdd_ctx->max_intf_count = cfg->max_intf_count;
1956
Jeff Johnsonc875e242016-09-23 18:12:34 -07001957 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001958
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001959 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1960 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1961
1962 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1963
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001964 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001965 if (cfg->services.en_11ax) {
1966 hdd_info("11AX: 11ax is enabled - update HDD config");
1967 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1968 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001969
1970 hdd_update_vdev_nss(hdd_ctx);
1971
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301972 hdd_update_hw_dbs_capable(hdd_ctx);
1973
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001974 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001975 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001976 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001977 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001978
Nitesh Shahe50711f2017-04-26 16:30:45 +05301979 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1980 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1981 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001982 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001983 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001984
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001985 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1986 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301987 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301988 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301989
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301990 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001991 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1992 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301993 hdd_ctx->config->txBFCsnValue =
1994 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1995
Arif Hussainee10f902017-12-27 16:30:17 -08001996 status = sme_cfg_set_int(hdd_ctx->hHal,
1997 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1998 hdd_ctx->config->txBFCsnValue);
1999 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302000 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2001
2002
2003 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002004 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
2005 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302006
2007 /*
2008 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2009 */
2010 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302011
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302012 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2013
Yue Macd359b72017-10-03 15:21:00 -07002014 /*
2015 * This needs to be done after HDD pdev is created and stored since
2016 * it will access the HDD pdev object lock.
2017 */
2018 hdd_runtime_suspend_context_init(hdd_ctx);
2019
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002020 /* Configure NAN datapath features */
2021 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002022 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002023 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002024 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2025 cfg->obss_detection_offloaded);
2026 if (QDF_IS_STATUS_ERROR(status))
2027 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002028
2029 status = sme_cfg_set_int(hdd_ctx->hHal,
2030 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2031 cfg->obss_color_collision_offloaded);
2032 if (QDF_IS_STATUS_ERROR(status))
2033 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002034}
2035
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002036bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002037{
Jeff Johnson9d295242017-08-29 14:39:48 -07002038 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002039 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002040
Jiachao Wuf610d912018-01-23 17:47:32 +08002041 if (!hdd_ctx) {
2042 hdd_info("Couldn't get hdd_ctx");
2043 return true;
2044 }
2045
2046 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002047 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002048 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302049 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002050 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002051
Dustin Brown920397d2017-12-13 16:27:50 -08002052 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002053 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2054
2055 if ((QDF_SAP_MODE == adapter->device_mode ||
2056 QDF_P2P_GO_MODE == adapter->device_mode) &&
bings0e03a982018-05-09 08:40:59 +08002057 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002058 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002059 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2060 true;
2061 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002062 adapter->session_id);
bings0e03a982018-05-09 08:40:59 +08002063 cdp_fc_vdev_flush(cds_get_context(QDF_MODULE_ID_SOC),
2064 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302065 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002066 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302067
2068 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002069}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002070
2071/**
2072 * hdd_is_valid_mac_address() - validate MAC address
2073 * @pMacAddr: Pointer to the input MAC address
2074 *
2075 * This function validates whether the given MAC address is valid or not
2076 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2077 * where X is the hexa decimal digit character and separated by ':'
2078 * This algorithm works even if MAC address is not separated by ':'
2079 *
2080 * This code checks given input string mac contains exactly 12 hexadecimal
2081 * digits and a separator colon : appears in the input string only after
2082 * an even number of hex digits.
2083 *
2084 * Return: 1 for valid and 0 for invalid
2085 */
2086bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2087{
2088 int xdigit = 0;
2089 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002090
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002091 while (*pMacAddr) {
2092 if (isxdigit(*pMacAddr)) {
2093 xdigit++;
2094 } else if (':' == *pMacAddr) {
2095 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2096 break;
2097
2098 ++separator;
2099 } else {
2100 /* Invalid MAC found */
2101 return 0;
2102 }
2103 ++pMacAddr;
2104 }
2105 return xdigit == 12 && (separator == 5 || separator == 0);
2106}
2107
2108/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302109 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2110 * @dev: Handle to struct net_device to be updated.
2111 *
2112 * Return: None
2113 */
2114static void hdd_mon_mode_ether_setup(struct net_device *dev)
2115{
2116 dev->header_ops = NULL;
2117 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2118 dev->hard_header_len = ETH_HLEN;
2119 dev->mtu = ETH_DATA_LEN;
2120 dev->addr_len = ETH_ALEN;
2121 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2122 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2123 dev->priv_flags |= IFF_TX_SKB_SHARING;
2124
2125 memset(dev->broadcast, 0xFF, ETH_ALEN);
2126}
2127
2128/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002129 * __hdd__mon_open() - HDD Open function
2130 * @dev: Pointer to net_device structure
2131 *
2132 * This is called in response to ifconfig up
2133 *
2134 * Return: 0 for success; non-zero for failure
2135 */
2136static int __hdd_mon_open(struct net_device *dev)
2137{
2138 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002139 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2140 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002141
Dustin Brownfdf17c12018-03-14 12:55:34 -07002142 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002143
2144 ret = wlan_hdd_validate_context(hdd_ctx);
2145 if (ret)
2146 return ret;
2147
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302148 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002149
2150 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2151 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2152 if (ret) {
2153 hdd_err("Failed to start WLAN modules return");
2154 return ret;
2155 }
2156 hdd_err("hdd_wlan_start_modules() successful !");
2157
2158 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2159 ret = hdd_start_adapter(adapter);
2160 if (ret) {
2161 hdd_err("Failed to start adapter :%d",
2162 adapter->device_mode);
2163 return ret;
2164 }
2165 hdd_err("hdd_start_adapters() successful !");
2166 }
2167 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2168 }
2169
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002170 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002171
2172 if (!ret)
2173 ret = hdd_enable_monitor_mode(dev);
2174
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002175 return ret;
2176}
2177
2178/**
2179 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2180 * @dev: Pointer to net_device structure
2181 *
2182 * This is called in response to ifconfig up
2183 *
2184 * Return: 0 for success; non-zero for failure
2185 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002186static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002187{
2188 int ret;
2189
2190 cds_ssr_protect(__func__);
2191 ret = __hdd_mon_open(dev);
2192 cds_ssr_unprotect(__func__);
2193
2194 return ret;
2195}
2196
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002197static QDF_STATUS
2198wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2199{
2200 struct policy_mgr_dual_mac_config cfg = {0};
2201 QDF_STATUS status;
2202 uint32_t channel_select_logic_conc;
2203 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2204
2205 if (!hdd_ctx) {
2206 hdd_err("HDD context is NULL");
2207 return QDF_STATUS_E_FAILURE;
2208 }
2209
2210
2211 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2212 return QDF_STATUS_SUCCESS;
2213
2214 cfg.scan_config = 0;
2215 cfg.fw_mode_config = 0;
2216 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2217
2218 channel_select_logic_conc = hdd_ctx->config->
2219 channel_select_logic_conc;
2220
2221 if (hdd_ctx->config->dual_mac_feature_disable !=
2222 DISABLE_DBS_CXN_AND_SCAN) {
2223 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2224 hdd_ctx->hdd_psoc, &cfg.scan_config,
2225 &cfg.fw_mode_config,
2226 hdd_ctx->config->dual_mac_feature_disable,
2227 channel_select_logic_conc);
2228
2229 if (status != QDF_STATUS_SUCCESS) {
2230 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2231 status);
2232 return status;
2233 }
2234 }
2235
2236 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2237 cfg.scan_config, cfg.fw_mode_config);
2238
2239 status = sme_soc_set_dual_mac_config(cfg);
2240 if (status != QDF_STATUS_SUCCESS) {
2241 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2242 return status;
2243 }
2244
2245 return QDF_STATUS_SUCCESS;
2246}
2247
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002248/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302249 * hdd_start_adapter() - Wrapper function for device specific adapter
2250 * @adapter: pointer to HDD adapter
2251 *
2252 * This function is called to start the device specific adapter for
2253 * the mode passed in the adapter's device_mode.
2254 *
2255 * Return: 0 for success; non-zero for failure
2256 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002257int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302258{
2259
2260 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002261 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302262
Dustin Brownfdf17c12018-03-14 12:55:34 -07002263 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002264 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302265
2266 switch (device_mode) {
2267 case QDF_P2P_CLIENT_MODE:
2268 case QDF_P2P_DEVICE_MODE:
2269 case QDF_OCB_MODE:
2270 case QDF_STA_MODE:
2271 case QDF_MONITOR_MODE:
2272 ret = hdd_start_station_adapter(adapter);
2273 if (ret)
2274 goto err_start_adapter;
2275 break;
2276 case QDF_P2P_GO_MODE:
2277 case QDF_SAP_MODE:
2278 ret = hdd_start_ap_adapter(adapter);
2279 if (ret)
2280 goto err_start_adapter;
2281 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302282 case QDF_IBSS_MODE:
2283 /*
2284 * For IBSS interface is initialized as part of
2285 * hdd_init_station_mode()
2286 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002287 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302288 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002289 /* vdevs are dynamically managed by firmware in FTM */
2290 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302291 default:
2292 hdd_err("Invalid session type %d", device_mode);
2293 QDF_ASSERT(0);
2294 goto err_start_adapter;
2295 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002296
Arun Khandavallifae92942016-08-01 13:31:08 +05302297 if (hdd_set_fw_params(adapter))
2298 hdd_err("Failed to set the FW params for the adapter!");
2299
2300 /*
2301 * Action frame registered in one adapter which will
2302 * applicable to all interfaces
2303 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302304 ret = wlan_hdd_cfg80211_register_frames(adapter);
2305 if (ret < 0) {
2306 hdd_err("Failed to register frames - ret %d", ret);
2307 goto err_start_adapter;
2308 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002309 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302310
Dustin Browndb2a8be2017-12-20 11:49:56 -08002311exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002312 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002313
Arun Khandavallifae92942016-08-01 13:31:08 +05302314 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002315
Arun Khandavallifae92942016-08-01 13:31:08 +05302316err_start_adapter:
2317 return -EINVAL;
2318}
2319
2320/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302321 * hdd_enable_power_management() - API to Enable Power Management
2322 *
2323 * API invokes Bus Interface Layer power management functionality
2324 *
2325 * Return: None
2326 */
2327static void hdd_enable_power_management(void)
2328{
2329 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2330
2331 if (!hif_ctx) {
2332 hdd_err("Bus Interface Context is Invalid");
2333 return;
2334 }
2335
2336 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2337}
2338
2339/**
2340 * hdd_disable_power_management() - API to disable Power Management
2341 *
2342 * API disable Bus Interface Layer Power management functionality
2343 *
2344 * Return: None
2345 */
2346static void hdd_disable_power_management(void)
2347{
2348 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2349
2350 if (!hif_ctx) {
2351 hdd_err("Bus Interface Context is Invalid");
2352 return;
2353 }
2354
2355 hif_disable_power_management(hif_ctx);
2356}
2357
2358/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302359 * hdd_update_hw_sw_info() - API to update the HW/SW information
2360 *
2361 * API to update the HW and SW information in the driver
2362 *
2363 * Return: None
2364 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002365static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302366{
2367 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002368 size_t target_hw_name_len;
2369 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302370
2371 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2372 if (!hif_sc) {
2373 hdd_err("HIF context is NULL");
2374 return;
2375 }
2376
2377 /*
2378 * target hw version/revision would only be retrieved after firmware
2379 * download
2380 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002381 hif_get_hw_info(hif_sc,
2382 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302383 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002384 &target_hw_name);
2385
2386 if (hdd_ctx->target_hw_name)
2387 qdf_mem_free(hdd_ctx->target_hw_name);
2388
2389 target_hw_name_len = strlen(target_hw_name) + 1;
2390 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2391 if (hdd_ctx->target_hw_name)
2392 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2393 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302394
2395 /* Get the wlan hw/fw version */
2396 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302397}
2398
2399/**
gbian62edd7e2017-03-07 13:12:13 +08002400 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2401 * @hdd_ctx: Pointer to hdd context
2402 *
2403 * Return: none
2404 */
2405static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002406hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002407{
2408 uint8_t num_entries = 0;
2409 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2410 uint8_t *tx_sched_wrr_ac;
2411 int i;
2412 cds_context_type *cds_ctx;
2413
2414 if (NULL == hdd_ctx)
2415 return;
2416
2417 if (NULL == hdd_ctx->config) {
2418 /* Do nothing if hdd_ctx is invalid */
2419 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2420 return;
2421 }
2422
2423 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2424
2425 if (!cds_ctx) {
2426 hdd_err("Invalid CDS Context");
2427 return;
2428 }
2429
2430 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2431 switch (i) {
2432 case OL_TX_WMM_AC_BE:
2433 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2434 break;
2435 case OL_TX_WMM_AC_BK:
2436 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2437 break;
2438 case OL_TX_WMM_AC_VI:
2439 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2440 break;
2441 case OL_TX_WMM_AC_VO:
2442 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2443 break;
2444 default:
2445 tx_sched_wrr_ac = NULL;
2446 break;
2447 }
2448
2449 hdd_string_to_u8_array(tx_sched_wrr_ac,
2450 tx_sched_wrr_param,
2451 &num_entries,
2452 sizeof(tx_sched_wrr_param));
2453
2454 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2455 cds_ctx->ac_specs[i].wrr_skip_weight =
2456 tx_sched_wrr_param[0];
2457 cds_ctx->ac_specs[i].credit_threshold =
2458 tx_sched_wrr_param[1];
2459 cds_ctx->ac_specs[i].send_limit =
2460 tx_sched_wrr_param[2];
2461 cds_ctx->ac_specs[i].credit_reserve =
2462 tx_sched_wrr_param[3];
2463 cds_ctx->ac_specs[i].discard_weight =
2464 tx_sched_wrr_param[4];
2465 }
2466
2467 num_entries = 0;
2468 }
2469}
2470
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302471#ifdef IPA_OFFLOAD
2472/**
2473 * hdd_update_ipa_component_config() - update ipa config
2474 * @hdd_ctx: Pointer to hdd context
2475 *
2476 * Return: none
2477 */
2478static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2479{
2480 struct hdd_config *cfg = hdd_ctx->config;
2481 struct wlan_ipa_config ipa_cfg;
2482
2483 ipa_cfg.ipa_config = cfg->IpaConfig;
2484 ipa_cfg.desc_size = cfg->IpaDescSize;
2485 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2486 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2487 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2488 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2489 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2490 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2491 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2492
2493 ucfg_ipa_update_config(&ipa_cfg);
2494}
2495#else
2496static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2497{
2498}
2499#endif
2500
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002501#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002502static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2503 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2504{
Jeff Johnson9d295242017-08-29 14:39:48 -07002505 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002506 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002507
2508 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2509 if (!adapter) {
2510 hdd_err("Adapter is NULL");
2511 return PM_MAX_NUM_OF_MODE;
2512 }
2513
2514 return policy_mgr_convert_device_mode_to_qdf_type(
2515 adapter->device_mode);
2516}
2517
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002518static void hdd_register_policy_manager_callback(
2519 struct wlan_objmgr_psoc *psoc)
2520{
2521 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002522
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002523 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002524 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002525 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2526 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002527 hdd_cbacks.get_mode_for_non_connected_vdev =
2528 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302529 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002530
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002531 if (QDF_STATUS_SUCCESS !=
2532 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2533 hdd_err("HDD callback registration with policy manager failed");
2534 }
2535}
2536#else
2537static void hdd_register_policy_manager_callback(
2538 struct wlan_objmgr_psoc *psoc)
2539{
2540}
2541#endif
2542
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002543static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002544{
2545 struct nan_callbacks cb_obj = {0};
2546
2547 cb_obj.ndi_open = hdd_ndi_open;
2548 cb_obj.ndi_close = hdd_ndi_close;
2549 cb_obj.ndi_start = hdd_ndi_start;
2550 cb_obj.ndi_delete = hdd_ndi_delete;
2551 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2552 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2553
Naveen Rawat37f62c82017-03-26 22:24:43 -07002554 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2555 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002556 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002557
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002558 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2559}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002560
Dustin Brown26b3d042017-12-21 11:13:27 -08002561#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002562/**
2563 * hdd_check_for_leaks() - Perform runtime memory leak checks
2564 *
2565 * This API triggers runtime memory leak detection. This feature enforces the
2566 * policy that any memory allocated at runtime must also be released at runtime.
2567 *
2568 * Allocating memory at runtime and releasing it at unload is effectively a
2569 * memory leak for configurations which never unload (e.g. LONU, statically
2570 * compiled driver). Such memory leaks are NOT false positives, and must be
2571 * fixed.
2572 *
2573 * Return: None
2574 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002575static void hdd_check_for_leaks(void)
2576{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002577 /* DO NOT REMOVE these checks; for false positives, read above first */
2578
Dustin Brown677e0862017-10-10 16:30:09 -07002579 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002580 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002581 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002582}
2583
Dustin Brown26b3d042017-12-21 11:13:27 -08002584#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2585#else
2586static inline void hdd_check_for_leaks(void) {}
2587
2588#define hdd_debug_domain_set(domain)
2589#endif /* CONFIG_LEAK_DETECTION */
2590
gbian62edd7e2017-03-07 13:12:13 +08002591/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002592 * hdd_update_country_code - Update country code
2593 * @hdd_ctx: HDD context
2594 *
2595 * Update country code based on module parameter country_code
2596 *
2597 * Return: 0 on success and errno on failure
2598 */
2599static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2600{
2601 if (!country_code)
2602 return 0;
2603
2604 return hdd_reg_set_country(hdd_ctx, country_code);
2605}
2606
2607/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302608 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2609 * @hdd_ctx: HDD context
2610 * @adapter: HDD adapter
2611 * @reinit: flag to indicate from SSR or normal path
2612 *
2613 * This function maintains the driver state machine it will be invoked from
2614 * startup, reinit and change interface. Depending on the driver state shall
2615 * perform the opening of the modules.
2616 *
2617 * Return: 0 for success; non-zero for failure
2618 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002619int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2620 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302621 bool reinit)
2622{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002623 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302624 qdf_device_t qdf_dev;
2625 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302626 bool unint = false;
2627 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002628 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302629
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002630 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302631
2632 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2633 if (!qdf_dev) {
2634 hdd_err("QDF Device Context is Invalid return");
2635 return -EINVAL;
2636 }
2637
Dustin Brown6f427922017-09-19 12:19:00 -07002638 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302639
Dustin Brown1fe30a82017-10-03 16:13:36 -07002640 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302641 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2642 mutex_unlock(&hdd_ctx->iface_change_lock);
2643 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002644 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302645 return 0;
2646 }
2647
Dustin Brown1fe30a82017-10-03 16:13:36 -07002648 hdd_ctx->start_modules_in_progress = true;
2649
Arun Khandavallifae92942016-08-01 13:31:08 +05302650 switch (hdd_ctx->driver_status) {
2651 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002652 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302653 unint = true;
2654 /* Fall through dont add break here */
2655 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002656 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2657
Dustin Brown26b3d042017-12-21 11:13:27 -08002658 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002659
Arun Khandavallifae92942016-08-01 13:31:08 +05302660 if (!reinit && !unint) {
2661 ret = pld_power_on(qdf_dev->dev);
2662 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002663 hdd_err("Failed to Powerup the device; errno: %d",
2664 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302665 goto release_lock;
2666 }
2667 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002668
2669 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2670 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302671 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2672 qdf_dev->bus_type,
2673 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2674 HIF_ENABLE_TYPE_PROBE);
2675 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002676 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302677 goto power_down;
2678 }
2679
2680 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302681 if (!hif_ctx) {
2682 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002683 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302684 goto power_down;
2685 }
2686
Arun Khandavallifae92942016-08-01 13:31:08 +05302687 status = ol_cds_init(qdf_dev, hif_ctx);
2688 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002689 hdd_err("No Memory to Create BMI Context; status: %d",
2690 status);
2691 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302692 goto hif_close;
2693 }
2694
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302695 hdd_update_ipa_component_config(hdd_ctx);
2696
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002697 ret = hdd_update_config(hdd_ctx);
2698 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002699 hdd_err("Failed to update configuration; errno: %d",
2700 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002701 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002702 }
2703
gbian62edd7e2017-03-07 13:12:13 +08002704 hdd_update_cds_ac_specs_params(hdd_ctx);
2705
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302706 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002707 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002708 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002709 ret = qdf_status_to_os_return(status);
2710 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302711 }
2712
Jeff Johnson79e36882018-05-06 17:15:33 -07002713 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302714 ret = hdd_update_components_config(hdd_ctx);
2715 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002716 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302717 ret);
2718 goto close;
2719 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002720 status = cds_dp_open(hdd_ctx->hdd_psoc);
2721 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002722 hdd_err("Failed to Open cds post open; status: %d",
2723 status);
2724 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002725 goto close;
2726 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302727
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002728 /*
2729 * NAN compoenet requires certian operations like, open adapter,
2730 * close adapter, etc. to be initiated by HDD, for those
2731 * register HDD callbacks with UMAC's NAN componenet.
2732 */
2733 hdd_nan_register_callbacks(hdd_ctx);
2734
Arun Khandavallifae92942016-08-01 13:31:08 +05302735 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2736
Jeff Johnson3a280122017-09-13 07:42:00 -07002737 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302738 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002739 hdd_err("Failed to pre-enable CDS; status: %d", status);
2740 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002741 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302742 }
2743
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002744 hdd_register_policy_manager_callback(
2745 hdd_ctx->hdd_psoc);
2746
Amar Singhal0928b192017-12-01 10:50:54 -08002747 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2748
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302749 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302750 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002751 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302752
Arun Khandavallifae92942016-08-01 13:31:08 +05302753 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002754 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302755 break;
2756 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302757
Arun Khandavallifae92942016-08-01 13:31:08 +05302758 /* Fall through dont add break here */
2759 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002760 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2761
Arun Khandavallifae92942016-08-01 13:31:08 +05302762 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002763 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002764 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002765 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302766 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302767 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2768 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002769 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302770 break;
2771 }
Dustin Browndca39692017-11-09 15:30:25 -08002772
2773 ret = hdd_configure_cds(hdd_ctx, adapter);
2774 if (ret) {
2775 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002776 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302777 }
Dustin Browndca39692017-11-09 15:30:25 -08002778
Komal Seelamf2136bb2016-09-28 18:30:44 +05302779 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002780
Arun Khandavallifae92942016-08-01 13:31:08 +05302781 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002782 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302783 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002784
Arun Khandavallifae92942016-08-01 13:31:08 +05302785 default:
2786 hdd_err("WLAN start invoked in wrong state! :%d\n",
2787 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002788 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302789 goto release_lock;
2790 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002791
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302792 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002793 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2794 ret = hdd_update_country_code(hdd_ctx);
2795 if (ret)
2796 hdd_err("Failed to update command line country code!");
2797 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302798 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002799
Dustin Browne74003f2018-03-14 12:51:58 -07002800 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002801
Arun Khandavallifae92942016-08-01 13:31:08 +05302802 return 0;
2803
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002804post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002805 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002806
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002807cds_txrx_free:
Jingxiang Ge95912f82018-04-19 12:01:26 +08002808 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
2809
2810 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2811 hdd_runtime_suspend_context_deinit(hdd_ctx);
2812 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
2813 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2814 }
2815
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002816 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002817
Arun Khandavallifae92942016-08-01 13:31:08 +05302818close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002819 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002820 hdd_info("Wlan transition aborted (now CLOSED)");
2821
Jeff Johnsone4b14592017-09-13 14:23:33 -07002822 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302823
Dustin Brown28b17892017-10-10 13:29:38 -07002824deinit_config:
2825 cds_deinit_ini_config();
2826
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002827cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302828 ol_cds_free();
2829
2830hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002831 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2832 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302833power_down:
2834 if (!reinit && !unint)
2835 pld_power_off(qdf_dev->dev);
2836release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302837 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302838 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002839
2840 /* many adapter resources are not freed by design in SSR case */
2841 if (!reinit)
2842 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002843 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002844
Dustin Browne74003f2018-03-14 12:51:58 -07002845 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002846
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002847 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302848}
2849
Naveen Rawat910726a2017-03-06 11:42:51 -08002850#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002851static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002852{
2853 int ret = os_if_wifi_pos_register_nl();
2854
2855 if (ret)
2856 hdd_err("os_if_wifi_pos_register_nl failed");
2857
2858 return ret;
2859}
2860
2861static int hdd_deactivate_wifi_pos(void)
2862{
2863 int ret = os_if_wifi_pos_deregister_nl();
2864
2865 if (ret)
2866 hdd_err("os_if_wifi_pos_deregister_nl failed");
2867
2868 return ret;
2869}
2870
2871/**
2872 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2873 * @hdd_ctx: hdd context
2874 *
2875 * Return: status of operation
2876 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002877static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002878{
2879 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2880 struct hdd_config *cfg = hdd_ctx->config;
2881
2882 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2883 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2884 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2885 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2886 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2887 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2888 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2889 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2890}
2891#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002892static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002893{
2894 return oem_activate_service(hdd_ctx);
2895}
2896
2897static int hdd_deactivate_wifi_pos(void)
2898{
2899 return 0;
2900}
2901
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002902static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002903{
2904}
2905#endif
2906
Arun Khandavallifae92942016-08-01 13:31:08 +05302907/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002908 * __hdd_open() - HDD Open function
2909 * @dev: Pointer to net_device structure
2910 *
2911 * This is called in response to ifconfig up
2912 *
2913 * Return: 0 for success; non-zero for failure
2914 */
2915static int __hdd_open(struct net_device *dev)
2916{
Jeff Johnson9d295242017-08-29 14:39:48 -07002917 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002918 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002919 int ret;
2920
Dustin Brownfdf17c12018-03-14 12:55:34 -07002921 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302922 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002923 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002924
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302925 /* Nothing to be done if device is unloading */
2926 if (cds_is_driver_unloading()) {
2927 hdd_err("Driver is unloading can not open the hdd");
2928 return -EBUSY;
2929 }
2930
Dustin Brown01847752017-10-25 13:56:27 -07002931 if (cds_is_driver_recovering()) {
2932 hdd_err("WLAN is currently recovering; Please try again.");
2933 return -EBUSY;
2934 }
2935
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302936 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2937 hdd_err("con_mode_handler is in progress; Please try again.");
2938 return -EBUSY;
2939 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302940
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302941 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302942 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2943
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302944 /*
2945 * This scenario can be hit in cases where in the wlan driver after
2946 * registering the netdevices and there is a failure in driver
2947 * initialization. So return error gracefully because the netdevices
2948 * will be de-registered as part of the load failure.
2949 */
2950
2951 if (!cds_is_driver_loaded()) {
2952 hdd_err("Failed to start the wlan driver!!");
2953 ret = -EIO;
2954 goto err_hdd_hdd_init_deinit_lock;
2955 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002957
Arun Khandavallifae92942016-08-01 13:31:08 +05302958 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2959 if (ret) {
2960 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302961 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302962 }
2963
2964
2965 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2966 ret = hdd_start_adapter(adapter);
2967 if (ret) {
2968 hdd_err("Failed to start adapter :%d",
2969 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302970 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302971 }
2972 }
2973
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002974 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2975 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002976 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002977 /* Enable TX queues only when we are connected */
2978 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302979 WLAN_START_ALL_NETIF_QUEUE,
2980 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002981 }
2982
Naveen Rawat286def52016-09-23 15:38:02 -07002983 /* Enable carrier and transmit queues for NDI */
2984 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002985 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002986 wlan_hdd_netif_queue_control(adapter,
2987 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2988 WLAN_CONTROL_PATH);
2989 }
2990
Naveen Rawat910726a2017-03-06 11:42:51 -08002991 hdd_populate_wifi_pos_cfg(hdd_ctx);
2992
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302993err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302994 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302995 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002996 return ret;
2997}
2998
Arun Khandavallifae92942016-08-01 13:31:08 +05302999
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003000/**
3001 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3002 * @dev: Pointer to net_device structure
3003 *
3004 * This is called in response to ifconfig up
3005 *
3006 * Return: 0 for success; non-zero for failure
3007 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003008static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003009{
3010 int ret;
3011
3012 cds_ssr_protect(__func__);
3013 ret = __hdd_open(dev);
3014 cds_ssr_unprotect(__func__);
3015
3016 return ret;
3017}
3018
3019/**
3020 * __hdd_stop() - HDD stop function
3021 * @dev: Pointer to net_device structure
3022 *
3023 * This is called in response to ifconfig down
3024 *
3025 * Return: 0 for success; non-zero for failure
3026 */
3027static int __hdd_stop(struct net_device *dev)
3028{
Jeff Johnson9d295242017-08-29 14:39:48 -07003029 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003030 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003031 int ret;
3032
Dustin Brownfdf17c12018-03-14 12:55:34 -07003033 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003034
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303035 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003036 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003037
3038 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303039 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003040 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003041
3042 /* Nothing to be done if the interface is not opened */
3043 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003044 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003045 return -ENODEV;
3046 }
3047
3048 /* Make sure the interface is marked as closed */
3049 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303050
3051 hdd_debug("Disabling Auto Power save timer");
3052 sme_ps_disable_auto_ps_timer(
3053 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07003054 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303055
3056 /*
3057 * Disable TX on the interface, after this hard_start_xmit() will not
3058 * be called on that interface
3059 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003060 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003061 hdd_device_mode_to_string(adapter->device_mode),
3062 adapter->device_mode);
3063
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303064 wlan_hdd_netif_queue_control(adapter,
3065 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3066 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003067
3068 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003069 * NAN data interface is different in some sense. The traffic on NDI is
3070 * bursty in nature and depends on the need to transfer. The service
3071 * layer may down the interface after the usage and up again when
3072 * required. In some sense, the NDI is expected to be available
3073 * (like SAP) iface until NDI delete request is issued by the service
3074 * layer. Skip BSS termination and adapter deletion for NAN Data
3075 * interface (NDI).
3076 */
3077 if (WLAN_HDD_IS_NDI(adapter))
3078 return 0;
3079
3080 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003081 * The interface is marked as down for outside world (aka kernel)
3082 * But the driver is pretty much alive inside. The driver needs to
3083 * tear down the existing connection on the netdev (session)
3084 * cleanup the data pipes and wait until the control plane is stabilized
3085 * for this interface. The call also needs to wait until the above
3086 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003087 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003088 * That is intentional to be able to scan if it is a STA/P2P interface
3089 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003090 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003091
3092 /* DeInit the adapter. This ensures datapath cleanup as well */
3093 hdd_deinit_adapter(hdd_ctx, adapter, true);
3094
Arun Khandavallifae92942016-08-01 13:31:08 +05303095
3096 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303097 * Upon wifi turn off, DUT has to flush the scan results so if
3098 * this is the last cli iface, flush the scan database.
3099 */
3100 if (!hdd_is_cli_iface_up(hdd_ctx))
3101 sme_scan_flush_result(hdd_ctx->hHal);
3102
3103 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303104 * Find if any iface is up. If any iface is up then can't put device to
3105 * sleep/power save mode
3106 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303107 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003108 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003109 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3110 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303111 hdd_prevent_suspend_timeout(
3112 hdd_ctx->config->iface_change_wait_time,
3113 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303114 }
3115
Dustin Browne74003f2018-03-14 12:51:58 -07003116 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003117 return 0;
3118}
3119
3120/**
3121 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3122 * @dev: pointer to net_device structure
3123 *
3124 * This is called in response to ifconfig down
3125 *
3126 * Return: 0 for success and error number for failure
3127 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003128static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003129{
3130 int ret;
3131
3132 cds_ssr_protect(__func__);
3133 ret = __hdd_stop(dev);
3134 cds_ssr_unprotect(__func__);
3135
3136 return ret;
3137}
3138
3139/**
3140 * __hdd_uninit() - HDD uninit function
3141 * @dev: Pointer to net_device structure
3142 *
3143 * This is called during the netdev unregister to uninitialize all data
3144 * associated with the device
3145 *
3146 * Return: None
3147 */
3148static void __hdd_uninit(struct net_device *dev)
3149{
Jeff Johnson9d295242017-08-29 14:39:48 -07003150 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003151 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152
Dustin Brownfdf17c12018-03-14 12:55:34 -07003153 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154
3155 do {
3156 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003157 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158 break;
3159 }
3160
Jeff Johnson399c6272017-08-30 10:51:00 -07003161 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3162 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003163 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164 break;
3165 }
3166
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003167 if (dev != adapter->dev)
3168 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169
Jeff Johnson399c6272017-08-30 10:51:00 -07003170 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171
3172 /* after uninit our adapter structure will no longer be valid */
3173 adapter->dev = NULL;
3174 adapter->magic = 0;
3175 } while (0);
3176
Dustin Browne74003f2018-03-14 12:51:58 -07003177 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178}
3179
3180/**
3181 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3182 * @dev: pointer to net_device structure
3183 *
3184 * This is called during the netdev unregister to uninitialize all data
3185 * associated with the device
3186 *
3187 * Return: none
3188 */
3189static void hdd_uninit(struct net_device *dev)
3190{
3191 cds_ssr_protect(__func__);
3192 __hdd_uninit(dev);
3193 cds_ssr_unprotect(__func__);
3194}
3195
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003196static int hdd_open_cesium_nl_sock(void)
3197{
3198#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3199 struct netlink_kernel_cfg cfg = {
3200 .groups = WLAN_NLINK_MCAST_GRP_ID,
3201 .input = NULL
3202 };
3203#endif
3204 int ret = 0;
3205
3206#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3207 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3208#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3209 THIS_MODULE,
3210#endif
3211 &cfg);
3212#else
3213 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3214 WLAN_NLINK_MCAST_GRP_ID,
3215 NULL, NULL, THIS_MODULE);
3216#endif
3217
3218 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003219 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003220 ret = -ECONNREFUSED;
3221 }
3222
3223 return ret;
3224}
3225
3226static void hdd_close_cesium_nl_sock(void)
3227{
3228 if (NULL != cesium_nl_srv_sock) {
3229 netlink_kernel_release(cesium_nl_srv_sock);
3230 cesium_nl_srv_sock = NULL;
3231 }
3232}
3233
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003234/**
3235 * __hdd_set_mac_address() - set the user specified mac address
3236 * @dev: Pointer to the net device.
3237 * @addr: Pointer to the sockaddr.
3238 *
3239 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003240 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241 *
3242 * Return: 0 for success, non zero for failure
3243 */
3244static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3245{
Jeff Johnson9d295242017-08-29 14:39:48 -07003246 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003247 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303249 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303251 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003252
Dustin Brownfdf17c12018-03-14 12:55:34 -07003253 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003254
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303255 if (netif_running(dev)) {
3256 hdd_err("On iface up, set mac address change isn't supported");
3257 return -EBUSY;
3258 }
3259
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003260 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3261 ret = wlan_hdd_validate_context(hdd_ctx);
3262 if (0 != ret)
3263 return ret;
3264
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303265 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
3266
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303267 if (hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes)) {
3268 hdd_err("adapter exist with same mac address " MAC_ADDRESS_STR,
3269 MAC_ADDR_ARRAY(mac_addr.bytes));
3270 return -EINVAL;
3271 }
3272
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303273 if (qdf_is_macaddr_zero(&mac_addr)) {
3274 hdd_err("MAC is all zero");
3275 return -EINVAL;
3276 }
3277
3278 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3279 hdd_err("MAC is Broadcast");
3280 return -EINVAL;
3281 }
3282
3283 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3284 hdd_err("MAC is Multicast");
3285 return -EINVAL;
3286 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303287 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3288 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303289
Jeff Johnson1e851a12017-10-28 14:36:12 -07003290 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003291 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3292
Dustin Browne74003f2018-03-14 12:51:58 -07003293 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303294 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003295}
3296
3297/**
3298 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3299 * function from SSR
3300 * @dev: pointer to net_device structure
3301 * @addr: Pointer to the sockaddr
3302 *
3303 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003304 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003305 *
3306 * Return: 0 for success.
3307 */
3308static int hdd_set_mac_address(struct net_device *dev, void *addr)
3309{
3310 int ret;
3311
3312 cds_ssr_protect(__func__);
3313 ret = __hdd_set_mac_address(dev, addr);
3314 cds_ssr_unprotect(__func__);
3315
3316 return ret;
3317}
3318
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003319uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320{
3321 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003322
Anurag Chouhan6d760662016-02-20 16:05:43 +05303323 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003324 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3325 break;
3326 }
3327
Anurag Chouhan6d760662016-02-20 16:05:43 +05303328 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003329 return NULL;
3330
3331 hdd_ctx->config->intfAddrMask |= (1 << i);
3332 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3333}
3334
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003335void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3336 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337{
3338 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003339
Anurag Chouhan6d760662016-02-20 16:05:43 +05303340 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341 if (!memcmp(releaseAddr,
3342 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3343 6)) {
3344 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3345 break;
3346 }
3347 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348}
3349
3350#ifdef WLAN_FEATURE_PACKET_FILTERING
3351/**
3352 * __hdd_set_multicast_list() - set the multicast address list
3353 * @dev: Pointer to the WLAN device.
3354 * @skb: Pointer to OS packet (sk_buff).
3355 *
3356 * This funciton sets the multicast address list.
3357 *
3358 * Return: None
3359 */
3360static void __hdd_set_multicast_list(struct net_device *dev)
3361{
Jeff Johnson9d295242017-08-29 14:39:48 -07003362 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363 int i = 0, status;
3364 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003365 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303366 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3367 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3368 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003369
Dustin Brownfdf17c12018-03-14 12:55:34 -07003370 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303371 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303372 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303373
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003374 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303375 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303376 goto out;
3377
Dustin Brownc788acb2017-08-01 17:43:51 -07003378 status = hdd_validate_adapter(adapter);
3379 if (status)
3380 goto out;
3381
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303382 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3383 hdd_err("%s: Driver module is closed", __func__);
3384 return;
3385 }
3386
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303387 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3388 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003389 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303390 goto out;
3391 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003392
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303393 /* Delete already configured multicast address list */
3394 if (adapter->mc_addr_list.mc_cnt > 0) {
3395 hdd_info("clear previously configured MC address list");
3396 hdd_disable_and_flush_mc_addr_list(adapter,
3397 pmo_mc_list_change_notify);
3398 }
3399
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003400 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003401 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303402 hdd_disable_and_flush_mc_addr_list(adapter,
3403 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 } else {
3405 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303406 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003407 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303408 pmo_ucfg_max_mc_addr_supported(psoc));
3409 hdd_disable_and_flush_mc_addr_list(adapter,
3410 pmo_mc_list_change_notify);
3411 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003413 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003414 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303415 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 if (i == mc_count)
3417 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303418 memset(&(mc_list_request->mc_addr[i].bytes),
3419 0, ETH_ALEN);
3420 memcpy(&(mc_list_request->mc_addr[i].bytes),
3421 ha->addr, ETH_ALEN);
3422 hdd_info("mlist[%d] = %pM", i,
3423 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003424 i++;
3425 }
3426 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303427
3428 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003429 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303430 mc_list_request->count = mc_count;
3431 status = hdd_cache_mc_addr_list(mc_list_request);
3432 if (status == 0) {
3433 hdd_enable_mc_addr_filtering(adapter,
3434 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303436 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303438out:
3439 if (mc_list_request)
3440 qdf_mem_free(mc_list_request);
Dustin Browne74003f2018-03-14 12:51:58 -07003441 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003442}
3443
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445/**
3446 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3447 * @dev: pointer to net_device
3448 *
3449 * Return: none
3450 */
3451static void hdd_set_multicast_list(struct net_device *dev)
3452{
3453 cds_ssr_protect(__func__);
3454 __hdd_set_multicast_list(dev);
3455 cds_ssr_unprotect(__func__);
3456}
3457#endif
3458
3459/**
3460 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3461 * @dev: Pointer to the WLAN device.
3462 * @skb: Pointer to OS packet (sk_buff).
3463 *
3464 * This function is registered with the Linux OS for network
3465 * core to decide which queue to use first.
3466 *
3467 * Return: ac, Queue Index/access category corresponding to UP in IP header
3468 */
3469static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3470#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3471 , void *accel_priv
3472#endif
3473#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3474 , select_queue_fallback_t fallback
3475#endif
3476)
3477{
3478 return hdd_wmm_select_queue(dev, skb);
3479}
3480
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003481static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003482 .ndo_open = hdd_open,
3483 .ndo_stop = hdd_stop,
3484 .ndo_uninit = hdd_uninit,
3485 .ndo_start_xmit = hdd_hard_start_xmit,
3486 .ndo_tx_timeout = hdd_tx_timeout,
3487 .ndo_get_stats = hdd_get_stats,
3488 .ndo_do_ioctl = hdd_ioctl,
3489 .ndo_set_mac_address = hdd_set_mac_address,
3490 .ndo_select_queue = hdd_select_queue,
3491#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493#endif
3494};
3495
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003496/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003497static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003498 .ndo_open = hdd_mon_open,
3499 .ndo_stop = hdd_stop,
3500 .ndo_get_stats = hdd_get_stats,
3501};
3502
3503/**
3504 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003505 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003506 * Return: None
3507 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003508void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003509{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003510 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003511 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003512 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003513 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003514}
3515
3516/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003517 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3518 * @hdd_ctx: global hdd context
3519 * @macAddr: mac address to assign to the interface
3520 * @name: User-visible name of the interface
3521 *
3522 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003523 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003524 *
3525 * Return: the pointer to hdd adapter, otherwise NULL
3526 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003527static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003529 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530 const char *name)
3531{
Jeff Johnson5505db82017-11-02 21:19:23 -07003532 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003533 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003534 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303535 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536 /*
3537 * cfg80211 initialization and registration....
3538 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003539 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003540#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3541 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003543 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3544 hdd_mon_mode_ether_setup : ether_setup),
3545 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003546
Jeff Johnson5505db82017-11-02 21:19:23 -07003547 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003548
3549 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003550 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003551
Jeff Johnson9d295242017-08-29 14:39:48 -07003552 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003553 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303554 qdf_mem_set(sta_ctx->conn_info.staId,
3555 sizeof(sta_ctx->conn_info.staId),
3556 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003557 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003558 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003560 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003561
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303562 qdf_status = qdf_event_create(
3563 &adapter->qdf_session_open_event);
3564 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3565 hdd_err("Session open QDF event init failed!");
3566 free_netdev(adapter->dev);
3567 return NULL;
3568 }
3569
3570 qdf_status = qdf_event_create(
3571 &adapter->qdf_session_close_event);
3572 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3573 hdd_err("Session close QDF event init failed!");
3574 free_netdev(adapter->dev);
3575 return NULL;
3576 }
3577
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303579 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580 init_completion(&adapter->linkup_event_var);
3581 init_completion(&adapter->cancel_rem_on_chan_var);
3582 init_completion(&adapter->rem_on_chan_ready_event);
3583 init_completion(&adapter->sta_authorized_event);
3584 init_completion(&adapter->offchannel_tx_event);
3585 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003586 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303587 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588
3589 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003590 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303591 adapter->disconnection_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003593 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594
Jeff Johnson5505db82017-11-02 21:19:23 -07003595 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003596 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003597 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003598 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003599 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600
3601 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003602 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003604 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605
Jeff Johnson5505db82017-11-02 21:19:23 -07003606 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003607
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608 hdd_set_station_ops(adapter->dev);
3609
Jeff Johnson5505db82017-11-02 21:19:23 -07003610 hdd_dev_setup_destructor(dev);
3611 dev->ieee80211_ptr = &adapter->wdev;
3612 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003613 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003614 adapter->wdev.netdev = dev;
3615 /* set dev's parent to underlying device */
3616 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003617 hdd_wmm_init(adapter);
3618 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303619 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620 }
3621
3622 return adapter;
3623}
3624
Jeff Johnson9d295242017-08-29 14:39:48 -07003625static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003627 struct net_device *dev = adapter->dev;
3628 int ret;
3629
Dustin Brown491d54b2018-03-14 12:39:11 -07003630 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003631
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003632 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003633 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3634
3635 ret = dev_alloc_name(dev, dev->name);
3636 if (ret < 0) {
3637 hdd_err(
3638 "unable to get dev name: %s, err = 0x%x",
3639 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303640 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 }
3642 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003643
3644 ret = register_netdevice(dev);
3645 if (ret) {
3646 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3647 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303648 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003649 }
3650 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003651 ret = register_netdev(dev);
3652 if (ret) {
3653 hdd_err("register_netdev(%s) failed, err = 0x%x",
3654 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303655 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 }
3657 }
3658 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3659
Dustin Browne74003f2018-03-14 12:51:58 -07003660 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003661
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303662 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003663}
3664
Krunal Sonib51eec72017-11-20 21:53:01 -08003665QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003666{
Krunal Sonib51eec72017-11-20 21:53:01 -08003667 struct hdd_adapter *adapter;
3668 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003669
Krunal Sonib51eec72017-11-20 21:53:01 -08003670 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3671 if (!hdd_ctx) {
3672 hdd_err("Invalid HDD_CTX");
3673 return QDF_STATUS_E_FAILURE;
3674 }
3675
3676 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3677 if (NULL == adapter) {
3678 hdd_err("NULL adapter");
3679 return QDF_STATUS_E_INVAL;
3680 }
3681 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303682 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003683 hdd_debug("session %d opened", adapter->session_id);
3684
3685 return QDF_STATUS_SUCCESS;
3686}
3687
3688QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3689{
3690 struct hdd_adapter *adapter;
3691 struct hdd_context *hdd_ctx;
3692
3693 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3694 if (!hdd_ctx) {
3695 hdd_err("Invalid HDD_CTX");
3696 return QDF_STATUS_E_FAILURE;
3697 }
3698
3699 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003701 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303702 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003703 }
3704
3705 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003706 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303707 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003708 }
3709
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003710 /*
3711 * For NAN Data interface, the close session results in the final
3712 * indication to the userspace
3713 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003714 if (adapter->device_mode == QDF_NDI_MODE)
3715 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003716
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003717 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3718
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003719 /*
3720 * We can be blocked while waiting for scheduled work to be
3721 * flushed, and the adapter structure can potentially be freed, in
3722 * which case the magic will have been reset. So make sure the
3723 * magic is still good, and hence the adapter structure is still
3724 * valid, before signaling completion
3725 */
3726 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303727 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003728
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303729 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003730}
3731
Jeff Johnson9d295242017-08-29 14:39:48 -07003732int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003733{
Dustin Brownd28772b2017-03-17 14:16:07 -07003734 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003735
Dustin Brownd28772b2017-03-17 14:16:07 -07003736 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003737 if (QDF_IS_STATUS_ERROR(status))
3738 return qdf_status_to_os_return(status);
3739
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003740 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003741 if (QDF_IS_STATUS_ERROR(status))
3742 return qdf_status_to_os_return(status);
3743
3744 if (wma_capability_enhanced_mcast_filter())
3745 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3746 else
3747 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003748
3749 return qdf_status_to_os_return(status);
3750}
3751
Jeff Johnson9d295242017-08-29 14:39:48 -07003752int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003753{
3754 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003755 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003756 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003757 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003758
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003759 vdev_id = adapter->session_id;
3760 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003761
3762 /* vdev created sanity check */
3763 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003764 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003765 return -EINVAL;
3766 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003767 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003768
Dustin Brownd28772b2017-03-17 14:16:07 -07003769 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303770 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003771 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003772 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003773 if (QDF_IS_STATUS_ERROR(status)) {
3774 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003775 errno = qdf_status_to_os_return(status);
3776 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003777 }
3778
3779 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303780 status = qdf_wait_for_event_completion(
3781 &adapter->qdf_session_close_event,
3782 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3783 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003784 if (adapter->device_mode == QDF_NDI_MODE)
3785 hdd_ndp_session_end_handler(adapter);
3786 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303787 adapter->session_id = HDD_SESSION_ID_INVALID;
3788 if (QDF_STATUS_E_TIMEOUT != status) {
3789 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003790 errno = -ETIMEDOUT;
3791 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303792 } else if (adapter->qdf_session_close_event.force_set) {
3793 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003794 errno = -EINVAL;
3795 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303796 } else {
3797 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003798 errno = -EINVAL;
3799 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303800 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003801 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003802
Yue Maf9782842017-05-08 12:49:49 -07003803release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003804 /*
3805 * In SSR or driver unloading case, directly exit may cause objects
3806 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003807 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003808 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003809 return errno;
3810
Sandeep Puligillaef415362017-08-30 16:37:13 -07003811 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003812 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003813 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003814 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003815 return errno;
3816 }
3817
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003818 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003819
3820 return 0;
3821}
3822
Krunal Sonib51eec72017-11-20 21:53:01 -08003823static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3824 struct sme_session_params *session_param,
3825 csr_roam_completeCallback callback,
3826 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003827{
Dustin Brownd28772b2017-03-17 14:16:07 -07003828 uint32_t type;
3829 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003830 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003831
3832 /* determine vdev (sub)type */
3833 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303834 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003835 hdd_err("failed to get vdev type: %d", status);
3836 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003837 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003838 session_param->sme_session_id = adapter->session_id;
3839 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3840 session_param->type_of_persona = type;
3841 session_param->subtype_of_persona = sub_type;
3842 session_param->session_open_cb = hdd_sme_open_session_callback;
3843 session_param->session_close_cb = hdd_sme_close_session_callback;
3844 session_param->callback = callback;
3845 session_param->callback_ctx = callback_ctx;
3846
3847 return 0;
3848}
3849
3850int hdd_vdev_create(struct hdd_adapter *adapter,
3851 csr_roam_completeCallback callback, void *ctx)
3852{
3853 QDF_STATUS status;
3854 int errno;
3855 struct hdd_context *hdd_ctx;
3856 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003857
3858 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003859
3860 /* do vdev create via objmgr */
3861 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003862 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003863 if (errno) {
3864 hdd_err("failed to create objmgr vdev: %d", errno);
3865 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003866 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003867
3868 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303869 status = qdf_event_reset(&adapter->qdf_session_open_event);
3870 if (QDF_STATUS_SUCCESS != status) {
3871 hdd_err("failed to reinit session open event");
3872 return -EINVAL;
3873 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003874 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3875 callback, ctx);
3876 if (errno) {
3877 hdd_err("failed to populating SME params");
3878 goto objmgr_vdev_destroy_procedure;
3879 }
3880
3881 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003882 if (QDF_IS_STATUS_ERROR(status)) {
3883 hdd_err("failed to open sme session: %d", status);
3884 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003885 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003886 }
3887
3888 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303889 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3890 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3891 if (QDF_STATUS_SUCCESS != status) {
3892 if (adapter->qdf_session_open_event.force_set) {
3893 /*
3894 * SSR/PDR has caused shutdown, which has forcefully
3895 * set the event. Return without the closing session.
3896 */
3897 adapter->session_id = HDD_SESSION_ID_INVALID;
3898 hdd_err("Session open event forcefully set");
3899 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303900 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003901
3902 if (QDF_STATUS_E_TIMEOUT == status)
3903 hdd_err("Session failed to open within timeout period");
3904 else
3905 hdd_err("Failed to wait for session open event(status-%d)",
3906 status);
3907 errno = -ETIMEDOUT;
3908 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3909 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003910 }
3911
3912 /* firmware ready for component communication, raise vdev_ready event */
3913 errno = hdd_vdev_ready(adapter);
3914 if (errno) {
3915 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003916 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003917 }
3918
Naveen Rawat2b430892018-03-13 13:58:18 -07003919 if (adapter->device_mode == QDF_STA_MODE) {
3920 hdd_debug("setting RTT mac randomization param: %d",
3921 hdd_ctx->config->enable_rtt_mac_randomization);
3922 errno = sme_cli_set_command(adapter->session_id,
3923 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
3924 hdd_ctx->config->enable_rtt_mac_randomization,
3925 VDEV_CMD);
3926 if (0 != errno)
3927 hdd_err("RTT mac randomization param set failed %d",
3928 errno);
3929 }
3930
Jeff Johnson1b780e42017-10-31 14:11:45 -07003931 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003932
3933 return 0;
3934
3935 /*
3936 * Due to legacy constraints, we need to destroy in the same order as
3937 * create. So, split error handling into 2 cases to accommodate.
3938 */
3939
Krunal Soni4a020c72017-10-30 20:58:40 -07003940objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003941 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003942
3943 return errno;
3944
Krunal Soni4a020c72017-10-30 20:58:40 -07003945hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003946 QDF_BUG(!hdd_vdev_destroy(adapter));
3947
3948 return errno;
3949}
3950
Jeff Johnson9d295242017-08-29 14:39:48 -07003951QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003952{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003953 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003954 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003955 QDF_STATUS status;
3956 int ret_val;
3957
Dustin Brownd28772b2017-03-17 14:16:07 -07003958 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3959 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3960 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003961 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003962
Jeff Johnson7f2c5912018-03-23 11:42:28 -07003963 hdd_roam_profile_init(adapter);
3964 hdd_register_wext(adapter->dev);
3965
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003966 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967
Jeff Johnsond377dce2017-10-04 10:32:42 -07003968 qdf_mem_set(sta_ctx->conn_info.staId,
3969 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303970
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003971 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003972 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303973 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003975 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976 hdd_ctx->config->OperatingChannel;
3977
3978 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003979 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980
3981 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303982 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003983 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984 status, status);
3985 goto error_init_txrx;
3986 }
3987
3988 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3989
3990 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303991 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003992 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993 status, status);
3994 goto error_wmm_init;
3995 }
3996
3997 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3998
Jeff Johnson1b780e42017-10-31 14:11:45 -07003999 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 WMI_PDEV_PARAM_BURST_ENABLE,
4001 hdd_ctx->config->enableSifsBurst,
4002 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004003 if (ret_val)
4004 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304006 /*
4007 * In case of USB tethering, LRO is disabled. If SSR happened
4008 * during that time, then as part of SSR init, do not enable
4009 * the LRO again. Keep the LRO state same as before SSR.
4010 */
4011 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004012 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304013
4014 /* rcpi info initialization */
4015 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4016
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304017 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019error_wmm_init:
4020 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4021 hdd_deinit_tx_rx(adapter);
4022error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004023 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004024 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004026 return status;
4027}
4028
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304029/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004030 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304031 * @hdd_ctx: global hdd context
4032 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004033 * @rtnl_held: Used to indicate whether or not the caller is holding
4034 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304035 *
4036 * This function De-initializes the STA/P2P/OCB adapter.
4037 *
4038 * Return: None.
4039 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004040static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004041 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004042 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304043{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004044 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304045
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304046 if (adapter->dev) {
4047 if (rtnl_held)
4048 adapter->dev->wireless_handlers = NULL;
4049 else {
4050 rtnl_lock();
4051 adapter->dev->wireless_handlers = NULL;
4052 rtnl_unlock();
4053 }
4054 }
4055
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304056 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4057 hdd_deinit_tx_rx(adapter);
4058 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4059 }
4060
4061 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4062 hdd_wmm_adapter_close(adapter);
4063 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4064 }
4065
Krunal Sonib51eec72017-11-20 21:53:01 -08004066
Dustin Browne74003f2018-03-14 12:51:58 -07004067 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304068}
4069
Krunal Sonib51eec72017-11-20 21:53:01 -08004070void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4071 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004072 bool rtnl_held)
4073{
Dustin Brown491d54b2018-03-14 12:39:11 -07004074 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304075
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004077 case QDF_STA_MODE:
4078 case QDF_P2P_CLIENT_MODE:
4079 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004080 case QDF_IBSS_MODE:
4081 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004082 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004083 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004084 break;
4085 }
4086
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004087 case QDF_SAP_MODE:
4088 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004089 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004090 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004091 break;
4092 }
4093
4094 default:
4095 break;
4096 }
4097
Dustin Browne74003f2018-03-14 12:51:58 -07004098 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004099}
4100
Jeff Johnson9d295242017-08-29 14:39:48 -07004101static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004102 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004103{
Jeff Johnson5505db82017-11-02 21:19:23 -07004104 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105
4106 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004107 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004108 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004109 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110 return;
4111 }
4112
Alok Kumarb64650c2018-03-23 17:05:11 +05304113 hdd_nud_deinit_tracking(adapter);
4114 qdf_mutex_destroy(&adapter->disconnection_status_lock);
4115
Rajeev Kumardca5f812016-02-04 17:28:06 -08004116 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304117
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004118 /*
4119 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4120 * the driver is almost closed and cannot handle either control
4121 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004122 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4123 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004124 * is not right. Setting this flag helps hdd_stop() to recognize that
4125 * the interface is closed and restricts any operations on that
4126 */
4127 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4128
4129 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004130 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004131 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004132 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004133 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134 /*
4135 * Note that the adapter is no longer valid at this point
4136 * since the memory has been reclaimed
4137 */
4138 }
4139}
4140
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004141static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004142 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004143{
Jeff Johnson9d295242017-08-29 14:39:48 -07004144 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004145
Dustin Brown920397d2017-12-13 16:27:50 -08004146 hdd_for_each_adapter(hdd_ctx, adapter) {
4147 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4148 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304149 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004151 }
Dustin Brown920397d2017-12-13 16:27:50 -08004152
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304153 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004154}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004155
Arun Khandavalli2358d522016-05-16 18:05:37 +05304156#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4157/**
4158 * hdd_set_fw_log_params() - Set log parameters to FW
4159 * @hdd_ctx: HDD Context
4160 * @adapter: HDD Adapter
4161 *
4162 * This function set the FW Debug log level based on the INI.
4163 *
4164 * Return: None
4165 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004166static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004167 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304168{
4169 uint8_t count = 0, numentries = 0,
4170 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4171 uint32_t value = 0;
4172 int ret;
4173
Arun Khandavallifae92942016-08-01 13:31:08 +05304174 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4175 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004176 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304177 return;
4178 }
4179
Arun Khandavallifae92942016-08-01 13:31:08 +05304180 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304181 hdd_ctx->fw_log_settings.dl_type =
4182 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004183 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304184 WMI_DBGLOG_TYPE,
4185 hdd_ctx->config->enableFwLogType,
4186 DBG_CMD);
4187 if (ret != 0)
4188 hdd_err("Failed to enable FW log type ret %d",
4189 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304190
4191 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304192 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004193 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304194 WMI_DBGLOG_LOG_LEVEL,
4195 hdd_ctx->config->enableFwLogLevel,
4196 DBG_CMD);
4197 if (ret != 0)
4198 hdd_err("Failed to enable FW log level ret %d",
4199 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304200
4201 hdd_string_to_u8_array(
4202 hdd_ctx->config->enableFwModuleLogLevel,
4203 moduleloglevel,
4204 &numentries,
4205 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4206
4207 while (count < numentries) {
4208 /*
4209 * FW module log level input string looks like
4210 * below:
4211 * gFwDebugModuleLoglevel=<FW Module ID>,
4212 * <Log Level>,...
4213 * For example:
4214 * gFwDebugModuleLoglevel=
4215 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4216 * Above input string means :
4217 * For FW module ID 1 enable log level 0
4218 * For FW module ID 2 enable log level 1
4219 * For FW module ID 3 enable log level 2
4220 * For FW module ID 4 enable log level 3
4221 * For FW module ID 5 enable log level 4
4222 * For FW module ID 6 enable log level 5
4223 * For FW module ID 7 enable log level 6
4224 */
4225
Nishank Aggarwale239d962017-03-03 12:26:02 +05304226 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4227 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4228 hdd_err("Module id %d and dbglog level %d input length is more than max",
4229 moduleloglevel[count],
4230 moduleloglevel[count + 1]);
4231 return;
4232 }
4233
4234 value = moduleloglevel[count] << 16;
4235 value |= moduleloglevel[count + 1];
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_MOD_LOG_LEVEL,
4238 value, DBG_CMD);
4239 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304240 hdd_err("Failed to enable FW module log level %d ret %d",
4241 value, ret);
4242
4243 count += 2;
4244 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304245
Arun Khandavalli2358d522016-05-16 18:05:37 +05304246}
4247#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004248static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004249 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304250{
4251}
4252
4253#endif
4254
4255/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004256 * hdd_configure_chain_mask() - programs chain mask to firmware
4257 * @adapter: HDD adapter
4258 *
4259 * Return: 0 on success or errno on failure
4260 */
4261static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4262{
4263 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004264 QDF_STATUS status;
4265 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004266 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4267
4268 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4269 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4270 hdd_ctx->config->txchainmask1x1,
4271 hdd_ctx->config->rxchainmask1x1);
4272 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4273 hdd_ctx->config->dual_mac_feature_disable,
4274 hdd_ctx->config->tx_chain_mask_2g,
4275 hdd_ctx->config->rx_chain_mask_2g);
4276 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4277 hdd_ctx->config->tx_chain_mask_5g,
4278 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004279 hdd_debug("enable_bt_chain_separation %d",
4280 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004281
Naveen Rawat98322472018-03-06 10:29:42 -08004282 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4283 HW_MODE_DBS_NONE,
4284 CDS_BAND_ALL);
4285 if (QDF_IS_STATUS_ERROR(status)) {
4286 hdd_err("couldn't get phy caps. skip chain mask programming");
4287 return qdf_status_to_os_return(status);
4288 }
4289
4290 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4291 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4292 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4293 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
4294 hdd_info("firmware not capable. skip chain mask programming");
4295 return 0;
4296 }
4297
Liangwei Dong22810e82018-03-15 03:42:12 -04004298 if (hdd_ctx->config->enable2x2 &&
4299 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004300 hdd_info("2x2 enabled. skip chain mask programming");
4301 return 0;
4302 }
4303
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004304 if (hdd_ctx->config->dual_mac_feature_disable !=
4305 DISABLE_DBS_CXN_AND_SCAN) {
4306 hdd_info("DBS enabled(%d). skip chain mask programming",
4307 hdd_ctx->config->dual_mac_feature_disable);
4308 return 0;
4309 }
4310
Naveen Rawatdacb5032018-02-08 15:23:24 -08004311 if (hdd_ctx->lte_coex_ant_share) {
4312 hdd_info("lte ant sharing enabled. skip chainmask programming");
4313 return 0;
4314 }
4315
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004316 if (hdd_ctx->config->txchainmask1x1) {
4317 ret_val = sme_cli_set_command(adapter->session_id,
4318 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4319 hdd_ctx->config->txchainmask1x1,
4320 PDEV_CMD);
4321 if (ret_val)
4322 goto error;
4323 }
4324
4325 if (hdd_ctx->config->rxchainmask1x1) {
4326 ret_val = sme_cli_set_command(adapter->session_id,
4327 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4328 hdd_ctx->config->rxchainmask1x1,
4329 PDEV_CMD);
4330 if (ret_val)
4331 goto error;
4332 }
4333
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004334 if (hdd_ctx->config->txchainmask1x1 ||
4335 hdd_ctx->config->rxchainmask1x1) {
4336 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4337 return 0;
4338 }
4339
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004340 if (hdd_ctx->config->tx_chain_mask_2g) {
4341 ret_val = sme_cli_set_command(adapter->session_id,
4342 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4343 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4344 if (0 != ret_val)
4345 goto error;
4346 }
4347
4348 if (hdd_ctx->config->rx_chain_mask_2g) {
4349 ret_val = sme_cli_set_command(adapter->session_id,
4350 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4351 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4352 if (0 != ret_val)
4353 goto error;
4354 }
4355
4356 if (hdd_ctx->config->tx_chain_mask_5g) {
4357 ret_val = sme_cli_set_command(adapter->session_id,
4358 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4359 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4360 if (0 != ret_val)
4361 goto error;
4362 }
4363
4364 if (hdd_ctx->config->rx_chain_mask_5g) {
4365 ret_val = sme_cli_set_command(adapter->session_id,
4366 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4367 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4368 if (0 != ret_val)
4369 goto error;
4370 }
4371
4372 return 0;
4373
4374error:
4375 hdd_err("WMI PDEV set param failed %d", ret_val);
4376 return -EINVAL;
4377}
4378
4379/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304380 * hdd_set_fw_params() - Set parameters to firmware
4381 * @adapter: HDD adapter
4382 *
4383 * This function Sets various parameters to fw once the
4384 * adapter is started.
4385 *
4386 * Return: 0 on success or errno on failure
4387 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004388int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304389{
4390 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004391 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304392
Dustin Brownfdf17c12018-03-14 12:55:34 -07004393 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304394
4395 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4396 if (!hdd_ctx)
4397 return -EINVAL;
4398
Dustin Brown732ab9c2017-06-15 13:24:09 -07004399 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4400 hdd_debug("FTM Mode is active; nothing to do");
4401 return 0;
4402 }
4403
Jeff Johnson1b780e42017-10-31 14:11:45 -07004404 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304405 WMI_PDEV_PARAM_DTIM_SYNTH,
4406 hdd_ctx->config->enable_lprx, PDEV_CMD);
4407 if (ret) {
4408 hdd_err("Failed to set LPRx");
4409 goto error;
4410 }
4411
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304412
4413 ret = sme_cli_set_command(
4414 adapter->session_id,
4415 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4416 hdd_ctx->config->enable_dtim_selection_diversity,
4417 PDEV_CMD);
4418 if (ret) {
4419 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4420 goto error;
4421 }
4422
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304423 ret = sme_cli_set_command(
4424 adapter->session_id,
4425 WMI_PDEV_PARAM_TX_SCH_DELAY,
4426 hdd_ctx->config->enable_tx_sch_delay,
4427 PDEV_CMD);
4428 if (ret) {
4429 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4430 goto error;
4431 }
4432
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304433 ret = sme_cli_set_command(
4434 adapter->session_id,
4435 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4436 hdd_ctx->config->enable_secondary_rate,
4437 PDEV_CMD);
4438 if (ret) {
4439 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4440 goto error;
4441 }
4442
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304443 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004444 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304445 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4446 hdd_ctx->config->upper_brssi_thresh);
4447
Jeff Johnson1b780e42017-10-31 14:11:45 -07004448 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304449 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4450 hdd_ctx->config->lower_brssi_thresh);
4451
Jeff Johnson1b780e42017-10-31 14:11:45 -07004452 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304453 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4454 hdd_ctx->config->enable_dtim_1chrx);
4455 }
4456
Dustin Brown732ab9c2017-06-15 13:24:09 -07004457 if (hdd_ctx->config->enable2x2) {
4458 hdd_debug("configuring 2x2 mode fw params");
4459
Jeff Johnson1b780e42017-10-31 14:11:45 -07004460 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004461 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4462 hdd_ctx->config->enable_cck_tx_fir_override,
4463 PDEV_CMD);
4464 if (ret) {
4465 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4466 ret);
4467 goto error;
4468 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004469
4470 if (hdd_configure_chain_mask(adapter))
4471 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004472 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304473#define HDD_DTIM_1CHAIN_RX_ID 0x5
4474#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004475 hdd_debug("configuring 1x1 mode fw params");
4476
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004477 /*
4478 * Disable DTIM 1 chain Rx when in 1x1,
4479 * we are passing two value
4480 * as param_id << 29 | param_value.
4481 * Below param_value = 0(disable)
4482 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004483 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004484 WMI_STA_SMPS_PARAM_CMDID,
4485 HDD_DTIM_1CHAIN_RX_ID <<
4486 HDD_SMPS_PARAM_VALUE_S,
4487 VDEV_CMD);
4488 if (ret) {
4489 hdd_err("DTIM 1 chain set failed %d", ret);
4490 goto error;
4491 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304492
Arun Khandavalli2358d522016-05-16 18:05:37 +05304493#undef HDD_DTIM_1CHAIN_RX_ID
4494#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004495
4496 if (hdd_configure_chain_mask(adapter))
4497 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004498 }
4499
Jeff Johnson1b780e42017-10-31 14:11:45 -07004500 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004501 WMI_PDEV_PARAM_HYST_EN,
4502 hdd_ctx->config->enableMemDeepSleep,
4503 PDEV_CMD);
4504 if (ret) {
4505 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4506 goto error;
4507 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304508
Jeff Johnson1b780e42017-10-31 14:11:45 -07004509 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004510 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4511 hdd_ctx->config->rts_profile,
4512 VDEV_CMD);
4513 if (ret) {
4514 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4515 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304516 }
4517
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004518 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4519
Jeff Johnson1b780e42017-10-31 14:11:45 -07004520 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004521 GEN_VDEV_PARAM_AMSDU,
4522 hdd_ctx->config->max_amsdu_num,
4523 GEN_CMD);
4524 if (ret != 0) {
4525 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4526 goto error;
4527 }
4528
Arun Khandavalli2358d522016-05-16 18:05:37 +05304529 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004530 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004531
Arun Khandavalli2358d522016-05-16 18:05:37 +05304532 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304533
Arun Khandavalli2358d522016-05-16 18:05:37 +05304534error:
4535 return -EINVAL;
4536}
4537
Ryan Hsu07495ea2016-01-21 15:25:39 -08004538/**
4539 * hdd_open_adapter() - open and setup the hdd adatper
4540 * @hdd_ctx: global hdd context
4541 * @session_type: type of the interface to be created
4542 * @iface_name: User-visible name of the interface
4543 * @macAddr: MAC address to assign to the interface
4544 * @name_assign_type: the name of assign type of the netdev
4545 * @rtnl_held: the rtnl lock hold flag
4546 *
4547 * This function open and setup the hdd adpater according to the device
4548 * type request, assign the name, the mac address assigned, and then prepared
4549 * the hdd related parameters, queue, lock and ready to start.
4550 *
4551 * Return: the pointer of hdd adapter, otherwise NULL.
4552 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004553struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004554 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004555 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004556 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004557{
Jeff Johnson9d295242017-08-29 14:39:48 -07004558 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304559 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004560
4561 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4562 /*
4563 * Max limit reached on the number of vdevs configured by the
4564 * host. Return error
4565 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304566 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4567 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568 return NULL;
4569 }
4570
4571 if (macAddr == NULL) {
4572 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304573 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574 return NULL;
4575 }
4576 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304577 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304578 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4579 " already exists",
4580 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004581 return NULL;
4582 }
4583
4584 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004585 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004586 /* Reset locally administered bit if the device mode is STA */
4587 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304588 hdd_info("locally administered bit reset in sta mode: "
4589 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004590 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004591 case QDF_P2P_CLIENT_MODE:
4592 case QDF_P2P_DEVICE_MODE:
4593 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004594 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304595 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004596 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4597 name_assign_type,
4598 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004599
4600 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304601 hdd_err("failed to allocate adapter for session %d",
4602 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004603 return NULL;
4604 }
4605
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004606 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004607 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004608 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004609 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304610 else if (QDF_MONITOR_MODE == session_type)
4611 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004612 else
4613 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4614
4615 adapter->device_mode = session_type;
4616
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004617
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618 /*
4619 * Workqueue which gets scheduled in IPv4 notification
4620 * callback
4621 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004622 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004623 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624
4625#ifdef WLAN_NS_OFFLOAD
4626 /*
4627 * Workqueue which gets scheduled in IPv6
4628 * notification callback.
4629 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004630 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004631 hdd_ipv6_notifier_work_queue);
4632#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004633 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004634 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004635 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004636
4637 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004638 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004639 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304640 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4641 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304642
Ravi Joshi1a292562017-05-18 16:28:54 -07004643 /* Initialize NAN Data Interface */
4644 if (QDF_NDI_MODE == session_type) {
4645 status = hdd_init_nan_data_mode(adapter);
4646 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004647 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004648 }
4649
Alok Kumarb64650c2018-03-23 17:05:11 +05304650 hdd_nud_init_tracking(adapter);
4651
4652 qdf_mutex_create(&adapter->disconnection_status_lock);
4653
Ravi Joshi1a292562017-05-18 16:28:54 -07004654 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004656 case QDF_P2P_GO_MODE:
4657 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004658 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4659 name_assign_type,
4660 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004661 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004662 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304663 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004664 return NULL;
4665 }
4666
4667 adapter->wdev.iftype =
4668 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004669 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004670 NL80211_IFTYPE_P2P_GO;
4671 adapter->device_mode = session_type;
4672
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004673 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004674 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004675 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004676
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004677 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004678 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304679 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4680 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304681
4682 /*
4683 * Workqueue which gets scheduled in IPv4 notification
4684 * callback
4685 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004686 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304687 hdd_ipv4_notifier_work_queue);
4688
4689#ifdef WLAN_NS_OFFLOAD
4690 /*
4691 * Workqueue which gets scheduled in IPv6
4692 * notification callback.
4693 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004694 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304695 hdd_ipv6_notifier_work_queue);
4696#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004697 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304698 case QDF_FTM_MODE:
4699 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4700 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004701 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304702 if (NULL == adapter) {
4703 hdd_err("Failed to allocate adapter for FTM mode");
4704 return NULL;
4705 }
4706 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4707 adapter->device_mode = session_type;
4708 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004709 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004710 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004711
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304712 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004713 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304714 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304715 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4716 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304717 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004718 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004719 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304720 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004721 return NULL;
4722 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004723
hqueaa33ee2017-05-04 17:56:35 +08004724 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4725
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304726 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004727 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004728 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729 }
4730
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304731 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004732 if (NULL != adapter) {
4733 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4734 adapter = NULL;
4735 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004736
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004737 return NULL;
4738 }
4739
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304740 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004741 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4742 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744 /* Adapter successfully added. Increment the vdev count */
4745 hdd_ctx->current_intf_count++;
4746
Jeff Johnson5880d792016-08-15 13:32:30 -07004747 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004748 hdd_ctx->current_intf_count);
4749
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004750 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004751 }
4752
Rajeev Kumardca5f812016-02-04 17:28:06 -08004753 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004754 hdd_err("Interface %s wow debug_fs init failed",
4755 netdev_name(adapter->dev));
4756
4757 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4758 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004759
4760 return adapter;
4761
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004762err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004763 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304764 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004765
4766 return NULL;
4767}
4768
Nirav Shaheb017be2018-02-15 11:20:58 +05304769#ifdef MSM_PLATFORM
4770static inline
4771void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4772{
4773 cancel_work_sync(&hdd_ctx->bus_bw_work);
4774}
4775#else
4776static inline
4777void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4778{
4779}
4780#endif
4781
Jeff Johnson9d295242017-08-29 14:39:48 -07004782QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004783 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004784{
Dustin Brown920397d2017-12-13 16:27:50 -08004785 /*
4786 * Here we are stopping global bus_bw timer & work per adapter.
4787 *
4788 * The reason is to fix one race condition between
4789 * bus bandwidth work and cleaning up an adapter.
4790 * Under some conditions, it is possible for the bus bandwidth
4791 * work to access a particularly destroyed adapter, leading to
4792 * use-after-free.
4793 */
4794 hdd_debug("wait for bus bw work to flush");
4795 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4796 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004797
Dustin Brown920397d2017-12-13 16:27:50 -08004798 /* cleanup adapter */
4799 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4800 adapter->device_mode);
4801 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4802 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004803
Dustin Brown920397d2017-12-13 16:27:50 -08004804 /* conditionally restart the bw timer */
4805 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004806
Dustin Brown920397d2017-12-13 16:27:50 -08004807 /* Adapter removed. Decrement vdev count */
4808 if (hdd_ctx->current_intf_count != 0)
4809 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004810
Dustin Brown920397d2017-12-13 16:27:50 -08004811 /* Fw will take care incase of concurrency */
4812 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004813}
4814
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004815/**
4816 * hdd_close_all_adapters - Close all open adapters
4817 * @hdd_ctx: Hdd context
4818 * rtnl_held: True if RTNL lock held
4819 *
4820 * Close all open adapters.
4821 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304822 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004823 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004824QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004825{
Dustin Brown920397d2017-12-13 16:27:50 -08004826 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304827 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004828
Dustin Brown491d54b2018-03-14 12:39:11 -07004829 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004830
4831 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004832 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4833 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304834 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004835 adapter->mac_addr.bytes);
4836 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4837
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304838 /* Adapter removed. Decrement vdev count */
4839 if (hdd_ctx->current_intf_count != 0)
4840 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004841 }
Dustin Brown920397d2017-12-13 16:27:50 -08004842 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004843
Dustin Browne74003f2018-03-14 12:51:58 -07004844 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004845
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304846 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004847}
4848
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004849void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304851 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004852 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004853
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004854 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004855 case QDF_STA_MODE:
4856 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004858 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004859 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004860 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004861 break;
4862 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004863 case QDF_SAP_MODE:
4864 case QDF_P2P_GO_MODE:
4865 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004866 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004867 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 break;
4869 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004870 case QDF_FTM_MODE:
4871 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004872 default:
4873 /*
4874 * wlan_hdd_reset_prob_rspies should not have been called
4875 * for these kind of devices
4876 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004877 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004878 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004879 return;
4880 }
4881
Anurag Chouhanc5548422016-02-24 18:33:27 +05304882 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004883 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004884 updateIE.ieBufferlength = 0;
4885 updateIE.pAdditionIEBuffer = NULL;
4886 updateIE.append = true;
4887 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004888 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304890 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004891 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004892 }
4893}
4894
Dustin Browndb2a8be2017-12-20 11:49:56 -08004895QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4896 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004897{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304898 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07004899 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900 union iwreq_data wrqu;
4901 tSirUpdateIE updateIE;
4902 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07004903 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004904
Dustin Brown491d54b2018-03-14 12:39:11 -07004905 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004906
Alok Kumarb64650c2018-03-23 17:05:11 +05304907 hdd_nud_ignore_tracking(adapter, true);
4908 hdd_nud_reset_tracking(adapter);
4909
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004910 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304911 wlan_hdd_netif_queue_control(adapter,
4912 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4913 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004914 /*
4915 * if this is the last active connection check & stop the
4916 * opportunistic timer first
4917 */
4918 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4919 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4920 policy_mgr_convert_device_mode_to_qdf_type(
4921 adapter->device_mode), NULL) == 1)) ||
4922 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4923 policy_mgr_check_and_stop_opportunistic_timer(
4924 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004925 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004926 case QDF_STA_MODE:
4927 case QDF_P2P_CLIENT_MODE:
4928 case QDF_IBSS_MODE:
4929 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004930 case QDF_NDI_MODE:
4931 if ((QDF_NDI_MODE == adapter->device_mode) ||
4932 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004933 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4934 hdd_is_connecting(
4935 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004936 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07004937 roam_profile = hdd_roam_profile(adapter);
4938 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004939 if (QDF_NDI_MODE == adapter->device_mode)
4940 qdf_ret_status = sme_roam_disconnect(
4941 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004942 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004943 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07004944 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004945 eCSR_BSS_TYPE_START_IBSS)
4946 qdf_ret_status = sme_roam_disconnect(
4947 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004948 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004949 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004950 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004951 qdf_ret_status =
4952 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004953 hdd_debug("Send disconnected event to userspace");
4954 wlan_hdd_cfg80211_indicate_disconnect(
4955 adapter->dev, true,
4956 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08004957 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004958 qdf_ret_status = sme_roam_disconnect(
4959 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004960 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004961 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004962 /* success implies disconnect command got
4963 * queued up successfully
4964 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004965 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4966 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004967 rc = wait_for_completion_timeout(
4968 &adapter->disconnect_comp_var,
4969 msecs_to_jiffies
4970 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004971 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004972 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004973 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004974 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4975 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004976 memset(&wrqu, '\0', sizeof(wrqu));
4977 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4978 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4979 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4980 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304981 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004982 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004983
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304984 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304985 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004986
4987#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004988 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004989#endif
4990
4991 hdd_deregister_tx_flow_control(adapter);
4992
4993#ifdef WLAN_NS_OFFLOAD
4994#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004995 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004996#endif
4997#endif
4998
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304999 if (adapter->device_mode == QDF_STA_MODE)
5000 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5001 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005002
5003 if (wlan_hdd_try_disconnect(adapter)) {
5004 hdd_err("Error: Can't disconnect adapter");
5005 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005006 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005007
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305008 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005009 break;
5010
Rajeev Kumar3b906202018-02-01 10:55:14 -08005011 case QDF_MONITOR_MODE:
5012 wlan_hdd_scan_abort(adapter);
5013 hdd_deregister_tx_flow_control(adapter);
5014 hdd_vdev_destroy(adapter);
5015 break;
5016
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005017 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08005018 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305019 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305020 sap_config = &adapter->session.ap.sap_config;
5021 if (sap_config)
5022 wlansap_reset_sap_config_add_ie(sap_config,
5023 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305024 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08005025 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005026 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005027
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005028 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07005029 if (QDF_SAP_MODE == adapter->device_mode) {
5030 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5031 cds_flush_delayed_work(
5032 &adapter->acs_pending_work);
5033 clear_bit(ACS_PENDING, &adapter->event_flags);
5034 }
5035 }
Krunal Soni22208392017-09-29 18:10:34 -07005036 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005037
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305039 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005040 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005041 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5043
5044 hdd_deregister_tx_flow_control(adapter);
5045
Kapil Guptac1224bf2017-06-22 21:22:40 +05305046 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005047 mutex_lock(&hdd_ctx->sap_lock);
5048 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305049 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305050 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005051
5052 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005053 status = wlansap_stop_bss(
5054 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005055
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305056 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005057 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005058 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305059 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305060 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305061 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305062 qdf_wait_for_event_completion(
5063 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005064 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005065
Anurag Chouhance0dc992016-02-16 18:18:03 +05305066 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005067 hdd_err("failure waiting for wlansap_stop_bss %d",
5068 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069 }
5070 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005071 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005072 }
5073 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005074 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5075 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005076 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005077 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305078 adapter->device_mode,
5079 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005080
Anurag Chouhanc5548422016-02-24 18:33:27 +05305081 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005082 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005083 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084 updateIE.ieBufferlength = 0;
5085 updateIE.pAdditionIEBuffer = NULL;
5086 updateIE.append = false;
5087 updateIE.notify = false;
5088 /* Probe bcn reset */
5089 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5090 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305091 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005092 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 }
5094 /* Assoc resp reset */
5095 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5096 &updateIE,
5097 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305098 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005099 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005100 }
5101 /* Reset WNI_CFG_PROBE_RSP Flags */
5102 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005103 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07005104 qdf_mem_free(adapter->session.ap.beacon);
5105 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305106 /*
5107 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5108 */
5109 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5110 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5111
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305112#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005113 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305114#endif
5115
5116#ifdef WLAN_NS_OFFLOAD
5117#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005118 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305119#endif
5120#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005121
5122 hdd_vdev_destroy(adapter);
5123
Krunal Sonib51eec72017-11-20 21:53:01 -08005124 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005125 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005126 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005127 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005128 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005129 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005130 hdd_deregister_tx_flow_control(adapter);
5131 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132 break;
5133 default:
5134 break;
5135 }
5136
Dustin Brown04348372017-12-14 16:13:39 -08005137 if (adapter->scan_info.default_scan_ies) {
5138 qdf_mem_free(adapter->scan_info.default_scan_ies);
5139 adapter->scan_info.default_scan_ies = NULL;
5140 }
5141
Dustin Browne74003f2018-03-14 12:51:58 -07005142 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005143
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305144 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005145}
5146
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305147/**
5148 * hdd_deinit_all_adapters - deinit all adapters
5149 * @hdd_ctx: HDD context
5150 * @rtnl_held: True if RTNL lock held
5151 *
5152 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005153void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305154{
Jeff Johnson9d295242017-08-29 14:39:48 -07005155 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305156
Dustin Brown491d54b2018-03-14 12:39:11 -07005157 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305158
Dustin Brown920397d2017-12-13 16:27:50 -08005159 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305160 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305161
Dustin Browne74003f2018-03-14 12:51:58 -07005162 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305163}
5164
Dustin Browndb2a8be2017-12-20 11:49:56 -08005165QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005166{
Jeff Johnson9d295242017-08-29 14:39:48 -07005167 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005168
Dustin Brown491d54b2018-03-14 12:39:11 -07005169 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305171 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5172
Dustin Brown920397d2017-12-13 16:27:50 -08005173 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005174 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005175
Dustin Browne74003f2018-03-14 12:51:58 -07005176 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005177
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305178 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005179}
5180
Paul Zhang84fa9382017-11-10 21:18:21 +08005181static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5182 struct hdd_adapter *adapter)
5183{
5184 switch (adapter->device_mode) {
5185 case QDF_STA_MODE:
5186 case QDF_P2P_CLIENT_MODE:
5187 case QDF_IBSS_MODE:
5188 case QDF_P2P_DEVICE_MODE:
5189 case QDF_NDI_MODE:
5190 wlan_hdd_scan_abort(adapter);
5191 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5192 if (adapter->device_mode == QDF_STA_MODE)
5193 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5194 adapter->dev);
5195 break;
5196 case QDF_P2P_GO_MODE:
5197 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5198 break;
5199 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305200 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005201 wlan_hdd_undo_acs(adapter);
5202 break;
5203 default:
5204 break;
5205 }
5206}
5207
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005208QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209{
Jeff Johnson9d295242017-08-29 14:39:48 -07005210 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005211 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005212 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005213 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214
Dustin Brown491d54b2018-03-14 12:39:11 -07005215 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305217 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5218
Dustin Brown920397d2017-12-13 16:27:50 -08005219 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005220 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5221 hdd_device_mode_to_string(adapter->device_mode),
5222 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305223
5224 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005225 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305226 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005227 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005228 adapter->session.station.hdd_reassoc_scenario = false;
5229 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305230
Arun Khandavallicc544b32017-01-30 19:52:16 +05305231 if (hdd_ctx->config->sap_internal_restart &&
5232 adapter->device_mode == QDF_SAP_MODE) {
5233 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305234 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305235 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005236 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005237 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005238 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005239 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5240 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305241 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305242 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005243 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005244 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005245
Paul Zhang84fa9382017-11-10 21:18:21 +08005246 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005247
5248 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005249 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005250 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005251 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305252 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5254 hdd_wmm_adapter_close(adapter);
5255 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5256 }
5257
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305258 if (adapter->device_mode == QDF_STA_MODE)
5259 hdd_clear_fils_connection_info(adapter);
5260
Wu Gao3545e642017-07-14 19:24:41 +08005261 if (adapter->device_mode == QDF_SAP_MODE) {
5262 /*
5263 * If adapter is SAP, set session ID to invalid
5264 * since SAP session will be cleanup during SSR.
5265 */
Wu Gao36717432016-11-21 15:09:48 +08005266 wlansap_set_invalid_session(
5267 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5268
Wu Gao3545e642017-07-14 19:24:41 +08005269 wlansap_cleanup_cac_timer(
5270 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5271 }
5272
Yue Ma42654682018-01-11 16:55:24 -08005273 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005274 if (adapter->device_mode == QDF_STA_MODE ||
5275 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005276 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005277 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005278 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005279
5280 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5281 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005282 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5283 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5284 if (adapter->sta_info[sta_id].in_use) {
5285 hdd_debug("[SSR] deregister STA with ID %d",
5286 sta_id);
5287 hdd_softap_deregister_sta(adapter,
5288 sta_id);
5289 adapter->sta_info[sta_id].in_use = 0;
5290 }
5291 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005292 }
5293
Alok Kumarb64650c2018-03-23 17:05:11 +05305294 hdd_nud_reset_tracking(adapter);
5295 hdd_nud_ignore_tracking(adapter, true);
5296 hdd_set_disconnect_status(adapter, false);
5297
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005298 hdd_softap_deinit_tx_rx(adapter);
5299
Yue Maf9782842017-05-08 12:49:49 -07005300 /* Destroy vdev which will be recreated during reinit. */
5301 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005302 }
5303
Dustin Browne74003f2018-03-14 12:51:58 -07005304 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305306 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307}
5308
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005309bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305310{
Dustin Brown920397d2017-12-13 16:27:50 -08005311 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305312 bool close_modules = true;
5313
Arun Khandavalliba479c42017-07-26 21:29:40 +05305314 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5315 hdd_info("FTM mode, don't close the module");
5316 return false;
5317 }
5318
Dustin Brown920397d2017-12-13 16:27:50 -08005319 hdd_for_each_adapter(hdd_ctx, adapter) {
5320 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5321 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005322 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305323 close_modules = false;
5324 break;
5325 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305326 }
5327
5328 return close_modules;
5329}
5330
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305331bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305332{
5333 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5334 return true;
5335 else
5336 return false;
5337}
5338
Anurag Chouhanc4092922016-09-08 15:56:11 +05305339#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005340 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305341struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5342 struct ieee80211_channel *channel,
5343 const u8 *bssid, const u8 *ssid,
5344 size_t ssid_len)
5345{
5346 return cfg80211_get_bss(wiphy, channel, bssid,
5347 ssid, ssid_len,
5348 WLAN_CAPABILITY_ESS,
5349 WLAN_CAPABILITY_ESS);
5350}
5351#else
5352struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5353 struct ieee80211_channel *channel,
5354 const u8 *bssid, const u8 *ssid,
5355 size_t ssid_len)
5356{
5357 return cfg80211_get_bss(wiphy, channel, bssid,
5358 ssid, ssid_len,
5359 IEEE80211_BSS_TYPE_ESS,
5360 IEEE80211_PRIVACY_ANY);
5361}
5362#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305363
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305364#if defined CFG80211_CONNECT_BSS || \
5365 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305366#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305367 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305368/**
5369 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5370 * @timeout_reason: reason for connect timeout
5371 *
5372 * This function is used to convert host timeout
5373 * reason enum to kernel specific enum.
5374 *
5375 * Return: nl timeout enum
5376 */
5377static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5378 tSirResultCodes timeout_reason)
5379{
5380 switch (timeout_reason) {
5381 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5382 return NL80211_TIMEOUT_SCAN;
5383 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5384 return NL80211_TIMEOUT_AUTH;
5385 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5386 return NL80211_TIMEOUT_ASSOC;
5387 default:
5388 return NL80211_TIMEOUT_UNSPECIFIED;
5389 }
5390}
5391
5392/**
5393 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5394 * @dev: network device
5395 * @bssid: bssid to which we want to associate
5396 * @timeout_reason: reason for connect timeout
5397 *
5398 * This API is used to send connection timeout reason to supplicant
5399 *
5400 * Return: void
5401 */
5402static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5403 const u8 *bssid,
5404 tSirResultCodes timeout_reason)
5405{
5406 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005407
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305408 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5409
5410 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5411 nl_timeout_reason);
5412}
5413
5414/**
5415 * __hdd_connect_bss() - API to send connection status to supplicant
5416 * @dev: network device
5417 * @bssid: bssid to which we want to associate
5418 * @req_ie: Request Information Element
5419 * @req_ie_len: len of the req IE
5420 * @resp_ie: Response IE
5421 * @resp_ie_len: len of ht response IE
5422 * @status: status
5423 * @gfp: Kernel Flag
5424 * @timeout_reason: reason for connect timeout
5425 *
5426 * Return: void
5427 */
5428static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5429 struct cfg80211_bss *bss, const u8 *req_ie,
5430 size_t req_ie_len, const u8 *resp_ie,
5431 size_t resp_ie_len, int status, gfp_t gfp,
5432 tSirResultCodes timeout_reason)
5433{
5434 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005435
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305436 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5437
5438 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5439 resp_ie, resp_ie_len, status, gfp,
5440 nl_timeout_reason);
5441}
5442#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305443#if defined CFG80211_CONNECT_TIMEOUT || \
5444 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305445static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5446 const u8 *bssid,
5447 tSirResultCodes timeout_reason)
5448{
5449 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5450}
5451#endif
5452
5453static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5454 struct cfg80211_bss *bss, const u8 *req_ie,
5455 size_t req_ie_len, const u8 *resp_ie,
5456 size_t resp_ie_len, int status, gfp_t gfp,
5457 tSirResultCodes timeout_reason)
5458{
5459 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5460 resp_ie, resp_ie_len, status, gfp);
5461}
5462#endif
5463
Abhishek Singha84d3952016-09-13 13:45:05 +05305464/**
5465 * hdd_connect_bss() - API to send connection status to supplicant
5466 * @dev: network device
5467 * @bssid: bssid to which we want to associate
5468 * @req_ie: Request Information Element
5469 * @req_ie_len: len of the req IE
5470 * @resp_ie: Response IE
5471 * @resp_ie_len: len of ht response IE
5472 * @status: status
5473 * @gfp: Kernel Flag
5474 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305475 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305476 *
5477 * The API is a wrapper to send connection status to supplicant
5478 *
5479 * Return: Void
5480 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305481#if defined CFG80211_CONNECT_TIMEOUT || \
5482 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305483static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5484 struct cfg80211_bss *bss, const u8 *req_ie,
5485 size_t req_ie_len, const u8 *resp_ie,
5486 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305487 bool connect_timeout,
5488 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305489{
5490 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305491 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305492 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305493 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5494 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305495}
5496#else
5497static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5498 struct cfg80211_bss *bss, const u8 *req_ie,
5499 size_t req_ie_len, const u8 *resp_ie,
5500 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305501 bool connect_timeout,
5502 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305503{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305504 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5505 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305506}
5507#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305508
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305509#if defined(WLAN_FEATURE_FILS_SK)
5510#if defined(CFG80211_CONNECT_DONE) || \
5511 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5512#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5513 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305514/**
5515 * hdd_populate_fils_params() - Populate FILS keys to connect response
5516 * @fils_params: connect response to supplicant
5517 * @fils_kek: FILS kek
5518 * @fils_kek_len: FILS kek length
5519 * @pmk: FILS PMK
5520 * @pmk_len: FILS PMK length
5521 * @pmkid: PMKID
5522 * @fils_seq_num: FILS Seq number
5523 *
5524 * Return: None
5525 */
5526static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5527 *fils_params, const uint8_t *fils_kek,
5528 size_t fils_kek_len, const uint8_t *pmk,
5529 size_t pmk_len, const uint8_t *pmkid,
5530 uint16_t fils_seq_num)
5531{
5532 /* Increament seq number to be used for next FILS */
5533 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5534 fils_params->update_erp_next_seq_num = true;
5535 fils_params->fils_kek = fils_kek;
5536 fils_params->fils_kek_len = fils_kek_len;
5537 fils_params->pmk = pmk;
5538 fils_params->pmk_len = pmk_len;
5539 fils_params->pmkid = pmkid;
5540}
5541#else
5542static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5543 *fils_params, const uint8_t
5544 *fils_kek, size_t fils_kek_len,
5545 const uint8_t *pmk, size_t pmk_len,
5546 const uint8_t *pmkid,
5547 uint16_t fils_seq_num)
5548{ }
5549#endif
5550
Jeff Johnson172237b2017-11-07 15:32:59 -08005551void hdd_update_hlp_info(struct net_device *dev,
5552 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305553{
5554 struct sk_buff *skb;
5555 uint16_t skb_len;
5556 struct llc_snap_hdr_t *llc_hdr;
5557 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305558 uint8_t *hlp_data;
5559 uint16_t hlp_data_len;
5560 struct fils_join_rsp_params *roam_fils_params
5561 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305562 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5563
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305564 if (!roam_fils_params) {
5565 hdd_err("FILS Roam Param NULL");
5566 return;
5567 }
5568
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005569 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305570 hdd_err("FILS HLP Data NULL, len %d",
5571 roam_fils_params->hlp_data_len);
5572 return;
5573 }
5574
5575 hlp_data = roam_fils_params->hlp_data;
5576 hlp_data_len = roam_fils_params->hlp_data_len;
5577
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305578 /* Calculate skb length */
5579 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5580 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5581 if (skb == NULL) {
5582 hdd_err("HLP packet nbuf alloc fails");
5583 return;
5584 }
5585
5586 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5587 QDF_MAC_ADDR_SIZE);
5588 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5589 QDF_MAC_ADDR_SIZE);
5590
5591 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5592 if (IS_SNAP(llc_hdr)) {
5593 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5594 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5595 }
5596
5597 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5598
5599 /*
5600 * This HLP packet is formed from HLP info encapsulated
5601 * in assoc response frame which is AEAD encrypted.
5602 * Hence, this checksum validation can be set unnecessary.
5603 * i.e. network layer need not worry about checksum.
5604 */
5605 skb->ip_summed = CHECKSUM_UNNECESSARY;
5606
5607 status = hdd_rx_packet_cbk(padapter, skb);
5608 if (QDF_IS_STATUS_ERROR(status)) {
5609 hdd_err("Sending HLP packet fails");
5610 return;
5611 }
5612 hdd_debug("send HLP packet to netif successfully");
5613}
5614
5615/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305616 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5617 * @dev: network device
5618 * @bssid: bssid to which we want to associate
5619 * @bss: cfg80211 bss info
5620 * @roam_info: information about connected bss
5621 * @req_ie: Request Information Element
5622 * @req_ie_len: len of the req IE
5623 * @resp_ie: Response IE
5624 * @resp_ie_len: len of ht response IE
5625 * @status: status
5626 * @gfp: allocation flags
5627 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5628 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305629 *
5630 * This API is used as wrapper to send FILS key/sequence number
5631 * params etc. to supplicant in case of FILS connection
5632 *
5633 * Return: None
5634 */
5635static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005636 struct cfg80211_bss *bss,
5637 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305638 const u8 *req_ie, size_t req_ie_len,
5639 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005640 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305641 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305642{
5643 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305644 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5645 struct fils_join_rsp_params *roam_fils_params =
5646 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005647
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305648 qdf_mem_zero(&fils_params, sizeof(fils_params));
5649
5650 if (!roam_fils_params) {
5651 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5652 } else {
5653 fils_params.status = status;
5654 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005655 fils_params.timeout_reason =
5656 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305657 fils_params.req_ie = req_ie;
5658 fils_params.req_ie_len = req_ie_len;
5659 fils_params.resp_ie = resp_ie;
5660 fils_params.resp_ie_len = resp_ie_len;
5661 fils_params.bss = bss;
5662 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5663 roam_fils_params->kek_len,
5664 roam_fils_params->fils_pmk,
5665 roam_fils_params->fils_pmk_len,
5666 roam_fils_params->fils_pmkid,
5667 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305668 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305669 }
5670 hdd_debug("FILS indicate connect status %d seq no %d",
5671 fils_params.status,
5672 fils_params.fils_erp_next_seq_num);
5673
5674 cfg80211_connect_done(dev, &fils_params, gfp);
5675
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305676 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305677 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305678
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305679 /* Clear all the FILS key info */
5680 if (roam_fils_params && roam_fils_params->fils_pmk)
5681 qdf_mem_free(roam_fils_params->fils_pmk);
5682 if (roam_fils_params)
5683 qdf_mem_free(roam_fils_params);
5684 roam_info->fils_join_rsp = NULL;
5685}
5686#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005687static inline void
5688hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005689 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005690 const u8 *req_ie, size_t req_ie_len,
5691 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5692 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305693 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305694{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305695#endif
5696#endif
5697
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305698#if defined(WLAN_FEATURE_FILS_SK) && \
5699 (defined(CFG80211_CONNECT_DONE) || \
5700 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305701/**
5702 * hdd_fils_update_connect_results() - API to send fils connection status to
5703 * supplicant.
5704 * @dev: network device
5705 * @bssid: bssid to which we want to associate
5706 * @bss: cfg80211 bss info
5707 * @roam_info: information about connected bss
5708 * @req_ie: Request Information Element
5709 * @req_ie_len: len of the req IE
5710 * @resp_ie: Response IE
5711 * @resp_ie_len: len of ht response IE
5712 * @status: status
5713 * @gfp: allocation flags
5714 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5715 * @timeout_reason: reason for connect timeout
5716 *
5717 * The API is a wrapper to send connection status to supplicant
5718 *
5719 * Return: 0 if success else failure
5720 */
5721static int hdd_fils_update_connect_results(struct net_device *dev,
5722 const u8 *bssid,
5723 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005724 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305725 size_t req_ie_len, const u8 *resp_ie,
5726 size_t resp_ie_len, u16 status, gfp_t gfp,
5727 bool connect_timeout,
5728 tSirResultCodes timeout_reason)
5729{
Dustin Brown491d54b2018-03-14 12:39:11 -07005730 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305731 if (!roam_info || !roam_info->is_fils_connection)
5732 return -EINVAL;
5733
5734 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5735 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305736 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305737 return 0;
5738}
5739#else
5740static inline int hdd_fils_update_connect_results(struct net_device *dev,
5741 const u8 *bssid,
5742 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005743 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305744 size_t req_ie_len, const u8 *resp_ie,
5745 size_t resp_ie_len, u16 status, gfp_t gfp,
5746 bool connect_timeout,
5747 tSirResultCodes timeout_reason)
5748{
5749 return -EINVAL;
5750}
5751#endif
5752
Anurag Chouhanc4092922016-09-08 15:56:11 +05305753/**
5754 * hdd_connect_result() - API to send connection status to supplicant
5755 * @dev: network device
5756 * @bssid: bssid to which we want to associate
5757 * @roam_info: information about connected bss
5758 * @req_ie: Request Information Element
5759 * @req_ie_len: len of the req IE
5760 * @resp_ie: Response IE
5761 * @resp_ie_len: len of ht response IE
5762 * @status: status
5763 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305764 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305765 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305766 *
5767 * The API is a wrapper to send connection status to supplicant
5768 * and allow runtime suspend
5769 *
5770 * Return: Void
5771 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305772void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005773 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305774 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305775 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305776 bool connect_timeout,
5777 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305778{
Jeff Johnson9d295242017-08-29 14:39:48 -07005779 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305780 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005781 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305782
5783 if (WLAN_STATUS_SUCCESS == status) {
5784 struct ieee80211_channel *chan;
5785 int freq;
5786 int chan_no = roam_info->pBssDesc->channelId;
5787
5788 if (chan_no <= 14)
5789 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005790 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305791 else
5792 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005793 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305794
5795 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5796 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5797 roam_info->u.pConnectedProfile->SSID.ssId,
5798 roam_info->u.pConnectedProfile->SSID.length);
5799 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305800
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305801 if (hdd_fils_update_connect_results(dev, bssid, bss,
5802 roam_info, req_ie, req_ie_len, resp_ie,
5803 resp_ie_len, status, gfp, connect_timeout,
5804 timeout_reason) != 0) {
5805 hdd_connect_bss(dev, bssid, bss, req_ie,
5806 req_ie_len, resp_ie, resp_ie_len,
5807 status, gfp, connect_timeout, timeout_reason);
5808 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305809
Jingxiang Geb49aa302018-01-17 20:54:15 +08005810 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005811 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305812}
5813#else
5814void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005815 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305816 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305817 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305818 bool connect_timeout,
5819 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305820{
Jeff Johnson9d295242017-08-29 14:39:48 -07005821 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005822 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305823
Anurag Chouhanc4092922016-09-08 15:56:11 +05305824 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5825 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005826
Jingxiang Geb49aa302018-01-17 20:54:15 +08005827 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005828 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305829}
5830#endif
5831
Jeff Johnsond9952752018-04-18 12:15:35 -07005832int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
5833 uint32_t bandwidth)
5834{
5835 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5836 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5837 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
5838 QDF_STATUS status;
5839 tHalHandle hal_hdl = hdd_ctx->hHal;
5840 struct qdf_mac_addr bssid;
5841 struct csr_roam_profile roam_profile;
5842 struct ch_params ch_params;
5843
5844 if (QDF_GLOBAL_MONITOR_MODE != hdd_get_conparam()) {
5845 hdd_err("Not supported, device is not in monitor mode");
5846 return -EINVAL;
5847 }
5848
Visweswara Tanuku006313a2018-04-12 12:26:34 +05305849 /* Validate Channel */
5850 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
5851 hdd_err("Channel %d Not supported", chan);
5852 return -EINVAL;
5853 }
5854
5855 if (WLAN_REG_IS_24GHZ_CH(chan)) {
5856 if (bandwidth == CH_WIDTH_80MHZ) {
5857 hdd_err("BW80 not possible in 2.4GHz band");
5858 return -EINVAL;
5859 }
5860 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
5861 (bandwidth != CH_WIDTH_MAX)) {
5862 hdd_err("Only BW20 possible on channel 14");
5863 return -EINVAL;
5864 }
5865 }
5866
5867 if (WLAN_REG_IS_5GHZ_CH(chan)) {
5868 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
5869 (bandwidth != CH_WIDTH_MAX)) {
5870 hdd_err("Only BW20 possible on channel 165");
5871 return -EINVAL;
5872 }
5873 }
5874
Jeff Johnsond9952752018-04-18 12:15:35 -07005875 hdd_debug("Set monitor mode Channel %d", chan);
5876 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
5877 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
5878 roam_profile.ChannelInfo.numOfChannels = 1;
5879 roam_profile.phyMode = ch_info->phy_mode;
5880 roam_profile.ch_params.ch_width = bandwidth;
5881 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
5882
5883 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
5884 QDF_MAC_ADDR_SIZE);
5885
5886 ch_params.ch_width = bandwidth;
5887 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
5888 if (ch_params.ch_width == CH_WIDTH_INVALID) {
5889 hdd_err("Invalid capture channel or bandwidth for a country");
5890 return -EINVAL;
5891 }
5892 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
5893 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
5894 hdd_err("Failed to change hw mode");
5895 return -EINVAL;
5896 }
5897
5898 status = sme_roam_channel_change_req(hal_hdl, bssid, &ch_params,
5899 &roam_profile);
5900 if (status) {
5901 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
5902 status);
5903 }
5904
5905 adapter->mon_chan = chan;
5906 adapter->mon_bandwidth = bandwidth;
5907 return qdf_status_to_os_return(status);
5908}
Anurag Chouhanc4092922016-09-08 15:56:11 +05305909
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005910QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005911{
Jeff Johnson9d295242017-08-29 14:39:48 -07005912 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005913#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005914 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005915#endif
5916 eConnectionState connState;
5917
Dustin Brown491d54b2018-03-14 12:39:11 -07005918 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005919
Dustin Brown920397d2017-12-13 16:27:50 -08005920 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305921 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005922 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305923
Yue Ma42654682018-01-11 16:55:24 -08005924 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5925 hdd_device_mode_to_string(adapter->device_mode),
5926 adapter->device_mode);
5927
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005928 hdd_wmm_init(adapter);
5929
5930 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005931 case QDF_STA_MODE:
5932 case QDF_P2P_CLIENT_MODE:
5933 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005934
5935 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5936 ->conn_info.connState;
5937
Krunal Sonib51eec72017-11-20 21:53:01 -08005938 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005939 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005940 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005941
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005942 /* Indicate disconnect event to supplicant
5943 * if associated previously
5944 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005946 eConnectionState_IbssConnected == connState ||
5947 eConnectionState_NotConnected == connState ||
5948 eConnectionState_IbssDisconnected == connState ||
5949 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005950 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005952 memset(&wrqu, '\0', sizeof(wrqu));
5953 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5954 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5955 wireless_send_event(adapter->dev, SIOCGIWAP,
5956 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005957 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005958 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005959
5960 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305961 wlan_hdd_cfg80211_indicate_disconnect(
5962 adapter->dev, false,
5963 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005964 } else if (eConnectionState_Connecting == connState) {
5965 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005966 * Indicate connect failure to supplicant if we
5967 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005968 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305969 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305970 NULL, 0, NULL, 0,
5971 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005972 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005973 }
5974
5975 hdd_register_tx_flow_control(adapter,
5976 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005977 hdd_tx_resume_cb,
5978 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979
Alok Kumarb64650c2018-03-23 17:05:11 +05305980 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005981 break;
5982
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005983 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005984 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005985 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305986
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005987 break;
5988
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005989 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005990#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005991 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005992 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5993#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005994 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005995 /* event supplicant to restart */
5996 cfg80211_del_sta(adapter->dev,
5997 (const u8 *)&bcastMac.bytes[0],
5998 GFP_KERNEL);
5999#endif
6000 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306001 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006002 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306003 hdd_set_mon_rx_cb(adapter->dev);
6004 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6005 adapter->mon_bandwidth);
6006 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006007 default:
6008 break;
6009 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006010 /*
6011 * Action frame registered in one adapter which will
6012 * applicable to all interfaces
6013 */
6014 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015 }
6016
Dustin Browne74003f2018-03-14 12:51:58 -07006017 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006018
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306019 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006020}
6021
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006022QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006023 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006024{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306025 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006026 qdf_list_node_t *node;
6027
6028 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006029
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006030 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006031 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006032 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006033
6034 if (QDF_IS_STATUS_ERROR(status))
6035 return status;
6036
6037 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6038
6039 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006040}
6041
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006042QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006043 struct hdd_adapter *current_adapter,
6044 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006045{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306046 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006047 qdf_list_node_t *node;
6048
6049 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006050
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006051 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006052 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006053 &current_adapter->node,
6054 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006055 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006056
6057 if (QDF_IS_STATUS_ERROR(status))
6058 return status;
6059
6060 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6061
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062 return status;
6063}
6064
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006065QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006066 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006067{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306068 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006069
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006070 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006071 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006072 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006073
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006074 return status;
6075}
6076
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006077QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006078 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006079{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306080 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006081 qdf_list_node_t *node;
6082
6083 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006084
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006085 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006086 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006087 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006088
6089 if (QDF_IS_STATUS_ERROR(status))
6090 return status;
6091
6092 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6093
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006094 return status;
6095}
6096
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006097QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006098 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006099{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306100 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006101
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006102 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006103 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006104 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006105
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006106 return status;
6107}
6108
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006109QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006110 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006111{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306112 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006113
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006114 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006115 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006116 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006117
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006118 return status;
6119}
6120
Jeff Johnson9d295242017-08-29 14:39:48 -07006121struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006122 tSirMacAddr macAddr)
6123{
Jeff Johnson9d295242017-08-29 14:39:48 -07006124 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006125
Dustin Brown920397d2017-12-13 16:27:50 -08006126 hdd_for_each_adapter(hdd_ctx, adapter) {
6127 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6128 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006129 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006130 }
6131
6132 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006133}
6134
Jeff Johnson9d295242017-08-29 14:39:48 -07006135struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006136 uint32_t vdev_id)
6137{
Jeff Johnson9d295242017-08-29 14:39:48 -07006138 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006139
Dustin Brown920397d2017-12-13 16:27:50 -08006140 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006141 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006142 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006143 }
6144
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006145 return NULL;
6146}
6147
Abhishek Singh7996eb72015-12-30 17:24:02 +05306148/**
6149 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6150 * the sessionid
6151 * @hdd_ctx: hdd context.
6152 * @sme_session_id: sme session is for the adapter to get.
6153 *
6154 * This function is used to get the adapter with provided session id
6155 *
6156 * Return: adapter pointer if found
6157 *
6158 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006159struct hdd_adapter *
6160hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6161 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306162{
Jeff Johnson9d295242017-08-29 14:39:48 -07006163 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306164
Dustin Brown920397d2017-12-13 16:27:50 -08006165 hdd_for_each_adapter(hdd_ctx, adapter) {
6166 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306167 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306168 }
Dustin Brown920397d2017-12-13 16:27:50 -08006169
Abhishek Singh7996eb72015-12-30 17:24:02 +05306170 return NULL;
6171}
6172
Jeff Johnson9d295242017-08-29 14:39:48 -07006173struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006174 const char *iface_name)
6175{
Jeff Johnson9d295242017-08-29 14:39:48 -07006176 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006177
Dustin Brown920397d2017-12-13 16:27:50 -08006178 hdd_for_each_adapter(hdd_ctx, adapter) {
6179 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006180 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006181 }
Dustin Brown920397d2017-12-13 16:27:50 -08006182
Naveen Rawat4edb6822017-04-12 10:09:17 -07006183 return NULL;
6184}
6185
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006186/**
6187 * hdd_get_adapter() - to get adapter matching the mode
6188 * @hdd_ctx: hdd context
6189 * @mode: adapter mode
6190 *
6191 * This routine will return the pointer to adapter matching
6192 * with the passed mode.
6193 *
6194 * Return: pointer to adapter or null
6195 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006196struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006197 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006198{
Jeff Johnson9d295242017-08-29 14:39:48 -07006199 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006200
Dustin Brown920397d2017-12-13 16:27:50 -08006201 hdd_for_each_adapter(hdd_ctx, adapter) {
6202 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006203 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204 }
6205
6206 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006207}
6208
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306209enum tQDF_ADAPTER_MODE hdd_get_device_mode(uint32_t session_id)
6210{
6211 struct hdd_context *hdd_ctx;
6212 struct hdd_adapter *adapter;
6213
6214 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6215 if (!hdd_ctx) {
6216 hdd_err("Invalid HDD context");
6217 return QDF_MAX_NO_OF_MODE;
6218 }
6219
6220 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6221 if (!adapter) {
6222 hdd_err("Invalid HDD adapter");
6223 return QDF_MAX_NO_OF_MODE;
6224 }
6225
6226 return adapter->device_mode;
6227}
6228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006229/**
6230 * hdd_get_operating_channel() - return operating channel of the device mode
6231 * @hdd_ctx: Pointer to the HDD context.
6232 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006233 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006234 * QDF_STA_MODE,
6235 * QDF_P2P_CLIENT_MODE,
6236 * QDF_SAP_MODE,
6237 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006238 *
6239 * This API returns the operating channel of the requested device mode
6240 *
6241 * Return: channel number. "0" id the requested device is not found OR it is
6242 * not connected.
6243 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006244uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006245 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246{
Jeff Johnson9d295242017-08-29 14:39:48 -07006247 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006248 uint8_t operatingChannel = 0;
6249
Dustin Brown920397d2017-12-13 16:27:50 -08006250 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251 if (mode == adapter->device_mode) {
6252 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006253 case QDF_STA_MODE:
6254 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006255 if (hdd_conn_is_connected
6256 (WLAN_HDD_GET_STATION_CTX_PTR
6257 (adapter))) {
6258 operatingChannel =
6259 (WLAN_HDD_GET_STATION_CTX_PTR
6260 (adapter))->conn_info.
6261 operationChannel;
6262 }
6263 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006264 case QDF_SAP_MODE:
6265 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006266 /* softap connection info */
6267 if (test_bit
6268 (SOFTAP_BSS_STARTED,
6269 &adapter->event_flags))
6270 operatingChannel =
6271 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006272 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006273 break;
6274 default:
6275 break;
6276 }
6277
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006278 /* Found the device of interest. break the loop */
6279 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006280 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006281 }
Dustin Brown920397d2017-12-13 16:27:50 -08006282
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006283 return operatingChannel;
6284}
6285
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006286static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006287 hdd_ctx)
6288{
Jeff Johnson9d295242017-08-29 14:39:48 -07006289 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006290
Dustin Brown491d54b2018-03-14 12:39:11 -07006291 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006292
Dustin Brown920397d2017-12-13 16:27:50 -08006293 hdd_for_each_adapter(hdd_ctx, adapter) {
6294 if (adapter->device_mode == QDF_STA_MODE ||
6295 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6296 adapter->device_mode == QDF_IBSS_MODE ||
6297 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6298 adapter->device_mode == QDF_SAP_MODE ||
6299 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300 wlan_hdd_cfg80211_deregister_frames(adapter);
6301 hdd_unregister_wext(adapter->dev);
6302 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006303 }
6304
Dustin Browne74003f2018-03-14 12:51:58 -07006305 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006306
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306307 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006308}
6309
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006310QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006311{
Jeff Johnson9d295242017-08-29 14:39:48 -07006312 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006313
Dustin Brown491d54b2018-03-14 12:39:11 -07006314 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315
Dustin Brown920397d2017-12-13 16:27:50 -08006316 hdd_for_each_adapter(hdd_ctx, adapter) {
6317 if (adapter->device_mode == QDF_STA_MODE ||
6318 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6319 adapter->device_mode == QDF_IBSS_MODE ||
6320 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6321 adapter->device_mode == QDF_SAP_MODE ||
6322 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006323 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006324 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306325 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006326 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327 }
6328
Dustin Browne74003f2018-03-14 12:51:58 -07006329 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006330
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306331 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006332}
6333
Dustin Brownf27bce82016-11-03 12:52:27 -07006334/**
6335 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6336 * adapters
6337 * @hdd_ctx: The HDD context containing the adapters to operate on
6338 *
6339 * return: QDF_STATUS_SUCCESS
6340 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006341static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006342{
Jeff Johnson9d295242017-08-29 14:39:48 -07006343 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006344 int err;
6345
Dustin Brown491d54b2018-03-14 12:39:11 -07006346 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006347
Dustin Brown920397d2017-12-13 16:27:50 -08006348 hdd_for_each_adapter(hdd_ctx, adapter) {
6349 if (adapter->device_mode == QDF_STA_MODE ||
6350 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6351 adapter->device_mode == QDF_IBSS_MODE ||
6352 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6353 adapter->device_mode == QDF_SAP_MODE ||
6354 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006355 err = wlan_hdd_sched_scan_stop(adapter->dev);
6356 if (err)
6357 hdd_err("Unable to stop scheduled scan");
6358 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006359 }
6360
Dustin Browne74003f2018-03-14 12:51:58 -07006361 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006362
6363 return QDF_STATUS_SUCCESS;
6364}
6365
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366#ifdef WLAN_NS_OFFLOAD
6367/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006368 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006369 * @hdd_ctx: Pointer to hdd context
6370 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006371 * Unregister for IPv6 address change notifications.
6372 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006373 * Return: None
6374 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006375static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006376{
6377 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378}
6379
6380/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006381 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006382 * @hdd_ctx: Pointer to hdd context
6383 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006384 * Register for IPv6 address change notifications.
6385 *
6386 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006387 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006388static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006389{
6390 int ret;
6391
6392 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6393 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006394 if (ret) {
6395 hdd_err("Failed to register IPv6 notifier: %d", ret);
6396 goto out;
6397 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006398
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006399 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006400out:
6401 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006402}
6403#else
6404/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006405 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006406 * @hdd_ctx: Pointer to hdd context
6407 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006408 * Unregister for IPv6 address change notifications.
6409 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410 * Return: None
6411 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006412static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006413{
6414}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006416/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006417 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006418 * @hdd_ctx: Pointer to hdd context
6419 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006420 * Register for IPv6 address change notifications.
6421 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006422 * Return: None
6423 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006424static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006425{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006426 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006427}
6428#endif
6429
Alok Kumarb64650c2018-03-23 17:05:11 +05306430void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6431{
6432 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6433 adapter->disconnection_in_progress = status;
6434 qdf_mutex_release(&adapter->disconnection_status_lock);
6435 hdd_debug("setting disconnection status: %d", status);
6436}
6437
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006438/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006439 * hdd_register_notifiers - Register netdev notifiers.
6440 * @hdd_ctx: HDD context
6441 *
6442 * Register netdev notifiers like IPv4 and IPv6.
6443 *
6444 * Return: 0 on success and errno on failure
6445 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006446static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006447{
6448 int ret;
6449
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006450 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6451 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306452 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006453
6454 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6455 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6456 if (ret) {
6457 hdd_err("Failed to register IPv4 notifier: %d", ret);
6458 goto unregister_ip6_notifier;
6459 }
6460
Alok Kumarb64650c2018-03-23 17:05:11 +05306461 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6462 if (ret) {
6463 hdd_err("Failed to register netevent notifier: %d",
6464 ret);
6465 goto unregister_inetaddr_notifier;
6466 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006467 return 0;
6468
Alok Kumarb64650c2018-03-23 17:05:11 +05306469unregister_inetaddr_notifier:
6470 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006471unregister_ip6_notifier:
6472 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006473out:
6474 return ret;
6475
6476}
6477
6478/**
6479 * hdd_unregister_notifiers - Unregister netdev notifiers.
6480 * @hdd_ctx: HDD context
6481 *
6482 * Unregister netdev notifiers like IPv4 and IPv6.
6483 *
6484 * Return: None.
6485 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006486void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006487{
Alok Kumarb64650c2018-03-23 17:05:11 +05306488 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006489 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6490
6491 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006492}
6493
6494/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006495 * hdd_exit_netlink_services - Exit netlink services
6496 * @hdd_ctx: HDD context
6497 *
6498 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6499 * nl service.
6500 *
6501 * Return: None.
6502 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006503static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006504{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006505 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006506 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006507 ptt_sock_deactivate_svc();
6508
6509 nl_srv_exit();
6510}
6511
6512/**
6513 * hdd_init_netlink_services- Init netlink services
6514 * @hdd_ctx: HDD context
6515 *
6516 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6517 * nl service.
6518 *
6519 * Return: 0 on success and errno on failure.
6520 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006521static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006522{
6523 int ret;
6524
Ryan Hsuceddceb2016-04-28 10:20:14 -07006525 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006526 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006527 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006528 goto out;
6529 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006530 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006531
Naveen Rawat910726a2017-03-06 11:42:51 -08006532 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006533 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006534 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006535 goto err_nl_srv;
6536 }
6537
6538 ret = ptt_sock_activate_svc();
6539 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006540 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006541 goto err_nl_srv;
6542 }
6543
6544 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006545 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006546 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006547
6548 ret = cnss_diag_activate_service();
6549 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006550 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006551 goto err_close_cesium;
6552 }
6553
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006554 ret = spectral_scan_activate_service();
6555 if (ret) {
6556 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6557 goto err_close_cesium;
6558 }
6559
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006560 return 0;
6561
6562err_close_cesium:
6563 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006564 ptt_sock_deactivate_svc();
6565err_nl_srv:
6566 nl_srv_exit();
6567out:
6568 return ret;
6569}
6570
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006571/**
6572 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6573 * @hdd_ctx: HDD context.
6574 *
6575 * Destroy RX wakelock.
6576 *
6577 * Return: None.
6578 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006579static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006580{
6581 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6582}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006583
6584/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006585 * hdd_rx_wake_lock_create() - Create RX wakelock
6586 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006587 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006588 * Create RX wakelock.
6589 *
6590 * Return: None.
6591 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006592static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006593{
6594 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6595}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006596
6597/**
Houston Hoffman160db392016-10-10 17:37:51 -07006598 * hdd_context_deinit() - Deinitialize HDD context
6599 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006600 *
Houston Hoffman160db392016-10-10 17:37:51 -07006601 * Deinitialize HDD context along with all the feature specific contexts but
6602 * do not free hdd context itself. Caller of this API is supposed to free
6603 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006604 *
Houston Hoffman160db392016-10-10 17:37:51 -07006605 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006606 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006607static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006608{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306609 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6610
Houston Hoffman160db392016-10-10 17:37:51 -07006611 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006612
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006613 hdd_sap_context_destroy(hdd_ctx);
6614
6615 hdd_rx_wake_lock_destroy(hdd_ctx);
6616
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006617 hdd_scan_context_destroy(hdd_ctx);
6618
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006619 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006620
Houston Hoffman160db392016-10-10 17:37:51 -07006621 return 0;
6622}
6623
6624/**
6625 * hdd_context_destroy() - Destroy HDD context
6626 * @hdd_ctx: HDD context to be destroyed.
6627 *
6628 * Free config and HDD context as well as destroy all the resources.
6629 *
6630 * Return: None
6631 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006632static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006633{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006634 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306635
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306636 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6637
Houston Hoffman160db392016-10-10 17:37:51 -07006638 hdd_context_deinit(hdd_ctx);
6639
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306640 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006641 hdd_ctx->config = NULL;
6642
6643 wiphy_free(hdd_ctx->wiphy);
6644}
6645
6646/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306647 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6648 *
6649 * This function is used to destroy bug report lock
6650 *
6651 * Return: None
6652 */
6653static void wlan_destroy_bug_report_lock(void)
6654{
6655 p_cds_contextType p_cds_context;
6656
6657 p_cds_context = cds_get_global_context();
6658 if (!p_cds_context) {
6659 hdd_err("cds context is NULL");
6660 return;
6661 }
6662
6663 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6664}
6665
6666/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006667 * hdd_wlan_exit() - HDD WLAN exit function
6668 * @hdd_ctx: Pointer to the HDD Context
6669 *
6670 * This is the driver exit point (invoked during rmmod)
6671 *
6672 * Return: None
6673 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006674static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006675{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006676 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306677 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006678
Dustin Brown491d54b2018-03-14 12:39:11 -07006679 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006680
Arun Khandavallifae92942016-08-01 13:31:08 +05306681 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682
Prashanth Bhattaab004382016-10-11 16:08:11 -07006683 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006684
6685#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306686 if (QDF_TIMER_STATE_RUNNING ==
6687 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6688 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006689 }
6690
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306691 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306692 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006693 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006694 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006695 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6696 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6697 hdd_ctx->last_acs_channel_list = NULL;
6698 hdd_ctx->num_of_channels = 0;
6699 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006700#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006701
Arun Khandavallifae92942016-08-01 13:31:08 +05306702 mutex_lock(&hdd_ctx->iface_change_lock);
6703 driver_status = hdd_ctx->driver_status;
6704 mutex_unlock(&hdd_ctx->iface_change_lock);
6705
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006706 /*
6707 * Powersave Offload Case
6708 * Disable Idle Power Save Mode
6709 */
6710 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006711 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306712 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006713
Arun Khandavallifae92942016-08-01 13:31:08 +05306714 if (driver_status != DRIVER_MODULES_CLOSED) {
6715 hdd_unregister_wext_all_adapters(hdd_ctx);
6716 /*
6717 * Cancel any outstanding scan requests. We are about to close
6718 * all of our adapters, but an adapter structure is what SME
6719 * passes back to our callback function. Hence if there
6720 * are any outstanding scan requests then there is a
6721 * race condition between when the adapter is closed and
6722 * when the callback is invoked. We try to resolve that
6723 * race condition here by canceling any outstanding scans
6724 * before we close the adapters.
6725 * Note that the scans may be cancelled in an asynchronous
6726 * manner, so ideally there needs to be some kind of
6727 * synchronization. Rather than introduce a new
6728 * synchronization here, we will utilize the fact that we are
6729 * about to Request Full Power, and since that is synchronized,
6730 * the expectation is that by the time Request Full Power has
6731 * completed, all scans will be cancelled
6732 */
6733 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006734 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006735 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006736 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006737 }
6738
Arunk Khandavalli830c9692018-03-22 12:17:40 +05306739 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306740 unregister_netdevice_notifier(&hdd_netdev_notifier);
6741
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006742 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306743
Dustin Brown021cecd2017-12-11 13:56:43 -08006744 hdd_driver_memdump_deinit();
6745
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306746 qdf_nbuf_deinit_replenish_timer();
6747
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306748 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6749 hdd_info("Release wakelock for monitor mode!");
6750 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6751 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6752 }
6753
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306754 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6755 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6756 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6757
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006758 /*
6759 * Close CDS
6760 * This frees pMac(HAL) context. There should not be any call
6761 * that requires pMac access after this.
6762 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006763
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006764 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -07006765 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766
Dustin Brownd005ad82018-01-19 10:32:13 -08006767 hdd_close_all_adapters(hdd_ctx, false);
6768
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306769 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306770 /*
6771 * If there is re_init failure wiphy would have already de-registered
6772 * check the wiphy status before un-registering again
6773 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306774 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306775 wiphy_unregister(wiphy);
6776 wlan_hdd_cfg80211_deinit(wiphy);
6777 hdd_lpass_notify_stop(hdd_ctx);
6778 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006779
Arun Khandavallifae92942016-08-01 13:31:08 +05306780 hdd_exit_netlink_services(hdd_ctx);
6781 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306782#ifdef FEATURE_WLAN_CH_AVOID
6783 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6784#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306785
Abhishek Singhe9068f12017-03-31 14:14:52 +05306786 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6787 if (driver_status)
6788 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006789
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006790 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006791}
6792
6793void __hdd_wlan_exit(void)
6794{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006795 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006796
Dustin Brown491d54b2018-03-14 12:39:11 -07006797 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798
Anurag Chouhan6d760662016-02-20 16:05:43 +05306799 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006801 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07006802 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006803 return;
6804 }
6805
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006806 /* Do all the cleanup before deregistering the driver */
6807 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006808
Dustin Browne74003f2018-03-14 12:51:58 -07006809 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006810}
6811
6812#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006813/**
6814 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006815 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006816 *
6817 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6818 * Then new ACS request will do a fresh scan without reusing the cached
6819 * scan information.
6820 *
6821 * Return: void
6822 */
Tang Yingying523322d2017-01-17 23:28:43 +08006823static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006824{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006825 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006826
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006827 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006828 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006829 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6830 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6831 hdd_ctx->last_acs_channel_list = NULL;
6832 hdd_ctx->num_of_channels = 0;
6833 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006834
6835 if (!hdd_ctx->hHal)
6836 return;
6837 sme_scan_flush_result(hdd_ctx->hHal);
6838}
6839#endif
6840
6841#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006842int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6843 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006844{
6845 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306846 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006847 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006848
6849 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6850
6851 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306852 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006853 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306854
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006855 if (!hdd_ctx->hHal)
6856 return -EINVAL;
6857
Jeff Johnsone7672e72017-10-21 15:10:04 -07006858 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006859 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306860 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006861 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862 return -EINVAL;
6863 }
6864
6865 return 0;
6866}
6867#endif
6868
6869/**
6870 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6871 * @state: state
6872 *
6873 * This function notifies FW with modem power status
6874 *
6875 * Return: 0 if successful, error number otherwise
6876 */
6877int hdd_wlan_notify_modem_power_state(int state)
6878{
6879 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306880 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006881 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882
Anurag Chouhan6d760662016-02-20 16:05:43 +05306883 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006884 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306885 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006886 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888 if (!hdd_ctx->hHal)
6889 return -EINVAL;
6890
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306891 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6892 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006893 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006894 state);
6895 return -EINVAL;
6896 }
6897 return 0;
6898}
6899
6900/**
6901 *
6902 * hdd_post_cds_enable_config() - HDD post cds start config helper
6903 * @adapter - Pointer to the HDD
6904 *
6905 * Return: None
6906 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006907QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006908{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306909 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006910
6911 /*
6912 * Send ready indication to the HDD. This will kick off the MAC
6913 * into a 'running' state and should kick off an initial scan.
6914 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306915 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6916 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006917 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6918 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306919 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006920 }
6921
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306922 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923}
6924
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05306925struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
6926{
6927 struct hdd_adapter *adapter;
6928
6929 hdd_for_each_adapter(hdd_ctx, adapter) {
6930 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
6931 return adapter;
6932 }
6933
6934 return NULL;
6935}
6936
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006937/* wake lock APIs for HDD */
6938void hdd_prevent_suspend(uint32_t reason)
6939{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306940 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006941}
6942
6943void hdd_allow_suspend(uint32_t reason)
6944{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306945 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006946}
6947
6948void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6949{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306950 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6951 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006952}
6953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006954/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006955QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006956{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006957
Amar Singhal6f8592b2017-04-26 14:31:58 -07006958 return sme_init_chan_list(hdd_ctx->hHal,
6959 hdd_ctx->reg.alpha2,
6960 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006961}
6962
6963/**
6964 * hdd_is_5g_supported() - check if hardware supports 5GHz
6965 * @hdd_ctx: Pointer to the hdd context
6966 *
6967 * HDD function to know if hardware supports 5GHz
6968 *
6969 * Return: true if hardware supports 5GHz
6970 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006971bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006972{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006973 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006974 return true;
6975
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006976 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006977 return true;
6978 else
6979 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006980}
6981
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006982static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006983{
6984 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006985 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006986
6987 wiphy = hdd_ctx->wiphy;
6988
6989 /*
6990 * The channel information in
6991 * wiphy needs to be initialized before wiphy registration
6992 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006993 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6994 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006995 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006996 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006997 }
6998
6999#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7000 wiphy->wowlan = &wowlan_support_reg_init;
7001#else
7002 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7003 WIPHY_WOWLAN_MAGIC_PKT |
7004 WIPHY_WOWLAN_DISCONNECT |
7005 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7006 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7007 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7008 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7009 WIPHY_WOWLAN_RFKILL_RELEASE;
7010
7011 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7012 WOW_MAX_FILTERS_PER_LIST);
7013 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7014 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7015#endif
7016
7017 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007018 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307019 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007020 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307021 return ret_val;
7022 }
7023
Amar Singhal2d812012018-02-03 15:06:47 +08007024 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007025
Amar Singhale4f28ee2015-10-21 14:36:56 -07007026 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007027}
7028
Mohit Khannaca4173b2017-09-12 21:52:19 -07007029#ifdef MSM_PLATFORM
7030/**
7031 * hdd_display_periodic_stats() - Function to display periodic stats
7032 * @hdd_ctx - handle to hdd context
7033 * @bool data_in_interval - true, if data detected in bw time interval
7034 *
7035 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7036 * Stats show up in wlan driver logs.
7037 *
7038 * Returns: None
7039 */
7040static inline
7041void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7042 bool data_in_interval)
7043{
7044 static u32 counter;
7045 static bool data_in_time_period;
7046 ol_txrx_pdev_handle pdev;
7047
7048 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7049 return;
7050
7051 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7052 if (!pdev) {
7053 hdd_err("pdev is NULL");
7054 return;
7055 }
7056
7057 counter++;
7058 if (data_in_interval)
7059 data_in_time_period = data_in_interval;
7060
7061 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7062 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7063 if (data_in_time_period) {
7064 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7065 CDP_TXRX_PATH_STATS,
7066 QDF_STATS_VERBOSITY_LEVEL_LOW);
7067 wlan_hdd_display_netif_queue_history
7068 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7069 qdf_dp_trace_dump_stats();
7070 }
7071 counter = 0;
7072 data_in_time_period = false;
7073 }
7074}
7075
Ravi Joshie2331e82015-07-01 18:18:54 -07007076/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007077 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7078 * @hdd_ctx: pointer to struct hdd_context
7079 *
7080 * Return: none
7081 */
7082static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7083{
7084 struct hdd_adapter *adapter;
7085
7086 hdd_for_each_adapter(hdd_ctx, adapter)
7087 hdd_send_rps_disable_ind(adapter);
7088}
7089
7090/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007091 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007092 * @hdd_ctx - handle to hdd context
7093 * @tx_packets - transmit packet count
7094 * @rx_packets - receive packet count
7095 *
7096 * The function controls the bus bandwidth and dynamic control of
7097 * tcp delayed ack configuration
7098 *
7099 * Returns: None
7100 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007101
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007102static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007103 const uint64_t tx_packets,
7104 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007105{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007106 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08007107 uint64_t temp_rx = 0;
7108 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007109 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007110 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007111 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007112 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007113 uint16_t index = 0;
7114 bool vote_level_change = false;
7115 bool rx_level_change = false;
7116 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007117
Mohit Khannaca4173b2017-09-12 21:52:19 -07007118 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007119 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007120 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007121 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007122 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007123 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007124 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007125 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007126
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007127 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007128 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7129 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007131 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007132 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007133 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7134 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307135 if (hdd_ctx->hbw_requested) {
7136 pld_remove_pm_qos(hdd_ctx->parent_dev);
7137 hdd_ctx->hbw_requested = false;
7138 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05307139 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007140 hdd_warn("low bandwidth set rx affinity fail");
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007141
7142 if (hdd_ctx->dynamic_rps)
7143 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007144 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307145 if (!hdd_ctx->hbw_requested) {
7146 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7147 hdd_ctx->hbw_requested = true;
7148 }
7149
Nirav Shah3bbfa512016-05-12 16:43:49 +05307150 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007151 hdd_warn("high bandwidth set rx affinity fail");
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007152
7153 if (hdd_ctx->dynamic_rps)
7154 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007155 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07007156 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007157 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007158
Mohit Khannaf8f96822017-05-17 17:11:59 -07007159 qdf_dp_trace_throttle_live_mode(
7160 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
7161
Mohit Khannae71e2262015-11-10 09:37:24 -08007162 /* fine-tuning parameters for RX Flows */
7163 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
7164
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007165 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007166
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307167 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07007168 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307169 else
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07007170 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307171
Ravi Joshifed83572016-10-07 16:20:37 -07007172 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
7173 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7174 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7175 next_rx_level = WLAN_SVC_TP_HIGH;
7176 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007177 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007178 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007179 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007180 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007181
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007182 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007183 struct wlan_rx_tp_data rx_tp_data = {0};
7184
Ravi Joshie2331e82015-07-01 18:18:54 -07007185 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007186 next_rx_level, temp_rx);
7187 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007188 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007189 /* Send throughput indication only if it is enabled.
7190 * Disabling tcp_del_ack will revert the tcp stack behavior
7191 * to default delayed ack. Note that this will disable the
7192 * dynamic delayed ack mechanism across the system
7193 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007194 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007195 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7196
Mohit Khanna6272fb682017-04-13 09:34:36 -07007197 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7198 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7199
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007200 rx_tp_data.level = next_rx_level;
7201 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7202 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7203 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007204 }
7205
Mohit Khannae71e2262015-11-10 09:37:24 -08007206 /* fine-tuning parameters for TX Flows */
7207 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7208 hdd_ctx->prev_tx = tx_packets;
7209 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7210 next_tx_level = WLAN_SVC_TP_HIGH;
7211 else
7212 next_tx_level = WLAN_SVC_TP_LOW;
7213
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007214 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7215 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007216 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7217 next_tx_level, temp_tx);
7218 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007219 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307220 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7221 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007222 &next_tx_level,
7223 sizeof(next_tx_level));
7224 }
7225
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007226 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007227 if (vote_level_change || tx_level_change || rx_level_change) {
7228 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7229 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7230 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7231 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7232 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7233 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7234 hdd_ctx->hdd_txrx_hist_idx++;
7235 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7236 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007237
7238 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007239}
7240
7241#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307242static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007243{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007244 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307245 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307246 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307247 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307248 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7249 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007250 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307251 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007252 bool connected = false;
7253 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7254
Prashanth Bhattaab004382016-10-11 16:08:11 -07007255 if (wlan_hdd_validate_context(hdd_ctx))
7256 return;
7257
Jeff Johnson214671b2017-10-30 19:45:23 -07007258 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007259 goto restart_timer;
7260
Dustin Brown920397d2017-12-13 16:27:50 -08007261 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307262 /*
7263 * Validate magic so we don't end up accessing
7264 * an invalid adapter.
7265 */
7266 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7267 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007268
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007269 if ((adapter->device_mode == QDF_STA_MODE ||
7270 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007271 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7272 != eConnectionState_Associated) {
7273
7274 continue;
7275 }
7276
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007277 if ((adapter->device_mode == QDF_SAP_MODE ||
7278 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007279 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007280
7281 continue;
7282 }
7283
7284 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7285 adapter->prev_tx_packets);
7286 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7287 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307288
7289 if (adapter->device_mode == QDF_SAP_MODE ||
7290 adapter->device_mode == QDF_P2P_GO_MODE ||
7291 adapter->device_mode == QDF_IBSS_MODE) {
7292
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007293 ret = cdp_get_intra_bss_fwd_pkts_count(
7294 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007295 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307296 &fwd_tx_packets, &fwd_rx_packets);
7297 if (ret == A_OK) {
7298 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7299 fwd_tx_packets,
7300 adapter->prev_fwd_tx_packets);
7301 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7302 fwd_tx_packets,
7303 adapter->prev_fwd_rx_packets);
7304 }
7305 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007306
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307307 if (adapter->device_mode == QDF_SAP_MODE)
7308 con_sap_adapter = adapter;
7309
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007310 total_rx += adapter->stats.rx_packets;
7311 total_tx += adapter->stats.tx_packets;
7312
7313 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7314 adapter->prev_tx_packets = adapter->stats.tx_packets;
7315 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307316 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7317 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007318 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7319 connected = true;
7320 }
7321
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007322 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007323 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007324 return;
7325 }
7326
Yun Parka29974a2018-04-09 12:05:49 -07007327 /* add intra bss forwarded tx and rx packets */
7328 tx_packets += fwd_tx_packets_diff;
7329 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007330
Yun Parka29974a2018-04-09 12:05:49 -07007331 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7332 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7333 &ipa_rx_packets);
7334 tx_packets += (uint64_t)ipa_tx_packets;
7335 rx_packets += (uint64_t)ipa_rx_packets;
7336
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307337 if (con_sap_adapter) {
7338 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7339 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7340 }
7341
Yun Parka29974a2018-04-09 12:05:49 -07007342 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7343 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7344 }
7345
7346 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007347
Jingxiang Gec64e1932017-08-22 14:38:59 +08007348restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007349 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007350 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007351 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307352 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007353 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007354 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007355}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007356
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307357/**
7358 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7359 * @arg: Argument of timer function
7360 *
7361 * Schedule a workqueue in this function where all the processing is done.
7362 *
7363 * Return: None.
7364 */
7365static void __hdd_bus_bw_cbk(void *arg)
7366{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007367 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307368
7369 if (wlan_hdd_validate_context(hdd_ctx))
7370 return;
7371
7372 schedule_work(&hdd_ctx->bus_bw_work);
7373}
7374
7375/**
7376 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7377 * @arg: Argument of timer function
7378 *
7379 * Return: None.
7380 */
7381static void hdd_bus_bw_cbk(void *arg)
7382{
7383 cds_ssr_protect(__func__);
7384 __hdd_bus_bw_cbk(arg);
7385 cds_ssr_unprotect(__func__);
7386}
7387
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007388int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007389{
7390 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307391 INIT_WORK(&hdd_ctx->bus_bw_work,
7392 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007393 hdd_ctx->bus_bw_timer_running = false;
7394 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307395 qdf_timer_init(NULL,
7396 &hdd_ctx->bus_bw_timer,
7397 hdd_bus_bw_cbk, (void *)hdd_ctx,
7398 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007399
7400 return 0;
7401}
7402
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007403void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007404{
Dustin Brownfce08d12017-01-17 16:29:38 -08007405 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007406 hdd_reset_tcp_delack(hdd_ctx);
7407
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007408 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307409 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307410 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007411 hdd_ctx->bus_bw_timer_running = false;
7412 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007413}
Lin Baic5c06882017-09-21 13:58:43 +08007414
7415void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7416{
7417 if (hdd_ctx)
7418 cancel_work_sync(&hdd_ctx->bus_bw_work);
7419}
jiadcdaf9bd2017-10-26 12:20:21 +08007420
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007421#endif
7422
7423/**
Nirav Shahed34b212016-04-25 10:59:16 +05307424 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7425 * @hdd_ctx: hdd context
7426 *
7427 * Return: 0 for success or error code
7428 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007429static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307430{
7431 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7432 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7433 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007434 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307435 return -ENOMEM;
7436 }
7437 return 0;
7438}
7439
7440/**
7441 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7442 * @hdd_ctx: hdd context
7443 *
7444 * Return: none
7445 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007446void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307447{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307448 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7449 return;
7450
7451 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7452 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307453}
7454
Nirav Shahda008342016-05-17 18:50:40 +05307455static uint8_t *convert_level_to_string(uint32_t level)
7456{
7457 switch (level) {
7458 /* initialize the wlan sub system */
7459 case WLAN_SVC_TP_NONE:
7460 return "NONE";
7461 case WLAN_SVC_TP_LOW:
7462 return "LOW";
7463 case WLAN_SVC_TP_MEDIUM:
7464 return "MED";
7465 case WLAN_SVC_TP_HIGH:
7466 return "HIGH";
7467 default:
7468 return "INVAL";
7469 }
7470}
7471
Nirav Shahed34b212016-04-25 10:59:16 +05307472
7473/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007474 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7475 * @hdd_ctx: hdd context
7476 *
7477 * Return: none
7478 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007479void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007480{
7481 int i;
7482
7483#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007484 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307485 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007486 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007487 hdd_ctx->config->busBandwidthHighThreshold,
7488 hdd_ctx->config->busBandwidthMediumThreshold,
7489 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007490 hdd_debug("Enable TCP DEL ACK: %d",
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007491 hdd_ctx->en_tcp_delack_no_lro);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007492 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007493 hdd_ctx->config->tcpDelackThresholdHigh,
7494 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007495 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307496 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007497#endif
7498
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007499 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307500 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7501
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007502 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007503
7504 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007505 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007506 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007507 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7508 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7509 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7510 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7511 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007512 hdd_ctx->hdd_txrx_hist[i].
7513 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007514 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007515 hdd_ctx->hdd_txrx_hist[i].
7516 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007517 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007518 hdd_ctx->hdd_txrx_hist[i].
7519 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007520 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007521}
7522
7523/**
7524 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7525 * @hdd_ctx: hdd context
7526 *
7527 * Return: none
7528 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007529void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007530{
7531 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307532 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7533 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007534}
7535
Mohit Khannaca4173b2017-09-12 21:52:19 -07007536/* length of the netif queue log needed per adapter */
7537#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7538
7539/**
7540 *
7541 * hdd_display_netif_queue_history_compact() - display compact netifq history
7542 * @hdd_ctx: hdd context
7543 *
7544 * Return: none
7545 */
7546static void
7547hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7548{
7549 int adapter_num = 0;
7550 int i;
7551 int bytes_written;
7552 u32 tbytes;
7553 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007554 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007555 char *comb_log_str;
7556 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007557 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007558
jiadbdefb252018-01-03 14:27:06 +08007559 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7560 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7561 if (!comb_log_str) {
7562 hdd_err("failed to alloc comb_log_str");
7563 return;
7564 }
7565
Mohit Khannaca4173b2017-09-12 21:52:19 -07007566 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007567
Dustin Brown920397d2017-12-13 16:27:50 -08007568 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007569 curr_time = qdf_system_ticks();
7570 total = curr_time - adapter->start_time;
7571 delta = curr_time - adapter->last_time;
7572
7573 if (adapter->pause_map) {
7574 pause = adapter->total_pause_time + delta;
7575 unpause = adapter->total_unpause_time;
7576 } else {
7577 unpause = adapter->total_unpause_time + delta;
7578 pause = adapter->total_pause_time;
7579 }
7580
7581 tbytes = 0;
7582 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7583 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7584 if (adapter->queue_oper_stats[i].pause_count == 0)
7585 continue;
7586 tbytes +=
7587 snprintf(
7588 &temp_str[tbytes],
7589 (tbytes >= sizeof(temp_str) ?
7590 0 : sizeof(temp_str) - tbytes),
7591 "%d(%d,%d) ",
7592 i,
7593 adapter->queue_oper_stats[i].
7594 pause_count,
7595 adapter->queue_oper_stats[i].
7596 unpause_count);
7597 }
7598 if (tbytes >= sizeof(temp_str))
7599 hdd_warn("log truncated");
7600
7601 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007602 bytes_written >= comb_log_str_size ? 0 :
7603 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007604 "[%d %d] (%d) %u/%ums %s|",
7605 adapter->session_id, adapter->device_mode,
7606 adapter->pause_map,
7607 qdf_system_ticks_to_msecs(pause),
7608 qdf_system_ticks_to_msecs(total),
7609 temp_str);
7610
Mohit Khannaca4173b2017-09-12 21:52:19 -07007611 adapter_num++;
7612 }
7613
7614 /* using QDF_TRACE to avoid printing function name */
7615 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7616 "STATS |%s", comb_log_str);
7617
jiadbdefb252018-01-03 14:27:06 +08007618 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007619 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007620
7621 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007622}
7623
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007624/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007625 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007626 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627 *
7628 * Return: none
7629 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007630void
7631wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7632 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007633{
7634
Jeff Johnson9d295242017-08-29 14:39:48 -07007635 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307637 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007638
Mohit Khannaca4173b2017-09-12 21:52:19 -07007639 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7640 hdd_display_netif_queue_history_compact(hdd_ctx);
7641 return;
7642 }
7643
Dustin Brown920397d2017-12-13 16:27:50 -08007644 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007645 hdd_debug("Netif queue operation statistics:");
7646 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007647 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007648 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307649 curr_time = qdf_system_ticks();
7650 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307651 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307652 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307653 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307654 unpause = adapter->total_unpause_time;
7655 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307656 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307657 pause = adapter->total_pause_time;
7658 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007659 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307660 qdf_system_ticks_to_msecs(total),
7661 qdf_system_ticks_to_msecs(pause),
7662 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007663 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007664
Nirav Shahda008342016-05-17 18:50:40 +05307665 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7666 qdf_time_t pause_delta = 0;
7667
7668 if (adapter->pause_map & (1 << i))
7669 pause_delta = delta;
7670
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007671 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007672 hdd_debug("%s: %d: %d: %ums",
7673 hdd_reason_type_to_string(i),
7674 adapter->queue_oper_stats[i].pause_count,
7675 adapter->queue_oper_stats[i].unpause_count,
7676 qdf_system_ticks_to_msecs(
7677 adapter->queue_oper_stats[i].total_pause_time +
7678 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007679 }
7680
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007681 hdd_debug("Netif queue operation history:");
7682 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307683 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7684
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007685 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007686
7687 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007688 /* using hdd_log to avoid printing function name */
7689 if (adapter->queue_oper_history[i].time == 0)
7690 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007691 hdd_debug("%d: %u: %s: %s: %x",
7692 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007693 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007694 hdd_action_type_to_string(
7695 adapter->queue_oper_history[i].netif_action),
7696 hdd_reason_type_to_string(
7697 adapter->queue_oper_history[i].netif_reason),
7698 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007699 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007700 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007701}
7702
7703/**
7704 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7705 * @hdd_ctx: hdd context
7706 *
7707 * Return: none
7708 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007709void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007710{
Jeff Johnson9d295242017-08-29 14:39:48 -07007711 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007712
Dustin Brown920397d2017-12-13 16:27:50 -08007713 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307714 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007715 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307716 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007717 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307718 adapter->history_index = 0;
7719 adapter->start_time = adapter->last_time = qdf_system_ticks();
7720 adapter->total_pause_time = 0;
7721 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007722 }
7723}
7724
7725/**
7726 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7727 * @halHandle: Hal handle
7728 * @pContext: Pointer to the context
7729 * @sessionId: Session ID
7730 * @scanId: Scan ID
7731 * @status: Status
7732 *
7733 * This is the callback to be executed when 11d scan is completed to flush out
7734 * the scan results
7735 *
7736 * 11d scan is done during driver load and is a passive scan on all
7737 * channels supported by the device, 11d scans may find some APs on
7738 * frequencies which are forbidden to be used in the regulatory domain
7739 * the device is operating in. If these APs are notified to the supplicant
7740 * it may try to connect to these APs, thus flush out all the scan results
7741 * which are present in SME after 11d scan is done.
7742 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307743 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007744 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307745static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007746 uint8_t sessionId, uint32_t scanId,
7747 eCsrScanStatus status)
7748{
Dustin Brown491d54b2018-03-14 12:39:11 -07007749 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007750
7751 sme_scan_flush_result(halHandle);
7752
Dustin Browne74003f2018-03-14 12:51:58 -07007753 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007754
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307755 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007756}
7757
7758#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7759/**
7760 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7761 * @hdd_ctx: hdd global context
7762 *
7763 * Return: none
7764 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007765static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007766{
7767 uint8_t i;
7768
7769 mutex_init(&hdd_ctx->op_ctx.op_lock);
7770 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7771 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7772 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7773 }
7774}
7775#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007776static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007777{
7778}
7779#endif
7780
Yingying Tang95409972016-10-20 15:16:15 +08007781#ifdef WLAN_FEATURE_WOW_PULSE
7782/**
7783 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007784 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007785 * @enable: enable or disable this behaviour
7786 *
7787 * Return: int
7788 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007789static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007790{
7791 struct hdd_config *pcfg_ini = phddctx->config;
7792 struct wow_pulse_mode wow_pulse_set_info;
7793 QDF_STATUS status;
7794
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007795 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007796
7797 if (false == phddctx->config->wow_pulse_support)
7798 return 0;
7799
7800 /* prepare the request to send to SME */
7801 if (enable == true) {
7802 wow_pulse_set_info.wow_pulse_enable = true;
7803 wow_pulse_set_info.wow_pulse_pin =
7804 pcfg_ini->wow_pulse_pin;
7805 wow_pulse_set_info.wow_pulse_interval_low =
7806 pcfg_ini->wow_pulse_interval_low;
7807 wow_pulse_set_info.wow_pulse_interval_high =
7808 pcfg_ini->wow_pulse_interval_high;
7809 } else {
7810 wow_pulse_set_info.wow_pulse_enable = false;
7811 wow_pulse_set_info.wow_pulse_pin = 0;
7812 wow_pulse_set_info.wow_pulse_interval_low = 0;
7813 wow_pulse_set_info.wow_pulse_interval_high = 0;
7814 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007815 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007816 wow_pulse_set_info.wow_pulse_enable,
7817 wow_pulse_set_info.wow_pulse_pin,
7818 wow_pulse_set_info.wow_pulse_interval_low,
7819 wow_pulse_set_info.wow_pulse_interval_high);
7820
7821 status = sme_set_wow_pulse(&wow_pulse_set_info);
7822 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007823 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007824 return -EIO;
7825 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007826 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007827 return 0;
7828}
7829#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007830static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007831{
7832 return 0;
7833}
7834#endif
7835
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007836#ifdef WLAN_FEATURE_FASTPATH
7837/**
7838 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7839 * @hdd_cfg: hdd config
7840 * @context: lower layer context
7841 *
7842 * Return: none
7843 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307844void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007845 void *context)
7846{
7847 if (hdd_cfg->fastpath_enable)
7848 hif_enable_fastpath(context);
7849}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007850#endif
7851
Yuanyuan Liu13738502016-04-06 17:41:37 -07007852#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007853/**
7854 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007855 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007856 * @level: thermal level
7857 *
7858 * Change IPA data path to SW path when the thermal throttle level greater
7859 * than 0, and restore the original data path when throttle level is 0
7860 *
7861 * Return: none
7862 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007863static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007864{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007865 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007866
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007867 /* Change IPA to SW path when throttle level greater than 0 */
7868 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307869 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007870 else
7871 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307872 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007873}
7874
7875/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307876 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7877 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307878 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007879 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307880 * Get a safe channel to restart SAP. PCL already takes into account the
7881 * unsafe channels. So, the PCL is validated with the ACS range to provide
7882 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007883 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307884 * Return: Channel number to restart SAP in case of success. In case of any
7885 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007886 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307887static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007888 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007889{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307890 struct sir_pcl_list pcl;
7891 QDF_STATUS status;
7892 uint32_t i, j;
7893 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007894 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307895 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007896 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007897
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307898 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7899 if (!hdd_ctx) {
7900 hdd_err("invalid HDD context");
7901 return INVALID_CHANNEL_ID;
7902 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007903
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307904 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7905 if (!hal_handle) {
7906 hdd_err("invalid HAL handle");
7907 return INVALID_CHANNEL_ID;
7908 }
7909
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007910 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7911 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007912 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7913 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307914 if (QDF_IS_STATUS_ERROR(status)) {
7915 hdd_err("Get PCL failed");
7916 return INVALID_CHANNEL_ID;
7917 }
7918
Frank Liudc2cefb2017-06-21 15:38:18 +08007919 /*
7920 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7921 * channel is unsafe channel, the pcl may be empty, instead of return,
7922 * try to choose a safe channel from acs range.
7923 */
7924 if (!pcl.pcl_len)
7925 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307926
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007927 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007928 adapter->session.ap.sap_config.acs_cfg.start_ch,
7929 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307930
7931 /* PCL already takes unsafe channel into account */
7932 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007933 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307934 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007935 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307936 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007937 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007938 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307939 return pcl.pcl_list[i];
7940 }
7941 }
7942
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007943 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307944
7945 /* Try for safe channel from all valid channel */
7946 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007947 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7948 &pcl.pcl_len);
7949 if (ret) {
7950 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307951 return INVALID_CHANNEL_ID;
7952 }
7953
7954 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007955 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307956 found = false;
7957 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007958 if (pcl.pcl_list[i] ==
7959 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007960 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307961 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007962 break;
7963 }
7964 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307965
7966 if (found)
7967 continue;
7968
7969 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007970 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307971 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007972 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007973 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307974 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007975 }
7976 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307977
7978 return INVALID_CHANNEL_ID;
7979}
Nirav Shaheb017be2018-02-15 11:20:58 +05307980#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307981
7982/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007983 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307984 * @adapter: AP adapter
7985 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007986 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307987 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007988 * Moves the SAP interface by invoking the function which
7989 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307990 *
7991 * Return: None
7992 */
Min Liu2fef5792018-01-19 17:59:42 +08007993void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7994 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307995{
Jeff Johnson87251032017-08-29 13:31:11 -07007996 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307997 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007998 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307999
8000 if (!adapter) {
8001 hdd_err("invalid adapter");
8002 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008003 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308004
8005 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8006
8007 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
8008 if (!hal_handle) {
8009 hdd_err("invalid HAL handle");
8010 return;
8011 }
8012
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008013 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8014
Jeff Johnson91df29d2017-10-27 19:29:50 -07008015 hdd_ap_ctx->sap_config.channel = channel;
8016 hdd_ap_ctx->sap_config.ch_params.ch_width =
8017 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308018
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008019 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008020 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308021
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07008022 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07008023 hdd_ap_ctx->sap_config.channel,
8024 hdd_ap_ctx->sap_config.sec_ch,
8025 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308026
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008027 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008028 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008029 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008030}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308031
Jeff Johnson9d295242017-08-29 14:39:48 -07008032int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308033{
8034 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308035 int status;
8036 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308037
8038 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8039
8040 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008041 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308042 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008043 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308044 }
8045 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008046 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308047 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308048 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008049 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308050 WLAN_VENDOR_ACS_WAIT_TIME);
8051 if (qdf_status != QDF_STATUS_SUCCESS) {
8052 hdd_err("failed to start external acs timer");
8053 return -ENOSPC;
8054 }
8055 /* Update config to application */
8056 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008057 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308058
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308059 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308060}
8061
Nirav Shaheb017be2018-02-15 11:20:58 +05308062#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308063/**
8064 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8065 * @hdd_ctx: hdd context pointer
8066 *
8067 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8068 * and if ACS is enabled, driver will ask userspace to restart the
8069 * sap. User space on LTE coex indication restart driver.
8070 *
8071 * Return - none
8072 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008073void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308074{
Dustin Brown920397d2017-12-13 16:27:50 -08008075 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308076 uint32_t i;
8077 bool found = false;
8078 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008079
Dustin Brown920397d2017-12-13 16:27:50 -08008080 hdd_for_each_adapter(hdd_ctxt, adapter) {
8081 if (!(adapter->device_mode == QDF_SAP_MODE &&
8082 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008083 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008084 adapter->device_mode,
8085 adapter->session.ap.sap_config.
8086 acs_cfg.acs_mode);
8087 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308088 }
8089
8090 found = false;
8091 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08008092 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05308093 hdd_ctxt->unsafe_channel_list[i]) {
8094 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008095 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08008096 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308097 break;
8098 }
8099 }
8100
8101 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008102 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008103 adapter->session.ap.operating_channel);
8104 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308105 }
8106
Kapil Gupta8878ad92017-02-13 11:56:04 +05308107 if (hdd_ctxt->config->vendor_acs_support &&
8108 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008109 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308110 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008111 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308112 } else
8113 restart_chan =
8114 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008115 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308116 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008117 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308118 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008119 /*
8120 * SAP restart due to unsafe channel. While
8121 * restarting the SAP, make sure to clear
8122 * acs_channel, channel to reset to
8123 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308124 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008125 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308126 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008127 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308128 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008129 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308130 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8131 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008132 hdd_debug("driver to start sap: %d",
8133 hdd_ctxt->config->sap_internal_restart);
8134 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008135 hdd_switch_sap_channel(adapter, restart_chan,
8136 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008137 else
8138 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308139 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308140 }
8141}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308142
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008143/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008144 * hdd_init_channel_avoidance() - Initialize channel avoidance
8145 * @hdd_ctx: HDD global context
8146 *
8147 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008148 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008149 * down to the lower layers. Then subscribe to subsequent channel
8150 * avoidance events.
8151 *
8152 * Return: None
8153 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008154static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008155{
8156 uint16_t unsafe_channel_count;
8157 int index;
8158
Yuanyuan Liu13738502016-04-06 17:41:37 -07008159 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8160 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008161 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008162 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008163
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008164 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008165 hdd_ctx->unsafe_channel_count);
8166
Anurag Chouhan6d760662016-02-20 16:05:43 +05308167 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008168 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008169
8170 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008171 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008172 hdd_ctx->unsafe_channel_list[index]);
8173
8174 }
8175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008176}
Dustin Brown676a2322017-08-15 13:16:13 -07008177
Jeff Johnson9d295242017-08-29 14:39:48 -07008178static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008179 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008180{
8181 uint8_t restart_chan;
8182
8183 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8184 if (!restart_chan) {
8185 hdd_alert("fail to restart SAP");
8186 return;
8187 }
8188
8189 /* SAP restart due to unsafe channel. While restarting
8190 * the SAP, make sure to clear acs_channel, channel to
8191 * reset to 0. Otherwise these settings will override
8192 * the ACS while restart.
8193 */
8194 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008195 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008196
8197 hdd_debug("sending coex indication");
8198
8199 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8200 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008201 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008202}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008203
8204int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8205 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8206{
8207 uint32_t size;
8208 uint16_t *unsafe_list;
8209 uint16_t chan_count;
8210
8211 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8212 return -EINVAL;
8213
8214 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8215 NUM_CHANNELS);
8216 if (chan_count) {
8217 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8218 unsafe_list = qdf_mem_malloc(size);
8219 if (!unsafe_list) {
8220 hdd_err("No memory for unsafe chan list size%d",
8221 size);
8222 return -ENOMEM;
8223 }
8224 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8225 } else {
8226 unsafe_list = NULL;
8227 }
8228
8229 *local_unsafe_list = unsafe_list;
8230 *local_unsafe_list_count = chan_count;
8231
8232 return 0;
8233}
8234
8235bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8236 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8237{
8238 int i, j;
8239
8240 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8241 return true;
8242 if (local_unsafe_list_count == 0)
8243 return false;
8244 for (i = 0; i < local_unsafe_list_count; i++) {
8245 for (j = 0; j < local_unsafe_list_count; j++)
8246 if (local_unsafe_list[i] ==
8247 hdd_ctx->unsafe_channel_list[j])
8248 break;
8249 if (j >= local_unsafe_list_count)
8250 break;
8251 }
8252 if (i >= local_unsafe_list_count) {
8253 hdd_info("unsafe chan list same");
8254 return false;
8255 }
8256
8257 return true;
8258}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008259#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008260static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008261{
8262}
Dustin Brown676a2322017-08-15 13:16:13 -07008263
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008264static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008265{
8266}
Dustin Brown676a2322017-08-15 13:16:13 -07008267
Jeff Johnson9d295242017-08-29 14:39:48 -07008268static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008269 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008270{
8271 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8272}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008273#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008274
8275/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008276 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8277 * user space
8278 * @frame_ind: Management frame data to be informed.
8279 *
8280 * This function is used to indicate management frame to
8281 * user space
8282 *
8283 * Return: None
8284 *
8285 */
8286void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8287{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008288 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008289 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008290 int i;
8291
Rajeev Kumard004abc2016-02-17 12:09:56 -08008292 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008293 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008294
8295 if (0 != wlan_hdd_validate_context(hdd_ctx))
8296 return;
8297
8298 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8299 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8300 adapter =
8301 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8302 if (adapter)
8303 break;
8304 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008305 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8306 hdd_for_each_adapter(hdd_ctx, adapter) {
8307 if ((NULL != adapter) &&
8308 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8309 __hdd_indicate_mgmt_frame(adapter,
8310 frame_ind->frame_len,
8311 frame_ind->frameBuf,
8312 frame_ind->frameType,
8313 frame_ind->rxChan,
8314 frame_ind->rxRssi);
8315 }
8316 }
8317 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008318 } else {
8319 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8320 frame_ind->sessionId);
8321 }
8322
8323 if ((NULL != adapter) &&
8324 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8325 __hdd_indicate_mgmt_frame(adapter,
8326 frame_ind->frame_len,
8327 frame_ind->frameBuf,
8328 frame_ind->frameType,
8329 frame_ind->rxChan,
8330 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008331}
8332
Kapil Gupta8878ad92017-02-13 11:56:04 +05308333void hdd_acs_response_timeout_handler(void *context)
8334{
8335 struct hdd_external_acs_timer_context *timer_context =
8336 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008337 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008338 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308339 uint8_t reason;
8340
Dustin Brown491d54b2018-03-14 12:39:11 -07008341 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308342 if (!timer_context) {
8343 hdd_err("invlaid timer context");
8344 return;
8345 }
8346 adapter = timer_context->adapter;
8347 reason = timer_context->reason;
8348
8349
8350 if ((!adapter) ||
8351 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8352 hdd_err("invalid adapter or adapter has invalid magic");
8353 return;
8354 }
8355 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8356 if (wlan_hdd_validate_context(hdd_ctx))
8357 return;
8358
8359 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8360 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8361 else
8362 return;
8363
8364 hdd_err("ACS timeout happened for %s reason %d",
8365 adapter->dev->name, reason);
8366 switch (reason) {
8367 /* SAP init case */
8368 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8369 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8370 false);
8371 wlan_hdd_cfg80211_start_acs(adapter);
8372 break;
8373 /* DFS detected on current channel */
8374 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8375 wlan_sap_update_next_channel(
8376 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8377 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008378 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308379 break;
8380 /* LTE coex event on current channel */
8381 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8382 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8383 break;
8384 default:
8385 hdd_info("invalid reason for timer invoke");
8386
8387 }
8388}
8389
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008390/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008391 * hdd_override_ini_config - Override INI config
8392 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008393 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008394 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008395 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008396 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008397 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008398static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008399{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008400
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008401 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8402 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008403 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008404 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008405 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008406 if (0 == enable_11d || 1 == enable_11d) {
8407 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008408 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008409 }
Leo Chang11545d62016-10-17 14:53:50 -07008410
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308411 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008412 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008413 hdd_debug("IpaConfig override to %d",
8414 hdd_ctx->config->IpaConfig);
8415 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308416
8417 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8418 !hdd_ctx->config->enable_bcast_probe_rsp) {
8419 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8420 hdd_ctx->config->rssi_assoc_reject_enabled,
8421 hdd_ctx->config->enable_bcast_probe_rsp);
8422 hdd_ctx->config->oce_sta_enabled = 0;
8423 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008424}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008425
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008426/**
8427 * hdd_set_trace_level_for_each - Set trace level for each INI config
8428 * @hdd_ctx - HDD context
8429 *
8430 * Set trace level for each module based on INI config.
8431 *
8432 * Return: None
8433 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008434static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008435{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308436 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8437 hdd_ctx->config->qdf_trace_enable_wdi);
8438 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8439 hdd_ctx->config->qdf_trace_enable_hdd);
8440 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8441 hdd_ctx->config->qdf_trace_enable_sme);
8442 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8443 hdd_ctx->config->qdf_trace_enable_pe);
8444 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8445 hdd_ctx->config->qdf_trace_enable_wma);
8446 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8447 hdd_ctx->config->qdf_trace_enable_sys);
8448 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8449 hdd_ctx->config->qdf_trace_enable_qdf);
8450 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8451 hdd_ctx->config->qdf_trace_enable_sap);
8452 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8453 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8454 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8455 hdd_ctx->config->qdf_trace_enable_bmi);
8456 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8457 hdd_ctx->config->qdf_trace_enable_cfg);
8458 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8459 hdd_ctx->config->qdf_trace_enable_epping);
8460 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8461 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8462 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008463 hdd_ctx->config->qdf_trace_enable_txrx);
8464 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8465 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308466 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8467 hdd_ctx->config->qdf_trace_enable_htc);
8468 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8469 hdd_ctx->config->qdf_trace_enable_hif);
8470 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8471 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8472 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8473 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008474 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8475 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008476 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8477 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008478 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8479 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008480 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8481 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008483 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008484}
8485
8486/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008487 * hdd_context_init() - Initialize HDD context
8488 * @hdd_ctx: HDD context.
8489 *
8490 * Initialize HDD context along with all the feature specific contexts.
8491 *
8492 * return: 0 on success and errno on failure.
8493 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008494static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008495{
8496 int ret;
8497
8498 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8499 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8500
8501 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308502 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008503
8504 init_completion(&hdd_ctx->mc_sus_event_var);
8505 init_completion(&hdd_ctx->ready_to_suspend);
8506
8507 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308508 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008509 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308510
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008511 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008512
8513 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8514
8515 ret = hdd_scan_context_init(hdd_ctx);
8516 if (ret)
8517 goto list_destroy;
8518
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008519 hdd_rx_wake_lock_create(hdd_ctx);
8520
8521 ret = hdd_sap_context_init(hdd_ctx);
8522 if (ret)
8523 goto scan_destroy;
8524
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008525 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8526
8527 hdd_init_offloaded_packets_ctx(hdd_ctx);
8528
8529 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8530 hdd_ctx->config);
8531 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008532 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008533
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308534 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8535 "monitor_mode_wakelock");
8536
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008537 return 0;
8538
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008539sap_destroy:
8540 hdd_sap_context_destroy(hdd_ctx);
8541
8542scan_destroy:
8543 hdd_scan_context_destroy(hdd_ctx);
8544 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008545list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008546 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008547
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008548 return ret;
8549}
8550
8551/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308552 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8553 * @hdd_ctx: pointer to hdd context
8554 *
8555 * Return: status of initialization
8556 * 0 - success
8557 * negative value - failure
8558 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008559static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308560{
8561 int ret;
8562
8563 if (!hdd_ctx->config->probe_req_ie_whitelist)
8564 return 0;
8565
8566 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8567 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8568 hdd_ctx->config->probe_req_ie_whitelist = false;
8569 return -EINVAL;
8570 }
8571
8572 /* parse ini string probe req oui */
8573 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8574 if (ret) {
8575 hdd_err("parsing error: disable ie whitelisting");
8576 hdd_ctx->config->probe_req_ie_whitelist = false;
8577 }
8578
8579 return ret;
8580}
8581
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308582/**
8583 * hdd_iface_change_callback() - Function invoked when stop modules expires
8584 * @priv: pointer to hdd context
8585 *
8586 * This function is invoked when the timer waiting for the interface change
8587 * expires, it shall cut-down the power to wlan and stop all the modules.
8588 *
8589 * Return: void
8590 */
8591static void hdd_iface_change_callback(void *priv)
8592{
8593 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8594 int ret;
8595 int status = wlan_hdd_validate_context(hdd_ctx);
8596
8597 if (status)
8598 return;
8599
Dustin Brown491d54b2018-03-14 12:39:11 -07008600 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308601 hdd_debug("Interface change timer expired close the modules!");
8602 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8603 if (ret)
8604 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008605 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308606}
8607
Nirav Shaheb017be2018-02-15 11:20:58 +05308608#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8609static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8610{
8611 wlan_logging_set_log_to_console(hdd_ctx->config->
8612 wlan_logging_to_console);
8613 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8614}
8615#else
8616static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8617{ }
8618#endif
8619
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308620/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008621 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308622 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008623 *
8624 * Allocate and initialize HDD context. HDD context is allocated as part of
8625 * wiphy allocation and then context is initialized.
8626 *
8627 * Return: HDD context on success and ERR_PTR on failure
8628 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008629static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008630{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308631 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008632 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008633 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008634
Dustin Brown491d54b2018-03-14 12:39:11 -07008635 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008636
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008637 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008638 if (hdd_ctx == NULL) {
8639 ret = -ENOMEM;
8640 goto err_out;
8641 }
8642
Dustin Brown6f427922017-09-19 12:19:00 -07008643 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8644 hdd_iface_change_callback,
8645 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308646
8647 mutex_init(&hdd_ctx->iface_change_lock);
8648
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008649 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308650 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008651
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308652 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008653 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008654 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008655 ret = -ENOMEM;
8656 goto err_free_hdd_context;
8657 }
8658
8659 /* Read and parse the qcom_cfg.ini file */
8660 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308661 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308662 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008663 WLAN_INI_FILE);
8664 ret = -EINVAL;
8665 goto err_free_config;
8666 }
8667
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308668 ie_whitelist_attrs_init(hdd_ctx);
8669
Dustin Brown7f939932017-05-18 15:02:17 -07008670 hdd_debug("setting timer multiplier: %u",
8671 hdd_ctx->config->timer_multiplier);
8672 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8673
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008674
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308675 if (hdd_ctx->config->fhostNSOffload)
8676 hdd_ctx->ns_offload_enable = true;
8677
Abhishek Singh5ea86532016-04-27 14:10:53 +05308678 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8679
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008680 hdd_override_ini_config(hdd_ctx);
8681
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008682 ret = hdd_context_init(hdd_ctx);
8683
8684 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008685 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008686
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008687 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308688 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008689
Anurag Chouhan6d760662016-02-20 16:05:43 +05308690 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008691 goto skip_multicast_logging;
8692
8693 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8694
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008695 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8696 if (ret)
8697 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308698
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008699 ret = hdd_init_netlink_services(hdd_ctx);
8700 if (ret)
8701 goto err_deinit_txrx_histogram;
8702
Nirav Shaheb017be2018-02-15 11:20:58 +05308703 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308704
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008705skip_multicast_logging:
8706 hdd_set_trace_level_for_each(hdd_ctx);
8707
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008708 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8709
Dustin Browne74003f2018-03-14 12:51:58 -07008710 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008711
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008712 return hdd_ctx;
8713
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008714err_deinit_txrx_histogram:
8715 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8716
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008717err_deinit_hdd_context:
8718 hdd_context_deinit(hdd_ctx);
8719
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008720err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308721 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008722
8723err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308724 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008725 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008726
8727err_out:
8728 return ERR_PTR(ret);
8729}
8730
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008731#ifdef WLAN_OPEN_P2P_INTERFACE
8732/**
8733 * hdd_open_p2p_interface - Open P2P interface
8734 * @hdd_ctx: HDD context
8735 * @rtnl_held: True if RTNL lock held
8736 *
8737 * Open P2P interface during probe. This function called to open the P2P
8738 * interface at probe along with STA interface.
8739 *
8740 * Return: 0 on success and errno on failure
8741 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008742static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008743{
Jeff Johnson9d295242017-08-29 14:39:48 -07008744 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008745 uint8_t *p2p_dev_addr;
8746
8747 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8748 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008749 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008750 hdd_ctx->config->intfMacAddr[0].bytes,
8751 sizeof(tSirMacAddr));
8752
8753 /*
8754 * Generate the P2P Device Address. This consists of
8755 * the device's primary MAC address with the locally
8756 * administered bit set.
8757 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008758 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008759 } else {
8760 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8761 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008762 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008763 return -ENOSPC;
8764 }
8765
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008766 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8767 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008768 }
8769
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008770 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008771 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008772 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008773
8774 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008775 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008776 return -ENOSPC;
8777 }
8778
8779 return 0;
8780}
8781#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008782static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008783 bool rtnl_held)
8784{
8785 return 0;
8786}
8787#endif
8788
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008789static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008790{
Jeff Johnson9d295242017-08-29 14:39:48 -07008791 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008792 int ret = 0;
8793
8794 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8795 wlan_hdd_get_intf_addr(hdd_ctx),
8796 NET_NAME_UNKNOWN, rtnl_held);
8797 if (adapter == NULL) {
8798 hdd_err("Failed to open 802.11p interface");
8799 ret = -ENOSPC;
8800 }
8801
8802 return ret;
8803}
8804
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008805/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308806 * hdd_start_station_adapter()- Start the Station Adapter
8807 * @adapter: HDD adapter
8808 *
8809 * This function initializes the adapter for the station mode.
8810 *
8811 * Return: 0 on success or errno on failure.
8812 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008813int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308814{
8815 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008816 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308817
Dustin Brownfdf17c12018-03-14 12:55:34 -07008818 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008819 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8820 hdd_err("session is already opened, %d",
8821 adapter->session_id);
8822 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8823 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308824
Krunal Sonib51eec72017-11-20 21:53:01 -08008825 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8826 if (ret) {
8827 hdd_err("failed to create vdev: %d", ret);
8828 return ret;
8829 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308830 status = hdd_init_station_mode(adapter);
8831
8832 if (QDF_STATUS_SUCCESS != status) {
8833 hdd_err("Error Initializing station mode: %d", status);
8834 return qdf_status_to_os_return(status);
8835 }
8836
Arun Khandavallifae92942016-08-01 13:31:08 +05308837 hdd_register_tx_flow_control(adapter,
8838 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008839 hdd_tx_resume_cb,
8840 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308841
Dustin Browne74003f2018-03-14 12:51:58 -07008842 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308843 return 0;
8844}
8845
8846/**
8847 * hdd_start_ap_adapter()- Start AP Adapter
8848 * @adapter: HDD adapter
8849 *
8850 * This function initializes the adapter for the AP mode.
8851 *
8852 * Return: 0 on success errno on failure.
8853 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008854int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308855{
8856 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008857 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008858 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008859 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308860
Dustin Brown491d54b2018-03-14 12:39:11 -07008861 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308862
Krunal Sonib51eec72017-11-20 21:53:01 -08008863 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8864 hdd_err("session is already opened, %d",
8865 adapter->session_id);
8866 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8867 }
8868 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008869 * In SSR case no need to create new sap context.
8870 * Otherwise create sap context first and then create
8871 * vdev as while creating the vdev, driver needs to
8872 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008873 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008874 if (adapter->session.ap.sap_context) {
8875 is_ssr = true;
8876 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008877 hdd_err("sap creation failed");
8878 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8879 }
8880
8881 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8882 adapter->session.ap.sap_context);
8883 if (ret) {
8884 hdd_err("failed to create vdev, status:%d", ret);
8885 hdd_sap_destroy_ctx(adapter);
8886 return ret;
8887 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008888
8889 if (adapter->device_mode == QDF_SAP_MODE)
8890 sme_cli_set_command(adapter->session_id,
8891 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8892 (bool)(hdd_ctx->config->fine_time_meas_cap &
8893 WMI_FW_AP_RTT_RESPR),
8894 VDEV_CMD);
8895
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008896 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308897
8898 if (QDF_STATUS_SUCCESS != status) {
8899 hdd_err("Error Initializing the AP mode: %d", status);
8900 return qdf_status_to_os_return(status);
8901 }
8902
Arun Khandavallifae92942016-08-01 13:31:08 +05308903 hdd_register_tx_flow_control(adapter,
8904 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008905 hdd_softap_tx_resume_cb,
8906 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308907
Dustin Browne74003f2018-03-14 12:51:58 -07008908 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308909 return 0;
8910}
8911
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308912static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8913 bool rtnl_held)
8914{
8915 struct hdd_adapter *adapter;
8916
8917 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8918 hdd_ctx->config->enableConcurrentSTA,
8919 wlan_hdd_get_intf_addr(hdd_ctx),
8920 NET_NAME_UNKNOWN, rtnl_held);
8921
8922 if (!adapter)
8923 return -ENOSPC;
8924
8925 return 0;
8926}
8927
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308928/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008929 * hdd_open_interfaces - Open all required interfaces
8930 * hdd_ctx: HDD context
8931 * rtnl_held: True if RTNL lock is held
8932 *
8933 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8934 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008935 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008936 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008937static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008938{
Jeff Johnson9d295242017-08-29 14:39:48 -07008939 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008940 int ret;
8941
Ravi Joshia307f632017-07-17 23:41:41 -07008942 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008943 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8944 con_mode == QDF_GLOBAL_FTM_MODE) {
8945 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8946 QDF_MONITOR_MODE : QDF_FTM_MODE;
8947
8948 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8949 wlan_hdd_get_intf_addr(hdd_ctx),
8950 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008951 if (!adapter) {
8952 hdd_err("open adapter failed");
8953 return -ENOSPC;
8954 }
Lin Bai1c678482017-12-18 18:29:11 +08008955
Ravi Joshia307f632017-07-17 23:41:41 -07008956 return 0;
8957 }
8958
Jeff Johnson957bc272017-02-02 08:54:48 -08008959 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308960 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008961 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008962
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008963 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008964 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008965 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008966
8967 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008968 return -ENOSPC;
8969
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308970 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8971 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8972 if (ret)
8973 hdd_err("Cannot create concurrent STA interface");
8974 }
8975
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008976 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8977 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008978 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008979
8980 /* Open 802.11p Interface */
8981 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008982 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8983 if (ret)
8984 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008985 }
8986
Jeff Johnson957bc272017-02-02 08:54:48 -08008987 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008988
Jeff Johnson957bc272017-02-02 08:54:48 -08008989err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008990 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008991 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008992}
8993
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008994
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308995#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8996/**
8997 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8998 * @cds_cfg: CDS Configuration
8999 * @hdd_ctx: Pointer to hdd context
9000 *
9001 * Return: none
9002 */
9003static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9004 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009005 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309006{
9007 cds_cfg->tx_flow_stop_queue_th =
9008 hdd_ctx->config->TxFlowStopQueueThreshold;
9009 cds_cfg->tx_flow_start_queue_offset =
9010 hdd_ctx->config->TxFlowStartQueueOffset;
9011}
9012#else
9013static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9014 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009015 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309016{
9017}
9018#endif
9019
9020#ifdef FEATURE_WLAN_RA_FILTERING
9021/**
9022 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9023 * @cds_cfg: CDS Configuration
9024 * @hdd_ctx: Pointer to hdd context
9025 *
9026 * Return: none
9027 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309028static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009029 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309030{
9031 cds_cfg->ra_ratelimit_interval =
9032 hdd_ctx->config->RArateLimitInterval;
9033 cds_cfg->is_ra_ratelimit_enabled =
9034 hdd_ctx->config->IsRArateLimitEnabled;
9035}
9036#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309037static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009038 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309039{
9040}
9041#endif
9042
9043/**
9044 * hdd_update_cds_config() - API to update cds configuration parameters
9045 * @hdd_ctx: HDD Context
9046 *
9047 * Return: 0 for Success, errno on failure
9048 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009049static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309050{
9051 struct cds_config_info *cds_cfg;
9052
9053 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9054 if (!cds_cfg) {
9055 hdd_err("failed to allocate cds config");
9056 return -ENOMEM;
9057 }
9058
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009059 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009060 if (!hdd_ctx->config->nMaxPsPoll ||
9061 !hdd_ctx->config->enablePowersaveOffload) {
9062 cds_cfg->powersave_offload_enabled =
9063 hdd_ctx->config->enablePowersaveOffload;
9064 } else {
9065 if ((hdd_ctx->config->enablePowersaveOffload ==
9066 PS_QPOWER_NODEEPSLEEP) ||
9067 (hdd_ctx->config->enablePowersaveOffload ==
9068 PS_LEGACY_NODEEPSLEEP))
9069 cds_cfg->powersave_offload_enabled =
9070 PS_LEGACY_NODEEPSLEEP;
9071 else
9072 cds_cfg->powersave_offload_enabled =
9073 PS_LEGACY_DEEPSLEEP;
9074 hdd_info("Qpower disabled in cds config, %d",
9075 cds_cfg->powersave_offload_enabled);
9076 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309077 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9078 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9079 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9080 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309081
9082 /*
9083 * Copy the DFS Phyerr Filtering Offload status.
9084 * This parameter reflects the value of the
9085 * dfs_phyerr_filter_offload flag as set in the ini.
9086 */
9087 cds_cfg->dfs_phyerr_filter_offload =
9088 hdd_ctx->config->fDfsPhyerrFilterOffload;
9089 if (hdd_ctx->config->ssdp)
9090 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9091
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309092 cds_cfg->force_target_assert_enabled =
9093 hdd_ctx->config->crash_inject_enabled;
9094
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309095 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9096 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9097
9098 cds_cfg->ap_maxoffload_reorderbuffs =
9099 hdd_ctx->config->apMaxOffloadReorderBuffs;
9100
9101 cds_cfg->ap_disable_intrabss_fwd =
9102 hdd_ctx->config->apDisableIntraBssFwd;
9103
9104 cds_cfg->dfs_pri_multiplier =
9105 hdd_ctx->config->dfsRadarPriMultiplier;
9106 cds_cfg->reorder_offload =
9107 hdd_ctx->config->reorderOffloadSupport;
9108
9109 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309110 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009111 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9112 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009113 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009114 hdd_ctx->config->IpaUcTxBufCount);
9115 hdd_ctx->config->IpaUcTxBufCount =
9116 rounddown_pow_of_two(
9117 hdd_ctx->config->IpaUcTxBufCount);
9118 if (!hdd_ctx->config->IpaUcTxBufCount) {
9119 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309120 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009121 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009122 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009123 hdd_ctx->config->IpaUcTxBufCount);
9124 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309125 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9126 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009127 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9128 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009129 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009130 hdd_ctx->config->IpaUcRxIndRingCount);
9131 hdd_ctx->config->IpaUcRxIndRingCount =
9132 rounddown_pow_of_two(
9133 hdd_ctx->config->IpaUcRxIndRingCount);
9134 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9135 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309136 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009137 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009138 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009139 hdd_ctx->config->IpaUcRxIndRingCount);
9140 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309141 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009142 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309143 cds_cfg->uc_tx_partition_base =
9144 hdd_ctx->config->IpaUcTxPartitionBase;
9145 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9146
9147 cds_cfg->ip_tcp_udp_checksum_offload =
9148 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009149 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309150 cds_cfg->ce_classify_enabled =
9151 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07009152 cds_cfg->bpf_packet_filter_enable =
9153 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309154 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9155 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9156 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009157 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009158 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009159 cds_cfg->max_msdus_per_rxinorderind =
9160 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009161 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009162 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05309163 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
9164 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309165 cds_cfg->auto_power_save_fail_mode =
9166 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309167
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309168 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009169 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009170 cds_cfg->delay_before_vdev_stop =
9171 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309172
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309173 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9174 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9175 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009176 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309177 cds_init_ini_config(cds_cfg);
9178 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309179
9180exit:
9181 qdf_mem_free(cds_cfg);
9182 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309183}
9184
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009185/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009186 * hdd_update_user_config() - API to update user configuration
9187 * parameters to obj mgr which are used by multiple components
9188 * @hdd_ctx: HDD Context
9189 *
9190 * Return: 0 for Success, errno on failure
9191 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009192static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009193{
9194 struct wlan_objmgr_psoc_user_config *user_config;
9195
9196 user_config = qdf_mem_malloc(sizeof(*user_config));
9197 if (user_config == NULL) {
9198 hdd_alert("Failed to alloc memory for user_config!");
9199 return -ENOMEM;
9200 }
9201
9202 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9203 user_config->dual_mac_feature_disable =
9204 hdd_ctx->config->dual_mac_feature_disable;
9205 user_config->indoor_channel_support =
9206 hdd_ctx->config->indoor_channel_support;
9207 user_config->is_11d_support_enabled =
9208 hdd_ctx->config->Is11dSupportEnabled;
9209 user_config->is_11h_support_enabled =
9210 hdd_ctx->config->Is11hSupportEnabled;
9211 user_config->optimize_chan_avoid_event =
9212 hdd_ctx->config->goptimize_chan_avoid_event;
9213 user_config->skip_dfs_chnl_in_p2p_search =
9214 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009215 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009216 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9217
9218 qdf_mem_free(user_config);
9219 return 0;
9220}
9221
9222/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009223 * hdd_init_thermal_info - Initialize thermal level
9224 * @hdd_ctx: HDD context
9225 *
9226 * Initialize thermal level at SME layer and set the thermal level callback
9227 * which would be called when a configured thermal threshold is hit.
9228 *
9229 * Return: 0 on success and errno on failure
9230 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009231static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009232{
9233 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309234 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009235
9236 thermal_param.smeThermalMgmtEnabled =
9237 hdd_ctx->config->thermalMitigationEnable;
9238 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9239
Poddar, Siddarth83905022016-04-16 17:56:08 -07009240 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9241 hdd_ctx->config->throttle_dutycycle_level0;
9242 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9243 hdd_ctx->config->throttle_dutycycle_level1;
9244 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9245 hdd_ctx->config->throttle_dutycycle_level2;
9246 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9247 hdd_ctx->config->throttle_dutycycle_level3;
9248
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009249 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9250 hdd_ctx->config->thermalTempMinLevel0;
9251 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9252 hdd_ctx->config->thermalTempMaxLevel0;
9253 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9254 hdd_ctx->config->thermalTempMinLevel1;
9255 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9256 hdd_ctx->config->thermalTempMaxLevel1;
9257 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9258 hdd_ctx->config->thermalTempMinLevel2;
9259 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9260 hdd_ctx->config->thermalTempMaxLevel2;
9261 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9262 hdd_ctx->config->thermalTempMinLevel3;
9263 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9264 hdd_ctx->config->thermalTempMaxLevel3;
9265
9266 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9267
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309268 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309269 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009270
9271 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9272 hdd_set_thermal_level_cb);
9273
9274 return 0;
9275
9276}
9277
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009278#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9279/**
9280 * hdd_hold_rtnl_lock - Hold RTNL lock
9281 *
9282 * Hold RTNL lock
9283 *
9284 * Return: True if held and false otherwise
9285 */
9286static inline bool hdd_hold_rtnl_lock(void)
9287{
9288 rtnl_lock();
9289 return true;
9290}
9291
9292/**
9293 * hdd_release_rtnl_lock - Release RTNL lock
9294 *
9295 * Release RTNL lock
9296 *
9297 * Return: None
9298 */
9299static inline void hdd_release_rtnl_lock(void)
9300{
9301 rtnl_unlock();
9302}
9303#else
9304static inline bool hdd_hold_rtnl_lock(void) { return false; }
9305static inline void hdd_release_rtnl_lock(void) { }
9306#endif
9307
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009308#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009309
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309310/* MAX iwpriv command support */
9311#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309312#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309313#define MAX_PKTLOG_SIZE 16
9314
9315/**
9316 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9317 * @hdd_ctx: hdd context
9318 * @set_value2: pktlog buffer size value
9319 *
9320 *
9321 * Return: 0 for success or error.
9322 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009323static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309324{
9325 struct sir_wifi_start_log start_log = { 0 };
9326 QDF_STATUS status;
9327
9328 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9329 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9330 start_log.ini_triggered = cds_is_packet_log_enabled();
9331 start_log.user_triggered = 1;
9332 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309333 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309334
9335 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9336 if (!QDF_IS_STATUS_SUCCESS(status)) {
9337 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009338 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309339 return -EINVAL;
9340 }
9341
9342 return 0;
9343}
9344
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009345/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309346 * hdd_pktlog_clear_buff() - clear pktlog buffer
9347 * @hdd_ctx: hdd context
9348 *
9349 * Return: 0 for success or error.
9350 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009351static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309352{
9353 struct sir_wifi_start_log start_log;
9354 QDF_STATUS status;
9355
9356 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9357 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9358 start_log.ini_triggered = cds_is_packet_log_enabled();
9359 start_log.user_triggered = 1;
9360 start_log.size = 0;
9361 start_log.is_pktlog_buff_clear = true;
9362
9363 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9364 if (!QDF_IS_STATUS_SUCCESS(status)) {
9365 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009366 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309367 return -EINVAL;
9368 }
9369
9370 return 0;
9371}
9372
9373
9374/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009375 * hdd_process_pktlog_command() - process pktlog command
9376 * @hdd_ctx: hdd context
9377 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309378 * @set_value2: pktlog buffer size value
9379 *
9380 * This function process pktlog command.
9381 * set_value2 only matters when set_value is 3 (set buff size)
9382 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009383 *
9384 * Return: 0 for success or error.
9385 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009386int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309387 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009388{
9389 int ret;
9390 bool enable;
9391 uint8_t user_triggered = 0;
9392
9393 ret = wlan_hdd_validate_context(hdd_ctx);
9394 if (0 != ret)
9395 return ret;
9396
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009397 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009398
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309399 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009400 hdd_err("invalid pktlog value %d", set_value);
9401 return -EINVAL;
9402 }
9403
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309404 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9405 if (set_value2 <= 0) {
9406 hdd_err("invalid pktlog size %d", set_value2);
9407 return -EINVAL;
9408 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9409 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9410 return -EINVAL;
9411 }
9412 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309413 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9414 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309415 }
9416
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009417 /*
9418 * set_value = 0 then disable packetlog
9419 * set_value = 1 enable packetlog forcefully
9420 * set_vlaue = 2 then disable packetlog if disabled through ini or
9421 * enable packetlog with AUTO type.
9422 */
9423 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9424 true : false;
9425
9426 if (1 == set_value) {
9427 enable = true;
9428 user_triggered = 1;
9429 }
9430
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309431 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009432}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009433
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009434/**
9435 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9436 * @hdd_ctx: HDD context
9437 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309438 * @user_triggered: triggered through iwpriv
9439 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009440 *
9441 * Return: 0 on success; error number otherwise
9442 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009443int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309444 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009445{
9446 struct sir_wifi_start_log start_log;
9447 QDF_STATUS status;
9448
9449 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9450 start_log.verbose_level =
9451 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009452 start_log.ini_triggered = cds_is_packet_log_enabled();
9453 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309454 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309455 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309456 /*
9457 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9458 * commands. Host uses this flag to decide whether to send pktlog
9459 * disable command to fw without sending pktlog enable command
9460 * previously. For eg, If vendor sends pktlog disable command without
9461 * sending pktlog enable command, then host discards the packet
9462 * but for iwpriv command, host will send it to fw.
9463 */
9464 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009465 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9466 if (!QDF_IS_STATUS_SUCCESS(status)) {
9467 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009468 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009469 return -EINVAL;
9470 }
9471
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309472 if (enable == true)
9473 hdd_ctx->is_pktlog_enabled = 1;
9474 else
9475 hdd_ctx->is_pktlog_enabled = 0;
9476
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009477 return 0;
9478}
9479#endif /* REMOVE_PKT_LOG */
9480
Komal Seelam92fff912016-03-24 11:51:41 +05309481/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009482 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9483 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309484 * @dev: Device Pointer
9485 * @num: Number of Valid Mac address
9486 *
9487 * Return: Pointer to MAC address buffer
9488 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009489static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9490 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309491{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009492 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309493}
Komal Seelam92fff912016-03-24 11:51:41 +05309494
9495/**
9496 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9497 * @hdd_ctx: HDD Context
9498 * @num: Number of random mac addresses needed
9499 *
9500 * Generate random addresses using bit manipulation on the base mac address
9501 *
9502 * Return: None
9503 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009504void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309505{
9506 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9507 uint32_t iter;
9508 struct hdd_config *ini = hdd_ctx->config;
9509 uint8_t *buf = NULL;
9510 uint8_t macaddr_b3, tmp_br3;
9511 uint8_t *src = ini->intfMacAddr[0].bytes;
9512
9513 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9514 buf = ini->intfMacAddr[iter].bytes;
9515 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9516 macaddr_b3 = buf[3];
9517 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9518 INTF_MACADDR_MASK;
9519 macaddr_b3 += tmp_br3;
9520 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9521 buf[0] |= 0x02;
9522 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009523 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309524 }
9525}
9526
9527/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009528 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309529 * @hdd_ctx: HDD Context
9530 *
9531 * API to get mac addresses from platform driver and update the driver
9532 * structures and configure FW with the base mac address.
9533 * Return: int
9534 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009535static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309536{
9537 uint32_t no_of_mac_addr, iter;
9538 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9539 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9540 uint8_t *addr, *buf;
9541 struct device *dev = hdd_ctx->parent_dev;
9542 struct hdd_config *ini = hdd_ctx->config;
9543 tSirMacAddr mac_addr;
9544 QDF_STATUS status;
9545
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009546 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309547
9548 if (no_of_mac_addr == 0 || !addr) {
9549 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9550 return -EINVAL;
9551 }
9552
9553 if (no_of_mac_addr > max_mac_addr)
9554 no_of_mac_addr = max_mac_addr;
9555
9556 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9557
9558 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9559 buf = ini->intfMacAddr[iter].bytes;
9560 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009561 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309562 }
9563
9564 status = sme_set_custom_mac_addr(mac_addr);
9565
9566 if (!QDF_IS_STATUS_SUCCESS(status))
9567 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009568
Komal Seelam92fff912016-03-24 11:51:41 +05309569 if (no_of_mac_addr < max_mac_addr)
9570 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9571 no_of_mac_addr);
9572 return 0;
9573}
9574
9575/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009576 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9577 * @hdd_ctx: HDD Context
9578 *
9579 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9580 * will generate its own MAC and update it to FW.
9581 *
9582 * Return: 0 for success
9583 * Non-zero error code for failure
9584 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009585static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009586{
9587 tSirMacAddr customMacAddr;
9588 QDF_STATUS status;
9589
9590 qdf_mem_copy(&customMacAddr,
9591 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9592 sizeof(tSirMacAddr));
9593 status = sme_set_custom_mac_addr(customMacAddr);
9594 if (!QDF_IS_STATUS_SUCCESS(status))
9595 return -EAGAIN;
9596 return 0;
9597}
9598
9599/**
Komal Seelam92fff912016-03-24 11:51:41 +05309600 * hdd_initialize_mac_address() - API to get wlan mac addresses
9601 * @hdd_ctx: HDD Context
9602 *
9603 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9604 * is provisioned with mac addresses, driver uses it, else it will use
9605 * wlan_mac.bin to update HW MAC addresses.
9606 *
9607 * Return: None
9608 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009609static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309610{
9611 QDF_STATUS status;
9612 int ret;
9613
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009614 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309615 if (ret == 0)
9616 return;
9617
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009618 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9619 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309620
9621 status = hdd_update_mac_config(hdd_ctx);
9622
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009623 if (QDF_IS_STATUS_SUCCESS(status))
9624 return;
9625
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009626 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9627 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009628
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009629 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009630 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009631 if (ret != 0) {
9632 hdd_err("MAC address out-of-sync, ret:%d", ret);
9633 QDF_ASSERT(ret);
9634 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009635 }
Komal Seelam92fff912016-03-24 11:51:41 +05309636}
9637
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009638static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009639{
9640 int vdev_id = 0;
9641 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9642 int value = hdd_ctx->config->smart_chainmask_enabled;
9643 int vpdev = PDEV_CMD;
9644 int ret;
9645
Naveen Rawat247a8682017-06-05 15:00:31 -07009646 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009647 if (ret)
9648 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9649
9650 return ret;
9651}
9652
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009653static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009654{
9655 int vdev_id = 0;
9656 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9657 int value = hdd_ctx->config->alternative_chainmask_enabled;
9658 int vpdev = PDEV_CMD;
9659 int ret;
9660
Naveen Rawat247a8682017-06-05 15:00:31 -07009661 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009662 if (ret)
9663 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9664 ret);
9665
9666 return ret;
9667}
9668
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009669static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009670{
9671 int vdev_id = 0;
9672 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9673 int value = hdd_ctx->config->ani_enabled;
9674 int vpdev = PDEV_CMD;
9675 int ret;
9676
Naveen Rawat247a8682017-06-05 15:00:31 -07009677 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009678 if (ret)
9679 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9680
9681 return ret;
9682}
9683
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009684/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009685 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9686 * @hdd_ctx: HDD context
9687 *
9688 * Pre configurations to be done at lower layer before calling cds enable.
9689 *
9690 * Return: 0 on success and errno on failure.
9691 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009692static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009693{
9694 int ret;
9695 QDF_STATUS status;
9696 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009697 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009698
Leo Changfdb45c32016-10-28 11:09:23 -07009699 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009700 /*
9701 * Set 802.11p config
9702 * TODO-OCB: This has been temporarily added here to ensure this
9703 * parameter is set in CSR when we init the channel list. This should
9704 * be removed once the 5.9 GHz channels are added to the regulatory
9705 * domain.
9706 */
9707 hdd_set_dot11p_config(hdd_ctx);
9708
9709 /*
9710 * Note that the cds_pre_enable() sequence triggers the cfg download.
9711 * The cfg download must occur before we update the SME config
9712 * since the SME config operation must access the cfg database
9713 */
9714 status = hdd_set_sme_config(hdd_ctx);
9715
9716 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009717 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009718 ret = qdf_status_to_os_return(status);
9719 goto out;
9720 }
9721
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009722 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9723 if (QDF_STATUS_SUCCESS != status) {
9724 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9725 ret = qdf_status_to_os_return(status);
9726 goto out;
9727 }
9728
Naveen Rawat247a8682017-06-05 15:00:31 -07009729 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009730 hdd_ctx->config->tx_chain_mask_1ss,
9731 PDEV_CMD);
9732 if (0 != ret) {
9733 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9734 goto out;
9735 }
9736
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009737 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9738 if (ret)
9739 goto out;
9740
9741 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9742 if (ret)
9743 goto out;
9744
Jeff Johnson12a744b2017-04-04 08:19:37 -07009745 ret = hdd_set_ani_enabled(hdd_ctx);
9746 if (ret)
9747 goto out;
9748
Naveen Rawat247a8682017-06-05 15:00:31 -07009749 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009750 hdd_ctx->config->arp_ac_category,
9751 PDEV_CMD);
9752 if (0 != ret) {
9753 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9754 hdd_ctx->config->arp_ac_category, ret);
9755 goto out;
9756 }
9757
Prashanth Bhatta07998752016-04-28 12:35:33 -07009758 status = hdd_set_sme_chan_list(hdd_ctx);
9759 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009760 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009761 ret = qdf_status_to_os_return(status);
9762 goto out;
9763 }
9764
9765 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009766 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009767 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009768 ret = -EINVAL;
9769 goto out;
9770 }
9771
Prashanth Bhatta07998752016-04-28 12:35:33 -07009772 /*
9773 * Set the MAC Address Currently this is used by HAL to add self sta.
9774 * Remove this once self sta is added as part of session open.
9775 */
9776 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9777 hdd_ctx->config->intfMacAddr[0].bytes,
9778 sizeof(hdd_ctx->config->intfMacAddr[0]));
9779
9780 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9781 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9782 hal_status, hal_status);
9783 ret = -EINVAL;
9784 goto out;
9785 }
9786
9787 hdd_init_channel_avoidance(hdd_ctx);
9788
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309789 /* update enable sap mandatory chan list */
9790 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9791 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009792out:
9793 return ret;
9794}
9795
9796/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009797 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9798 * @context_ptr - hdd context pointer
9799 * @event_ptr - event structure pointer
9800 *
9801 * This is the p2p listen offload stop event handler, it sends vendor
9802 * event back to supplicant to notify the stop reason.
9803 *
9804 * Return: None
9805 */
9806static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9807 void *event_ptr)
9808{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009809 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009810 struct sir_p2p_lo_event *evt = event_ptr;
9811 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009812 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009813
Dustin Brown491d54b2018-03-14 12:39:11 -07009814 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009815
9816 if (hdd_ctx == NULL) {
9817 hdd_err("Invalid HDD context pointer");
9818 return;
9819 }
9820
Peng Xu5c682812017-08-06 07:39:13 -07009821 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9822 if (!adapter) {
9823 hdd_err("Cannot find adapter by vdev_id = %d",
9824 evt->vdev_id);
9825 return;
9826 }
9827
Peng Xu8fdaa492016-06-22 10:20:47 -07009828 vendor_event =
9829 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009830 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009831 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9832 GFP_KERNEL);
9833
9834 if (!vendor_event) {
9835 hdd_err("cfg80211_vendor_event_alloc failed");
9836 return;
9837 }
9838
9839 if (nla_put_u32(vendor_event,
9840 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9841 evt->reason_code)) {
9842 hdd_err("nla put failed");
9843 kfree_skb(vendor_event);
9844 return;
9845 }
9846
9847 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009848 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9849 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009850}
9851
9852/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309853 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9854 * @hdd_ctx: HDD context
9855 *
9856 * This function sends the adaptive dwell time config configuration to the
9857 * firmware via WMA
9858 *
9859 * Return: 0 - success, < 0 - failure
9860 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009861static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309862{
9863 QDF_STATUS status;
9864 struct adaptive_dwelltime_params dwelltime_params;
9865
9866 dwelltime_params.is_enabled =
9867 hdd_ctx->config->adaptive_dwell_mode_enabled;
9868 dwelltime_params.dwelltime_mode =
9869 hdd_ctx->config->global_adapt_dwelltime_mode;
9870 dwelltime_params.lpf_weight =
9871 hdd_ctx->config->adapt_dwell_lpf_weight;
9872 dwelltime_params.passive_mon_intval =
9873 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9874 dwelltime_params.wifi_act_threshold =
9875 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9876
9877 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9878 &dwelltime_params);
9879
9880 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9881 if (!QDF_IS_STATUS_SUCCESS(status)) {
9882 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9883 return -EAGAIN;
9884 }
9885 return 0;
9886}
9887
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009888int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309889{
9890 QDF_STATUS status;
9891 struct wmi_dbs_scan_sel_params dbs_scan_params;
9892 uint32_t i = 0;
9893 uint8_t count = 0, numentries = 0;
9894 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9895 * CDS_DBS_SCAN_CLIENTS_MAX];
9896
9897 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +05309898 if ((hdd_ctx->config->dual_mac_feature_disable ==
9899 DISABLE_DBS_CXN_AND_SCAN) ||
9900 (hdd_ctx->config->dual_mac_feature_disable ==
9901 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309902 return -EINVAL;
9903
9904 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9905 dbs_scan_config, &numentries,
9906 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9907 * CDS_DBS_SCAN_CLIENTS_MAX));
9908
9909 hdd_info("numentries %hu", numentries);
9910 if (!numentries) {
9911 hdd_info("Donot send scan_selection_config");
9912 return 0;
9913 }
9914
9915 /* hdd_set_fw_log_params */
9916 dbs_scan_params.num_clients = 0;
9917 while (count < (numentries - 2)) {
9918 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9919 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9920 dbs_scan_params.num_non_dbs_scans[i] =
9921 dbs_scan_config[count + 2];
9922 dbs_scan_params.num_clients++;
9923 hdd_debug("module:%d NDS:%d NNDS:%d",
9924 dbs_scan_params.module_id[i],
9925 dbs_scan_params.num_dbs_scans[i],
9926 dbs_scan_params.num_non_dbs_scans[i]);
9927 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9928 i++;
9929 }
9930
9931 dbs_scan_params.pdev_id = 0;
9932
9933 hdd_debug("clients:%d pdev:%d",
9934 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9935
9936 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9937 &dbs_scan_params);
9938 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9939 if (!QDF_IS_STATUS_SUCCESS(status)) {
9940 hdd_err("Failed to send DBS Scan selection configuration!");
9941 return -EAGAIN;
9942 }
9943 return 0;
9944}
9945
Arun Khandavallid4349a92016-07-25 11:10:43 +05309946#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9947/**
9948 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9949 * @hdd_ctx: HDD context
9950 *
9951 * Set auto shutdown callback to get indications from firmware to indicate
9952 * userspace to shutdown WLAN after a configured amount of inactivity.
9953 *
9954 * Return: 0 on success and errno on failure.
9955 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009956static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309957{
9958 QDF_STATUS status;
9959
9960 if (!hdd_ctx->config->WlanAutoShutdown)
9961 return 0;
9962
9963 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9964 wlan_hdd_auto_shutdown_cb);
9965 if (status != QDF_STATUS_SUCCESS)
9966 hdd_err("Auto shutdown feature could not be enabled: %d",
9967 status);
9968
9969 return qdf_status_to_os_return(status);
9970}
9971#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009972static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309973{
9974 return 0;
9975}
9976#endif
9977
9978/**
9979 * hdd_features_init() - Init features
9980 * @hdd_ctx: HDD context
9981 * @adapter: Primary adapter context
9982 *
9983 * Initialize features and their feature context after WLAN firmware is up.
9984 *
9985 * Return: 0 on success and errno on failure.
9986 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009987static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309988{
9989 tSirTxPowerLimit hddtxlimit;
9990 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309991 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309992 int ret;
9993
Dustin Brown491d54b2018-03-14 12:39:11 -07009994 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309995
Arun Khandavallid4349a92016-07-25 11:10:43 +05309996 /* FW capabilities received, Set the Dot11 mode */
9997 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009998 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9999 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010000
Arun Khandavallid4349a92016-07-25 11:10:43 +053010001
10002 if (hdd_ctx->config->fIsImpsEnabled)
10003 hdd_set_idle_ps_config(hdd_ctx, true);
10004 else
10005 hdd_set_idle_ps_config(hdd_ctx, false);
10006
Poddar, Siddarth37033032017-10-11 15:47:40 +053010007 /* Send Enable/Disable data stall detection cmd to FW */
10008 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10009 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10010
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010011 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010012 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010013
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010014 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
10015 hdd_warn("Error in setting Voltage Corner mode config to FW");
10016
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010017 if (hdd_rx_ol_init(hdd_ctx))
10018 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010019
10020 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10021 hdd_err("Unable to send adaptive dwelltime setting to FW");
10022
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010023 if (hdd_dbs_scan_selection_init(hdd_ctx))
10024 hdd_err("Unable to send DBS scan selection setting to FW");
10025
Arun Khandavallid4349a92016-07-25 11:10:43 +053010026 ret = hdd_init_thermal_info(hdd_ctx);
10027 if (ret) {
10028 hdd_err("Error while initializing thermal information");
10029 goto deregister_frames;
10030 }
10031
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010032 /**
10033 * In case of SSR/PDR, if pktlog was enabled manually before
10034 * SSR/PDR, Then enabled it again automatically after Wlan
10035 * device up.
10036 */
10037 if (cds_is_driver_recovering()) {
10038 if (hdd_ctx->is_pktlog_enabled)
10039 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +080010040 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010041
Arun Khandavallid4349a92016-07-25 11:10:43 +053010042 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10043 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
10044 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
10045 if (!QDF_IS_STATUS_SUCCESS(status))
10046 hdd_err("Error setting txlimit in sme: %d", status);
10047
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010048 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010049
Arun Khandavallid4349a92016-07-25 11:10:43 +053010050 ret = hdd_register_cb(hdd_ctx);
10051 if (ret) {
10052 hdd_err("Failed to register HDD callbacks!");
10053 goto deregister_frames;
10054 }
10055
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010056 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10057 status = sme_enable_disable_chanavoidind_event(
10058 hdd_ctx->hHal, 0);
10059 if (!QDF_IS_STATUS_SUCCESS(status)) {
10060 hdd_err("Failed to disable Chan Avoidance Indication");
10061 goto deregister_cb;
10062 }
10063 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010064
Manjeet Singha9cae432017-02-28 11:58:22 +053010065 if (hdd_ctx->config->enable_5g_band_pref) {
10066 band_pref_params.rssi_boost_threshold_5g =
10067 hdd_ctx->config->rssi_boost_threshold_5g;
10068 band_pref_params.rssi_boost_factor_5g =
10069 hdd_ctx->config->rssi_boost_factor_5g;
10070 band_pref_params.max_rssi_boost_5g =
10071 hdd_ctx->config->max_rssi_boost_5g;
10072 band_pref_params.rssi_penalize_threshold_5g =
10073 hdd_ctx->config->rssi_penalize_threshold_5g;
10074 band_pref_params.rssi_penalize_factor_5g =
10075 hdd_ctx->config->rssi_penalize_factor_5g;
10076 band_pref_params.max_rssi_penalize_5g =
10077 hdd_ctx->config->max_rssi_penalize_5g;
10078 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
10079 }
10080
Arun Khandavallid4349a92016-07-25 11:10:43 +053010081 /* register P2P Listen Offload event callback */
10082 if (wma_is_p2p_lo_capable())
10083 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
10084 wlan_hdd_p2p_lo_event_callback);
10085
10086 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10087
10088 if (ret)
10089 goto deregister_cb;
10090
Dustin Brown11638b72018-01-25 17:37:25 +053010091 wlan_hdd_init_chan_info(hdd_ctx);
10092
Dustin Browne74003f2018-03-14 12:51:58 -070010093 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010094 return 0;
10095
10096deregister_cb:
10097 hdd_deregister_cb(hdd_ctx);
10098deregister_frames:
10099 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010100 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010101}
10102
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010103/**
10104 * hdd_features_deinit() - Deinit features
10105 * @hdd_ctx: HDD context
10106 *
10107 * De-Initialize features and their feature context.
10108 *
10109 * Return: none.
10110 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010111static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010112{
Dustin Brown11638b72018-01-25 17:37:25 +053010113 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010114 wlan_hdd_tsf_deinit(hdd_ctx);
10115}
10116
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010117/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010118 * hdd_register_bcn_cb() - register scan beacon callback
10119 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010120 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010121 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010122 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010123static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010124{
10125 QDF_STATUS status;
10126
10127 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10128 wlan_cfg80211_inform_bss_frame,
10129 SCAN_CB_TYPE_INFORM_BCN);
10130 if (!QDF_IS_STATUS_SUCCESS(status)) {
10131 hdd_err("failed with status code %08d [x%08x]",
10132 status, status);
10133 return status;
10134 }
10135
10136 return QDF_STATUS_SUCCESS;
10137}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010138
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010139/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010140 * hdd_configure_cds() - Configure cds modules
10141 * @hdd_ctx: HDD context
10142 * @adapter: Primary adapter context
10143 *
10144 * Enable Cds modules after WLAN firmware is up.
10145 *
10146 * Return: 0 on success and errno on failure.
10147 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010148int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +053010149{
10150 int ret;
10151 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010152 int set_value;
10153 uint32_t num_abg_tx_chains = 0;
10154 uint32_t num_11b_tx_chains = 0;
10155 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010156 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010157
10158 if (hdd_ctx->config->sifs_burst_duration) {
10159 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
10160 hdd_ctx->config->sifs_burst_duration;
10161
10162 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
10163 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
10164 set_value, PDEV_CMD);
10165 }
10166
10167 if (hdd_ctx->config->is_force_1x1)
10168 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10169 1, PDEV_CMD);
10170 /* set chip power save failure detected callback */
10171 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
10172 hdd_chip_pwr_save_fail_detected_cb);
10173
10174 if (hdd_ctx->config->max_mpdus_inampdu) {
10175 set_value = hdd_ctx->config->max_mpdus_inampdu;
10176 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10177 set_value, PDEV_CMD);
10178 }
10179
10180 if (hdd_ctx->config->enable_rts_sifsbursting) {
10181 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10182 sme_cli_set_command(0,
10183 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10184 set_value, PDEV_CMD);
10185 }
10186
10187 if (hdd_ctx->config->sap_get_peer_info) {
10188 set_value = hdd_ctx->config->sap_get_peer_info;
10189 sme_cli_set_command(0,
10190 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10191 set_value, PDEV_CMD);
10192 }
10193
10194 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10195 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10196 if (!hdd_ctx->config->enable2x2) {
10197 if (num_11b_tx_chains > 1)
10198 num_11b_tx_chains = 1;
10199 if (num_11ag_tx_chains > 1)
10200 num_11ag_tx_chains = 1;
10201 }
10202 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10203 num_11b_tx_chains);
10204 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10205 num_11ag_tx_chains);
10206 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10207 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010208
10209 ret = hdd_pre_enable_configure(hdd_ctx);
10210 if (ret) {
10211 hdd_err("Failed to pre-configure cds");
10212 goto out;
10213 }
10214
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010215 /* Always get latest IPA resources allocated from cds_open and configure
10216 * IPA module before configuring them to FW. Sequence required as crash
10217 * observed otherwise.
10218 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010219 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10220 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010221 hdd_err("Failed to setup pipes");
10222 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010223 }
10224
Arun Khandavallifae92942016-08-01 13:31:08 +053010225 /*
10226 * Start CDS which starts up the SME/MAC/HAL modules and everything
10227 * else
10228 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010229 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010230
10231 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010232 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010233 goto out;
10234 }
10235
10236 status = hdd_post_cds_enable_config(hdd_ctx);
10237 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010238 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010239 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010240 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010241 status = hdd_register_bcn_cb(hdd_ctx);
10242 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010243 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010244 goto cds_disable;
10245 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010246
10247 ret = hdd_features_init(hdd_ctx, adapter);
10248 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010249 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010250
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010251 if (hdd_ctx->ol_enable)
10252 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10253 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010254 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010255 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010256 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10257 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010258 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010259 goto cds_disable;
10260 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010261 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10262 wlan_hdd_send_mode_change_event);
10263 if (!QDF_IS_STATUS_SUCCESS(status)) {
10264 hdd_debug("Failed to register mode change cb with Policy Manager");
10265 goto cds_disable;
10266 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010267
Jeff Johnson8bb61112018-03-31 13:33:54 -070010268 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010269 hdd_debug("enhance green ap is not enabled");
10270
Nachiket Kukadedd302662017-07-13 17:31:44 +053010271 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10272 hdd_debug("Failed to set wow pulse");
10273
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010274 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10275 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010276 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10277 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10278
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010279
10280 if (hdd_ctx->config->enable_phy_reg_retention)
10281 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10282 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10283
Arun Khandavallifae92942016-08-01 13:31:08 +053010284 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010285
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010286cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010287 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010288
Arun Khandavallifae92942016-08-01 13:31:08 +053010289out:
10290 return -EINVAL;
10291}
10292
10293/**
10294 * hdd_deconfigure_cds() -De-Configure cds
10295 * @hdd_ctx: HDD context
10296 *
10297 * Deconfigure Cds modules before WLAN firmware is down.
10298 *
10299 * Return: 0 on success and errno on failure.
10300 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010301static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010302{
10303 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010304 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010305
Dustin Brown491d54b2018-03-14 12:39:11 -070010306 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010307
10308 /* De-init features */
10309 hdd_features_deinit(hdd_ctx);
10310
Arun Khandavallifae92942016-08-01 13:31:08 +053010311 /* De-register the SME callbacks */
10312 hdd_deregister_cb(hdd_ctx);
10313
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010314 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10315 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10316 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10317 }
10318
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010319 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010320 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10321 hdd_err("Failed to Disable the CDS Modules! :%d",
10322 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010323 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010324 }
10325
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010326 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010327 hdd_err("Failed to disconnect pipes");
10328 ret = -EINVAL;
10329 }
10330
Dustin Browne74003f2018-03-14 12:51:58 -070010331 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010332 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010333}
10334
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010335#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10336static void hdd_deregister_policy_manager_callback(
10337 struct wlan_objmgr_psoc *psoc)
10338{
10339 if (QDF_STATUS_SUCCESS !=
10340 policy_mgr_deregister_hdd_cb(psoc)) {
10341 hdd_err("HDD callback deregister with policy manager failed");
10342 }
10343}
10344#else
10345static void hdd_deregister_policy_manager_callback(
10346 struct wlan_objmgr_psoc *psoc)
10347{
10348}
10349#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010350
10351/**
10352 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10353 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010354 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010355 *
10356 * This function maintains the driver state machine it will be invoked from
10357 * exit, shutdown and con_mode change handler. Depending on the driver state
10358 * shall perform the stopping/closing of the modules.
10359 *
10360 * Return: 0 for success; non-zero for failure
10361 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010362int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010363{
10364 void *hif_ctx;
10365 qdf_device_t qdf_ctx;
10366 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010367 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010368 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010369 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10370 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010371 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010372 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010373
Dustin Brown491d54b2018-03-14 12:39:11 -070010374 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010375 hdd_alert("stop WLAN module: entering driver status=%d",
10376 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010377
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010378 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10379
Arun Khandavallifae92942016-08-01 13:31:08 +053010380 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10381 if (!qdf_ctx) {
10382 hdd_err("QDF device context NULL");
10383 return -EINVAL;
10384 }
10385
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010386 mutex_lock(&hdd_ctx->iface_change_lock);
10387 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010388 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010389
Dustin Brown70111822017-03-30 15:31:40 -070010390 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010391 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010392 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010393 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010394
10395 cds_print_external_threads();
10396
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010397 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010398 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010399 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10400 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010401 hdd_prevent_suspend_timeout(
10402 hdd_ctx->config->iface_change_wait_time,
10403 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010404 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010405 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010406 return 0;
10407 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010408 }
10409
Arun Khandavallifae92942016-08-01 13:31:08 +053010410 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10411
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010412 /* free user wowl patterns */
10413 hdd_free_user_wowl_ptrns();
10414
Arun Khandavallifae92942016-08-01 13:31:08 +053010415 switch (hdd_ctx->driver_status) {
10416 case DRIVER_MODULES_UNINITIALIZED:
10417 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010418 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010419 case DRIVER_MODULES_CLOSED:
10420 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010421 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010422 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010423 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10424
Komal Seelamf2136bb2016-09-28 18:30:44 +053010425 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010426 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010427 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010428 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010429 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010430 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010431 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010432
Arun Khandavallifae92942016-08-01 13:31:08 +053010433 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010434 hdd_info("Wlan transitioned (now OPENED)");
10435
10436 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010437 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010438 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010439 break;
10440 default:
10441 hdd_err("Trying to stop wlan in a wrong state: %d",
10442 hdd_ctx->driver_status);
10443 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010444 ret = -EINVAL;
10445 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010446 }
10447
Amar Singhal18081642018-01-26 16:04:13 -080010448 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010449 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010450
Rajeev Kumarbe021242017-02-16 16:12:23 -080010451 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010452 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10453 hdd_err("Failed to process post CDS disable Modules! :%d",
10454 qdf_status);
10455 ret = -EINVAL;
10456 QDF_ASSERT(0);
10457 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010458
psimhadeea0a12017-12-18 14:50:02 -080010459 hdd_runtime_suspend_context_deinit(hdd_ctx);
10460
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010461 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10462 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10463 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10464 ret = -EINVAL;
10465 QDF_ASSERT(0);
10466 }
10467
Jeff Johnsone4b14592017-09-13 14:23:33 -070010468 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010469 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010470 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010471 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010472 QDF_ASSERT(0);
10473 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010474
Amar Singhal410675c2018-01-10 12:14:21 -080010475 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010476 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10477 if (ret) {
10478 hdd_err("Failed to destroy pdev; errno:%d", ret);
10479 QDF_ASSERT(0);
10480 }
10481
10482 /*
10483 * Reset total mac phy during module stop such that during
10484 * next module start same psoc is used to populate new service
10485 * ready data
10486 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010487 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10488 if (tgt_hdl)
10489 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10490
Liangwei Dong50a64a72018-01-11 01:17:00 -050010491
Arun Khandavallifae92942016-08-01 13:31:08 +053010492 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10493 if (!hif_ctx) {
10494 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010495 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010496 }
10497
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010498 if (hdd_ctx->target_hw_name) {
10499 qdf_mem_free(hdd_ctx->target_hw_name);
10500 hdd_ctx->target_hw_name = NULL;
10501 }
10502
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010503 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010504
10505 ol_cds_free();
10506
Dustin Brown70111822017-03-30 15:31:40 -070010507 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010508 ret = pld_power_off(qdf_ctx->dev);
10509 if (ret)
10510 hdd_err("CNSS power down failed put device into Low power mode:%d",
10511 ret);
10512 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010513
Dustin Brown4bc0a622017-12-06 15:56:50 -080010514 /* many adapter resources are not freed by design in SSR case */
10515 if (!is_recovery_stop)
10516 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010517 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010518
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010519 /* Once the firmware sequence is completed reset this flag */
10520 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010521 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010522 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010523
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010524done:
10525 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010526 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010527 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010528 hdd_alert("stop WLAN module: exit driver status=%d",
10529 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010530
Dustin Browne74003f2018-03-14 12:51:58 -070010531 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010532
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010533 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010534}
10535
Arun Khandavallifae92942016-08-01 13:31:08 +053010536
Wen Gong3f003382018-05-14 14:26:37 +080010537#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053010538/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010539 * hdd_state_info_dump() - prints state information of hdd layer
10540 * @buf: buffer pointer
10541 * @size: size of buffer to be filled
10542 *
10543 * This function is used to dump state information of hdd layer
10544 *
10545 * Return: None
10546 */
10547static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10548{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010549 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010550 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010551 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010552 uint16_t len = 0;
10553 char *buf = *buf_ptr;
10554
10555 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10556 if (!hdd_ctx) {
10557 hdd_err("Failed to get hdd context ");
10558 return;
10559 }
10560
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010561 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010562
10563 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010564 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010565 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010566 "\n is_scheduler_suspended %d",
10567 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010568
Dustin Brown920397d2017-12-13 16:27:50 -080010569 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010570 if (adapter->dev)
10571 len += scnprintf(buf + len, *size - len,
10572 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010573 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010574 "\n device_mode: %d", adapter->device_mode);
10575 switch (adapter->device_mode) {
10576 case QDF_STA_MODE:
10577 case QDF_P2P_CLIENT_MODE:
10578 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10579 len += scnprintf(buf + len, *size - len,
10580 "\n connState: %d",
10581 hdd_sta_ctx->conn_info.connState);
10582 break;
10583
10584 default:
10585 break;
10586 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010587 }
10588
10589 *size -= len;
10590 *buf_ptr += len;
10591}
10592
10593/**
10594 * hdd_register_debug_callback() - registration function for hdd layer
10595 * to print hdd state information
10596 *
10597 * Return: None
10598 */
10599static void hdd_register_debug_callback(void)
10600{
10601 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10602}
Wen Gong3f003382018-05-14 14:26:37 +080010603#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080010604static void hdd_register_debug_callback(void)
10605{
10606}
Wen Gong3f003382018-05-14 14:26:37 +080010607#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010608
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010609/*
10610 * wlan_init_bug_report_lock() - Initialize bug report lock
10611 *
10612 * This function is used to create bug report lock
10613 *
10614 * Return: None
10615 */
10616static void wlan_init_bug_report_lock(void)
10617{
10618 p_cds_contextType p_cds_context;
10619
10620 p_cds_context = cds_get_global_context();
10621 if (!p_cds_context) {
10622 hdd_err("cds context is NULL");
10623 return;
10624 }
10625
10626 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10627}
10628
Mohit Khannaf8f96822017-05-17 17:11:59 -070010629void hdd_dp_trace_init(struct hdd_config *config)
10630{
10631
10632 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10633 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10634 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10635 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10636 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10637 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10638 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010639 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010640
10641 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10642 &num_entries, sizeof(config_params));
10643
10644 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010645 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010646 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010647 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010648 else if (bw_compute_interval > 1000) {
10649 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10650 thresh_time_limit = 1;
10651 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010652 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10653
10654 switch (num_entries) {
10655 case 4:
10656 proto_bitmap = config_params[3];
10657 case 3:
10658 verbosity = config_params[2];
10659 case 2:
10660 thresh = config_params[1];
10661 case 1:
10662 live_mode = config_params[0];
10663 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010664 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010665 live_mode, thresh, thresh_time_limit,
10666 verbosity, proto_bitmap);
10667 };
10668
10669 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10670 verbosity, proto_bitmap);
10671
10672}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010673/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010674 * hdd_wlan_startup() - HDD init function
10675 * @dev: Pointer to the underlying device
10676 *
10677 * This is the driver startup code executed once a WLAN device has been detected
10678 *
10679 * Return: 0 for success, < 0 for failure
10680 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010681int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010682{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010683 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010684 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010685 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010686 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010687
Dustin Brown491d54b2018-03-14 12:39:11 -070010688 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010689
Arun Khandavallifae92942016-08-01 13:31:08 +053010690 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010691
10692 if (IS_ERR(hdd_ctx))
10693 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010694
Abhishek Singhe9068f12017-03-31 14:14:52 +053010695 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10696 DEFAULT_PSOC_ID);
10697 if (ret) {
10698 hdd_err("Psoc creation fails!");
10699 QDF_BUG(0);
10700 goto err_hdd_free_context;
10701 }
10702
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010703 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010704#ifdef FEATURE_WLAN_CH_AVOID
10705 mutex_init(&hdd_ctx->avoid_freq_lock);
10706#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010707
Naveen Rawate02f8f52018-04-05 11:58:04 -070010708 osif_request_manager_init();
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010709 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010710 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010711
Dustin Brown021cecd2017-12-11 13:56:43 -080010712 hdd_driver_memdump_init();
10713
Jeff Johnson957bc272017-02-02 08:54:48 -080010714 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010715 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010716 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010717 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010718 }
10719
Yingying Tang80e15f32016-09-27 18:23:01 +080010720 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010721
Anurag Chouhan6d760662016-02-20 16:05:43 +053010722 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010723
10724 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010725 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010726 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010727 }
10728
Prashanth Bhatta07998752016-04-28 12:35:33 -070010729 ret = hdd_wiphy_init(hdd_ctx);
10730 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010731 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010732 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010733 }
10734
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010735 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010736 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010737
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010738 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010739
Paul Zhangfb02f452017-12-22 11:58:43 +080010740 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10741 if (ret) {
10742 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010743 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080010744 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010745
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010746 ret = register_reboot_notifier(&system_reboot_notifier);
10747 if (ret) {
10748 hdd_err("Failed to register reboot notifier: %d", ret);
10749 goto err_unregister_netdev;
10750 }
10751
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010752 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010753
Jeff Johnson957bc272017-02-02 08:54:48 -080010754 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10755 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010756 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010757 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010758 }
10759
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010760 hdd_release_rtnl_lock();
10761 rtnl_held = false;
10762
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010763 wlan_hdd_update_11n_mode(hdd_ctx->config);
10764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010765#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010766 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010767 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010768 hdd_skip_acs_scan_timer_handler,
10769 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010770 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010771 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010772 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010773#endif
10774
Prashanth Bhattaab004382016-10-11 16:08:11 -070010775 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010776
Jeff Johnson9afc5012016-09-23 13:56:27 -070010777 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010778
Nirav Shahbd36b062016-07-18 11:12:59 +053010779 if (hdd_ctx->rps)
10780 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010781
Paul Zhangfb02f452017-12-22 11:58:43 +080010782 ret = hdd_register_notifiers(hdd_ctx);
10783 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010784 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010785
Paul Zhangfb02f452017-12-22 11:58:43 +080010786 status = wlansap_global_init();
10787 if (QDF_IS_STATUS_ERROR(status)) {
10788 hdd_unregister_notifiers(hdd_ctx);
10789 goto err_close_adapters;
10790 }
10791
Arun Khandavallifae92942016-08-01 13:31:08 +053010792 if (hdd_ctx->config->fIsImpsEnabled)
10793 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010794 else
10795 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010796
Mukul Sharma07bd8752017-10-10 16:58:14 +053010797 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010798 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10799 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010800 hdd_prevent_suspend_timeout(
10801 hdd_ctx->config->iface_change_wait_time,
10802 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10803 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010804
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010805 goto success;
10806
Jeff Johnson957bc272017-02-02 08:54:48 -080010807err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010808 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010809
Jeff Johnson46bde382017-02-01 15:31:16 -080010810err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010811 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010812 if (rtnl_held)
10813 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010814
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010815err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010816 unregister_netdevice_notifier(&hdd_netdev_notifier);
10817
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010818err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010819 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010820
Arun Khandavallifae92942016-08-01 13:31:08 +053010821err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010822 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010823
Dustin Brown021cecd2017-12-11 13:56:43 -080010824err_memdump_deinit:
10825 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010826
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010827 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070010828 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010829 hdd_exit_netlink_services(hdd_ctx);
10830
Dustin Brown20912462017-06-07 13:48:25 -070010831 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10832
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010833err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010834 if (cds_is_fw_down())
10835 hdd_err("Not setting the complete event as fw is down");
10836 else
10837 hdd_start_complete(ret);
10838
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010839 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010840 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010841 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010842
10843success:
Dustin Browne74003f2018-03-14 12:51:58 -070010844 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010845 return 0;
10846}
10847
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010848/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010849 * hdd_wlan_update_target_info() - update target type info
10850 * @hdd_ctx: HDD context
10851 * @context: hif context
10852 *
10853 * Update target info received from firmware in hdd context
10854 * Return:None
10855 */
10856
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010857void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010858{
10859 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10860
10861 if (!tgt_info) {
10862 hdd_err("Target info is Null");
10863 return;
10864 }
10865
10866 hdd_ctx->target_type = tgt_info->target_type;
10867}
10868
10869/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010870 * hdd_get_nud_stats_cb() - callback api to update the stats
10871 * received from the firmware
10872 * @data: pointer to adapter.
10873 * @rsp: pointer to data received from FW.
10874 *
10875 * This is called when wlan driver received response event for
10876 * get arp stats to firmware.
10877 *
10878 * Return: None
10879 */
10880static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10881{
10882 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10883 struct hdd_nud_stats_context *context;
10884 int status;
10885 struct hdd_adapter *adapter = NULL;
10886
Dustin Brown491d54b2018-03-14 12:39:11 -070010887 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010888
10889 if (!rsp) {
10890 hdd_err("data is null");
10891 return;
10892 }
10893
10894 status = wlan_hdd_validate_context(hdd_ctx);
10895 if (0 != status)
10896 return;
10897
10898 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10899 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10900 hdd_err("Invalid adapter or adapter has invalid magic");
10901 return;
10902 }
10903
Dustin Brown5e89ef82018-03-14 11:50:23 -070010904 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10905 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10906 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10907 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10908 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10909 rsp->out_of_order_arp_rsp_drop_cnt);
10910 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
10911 hdd_info("rsp->connect_status :%x", rsp->connect_status);
10912 hdd_info("rsp->ba_session_establishment_status :%x",
10913 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010914
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010915 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010916 adapter->dad |= rsp->dad_detected;
10917 adapter->con_status = rsp->connect_status;
10918
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053010919 /* Flag true indicates connectivity check stats present. */
10920 if (rsp->connect_stats_present) {
10921 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
10922 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
10923 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
10924 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
10925 rsp->icmpv4_rsp_recvd;
10926 }
10927
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010928 spin_lock(&hdd_context_lock);
10929 context = &hdd_ctx->nud_stats_context;
10930 complete(&context->response_event);
10931 spin_unlock(&hdd_context_lock);
10932
Dustin Browne74003f2018-03-14 12:51:58 -070010933 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010934}
10935
10936/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010937 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010938 * @hdd_ctx: HDD context
10939 *
10940 * Register the HDD callbacks to CDS/SME.
10941 *
10942 * Return: 0 for success or Error code for failure
10943 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010944int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010945{
10946 QDF_STATUS status;
10947 int ret = 0;
10948
Dustin Brown491d54b2018-03-14 12:39:11 -070010949 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010950
10951 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10952
10953 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10954 hdd_send_oem_data_rsp_msg);
10955
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010956 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10957 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010958 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10959 sme_nan_register_callback(hdd_ctx->hHal,
10960 wlan_hdd_cfg80211_nan_callback);
10961 sme_stats_ext_register_callback(hdd_ctx->hHal,
10962 wlan_hdd_cfg80211_stats_ext_callback);
10963
10964 sme_ext_scan_register_callback(hdd_ctx->hHal,
10965 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010966 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10967 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010968
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010969 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10970 hdd_rssi_threshold_breached);
10971
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010972 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10973
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010974 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10975 wlan_hdd_cfg80211_link_layer_stats_callback);
10976
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010977 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10978
Zhang Qianca38fb12016-12-23 11:10:48 +080010979 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10980 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10981
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010982 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10983 hdd_lost_link_info_cb);
10984 /* print error and not block the startup process */
10985 if (!QDF_IS_STATUS_SUCCESS(status))
10986 hdd_err("set lost link info callback failed");
10987
Poddar, Siddarth34872782017-08-10 14:08:51 +053010988 ret = hdd_register_data_stall_detect_cb();
10989 if (ret) {
10990 hdd_err("Register data stall detect detect callback failed.");
10991 return ret;
10992 }
10993
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010994 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10995
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010996 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010997 hdd_set_connection_in_progress,
10998 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010999
11000 status = sme_congestion_register_callback(hdd_ctx->hHal,
11001 hdd_update_cca_info_cb);
11002 if (!QDF_IS_STATUS_SUCCESS(status))
11003 hdd_err("set congestion callback failed");
11004
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011005 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
11006 hdd_bt_activity_cb);
11007 if (!QDF_IS_STATUS_SUCCESS(status))
11008 hdd_err("set bt activity info callback failed");
11009
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011010 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
11011 hdd_tx_queue_cb);
11012 if (!QDF_IS_STATUS_SUCCESS(status))
11013 hdd_err("Register tx queue callback failed");
11014
Dustin Browne74003f2018-03-14 12:51:58 -070011015 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011016
11017 return ret;
11018}
11019
11020/**
11021 * hdd_deregister_cb() - De-Register HDD callbacks.
11022 * @hdd_ctx: HDD context
11023 *
11024 * De-Register the HDD callbacks to CDS/SME.
11025 *
11026 * Return: void
11027 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011028void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011029{
11030 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011031 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011032
Dustin Brown491d54b2018-03-14 12:39:11 -070011033 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011034
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011035 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011036 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
11037 if (!QDF_IS_STATUS_SUCCESS(status))
11038 hdd_err("De-register of dcc stats callback failed: %d",
11039 status);
11040
11041 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011042 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
11043
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011044 sme_stats_ext_register_callback(hdd_ctx->hHal,
11045 wlan_hdd_cfg80211_stats_ext_callback);
11046
11047 sme_nan_deregister_callback(hdd_ctx->hHal);
11048 status = sme_reset_tsfcb(hdd_ctx->hHal);
11049 if (!QDF_IS_STATUS_SUCCESS(status))
11050 hdd_err("Failed to de-register tsfcb the callback:%d",
11051 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011052
Poddar, Siddarth34872782017-08-10 14:08:51 +053011053 ret = hdd_deregister_data_stall_detect_cb();
11054 if (ret)
11055 hdd_err("Failed to de-register data stall detect event callback");
11056
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011057 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
11058 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
11059
Dustin Browne74003f2018-03-14 12:51:58 -070011060 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011061}
11062
11063/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011064 * hdd_softap_sta_deauth() - handle deauth req from HDD
11065 * @adapter: Pointer to the HDD
11066 * @enable: bool value
11067 *
11068 * This to take counter measure to handle deauth req from HDD
11069 *
11070 * Return: None
11071 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011072QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011073 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011074{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011075 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011076
Dustin Brown491d54b2018-03-14 12:39:11 -070011077 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011078
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011079 /* Ignore request to deauth bcmc station */
11080 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011081 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011082
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011083 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011084 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11085 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011086
Dustin Browne74003f2018-03-14 12:51:58 -070011087 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011088 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011089}
11090
11091/**
11092 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11093 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011094 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011095 *
11096 * This to take counter measure to handle deauth req from HDD
11097 *
11098 * Return: None
11099 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011100void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011101 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011102{
Dustin Brown491d54b2018-03-14 12:39:11 -070011103 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011105 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011106 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011107 return;
11108
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011109 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011110 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011111}
11112
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011113/**
11114 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11115 * @hdd_ctx: HDD Context
11116 *
11117 * API to find if there is any STA or P2P-Client is connected
11118 *
11119 * Return: true if connected; false otherwise
11120 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011121QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011122{
11123 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
11124}
11125
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011126/**
11127 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
11128 * @adapter: HDD adapter pointer
11129 *
11130 * This function loop through each adapter and disable roaming on each STA
11131 * device mode except the input adapter.
11132 *
11133 * Note: On the input adapter roaming is not enabled yet hence no need to
11134 * disable.
11135 *
11136 * Return: None
11137 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011138void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011139{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011140 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011141 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011142
11143 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011144 hdd_ctx->config->isRoamOffloadScanEnabled &&
11145 QDF_STA_MODE == adapter->device_mode &&
11146 policy_mgr_is_sta_active_connection_exists(
11147 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011148 hdd_debug("Connect received on STA session Id(%d)",
11149 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011150 /*
11151 * Loop through adapter and disable roaming for each STA device
11152 * mode except the input adapter.
11153 */
Dustin Brown920397d2017-12-13 16:27:50 -080011154 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011155 if (QDF_STA_MODE == adapterIdx->device_mode &&
11156 adapter->session_id != adapterIdx->session_id) {
11157 hdd_debug("Disable Roaming on session Id(%d)",
11158 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011159 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
11160 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011161 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011162 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011163 }
11164 }
11165}
11166
11167/**
11168 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
11169 * @adapter: HDD adapter pointer
11170 *
11171 * This function loop through each adapter and enable roaming on each STA
11172 * device mode except the input adapter.
11173 * Note: On the input adapter no need to enable roaming because link got
11174 * disconnected on this.
11175 *
11176 * Return: None
11177 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011178void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011179{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011180 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011181 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011182
11183 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011184 hdd_ctx->config->isRoamOffloadScanEnabled &&
11185 QDF_STA_MODE == adapter->device_mode &&
11186 policy_mgr_is_sta_active_connection_exists(
11187 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011188 hdd_debug("Disconnect received on STA session Id(%d)",
11189 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011190 /*
11191 * Loop through adapter and enable roaming for each STA device
11192 * mode except the input adapter.
11193 */
Dustin Brown920397d2017-12-13 16:27:50 -080011194 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011195 if (QDF_STA_MODE == adapterIdx->device_mode &&
11196 adapter->session_id != adapterIdx->session_id) {
11197 hdd_debug("Enabling Roaming on session Id(%d)",
11198 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011199 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
11200 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011201 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011202 REASON_CONNECT);
11203 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011204 }
11205 }
11206}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011207
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011208/**
11209 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11210 * @skb: sk buffer pointer
11211 *
11212 * Sends the bcast message to SVC multicast group with generic nl socket
11213 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11214 *
11215 * Return: None
11216 */
11217static void nl_srv_bcast_svc(struct sk_buff *skb)
11218{
11219#ifdef CNSS_GENL
11220 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11221#else
11222 nl_srv_bcast(skb);
11223#endif
11224}
11225
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011226void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011227{
11228 struct sk_buff *skb;
11229 struct nlmsghdr *nlh;
11230 tAniMsgHdr *ani_hdr;
11231 void *nl_data = NULL;
11232 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011233 struct radio_index_tlv *radio_info;
11234 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011235
11236 if (in_interrupt() || irqs_disabled() || in_atomic())
11237 flags = GFP_ATOMIC;
11238
11239 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11240
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011241 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011242 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011243
11244 nlh = (struct nlmsghdr *)skb->data;
11245 nlh->nlmsg_pid = 0; /* from kernel */
11246 nlh->nlmsg_flags = 0;
11247 nlh->nlmsg_seq = 0;
11248 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11249
11250 ani_hdr = NLMSG_DATA(nlh);
11251 ani_hdr->type = type;
11252
11253 switch (type) {
11254 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011255 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011256 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011257 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011258 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011259 ani_hdr->length = 0;
11260 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011261 break;
11262 case WLAN_SVC_WLAN_STATUS_IND:
11263 case WLAN_SVC_WLAN_VERSION_IND:
11264 case WLAN_SVC_DFS_CAC_START_IND:
11265 case WLAN_SVC_DFS_CAC_END_IND:
11266 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11267 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11268 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011269 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011270 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011271 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011272 ani_hdr->length = len;
11273 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11274 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11275 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011276 break;
11277
11278 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011279 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011280 type);
11281 kfree_skb(skb);
11282 return;
11283 }
11284
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011285 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011286 * Add radio index at the end of the svc event in TLV format
11287 * to maintain the backward compatibility with userspace
11288 * applications.
11289 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011290
11291 tlv_len = 0;
11292
11293 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11294 < WLAN_NL_MAX_PAYLOAD) {
11295 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11296 sizeof(*ani_hdr) + len);
11297 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11298 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11299 radio_info->radio = radio;
11300 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011301 hdd_debug("Added radio index tlv - radio index %d",
11302 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011303 }
11304
11305 nlh->nlmsg_len += tlv_len;
11306 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11307
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011308 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011309}
11310
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011311#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11312void wlan_hdd_auto_shutdown_cb(void)
11313{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011314 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011315
11316 if (!hdd_ctx)
11317 return;
11318
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011319 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011320 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11321 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011322}
11323
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011324void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011325{
Jeff Johnson9d295242017-08-29 14:39:48 -070011326 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011327 bool ap_connected = false, sta_connected = false;
11328 tHalHandle hal_handle;
11329
11330 hal_handle = hdd_ctx->hHal;
11331 if (hal_handle == NULL)
11332 return;
11333
11334 if (hdd_ctx->config->WlanAutoShutdown == 0)
11335 return;
11336
11337 if (enable == false) {
11338 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011339 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011340 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011341 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011342 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011343 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011344 return;
11345 }
11346
11347 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011348 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11349 hdd_for_each_adapter(hdd_ctx, adapter) {
11350 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011351 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11352 conn_info.connState ==
11353 eConnectionState_Associated) {
11354 sta_connected = true;
11355 break;
11356 }
11357 }
Dustin Brown920397d2017-12-13 16:27:50 -080011358
11359 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011360 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011361 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011362 ap_connected = true;
11363 break;
11364 }
11365 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011366 }
11367 }
11368
11369 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011370 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011371 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011372 }
Jeff Johnson68755312017-02-10 11:46:55 -080011373
11374 if (sme_set_auto_shutdown_timer(hal_handle,
11375 hdd_ctx->config->WlanAutoShutdown)
11376 != QDF_STATUS_SUCCESS)
11377 hdd_err("Failed to start wlan auto shutdown timer");
11378 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011379 hdd_info("Auto Shutdown timer for %d seconds enabled",
11380 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011381}
11382#endif
11383
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011384struct hdd_adapter *
11385hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11386 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011387{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011388 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011389 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011390
11391 con_sap_adapter = NULL;
11392
Dustin Brown920397d2017-12-13 16:27:50 -080011393 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011394 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11395 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011396 adapter != this_sap_adapter) {
11397 if (check_start_bss) {
11398 if (test_bit(SOFTAP_BSS_STARTED,
11399 &adapter->event_flags)) {
11400 con_sap_adapter = adapter;
11401 break;
11402 }
11403 } else {
11404 con_sap_adapter = adapter;
11405 break;
11406 }
11407 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011408 }
11409
11410 return con_sap_adapter;
11411}
11412
11413#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011414static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011415{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011416 return adapter->device_mode == QDF_STA_MODE ||
11417 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011418}
11419
Jeff Johnson9d295242017-08-29 14:39:48 -070011420static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011421{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011422 return adapter->device_mode == QDF_SAP_MODE ||
11423 adapter->device_mode == QDF_P2P_GO_MODE;
11424}
11425
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011426static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011427{
Dustin Brown920397d2017-12-13 16:27:50 -080011428 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011429
Dustin Brown920397d2017-12-13 16:27:50 -080011430 hdd_for_each_adapter(hdd_ctx, adapter) {
11431 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011432 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11433 conn_info.connState == eConnectionState_Associated) {
11434 return true;
11435 }
11436
Dustin Brown920397d2017-12-13 16:27:50 -080011437 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011438 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011439 return true;
11440 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011441 }
11442
11443 return false;
11444}
11445
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011446static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011447{
11448 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011449
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011450 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011451 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011452 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011453
Dustin Brown5ec6b552017-03-31 12:11:40 -070011454 return is_running;
11455}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011456
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011457static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011458{
11459 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11460 hdd_ctx->bus_bw_timer_running = true;
11461 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11462 hdd_ctx->config->busBandwidthComputeInterval);
11463 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11464}
11465
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011466void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011467{
Dustin Brown491d54b2018-03-14 12:39:11 -070011468 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011469
11470 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11471 hdd_debug("Bandwidth compute timer already started");
11472 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011473 }
11474
Dustin Brown5ec6b552017-03-31 12:11:40 -070011475 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11476
Dustin Browne74003f2018-03-14 12:51:58 -070011477 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011478}
11479
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011480void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011481{
Dustin Brown491d54b2018-03-14 12:39:11 -070011482 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011483
11484 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11485 hdd_debug("Bandwidth compute timer already started");
11486 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011487 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011488
11489 if (hdd_any_adapter_is_assoc(hdd_ctx))
11490 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11491
Dustin Browne74003f2018-03-14 12:51:58 -070011492 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011493}
11494
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011495static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011496{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011497 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011498
11499 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11500 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11501 hdd_ctx->bus_bw_timer_running = false;
11502 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11503
11504 hdd_reset_tcp_delack(hdd_ctx);
11505}
11506
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011507void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011508{
Dustin Brown491d54b2018-03-14 12:39:11 -070011509 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011510
11511 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11512 hdd_debug("Bandwidth compute timer already stopped");
11513 return;
11514 }
11515
11516 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11517
Dustin Browne74003f2018-03-14 12:51:58 -070011518 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011519}
11520
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011521void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011522{
Dustin Brown491d54b2018-03-14 12:39:11 -070011523 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011524
11525 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11526 hdd_debug("Bandwidth compute timer already stopped");
11527 return;
11528 }
11529
11530 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11531 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11532
Dustin Browne74003f2018-03-14 12:51:58 -070011533 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011534}
11535#endif
11536
11537/**
11538 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11539 * and sta's operating channel.
11540 * @sta_adapter: Describe the first argument to foobar.
11541 * @ap_adapter: Describe the second argument to foobar.
11542 * @roam_profile: Roam profile of AP to which STA wants to connect.
11543 * @concurrent_chnl_same: If both SAP and STA channels are same then
11544 * set this flag to true else false.
11545 *
11546 * This function checks the sap's operating channel and sta's operating channel.
11547 * if both are same then it will return false else it will restart the sap in
11548 * sta's channel and return true.
11549 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011550 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011551 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011552QDF_STATUS
11553wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11554 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011555 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011556 tScanResultHandle *scan_cache,
11557 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011558{
Jeff Johnson87251032017-08-29 13:31:11 -070011559 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011560 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011561 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011562 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011563 *concurrent_chnl_same = true;
11564
11565 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11566 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011567 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011568 scan_cache,
11569 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011570 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011571 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011572 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011573 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011574 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011575 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011576 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011577 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011578 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011579 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011580 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011581 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011582 }
11583 }
11584 } else {
11585 /*
11586 * Lets handle worst case scenario here, Scan cache lookup is
11587 * failed so we have to stop the SAP to avoid any channel
11588 * discrepancy between SAP's channel and STA's channel.
11589 * Return the status as failure so caller function could know
11590 * that scan look up is failed.
11591 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011592 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011593 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011594 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011595 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011596}
11597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011598/**
11599 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11600 * @ap_adapter: SAP adapter
11601 *
11602 * This function will process the stopping of sap adapter.
11603 *
11604 * Return: None
11605 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011606void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011607{
Jeff Johnson87251032017-08-29 13:31:11 -070011608 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011609 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011610 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011611 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011612
11613 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011614 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011615 return;
11616 }
11617
11618 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11619 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011620 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011621 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011622
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011623 mutex_lock(&hdd_ctx->sap_lock);
11624 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011625 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011626 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011627 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011628 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011629 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011630 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011631 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011632 qdf_stop_bss_event,
11633 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011634 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011635 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011636 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011637 return;
11638 }
11639 }
11640 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011641 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11642 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011643 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011644 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011645 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011646 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011647 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011648 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011649 }
11650 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011651}
11652
11653/**
11654 * wlan_hdd_start_sap() - this function starts bss of SAP.
11655 * @ap_adapter: SAP adapter
11656 *
11657 * This function will process the starting of sap adapter.
11658 *
11659 * Return: None
11660 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011661void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011662{
Jeff Johnson87251032017-08-29 13:31:11 -070011663 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011664 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011665 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011666 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070011667 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011668
11669 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011670 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011671 return;
11672 }
11673
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011674 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011675 hdd_err("SoftAp role has not been enabled");
11676 return;
11677 }
11678
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011679 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11680 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11681 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011682 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011683
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011684 mutex_lock(&hdd_ctx->sap_lock);
11685 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11686 goto end;
11687
11688 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011689 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011690 goto end;
11691 }
11692
Wei Song2f76f642016-11-18 16:32:53 +080011693 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011694 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011695 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011696 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011697 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011698 goto end;
11699
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011700 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011701 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011702 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011703 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011704 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011705 goto end;
11706 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011707 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011708 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011709 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011710 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011711 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11712 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011713 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011714 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011715 true);
11716 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011717 mutex_unlock(&hdd_ctx->sap_lock);
11718
11719 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011720end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011721 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011722 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011723 /* SAP context and beacon cleanup will happen during driver unload
11724 * in hdd_stop_adapter
11725 */
11726 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11727
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011728}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011729
11730/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011731 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11732 * mac scan config
11733 * @status: Status of set antenna mode
11734 *
11735 * Callback on setting the dual mac configuration
11736 *
11737 * Return: None
11738 */
11739void wlan_hdd_soc_set_antenna_mode_cb(
11740 enum set_antenna_mode_status status)
11741{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011742 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011743
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011744 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011745
11746 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11747 if (0 != wlan_hdd_validate_context(hdd_ctx))
11748 return;
11749
11750 /* Signal the completion of set dual mac config */
11751 complete(&hdd_ctx->set_antenna_mode_cmpl);
11752}
11753
11754/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011755 * hdd_get_fw_version() - Get FW version
11756 * @hdd_ctx: pointer to HDD context.
11757 * @major_spid: FW version - major spid.
11758 * @minor_spid: FW version - minor spid
11759 * @ssid: FW version - ssid
11760 * @crmid: FW version - crmid
11761 *
11762 * This function is called to get the firmware build version stored
11763 * as part of the HDD context
11764 *
11765 * Return: None
11766 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011767void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011768 uint32_t *major_spid, uint32_t *minor_spid,
11769 uint32_t *siid, uint32_t *crmid)
11770{
11771 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11772 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11773 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11774 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11775}
11776
11777#ifdef QCA_CONFIG_SMP
11778/**
11779 * wlan_hdd_get_cpu() - get cpu_index
11780 *
11781 * Return: cpu_index
11782 */
11783int wlan_hdd_get_cpu(void)
11784{
11785 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011786
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011787 put_cpu();
11788 return cpu_index;
11789}
11790#endif
11791
11792/**
11793 * hdd_get_fwpath() - get framework path
11794 *
11795 * This function is used to get the string written by
11796 * userspace to start the wlan driver
11797 *
11798 * Return: string
11799 */
11800const char *hdd_get_fwpath(void)
11801{
11802 return fwpath.string;
11803}
11804
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011805static int hdd_qdf_print_init(void)
11806{
11807 int qdf_print_idx;
11808 QDF_STATUS status;
11809
11810 status = qdf_print_setup();
11811 if (status != QDF_STATUS_SUCCESS) {
11812 pr_err("qdf_print_setup failed\n");
11813 return -EINVAL;
11814 }
11815
11816 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11817
11818 if (qdf_print_idx < 0) {
11819 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11820 qdf_print_idx);
11821 return -EINVAL;
11822 }
11823
11824 qdf_set_pidx(qdf_print_idx);
11825
11826 return 0;
11827}
11828
11829static void hdd_qdf_print_deinit(void)
11830{
11831 int qdf_print_idx;
11832
11833 qdf_print_idx = qdf_get_pidx();
11834 qdf_print_ctrl_cleanup(qdf_print_idx);
11835}
11836
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011837/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011838 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011839 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011840 * This function initilizes CDS global context with the help of cds_init. This
11841 * has to be the first function called after probe to get a valid global
11842 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011843 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011844 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011845 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011846int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011847{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011848 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011849 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011850
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011851 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011852 if (QDF_IS_STATUS_ERROR(status)) {
11853 hdd_err("Failed to allocate CDS context");
11854 ret = -ENOMEM;
11855 goto err_out;
11856 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011857
11858 wlan_init_bug_report_lock();
11859
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011860#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11861 wlan_logging_sock_init_svc();
11862#endif
11863
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011864 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11865 (void *)hdd_drv_ops_inactivity_handler, NULL,
11866 QDF_TIMER_TYPE_SW);
11867
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011868 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011869 hdd_qdf_print_init();
11870
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011871 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011872
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011873err_out:
11874 return ret;
11875}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011876
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011877/**
11878 * hdd_deinit() - Deinitialize Driver
11879 *
11880 * This function frees CDS global context with the help of cds_deinit. This
11881 * has to be the last function call in remove callback to free the global
11882 * context.
11883 */
11884void hdd_deinit(void)
11885{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011886 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011887
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011888 wlan_destroy_bug_report_lock();
11889 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011890
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011891 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011892#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11893 wlan_logging_sock_deinit_svc();
11894#endif
11895}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011896
Yue Ma6e7b1a02017-04-03 14:17:46 -070011897#ifdef QCA_WIFI_NAPIER_EMULATION
11898#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11899#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011900#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011901#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011902
Sachin Ahujadddd2632017-03-07 19:07:24 +053011903static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11904 struct file *file)
11905{
11906 return 0;
11907}
11908
11909static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11910 const char __user *user_buf,
11911 size_t count,
11912 loff_t *f_pos)
11913{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011914 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011915 static const char wlan_off_str[] = "OFF";
11916 static const char wlan_on_str[] = "ON";
11917 int ret;
11918 unsigned long rc;
11919
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011920 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011921 pr_err("Failed to read buffer\n");
11922 return -EINVAL;
11923 }
11924
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011925 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011926 pr_debug("Wifi turning off from UI\n");
11927 goto exit;
11928 }
11929
Sachin Ahuja16904db2017-12-13 19:56:57 +053011930 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
11931 pr_info("Wifi Turning On from UI\n");
11932 }
11933
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011934 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011935 pr_err("Invalid value received from framework");
11936 goto exit;
11937 }
11938
11939 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011940 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011941 rc = wait_for_completion_timeout(&wlan_start_comp,
11942 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11943 if (!rc) {
11944 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11945 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053011946 return ret;
11947 }
11948
11949 hdd_start_complete(0);
11950 }
11951
11952exit:
11953 return count;
11954}
11955
11956
11957const struct file_operations wlan_hdd_state_fops = {
11958 .owner = THIS_MODULE,
11959 .open = wlan_hdd_state_ctrl_param_open,
11960 .write = wlan_hdd_state_ctrl_param_write,
11961};
11962
11963static int wlan_hdd_state_ctrl_param_create(void)
11964{
11965 unsigned int wlan_hdd_state_major = 0;
11966 int ret;
11967 struct device *dev;
11968
11969 device = MKDEV(wlan_hdd_state_major, 0);
11970
11971 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11972 if (ret) {
11973 pr_err("Failed to register qcwlanstate");
11974 goto dev_alloc_err;
11975 }
11976 wlan_hdd_state_major = MAJOR(device);
11977
11978 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11979 if (IS_ERR(class)) {
11980 pr_err("wlan_hdd_state class_create error");
11981 goto class_err;
11982 }
11983
11984 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11985 if (IS_ERR(dev)) {
11986 pr_err("wlan_hdd_statedevice_create error");
11987 goto err_class_destroy;
11988 }
11989
11990 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11991 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11992 if (ret) {
11993 pr_err("Failed to add cdev error");
11994 goto cdev_add_err;
11995 }
11996
11997 pr_info("wlan_hdd_state %s major(%d) initialized",
11998 WLAN_MODULE_NAME, wlan_hdd_state_major);
11999
12000 return 0;
12001
12002cdev_add_err:
12003 device_destroy(class, device);
12004err_class_destroy:
12005 class_destroy(class);
12006class_err:
12007 unregister_chrdev_region(device, dev_num);
12008dev_alloc_err:
12009 return -ENODEV;
12010}
12011
12012static void wlan_hdd_state_ctrl_param_destroy(void)
12013{
12014 cdev_del(&wlan_hdd_state_cdev);
12015 device_destroy(class, device);
12016 class_destroy(class);
12017 unregister_chrdev_region(device, dev_num);
12018
12019 pr_info("Device node unregistered");
12020}
12021
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012022/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053012023 * component_init - API to init cld component's
12024 *
12025 * Return: None
12026 */
12027static void component_init(void)
12028{
12029 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012030 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012031 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012032 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012033}
12034
12035/**
12036 * component_deinit - API to deinit cld component's
12037 *
12038 * Return: None
12039 */
12040static void component_deinit(void)
12041{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012042 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012043 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012044 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012045 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012046}
12047
12048void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12049{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012050 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012051 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012052}
12053
12054void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12055{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012056 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012057 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012058}
12059
12060/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012061 * __hdd_module_init - Module init helper
12062 *
12063 * Module init helper function used by both module and static driver.
12064 *
12065 * Return: 0 for success, errno on failure
12066 */
12067static int __hdd_module_init(void)
12068{
12069 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012070
Dustin Brown96cd9632017-11-13 12:45:04 -080012071 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012072 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012073 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012074 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012075
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012076 pld_init();
12077
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012078 ret = hdd_init();
12079 if (ret) {
12080 pr_err("hdd_init failed %x\n", ret);
12081 goto err_hdd_init;
12082 }
12083
Rajeev Kumar97767a02016-11-30 11:20:40 -080012084 dispatcher_init();
12085
Mukul Sharmad75a6672017-06-22 15:40:53 +053012086 /* Ensure to call post objmgr init */
12087 component_init();
12088
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012089 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012090
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012091 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012092
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012093 ret = wlan_hdd_register_driver();
12094 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012095 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12096 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012097 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012098 }
12099
Sachin Ahuja16904db2017-12-13 19:56:57 +053012100 ret = wlan_hdd_state_ctrl_param_create();
12101 if (ret) {
12102 pr_err("wlan_hdd_state_create:%x\n", ret);
12103 goto out;
12104 }
12105
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012106 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012107
12108 return 0;
12109out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012110 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012111 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012112 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012113 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012114
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012115err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012116 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012117 return ret;
12118}
12119
12120/**
12121 * __hdd_module_exit - Module exit helper
12122 *
12123 * Module exit helper function used by both module and static driver.
12124 */
12125static void __hdd_module_exit(void)
12126{
Will Huang36049722018-04-13 11:48:51 +080012127 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012128
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012129 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12130 QWLAN_VERSIONSTR);
12131
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012132 if (!hdd_wait_for_recovery_completion())
12133 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012134
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012135 if (hdd_ctx)
12136 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012137
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012138 wlan_hdd_unregister_driver();
12139
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012140 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012141
Mukul Sharmad75a6672017-06-22 15:40:53 +053012142 /* Ensure to call prior to objmgr deinit */
12143 component_deinit();
12144
Rajeev Kumar97767a02016-11-30 11:20:40 -080012145 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012146
12147 hdd_sysfs_destroy_version_interface();
12148
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012149 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012150 pld_deinit();
12151
Sachin Ahujadddd2632017-03-07 19:07:24 +053012152 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012153}
12154
Arun Khandavallifae92942016-08-01 13:31:08 +053012155#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012156/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012157 * wlan_boot_cb() - Wlan boot callback
12158 * @kobj: object whose directory we're creating the link in.
12159 * @attr: attribute the user is interacting with
12160 * @buff: the buffer containing the user data
12161 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012162 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012163 * This callback is invoked when the fs is ready to start the
12164 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012165 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012166 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012167 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012168static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012169 struct kobj_attribute *attr,
12170 const char *buf,
12171 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012172{
Arun Khandavallifae92942016-08-01 13:31:08 +053012173
Arun Khandavallifae92942016-08-01 13:31:08 +053012174 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012175 pr_err("%s: wlan driver already initialized\n", __func__);
12176 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012177 }
12178
Arun Khandavallifae92942016-08-01 13:31:08 +053012179 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012180 pr_err("%s: wlan driver initialization failed\n", __func__);
12181 return -EIO;
12182 }
12183
12184 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012185
12186 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012187}
Arun Khandavallifae92942016-08-01 13:31:08 +053012188
12189/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012190 * hdd_sysfs_cleanup() - cleanup sysfs
12191 *
12192 * Return: None
12193 *
12194 */
12195static void hdd_sysfs_cleanup(void)
12196{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012197 /* remove from group */
12198 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12199 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12200 wlan_loader->attr_group);
12201
12202 /* unlink the object from parent */
12203 kobject_del(wlan_loader->boot_wlan_obj);
12204
12205 /* free the object */
12206 kobject_put(wlan_loader->boot_wlan_obj);
12207
12208 kfree(wlan_loader->attr_group);
12209 kfree(wlan_loader);
12210
12211 wlan_loader = NULL;
12212}
12213
12214/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012215 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12216 * ready
12217 *
12218 * This is creates the syfs entry boot_wlan. Which shall be invoked
12219 * when the filesystem is ready.
12220 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012221 * QDF API cannot be used here since this function is called even before
12222 * initializing WLAN driver.
12223 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012224 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012225 */
12226static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012227{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012228 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012229
12230 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012231 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012232 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012233
12234 wlan_loader->boot_wlan_obj = NULL;
12235 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12236 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012237 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012238 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012239
12240 wlan_loader->loaded_state = 0;
12241 wlan_loader->attr_group->attrs = attrs;
12242
12243 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12244 kernel_kobj);
12245 if (!wlan_loader->boot_wlan_obj) {
12246 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012247 goto error_return;
12248 }
12249
12250 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12251 wlan_loader->attr_group);
12252 if (ret) {
12253 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12254 goto error_return;
12255 }
12256
12257 return 0;
12258
12259error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012260 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012261
12262 return ret;
12263}
12264
12265/**
12266 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12267 *
12268 * Return: 0 on success or errno on failure
12269 */
12270static int wlan_deinit_sysfs(void)
12271{
Arun Khandavallifae92942016-08-01 13:31:08 +053012272 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012273 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012274 return -EINVAL;
12275 }
12276
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012277 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012278 return 0;
12279}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012280
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012281#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012282
12283#ifdef MODULE
12284/**
12285 * __hdd_module_init - Module init helper
12286 *
12287 * Module init helper function used by both module and static driver.
12288 *
12289 * Return: 0 for success, errno on failure
12290 */
12291static int hdd_module_init(void)
12292{
Arun Khandavallifae92942016-08-01 13:31:08 +053012293 if (__hdd_module_init()) {
12294 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012295 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012296 }
12297
Dustin Brownab482ac2017-06-09 17:00:44 -070012298 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012299}
12300#else
12301static int __init hdd_module_init(void)
12302{
12303 int ret = -EINVAL;
12304
12305 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012306 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012307 pr_err("Failed to create sysfs entry for loading wlan");
12308
12309 return ret;
12310}
12311#endif
12312
12313
12314#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012315/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012316 * hdd_module_exit() - Exit function
12317 *
12318 * This is the driver exit point (invoked when module is unloaded using rmmod)
12319 *
12320 * Return: None
12321 */
12322static void __exit hdd_module_exit(void)
12323{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012324 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012325}
Arun Khandavallifae92942016-08-01 13:31:08 +053012326#else
12327static void __exit hdd_module_exit(void)
12328{
12329 __hdd_module_exit();
12330 wlan_deinit_sysfs();
12331}
12332#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012333
Srinivas Girigowda841da292018-02-21 16:33:00 -080012334static int fwpath_changed_handler(const char *kmessage,
12335 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012336{
12337 return param_set_copystring(kmessage, kp);
12338}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012339
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012340/**
12341 * is_con_mode_valid() check con mode is valid or not
12342 * @mode: global con mode
12343 *
12344 * Return: TRUE on success FALSE on failure
12345 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012346static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012347{
12348 switch (mode) {
12349 case QDF_GLOBAL_MONITOR_MODE:
12350 case QDF_GLOBAL_FTM_MODE:
12351 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012352 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012353 return true;
12354 default:
12355 return false;
12356 }
12357}
12358
12359/**
12360 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12361 * @mode: global con mode
12362 *
12363 * Return: adapter mode
12364 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012365static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012366 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012367{
12368
12369 switch (mode) {
12370 case QDF_GLOBAL_MISSION_MODE:
12371 return QDF_STA_MODE;
12372 case QDF_GLOBAL_MONITOR_MODE:
12373 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012374 case QDF_GLOBAL_EPPING_MODE:
12375 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012376 case QDF_GLOBAL_FTM_MODE:
12377 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012378 case QDF_GLOBAL_QVIT_MODE:
12379 return QDF_QVIT_MODE;
12380 default:
12381 return QDF_MAX_NO_OF_MODE;
12382 }
12383}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012384
Dustin Brown27cd9942017-09-27 16:11:44 -070012385static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012386 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012387{
12388 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12389 return;
12390
12391 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012392 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012393 hdd_info("Release wakelock for monitor mode!");
12394 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12395 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012396 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012397 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012398 case QDF_GLOBAL_FTM_MODE:
12399 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012400 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012401 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012402
Dustin Brown27cd9942017-09-27 16:11:44 -070012403 break;
12404 default:
12405 break;
12406 }
12407}
12408
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012409static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012410 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012411{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012412 int driver_status;
12413
12414 driver_status = hdd_ctx->driver_status;
12415
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012416 switch (curr_mode) {
12417 case QDF_GLOBAL_MISSION_MODE:
12418 case QDF_GLOBAL_MONITOR_MODE:
12419 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012420 hdd_deinit_all_adapters(hdd_ctx, false);
12421 hdd_close_all_adapters(hdd_ctx, false);
12422 break;
12423 case QDF_GLOBAL_EPPING_MODE:
12424 epping_disable();
12425 epping_close();
12426 break;
12427 default:
12428 return;
12429 }
12430}
12431
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012432static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012433 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012434{
Jeff Johnson9d295242017-08-29 14:39:48 -070012435 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012436 int ret = 0;
12437 bool rtnl_held;
12438 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12439 QDF_STATUS status;
12440
12441 if (!qdf_dev) {
12442 hdd_err("qdf device context is Null return!");
12443 return -EINVAL;
12444 }
12445
12446 rtnl_held = hdd_hold_rtnl_lock();
12447 switch (mode) {
12448 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012449 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12450 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012451 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012452 break;
12453 case QDF_GLOBAL_FTM_MODE:
12454 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12455 wlan_hdd_get_intf_addr(hdd_ctx),
12456 NET_NAME_UNKNOWN, rtnl_held);
12457 if (adapter == NULL)
12458 ret = -EINVAL;
12459 break;
12460 case QDF_GLOBAL_MONITOR_MODE:
12461 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12462 wlan_hdd_get_intf_addr(hdd_ctx),
12463 NET_NAME_UNKNOWN, rtnl_held);
12464 if (adapter == NULL)
12465 ret = -EINVAL;
12466 break;
12467 case QDF_GLOBAL_EPPING_MODE:
12468 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012469 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012470 hdd_err("Failed to open in eeping mode: %d", status);
12471 ret = -EINVAL;
12472 break;
12473 }
12474 ret = epping_enable(qdf_dev->dev);
12475 if (ret) {
12476 hdd_err("Failed to enable in epping mode : %d", ret);
12477 epping_close();
12478 }
12479 break;
12480 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012481 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012482 ret = -ENOTSUPP;
12483 break;
12484 }
12485 hdd_release_rtnl_lock();
12486 rtnl_held = false;
12487 return ret;
12488}
12489
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012490/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012491 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012492 * @kmessage: con mode name on which driver to be bring up
12493 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012494 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012495 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012496 * This function is invoked when user updates con mode using sys entry,
12497 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012498 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012499 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012500 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012501static int __con_mode_handler(const char *kmessage,
12502 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012503 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012504{
12505 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012506 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012507 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012508 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012509 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012510
Dustin Brownab6029b2017-05-24 13:04:19 -070012511 hdd_info("con_mode handler: %s", kmessage);
12512
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012513 ret = wlan_hdd_validate_context(hdd_ctx);
12514 if (ret)
12515 return ret;
12516
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012517 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012518 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012519
Dustin Brown20024e32018-01-03 12:34:58 -080012520 ret = kstrtoint(kmessage, 0, &new_con_mode);
12521 if (ret) {
12522 hdd_err("Failed to parse con_mode '%s'", kmessage);
12523 goto reset_flags;
12524 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012525 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012526
Dustin Brown20024e32018-01-03 12:34:58 -080012527 if (!is_con_mode_valid(new_con_mode)) {
12528 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012529 ret = -EINVAL;
12530 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012531 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012532
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012533 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012534 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012535 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012536 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012537 ret = 0;
12538 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012539 }
12540
Dustin Brown27cd9942017-09-27 16:11:44 -070012541 /* ensure adapters are stopped */
12542 hdd_stop_present_mode(hdd_ctx, curr_mode);
12543
Frank Liu6666f832018-01-04 10:06:05 +080012544 /* Cleanup present mode before switching to new mode */
12545 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12546
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012547 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012548 if (ret) {
12549 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012550 goto reset_flags;
12551 }
12552
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012553
Dustin Brown20024e32018-01-03 12:34:58 -080012554 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012555
Frank Liu6666f832018-01-04 10:06:05 +080012556 /*
12557 * Set ACTIVE domain before adapters created, otherwise check domain
12558 * match will fail when cleanup adapters.
12559 */
12560 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012561 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012562 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012563 if (ret) {
12564 hdd_err("Failed to register for new mode");
12565 goto reset_flags;
12566 }
12567
Dustin Brown20024e32018-01-03 12:34:58 -080012568 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012569 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12570 hdd_err("invalid adapter");
12571 ret = -EINVAL;
12572 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012573 }
12574
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012575 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012576 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012577 hdd_err("Failed to get adapter:%d", adapter_mode);
12578 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012579 }
12580
12581 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12582 if (ret) {
12583 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012584 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012585 }
12586
Dustin Brown20024e32018-01-03 12:34:58 -080012587 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012588 if (hdd_start_adapter(adapter)) {
12589 hdd_err("Failed to start %s adapter", kmessage);
12590 ret = -EINVAL;
12591 goto reset_flags;
12592 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012593
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012594 hdd_info("Acquire wakelock for monitor mode!");
12595 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12596 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12597 }
12598
Dustin Brown20024e32018-01-03 12:34:58 -080012599 /* con_mode is a global module parameter */
12600 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012601 hdd_info("Mode successfully changed to %s", kmessage);
12602 ret = 0;
12603
12604reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012605 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012606 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012607 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012608 return ret;
12609}
12610
12611
Srinivas Girigowda841da292018-02-21 16:33:00 -080012612static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012613{
12614 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012615 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012616
12617 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12618 ret = wlan_hdd_validate_context(hdd_ctx);
12619 if (ret)
12620 return ret;
12621
12622 cds_ssr_protect(__func__);
12623 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12624 cds_ssr_unprotect(__func__);
12625
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012626 return ret;
12627}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012628
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012629static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012630 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012631{
12632 int ret;
12633
12634 ret = param_set_int(kmessage, kp);
12635
12636 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12637 pr_err("Only FTM mode supported!");
12638 return -ENOTSUPP;
12639 }
12640
12641 hdd_set_conparam(con_mode_ftm);
12642 con_mode = con_mode_ftm;
12643
12644 return ret;
12645}
12646
Ravi Joshia307f632017-07-17 23:41:41 -070012647static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012648 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012649{
12650 int ret;
12651
12652 ret = param_set_int(kmessage, kp);
12653
12654 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12655 pr_err("Only Monitor mode supported!");
12656 return -ENOTSUPP;
12657 }
12658
12659 hdd_set_conparam(con_mode_monitor);
12660 con_mode = con_mode_monitor;
12661
12662 return ret;
12663}
12664
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012665/**
12666 * hdd_get_conparam() - driver exit point
12667 *
12668 * This is the driver exit point (invoked when module is unloaded using rmmod)
12669 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012670 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012671 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012672enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012673{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012674 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012675}
12676
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012677void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012678{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012679 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012680}
12681
Komal Seelamc11bb222016-01-27 18:57:10 +053012682/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012683 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12684 * @hdd_ctx: HDD context
12685 *
12686 * Cleans up the pre cac interface, if it exists
12687 *
12688 * Return: None
12689 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012690void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012691{
12692 uint8_t session_id;
12693 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012694 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012695
12696 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12697 if (QDF_IS_STATUS_ERROR(status)) {
12698 hdd_err("failed to get pre cac vdev id");
12699 return;
12700 }
12701
12702 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12703 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070012704 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012705 return;
12706 }
12707
12708 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12709 wlan_hdd_sap_pre_cac_failure,
12710 (void *)precac_adapter);
12711 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12712
12713}
12714
12715/**
Komal Seelamec702b02016-02-24 18:42:16 +053012716 * hdd_update_ol_config - API to update ol configuration parameters
12717 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012718 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012719 * Return: void
12720 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012721static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012722{
Komal Seelamec702b02016-02-24 18:42:16 +053012723 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012724 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012725
Komal Seelamec702b02016-02-24 18:42:16 +053012726 if (!ol_ctx)
12727 return;
12728
12729 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12730 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12731 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12732 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012733 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012734
12735 ol_init_ini_config(ol_ctx, &cfg);
12736}
12737
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012738#ifdef FEATURE_RUNTIME_PM
12739/**
12740 * hdd_populate_runtime_cfg() - populate runtime configuration
12741 * @hdd_ctx: hdd context
12742 * @cfg: pointer to the configuration memory being populated
12743 *
12744 * Return: void
12745 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012746static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012747 struct hif_config_info *cfg)
12748{
12749 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12750 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12751}
12752#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012753static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012754 struct hif_config_info *cfg)
12755{
12756}
12757#endif
12758
Komal Seelamec702b02016-02-24 18:42:16 +053012759/**
12760 * hdd_update_hif_config - API to update HIF configuration parameters
12761 * @hdd_ctx: HDD Context
12762 *
12763 * Return: void
12764 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012765static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012766{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012767 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012768 struct hif_config_info cfg;
12769
12770 if (!scn)
12771 return;
12772
12773 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012774 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012775 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012776
12777 if (hdd_ctx->config->prevent_link_down)
12778 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012779}
12780
12781/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012782 * hdd_update_dp_config() - Propagate config parameters to Lithium
12783 * datapath
12784 * @hdd_ctx: HDD Context
12785 *
12786 * Return: 0 for success/errno for failure
12787 */
12788static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12789{
12790 struct cdp_config_params params;
12791 QDF_STATUS status;
12792
12793 params.tso_enable = hdd_ctx->config->tso_enable;
12794 params.lro_enable = hdd_ctx->config->lro_enable;
12795#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12796 params.tx_flow_stop_queue_threshold =
12797 hdd_ctx->config->TxFlowStopQueueThreshold;
12798 params.tx_flow_start_queue_offset =
12799 hdd_ctx->config->TxFlowStartQueueOffset;
12800#endif
12801 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12802 params.napi_enable = hdd_ctx->napi_enable;
12803 params.tcp_udp_checksumoffload =
12804 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12805
12806 status = cdp_update_config_parameters(
12807 cds_get_context(QDF_MODULE_ID_SOC),
12808 &params);
12809 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012810 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012811 return status;
12812 }
12813
12814 return 0;
12815}
12816
12817/**
Komal Seelamec702b02016-02-24 18:42:16 +053012818 * hdd_update_config() - Initialize driver per module ini parameters
12819 * @hdd_ctx: HDD Context
12820 *
12821 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012822 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012823 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012824int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012825{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012826 int ret;
12827
Komal Seelamec702b02016-02-24 18:42:16 +053012828 hdd_update_ol_config(hdd_ctx);
12829 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012830 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12831 ret = hdd_update_cds_config_ftm(hdd_ctx);
12832 else
12833 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012834 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012835
12836 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012837}
12838
Mukul Sharma9d797a02017-01-05 20:26:03 +053012839#ifdef FEATURE_WLAN_RA_FILTERING
12840/**
12841 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12842 * @psoc_cfg: pmo psoc Configuration
12843 * @hdd_ctx: Pointer to hdd context
12844 *
12845 * Return: none
12846 */
12847static inline void hdd_ra_populate_pmo_config(
12848 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012849 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012850{
12851 psoc_cfg->ra_ratelimit_interval =
12852 hdd_ctx->config->RArateLimitInterval;
12853 psoc_cfg->ra_ratelimit_enable =
12854 hdd_ctx->config->IsRArateLimitEnabled;
12855}
12856#else
12857static inline void hdd_ra_populate_pmo_config(
12858 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012859 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012860{
12861}
12862#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012863
Mukul Sharma9d797a02017-01-05 20:26:03 +053012864/**
12865 * hdd_update_pmo_config - API to update pmo configuration parameters
12866 * @hdd_ctx: HDD context
12867 *
12868 * Return: void
12869 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012870static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012871{
Mukul Sharma9d797a02017-01-05 20:26:03 +053012872 struct pmo_psoc_cfg psoc_cfg;
12873 QDF_STATUS status;
12874
12875 /*
12876 * Value of hdd_ctx->wowEnable can be,
12877 * 0 - Disable both magic pattern match and pattern byte match.
12878 * 1 - Enable magic pattern match on all interfaces.
12879 * 2 - Enable pattern byte match on all interfaces.
12880 * 3 - Enable both magic patter and pattern byte match on
12881 * all interfaces.
12882 */
12883 psoc_cfg.magic_ptrn_enable =
12884 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12885 psoc_cfg.ptrn_match_enable_all_vdev =
12886 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080012887 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012888 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012889 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080012890 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012891 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080012892 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012893 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12894 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080012895 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012896 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012897 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053012898 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12899 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12900 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080012901 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012902 psoc_cfg.auto_power_save_fail_mode =
12903 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012904
12905 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012906 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12907 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012908
Dustin Brownb9987af2018-03-01 17:15:11 -080012909 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
12910 if (QDF_IS_STATUS_ERROR(status))
12911 hdd_err("failed pmo psoc configuration; status:%d", status);
12912
12913 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012914}
12915
Abhishek Singhb20db962017-03-03 21:28:46 +053012916#ifdef FEATURE_WLAN_SCAN_PNO
12917static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12918 struct hdd_config *cfg)
12919{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012920 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12921
Abhishek Singhb20db962017-03-03 21:28:46 +053012922 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12923 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12924 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12925 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12926 pno_cfg->channel_prediction_full_scan =
12927 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012928 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12929 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12930 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12931 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012932}
12933#else
12934static inline void
12935hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012936 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012937{
Abhishek Singhb20db962017-03-03 21:28:46 +053012938}
12939#endif
12940
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012941void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12942 struct hdd_config *cfg)
12943{
12944 uint8_t i = 0;
12945
12946 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12947 if (!ie_whitelist->white_list)
12948 return;
12949
12950 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12951 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12952 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12953 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12954 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12955 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12956 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12957 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12958
12959 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12960 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12961 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12962}
12963
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012964uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12965{
12966 uint8_t i, score;
12967
12968 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12969 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12970 if (score > MAX_INDEX_SCORE)
12971 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12972 MAX_INDEX_SCORE, i);
12973 }
12974
12975 return per_index_score;
12976}
12977
12978/**
12979 * hdd_update_score_config - API to update candidate scoring related params
12980 * configuration parameters
12981 * @score_config: score config to update
12982 * @cfg: config params
12983 *
12984 * Return: 0 if success else err
12985 */
12986static void hdd_update_score_config(
12987 struct scoring_config *score_config, struct hdd_config *cfg)
12988{
12989 int total_weight;
12990
12991 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12992 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12993 score_config->weight_cfg.vht_caps_weightage =
12994 cfg->vht_caps_weightage;
12995 score_config->weight_cfg.he_caps_weightage =
12996 cfg->he_caps_weightage;
12997 score_config->weight_cfg.chan_width_weightage =
12998 cfg->chan_width_weightage;
12999 score_config->weight_cfg.chan_band_weightage =
13000 cfg->chan_band_weightage;
13001 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
13002 score_config->weight_cfg.beamforming_cap_weightage =
13003 cfg->beamforming_cap_weightage;
13004 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
13005 score_config->weight_cfg.channel_congestion_weightage =
13006 cfg->channel_congestion_weightage;
13007 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
13008
13009 total_weight = score_config->weight_cfg.rssi_weightage +
13010 score_config->weight_cfg.ht_caps_weightage +
13011 score_config->weight_cfg.vht_caps_weightage +
13012 score_config->weight_cfg.he_caps_weightage +
13013 score_config->weight_cfg.chan_width_weightage +
13014 score_config->weight_cfg.chan_band_weightage +
13015 score_config->weight_cfg.nss_weightage +
13016 score_config->weight_cfg.beamforming_cap_weightage +
13017 score_config->weight_cfg.pcl_weightage +
13018 score_config->weight_cfg.channel_congestion_weightage +
13019 score_config->weight_cfg.oce_wan_weightage;
13020
13021 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
13022 hdd_err("total weight is greater than %d fallback to default values",
13023 BEST_CANDIDATE_MAX_WEIGHT);
13024
13025 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
13026 score_config->weight_cfg.ht_caps_weightage =
13027 HT_CAPABILITY_WEIGHTAGE;
13028 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
13029 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
13030 score_config->weight_cfg.chan_width_weightage =
13031 CHAN_WIDTH_WEIGHTAGE;
13032 score_config->weight_cfg.chan_band_weightage =
13033 CHAN_BAND_WEIGHTAGE;
13034 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
13035 score_config->weight_cfg.beamforming_cap_weightage =
13036 BEAMFORMING_CAP_WEIGHTAGE;
13037 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
13038 score_config->weight_cfg.channel_congestion_weightage =
13039 CHANNEL_CONGESTION_WEIGHTAGE;
13040 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
13041 }
13042
13043 score_config->bandwidth_weight_per_index =
13044 hdd_limit_max_per_index_score(
13045 cfg->bandwidth_weight_per_index);
13046 score_config->nss_weight_per_index =
13047 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13048 score_config->band_weight_per_index =
13049 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13050
13051 score_config->rssi_score.best_rssi_threshold =
13052 cfg->best_rssi_threshold;
13053 score_config->rssi_score.good_rssi_threshold =
13054 cfg->good_rssi_threshold;
13055 score_config->rssi_score.bad_rssi_threshold =
13056 cfg->bad_rssi_threshold;
13057 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13058 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13059 score_config->rssi_score.good_rssi_bucket_size =
13060 cfg->good_rssi_bucket_size;
13061 score_config->rssi_score.bad_rssi_bucket_size =
13062 cfg->bad_rssi_bucket_size;
13063 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13064 cfg->rssi_pref_5g_rssi_thresh;
13065
13066 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13067 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13068 hdd_limit_max_per_index_score(
13069 cfg->esp_qbss_score_slots3_to_0);
13070 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13071 hdd_limit_max_per_index_score(
13072 cfg->esp_qbss_score_slots7_to_4);
13073 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13074 hdd_limit_max_per_index_score(
13075 cfg->esp_qbss_score_slots11_to_8);
13076 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13077 hdd_limit_max_per_index_score(
13078 cfg->esp_qbss_score_slots15_to_12);
13079
13080 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13081 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13082 hdd_limit_max_per_index_score(
13083 cfg->oce_wan_score_slots3_to_0);
13084 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13085 hdd_limit_max_per_index_score(
13086 cfg->oce_wan_score_slots7_to_4);
13087 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13088 hdd_limit_max_per_index_score(
13089 cfg->oce_wan_score_slots11_to_8);
13090 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13091 hdd_limit_max_per_index_score(
13092 cfg->oce_wan_score_slots15_to_12);
13093
13094
13095 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13096 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13097 score_config->nss = cfg->enable2x2 ? 2 : 1;
13098
13099 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13100 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13101 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13102 score_config->he_cap = 1;
13103
13104 if (score_config->he_cap ||
13105 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13106 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13107 score_config->vht_cap = 1;
13108
13109 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13110 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13111 score_config->ht_cap = 1;
13112
13113 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13114 score_config->vht_24G_cap = 1;
13115
13116 if (cfg->enableTxBF)
13117 score_config->beamformee_cap = 1;
13118
13119}
13120
Abhishek Singh257a9482017-03-06 16:52:39 +053013121/**
bings81fe50a2017-11-27 14:33:26 +080013122 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13123 * @hdd_ctx: HDD context
13124 *
13125 * Return: 0 if success else err
13126 */
13127static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13128{
13129 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13130 struct hdd_config *cfg = hdd_ctx->config;
13131 struct dfs_user_config dfs_cfg;
13132 QDF_STATUS status;
13133
13134 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13135 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13136 if (QDF_IS_STATUS_ERROR(status)) {
13137 hdd_err("failed dfs psoc configuration");
13138 return -EINVAL;
13139 }
13140
13141 return 0;
13142}
13143
13144/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013145 * hdd_update_scan_config - API to update scan configuration parameters
13146 * @hdd_ctx: HDD context
13147 *
13148 * Return: 0 if success else err
13149 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013150static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013151{
13152 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13153 struct scan_user_cfg scan_cfg;
13154 struct hdd_config *cfg = hdd_ctx->config;
13155 QDF_STATUS status;
13156
13157 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13158 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13159 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13160 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13161 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13162 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13163 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013164 /* convert to ms */
13165 scan_cfg.scan_cache_aging_time =
13166 cfg->scanAgingTimeout * 1000;
13167 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13168 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13169 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13170 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013171 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013172 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013173 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13174 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013175 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013176 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013177 scan_cfg.sta_miracast_mcc_rest_time =
13178 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013179
Abhishek Singhb20db962017-03-03 21:28:46 +053013180 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013181 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013182 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013183
Abhishek Singh257a9482017-03-06 16:52:39 +053013184 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13185 if (status != QDF_STATUS_SUCCESS) {
13186 hdd_err("failed pmo psoc configuration");
13187 return -EINVAL;
13188 }
13189
13190 return 0;
13191}
Abhishek Singh257a9482017-03-06 16:52:39 +053013192
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013193int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013194{
13195 int ret;
13196
13197 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013198 if (ret)
13199 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013200
Abhishek Singh257a9482017-03-06 16:52:39 +053013201 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013202 if (ret)
13203 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013204
Frank Liud4b2fa02017-03-29 11:46:48 +080013205 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013206 if (ret)
13207 return ret;
13208
13209 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013210 if (ret)
13211 return ret;
13212
13213 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013214
13215 return ret;
13216}
13217
Agrawal Ashish65634612016-08-18 13:24:32 +053013218/**
13219 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13220 * @mode : cfg80211 DFS mode
13221 *
13222 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13223 */
13224enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13225{
13226 switch (mode) {
13227 case DFS_MODE_ENABLE:
13228 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013229 case DFS_MODE_DISABLE:
13230 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013231 case DFS_MODE_DEPRIORITIZE:
13232 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013233 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013234 hdd_debug("ACS dfs mode is NONE");
13235 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013236 }
13237}
13238
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013239/**
13240 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13241 * @hddctx: pointer to hdd context
13242 * @set_value: enable/disable
13243 *
13244 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13245 * Host(even though it is duplicate). When Host send vendor command
13246 * disable,FW doesn't perform any action. Whenever any change in
13247 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13248 *
13249 * return - 0 on success, appropriate error values on failure.
13250 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013251int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013252{
13253 QDF_STATUS status;
13254
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013255 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013256 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013257
13258 if (!hddctx->config->goptimize_chan_avoid_event) {
13259 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13260 return -EINVAL;
13261 }
13262
13263 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13264 if (!QDF_IS_STATUS_SUCCESS(status)) {
13265 hdd_err("Failed to send chan avoid command to SME");
13266 return -EINVAL;
13267 }
13268 return 0;
13269}
Agrawal Ashish65634612016-08-18 13:24:32 +053013270
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013271/**
13272 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13273 * @value: value to set
13274 *
13275 * This function will set the passed value to roaming in progress flag.
13276 *
13277 * Return: None
13278 */
13279void hdd_set_roaming_in_progress(bool value)
13280{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013281 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013282
13283 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13284 if (!hdd_ctx) {
13285 hdd_err("HDD context is NULL");
13286 return;
13287 }
13288
13289 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013290 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013291}
13292
13293/**
13294 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013295 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013296 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013297 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013298 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013299bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013300{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013301 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013302 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013303
13304 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13305 if (!hdd_ctx) {
13306 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013307 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013308 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013309 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13310 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013311 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13312 hdd_ctx->roaming_in_progress);
13313
13314 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013315}
13316
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013317/**
13318 * hdd_is_connection_in_progress() - check if connection is in
13319 * progress
13320 * @session_id: session id
13321 * @reason: scan reject reason
13322 *
13323 * Go through each adapter and check if Connection is in progress
13324 *
13325 * Return: true if connection is in progress else false
13326 */
13327bool hdd_is_connection_in_progress(uint8_t *session_id,
13328 enum scan_reject_states *reason)
13329{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013330 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013331 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013332 uint8_t sta_id = 0;
13333 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013334 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013335
13336 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13337 if (!hdd_ctx) {
13338 hdd_err("HDD context is NULL");
13339 return false;
13340 }
13341
Dustin Brown920397d2017-12-13 16:27:50 -080013342 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013343 hdd_info("Adapter with device mode %s(%d) exists",
13344 hdd_device_mode_to_string(adapter->device_mode),
13345 adapter->device_mode);
13346 if (((QDF_STA_MODE == adapter->device_mode)
13347 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13348 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13349 && (eConnectionState_Connecting ==
13350 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13351 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013352 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013353 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013354 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013355 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013356 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013357 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013358 }
13359 return true;
13360 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013361 /*
13362 * sme_neighbor_middle_of_roaming is for LFR2
13363 * hdd_is_roaming_in_progress is for LFR3
13364 */
13365 if (((QDF_STA_MODE == adapter->device_mode) &&
13366 sme_neighbor_middle_of_roaming(
13367 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013368 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013369 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013370 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013371 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013372 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013373 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013374 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013375 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013376 }
13377 return true;
13378 }
13379 if ((QDF_STA_MODE == adapter->device_mode) ||
13380 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13381 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13382 hdd_sta_ctx =
13383 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13384 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013385 hdd_sta_ctx->conn_info.connState)
13386 && sme_is_sta_key_exchange_in_progress(
13387 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013388 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013389 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013390 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013391 " is in middle of WPS/EAPOL exchange.",
13392 MAC_ADDR_ARRAY(sta_mac));
13393 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013394 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013395 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013396 }
13397 return true;
13398 }
13399 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13400 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13401 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13402 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013403 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013404 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013405 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013406 continue;
13407
13408 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013409 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013410 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013411 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013412 " of SAP/GO is in middle of WPS/EAPOL exchange",
13413 MAC_ADDR_ARRAY(sta_mac));
13414 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013415 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013416 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013417 }
13418 return true;
13419 }
13420 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013421 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013422 return true;
13423 }
13424 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013425 }
Dustin Brown920397d2017-12-13 16:27:50 -080013426
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013427 return false;
13428}
13429
13430/**
13431 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013432 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013433 *
13434 * Return: None
13435 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013436void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013437{
Jeff Johnson87251032017-08-29 13:31:11 -070013438 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013439 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013440 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013441 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070013442 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013443 void *sap_ctx;
13444
13445 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013446 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013447 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013448
13449 mutex_lock(&hdd_ctx->sap_lock);
13450 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13451 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013452 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13453 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13454 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13455 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013456 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013457 qdf_stop_bss_event,
13458 SME_CMD_TIMEOUT_VALUE);
13459
13460 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013461 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013462 goto end;
13463 }
13464 }
13465 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013466 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013467 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013468 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013469 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013470 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013471
13472 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013473 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013474 wlansap_reset_sap_config_add_ie(sap_config,
13475 eUPDATE_IE_ALL);
13476 goto end;
13477 }
13478
13479 qdf_event_reset(&hostapd_state->qdf_event);
13480 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13481 sap_config,
13482 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013483 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013484 wlansap_reset_sap_config_add_ie(sap_config,
13485 eUPDATE_IE_ALL);
13486 goto end;
13487 }
13488
Jeff Johnson6867ec32017-09-29 20:30:20 -070013489 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013490 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013491 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013492 SME_CMD_TIMEOUT_VALUE);
13493 wlansap_reset_sap_config_add_ie(sap_config,
13494 eUPDATE_IE_ALL);
13495 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013496 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013497 goto end;
13498 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013499 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013500 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013501 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013502 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13503 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013504 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013505 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013506 ap_adapter->device_mode,
13507 true);
13508 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013509 }
13510end:
13511 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013512}
13513
13514/**
13515 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13516 * with non dfs acs
13517 *
13518 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13519 *
13520 * Return: None
13521 */
13522void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13523{
Jeff Johnson9d295242017-08-29 14:39:48 -070013524 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013525 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013526 cds_context_type *cds_ctx;
13527
13528 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13529 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013530 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013531 return;
13532 }
13533
13534 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13535 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013536 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013537 return;
13538 }
13539
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013540 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13541 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013542 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013543 return;
13544 }
13545
13546 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013547 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13548 &ap_adapter->event_flags) &&
13549 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013550 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013551
Jeff Johnson6867ec32017-09-29 20:30:20 -070013552 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013553 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013554 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013555 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013556 acs_cfg.acs_mode = true;
13557
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013558 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013559 }
13560}
13561
13562/**
13563 * hdd_set_connection_in_progress() - to set the connection in
13564 * progress flag
13565 * @value: value to set
13566 *
13567 * This function will set the passed value to connection in progress flag.
13568 * If value is previously being set to true then no need to set it again.
13569 *
13570 * Return: true if value is being set correctly and false otherwise.
13571 */
13572bool hdd_set_connection_in_progress(bool value)
13573{
13574 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013575 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013576
13577 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13578 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013579 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013580 return false;
13581 }
13582
13583 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13584 /*
13585 * if the value is set to true previously and if someone is
13586 * trying to make it true again then it could be some race
13587 * condition being triggered. Avoid this situation by returning
13588 * false
13589 */
13590 if (hdd_ctx->connection_in_progress && value)
13591 status = false;
13592 else
13593 hdd_ctx->connection_in_progress = value;
13594 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13595 return status;
13596}
13597
Jeff Johnson9d295242017-08-29 14:39:48 -070013598int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013599{
13600 if (!adapter) {
13601 hdd_err("Invalid adapter");
13602 return -EINVAL;
13603 }
13604 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013605 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013606 WMA_VDEV_MCC_SET_TIME_QUOTA,
13607 set_value, VDEV_CMD);
13608 return 0;
13609
13610}
13611
Jeff Johnson9d295242017-08-29 14:39:48 -070013612int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013613{
13614 if (!adapter) {
13615 hdd_err("Invalid adapter");
13616 return -EINVAL;
13617 }
13618
13619 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013620 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013621 WMA_VDEV_MCC_SET_TIME_LATENCY,
13622 set_value, VDEV_CMD);
13623 return 0;
13624}
13625
Jeff Johnson9d295242017-08-29 14:39:48 -070013626struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013627 *psoc, uint8_t vdev_id)
13628{
Jeff Johnson9d295242017-08-29 14:39:48 -070013629 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013630 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013631
13632 /*
13633 * Currently PSOC is not being used. But this logic will
13634 * change once we have the converged implementation of
13635 * HDD context per PSOC in place. This would break if
13636 * multiple vdev objects reuse the vdev id.
13637 */
13638 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13639 if (!adapter)
13640 hdd_err("Get adapter by vdev id failed");
13641
13642 return adapter;
13643}
13644
Jeff Johnson9d295242017-08-29 14:39:48 -070013645int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013646 int8_t *rssi, int8_t *snr)
13647{
13648 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013649 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013650
Jeff Johnson025618c2018-03-18 14:41:00 -070013651 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013652 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013653 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013654 if (QDF_STATUS_SUCCESS != status) {
13655 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13656 return -EINVAL;
13657 }
13658
13659 return 0;
13660}
13661
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013662/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013663 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13664 * @adapter - HDD adapter
13665 * @tos - type of service
13666 * @status - status of the traffic
13667 *
13668 * Return: 0 on success and non zero value on failure
13669 */
13670
13671int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13672 bool is_tos_active)
13673{
13674 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013675 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013676 uint32_t max_off_chan_time = 0;
13677 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013678 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013679 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013680
13681 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13682 ret = wlan_hdd_validate_context(hdd_ctx);
13683
13684 if (ret < 0) {
13685 hdd_err("failed to set limit off chan params");
13686 return ret;
13687 }
13688
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013689 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13690
13691 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013692 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013693 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013694 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013695
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013696 if (adapter->active_ac) {
13697 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013698 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013699 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13700 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13701 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013702 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013703 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013704 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13705 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13706 PM_LATENCY);
13707 } else {
13708 /*ignore this command if only BE/BK is active */
13709 is_tos_active = false;
13710 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13711 hdd_ctx->config->conc_system_pref);
13712 }
13713 } else {
13714 /* No active tos */
13715 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13716 hdd_ctx->config->conc_system_pref);
13717 }
13718
Jeff Johnson1b780e42017-10-31 14:11:45 -070013719 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013720 is_tos_active, max_off_chan_time,
13721 hdd_ctx->config->nRestTimeConc, true);
13722 if (!QDF_IS_STATUS_SUCCESS(status)) {
13723 hdd_err("failed to set limit off chan params");
13724 ret = -EINVAL;
13725 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013726
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013727 return ret;
13728}
13729
13730/**
13731 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13732 * @adapter - HDD adapter
13733 *
13734 * Return: 0 on success and non zero value on failure
13735 */
13736int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13737{
13738 struct hdd_context *hdd_ctx;
13739 int ret;
13740 QDF_STATUS status;
13741 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13742
13743 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13744 ret = wlan_hdd_validate_context(hdd_ctx);
13745 if (ret < 0)
13746 return ret;
13747
13748 /* set the system preferece to default */
13749 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13750 hdd_ctx->config->conc_system_pref);
13751
13752 /* clear the bitmap */
13753 adapter->active_ac = 0;
13754
13755 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013756 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013757
Jeff Johnson1b780e42017-10-31 14:11:45 -070013758 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013759 false, 0, 0, false);
13760 if (!QDF_IS_STATUS_SUCCESS(status)) {
13761 hdd_err("failed to reset limit off chan params");
13762 ret = -EINVAL;
13763 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013764
13765 return ret;
13766}
13767
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013768/**
13769 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13770 * @drv_op: Enum indicating driver op
13771 *
13772 * Return: none
13773 */
13774void hdd_start_driver_ops_timer(int drv_op)
13775{
13776 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13777 switch (drv_op) {
13778 case eHDD_DRV_OP_PROBE:
13779 memcpy(drv_ops_string, "probe", sizeof("probe"));
13780 break;
13781 case eHDD_DRV_OP_REMOVE:
13782 memcpy(drv_ops_string, "remove", sizeof("remove"));
13783 break;
13784 case eHDD_DRV_OP_SHUTDOWN:
13785 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13786 break;
13787 case eHDD_DRV_OP_REINIT:
13788 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13789 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013790 case eHDD_DRV_OP_IFF_UP:
13791 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13792 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013793 }
13794
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013795 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013796 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13797 HDD_OPS_INACTIVITY_TIMEOUT);
13798}
13799
13800/**
13801 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13802 *
13803 * Return: none
13804 */
13805void hdd_stop_driver_ops_timer(void)
13806{
13807 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13808}
13809
13810/**
13811 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13812 * inactivity timer
13813 *
13814 * Return: None
13815 */
13816void hdd_drv_ops_inactivity_handler(void)
13817{
13818 hdd_err("%s: %d Sec timer expired while in .%s",
13819 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13820
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013821 if (hdd_drv_ops_task) {
13822 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13823 qdf_print_thread_trace(hdd_drv_ops_task);
13824 } else {
13825 hdd_err("hdd_drv_ops_task is null");
13826 }
13827
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013828 /* Driver shutdown is stuck, no recovery possible at this point */
13829 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13830 sizeof("shutdown")))
13831 QDF_BUG(0);
13832
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013833 if (cds_is_fw_down()) {
13834 hdd_err("FW is down");
13835 return;
13836 }
13837
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013838 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013839 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013840 else
13841 QDF_BUG(0);
13842}
13843
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013844void hdd_pld_ipa_uc_shutdown_pipes(void)
13845{
13846 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13847
13848 if (!hdd_ctx)
13849 return;
13850
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053013851 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013852}
13853
Yun Parkff6a16a2017-09-26 16:38:18 -070013854/**
13855 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13856 * @struct hdd_context *hdd_ctx
13857 * @struct hdd_adapter *padapter
13858 * @bool enble
13859 *
13860 * Return: none
13861 */
13862void hdd_set_rx_mode_rps(bool enable)
13863{
13864 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070013865 struct hdd_context *hdd_ctx;
13866 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070013867
Ryan Hsu0e878fa2018-05-04 15:22:09 -070013868 if (!cds_cfg)
13869 return;
13870
13871 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13872 if (!hdd_ctx)
13873 return;
13874
13875 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13876 if (!adapter)
13877 return;
13878
13879 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070013880 if (enable && !cds_cfg->rps_enabled)
13881 hdd_send_rps_ind(adapter);
13882 else if (!enable && cds_cfg->rps_enabled)
13883 hdd_send_rps_disable_ind(adapter);
13884 }
13885}
13886
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053013887bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
13888{
13889 struct hdd_adapter *adapter = NULL;
13890
13891 hdd_for_each_adapter(hdd_ctx, adapter) {
13892 if ((adapter->device_mode == QDF_STA_MODE ||
13893 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
13894 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
13895 &adapter->event_flags)){
13896 return true;
13897 }
13898 }
13899
13900 return false;
13901}
13902
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013903/* Register the module init/exit functions */
13904module_init(hdd_module_init);
13905module_exit(hdd_module_exit);
13906
13907MODULE_LICENSE("Dual BSD/GPL");
13908MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13909MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13910
Srinivas Girigowda841da292018-02-21 16:33:00 -080013911static const struct kernel_param_ops con_mode_ops = {
13912 .set = con_mode_handler,
13913 .get = param_get_int,
13914};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013915
Srinivas Girigowda841da292018-02-21 16:33:00 -080013916static const struct kernel_param_ops con_mode_ftm_ops = {
13917 .set = con_mode_handler_ftm,
13918 .get = param_get_int,
13919};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013920
Srinivas Girigowda841da292018-02-21 16:33:00 -080013921static const struct kernel_param_ops con_mode_monitor_ops = {
13922 .set = con_mode_handler_monitor,
13923 .get = param_get_int,
13924};
Ravi Joshia307f632017-07-17 23:41:41 -070013925
Srinivas Girigowda841da292018-02-21 16:33:00 -080013926static const struct kernel_param_ops fwpath_ops = {
13927 .set = fwpath_changed_handler,
13928 .get = param_get_string,
13929};
13930
13931module_param_cb(con_mode, &con_mode_ops, &con_mode,
13932 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13933
13934module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
13935 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13936
13937module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
13938 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13939
13940module_param_cb(fwpath, &fwpath_ops, &fwpath,
13941 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013942
13943module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13944
13945module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13946
13947module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);