blob: 538910f41a076a0cb10c7fa37a9462a73d54d1f2 [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 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_main.c
30 *
31 * WLAN Host Device Driver implementation
32 *
33 */
34
35/* Include Files */
36#include <wlan_hdd_includes.h>
37#include <cds_api.h>
38#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053039#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <linux/etherdevice.h>
41#include <linux/firmware.h>
42#include <wlan_hdd_tx_rx.h>
43#include <wni_api.h>
44#include <wlan_hdd_cfg.h>
45#include <wlan_ptt_sock_svc.h>
46#include <dbglog_host.h>
47#include <wlan_logging_sock_svc.h>
48#include <wlan_hdd_wowl.h>
49#include <wlan_hdd_misc.h>
50#include <wlan_hdd_wext.h>
51#include "wlan_hdd_trace.h"
52#include "wlan_hdd_ioctl.h"
53#include "wlan_hdd_ftm.h"
54#include "wlan_hdd_power.h"
55#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070056#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080057#include "wlan_hdd_request_manager.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053058#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053059#include "qdf_trace.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080060#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080061#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080062#endif
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070063#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080064#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070065#include <cdp_txrx_stats.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066
67#include <net/addrconf.h>
68#include <linux/wireless.h>
69#include <net/cfg80211.h>
70#include <linux/inetdevice.h>
71#include <net/addrconf.h>
72#include "wlan_hdd_cfg80211.h"
73#include "wlan_hdd_ext_scan.h"
74#include "wlan_hdd_p2p.h"
75#include <linux/rtnetlink.h>
76#include "sap_api.h"
77#include <linux/semaphore.h>
78#include <linux/ctype.h>
79#include <linux/compat.h>
80#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#include <soc/qcom/subsystem_restart.h>
82#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083#include <wlan_hdd_hostapd.h>
84#include <wlan_hdd_softap_tx_rx.h>
85#include "cfg_api.h"
86#include "qwlan_version.h"
87#include "wma_types.h"
88#include "wlan_hdd_tdls.h"
89#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053090#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070092#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070093#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080094#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095#include "wlan_hdd_nan.h"
96#include "wlan_hdd_debugfs.h"
97#include "wlan_hdd_driver_ops.h"
98#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053099#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800100
101#include <wlan_hdd_ipa.h>
102#include "hif.h"
103#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800104#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700105#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530106#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700107#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700108#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530109#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700110#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530111#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800112#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800113#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530114#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800115#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800116#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530117#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530118#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800119#include "os_if_wifi_pos.h"
120#include "wifi_pos_api.h"
121#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800122#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700123#include "os_if_nan.h"
124#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700125#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700126#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530127#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530128#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700129#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800130#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530131#include "wlan_disa_ucfg_api.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"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530137
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530138#include <wlan_green_ap_ucfg_api.h>
139
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
Sachin Ahujadddd2632017-03-07 19:07:24 +0530158int wlan_start_ret_val;
159static DECLARE_COMPLETION(wlan_start_comp);
160static unsigned int dev_num = 1;
161static struct cdev wlan_hdd_state_cdev;
162static struct class *class;
163static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530164#ifndef MODULE
165static struct gwlan_loader *wlan_loader;
166static ssize_t wlan_boot_cb(struct kobject *kobj,
167 struct kobj_attribute *attr,
168 const char *buf, size_t count);
169struct gwlan_loader {
170 bool loaded_state;
171 struct kobject *boot_wlan_obj;
172 struct attribute_group *attr_group;
173};
174
175static struct kobj_attribute wlan_boot_attribute =
176 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
177
178static struct attribute *attrs[] = {
179 &wlan_boot_attribute.attr,
180 NULL,
181};
182
183#define MODULE_INITIALIZED 1
184#endif
185
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530186#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
187#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800188#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530189
190static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800191static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530192static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
193
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800194/* the Android framework expects this param even though we don't use it */
195#define BUF_LEN 20
196static char fwpath_buffer[BUF_LEN];
197static struct kparam_string fwpath = {
198 .string = fwpath_buffer,
199 .maxlen = BUF_LEN,
200};
201
202static char *country_code;
203static int enable_11d = -1;
204static int enable_dfs_chan_scan = -1;
205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800206/*
207 * spinlock for synchronizing asynchronous request/response
208 * (full description of use in wlan_hdd_main.h)
209 */
210DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530211DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800212
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800213#define WLAN_NLINK_CESIUM 30
214
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530215static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800216
217#define WOW_MAX_FILTER_LISTS 1
218#define WOW_MAX_FILTERS_PER_LIST 4
219#define WOW_MIN_PATTERN_SIZE 6
220#define WOW_MAX_PATTERN_SIZE 64
221
222#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
223static const struct wiphy_wowlan_support wowlan_support_reg_init = {
224 .flags = WIPHY_WOWLAN_ANY |
225 WIPHY_WOWLAN_MAGIC_PKT |
226 WIPHY_WOWLAN_DISCONNECT |
227 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
228 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
229 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
230 WIPHY_WOWLAN_4WAY_HANDSHAKE |
231 WIPHY_WOWLAN_RFKILL_RELEASE,
232 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
233 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
234 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
235};
236#endif
237
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700238static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
239 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
243 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
244 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
251 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
252 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
253 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
254 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
255 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700273 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700274 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700275 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530276 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700277};
278
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530279int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
280 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
281 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
282 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
283 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
284};
285
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800286/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530287struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800288
289struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800290#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700291static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800292#endif
293
Sachin Ahujadddd2632017-03-07 19:07:24 +0530294void hdd_start_complete(int ret)
295{
296 wlan_start_ret_val = ret;
297
298 complete(&wlan_start_comp);
299}
300
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800301/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530302 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700303 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530304 *
305 * Return: none
306 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700307static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530308{
Jeff Johnson9d295242017-08-29 14:39:48 -0700309 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530310
Dustin Brown920397d2017-12-13 16:27:50 -0800311 hdd_for_each_adapter(hdd_ctx, adapter)
312 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530313}
314
315/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800316 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
317 * @vdev_id: vdev_id
318 * @action: action type
319 * @reason: reason type
320 *
321 * Return: none
322 */
323void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
324 enum netif_action_type action, enum netif_reason_type reason)
325{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700326 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700327 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800328
329 if (!hdd_ctx) {
330 hdd_err("hdd ctx is NULL");
331 return;
332 }
333 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
334
335 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800336}
337
338/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700339 * Store WLAN driver version and timestamp info in global variables such that
340 * crash debugger can extract them from driver debug symbol and crashdump for
341 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800342 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800343#ifdef BUILD_TAG
344uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
345#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800346uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700347#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800348
349/**
350 * hdd_device_mode_to_string() - return string conversion of device mode
351 * @device_mode: device mode
352 *
353 * This utility function helps log string conversion of device mode.
354 *
355 * Return: string conversion of device mode, if match found;
356 * "Unknown" otherwise.
357 */
358const char *hdd_device_mode_to_string(uint8_t device_mode)
359{
360 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800361 CASE_RETURN_STRING(QDF_STA_MODE);
362 CASE_RETURN_STRING(QDF_SAP_MODE);
363 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
364 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
365 CASE_RETURN_STRING(QDF_FTM_MODE);
366 CASE_RETURN_STRING(QDF_IBSS_MODE);
367 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
368 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700369 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800370 default:
371 return "Unknown";
372 }
373}
374
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530375/**
376 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
377 * @adapter: HDD adapter
378 * @chan_number: Channel number
379 * @chan_bw: Bandwidth
380 *
381 * Checks if the given bandwidth is valid for the given channel number.
382 *
383 * Return: 0 for success, non-zero for failure
384 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700385int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530386 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800387 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530388{
389 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
390 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
391 bool found = false;
392 tHalHandle hal;
393
394 hal = WLAN_HDD_GET_HAL_CTX(adapter);
395 if (!hal) {
396 hdd_err("Invalid HAL context");
397 return -EINVAL;
398 }
399
400 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
401 hdd_err("No valid channel list");
402 return -EOPNOTSUPP;
403 }
404
405 for (i = 0; i < len; i++) {
406 if (chan[i] == chan_number) {
407 found = true;
408 break;
409 }
410 }
411
412 if (found == false) {
413 hdd_err("Channel not in driver's valid channel list");
414 return -EOPNOTSUPP;
415 }
416
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700417 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
418 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530419 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
420 return -EINVAL;
421 }
422
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700423 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530424 if (chan_bw == CH_WIDTH_80MHZ) {
425 hdd_err("BW80 not possible in 2.4GHz band");
426 return -EINVAL;
427 }
428 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
429 (chan_bw != CH_WIDTH_MAX)) {
430 hdd_err("Only BW20 possible on channel 14");
431 return -EINVAL;
432 }
433 }
434
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700435 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530436 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
437 (chan_bw != CH_WIDTH_MAX)) {
438 hdd_err("Only BW20 possible on channel 165");
439 return -EINVAL;
440 }
441 }
442
443 return 0;
444}
445
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530446/**
447 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
448 *
449 * Block the unloading of the driver (or) interface up until the
450 * cds recovery is completed
451 *
452 * Return: true for recovery completion else false
453 */
454static bool hdd_wait_for_recovery_completion(void)
455{
456 int retry = 0;
457
458 /* Wait for recovery to complete */
459 while (cds_is_driver_recovering()) {
460 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
461 hdd_err("Recovery in progress; wait here!!!");
462 msleep(1000);
463 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
464 hdd_err("SSR never completed, error");
465 /*
466 * Trigger the bug_on in the internal builds, in the
467 * customer builds self-recovery will be enabled
468 * in those cases just return error.
469 */
470 if (cds_is_self_recovery_enabled())
471 return false;
472 QDF_BUG(0);
473 }
474 }
475
476 hdd_info("Recovery completed successfully!");
477 return true;
478}
479
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800480static int __hdd_netdev_notifier_call(struct notifier_block *nb,
481 unsigned long state, void *data)
482{
483#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
484 struct netdev_notifier_info *dev_notif_info = data;
485 struct net_device *dev = dev_notif_info->dev;
486#else
487 struct net_device *dev = data;
488#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700489 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700490 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800492 ENTER_DEV(dev);
493
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 /* Make sure that this callback corresponds to our device. */
495 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
496 return NOTIFY_DONE;
497
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530498 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800499 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700500 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800501 return NOTIFY_DONE;
502 }
503
504 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700505 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800506 return NOTIFY_DONE;
507 }
508
509 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
510 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800511 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530512 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800513 return NOTIFY_DONE;
514 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800515
516 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
517 hdd_err("%s: Driver module is closed", __func__);
518 return NOTIFY_DONE;
519 }
520
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530521 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800522 return NOTIFY_DONE;
523
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800524 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800525 dev->name, state);
526
527 switch (state) {
528 case NETDEV_REGISTER:
529 break;
530
531 case NETDEV_UNREGISTER:
532 break;
533
534 case NETDEV_UP:
535 sme_ch_avoid_update_req(hdd_ctx->hHal);
536 break;
537
538 case NETDEV_DOWN:
539 break;
540
541 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700542 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543 complete(&adapter->linkup_event_var);
544 break;
545
546 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700547 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
548 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530549 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700550 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800551 } else {
hqueaa33ee2017-05-04 17:56:35 +0800552 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800553 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800554 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530555 /*
556 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
557 * of return status of hdd_stop call, kernel resets the IFF_UP
558 * flag after which driver does not send the cfg80211_scan_done.
559 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
560 */
561 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 break;
563
564 default:
565 break;
566 }
567
568 return NOTIFY_DONE;
569}
570
571/**
572 * hdd_netdev_notifier_call() - netdev notifier callback function
573 * @nb: pointer to notifier block
574 * @state: state
575 * @ndev: ndev pointer
576 *
577 * Return: 0 on success, error number otherwise.
578 */
579static int hdd_netdev_notifier_call(struct notifier_block *nb,
580 unsigned long state,
581 void *ndev)
582{
583 int ret;
584
585 cds_ssr_protect(__func__);
586 ret = __hdd_netdev_notifier_call(nb, state, ndev);
587 cds_ssr_unprotect(__func__);
588
589 return ret;
590}
591
592struct notifier_block hdd_netdev_notifier = {
593 .notifier_call = hdd_netdev_notifier_call,
594};
595
596/* variable to hold the insmod parameters */
597static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800598
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530599static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700600int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530601
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800602/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800603static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800604
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530605/**
606 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
607 * @ch_width: NL channel width
608 *
609 * Converts the NL channel width to the driver's internal representation
610 *
611 * Return: Converted channel width. In case of non matching NL channel width,
612 * CH_WIDTH_MAX will be returned.
613 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800614enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530615{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800616 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700617
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800618 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530619 switch (ch_width) {
620 case NL80211_CHAN_WIDTH_20_NOHT:
621 case NL80211_CHAN_WIDTH_20:
622 return CH_WIDTH_20MHZ;
623 case NL80211_CHAN_WIDTH_40:
624 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530625 case NL80211_CHAN_WIDTH_80:
626 return CH_WIDTH_80MHZ;
627 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800628 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
629 return CH_WIDTH_80P80MHZ;
630 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
631 return CH_WIDTH_160MHZ;
632 else
633 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530634 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800635 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
636 return CH_WIDTH_160MHZ;
637 else
638 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530639 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800640 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530641 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800642 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530643 default:
644 hdd_err("Invalid channel width %d, setting to default",
645 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800646 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530647 }
648}
649
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530650/* wlan_hdd_find_opclass() - Find operating class for a channel
651 * @hal: handler to HAL
652 * @channel: channel id
653 * @bw_offset: bandwidth offset
654 *
655 * Function invokes sme api to find the operating class
656 *
657 * Return: operating class
658 */
659uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
660 uint8_t bw_offset)
661{
662 uint8_t opclass = 0;
663
664 sme_get_opclass(hal, channel, bw_offset, &opclass);
665 return opclass;
666}
667
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800668/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530669 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530670 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671 * @bitmask: Bitmask of log levels to be enabled
672 *
673 * Called immediately after the cfg.ini is read in order to configure
674 * the desired trace levels.
675 *
676 * Return: None
677 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530678int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800679{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530680 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530681 int qdf_print_idx = -1;
682 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800683 /*
684 * if the bitmask is the default value, then a bitmask was not
685 * specified in cfg.ini, so leave the logging level alone (it
686 * will remain at the "compiled in" default value)
687 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700688 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530689 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800690
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530691 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800692
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530693 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530694 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530695 QDF_TRACE_LEVEL_NONE, 0);
696
697 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530698 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800699 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530700 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800701 while (0 != bitmask) {
702 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530703 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530704 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530705 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530706 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800707 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700708
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800709 level++;
710 bitmask >>= 1;
711 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530712 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800713}
714
715/**
Chris Guo1751acf2017-07-03 14:09:01 +0800716 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
717 * @hdd_ctx: HDD context pointer
718 *
719 * Return: 0 if the context is valid. Error code otherwise
720 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700721int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800722{
723 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
724 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
725 return -ENODEV;
726 }
727
728 if (cds_is_driver_recovering()) {
729 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
730 (void *)_RET_IP_, cds_get_driver_state());
731 return -EAGAIN;
732 }
733
734 if (hdd_ctx->start_modules_in_progress ||
735 hdd_ctx->stop_modules_in_progress) {
736 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
737 (void *)_RET_IP_);
738 return -EAGAIN;
739 }
740
741 return 0;
742}
743
744
745/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746 * wlan_hdd_validate_context() - check the HDD context
747 * @hdd_ctx: HDD context pointer
748 *
749 * Return: 0 if the context is valid. Error code otherwise
750 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700751int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800752{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800753 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530754 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800755 return -ENODEV;
756 }
757
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800758 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800759 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530760 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 return -EAGAIN;
762 }
763
Yue Ma9f275d92017-09-14 16:58:41 -0700764 if (cds_is_load_or_unload_in_progress()) {
765 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
766 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700768 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530769
770 if (hdd_ctx->start_modules_in_progress ||
771 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800772 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530773 (void *)_RET_IP_);
774 return -EAGAIN;
775 }
776
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530777 if (cds_is_driver_in_bad_state()) {
778 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
779 (void *)_RET_IP_, cds_get_driver_state());
780 return -ENODEV;
781 }
782
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783 return 0;
784}
785
Jeff Johnson9d295242017-08-29 14:39:48 -0700786int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700787{
788 if (!adapter) {
789 hdd_err("adapter is null");
790 return -EINVAL;
791 }
792
793 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
794 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
795 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
796 return -EINVAL;
797 }
798
799 if (!adapter->dev) {
800 hdd_err("adapter net_device is null");
801 return -EINVAL;
802 }
803
804 if (!(adapter->dev->flags & IFF_UP)) {
805 hdd_info("adapter net_device is not up");
806 return -EAGAIN;
807 }
808
Jeff Johnson1b780e42017-10-31 14:11:45 -0700809 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700810 hdd_info("adapter session is not open");
811 return -EAGAIN;
812 }
813
Jeff Johnson1b780e42017-10-31 14:11:45 -0700814 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
815 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700816 return -EINVAL;
817 }
818
819 return 0;
820}
821
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800822/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530823 * wlan_hdd_validate_modules_state() - Check modules status
824 * @hdd_ctx: HDD context pointer
825 *
826 * Check's the driver module's state and returns true if the
827 * modules are enabled returns false if modules are closed.
828 *
829 * Return: True if modules are enabled or false.
830 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700831bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530832{
833 mutex_lock(&hdd_ctx->iface_change_lock);
834 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
835 mutex_unlock(&hdd_ctx->iface_change_lock);
836 hdd_notice("Modules not enabled, Present status: %d",
837 hdd_ctx->driver_status);
838 return false;
839 }
840 mutex_unlock(&hdd_ctx->iface_change_lock);
841 return true;
842}
843
844/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700846 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 *
848 * This function sets the IBSS power save config parameters to WMA
849 * which will send it to firmware if FW supports IBSS power save
850 * before vdev start.
851 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530852 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 * on failure.
854 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700855QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856{
857 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700858 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859
860 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700861 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530862 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 }
864
Jeff Johnson1b780e42017-10-31 14:11:45 -0700865 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
867 hdd_ctx->config->ibssATIMWinSize,
868 VDEV_CMD);
869 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700870 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530871 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872 }
873
Jeff Johnson1b780e42017-10-31 14:11:45 -0700874 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
876 hdd_ctx->config->isIbssPowerSaveAllowed,
877 VDEV_CMD);
878 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700879 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
880 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530881 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800882 }
883
Jeff Johnson1b780e42017-10-31 14:11:45 -0700884 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
886 hdd_ctx->config->
887 isIbssPowerCollapseAllowed, VDEV_CMD);
888 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700889 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
890 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530891 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 }
893
Jeff Johnson1b780e42017-10-31 14:11:45 -0700894 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
896 hdd_ctx->config->isIbssAwakeOnTxRx,
897 VDEV_CMD);
898 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700899 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530900 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 }
902
Jeff Johnson1b780e42017-10-31 14:11:45 -0700903 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
905 hdd_ctx->config->ibssInactivityCount,
906 VDEV_CMD);
907 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700908 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530909 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800910 }
911
Jeff Johnson1b780e42017-10-31 14:11:45 -0700912 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800913 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
914 hdd_ctx->config->ibssTxSpEndInactivityTime,
915 VDEV_CMD);
916 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700917 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
918 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530919 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 }
921
Jeff Johnson1b780e42017-10-31 14:11:45 -0700922 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
924 hdd_ctx->config->ibssPsWarmupTime,
925 VDEV_CMD);
926 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700927 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
928 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530929 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800930 }
931
Jeff Johnson1b780e42017-10-31 14:11:45 -0700932 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
934 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
935 VDEV_CMD);
936 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700937 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
938 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530939 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800940 }
941
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530942 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800943}
944
Yue Macd359b72017-10-03 15:21:00 -0700945#ifdef FEATURE_RUNTIME_PM
946/**
947 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
948 * @hdd_ctx: HDD context
949 *
950 * Return: None
951 */
952static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
953{
954 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
955
Yue Macd359b72017-10-03 15:21:00 -0700956 qdf_runtime_lock_init(&ctx->dfs);
957
958 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
959}
960
961/**
962 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
963 * @hdd_ctx: HDD Context
964 *
965 * Return: None
966 */
967static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
968{
969 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
970
Yue Macd359b72017-10-03 15:21:00 -0700971 qdf_runtime_lock_deinit(&ctx->dfs);
972
973 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
974}
975
976static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
977{
978 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
979
980 qdf_runtime_lock_init(&ctx->connect);
981}
982
Yue Ma9e89e832017-11-14 11:40:23 -0800983static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter)
Yue Macd359b72017-10-03 15:21:00 -0700984{
985 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
986
987 qdf_runtime_lock_deinit(&ctx->connect);
988}
989#else /* FEATURE_RUNTIME_PM */
990static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
991static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
992static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
Yue Ma9e89e832017-11-14 11:40:23 -0800993static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter) {}
Yue Macd359b72017-10-03 15:21:00 -0700994#endif /* FEATURE_RUNTIME_PM */
995
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800996#define INTF_MACADDR_MASK 0x7
997
998/**
999 * hdd_update_macaddr() - update mac address
1000 * @config: hdd configuration
1001 * @hw_macaddr: mac address
1002 *
1003 * Mac address for multiple virtual interface is found as following
1004 * i) The mac address of the first interface is just the actual hw mac address.
1005 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1006 * define the mac address for the remaining interfaces and locally
1007 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1008 * supported virtual interfaces, right now this is 0x07 (meaning 8
1009 * interface).
1010 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1011 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1012 *
1013 * Return: None
1014 */
1015void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301016 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017{
1018 int8_t i;
1019 uint8_t macaddr_b3, tmp_br3;
1020
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301021 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301022 QDF_MAC_ADDR_SIZE);
1023 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301024 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301025 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1027 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1028 INTF_MACADDR_MASK;
1029 macaddr_b3 += tmp_br3;
1030
1031 /* XOR-ing bit-24 of the mac address. This will give enough
1032 * mac address range before collision
1033 */
1034 macaddr_b3 ^= (1 << 7);
1035
1036 /* Set locally administered bit */
1037 config->intfMacAddr[i].bytes[0] |= 0x02;
1038 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001039 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 MAC_ADDRESS_STR, i,
1041 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1042 }
1043}
1044
Kabilan Kannan44a58372017-12-06 18:16:11 -08001045static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1046{
1047 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1048 struct tdls_start_params tdls_cfg;
1049 struct tdls_user_config *config = &tdls_cfg.config;
1050 struct hdd_config *cfg = hdd_ctx->config;
1051 QDF_STATUS status;
1052
1053 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1054 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1055 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1056 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1057 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1058 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1059 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1060 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1061 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1062 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1063 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1064 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1065 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1066 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1067 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1068 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1069 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1070 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1071 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1072 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1073 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1074 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1075 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1076 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1077 (cfg->fEnableTDLSImplicitTrigger ?
1078 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1079 (cfg->fTDLSExternalControl ?
1080 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1081 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1082 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1083
1084 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1085 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1086 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1087 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1088 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1089 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1090 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1091 tdls_cfg.tdls_evt_cb_data = psoc;
1092 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
1093 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
1094 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
1095 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1096 tdls_cfg.tdls_wmm_cb_data = psoc;
1097 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1098 tdls_cfg.tdls_rx_cb_data = psoc;
1099 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1100
1101 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1102 if (status != QDF_STATUS_SUCCESS) {
1103 hdd_err("failed pmo psoc configuration");
1104 return -EINVAL;
1105 }
1106
1107 hdd_ctx->tdls_umac_comp_active = true;
1108 /* enable napier specific tdls data path */
1109 hdd_ctx->tdls_nap_active = true;
1110
1111 return 0;
1112}
1113
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001114static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 struct wma_tgt_services *cfg)
1116{
1117 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001118
1119 /* Set up UAPSD */
1120 config->apUapsdEnabled &= cfg->uapsd;
1121
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001122 /* 11AX mode support */
1123 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1124 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1125 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1126
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001127 /* 11AC mode support */
1128 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1129 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1130 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131
1132 /* ARP offload: override user setting if invalid */
1133 config->fhostArpOffload &= cfg->arp_offload;
1134
1135#ifdef FEATURE_WLAN_SCAN_PNO
1136 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001137 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 if (cfg->pno_offload)
1139 config->PnoOffload = true;
1140#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141#ifdef FEATURE_WLAN_TDLS
1142 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301143 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1144 cfg->en_tdls_offchan;
1145 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1146 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001147 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001149 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001150 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001152#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1153 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1154#endif
Will Huang496b36c2017-07-11 16:38:50 +08001155 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001156 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001157 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001158 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001159
1160}
1161
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001162/**
1163 * hdd_update_vdev_nss() - sets the vdev nss
1164 * @hdd_ctx: HDD context
1165 *
1166 * Sets the Nss per vdev type based on INI
1167 *
1168 * Return: None
1169 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001170static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001171{
1172 struct hdd_config *cfg_ini = hdd_ctx->config;
1173 uint8_t max_supp_nss = 1;
1174
Naveen Rawat10b1c152017-01-18 11:16:06 -08001175 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001176 max_supp_nss = 2;
1177
1178 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001179 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001180
1181 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001182 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001183}
1184
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301185/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301186 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1187 * @hdd_ctx: HDD context
1188 *
1189 * Updates wiphy vhtcap fields
1190 *
1191 * Return: None
1192 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001193static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301194{
1195 struct ieee80211_supported_band *band_5g =
1196 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1197 uint32_t val;
1198
1199 if (!band_5g) {
1200 hdd_debug("5GHz band disabled, skipping capability population");
1201 return;
1202 }
1203
1204 val = hdd_ctx->config->txBFCsnValue;
1205 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1206
1207 val = NUM_OF_SOUNDING_DIMENSIONS;
1208 band_5g->vht_cap.cap |=
1209 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1210
1211 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1212 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1213}
1214
1215/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301216 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1217 * @hdd_ctx: HDD context
1218 *
1219 * Sets the DBS capability as per INI and firmware capability
1220 *
1221 * Return: None
1222 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001223static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301224{
1225 struct hdd_config *cfg_ini = hdd_ctx->config;
1226 uint8_t hw_dbs_capable = 0;
1227
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001228 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1229 ((cfg_ini->dual_mac_feature_disable ==
1230 ENABLE_DBS_CXN_AND_SCAN) ||
1231 (cfg_ini->dual_mac_feature_disable ==
1232 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301233 hw_dbs_capable = 1;
1234
1235 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1236}
1237
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001238static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001239 struct wma_tgt_ht_cap *cfg)
1240{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301241 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242 uint32_t value, val32;
1243 uint16_t val16;
1244 struct hdd_config *pconfig = hdd_ctx->config;
1245 tSirMacHTCapabilityInfo *phtCapInfo;
1246 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1247 uint8_t enable_tx_stbc;
1248
1249 /* check and update RX STBC */
1250 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1251 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1252
1253 /* get the MPDU density */
1254 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1255
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301256 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001257 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001258 value = 0;
1259 }
1260
1261 /*
1262 * MPDU density:
1263 * override user's setting if value is larger
1264 * than the one supported by target
1265 */
1266 if (value > cfg->mpdu_density) {
1267 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1268 cfg->mpdu_density);
1269
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301270 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001271 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001272 }
1273
1274 /* get the HT capability info */
1275 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301276 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001277 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001278 return;
1279 }
1280 val16 = (uint16_t) val32;
1281 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1282
1283 /* Set the LDPC capability */
1284 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1285
1286 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1287 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1288
1289 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1290 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1291
1292 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1293 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1294
1295 enable_tx_stbc = pconfig->enableTxSTBC;
1296
1297 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1298 pconfig->enable2x2 = 1;
1299 } else {
1300 pconfig->enable2x2 = 0;
1301 enable_tx_stbc = 0;
1302
1303 /* 1x1 */
1304 /* Update Rx Highest Long GI data Rate */
1305 if (sme_cfg_set_int(hdd_ctx->hHal,
1306 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001307 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301308 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001309 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001310 }
1311
1312 /* Update Tx Highest Long GI data Rate */
1313 if (sme_cfg_set_int
1314 (hdd_ctx->hHal,
1315 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001316 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301317 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001318 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319 }
1320 }
1321 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1322 enable_tx_stbc = 0;
1323 phtCapInfo->txSTBC = enable_tx_stbc;
1324
1325 val32 = val16;
1326 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301327 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001328 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1330 value = SIZE_OF_SUPPORTED_MCS_SET;
1331 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301332 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001333 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001334
1335 if (pconfig->enable2x2) {
1336 for (value = 0; value < cfg->num_rf_chains; value++)
1337 mcs_set[value] =
1338 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1339
1340 status =
1341 sme_cfg_set_str(hdd_ctx->hHal,
1342 WNI_CFG_SUPPORTED_MCS_SET,
1343 mcs_set,
1344 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301345 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001346 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 }
1348 }
1349#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1350}
1351
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001352static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001353 struct wma_tgt_vht_cap *cfg)
1354{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301355 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001356 uint32_t value = 0;
1357 struct hdd_config *pconfig = hdd_ctx->config;
1358 struct wiphy *wiphy = hdd_ctx->wiphy;
1359 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001360 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001361 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001362 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001363 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364
Dustin Brown5e06bd32016-10-04 12:49:10 -07001365 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001366 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001367 return;
1368 }
1369
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370 /* Get the current MPDU length */
1371 status =
1372 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1373 &value);
1374
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301375 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001376 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001377 value = 0;
1378 }
1379
1380 /*
1381 * VHT max MPDU length:
1382 * override if user configured value is too high
1383 * that the target cannot support
1384 */
1385 if (value > cfg->vht_max_mpdu) {
1386 status = sme_cfg_set_int(hdd_ctx->hHal,
1387 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1388 cfg->vht_max_mpdu);
1389
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001390 if (status == QDF_STATUS_E_FAILURE)
1391 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001392 }
1393
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001394 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1395 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1396
1397 if (pconfig->enable2x2)
1398 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1399
1400 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1401 QDF_STATUS_E_FAILURE) {
1402 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1403 }
1404
1405 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1406 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1407 if (pconfig->enable2x2)
1408 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1409
1410 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1411 QDF_STATUS_E_FAILURE) {
1412 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1413 }
1414
1415 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1416 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1417 if (pconfig->enable2x2)
1418 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1419
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001420 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001421 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1422
1423 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1424 QDF_STATUS_E_FAILURE) {
1425 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1426 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001428 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001429 &value);
1430
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301431 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001432 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001433 value = 0;
1434 }
1435
jiad4a7a33c2017-08-08 15:32:24 +08001436 /* Set HW RX LDPC capability */
1437 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1438 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439 status = sme_cfg_set_int(hdd_ctx->hHal,
1440 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001441 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001443 if (status == QDF_STATUS_E_FAILURE)
1444 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001445 }
1446
1447 /* Get current GI 80 value */
1448 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1449 &value);
1450
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301451 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001452 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001453 value = 0;
1454 }
1455
1456 /* set the Guard interval 80MHz */
1457 if (value && !cfg->vht_short_gi_80) {
1458 status = sme_cfg_set_int(hdd_ctx->hHal,
1459 WNI_CFG_VHT_SHORT_GI_80MHZ,
1460 cfg->vht_short_gi_80);
1461
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001462 if (status == QDF_STATUS_E_FAILURE)
1463 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464 }
1465
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466 /* Get VHT TX STBC cap */
1467 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1468
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301469 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001470 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001471 value = 0;
1472 }
1473
1474 /* VHT TX STBC cap */
1475 if (value && !cfg->vht_tx_stbc) {
1476 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1477 cfg->vht_tx_stbc);
1478
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001479 if (status == QDF_STATUS_E_FAILURE)
1480 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481 }
1482
1483 /* Get VHT RX STBC cap */
1484 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1485
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301486 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001487 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 value = 0;
1489 }
1490
1491 /* VHT RX STBC cap */
1492 if (value && !cfg->vht_rx_stbc) {
1493 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1494 cfg->vht_rx_stbc);
1495
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001496 if (status == QDF_STATUS_E_FAILURE)
1497 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001498 }
1499
1500 /* Get VHT SU Beamformer cap */
1501 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1502 &value);
1503
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301504 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001505 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001506 value = 0;
1507 }
1508
1509 /* set VHT SU Beamformer cap */
1510 if (value && !cfg->vht_su_bformer) {
1511 status = sme_cfg_set_int(hdd_ctx->hHal,
1512 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1513 cfg->vht_su_bformer);
1514
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001515 if (status == QDF_STATUS_E_FAILURE)
1516 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001517 }
1518
1519 /* check and update SU BEAMFORMEE capabality */
1520 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1521 pconfig->enableTxBF = cfg->vht_su_bformee;
1522
1523 status = sme_cfg_set_int(hdd_ctx->hHal,
1524 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1525 pconfig->enableTxBF);
1526
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001527 if (status == QDF_STATUS_E_FAILURE)
1528 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529
1530 /* Get VHT MU Beamformer cap */
1531 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1532 &value);
1533
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301534 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001535 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001536 value = 0;
1537 }
1538
1539 /* set VHT MU Beamformer cap */
1540 if (value && !cfg->vht_mu_bformer) {
1541 status = sme_cfg_set_int(hdd_ctx->hHal,
1542 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1543 cfg->vht_mu_bformer);
1544
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001545 if (status == QDF_STATUS_E_FAILURE)
1546 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001547 }
1548
1549 /* Get VHT MU Beamformee cap */
1550 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1551 &value);
1552
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301553 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001554 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555 value = 0;
1556 }
1557
1558 /* set VHT MU Beamformee cap */
1559 if (value && !cfg->vht_mu_bformee) {
1560 status = sme_cfg_set_int(hdd_ctx->hHal,
1561 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1562 cfg->vht_mu_bformee);
1563
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001564 if (status == QDF_STATUS_E_FAILURE)
1565 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001566 }
1567
1568 /* Get VHT MAX AMPDU Len exp */
1569 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1570 &value);
1571
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301572 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001573 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001574 value = 0;
1575 }
1576
1577 /*
1578 * VHT max AMPDU len exp:
1579 * override if user configured value is too high
1580 * that the target cannot support.
1581 * Even though Rome publish ampdu_len=7, it can
1582 * only support 4 because of some h/w bug.
1583 */
1584
1585 if (value > cfg->vht_max_ampdu_len_exp) {
1586 status = sme_cfg_set_int(hdd_ctx->hHal,
1587 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1588 cfg->vht_max_ampdu_len_exp);
1589
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001590 if (status == QDF_STATUS_E_FAILURE)
1591 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001592 }
1593
1594 /* Get VHT TXOP PS CAP */
1595 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1596
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301597 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001598 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599 value = 0;
1600 }
1601
1602 /* set VHT TXOP PS cap */
1603 if (value && !cfg->vht_txop_ps) {
1604 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1605 cfg->vht_txop_ps);
1606
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001607 if (status == QDF_STATUS_E_FAILURE)
1608 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001609 }
1610
1611 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1612 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1613 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1614 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1615 else
1616 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1617
1618
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001619 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1620 status = sme_cfg_set_int(hdd_ctx->hHal,
1621 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1622 VHT_CAP_160_AND_80P80_SUPP);
1623 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001624 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625 band_5g->vht_cap.cap |=
1626 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001627 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1628 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1629 status = sme_cfg_set_int(hdd_ctx->hHal,
1630 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1631 VHT_CAP_160_SUPP);
1632 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001633 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634 band_5g->vht_cap.cap |=
1635 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001636 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1637 }
1638 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1639 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301640 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001641 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301642 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001643 &value);
1644 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301645 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001646 value = 0;
1647 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301648 /* set the Guard interval 160MHz */
1649 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001650 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301651 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1652 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001653
1654 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301655 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001656 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657
1658 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1659 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1660
1661 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1662 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1663 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1664 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1665
1666 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1667 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1668
1669 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1670 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1671 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1672 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1673 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1674 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1675
1676 band_5g->vht_cap.cap |=
1677 (cfg->vht_max_ampdu_len_exp <<
1678 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1679
1680 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1681 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1682 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1683 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1684 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1685 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1686 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1687 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1688
1689 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1690 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1691
1692}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001694/**
1695 * hdd_generate_macaddr_auto() - Auto-generate mac address
1696 * @hdd_ctx: Pointer to the HDD context
1697 *
1698 * Auto-generate mac address using device serial number.
1699 * Keep the first 3 bytes of OUI as before and replace
1700 * the last 3 bytes with the lower 3 bytes of serial number.
1701 *
1702 * Return: 0 for success
1703 * Non zero failure code for errors
1704 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001705static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001706{
1707 unsigned int serialno = 0;
1708 struct qdf_mac_addr mac_addr = {
1709 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1710 };
1711
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001712 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001713 if (serialno == 0)
1714 return -EINVAL;
1715
1716 serialno &= 0x00ffffff;
1717
1718 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1719 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1720 mac_addr.bytes[5] = serialno & 0xff;
1721
1722 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1723 return 0;
1724}
1725
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301726/**
1727 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1728 * configuration to cfg_ini in HDD
1729 * @hdd_ctx: Pointer to hdd_ctx
1730 * @cfg: target configuration
1731 *
1732 * Return: None
1733 */
1734#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001735static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301736 struct wma_tgt_cfg *cfg)
1737{
1738 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1739}
1740#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001741static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301742 struct wma_tgt_cfg *cfg)
1743{
1744}
1745#endif
1746
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301747uint8_t hdd_check_green_ap_enable(struct hdd_context *hdd_ctx,
1748 bool *is_enabled)
1749{
1750 struct hdd_config *cfg;
1751 uint32_t concurrency_mode;
1752
1753 cfg = hdd_ctx->config;
1754 if (!cfg) {
1755 hdd_err("NULL hdd config");
1756 return -EINVAL;
1757 }
1758
1759 concurrency_mode = policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc);
1760
1761 if (cfg->enable2x2 && cfg->enableGreenAP) {
1762 if ((concurrency_mode & (1 << QDF_SAP_MODE)) &&
1763 !(concurrency_mode & (~(1 << QDF_SAP_MODE))))
1764 *is_enabled = true;
1765 }
1766 return 0;
1767}
1768
1769static int hdd_update_green_ap_config(struct hdd_context *hdd_ctx)
1770{
1771 struct green_ap_user_cfg green_ap_cfg;
1772 struct hdd_config *cfg = hdd_ctx->config;
1773 QDF_STATUS status;
1774
1775 green_ap_cfg.host_enable_egap = cfg->enable_egap;
1776 green_ap_cfg.egap_inactivity_time = cfg->egap_inact_time;
1777 green_ap_cfg.egap_wait_time = cfg->egap_wait_time;
1778 green_ap_cfg.egap_feature_flags = cfg->egap_feature_flag;
1779
1780 status = ucfg_green_ap_update_user_config(hdd_ctx->hdd_pdev,
1781 &green_ap_cfg);
1782 if (status != QDF_STATUS_SUCCESS) {
1783 hdd_err("failed to update green ap user configuration");
1784 return -EINVAL;
1785 }
1786
1787 return 0;
1788}
1789
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001790void hdd_update_tgt_cfg(void *context, void *param)
1791{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001792 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001793 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794 struct wma_tgt_cfg *cfg = param;
1795 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001796 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301797 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301798
Dustin Brownbd68fe12017-11-21 15:28:52 -08001799 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1800 if (ret) {
1801 hdd_err("Failed to create pdev; errno:%d", ret);
1802 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001803 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001804 hdd_debug("New pdev has been created with pdev_id = %u",
1805 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301806 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001807
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301808 ret = hdd_update_green_ap_config(hdd_ctx);
1809
Naveen Rawat64e477e2016-05-20 10:34:56 -07001810 if (cds_cfg) {
1811 if (hdd_ctx->config->enable_sub_20_channel_width !=
1812 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1813 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1814 cds_cfg->sub_20_channel_width =
1815 WLAN_SUB_20_CH_WIDTH_NONE;
1816 } else {
1817 cds_cfg->sub_20_channel_width =
1818 hdd_ctx->config->enable_sub_20_channel_width;
1819 }
1820 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001821
1822 /* first store the INI band capability */
1823 temp_band_cap = hdd_ctx->config->nBandCapability;
1824
1825 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301826 hdd_ctx->is_fils_roaming_supported =
1827 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001828
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001829 /*
1830 * now overwrite the target band capability with INI
1831 * setting if INI setting is a subset
1832 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001833
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001834 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1835 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001836 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001837 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1838 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001839 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001840 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001841 }
1842
Amar Singhal58b45ef2017-08-01 13:43:54 -07001843 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1844
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301845 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001846 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1847 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1848 }
1849
1850 /* This can be extended to other configurations like ht, vht cap... */
1851
Anurag Chouhanc5548422016-02-24 18:33:27 +05301852 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001853 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001854 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001855 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001856 static struct qdf_mac_addr default_mac_addr = {
1857 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1858 };
1859 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1860 &default_mac_addr)) {
1861 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1862 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1863 MAC_ADDRESS_STR,
1864 MAC_ADDR_ARRAY(hdd_ctx->config->
1865 intfMacAddr[0].bytes));
1866 } else {
1867 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1868 MAC_ADDRESS_STR,
1869 MAC_ADDR_ARRAY(hdd_ctx->config->
1870 intfMacAddr[0].bytes));
1871 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001872 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001873 }
1874
1875 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001876 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877
1878 hdd_ctx->max_intf_count = cfg->max_intf_count;
1879
Jeff Johnsonc875e242016-09-23 18:12:34 -07001880 hdd_lpass_target_config(hdd_ctx, cfg);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301881 ucfg_green_ap_target_config(hdd_ctx->hdd_pdev, cfg->egap_support);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001882
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001883 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1884 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1885
1886 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001888 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001889 if (cfg->services.en_11ax) {
1890 hdd_info("11AX: 11ax is enabled - update HDD config");
1891 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1892 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001893
1894 hdd_update_vdev_nss(hdd_ctx);
1895
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301896 hdd_update_hw_dbs_capable(hdd_ctx);
1897
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001898 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001899 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001900 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001901 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001902
Nitesh Shahe50711f2017-04-26 16:30:45 +05301903 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1904 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1905 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001906 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001907 hdd_ctx->current_antenna_mode);
1908
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001909 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1910 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301911 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301912 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301913
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301914 if ((hdd_ctx->config->txBFCsnValue >
1915 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1916 !cfg->tx_bfee_8ss_enabled)
1917 hdd_ctx->config->txBFCsnValue =
1918 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1919
1920 if (sme_cfg_set_int(hdd_ctx->hHal,
1921 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1922 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1923 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1924
1925
1926 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1927 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1928 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301929
1930 /*
1931 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1932 */
1933 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301934
Arun Khandavallid454d422016-08-17 12:47:05 +05301935 /*
1936 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1937 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1938 * configure the STA mode wow pattern.
1939 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301940 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301941 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301942
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301943 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1944
Yue Macd359b72017-10-03 15:21:00 -07001945 /*
1946 * This needs to be done after HDD pdev is created and stored since
1947 * it will access the HDD pdev object lock.
1948 */
1949 hdd_runtime_suspend_context_init(hdd_ctx);
1950
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001951 /* Configure NAN datapath features */
1952 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001953 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08001954 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001955}
1956
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001957bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001958{
Jeff Johnson9d295242017-08-29 14:39:48 -07001959 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07001960 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001961
Arif Hussaincd151632017-02-11 16:57:19 -08001962 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001963 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001964 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301965 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001966 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001967
Dustin Brown920397d2017-12-13 16:27:50 -08001968 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08001969 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1970
1971 if ((QDF_SAP_MODE == adapter->device_mode ||
1972 QDF_P2P_GO_MODE == adapter->device_mode) &&
1973 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07001974 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08001975 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1976 true;
1977 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07001978 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301979 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001980 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301981
1982 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001983}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001984
1985/**
1986 * hdd_is_valid_mac_address() - validate MAC address
1987 * @pMacAddr: Pointer to the input MAC address
1988 *
1989 * This function validates whether the given MAC address is valid or not
1990 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1991 * where X is the hexa decimal digit character and separated by ':'
1992 * This algorithm works even if MAC address is not separated by ':'
1993 *
1994 * This code checks given input string mac contains exactly 12 hexadecimal
1995 * digits and a separator colon : appears in the input string only after
1996 * an even number of hex digits.
1997 *
1998 * Return: 1 for valid and 0 for invalid
1999 */
2000bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2001{
2002 int xdigit = 0;
2003 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002004
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002005 while (*pMacAddr) {
2006 if (isxdigit(*pMacAddr)) {
2007 xdigit++;
2008 } else if (':' == *pMacAddr) {
2009 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2010 break;
2011
2012 ++separator;
2013 } else {
2014 /* Invalid MAC found */
2015 return 0;
2016 }
2017 ++pMacAddr;
2018 }
2019 return xdigit == 12 && (separator == 5 || separator == 0);
2020}
2021
2022/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302023 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2024 * @dev: Handle to struct net_device to be updated.
2025 *
2026 * Return: None
2027 */
2028static void hdd_mon_mode_ether_setup(struct net_device *dev)
2029{
2030 dev->header_ops = NULL;
2031 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2032 dev->hard_header_len = ETH_HLEN;
2033 dev->mtu = ETH_DATA_LEN;
2034 dev->addr_len = ETH_ALEN;
2035 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2036 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2037 dev->priv_flags |= IFF_TX_SKB_SHARING;
2038
2039 memset(dev->broadcast, 0xFF, ETH_ALEN);
2040}
2041
2042/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002043 * __hdd__mon_open() - HDD Open function
2044 * @dev: Pointer to net_device structure
2045 *
2046 * This is called in response to ifconfig up
2047 *
2048 * Return: 0 for success; non-zero for failure
2049 */
2050static int __hdd_mon_open(struct net_device *dev)
2051{
2052 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002053 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2054 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002055
2056 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002057
2058 ret = wlan_hdd_validate_context(hdd_ctx);
2059 if (ret)
2060 return ret;
2061
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302062 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002063
2064 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2065 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2066 if (ret) {
2067 hdd_err("Failed to start WLAN modules return");
2068 return ret;
2069 }
2070 hdd_err("hdd_wlan_start_modules() successful !");
2071
2072 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2073 ret = hdd_start_adapter(adapter);
2074 if (ret) {
2075 hdd_err("Failed to start adapter :%d",
2076 adapter->device_mode);
2077 return ret;
2078 }
2079 hdd_err("hdd_start_adapters() successful !");
2080 }
2081 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2082 }
2083
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002084 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002085
2086 if (!ret)
2087 ret = hdd_enable_monitor_mode(dev);
2088
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002089 return ret;
2090}
2091
2092/**
2093 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2094 * @dev: Pointer to net_device structure
2095 *
2096 * This is called in response to ifconfig up
2097 *
2098 * Return: 0 for success; non-zero for failure
2099 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002100static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002101{
2102 int ret;
2103
2104 cds_ssr_protect(__func__);
2105 ret = __hdd_mon_open(dev);
2106 cds_ssr_unprotect(__func__);
2107
2108 return ret;
2109}
2110
2111/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302112 * hdd_start_adapter() - Wrapper function for device specific adapter
2113 * @adapter: pointer to HDD adapter
2114 *
2115 * This function is called to start the device specific adapter for
2116 * the mode passed in the adapter's device_mode.
2117 *
2118 * Return: 0 for success; non-zero for failure
2119 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002120int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302121{
2122
2123 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002124 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302125
2126 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002127 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302128
2129 switch (device_mode) {
2130 case QDF_P2P_CLIENT_MODE:
2131 case QDF_P2P_DEVICE_MODE:
2132 case QDF_OCB_MODE:
2133 case QDF_STA_MODE:
2134 case QDF_MONITOR_MODE:
2135 ret = hdd_start_station_adapter(adapter);
2136 if (ret)
2137 goto err_start_adapter;
2138 break;
2139 case QDF_P2P_GO_MODE:
2140 case QDF_SAP_MODE:
2141 ret = hdd_start_ap_adapter(adapter);
2142 if (ret)
2143 goto err_start_adapter;
2144 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302145 case QDF_IBSS_MODE:
2146 /*
2147 * For IBSS interface is initialized as part of
2148 * hdd_init_station_mode()
2149 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002150 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302151 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002152 /* vdevs are dynamically managed by firmware in FTM */
2153 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302154 default:
2155 hdd_err("Invalid session type %d", device_mode);
2156 QDF_ASSERT(0);
2157 goto err_start_adapter;
2158 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002159
Arun Khandavallifae92942016-08-01 13:31:08 +05302160 if (hdd_set_fw_params(adapter))
2161 hdd_err("Failed to set the FW params for the adapter!");
2162
2163 /*
2164 * Action frame registered in one adapter which will
2165 * applicable to all interfaces
2166 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302167 ret = wlan_hdd_cfg80211_register_frames(adapter);
2168 if (ret < 0) {
2169 hdd_err("Failed to register frames - ret %d", ret);
2170 goto err_start_adapter;
2171 }
2172
Dustin Browndb2a8be2017-12-20 11:49:56 -08002173exit_with_success:
Arun Khandavallifae92942016-08-01 13:31:08 +05302174 EXIT();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002175
Arun Khandavallifae92942016-08-01 13:31:08 +05302176 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002177
Arun Khandavallifae92942016-08-01 13:31:08 +05302178err_start_adapter:
2179 return -EINVAL;
2180}
2181
2182/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302183 * hdd_enable_power_management() - API to Enable Power Management
2184 *
2185 * API invokes Bus Interface Layer power management functionality
2186 *
2187 * Return: None
2188 */
2189static void hdd_enable_power_management(void)
2190{
2191 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2192
2193 if (!hif_ctx) {
2194 hdd_err("Bus Interface Context is Invalid");
2195 return;
2196 }
2197
2198 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2199}
2200
2201/**
2202 * hdd_disable_power_management() - API to disable Power Management
2203 *
2204 * API disable Bus Interface Layer Power management functionality
2205 *
2206 * Return: None
2207 */
2208static void hdd_disable_power_management(void)
2209{
2210 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2211
2212 if (!hif_ctx) {
2213 hdd_err("Bus Interface Context is Invalid");
2214 return;
2215 }
2216
2217 hif_disable_power_management(hif_ctx);
2218}
2219
2220/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302221 * hdd_update_hw_sw_info() - API to update the HW/SW information
2222 *
2223 * API to update the HW and SW information in the driver
2224 *
2225 * Return: None
2226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002227static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302228{
2229 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002230 size_t target_hw_name_len;
2231 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302232
2233 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2234 if (!hif_sc) {
2235 hdd_err("HIF context is NULL");
2236 return;
2237 }
2238
2239 /*
2240 * target hw version/revision would only be retrieved after firmware
2241 * download
2242 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002243 hif_get_hw_info(hif_sc,
2244 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302245 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002246 &target_hw_name);
2247
2248 if (hdd_ctx->target_hw_name)
2249 qdf_mem_free(hdd_ctx->target_hw_name);
2250
2251 target_hw_name_len = strlen(target_hw_name) + 1;
2252 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2253 if (hdd_ctx->target_hw_name)
2254 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2255 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302256
2257 /* Get the wlan hw/fw version */
2258 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302259}
2260
2261/**
gbian62edd7e2017-03-07 13:12:13 +08002262 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2263 * @hdd_ctx: Pointer to hdd context
2264 *
2265 * Return: none
2266 */
2267static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002268hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002269{
2270 uint8_t num_entries = 0;
2271 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2272 uint8_t *tx_sched_wrr_ac;
2273 int i;
2274 cds_context_type *cds_ctx;
2275
2276 if (NULL == hdd_ctx)
2277 return;
2278
2279 if (NULL == hdd_ctx->config) {
2280 /* Do nothing if hdd_ctx is invalid */
2281 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2282 return;
2283 }
2284
2285 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2286
2287 if (!cds_ctx) {
2288 hdd_err("Invalid CDS Context");
2289 return;
2290 }
2291
2292 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2293 switch (i) {
2294 case OL_TX_WMM_AC_BE:
2295 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2296 break;
2297 case OL_TX_WMM_AC_BK:
2298 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2299 break;
2300 case OL_TX_WMM_AC_VI:
2301 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2302 break;
2303 case OL_TX_WMM_AC_VO:
2304 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2305 break;
2306 default:
2307 tx_sched_wrr_ac = NULL;
2308 break;
2309 }
2310
2311 hdd_string_to_u8_array(tx_sched_wrr_ac,
2312 tx_sched_wrr_param,
2313 &num_entries,
2314 sizeof(tx_sched_wrr_param));
2315
2316 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2317 cds_ctx->ac_specs[i].wrr_skip_weight =
2318 tx_sched_wrr_param[0];
2319 cds_ctx->ac_specs[i].credit_threshold =
2320 tx_sched_wrr_param[1];
2321 cds_ctx->ac_specs[i].send_limit =
2322 tx_sched_wrr_param[2];
2323 cds_ctx->ac_specs[i].credit_reserve =
2324 tx_sched_wrr_param[3];
2325 cds_ctx->ac_specs[i].discard_weight =
2326 tx_sched_wrr_param[4];
2327 }
2328
2329 num_entries = 0;
2330 }
2331}
2332
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002333#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002334static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2335 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2336{
Jeff Johnson9d295242017-08-29 14:39:48 -07002337 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002338 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002339
2340 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2341 if (!adapter) {
2342 hdd_err("Adapter is NULL");
2343 return PM_MAX_NUM_OF_MODE;
2344 }
2345
2346 return policy_mgr_convert_device_mode_to_qdf_type(
2347 adapter->device_mode);
2348}
2349
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002350static void hdd_register_policy_manager_callback(
2351 struct wlan_objmgr_psoc *psoc)
2352{
2353 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002354
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002355 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002356 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002357 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2358 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002359 hdd_cbacks.get_mode_for_non_connected_vdev =
2360 wlan_hdd_get_mode_for_non_connected_vdev;
2361
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002362 if (QDF_STATUS_SUCCESS !=
2363 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2364 hdd_err("HDD callback registration with policy manager failed");
2365 }
2366}
2367#else
2368static void hdd_register_policy_manager_callback(
2369 struct wlan_objmgr_psoc *psoc)
2370{
2371}
2372#endif
2373
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002374#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002375static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002376{
2377 struct nan_callbacks cb_obj = {0};
2378
2379 cb_obj.ndi_open = hdd_ndi_open;
2380 cb_obj.ndi_close = hdd_ndi_close;
2381 cb_obj.ndi_start = hdd_ndi_start;
2382 cb_obj.ndi_delete = hdd_ndi_delete;
2383 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2384 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2385
Naveen Rawat37f62c82017-03-26 22:24:43 -07002386 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2387 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002388 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002389
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002390 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2391}
2392#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002393static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002394{
2395}
2396#endif
2397
Dustin Brown26b3d042017-12-21 11:13:27 -08002398#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002399/**
2400 * hdd_check_for_leaks() - Perform runtime memory leak checks
2401 *
2402 * This API triggers runtime memory leak detection. This feature enforces the
2403 * policy that any memory allocated at runtime must also be released at runtime.
2404 *
2405 * Allocating memory at runtime and releasing it at unload is effectively a
2406 * memory leak for configurations which never unload (e.g. LONU, statically
2407 * compiled driver). Such memory leaks are NOT false positives, and must be
2408 * fixed.
2409 *
2410 * Return: None
2411 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002412static void hdd_check_for_leaks(void)
2413{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002414 /* DO NOT REMOVE these checks; for false positives, read above first */
2415
Dustin Brown677e0862017-10-10 16:30:09 -07002416 qdf_mc_timer_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002417 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002418}
2419
Dustin Brown26b3d042017-12-21 11:13:27 -08002420#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2421#else
2422static inline void hdd_check_for_leaks(void) {}
2423
2424#define hdd_debug_domain_set(domain)
2425#endif /* CONFIG_LEAK_DETECTION */
2426
gbian62edd7e2017-03-07 13:12:13 +08002427/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302428 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2429 * @hdd_ctx: HDD context
2430 * @adapter: HDD adapter
2431 * @reinit: flag to indicate from SSR or normal path
2432 *
2433 * This function maintains the driver state machine it will be invoked from
2434 * startup, reinit and change interface. Depending on the driver state shall
2435 * perform the opening of the modules.
2436 *
2437 * Return: 0 for success; non-zero for failure
2438 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002439int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2440 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302441 bool reinit)
2442{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002443 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302444 qdf_device_t qdf_dev;
2445 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302446 bool unint = false;
2447 void *hif_ctx;
2448
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002449 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302450
2451 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2452 if (!qdf_dev) {
2453 hdd_err("QDF Device Context is Invalid return");
2454 return -EINVAL;
2455 }
2456
Dustin Brown6f427922017-09-19 12:19:00 -07002457 hdd_set_idle_ps_config(hdd_ctx, false);
2458 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302459
Dustin Brown1fe30a82017-10-03 16:13:36 -07002460 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302461 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2462 mutex_unlock(&hdd_ctx->iface_change_lock);
2463 hdd_info("Driver modules already Enabled");
2464 EXIT();
2465 return 0;
2466 }
2467
Dustin Brown1fe30a82017-10-03 16:13:36 -07002468 hdd_ctx->start_modules_in_progress = true;
2469
Arun Khandavallifae92942016-08-01 13:31:08 +05302470 switch (hdd_ctx->driver_status) {
2471 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002472 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302473 unint = true;
2474 /* Fall through dont add break here */
2475 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002476 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2477
Dustin Brown26b3d042017-12-21 11:13:27 -08002478 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002479
Arun Khandavallifae92942016-08-01 13:31:08 +05302480 if (!reinit && !unint) {
2481 ret = pld_power_on(qdf_dev->dev);
2482 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002483 hdd_err("Failed to Powerup the device; errno: %d",
2484 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302485 goto release_lock;
2486 }
2487 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002488
2489 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2490 hdd_ctx->config->enable_fw_log);
2491
Arun Khandavallifae92942016-08-01 13:31:08 +05302492 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2493 qdf_dev->bus_type,
2494 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2495 HIF_ENABLE_TYPE_PROBE);
2496 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002497 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302498 goto power_down;
2499 }
2500
2501 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302502 if (!hif_ctx) {
2503 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002504 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302505 goto power_down;
2506 }
2507
Arun Khandavallifae92942016-08-01 13:31:08 +05302508 status = ol_cds_init(qdf_dev, hif_ctx);
2509 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002510 hdd_err("No Memory to Create BMI Context; status: %d",
2511 status);
2512 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302513 goto hif_close;
2514 }
2515
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002516 ret = hdd_update_config(hdd_ctx);
2517 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002518 hdd_err("Failed to update configuration; errno: %d",
2519 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002520 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002521 }
2522
gbian62edd7e2017-03-07 13:12:13 +08002523 hdd_update_cds_ac_specs_params(hdd_ctx);
2524
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302525 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002526 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002527 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002528 ret = qdf_status_to_os_return(status);
2529 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302530 }
2531
Mukul Sharma9d797a02017-01-05 20:26:03 +05302532 /* initalize components configurations after psoc open */
2533 ret = hdd_update_components_config(hdd_ctx);
2534 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002535 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302536 ret);
2537 goto close;
2538 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002539 status = cds_dp_open(hdd_ctx->hdd_psoc);
2540 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002541 hdd_err("Failed to Open cds post open; status: %d",
2542 status);
2543 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002544 goto close;
2545 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302546
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002547 /*
2548 * NAN compoenet requires certian operations like, open adapter,
2549 * close adapter, etc. to be initiated by HDD, for those
2550 * register HDD callbacks with UMAC's NAN componenet.
2551 */
2552 hdd_nan_register_callbacks(hdd_ctx);
2553
Arun Khandavallifae92942016-08-01 13:31:08 +05302554 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2555
Jeff Johnson3a280122017-09-13 07:42:00 -07002556 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302557 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002558 hdd_err("Failed to pre-enable CDS; status: %d", status);
2559 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002560 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302561 }
2562
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002563 hdd_register_policy_manager_callback(
2564 hdd_ctx->hdd_psoc);
2565
Amar Singhal0928b192017-12-01 10:50:54 -08002566 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2567
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302568 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302569 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002570 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302571
Arun Khandavallifae92942016-08-01 13:31:08 +05302572 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2573 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2574 hdd_ftm_mc_process_msg);
2575 break;
2576 }
2577 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002578 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302579 break;
2580 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302581
2582 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002583 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2584 if (ret) {
2585 hdd_err("HDD IPA UC reinit failed; errno: %d",
2586 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002587 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002588 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302589 }
2590
Arun Khandavallifae92942016-08-01 13:31:08 +05302591 /* Fall through dont add break here */
2592 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002593 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2594
Arun Khandavallifae92942016-08-01 13:31:08 +05302595 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002596 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002597 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002598 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302599 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302600 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2601 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002602 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302603 break;
2604 }
Dustin Browndca39692017-11-09 15:30:25 -08002605
2606 ret = hdd_configure_cds(hdd_ctx, adapter);
2607 if (ret) {
2608 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002609 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302610 }
Dustin Browndca39692017-11-09 15:30:25 -08002611
Komal Seelamf2136bb2016-09-28 18:30:44 +05302612 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002613
Arun Khandavallifae92942016-08-01 13:31:08 +05302614 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002615 hdd_info("Wlan transitioned (now ENABLED)");
2616
Arun Khandavallifae92942016-08-01 13:31:08 +05302617 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002618
Arun Khandavallifae92942016-08-01 13:31:08 +05302619 default:
2620 hdd_err("WLAN start invoked in wrong state! :%d\n",
2621 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002622 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302623 goto release_lock;
2624 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002625
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302626 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302627 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002628
Arun Khandavallifae92942016-08-01 13:31:08 +05302629 EXIT();
Dustin Brown550f6d22017-12-14 15:44:01 -08002630
Arun Khandavallifae92942016-08-01 13:31:08 +05302631 return 0;
2632
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002633post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002634 cds_post_disable();
Dustin Brownbd68fe12017-11-21 15:28:52 -08002635 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002636
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002637cds_txrx_free:
2638 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002639
Arun Khandavallifae92942016-08-01 13:31:08 +05302640close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002641 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002642 hdd_info("Wlan transition aborted (now CLOSED)");
2643
Jeff Johnsone4b14592017-09-13 14:23:33 -07002644 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302645
Dustin Brown28b17892017-10-10 13:29:38 -07002646deinit_config:
2647 cds_deinit_ini_config();
2648
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002649cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302650 ol_cds_free();
2651
2652hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002653 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2654 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302655power_down:
2656 if (!reinit && !unint)
2657 pld_power_off(qdf_dev->dev);
2658release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302659 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302660 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002661
2662 /* many adapter resources are not freed by design in SSR case */
2663 if (!reinit)
2664 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002665 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002666
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302667 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002668
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002669 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302670}
2671
Naveen Rawat910726a2017-03-06 11:42:51 -08002672#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002673static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002674{
2675 int ret = os_if_wifi_pos_register_nl();
2676
2677 if (ret)
2678 hdd_err("os_if_wifi_pos_register_nl failed");
2679
2680 return ret;
2681}
2682
2683static int hdd_deactivate_wifi_pos(void)
2684{
2685 int ret = os_if_wifi_pos_deregister_nl();
2686
2687 if (ret)
2688 hdd_err("os_if_wifi_pos_deregister_nl failed");
2689
2690 return ret;
2691}
2692
2693/**
2694 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2695 * @hdd_ctx: hdd context
2696 *
2697 * Return: status of operation
2698 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002699static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002700{
2701 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2702 struct hdd_config *cfg = hdd_ctx->config;
2703
2704 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2705 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2706 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2707 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2708 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2709 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2710 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2711 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2712}
2713#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002714static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002715{
2716 return oem_activate_service(hdd_ctx);
2717}
2718
2719static int hdd_deactivate_wifi_pos(void)
2720{
2721 return 0;
2722}
2723
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002724static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002725{
2726}
2727#endif
2728
Arun Khandavallifae92942016-08-01 13:31:08 +05302729/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002730 * __hdd_open() - HDD Open function
2731 * @dev: Pointer to net_device structure
2732 *
2733 * This is called in response to ifconfig up
2734 *
2735 * Return: 0 for success; non-zero for failure
2736 */
2737static int __hdd_open(struct net_device *dev)
2738{
Jeff Johnson9d295242017-08-29 14:39:48 -07002739 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002740 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002741 int ret;
2742
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002743 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302744 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002745 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002746
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302747 /* Nothing to be done if device is unloading */
2748 if (cds_is_driver_unloading()) {
2749 hdd_err("Driver is unloading can not open the hdd");
2750 return -EBUSY;
2751 }
2752
Dustin Brown01847752017-10-25 13:56:27 -07002753 if (cds_is_driver_recovering()) {
2754 hdd_err("WLAN is currently recovering; Please try again.");
2755 return -EBUSY;
2756 }
2757
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302758 mutex_lock(&hdd_init_deinit_lock);
2759
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302760 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2761
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302762 /*
2763 * This scenario can be hit in cases where in the wlan driver after
2764 * registering the netdevices and there is a failure in driver
2765 * initialization. So return error gracefully because the netdevices
2766 * will be de-registered as part of the load failure.
2767 */
2768
2769 if (!cds_is_driver_loaded()) {
2770 hdd_err("Failed to start the wlan driver!!");
2771 ret = -EIO;
2772 goto err_hdd_hdd_init_deinit_lock;
2773 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302774
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002775
Arun Khandavallifae92942016-08-01 13:31:08 +05302776 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2777 if (ret) {
2778 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302779 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302780 }
2781
2782
2783 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2784 ret = hdd_start_adapter(adapter);
2785 if (ret) {
2786 hdd_err("Failed to start adapter :%d",
2787 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302788 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302789 }
2790 }
2791
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2793 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002794 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002795 /* Enable TX queues only when we are connected */
2796 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302797 WLAN_START_ALL_NETIF_QUEUE,
2798 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002799 }
2800
Naveen Rawat286def52016-09-23 15:38:02 -07002801 /* Enable carrier and transmit queues for NDI */
2802 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002803 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002804 wlan_hdd_netif_queue_control(adapter,
2805 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2806 WLAN_CONTROL_PATH);
2807 }
2808
Naveen Rawat910726a2017-03-06 11:42:51 -08002809 hdd_populate_wifi_pos_cfg(hdd_ctx);
2810
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302811err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302812 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302813 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814 return ret;
2815}
2816
Arun Khandavallifae92942016-08-01 13:31:08 +05302817
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002818/**
2819 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2820 * @dev: Pointer to net_device structure
2821 *
2822 * This is called in response to ifconfig up
2823 *
2824 * Return: 0 for success; non-zero for failure
2825 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002826static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002827{
2828 int ret;
2829
2830 cds_ssr_protect(__func__);
2831 ret = __hdd_open(dev);
2832 cds_ssr_unprotect(__func__);
2833
2834 return ret;
2835}
2836
2837/**
2838 * __hdd_stop() - HDD stop function
2839 * @dev: Pointer to net_device structure
2840 *
2841 * This is called in response to ifconfig down
2842 *
2843 * Return: 0 for success; non-zero for failure
2844 */
2845static int __hdd_stop(struct net_device *dev)
2846{
Jeff Johnson9d295242017-08-29 14:39:48 -07002847 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002848 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002849 int ret;
2850
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002851 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002852
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302853 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002854 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002855
2856 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302857 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002858 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002859
2860 /* Nothing to be done if the interface is not opened */
2861 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002862 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002863 return -ENODEV;
2864 }
2865
2866 /* Make sure the interface is marked as closed */
2867 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302868
2869 hdd_debug("Disabling Auto Power save timer");
2870 sme_ps_disable_auto_ps_timer(
2871 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002872 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302873
2874 /*
2875 * Disable TX on the interface, after this hard_start_xmit() will not
2876 * be called on that interface
2877 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002878 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2879 hdd_device_mode_to_string(adapter->device_mode),
2880 adapter->device_mode);
2881
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302882 wlan_hdd_netif_queue_control(adapter,
2883 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2884 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002885
2886 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002887 * NAN data interface is different in some sense. The traffic on NDI is
2888 * bursty in nature and depends on the need to transfer. The service
2889 * layer may down the interface after the usage and up again when
2890 * required. In some sense, the NDI is expected to be available
2891 * (like SAP) iface until NDI delete request is issued by the service
2892 * layer. Skip BSS termination and adapter deletion for NAN Data
2893 * interface (NDI).
2894 */
2895 if (WLAN_HDD_IS_NDI(adapter))
2896 return 0;
2897
2898 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002899 * The interface is marked as down for outside world (aka kernel)
2900 * But the driver is pretty much alive inside. The driver needs to
2901 * tear down the existing connection on the netdev (session)
2902 * cleanup the data pipes and wait until the control plane is stabilized
2903 * for this interface. The call also needs to wait until the above
2904 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002905 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002906 * That is intentional to be able to scan if it is a STA/P2P interface
2907 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002908 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002909
2910 /* DeInit the adapter. This ensures datapath cleanup as well */
2911 hdd_deinit_adapter(hdd_ctx, adapter, true);
2912
Arun Khandavallifae92942016-08-01 13:31:08 +05302913
2914 /*
2915 * Find if any iface is up. If any iface is up then can't put device to
2916 * sleep/power save mode
2917 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302918 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002919 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07002920 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
2921 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302922 hdd_prevent_suspend_timeout(
2923 hdd_ctx->config->iface_change_wait_time,
2924 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302925 }
2926
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002927 EXIT();
2928 return 0;
2929}
2930
2931/**
2932 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2933 * @dev: pointer to net_device structure
2934 *
2935 * This is called in response to ifconfig down
2936 *
2937 * Return: 0 for success and error number for failure
2938 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002939static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002940{
2941 int ret;
2942
2943 cds_ssr_protect(__func__);
2944 ret = __hdd_stop(dev);
2945 cds_ssr_unprotect(__func__);
2946
2947 return ret;
2948}
2949
2950/**
2951 * __hdd_uninit() - HDD uninit function
2952 * @dev: Pointer to net_device structure
2953 *
2954 * This is called during the netdev unregister to uninitialize all data
2955 * associated with the device
2956 *
2957 * Return: None
2958 */
2959static void __hdd_uninit(struct net_device *dev)
2960{
Jeff Johnson9d295242017-08-29 14:39:48 -07002961 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002962 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002963
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002964 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002965
2966 do {
2967 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002968 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002969 break;
2970 }
2971
Jeff Johnson399c6272017-08-30 10:51:00 -07002972 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2973 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002974 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002975 break;
2976 }
2977
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002978 if (dev != adapter->dev)
2979 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002980
Jeff Johnson399c6272017-08-30 10:51:00 -07002981 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982
2983 /* after uninit our adapter structure will no longer be valid */
2984 adapter->dev = NULL;
2985 adapter->magic = 0;
2986 } while (0);
2987
2988 EXIT();
2989}
2990
2991/**
2992 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2993 * @dev: pointer to net_device structure
2994 *
2995 * This is called during the netdev unregister to uninitialize all data
2996 * associated with the device
2997 *
2998 * Return: none
2999 */
3000static void hdd_uninit(struct net_device *dev)
3001{
3002 cds_ssr_protect(__func__);
3003 __hdd_uninit(dev);
3004 cds_ssr_unprotect(__func__);
3005}
3006
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003007static int hdd_open_cesium_nl_sock(void)
3008{
3009#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3010 struct netlink_kernel_cfg cfg = {
3011 .groups = WLAN_NLINK_MCAST_GRP_ID,
3012 .input = NULL
3013 };
3014#endif
3015 int ret = 0;
3016
3017#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3018 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3019#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3020 THIS_MODULE,
3021#endif
3022 &cfg);
3023#else
3024 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3025 WLAN_NLINK_MCAST_GRP_ID,
3026 NULL, NULL, THIS_MODULE);
3027#endif
3028
3029 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003030 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003031 ret = -ECONNREFUSED;
3032 }
3033
3034 return ret;
3035}
3036
3037static void hdd_close_cesium_nl_sock(void)
3038{
3039 if (NULL != cesium_nl_srv_sock) {
3040 netlink_kernel_release(cesium_nl_srv_sock);
3041 cesium_nl_srv_sock = NULL;
3042 }
3043}
3044
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003045/**
3046 * __hdd_set_mac_address() - set the user specified mac address
3047 * @dev: Pointer to the net device.
3048 * @addr: Pointer to the sockaddr.
3049 *
3050 * This function sets the user specified mac address using
3051 * the command ifconfig wlanX hw ether <mac adress>.
3052 *
3053 * Return: 0 for success, non zero for failure
3054 */
3055static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3056{
Jeff Johnson9d295242017-08-29 14:39:48 -07003057 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003058 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303060 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003061 int ret;
3062
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003063 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003064
3065 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3066 ret = wlan_hdd_validate_context(hdd_ctx);
3067 if (0 != ret)
3068 return ret;
3069
Jeff Johnson1e851a12017-10-28 14:36:12 -07003070 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003071 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3072
3073 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303074 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003075}
3076
3077/**
3078 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3079 * function from SSR
3080 * @dev: pointer to net_device structure
3081 * @addr: Pointer to the sockaddr
3082 *
3083 * This function sets the user specified mac address using
3084 * the command ifconfig wlanX hw ether <mac adress>.
3085 *
3086 * Return: 0 for success.
3087 */
3088static int hdd_set_mac_address(struct net_device *dev, void *addr)
3089{
3090 int ret;
3091
3092 cds_ssr_protect(__func__);
3093 ret = __hdd_set_mac_address(dev, addr);
3094 cds_ssr_unprotect(__func__);
3095
3096 return ret;
3097}
3098
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003099uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003100{
3101 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003102
Anurag Chouhan6d760662016-02-20 16:05:43 +05303103 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003104 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3105 break;
3106 }
3107
Anurag Chouhan6d760662016-02-20 16:05:43 +05303108 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003109 return NULL;
3110
3111 hdd_ctx->config->intfAddrMask |= (1 << i);
3112 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3113}
3114
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003115void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3116 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003117{
3118 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003119
Anurag Chouhan6d760662016-02-20 16:05:43 +05303120 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121 if (!memcmp(releaseAddr,
3122 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3123 6)) {
3124 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3125 break;
3126 }
3127 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003128}
3129
3130#ifdef WLAN_FEATURE_PACKET_FILTERING
3131/**
3132 * __hdd_set_multicast_list() - set the multicast address list
3133 * @dev: Pointer to the WLAN device.
3134 * @skb: Pointer to OS packet (sk_buff).
3135 *
3136 * This funciton sets the multicast address list.
3137 *
3138 * Return: None
3139 */
3140static void __hdd_set_multicast_list(struct net_device *dev)
3141{
Jeff Johnson9d295242017-08-29 14:39:48 -07003142 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003143 int i = 0, status;
3144 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003145 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303146 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3147 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3148 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003149
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003150 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303151 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303152 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303153
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303155 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303156 goto out;
3157
Dustin Brownc788acb2017-08-01 17:43:51 -07003158 status = hdd_validate_adapter(adapter);
3159 if (status)
3160 goto out;
3161
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303162 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3163 hdd_err("%s: Driver module is closed", __func__);
3164 return;
3165 }
3166
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303167 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3168 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003169 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303170 goto out;
3171 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003172
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303173 /* Delete already configured multicast address list */
3174 if (adapter->mc_addr_list.mc_cnt > 0) {
3175 hdd_info("clear previously configured MC address list");
3176 hdd_disable_and_flush_mc_addr_list(adapter,
3177 pmo_mc_list_change_notify);
3178 }
3179
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003180 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003181 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303182 hdd_disable_and_flush_mc_addr_list(adapter,
3183 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003184 } else {
3185 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303186 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003187 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303188 pmo_ucfg_max_mc_addr_supported(psoc));
3189 hdd_disable_and_flush_mc_addr_list(adapter,
3190 pmo_mc_list_change_notify);
3191 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003193 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003194 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303195 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003196 if (i == mc_count)
3197 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303198 memset(&(mc_list_request->mc_addr[i].bytes),
3199 0, ETH_ALEN);
3200 memcpy(&(mc_list_request->mc_addr[i].bytes),
3201 ha->addr, ETH_ALEN);
3202 hdd_info("mlist[%d] = %pM", i,
3203 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204 i++;
3205 }
3206 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303207
3208 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003209 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303210 mc_list_request->count = mc_count;
3211 status = hdd_cache_mc_addr_list(mc_list_request);
3212 if (status == 0) {
3213 hdd_enable_mc_addr_filtering(adapter,
3214 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303216 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303218out:
3219 if (mc_list_request)
3220 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303221 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003222}
3223
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003225/**
3226 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3227 * @dev: pointer to net_device
3228 *
3229 * Return: none
3230 */
3231static void hdd_set_multicast_list(struct net_device *dev)
3232{
3233 cds_ssr_protect(__func__);
3234 __hdd_set_multicast_list(dev);
3235 cds_ssr_unprotect(__func__);
3236}
3237#endif
3238
3239/**
3240 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3241 * @dev: Pointer to the WLAN device.
3242 * @skb: Pointer to OS packet (sk_buff).
3243 *
3244 * This function is registered with the Linux OS for network
3245 * core to decide which queue to use first.
3246 *
3247 * Return: ac, Queue Index/access category corresponding to UP in IP header
3248 */
3249static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3250#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3251 , void *accel_priv
3252#endif
3253#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3254 , select_queue_fallback_t fallback
3255#endif
3256)
3257{
3258 return hdd_wmm_select_queue(dev, skb);
3259}
3260
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003261static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003262 .ndo_open = hdd_open,
3263 .ndo_stop = hdd_stop,
3264 .ndo_uninit = hdd_uninit,
3265 .ndo_start_xmit = hdd_hard_start_xmit,
3266 .ndo_tx_timeout = hdd_tx_timeout,
3267 .ndo_get_stats = hdd_get_stats,
3268 .ndo_do_ioctl = hdd_ioctl,
3269 .ndo_set_mac_address = hdd_set_mac_address,
3270 .ndo_select_queue = hdd_select_queue,
3271#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273#endif
3274};
3275
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003276/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003277static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003278 .ndo_open = hdd_mon_open,
3279 .ndo_stop = hdd_stop,
3280 .ndo_get_stats = hdd_get_stats,
3281};
3282
3283/**
3284 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003285 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003286 * Return: None
3287 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003288void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003290 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003291 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003292 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003293 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003294}
3295
3296/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003297 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3298 * @hdd_ctx: global hdd context
3299 * @macAddr: mac address to assign to the interface
3300 * @name: User-visible name of the interface
3301 *
3302 * hdd adapter pointer would point to the netdev->priv space, this function
3303 * would retrive the pointer, and setup the hdd adapter configuration.
3304 *
3305 * Return: the pointer to hdd adapter, otherwise NULL
3306 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003307static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003309 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003310 const char *name)
3311{
Jeff Johnson5505db82017-11-02 21:19:23 -07003312 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003313 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003314 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303315 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316 /*
3317 * cfg80211 initialization and registration....
3318 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003319 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003320#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3321 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003322#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003323 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3324 hdd_mon_mode_ether_setup : ether_setup),
3325 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003326
Jeff Johnson5505db82017-11-02 21:19:23 -07003327 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003328
3329 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003330 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003331
Jeff Johnson9d295242017-08-29 14:39:48 -07003332 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003333 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303334 qdf_mem_set(sta_ctx->conn_info.staId,
3335 sizeof(sta_ctx->conn_info.staId),
3336 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003337 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003338 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003340 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303342 qdf_status = qdf_event_create(
3343 &adapter->qdf_session_open_event);
3344 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3345 hdd_err("Session open QDF event init failed!");
3346 free_netdev(adapter->dev);
3347 return NULL;
3348 }
3349
3350 qdf_status = qdf_event_create(
3351 &adapter->qdf_session_close_event);
3352 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3353 hdd_err("Session close QDF event init failed!");
3354 free_netdev(adapter->dev);
3355 return NULL;
3356 }
3357
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003358 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303359 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360 init_completion(&adapter->linkup_event_var);
3361 init_completion(&adapter->cancel_rem_on_chan_var);
3362 init_completion(&adapter->rem_on_chan_ready_event);
3363 init_completion(&adapter->sta_authorized_event);
3364 init_completion(&adapter->offchannel_tx_event);
3365 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003366 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003367 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303368 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003369
3370 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003371 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003372 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003373 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003374
Jeff Johnson5505db82017-11-02 21:19:23 -07003375 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003376 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003377 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003379 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003380
3381 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003382 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003383 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003384 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385
Jeff Johnson5505db82017-11-02 21:19:23 -07003386 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003388 hdd_set_station_ops(adapter->dev);
3389
Jeff Johnson5505db82017-11-02 21:19:23 -07003390 hdd_dev_setup_destructor(dev);
3391 dev->ieee80211_ptr = &adapter->wdev;
3392 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003393 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003394 adapter->wdev.netdev = dev;
3395 /* set dev's parent to underlying device */
3396 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003397 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303398 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003399 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303400 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003401 }
3402
3403 return adapter;
3404}
3405
Jeff Johnson9d295242017-08-29 14:39:48 -07003406static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003408 struct net_device *dev = adapter->dev;
3409 int ret;
3410
3411 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003413 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003414 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3415
3416 ret = dev_alloc_name(dev, dev->name);
3417 if (ret < 0) {
3418 hdd_err(
3419 "unable to get dev name: %s, err = 0x%x",
3420 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303421 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003422 }
3423 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003424
3425 ret = register_netdevice(dev);
3426 if (ret) {
3427 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3428 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303429 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430 }
3431 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003432 ret = register_netdev(dev);
3433 if (ret) {
3434 hdd_err("register_netdev(%s) failed, err = 0x%x",
3435 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303436 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437 }
3438 }
3439 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3440
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003441 EXIT();
3442
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303443 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444}
3445
Krunal Sonib51eec72017-11-20 21:53:01 -08003446QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003447{
Krunal Sonib51eec72017-11-20 21:53:01 -08003448 struct hdd_adapter *adapter;
3449 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450
Krunal Sonib51eec72017-11-20 21:53:01 -08003451 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3452 if (!hdd_ctx) {
3453 hdd_err("Invalid HDD_CTX");
3454 return QDF_STATUS_E_FAILURE;
3455 }
3456
3457 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3458 if (NULL == adapter) {
3459 hdd_err("NULL adapter");
3460 return QDF_STATUS_E_INVAL;
3461 }
3462 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303463 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003464 hdd_debug("session %d opened", adapter->session_id);
3465
3466 return QDF_STATUS_SUCCESS;
3467}
3468
3469QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3470{
3471 struct hdd_adapter *adapter;
3472 struct hdd_context *hdd_ctx;
3473
3474 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3475 if (!hdd_ctx) {
3476 hdd_err("Invalid HDD_CTX");
3477 return QDF_STATUS_E_FAILURE;
3478 }
3479
3480 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003481 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003482 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303483 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003484 }
3485
3486 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003487 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303488 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489 }
3490
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003491 /*
3492 * For NAN Data interface, the close session results in the final
3493 * indication to the userspace
3494 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003495 if (adapter->device_mode == QDF_NDI_MODE)
3496 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003497
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3499
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500 /*
3501 * We can be blocked while waiting for scheduled work to be
3502 * flushed, and the adapter structure can potentially be freed, in
3503 * which case the magic will have been reset. So make sure the
3504 * magic is still good, and hence the adapter structure is still
3505 * valid, before signaling completion
3506 */
3507 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303508 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003509
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303510 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003511}
3512
Jeff Johnson9d295242017-08-29 14:39:48 -07003513int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003514{
Dustin Brownd28772b2017-03-17 14:16:07 -07003515 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516
Dustin Brownd28772b2017-03-17 14:16:07 -07003517 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003518 if (QDF_IS_STATUS_ERROR(status))
3519 return qdf_status_to_os_return(status);
3520
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003521 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003522 if (QDF_IS_STATUS_ERROR(status))
3523 return qdf_status_to_os_return(status);
3524
3525 if (wma_capability_enhanced_mcast_filter())
3526 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3527 else
3528 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003529
3530 return qdf_status_to_os_return(status);
3531}
3532
Jeff Johnson9d295242017-08-29 14:39:48 -07003533int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003534{
3535 QDF_STATUS status;
3536 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003537 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003538 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003539
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003540 vdev_id = adapter->session_id;
3541 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003542
3543 /* vdev created sanity check */
3544 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003545 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003546 return -EINVAL;
3547 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003548 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003549 /*
3550 * In SSR case, there is no need to destroy vdev in firmware since
3551 * it has already asserted. vdev can be released directly.
3552 */
Krunal Sonib51eec72017-11-20 21:53:01 -08003553 if (cds_is_driver_recovering()) {
3554 hdd_debug("SSR: silently release the vdev for session-id: %d",
3555 adapter->session_id);
3556 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Yue Maf9782842017-05-08 12:49:49 -07003557 goto release_vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08003558 }
Yue Maf9782842017-05-08 12:49:49 -07003559
Dustin Brownd28772b2017-03-17 14:16:07 -07003560 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303561 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003562 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003563 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003564 if (QDF_IS_STATUS_ERROR(status)) {
3565 hdd_err("failed to close sme session: %d", status);
3566 return qdf_status_to_os_return(status);
3567 }
3568
3569 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303570 status = qdf_wait_for_event_completion(
3571 &adapter->qdf_session_close_event,
3572 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3573 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003574 if (adapter->device_mode == QDF_NDI_MODE)
3575 hdd_ndp_session_end_handler(adapter);
3576 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303577 adapter->session_id = HDD_SESSION_ID_INVALID;
3578 if (QDF_STATUS_E_TIMEOUT != status) {
3579 hdd_err("timed out waiting for close sme session: %u", status);
3580 return -ETIMEDOUT;
3581 } else if (adapter->qdf_session_close_event.force_set) {
3582 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
3583 return -EINVAL;
3584 } else {
3585 hdd_err("Failed to close sme session (%u)", status);
3586 return -EINVAL;
3587 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003588 }
Yue Maf9782842017-05-08 12:49:49 -07003589release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003590 /* do vdev logical destroy via objmgr */
3591 errno = hdd_objmgr_destroy_vdev(adapter);
3592 if (errno) {
3593 hdd_err("failed to destroy objmgr vdev: %d", errno);
3594 return errno;
3595 }
3596
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003597 /* now that sme session is closed, allow physical vdev destroy */
3598 errno = hdd_objmgr_release_vdev(adapter);
3599 if (errno) {
3600 hdd_err("failed to release objmgr vdev: %d", errno);
3601 return errno;
3602 }
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003603 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003604
3605 return 0;
3606}
3607
Krunal Sonib51eec72017-11-20 21:53:01 -08003608static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3609 struct sme_session_params *session_param,
3610 csr_roam_completeCallback callback,
3611 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003612{
Dustin Brownd28772b2017-03-17 14:16:07 -07003613 uint32_t type;
3614 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003615 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003616
3617 /* determine vdev (sub)type */
3618 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303619 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003620 hdd_err("failed to get vdev type: %d", status);
3621 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003622 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003623 session_param->sme_session_id = adapter->session_id;
3624 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3625 session_param->type_of_persona = type;
3626 session_param->subtype_of_persona = sub_type;
3627 session_param->session_open_cb = hdd_sme_open_session_callback;
3628 session_param->session_close_cb = hdd_sme_close_session_callback;
3629 session_param->callback = callback;
3630 session_param->callback_ctx = callback_ctx;
3631
3632 return 0;
3633}
3634
3635int hdd_vdev_create(struct hdd_adapter *adapter,
3636 csr_roam_completeCallback callback, void *ctx)
3637{
3638 QDF_STATUS status;
3639 int errno;
3640 struct hdd_context *hdd_ctx;
3641 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003642
3643 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003644
3645 /* do vdev create via objmgr */
3646 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003647 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003648 if (errno) {
3649 hdd_err("failed to create objmgr vdev: %d", errno);
3650 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003651 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003652
3653 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303654 status = qdf_event_reset(&adapter->qdf_session_open_event);
3655 if (QDF_STATUS_SUCCESS != status) {
3656 hdd_err("failed to reinit session open event");
3657 return -EINVAL;
3658 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003659 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3660 callback, ctx);
3661 if (errno) {
3662 hdd_err("failed to populating SME params");
3663 goto objmgr_vdev_destroy_procedure;
3664 }
3665
3666 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003667 if (QDF_IS_STATUS_ERROR(status)) {
3668 hdd_err("failed to open sme session: %d", status);
3669 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003670 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003671 }
3672
3673 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303674 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3675 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3676 if (QDF_STATUS_SUCCESS != status) {
3677 if (adapter->qdf_session_open_event.force_set) {
3678 /*
3679 * SSR/PDR has caused shutdown, which has forcefully
3680 * set the event. Return without the closing session.
3681 */
3682 adapter->session_id = HDD_SESSION_ID_INVALID;
3683 hdd_err("Session open event forcefully set");
3684 return -EINVAL;
3685 } else {
3686 if (QDF_STATUS_E_TIMEOUT == status)
3687 hdd_err("Session failed to open within timeout period");
3688 else
3689 hdd_err("Failed to wait for session open event(status-%d)",
3690 status);
3691 errno = -ETIMEDOUT;
3692 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3693 goto hdd_vdev_destroy_procedure;
3694 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003695 }
3696
3697 /* firmware ready for component communication, raise vdev_ready event */
3698 errno = hdd_vdev_ready(adapter);
3699 if (errno) {
3700 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003701 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003702 }
3703
Jeff Johnson1b780e42017-10-31 14:11:45 -07003704 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003705
3706 return 0;
3707
3708 /*
3709 * Due to legacy constraints, we need to destroy in the same order as
3710 * create. So, split error handling into 2 cases to accommodate.
3711 */
3712
Krunal Soni4a020c72017-10-30 20:58:40 -07003713objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003714 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003715
3716 return errno;
3717
Krunal Soni4a020c72017-10-30 20:58:40 -07003718hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003719 QDF_BUG(!hdd_vdev_destroy(adapter));
3720
3721 return errno;
3722}
3723
Jeff Johnson9d295242017-08-29 14:39:48 -07003724QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003725{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003726 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003727 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003728 QDF_STATUS status;
3729 int ret_val;
3730
Dustin Brownd28772b2017-03-17 14:16:07 -07003731 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3732 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3733 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003734 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003735
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003736 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003737 status = hdd_register_wext(adapter->dev);
3738 if (QDF_IS_STATUS_ERROR(status)) {
3739 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003740 goto error_register_wext;
3741 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003742 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003743
Himanshu Agarwalb229a142017-12-21 10:16:45 +05303744 hdd_debug("Disabling Green AP");
3745 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev, false);
3746 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
3747
Jeff Johnsond377dce2017-10-04 10:32:42 -07003748 qdf_mem_set(sta_ctx->conn_info.staId,
3749 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303750
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003751 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003752 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003753 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003754 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003755 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003756 hdd_ctx->config->OperatingChannel;
3757
3758 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003759 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003760
3761 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303762 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003763 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003764 status, status);
3765 goto error_init_txrx;
3766 }
3767
3768 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3769
3770 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303771 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003772 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003773 status, status);
3774 goto error_wmm_init;
3775 }
3776
3777 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3778
Jeff Johnson1b780e42017-10-31 14:11:45 -07003779 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003780 WMI_PDEV_PARAM_BURST_ENABLE,
3781 hdd_ctx->config->enableSifsBurst,
3782 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003783 if (ret_val)
3784 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303786 /*
3787 * In case of USB tethering, LRO is disabled. If SSR happened
3788 * during that time, then as part of SSR init, do not enable
3789 * the LRO again. Keep the LRO state same as before SSR.
3790 */
3791 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003792 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303793
3794 /* rcpi info initialization */
3795 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3796
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303797 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003798
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003799error_wmm_init:
3800 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3801 hdd_deinit_tx_rx(adapter);
3802error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003803 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003804error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003805 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003807 return status;
3808}
3809
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303810/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003811 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303812 * @hdd_ctx: global hdd context
3813 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003814 * @rtnl_held: Used to indicate whether or not the caller is holding
3815 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303816 *
3817 * This function De-initializes the STA/P2P/OCB adapter.
3818 *
3819 * Return: None.
3820 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003821static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003822 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003823 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303824{
3825 ENTER_DEV(adapter->dev);
3826
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303827 if (adapter->dev) {
3828 if (rtnl_held)
3829 adapter->dev->wireless_handlers = NULL;
3830 else {
3831 rtnl_lock();
3832 adapter->dev->wireless_handlers = NULL;
3833 rtnl_unlock();
3834 }
3835 }
3836
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303837 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3838 hdd_deinit_tx_rx(adapter);
3839 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3840 }
3841
3842 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3843 hdd_wmm_adapter_close(adapter);
3844 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3845 }
3846
Krunal Sonib51eec72017-11-20 21:53:01 -08003847
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303848 EXIT();
3849}
3850
Krunal Sonib51eec72017-11-20 21:53:01 -08003851void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3852 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003853 bool rtnl_held)
3854{
3855 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303856
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003858 case QDF_STA_MODE:
3859 case QDF_P2P_CLIENT_MODE:
3860 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003861 case QDF_IBSS_MODE:
3862 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003863 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003864 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003865 break;
3866 }
3867
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003868 case QDF_SAP_MODE:
3869 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003871 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872 break;
3873 }
3874
3875 default:
3876 break;
3877 }
3878
3879 EXIT();
3880}
3881
Jeff Johnson9d295242017-08-29 14:39:48 -07003882static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003883 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003884{
Jeff Johnson5505db82017-11-02 21:19:23 -07003885 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886
3887 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003888 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003890 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891 return;
3892 }
3893
Rajeev Kumardca5f812016-02-04 17:28:06 -08003894 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303895
Yue Ma9e89e832017-11-14 11:40:23 -08003896 hdd_adapter_runtime_suspend_deinit(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303897
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003898 /*
3899 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3900 * the driver is almost closed and cannot handle either control
3901 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003902 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3903 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003904 * is not right. Setting this flag helps hdd_stop() to recognize that
3905 * the interface is closed and restricts any operations on that
3906 */
3907 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3908
3909 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003910 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003911 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003912 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003913 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 /*
3915 * Note that the adapter is no longer valid at this point
3916 * since the memory has been reclaimed
3917 */
3918 }
3919}
3920
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003921static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003922 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923{
Jeff Johnson9d295242017-08-29 14:39:48 -07003924 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003925
Dustin Brown920397d2017-12-13 16:27:50 -08003926 hdd_for_each_adapter(hdd_ctx, adapter) {
3927 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
3928 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303929 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 }
Dustin Brown920397d2017-12-13 16:27:50 -08003932
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303933 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003934}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003935
Arun Khandavalli2358d522016-05-16 18:05:37 +05303936#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3937/**
3938 * hdd_set_fw_log_params() - Set log parameters to FW
3939 * @hdd_ctx: HDD Context
3940 * @adapter: HDD Adapter
3941 *
3942 * This function set the FW Debug log level based on the INI.
3943 *
3944 * Return: None
3945 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003946static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003947 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303948{
3949 uint8_t count = 0, numentries = 0,
3950 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3951 uint32_t value = 0;
3952 int ret;
3953
Arun Khandavallifae92942016-08-01 13:31:08 +05303954 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3955 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003956 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303957 return;
3958 }
3959
Arun Khandavallifae92942016-08-01 13:31:08 +05303960 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303961 hdd_ctx->fw_log_settings.dl_type =
3962 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003963 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303964 WMI_DBGLOG_TYPE,
3965 hdd_ctx->config->enableFwLogType,
3966 DBG_CMD);
3967 if (ret != 0)
3968 hdd_err("Failed to enable FW log type ret %d",
3969 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303970
3971 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303972 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003973 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303974 WMI_DBGLOG_LOG_LEVEL,
3975 hdd_ctx->config->enableFwLogLevel,
3976 DBG_CMD);
3977 if (ret != 0)
3978 hdd_err("Failed to enable FW log level ret %d",
3979 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303980
3981 hdd_string_to_u8_array(
3982 hdd_ctx->config->enableFwModuleLogLevel,
3983 moduleloglevel,
3984 &numentries,
3985 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3986
3987 while (count < numentries) {
3988 /*
3989 * FW module log level input string looks like
3990 * below:
3991 * gFwDebugModuleLoglevel=<FW Module ID>,
3992 * <Log Level>,...
3993 * For example:
3994 * gFwDebugModuleLoglevel=
3995 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3996 * Above input string means :
3997 * For FW module ID 1 enable log level 0
3998 * For FW module ID 2 enable log level 1
3999 * For FW module ID 3 enable log level 2
4000 * For FW module ID 4 enable log level 3
4001 * For FW module ID 5 enable log level 4
4002 * For FW module ID 6 enable log level 5
4003 * For FW module ID 7 enable log level 6
4004 */
4005
Nishank Aggarwale239d962017-03-03 12:26:02 +05304006 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4007 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4008 hdd_err("Module id %d and dbglog level %d input length is more than max",
4009 moduleloglevel[count],
4010 moduleloglevel[count + 1]);
4011 return;
4012 }
4013
4014 value = moduleloglevel[count] << 16;
4015 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004016 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304017 WMI_DBGLOG_MOD_LOG_LEVEL,
4018 value, DBG_CMD);
4019 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304020 hdd_err("Failed to enable FW module log level %d ret %d",
4021 value, ret);
4022
4023 count += 2;
4024 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304025
Arun Khandavalli2358d522016-05-16 18:05:37 +05304026}
4027#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004028static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004029 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304030{
4031}
4032
4033#endif
4034
4035/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004036 * hdd_configure_chain_mask() - programs chain mask to firmware
4037 * @adapter: HDD adapter
4038 *
4039 * Return: 0 on success or errno on failure
4040 */
4041static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4042{
4043 int ret_val;
4044 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4045
4046 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4047 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4048 hdd_ctx->config->txchainmask1x1,
4049 hdd_ctx->config->rxchainmask1x1);
4050 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4051 hdd_ctx->config->dual_mac_feature_disable,
4052 hdd_ctx->config->tx_chain_mask_2g,
4053 hdd_ctx->config->rx_chain_mask_2g);
4054 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4055 hdd_ctx->config->tx_chain_mask_5g,
4056 hdd_ctx->config->rx_chain_mask_5g);
4057
4058 if (hdd_ctx->config->enable2x2) {
4059 hdd_info("2x2 enabled. skip chain mask programming");
4060 return 0;
4061 }
4062
4063 if (hdd_ctx->config->txchainmask1x1) {
4064 ret_val = sme_cli_set_command(adapter->session_id,
4065 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4066 hdd_ctx->config->txchainmask1x1,
4067 PDEV_CMD);
4068 if (ret_val)
4069 goto error;
4070 }
4071
4072 if (hdd_ctx->config->rxchainmask1x1) {
4073 ret_val = sme_cli_set_command(adapter->session_id,
4074 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4075 hdd_ctx->config->rxchainmask1x1,
4076 PDEV_CMD);
4077 if (ret_val)
4078 goto error;
4079 }
4080
4081 if (hdd_ctx->lte_coex_ant_share) {
4082 hdd_info("lte ant sharing enabled. skip per band chain mask");
4083 return 0;
4084 }
4085
4086 if (hdd_ctx->config->txchainmask1x1 ||
4087 hdd_ctx->config->rxchainmask1x1) {
4088 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4089 return 0;
4090 }
4091
4092 if (!hdd_ctx->config->dual_mac_feature_disable) {
4093 hdd_info("DBS enabled. skip per band chain mask");
4094 return 0;
4095 }
4096
4097 if (hdd_ctx->config->tx_chain_mask_2g) {
4098 ret_val = sme_cli_set_command(adapter->session_id,
4099 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4100 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4101 if (0 != ret_val)
4102 goto error;
4103 }
4104
4105 if (hdd_ctx->config->rx_chain_mask_2g) {
4106 ret_val = sme_cli_set_command(adapter->session_id,
4107 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4108 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4109 if (0 != ret_val)
4110 goto error;
4111 }
4112
4113 if (hdd_ctx->config->tx_chain_mask_5g) {
4114 ret_val = sme_cli_set_command(adapter->session_id,
4115 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4116 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4117 if (0 != ret_val)
4118 goto error;
4119 }
4120
4121 if (hdd_ctx->config->rx_chain_mask_5g) {
4122 ret_val = sme_cli_set_command(adapter->session_id,
4123 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4124 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4125 if (0 != ret_val)
4126 goto error;
4127 }
4128
4129 return 0;
4130
4131error:
4132 hdd_err("WMI PDEV set param failed %d", ret_val);
4133 return -EINVAL;
4134}
4135
4136/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304137 * hdd_set_fw_params() - Set parameters to firmware
4138 * @adapter: HDD adapter
4139 *
4140 * This function Sets various parameters to fw once the
4141 * adapter is started.
4142 *
4143 * Return: 0 on success or errno on failure
4144 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004145int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304146{
4147 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004148 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304149
4150 ENTER_DEV(adapter->dev);
4151
4152 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4153 if (!hdd_ctx)
4154 return -EINVAL;
4155
Dustin Brown732ab9c2017-06-15 13:24:09 -07004156 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4157 hdd_debug("FTM Mode is active; nothing to do");
4158 return 0;
4159 }
4160
Jeff Johnson1b780e42017-10-31 14:11:45 -07004161 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304162 WMI_PDEV_PARAM_DTIM_SYNTH,
4163 hdd_ctx->config->enable_lprx, PDEV_CMD);
4164 if (ret) {
4165 hdd_err("Failed to set LPRx");
4166 goto error;
4167 }
4168
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304169 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004170 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304171 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4172 hdd_ctx->config->upper_brssi_thresh);
4173
Jeff Johnson1b780e42017-10-31 14:11:45 -07004174 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304175 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4176 hdd_ctx->config->lower_brssi_thresh);
4177
Jeff Johnson1b780e42017-10-31 14:11:45 -07004178 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304179 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4180 hdd_ctx->config->enable_dtim_1chrx);
4181 }
4182
Dustin Brown732ab9c2017-06-15 13:24:09 -07004183 if (hdd_ctx->config->enable2x2) {
4184 hdd_debug("configuring 2x2 mode fw params");
4185
Jeff Johnson1b780e42017-10-31 14:11:45 -07004186 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004187 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4188 hdd_ctx->config->enable_cck_tx_fir_override,
4189 PDEV_CMD);
4190 if (ret) {
4191 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4192 ret);
4193 goto error;
4194 }
4195 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304196#define HDD_DTIM_1CHAIN_RX_ID 0x5
4197#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004198 hdd_debug("configuring 1x1 mode fw params");
4199
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004200 /*
4201 * Disable DTIM 1 chain Rx when in 1x1,
4202 * we are passing two value
4203 * as param_id << 29 | param_value.
4204 * Below param_value = 0(disable)
4205 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004206 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004207 WMI_STA_SMPS_PARAM_CMDID,
4208 HDD_DTIM_1CHAIN_RX_ID <<
4209 HDD_SMPS_PARAM_VALUE_S,
4210 VDEV_CMD);
4211 if (ret) {
4212 hdd_err("DTIM 1 chain set failed %d", ret);
4213 goto error;
4214 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304215
Arun Khandavalli2358d522016-05-16 18:05:37 +05304216#undef HDD_DTIM_1CHAIN_RX_ID
4217#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004218
4219 if (hdd_configure_chain_mask(adapter))
4220 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004221 }
4222
Jeff Johnson1b780e42017-10-31 14:11:45 -07004223 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004224 WMI_PDEV_PARAM_HYST_EN,
4225 hdd_ctx->config->enableMemDeepSleep,
4226 PDEV_CMD);
4227 if (ret) {
4228 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4229 goto error;
4230 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304231
Jeff Johnson1b780e42017-10-31 14:11:45 -07004232 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004233 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4234 hdd_ctx->config->rts_profile,
4235 VDEV_CMD);
4236 if (ret) {
4237 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4238 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304239 }
4240
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004241 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4242
Jeff Johnson1b780e42017-10-31 14:11:45 -07004243 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004244 GEN_VDEV_PARAM_AMSDU,
4245 hdd_ctx->config->max_amsdu_num,
4246 GEN_CMD);
4247 if (ret != 0) {
4248 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4249 goto error;
4250 }
4251
Arun Khandavalli2358d522016-05-16 18:05:37 +05304252 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304253 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004254
Arun Khandavalli2358d522016-05-16 18:05:37 +05304255 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304256
Arun Khandavalli2358d522016-05-16 18:05:37 +05304257error:
4258 return -EINVAL;
4259}
4260
Ryan Hsu07495ea2016-01-21 15:25:39 -08004261/**
4262 * hdd_open_adapter() - open and setup the hdd adatper
4263 * @hdd_ctx: global hdd context
4264 * @session_type: type of the interface to be created
4265 * @iface_name: User-visible name of the interface
4266 * @macAddr: MAC address to assign to the interface
4267 * @name_assign_type: the name of assign type of the netdev
4268 * @rtnl_held: the rtnl lock hold flag
4269 *
4270 * This function open and setup the hdd adpater according to the device
4271 * type request, assign the name, the mac address assigned, and then prepared
4272 * the hdd related parameters, queue, lock and ready to start.
4273 *
4274 * Return: the pointer of hdd adapter, otherwise NULL.
4275 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004276struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004277 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004278 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004279 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280{
Jeff Johnson9d295242017-08-29 14:39:48 -07004281 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304282 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283
4284 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4285 /*
4286 * Max limit reached on the number of vdevs configured by the
4287 * host. Return error
4288 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304289 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4290 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 return NULL;
4292 }
4293
4294 if (macAddr == NULL) {
4295 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304296 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297 return NULL;
4298 }
4299 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304300 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304301 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4302 " already exists",
4303 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 return NULL;
4305 }
4306
4307 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004308 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004309 /* Reset locally administered bit if the device mode is STA */
4310 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304311 hdd_info("locally administered bit reset in sta mode: "
4312 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004314 case QDF_P2P_CLIENT_MODE:
4315 case QDF_P2P_DEVICE_MODE:
4316 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004317 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304318 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004319 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4320 name_assign_type,
4321 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322
4323 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304324 hdd_err("failed to allocate adapter for session %d",
4325 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004326 return NULL;
4327 }
4328
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004329 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004330 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004331 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004332 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304333 else if (QDF_MONITOR_MODE == session_type)
4334 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335 else
4336 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4337
4338 adapter->device_mode = session_type;
4339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341 /*
4342 * Workqueue which gets scheduled in IPv4 notification
4343 * callback
4344 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004345 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004346 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347
4348#ifdef WLAN_NS_OFFLOAD
4349 /*
4350 * Workqueue which gets scheduled in IPv6
4351 * notification callback.
4352 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004353 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354 hdd_ipv6_notifier_work_queue);
4355#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004356 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004357 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004358 goto err_deinit_adapter_runtime_pm;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004359
4360 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004361 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004362 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304363 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4364 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304365
Ravi Joshi1a292562017-05-18 16:28:54 -07004366 /* Initialize NAN Data Interface */
4367 if (QDF_NDI_MODE == session_type) {
4368 status = hdd_init_nan_data_mode(adapter);
4369 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004370 goto err_deinit_adapter_runtime_pm;
Ravi Joshi1a292562017-05-18 16:28:54 -07004371 }
4372
4373 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004374
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004375 case QDF_P2P_GO_MODE:
4376 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004377 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4378 name_assign_type,
4379 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004380 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004381 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304382 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383 return NULL;
4384 }
4385
4386 adapter->wdev.iftype =
4387 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004388 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389 NL80211_IFTYPE_P2P_GO;
4390 adapter->device_mode = session_type;
4391
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004392 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004393 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004395
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004396 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004397 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304398 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4399 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304400
4401 /*
4402 * Workqueue which gets scheduled in IPv4 notification
4403 * callback
4404 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004405 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304406 hdd_ipv4_notifier_work_queue);
4407
4408#ifdef WLAN_NS_OFFLOAD
4409 /*
4410 * Workqueue which gets scheduled in IPv6
4411 * notification callback.
4412 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004413 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304414 hdd_ipv6_notifier_work_queue);
4415#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304417 case QDF_FTM_MODE:
4418 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4419 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004420 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304421 if (NULL == adapter) {
4422 hdd_err("Failed to allocate adapter for FTM mode");
4423 return NULL;
4424 }
4425 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4426 adapter->device_mode = session_type;
4427 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004428 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004429 goto err_deinit_adapter_runtime_pm;
Krunal Sonib51eec72017-11-20 21:53:01 -08004430
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304431 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004432 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304433 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304434 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4435 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304436 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004438 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304439 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004440 return NULL;
4441 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442
hqueaa33ee2017-05-04 17:56:35 +08004443 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4444
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304445 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004447 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448 }
4449
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304450 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451 if (NULL != adapter) {
4452 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4453 adapter = NULL;
4454 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004455
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004456 return NULL;
4457 }
4458
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304459 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004460 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4461 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004462
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463 /* Adapter successfully added. Increment the vdev count */
4464 hdd_ctx->current_intf_count++;
4465
Jeff Johnson5880d792016-08-15 13:32:30 -07004466 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004467 hdd_ctx->current_intf_count);
4468
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004469 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004470 }
4471
Rajeev Kumardca5f812016-02-04 17:28:06 -08004472 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004473 hdd_err("Interface %s wow debug_fs init failed",
4474 netdev_name(adapter->dev));
4475
4476 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4477 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004478
4479 return adapter;
4480
Yue Ma9e89e832017-11-14 11:40:23 -08004481err_deinit_adapter_runtime_pm:
4482 /*
4483 * For certain error cases that hdd_alloc_station_adapter()
4484 * is used to allocate the adapter.
4485 */
4486 hdd_adapter_runtime_suspend_deinit(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004487err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004488 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304489 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004490
4491 return NULL;
4492}
4493
Jeff Johnson9d295242017-08-29 14:39:48 -07004494QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004495 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004496{
Dustin Brown920397d2017-12-13 16:27:50 -08004497 /*
4498 * Here we are stopping global bus_bw timer & work per adapter.
4499 *
4500 * The reason is to fix one race condition between
4501 * bus bandwidth work and cleaning up an adapter.
4502 * Under some conditions, it is possible for the bus bandwidth
4503 * work to access a particularly destroyed adapter, leading to
4504 * use-after-free.
4505 */
4506 hdd_debug("wait for bus bw work to flush");
4507 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4508 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004509
Dustin Brown920397d2017-12-13 16:27:50 -08004510 /* cleanup adapter */
4511 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4512 adapter->device_mode);
4513 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4514 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004515
Dustin Brown920397d2017-12-13 16:27:50 -08004516 /* conditionally restart the bw timer */
4517 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518
Dustin Brown920397d2017-12-13 16:27:50 -08004519 /* Adapter removed. Decrement vdev count */
4520 if (hdd_ctx->current_intf_count != 0)
4521 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004522
Dustin Brown920397d2017-12-13 16:27:50 -08004523 /* Fw will take care incase of concurrency */
4524 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004525}
4526
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004527/**
4528 * hdd_close_all_adapters - Close all open adapters
4529 * @hdd_ctx: Hdd context
4530 * rtnl_held: True if RTNL lock held
4531 *
4532 * Close all open adapters.
4533 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304534 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004535 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004536QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537{
Dustin Brown920397d2017-12-13 16:27:50 -08004538 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304539 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004540
4541 ENTER();
4542
4543 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004544 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4545 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304546 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004547 adapter->mac_addr.bytes);
4548 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4549
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304550 /* Adapter removed. Decrement vdev count */
4551 if (hdd_ctx->current_intf_count != 0)
4552 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004553 }
Dustin Brown920397d2017-12-13 16:27:50 -08004554 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004555
4556 EXIT();
4557
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304558 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559}
4560
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004561void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004562{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304563 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004564 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004565
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004566 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004567 case QDF_STA_MODE:
4568 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004569 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004570 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004571 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004572 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004573 break;
4574 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004575 case QDF_SAP_MODE:
4576 case QDF_P2P_GO_MODE:
4577 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004578 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004579 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004580 break;
4581 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004582 case QDF_FTM_MODE:
4583 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004584 default:
4585 /*
4586 * wlan_hdd_reset_prob_rspies should not have been called
4587 * for these kind of devices
4588 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004589 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004590 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004591 return;
4592 }
4593
Anurag Chouhanc5548422016-02-24 18:33:27 +05304594 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004595 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004596 updateIE.ieBufferlength = 0;
4597 updateIE.pAdditionIEBuffer = NULL;
4598 updateIE.append = true;
4599 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004600 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004601 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304602 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004603 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004604 }
4605}
4606
Dustin Browndb2a8be2017-12-20 11:49:56 -08004607QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4608 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004609{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304610 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004611 struct hdd_wext_state *pWextState =
4612 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004613 union iwreq_data wrqu;
4614 tSirUpdateIE updateIE;
4615 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304616 tsap_Config_t *sap_config;
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304617 bool is_enabled = false;
4618 uint8_t ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619
4620 ENTER();
4621
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004622 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304623 wlan_hdd_netif_queue_control(adapter,
4624 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4625 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004626 /*
4627 * if this is the last active connection check & stop the
4628 * opportunistic timer first
4629 */
4630 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4631 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4632 policy_mgr_convert_device_mode_to_qdf_type(
4633 adapter->device_mode), NULL) == 1)) ||
4634 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4635 policy_mgr_check_and_stop_opportunistic_timer(
4636 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004637 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004638 case QDF_STA_MODE:
4639 case QDF_P2P_CLIENT_MODE:
4640 case QDF_IBSS_MODE:
4641 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004642 case QDF_NDI_MODE:
4643 if ((QDF_NDI_MODE == adapter->device_mode) ||
4644 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004645 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4646 hdd_is_connecting(
4647 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004648 INIT_COMPLETION(adapter->disconnect_comp_var);
4649 /*
4650 * For NDI do not use pWextState from sta_ctx, if needed
4651 * extract from ndi_ctx.
4652 */
4653 if (QDF_NDI_MODE == adapter->device_mode)
4654 qdf_ret_status = sme_roam_disconnect(
4655 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004656 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004657 eCSR_DISCONNECT_REASON_NDI_DELETE);
4658 else if (pWextState->roamProfile.BSSType ==
4659 eCSR_BSS_TYPE_START_IBSS)
4660 qdf_ret_status = sme_roam_disconnect(
4661 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004662 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004663 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004664 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004665 qdf_ret_status =
4666 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004667 hdd_debug("Send disconnected event to userspace");
4668 wlan_hdd_cfg80211_indicate_disconnect(
4669 adapter->dev, true,
4670 WLAN_REASON_UNSPECIFIED);
4671 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004672 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004673 qdf_ret_status = sme_roam_disconnect(
4674 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004675 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004676 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004677 /* success implies disconnect command got
4678 * queued up successfully
4679 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004680 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4681 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004682 rc = wait_for_completion_timeout(
4683 &adapter->disconnect_comp_var,
4684 msecs_to_jiffies
4685 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004686 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004687 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004688 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004689 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4690 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004691 memset(&wrqu, '\0', sizeof(wrqu));
4692 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4693 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4694 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4695 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304696 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004697 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004698
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304699 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304700 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004701
4702#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004703 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004704#endif
4705
4706 hdd_deregister_tx_flow_control(adapter);
4707
4708#ifdef WLAN_NS_OFFLOAD
4709#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004710 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004711#endif
4712#endif
4713
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304714 if (adapter->device_mode == QDF_STA_MODE)
4715 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4716 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004717
4718 if (wlan_hdd_try_disconnect(adapter)) {
4719 hdd_err("Error: Can't disconnect adapter");
4720 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004721 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004722
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304723 ret = hdd_check_green_ap_enable(hdd_ctx, &is_enabled);
4724 if (!ret) {
4725 hdd_debug("Green AP enable status: %d", is_enabled);
4726 if (is_enabled) {
4727 hdd_debug("Enabling Green AP");
4728 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
4729 true);
4730 wlan_green_ap_start(hdd_ctx->hdd_pdev);
4731 }
4732 } else {
4733 hdd_err("Failed to check if Green AP should be enabled or not");
4734 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004735
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304736 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004737 break;
4738
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004739 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004740 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304741 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304742 sap_config = &adapter->session.ap.sap_config;
4743 if (sap_config)
4744 wlansap_reset_sap_config_add_ie(sap_config,
4745 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304746 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004747 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004748
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004749 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004750 if (QDF_SAP_MODE == adapter->device_mode) {
4751 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4752 cds_flush_delayed_work(
4753 &adapter->acs_pending_work);
4754 clear_bit(ACS_PENDING, &adapter->event_flags);
4755 }
4756 }
Krunal Soni22208392017-09-29 18:10:34 -07004757 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004758
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004759 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004760 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004761 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004762 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4763
4764 hdd_deregister_tx_flow_control(adapter);
4765
Kapil Guptac1224bf2017-06-22 21:22:40 +05304766 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004767 mutex_lock(&hdd_ctx->sap_lock);
4768 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304769 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304770 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004771
4772 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004773 status = wlansap_stop_bss(
4774 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004775
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304776 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004777 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004778 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304779 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304780 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304781 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304782 qdf_wait_for_event_completion(
4783 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004784 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004785
Anurag Chouhance0dc992016-02-16 18:18:03 +05304786 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004787 hdd_err("failure waiting for wlansap_stop_bss %d",
4788 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004789 }
4790 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004791 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004792 }
4793 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004794 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4795 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004796 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004797
Anurag Chouhanc5548422016-02-24 18:33:27 +05304798 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004799 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004800 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004801 updateIE.ieBufferlength = 0;
4802 updateIE.pAdditionIEBuffer = NULL;
4803 updateIE.append = false;
4804 updateIE.notify = false;
4805 /* Probe bcn reset */
4806 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4807 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304808 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004809 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004810 }
4811 /* Assoc resp reset */
4812 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4813 &updateIE,
4814 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304815 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004816 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004817 }
4818 /* Reset WNI_CFG_PROBE_RSP Flags */
4819 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004820 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004821 qdf_mem_free(adapter->session.ap.beacon);
4822 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304823 /*
4824 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4825 */
4826 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4827 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4828
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304829#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004830 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304831#endif
4832
4833#ifdef WLAN_NS_OFFLOAD
4834#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004835 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304836#endif
4837#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08004838
4839 hdd_vdev_destroy(adapter);
4840
Krunal Sonib51eec72017-11-20 21:53:01 -08004841 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004842 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004843 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004844 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004845 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004846 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004847 break;
4848 default:
4849 break;
4850 }
4851
Dustin Brown04348372017-12-14 16:13:39 -08004852 if (adapter->scan_info.default_scan_ies) {
4853 qdf_mem_free(adapter->scan_info.default_scan_ies);
4854 adapter->scan_info.default_scan_ies = NULL;
4855 }
4856
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857 EXIT();
Dustin Brown04348372017-12-14 16:13:39 -08004858
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304859 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004860}
4861
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304862/**
4863 * hdd_deinit_all_adapters - deinit all adapters
4864 * @hdd_ctx: HDD context
4865 * @rtnl_held: True if RTNL lock held
4866 *
4867 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004868void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304869{
Jeff Johnson9d295242017-08-29 14:39:48 -07004870 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304871
4872 ENTER();
4873
Dustin Brown920397d2017-12-13 16:27:50 -08004874 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304875 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304876
4877 EXIT();
4878}
4879
Dustin Browndb2a8be2017-12-20 11:49:56 -08004880QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004881{
Jeff Johnson9d295242017-08-29 14:39:48 -07004882 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004883
4884 ENTER();
4885
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304886 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4887
Dustin Brown920397d2017-12-13 16:27:50 -08004888 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08004889 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004890
4891 EXIT();
4892
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304893 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004894}
4895
Paul Zhang84fa9382017-11-10 21:18:21 +08004896static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4897 struct hdd_adapter *adapter)
4898{
4899 switch (adapter->device_mode) {
4900 case QDF_STA_MODE:
4901 case QDF_P2P_CLIENT_MODE:
4902 case QDF_IBSS_MODE:
4903 case QDF_P2P_DEVICE_MODE:
4904 case QDF_NDI_MODE:
4905 wlan_hdd_scan_abort(adapter);
4906 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4907 if (adapter->device_mode == QDF_STA_MODE)
4908 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4909 adapter->dev);
4910 break;
4911 case QDF_P2P_GO_MODE:
4912 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4913 break;
4914 case QDF_SAP_MODE:
4915 wlan_hdd_undo_acs(adapter);
4916 break;
4917 default:
4918 break;
4919 }
4920}
4921
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004922QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004923{
Jeff Johnson9d295242017-08-29 14:39:48 -07004924 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004925 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004926 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004927
4928 ENTER();
4929
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304930 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4931
Dustin Brown920397d2017-12-13 16:27:50 -08004932 hdd_for_each_adapter(hdd_ctx, adapter) {
Yue Mad5b4b9f2017-05-26 16:23:40 -07004933 hdd_notice("Disabling queues for adapter type: %d",
4934 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304935
4936 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004937 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304938 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004939 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304940
Arun Khandavallicc544b32017-01-30 19:52:16 +05304941 if (hdd_ctx->config->sap_internal_restart &&
4942 adapter->device_mode == QDF_SAP_MODE) {
4943 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304944 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304945 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004946 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08004947 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004948 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004949 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4950 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304951 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304952 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004953 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004954 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004955
Paul Zhang84fa9382017-11-10 21:18:21 +08004956 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07004957 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004958
4959 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004960 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004961 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004962 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4963 hdd_wmm_adapter_close(adapter);
4964 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4965 }
4966
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304967 if (adapter->device_mode == QDF_STA_MODE)
4968 hdd_clear_fils_connection_info(adapter);
4969
Wu Gao3545e642017-07-14 19:24:41 +08004970 if (adapter->device_mode == QDF_SAP_MODE) {
4971 /*
4972 * If adapter is SAP, set session ID to invalid
4973 * since SAP session will be cleanup during SSR.
4974 */
Wu Gao36717432016-11-21 15:09:48 +08004975 wlansap_set_invalid_session(
4976 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4977
Wu Gao3545e642017-07-14 19:24:41 +08004978 wlansap_cleanup_cac_timer(
4979 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4980 }
4981
Yue Mad5b4b9f2017-05-26 16:23:40 -07004982 /* Delete peers if any for STA and P2P client modes */
4983 if (adapter->device_mode == QDF_STA_MODE ||
4984 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004985 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004986 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004987 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004988
4989 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4990 peerMacAddr.bytes);
4991 }
4992
Yue Maf9782842017-05-08 12:49:49 -07004993 /* Destroy vdev which will be recreated during reinit. */
4994 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995 }
4996
4997 EXIT();
4998
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304999 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005000}
5001
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005002bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305003{
Dustin Brown920397d2017-12-13 16:27:50 -08005004 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305005 bool close_modules = true;
5006
Arun Khandavalliba479c42017-07-26 21:29:40 +05305007 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5008 hdd_info("FTM mode, don't close the module");
5009 return false;
5010 }
5011
Dustin Brown920397d2017-12-13 16:27:50 -08005012 hdd_for_each_adapter(hdd_ctx, adapter) {
5013 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5014 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005015 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305016 close_modules = false;
5017 break;
5018 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305019 }
5020
5021 return close_modules;
5022}
5023
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305024bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305025{
5026 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5027 return true;
5028 else
5029 return false;
5030}
5031
Anurag Chouhanc4092922016-09-08 15:56:11 +05305032#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005033 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305034struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5035 struct ieee80211_channel *channel,
5036 const u8 *bssid, const u8 *ssid,
5037 size_t ssid_len)
5038{
5039 return cfg80211_get_bss(wiphy, channel, bssid,
5040 ssid, ssid_len,
5041 WLAN_CAPABILITY_ESS,
5042 WLAN_CAPABILITY_ESS);
5043}
5044#else
5045struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5046 struct ieee80211_channel *channel,
5047 const u8 *bssid, const u8 *ssid,
5048 size_t ssid_len)
5049{
5050 return cfg80211_get_bss(wiphy, channel, bssid,
5051 ssid, ssid_len,
5052 IEEE80211_BSS_TYPE_ESS,
5053 IEEE80211_PRIVACY_ANY);
5054}
5055#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305056
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305057#if defined CFG80211_CONNECT_BSS || \
5058 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305059#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305060 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305061/**
5062 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5063 * @timeout_reason: reason for connect timeout
5064 *
5065 * This function is used to convert host timeout
5066 * reason enum to kernel specific enum.
5067 *
5068 * Return: nl timeout enum
5069 */
5070static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5071 tSirResultCodes timeout_reason)
5072{
5073 switch (timeout_reason) {
5074 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5075 return NL80211_TIMEOUT_SCAN;
5076 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5077 return NL80211_TIMEOUT_AUTH;
5078 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5079 return NL80211_TIMEOUT_ASSOC;
5080 default:
5081 return NL80211_TIMEOUT_UNSPECIFIED;
5082 }
5083}
5084
5085/**
5086 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5087 * @dev: network device
5088 * @bssid: bssid to which we want to associate
5089 * @timeout_reason: reason for connect timeout
5090 *
5091 * This API is used to send connection timeout reason to supplicant
5092 *
5093 * Return: void
5094 */
5095static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5096 const u8 *bssid,
5097 tSirResultCodes timeout_reason)
5098{
5099 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005100
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305101 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5102
5103 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5104 nl_timeout_reason);
5105}
5106
5107/**
5108 * __hdd_connect_bss() - API to send connection status to supplicant
5109 * @dev: network device
5110 * @bssid: bssid to which we want to associate
5111 * @req_ie: Request Information Element
5112 * @req_ie_len: len of the req IE
5113 * @resp_ie: Response IE
5114 * @resp_ie_len: len of ht response IE
5115 * @status: status
5116 * @gfp: Kernel Flag
5117 * @timeout_reason: reason for connect timeout
5118 *
5119 * Return: void
5120 */
5121static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5122 struct cfg80211_bss *bss, const u8 *req_ie,
5123 size_t req_ie_len, const u8 *resp_ie,
5124 size_t resp_ie_len, int status, gfp_t gfp,
5125 tSirResultCodes timeout_reason)
5126{
5127 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005128
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305129 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5130
5131 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5132 resp_ie, resp_ie_len, status, gfp,
5133 nl_timeout_reason);
5134}
5135#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305136#if defined CFG80211_CONNECT_TIMEOUT || \
5137 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305138static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5139 const u8 *bssid,
5140 tSirResultCodes timeout_reason)
5141{
5142 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5143}
5144#endif
5145
5146static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5147 struct cfg80211_bss *bss, const u8 *req_ie,
5148 size_t req_ie_len, const u8 *resp_ie,
5149 size_t resp_ie_len, int status, gfp_t gfp,
5150 tSirResultCodes timeout_reason)
5151{
5152 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5153 resp_ie, resp_ie_len, status, gfp);
5154}
5155#endif
5156
Abhishek Singha84d3952016-09-13 13:45:05 +05305157/**
5158 * hdd_connect_bss() - API to send connection status to supplicant
5159 * @dev: network device
5160 * @bssid: bssid to which we want to associate
5161 * @req_ie: Request Information Element
5162 * @req_ie_len: len of the req IE
5163 * @resp_ie: Response IE
5164 * @resp_ie_len: len of ht response IE
5165 * @status: status
5166 * @gfp: Kernel Flag
5167 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305168 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305169 *
5170 * The API is a wrapper to send connection status to supplicant
5171 *
5172 * Return: Void
5173 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305174#if defined CFG80211_CONNECT_TIMEOUT || \
5175 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305176static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5177 struct cfg80211_bss *bss, const u8 *req_ie,
5178 size_t req_ie_len, const u8 *resp_ie,
5179 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305180 bool connect_timeout,
5181 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305182{
5183 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305184 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305185 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305186 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5187 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305188}
5189#else
5190static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5191 struct cfg80211_bss *bss, const u8 *req_ie,
5192 size_t req_ie_len, const u8 *resp_ie,
5193 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305194 bool connect_timeout,
5195 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305196{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305197 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5198 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305199}
5200#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305201
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305202#if defined(WLAN_FEATURE_FILS_SK)
5203#if defined(CFG80211_CONNECT_DONE) || \
5204 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5205#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5206 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305207/**
5208 * hdd_populate_fils_params() - Populate FILS keys to connect response
5209 * @fils_params: connect response to supplicant
5210 * @fils_kek: FILS kek
5211 * @fils_kek_len: FILS kek length
5212 * @pmk: FILS PMK
5213 * @pmk_len: FILS PMK length
5214 * @pmkid: PMKID
5215 * @fils_seq_num: FILS Seq number
5216 *
5217 * Return: None
5218 */
5219static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5220 *fils_params, const uint8_t *fils_kek,
5221 size_t fils_kek_len, const uint8_t *pmk,
5222 size_t pmk_len, const uint8_t *pmkid,
5223 uint16_t fils_seq_num)
5224{
5225 /* Increament seq number to be used for next FILS */
5226 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5227 fils_params->update_erp_next_seq_num = true;
5228 fils_params->fils_kek = fils_kek;
5229 fils_params->fils_kek_len = fils_kek_len;
5230 fils_params->pmk = pmk;
5231 fils_params->pmk_len = pmk_len;
5232 fils_params->pmkid = pmkid;
5233}
5234#else
5235static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5236 *fils_params, const uint8_t
5237 *fils_kek, size_t fils_kek_len,
5238 const uint8_t *pmk, size_t pmk_len,
5239 const uint8_t *pmkid,
5240 uint16_t fils_seq_num)
5241{ }
5242#endif
5243
Jeff Johnson172237b2017-11-07 15:32:59 -08005244void hdd_update_hlp_info(struct net_device *dev,
5245 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305246{
5247 struct sk_buff *skb;
5248 uint16_t skb_len;
5249 struct llc_snap_hdr_t *llc_hdr;
5250 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305251 uint8_t *hlp_data;
5252 uint16_t hlp_data_len;
5253 struct fils_join_rsp_params *roam_fils_params
5254 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305255 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5256
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305257 if (!roam_fils_params) {
5258 hdd_err("FILS Roam Param NULL");
5259 return;
5260 }
5261
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005262 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305263 hdd_err("FILS HLP Data NULL, len %d",
5264 roam_fils_params->hlp_data_len);
5265 return;
5266 }
5267
5268 hlp_data = roam_fils_params->hlp_data;
5269 hlp_data_len = roam_fils_params->hlp_data_len;
5270
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305271 /* Calculate skb length */
5272 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5273 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5274 if (skb == NULL) {
5275 hdd_err("HLP packet nbuf alloc fails");
5276 return;
5277 }
5278
5279 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5280 QDF_MAC_ADDR_SIZE);
5281 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5282 QDF_MAC_ADDR_SIZE);
5283
5284 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5285 if (IS_SNAP(llc_hdr)) {
5286 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5287 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5288 }
5289
5290 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5291
5292 /*
5293 * This HLP packet is formed from HLP info encapsulated
5294 * in assoc response frame which is AEAD encrypted.
5295 * Hence, this checksum validation can be set unnecessary.
5296 * i.e. network layer need not worry about checksum.
5297 */
5298 skb->ip_summed = CHECKSUM_UNNECESSARY;
5299
5300 status = hdd_rx_packet_cbk(padapter, skb);
5301 if (QDF_IS_STATUS_ERROR(status)) {
5302 hdd_err("Sending HLP packet fails");
5303 return;
5304 }
5305 hdd_debug("send HLP packet to netif successfully");
5306}
5307
5308/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305309 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5310 * @dev: network device
5311 * @bssid: bssid to which we want to associate
5312 * @bss: cfg80211 bss info
5313 * @roam_info: information about connected bss
5314 * @req_ie: Request Information Element
5315 * @req_ie_len: len of the req IE
5316 * @resp_ie: Response IE
5317 * @resp_ie_len: len of ht response IE
5318 * @status: status
5319 * @gfp: allocation flags
5320 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5321 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305322 *
5323 * This API is used as wrapper to send FILS key/sequence number
5324 * params etc. to supplicant in case of FILS connection
5325 *
5326 * Return: None
5327 */
5328static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005329 struct cfg80211_bss *bss,
5330 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305331 const u8 *req_ie, size_t req_ie_len,
5332 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005333 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305334 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305335{
5336 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305337 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5338 struct fils_join_rsp_params *roam_fils_params =
5339 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005340
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305341 qdf_mem_zero(&fils_params, sizeof(fils_params));
5342
5343 if (!roam_fils_params) {
5344 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5345 } else {
5346 fils_params.status = status;
5347 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005348 fils_params.timeout_reason =
5349 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305350 fils_params.req_ie = req_ie;
5351 fils_params.req_ie_len = req_ie_len;
5352 fils_params.resp_ie = resp_ie;
5353 fils_params.resp_ie_len = resp_ie_len;
5354 fils_params.bss = bss;
5355 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5356 roam_fils_params->kek_len,
5357 roam_fils_params->fils_pmk,
5358 roam_fils_params->fils_pmk_len,
5359 roam_fils_params->fils_pmkid,
5360 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305361 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305362 }
5363 hdd_debug("FILS indicate connect status %d seq no %d",
5364 fils_params.status,
5365 fils_params.fils_erp_next_seq_num);
5366
5367 cfg80211_connect_done(dev, &fils_params, gfp);
5368
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305369 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305370 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305371
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305372 /* Clear all the FILS key info */
5373 if (roam_fils_params && roam_fils_params->fils_pmk)
5374 qdf_mem_free(roam_fils_params->fils_pmk);
5375 if (roam_fils_params)
5376 qdf_mem_free(roam_fils_params);
5377 roam_info->fils_join_rsp = NULL;
5378}
5379#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005380static inline void
5381hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005382 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005383 const u8 *req_ie, size_t req_ie_len,
5384 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5385 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305386 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305387{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305388#endif
5389#endif
5390
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305391#if defined(WLAN_FEATURE_FILS_SK) && \
5392 (defined(CFG80211_CONNECT_DONE) || \
5393 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305394/**
5395 * hdd_fils_update_connect_results() - API to send fils connection status to
5396 * supplicant.
5397 * @dev: network device
5398 * @bssid: bssid to which we want to associate
5399 * @bss: cfg80211 bss info
5400 * @roam_info: information about connected bss
5401 * @req_ie: Request Information Element
5402 * @req_ie_len: len of the req IE
5403 * @resp_ie: Response IE
5404 * @resp_ie_len: len of ht response IE
5405 * @status: status
5406 * @gfp: allocation flags
5407 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5408 * @timeout_reason: reason for connect timeout
5409 *
5410 * The API is a wrapper to send connection status to supplicant
5411 *
5412 * Return: 0 if success else failure
5413 */
5414static int hdd_fils_update_connect_results(struct net_device *dev,
5415 const u8 *bssid,
5416 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005417 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305418 size_t req_ie_len, const u8 *resp_ie,
5419 size_t resp_ie_len, u16 status, gfp_t gfp,
5420 bool connect_timeout,
5421 tSirResultCodes timeout_reason)
5422{
5423 ENTER();
5424 if (!roam_info || !roam_info->is_fils_connection)
5425 return -EINVAL;
5426
5427 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5428 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305429 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305430 return 0;
5431}
5432#else
5433static inline int hdd_fils_update_connect_results(struct net_device *dev,
5434 const u8 *bssid,
5435 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005436 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305437 size_t req_ie_len, const u8 *resp_ie,
5438 size_t resp_ie_len, u16 status, gfp_t gfp,
5439 bool connect_timeout,
5440 tSirResultCodes timeout_reason)
5441{
5442 return -EINVAL;
5443}
5444#endif
5445
Anurag Chouhanc4092922016-09-08 15:56:11 +05305446/**
5447 * hdd_connect_result() - API to send connection status to supplicant
5448 * @dev: network device
5449 * @bssid: bssid to which we want to associate
5450 * @roam_info: information about connected bss
5451 * @req_ie: Request Information Element
5452 * @req_ie_len: len of the req IE
5453 * @resp_ie: Response IE
5454 * @resp_ie_len: len of ht response IE
5455 * @status: status
5456 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305457 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305458 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305459 *
5460 * The API is a wrapper to send connection status to supplicant
5461 * and allow runtime suspend
5462 *
5463 * Return: Void
5464 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305465void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005466 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305467 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305468 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305469 bool connect_timeout,
5470 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305471{
Jeff Johnson9d295242017-08-29 14:39:48 -07005472 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305473 struct cfg80211_bss *bss = NULL;
5474
5475 if (WLAN_STATUS_SUCCESS == status) {
5476 struct ieee80211_channel *chan;
5477 int freq;
5478 int chan_no = roam_info->pBssDesc->channelId;
5479
5480 if (chan_no <= 14)
5481 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005482 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305483 else
5484 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005485 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305486
5487 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5488 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5489 roam_info->u.pConnectedProfile->SSID.ssId,
5490 roam_info->u.pConnectedProfile->SSID.length);
5491 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305492
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305493 if (hdd_fils_update_connect_results(dev, bssid, bss,
5494 roam_info, req_ie, req_ie_len, resp_ie,
5495 resp_ie_len, status, gfp, connect_timeout,
5496 timeout_reason) != 0) {
5497 hdd_connect_bss(dev, bssid, bss, req_ie,
5498 req_ie_len, resp_ie, resp_ie_len,
5499 status, gfp, connect_timeout, timeout_reason);
5500 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305501
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005502 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005503 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305504}
5505#else
5506void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005507 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305508 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305509 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305510 bool connect_timeout,
5511 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305512{
Jeff Johnson9d295242017-08-29 14:39:48 -07005513 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305514
Anurag Chouhanc4092922016-09-08 15:56:11 +05305515 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5516 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005517
5518 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005519 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305520}
5521#endif
5522
5523
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005524QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005525{
Jeff Johnson9d295242017-08-29 14:39:48 -07005526 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005527#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305528 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005529#endif
5530 eConnectionState connState;
5531
5532 ENTER();
5533
Dustin Brown920397d2017-12-13 16:27:50 -08005534 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305535 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005536 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005538 hdd_wmm_init(adapter);
5539
5540 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005541 case QDF_STA_MODE:
5542 case QDF_P2P_CLIENT_MODE:
5543 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005544
5545 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5546 ->conn_info.connState;
5547
Krunal Sonib51eec72017-11-20 21:53:01 -08005548 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005549 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005550 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005551
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005552 /* Indicate disconnect event to supplicant
5553 * if associated previously
5554 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005555 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005556 eConnectionState_IbssConnected == connState ||
5557 eConnectionState_NotConnected == connState ||
5558 eConnectionState_IbssDisconnected == connState ||
5559 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005560 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005561
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562 memset(&wrqu, '\0', sizeof(wrqu));
5563 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5564 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5565 wireless_send_event(adapter->dev, SIOCGIWAP,
5566 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005567 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005568 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005569
5570 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305571 wlan_hdd_cfg80211_indicate_disconnect(
5572 adapter->dev, false,
5573 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005574 } else if (eConnectionState_Connecting == connState) {
5575 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005576 * Indicate connect failure to supplicant if we
5577 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005578 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305579 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305580 NULL, 0, NULL, 0,
5581 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005582 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005583 }
5584
5585 hdd_register_tx_flow_control(adapter,
5586 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005587 hdd_tx_resume_cb,
5588 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005589
5590 break;
5591
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005592 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005593 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005594 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305595
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005596 break;
5597
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005598 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005599#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005600 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005601 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5602#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005603 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005604 /* event supplicant to restart */
5605 cfg80211_del_sta(adapter->dev,
5606 (const u8 *)&bcastMac.bytes[0],
5607 GFP_KERNEL);
5608#endif
5609 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305610 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005611 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305612 hdd_set_mon_rx_cb(adapter->dev);
5613 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5614 adapter->mon_bandwidth);
5615 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005616 default:
5617 break;
5618 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005619 /*
5620 * Action frame registered in one adapter which will
5621 * applicable to all interfaces
5622 */
5623 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005624 }
5625
5626 EXIT();
5627
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305628 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005629}
5630
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005631QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005632 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005633{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305634 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005635 qdf_list_node_t *node;
5636
5637 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005638
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005639 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005640 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005641 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005642
5643 if (QDF_IS_STATUS_ERROR(status))
5644 return status;
5645
5646 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5647
5648 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005649}
5650
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005651QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005652 struct hdd_adapter *current_adapter,
5653 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005654{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305655 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005656 qdf_list_node_t *node;
5657
5658 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005659
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005660 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005661 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005662 &current_adapter->node,
5663 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005664 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005665
5666 if (QDF_IS_STATUS_ERROR(status))
5667 return status;
5668
5669 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5670
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671 return status;
5672}
5673
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005674QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005675 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005676{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305677 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005678
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005679 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005680 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005681 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005682
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005683 return status;
5684}
5685
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005686QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005687 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005688{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305689 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005690 qdf_list_node_t *node;
5691
5692 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005693
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005694 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005695 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005696 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005697
5698 if (QDF_IS_STATUS_ERROR(status))
5699 return status;
5700
5701 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5702
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703 return status;
5704}
5705
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005706QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005707 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005708{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305709 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005710
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005711 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005712 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005713 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005714
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715 return status;
5716}
5717
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005718QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005719 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305721 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005722
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005723 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005724 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005725 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005726
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005727 return status;
5728}
5729
Jeff Johnson9d295242017-08-29 14:39:48 -07005730struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005731 tSirMacAddr macAddr)
5732{
Jeff Johnson9d295242017-08-29 14:39:48 -07005733 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005734
Dustin Brown920397d2017-12-13 16:27:50 -08005735 hdd_for_each_adapter(hdd_ctx, adapter) {
5736 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5737 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005738 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005739 }
5740
5741 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005742}
5743
Jeff Johnson9d295242017-08-29 14:39:48 -07005744struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005745 uint32_t vdev_id)
5746{
Jeff Johnson9d295242017-08-29 14:39:48 -07005747 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005748
Dustin Brown920397d2017-12-13 16:27:50 -08005749 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005750 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005751 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005752 }
5753
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -08005754 hdd_err_ratelimited(RATE_LIMIT_ERROR_LOG,
5755 "vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005756
5757 return NULL;
5758}
5759
Abhishek Singh7996eb72015-12-30 17:24:02 +05305760/**
5761 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5762 * the sessionid
5763 * @hdd_ctx: hdd context.
5764 * @sme_session_id: sme session is for the adapter to get.
5765 *
5766 * This function is used to get the adapter with provided session id
5767 *
5768 * Return: adapter pointer if found
5769 *
5770 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005771struct hdd_adapter *
5772hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5773 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305774{
Jeff Johnson9d295242017-08-29 14:39:48 -07005775 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305776
Dustin Brown920397d2017-12-13 16:27:50 -08005777 hdd_for_each_adapter(hdd_ctx, adapter) {
5778 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305779 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305780 }
Dustin Brown920397d2017-12-13 16:27:50 -08005781
Abhishek Singh7996eb72015-12-30 17:24:02 +05305782 return NULL;
5783}
5784
Jeff Johnson9d295242017-08-29 14:39:48 -07005785struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005786 const char *iface_name)
5787{
Jeff Johnson9d295242017-08-29 14:39:48 -07005788 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005789
Dustin Brown920397d2017-12-13 16:27:50 -08005790 hdd_for_each_adapter(hdd_ctx, adapter) {
5791 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07005792 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005793 }
Dustin Brown920397d2017-12-13 16:27:50 -08005794
Naveen Rawat4edb6822017-04-12 10:09:17 -07005795 return NULL;
5796}
5797
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005798/**
5799 * hdd_get_adapter() - to get adapter matching the mode
5800 * @hdd_ctx: hdd context
5801 * @mode: adapter mode
5802 *
5803 * This routine will return the pointer to adapter matching
5804 * with the passed mode.
5805 *
5806 * Return: pointer to adapter or null
5807 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005808struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005809 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005810{
Jeff Johnson9d295242017-08-29 14:39:48 -07005811 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005812
Dustin Brown920397d2017-12-13 16:27:50 -08005813 hdd_for_each_adapter(hdd_ctx, adapter) {
5814 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005815 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005816 }
5817
5818 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005819}
5820
5821/**
5822 * hdd_get_operating_channel() - return operating channel of the device mode
5823 * @hdd_ctx: Pointer to the HDD context.
5824 * @mode: Device mode for which operating channel is required.
5825 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005826 * QDF_STA_MODE,
5827 * QDF_P2P_CLIENT_MODE,
5828 * QDF_SAP_MODE,
5829 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005830 *
5831 * This API returns the operating channel of the requested device mode
5832 *
5833 * Return: channel number. "0" id the requested device is not found OR it is
5834 * not connected.
5835 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005836uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005837 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005838{
Jeff Johnson9d295242017-08-29 14:39:48 -07005839 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005840 uint8_t operatingChannel = 0;
5841
Dustin Brown920397d2017-12-13 16:27:50 -08005842 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005843 if (mode == adapter->device_mode) {
5844 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005845 case QDF_STA_MODE:
5846 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005847 if (hdd_conn_is_connected
5848 (WLAN_HDD_GET_STATION_CTX_PTR
5849 (adapter))) {
5850 operatingChannel =
5851 (WLAN_HDD_GET_STATION_CTX_PTR
5852 (adapter))->conn_info.
5853 operationChannel;
5854 }
5855 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005856 case QDF_SAP_MODE:
5857 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005858 /* softap connection info */
5859 if (test_bit
5860 (SOFTAP_BSS_STARTED,
5861 &adapter->event_flags))
5862 operatingChannel =
5863 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005864 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005865 break;
5866 default:
5867 break;
5868 }
5869
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005870 /* Found the device of interest. break the loop */
5871 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005872 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005873 }
Dustin Brown920397d2017-12-13 16:27:50 -08005874
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005875 return operatingChannel;
5876}
5877
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005878static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005879 hdd_ctx)
5880{
Jeff Johnson9d295242017-08-29 14:39:48 -07005881 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005882
5883 ENTER();
5884
Dustin Brown920397d2017-12-13 16:27:50 -08005885 hdd_for_each_adapter(hdd_ctx, adapter) {
5886 if (adapter->device_mode == QDF_STA_MODE ||
5887 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5888 adapter->device_mode == QDF_IBSS_MODE ||
5889 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5890 adapter->device_mode == QDF_SAP_MODE ||
5891 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005892 wlan_hdd_cfg80211_deregister_frames(adapter);
5893 hdd_unregister_wext(adapter->dev);
5894 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005895 }
5896
5897 EXIT();
5898
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305899 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005900}
5901
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005902QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005903{
Jeff Johnson9d295242017-08-29 14:39:48 -07005904 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005905
5906 ENTER();
5907
Dustin Brown920397d2017-12-13 16:27:50 -08005908 hdd_for_each_adapter(hdd_ctx, adapter) {
5909 if (adapter->device_mode == QDF_STA_MODE ||
5910 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5911 adapter->device_mode == QDF_IBSS_MODE ||
5912 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5913 adapter->device_mode == QDF_SAP_MODE ||
5914 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005915 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005916 adapter->session_id, INVALID_SCAN_ID,
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005917 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005918 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005919 }
5920
5921 EXIT();
5922
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305923 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005924}
5925
Dustin Brownf27bce82016-11-03 12:52:27 -07005926/**
5927 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5928 * adapters
5929 * @hdd_ctx: The HDD context containing the adapters to operate on
5930 *
5931 * return: QDF_STATUS_SUCCESS
5932 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005933static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005934{
Jeff Johnson9d295242017-08-29 14:39:48 -07005935 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005936 int err;
5937
5938 ENTER();
5939
Dustin Brown920397d2017-12-13 16:27:50 -08005940 hdd_for_each_adapter(hdd_ctx, adapter) {
5941 if (adapter->device_mode == QDF_STA_MODE ||
5942 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5943 adapter->device_mode == QDF_IBSS_MODE ||
5944 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5945 adapter->device_mode == QDF_SAP_MODE ||
5946 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07005947 err = wlan_hdd_sched_scan_stop(adapter->dev);
5948 if (err)
5949 hdd_err("Unable to stop scheduled scan");
5950 }
Dustin Brownf27bce82016-11-03 12:52:27 -07005951 }
5952
5953 EXIT();
5954
5955 return QDF_STATUS_SUCCESS;
5956}
5957
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005958#ifdef WLAN_NS_OFFLOAD
5959/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005960 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005961 * @hdd_ctx: Pointer to hdd context
5962 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005963 * Unregister for IPv6 address change notifications.
5964 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005965 * Return: None
5966 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005967static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005968{
5969 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005970}
5971
5972/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005973 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005974 * @hdd_ctx: Pointer to hdd context
5975 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005976 * Register for IPv6 address change notifications.
5977 *
5978 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005980static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005981{
5982 int ret;
5983
5984 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5985 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005986 if (ret) {
5987 hdd_err("Failed to register IPv6 notifier: %d", ret);
5988 goto out;
5989 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005990
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005991 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005992out:
5993 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005994}
5995#else
5996/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005997 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005998 * @hdd_ctx: Pointer to hdd context
5999 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006000 * Unregister for IPv6 address change notifications.
6001 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006002 * Return: None
6003 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006004static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006005{
6006}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006008/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006009 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006010 * @hdd_ctx: Pointer to hdd context
6011 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006012 * Register for IPv6 address change notifications.
6013 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006014 * Return: None
6015 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006016static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006017{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006018 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006019}
6020#endif
6021
6022/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006023 * hdd_register_notifiers - Register netdev notifiers.
6024 * @hdd_ctx: HDD context
6025 *
6026 * Register netdev notifiers like IPv4 and IPv6.
6027 *
6028 * Return: 0 on success and errno on failure
6029 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006030static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006031{
6032 int ret;
6033
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006034 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6035 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306036 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006037
6038 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6039 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6040 if (ret) {
6041 hdd_err("Failed to register IPv4 notifier: %d", ret);
6042 goto unregister_ip6_notifier;
6043 }
6044
6045 return 0;
6046
6047unregister_ip6_notifier:
6048 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006049out:
6050 return ret;
6051
6052}
6053
6054/**
6055 * hdd_unregister_notifiers - Unregister netdev notifiers.
6056 * @hdd_ctx: HDD context
6057 *
6058 * Unregister netdev notifiers like IPv4 and IPv6.
6059 *
6060 * Return: None.
6061 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006062void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006063{
6064 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6065
6066 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006067}
6068
6069/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006070 * hdd_exit_netlink_services - Exit netlink services
6071 * @hdd_ctx: HDD context
6072 *
6073 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6074 * nl service.
6075 *
6076 * Return: None.
6077 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006078static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006079{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006080 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006081 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006082 ptt_sock_deactivate_svc();
6083
6084 nl_srv_exit();
6085}
6086
6087/**
6088 * hdd_init_netlink_services- Init netlink services
6089 * @hdd_ctx: HDD context
6090 *
6091 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6092 * nl service.
6093 *
6094 * Return: 0 on success and errno on failure.
6095 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006096static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006097{
6098 int ret;
6099
Ryan Hsuceddceb2016-04-28 10:20:14 -07006100 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006101 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006102 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006103 goto out;
6104 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006105 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006106
Naveen Rawat910726a2017-03-06 11:42:51 -08006107 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006108 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006109 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006110 goto err_nl_srv;
6111 }
6112
6113 ret = ptt_sock_activate_svc();
6114 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006115 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006116 goto err_nl_srv;
6117 }
6118
6119 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006120 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006121 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006122
6123 ret = cnss_diag_activate_service();
6124 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006125 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006126 goto err_close_cesium;
6127 }
6128
6129 return 0;
6130
6131err_close_cesium:
6132 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006133 ptt_sock_deactivate_svc();
6134err_nl_srv:
6135 nl_srv_exit();
6136out:
6137 return ret;
6138}
6139
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006140/**
6141 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6142 * @hdd_ctx: HDD context.
6143 *
6144 * Destroy RX wakelock.
6145 *
6146 * Return: None.
6147 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006148static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006149{
6150 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6151}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006152
6153/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006154 * hdd_rx_wake_lock_create() - Create RX wakelock
6155 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006156 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006157 * Create RX wakelock.
6158 *
6159 * Return: None.
6160 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006161static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006162{
6163 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6164}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006165
6166/**
Houston Hoffman160db392016-10-10 17:37:51 -07006167 * hdd_context_deinit() - Deinitialize HDD context
6168 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006169 *
Houston Hoffman160db392016-10-10 17:37:51 -07006170 * Deinitialize HDD context along with all the feature specific contexts but
6171 * do not free hdd context itself. Caller of this API is supposed to free
6172 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006173 *
Houston Hoffman160db392016-10-10 17:37:51 -07006174 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006175 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006176static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006177{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306178 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6179
Houston Hoffman160db392016-10-10 17:37:51 -07006180 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006181
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006182 hdd_sap_context_destroy(hdd_ctx);
6183
6184 hdd_rx_wake_lock_destroy(hdd_ctx);
6185
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006186 hdd_scan_context_destroy(hdd_ctx);
6187
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006188 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006189
Houston Hoffman160db392016-10-10 17:37:51 -07006190 return 0;
6191}
6192
6193/**
6194 * hdd_context_destroy() - Destroy HDD context
6195 * @hdd_ctx: HDD context to be destroyed.
6196 *
6197 * Free config and HDD context as well as destroy all the resources.
6198 *
6199 * Return: None
6200 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006201static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006202{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006203 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306204
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306205 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6206
Houston Hoffman160db392016-10-10 17:37:51 -07006207 hdd_context_deinit(hdd_ctx);
6208
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306209 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006210 hdd_ctx->config = NULL;
6211
6212 wiphy_free(hdd_ctx->wiphy);
6213}
6214
6215/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306216 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6217 *
6218 * This function is used to destroy bug report lock
6219 *
6220 * Return: None
6221 */
6222static void wlan_destroy_bug_report_lock(void)
6223{
6224 p_cds_contextType p_cds_context;
6225
6226 p_cds_context = cds_get_global_context();
6227 if (!p_cds_context) {
6228 hdd_err("cds context is NULL");
6229 return;
6230 }
6231
6232 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6233}
6234
6235/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236 * hdd_wlan_exit() - HDD WLAN exit function
6237 * @hdd_ctx: Pointer to the HDD Context
6238 *
6239 * This is the driver exit point (invoked during rmmod)
6240 *
6241 * Return: None
6242 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006243static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006244{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306246 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247
6248 ENTER();
6249
Dustin Brown6f427922017-09-19 12:19:00 -07006250 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306251
6252 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006253
Prashanth Bhattaab004382016-10-11 16:08:11 -07006254 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006255
6256#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306257 if (QDF_TIMER_STATE_RUNNING ==
6258 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6259 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260 }
6261
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306262 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306263 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006264 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006266 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6267 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6268 hdd_ctx->last_acs_channel_list = NULL;
6269 hdd_ctx->num_of_channels = 0;
6270 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006271#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006272
Arun Khandavallifae92942016-08-01 13:31:08 +05306273 mutex_lock(&hdd_ctx->iface_change_lock);
6274 driver_status = hdd_ctx->driver_status;
6275 mutex_unlock(&hdd_ctx->iface_change_lock);
6276
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277 /*
6278 * Powersave Offload Case
6279 * Disable Idle Power Save Mode
6280 */
6281 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006282 /* clear the scan queue in all the scenarios */
6283 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006284
Arun Khandavallifae92942016-08-01 13:31:08 +05306285 if (driver_status != DRIVER_MODULES_CLOSED) {
6286 hdd_unregister_wext_all_adapters(hdd_ctx);
6287 /*
6288 * Cancel any outstanding scan requests. We are about to close
6289 * all of our adapters, but an adapter structure is what SME
6290 * passes back to our callback function. Hence if there
6291 * are any outstanding scan requests then there is a
6292 * race condition between when the adapter is closed and
6293 * when the callback is invoked. We try to resolve that
6294 * race condition here by canceling any outstanding scans
6295 * before we close the adapters.
6296 * Note that the scans may be cancelled in an asynchronous
6297 * manner, so ideally there needs to be some kind of
6298 * synchronization. Rather than introduce a new
6299 * synchronization here, we will utilize the fact that we are
6300 * about to Request Full Power, and since that is synchronized,
6301 * the expectation is that by the time Request Full Power has
6302 * completed, all scans will be cancelled
6303 */
6304 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006305 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006306 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006307 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006308 }
6309
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306310 unregister_netdevice_notifier(&hdd_netdev_notifier);
6311
Dustin Brown36e24e22017-12-21 12:34:13 -08006312 hdd_close_all_adapters(hdd_ctx, false);
6313
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006314 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306315
Dustin Brown021cecd2017-12-11 13:56:43 -08006316 hdd_driver_memdump_deinit();
6317
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306318 qdf_nbuf_deinit_replenish_timer();
6319
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306320 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6321 hdd_info("Release wakelock for monitor mode!");
6322 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6323 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6324 }
6325
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306326 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6327 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6328 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6329
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006330 /*
6331 * Close CDS
6332 * This frees pMac(HAL) context. There should not be any call
6333 * that requires pMac access after this.
6334 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006335
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006336 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006337
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006338 hdd_ipa_cleanup(hdd_ctx);
6339
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306340 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306341 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306342 /*
6343 * If there is re_init failure wiphy would have already de-registered
6344 * check the wiphy status before un-registering again
6345 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306346 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306347 wiphy_unregister(wiphy);
6348 wlan_hdd_cfg80211_deinit(wiphy);
6349 hdd_lpass_notify_stop(hdd_ctx);
6350 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006351
Arun Khandavallifae92942016-08-01 13:31:08 +05306352 hdd_exit_netlink_services(hdd_ctx);
6353 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306354#ifdef FEATURE_WLAN_CH_AVOID
6355 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6356#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306357
Abhishek Singhe9068f12017-03-31 14:14:52 +05306358 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6359 if (driver_status)
6360 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006361
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006362 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006363}
6364
6365void __hdd_wlan_exit(void)
6366{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006367 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368
6369 ENTER();
6370
Anurag Chouhan6d760662016-02-20 16:05:43 +05306371 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006373 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006374 EXIT();
6375 return;
6376 }
6377
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378 /* Do all the cleanup before deregistering the driver */
6379 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006380
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006381 EXIT();
6382}
6383
6384#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006385/**
6386 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006387 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006388 *
6389 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6390 * Then new ACS request will do a fresh scan without reusing the cached
6391 * scan information.
6392 *
6393 * Return: void
6394 */
Tang Yingying523322d2017-01-17 23:28:43 +08006395static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006396{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006397 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006398
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006399 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006400 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006401 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6402 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6403 hdd_ctx->last_acs_channel_list = NULL;
6404 hdd_ctx->num_of_channels = 0;
6405 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006406
6407 if (!hdd_ctx->hHal)
6408 return;
6409 sme_scan_flush_result(hdd_ctx->hHal);
6410}
6411#endif
6412
6413#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006414int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6415 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006416{
6417 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306418 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006419 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006420
6421 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6422
6423 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306424 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006425 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006427 if (!hdd_ctx->hHal)
6428 return -EINVAL;
6429
Jeff Johnsone7672e72017-10-21 15:10:04 -07006430 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006431 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306432 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006433 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006434 return -EINVAL;
6435 }
6436
6437 return 0;
6438}
6439#endif
6440
6441/**
6442 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6443 * @state: state
6444 *
6445 * This function notifies FW with modem power status
6446 *
6447 * Return: 0 if successful, error number otherwise
6448 */
6449int hdd_wlan_notify_modem_power_state(int state)
6450{
6451 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306452 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006453 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006454
Anurag Chouhan6d760662016-02-20 16:05:43 +05306455 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006456 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306457 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006458 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306459
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006460 if (!hdd_ctx->hHal)
6461 return -EINVAL;
6462
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306463 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6464 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006465 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006466 state);
6467 return -EINVAL;
6468 }
6469 return 0;
6470}
6471
6472/**
6473 *
6474 * hdd_post_cds_enable_config() - HDD post cds start config helper
6475 * @adapter - Pointer to the HDD
6476 *
6477 * Return: None
6478 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006479QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306481 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006482
6483 /*
6484 * Send ready indication to the HDD. This will kick off the MAC
6485 * into a 'running' state and should kick off an initial scan.
6486 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306487 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6488 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006489 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6490 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306491 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006492 }
6493
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306494 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006495}
6496
6497/* wake lock APIs for HDD */
6498void hdd_prevent_suspend(uint32_t reason)
6499{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306500 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006501}
6502
6503void hdd_allow_suspend(uint32_t reason)
6504{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306505 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506}
6507
6508void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6509{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306510 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6511 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006512}
6513
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006515QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006516{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006517
Amar Singhal6f8592b2017-04-26 14:31:58 -07006518 return sme_init_chan_list(hdd_ctx->hHal,
6519 hdd_ctx->reg.alpha2,
6520 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006521}
6522
6523/**
6524 * hdd_is_5g_supported() - check if hardware supports 5GHz
6525 * @hdd_ctx: Pointer to the hdd context
6526 *
6527 * HDD function to know if hardware supports 5GHz
6528 *
6529 * Return: true if hardware supports 5GHz
6530 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006531bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006532{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006533 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006534 return true;
6535
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006536 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006537 return true;
6538 else
6539 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540}
6541
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006542static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006543{
6544 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006545 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006546
6547 wiphy = hdd_ctx->wiphy;
6548
6549 /*
6550 * The channel information in
6551 * wiphy needs to be initialized before wiphy registration
6552 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006553 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6554 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006555 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006556 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006557 }
6558
6559#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6560 wiphy->wowlan = &wowlan_support_reg_init;
6561#else
6562 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6563 WIPHY_WOWLAN_MAGIC_PKT |
6564 WIPHY_WOWLAN_DISCONNECT |
6565 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6566 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6567 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6568 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6569 WIPHY_WOWLAN_RFKILL_RELEASE;
6570
6571 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6572 WOW_MAX_FILTERS_PER_LIST);
6573 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6574 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6575#endif
6576
6577 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006578 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306579 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006580 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306581 return ret_val;
6582 }
6583
Amar Singhal5cccafe2017-02-15 12:42:58 -08006584 if (!hdd_ctx->reg_offload)
6585 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006586
Amar Singhale4f28ee2015-10-21 14:36:56 -07006587 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006588}
6589
Mohit Khannaca4173b2017-09-12 21:52:19 -07006590#ifdef MSM_PLATFORM
6591/**
6592 * hdd_display_periodic_stats() - Function to display periodic stats
6593 * @hdd_ctx - handle to hdd context
6594 * @bool data_in_interval - true, if data detected in bw time interval
6595 *
6596 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6597 * Stats show up in wlan driver logs.
6598 *
6599 * Returns: None
6600 */
6601static inline
6602void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6603 bool data_in_interval)
6604{
6605 static u32 counter;
6606 static bool data_in_time_period;
6607 ol_txrx_pdev_handle pdev;
6608
6609 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6610 return;
6611
6612 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6613 if (!pdev) {
6614 hdd_err("pdev is NULL");
6615 return;
6616 }
6617
6618 counter++;
6619 if (data_in_interval)
6620 data_in_time_period = data_in_interval;
6621
6622 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6623 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6624 if (data_in_time_period) {
6625 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6626 CDP_TXRX_PATH_STATS,
6627 QDF_STATS_VERBOSITY_LEVEL_LOW);
6628 wlan_hdd_display_netif_queue_history
6629 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6630 qdf_dp_trace_dump_stats();
6631 }
6632 counter = 0;
6633 data_in_time_period = false;
6634 }
6635}
6636
Ravi Joshie2331e82015-07-01 18:18:54 -07006637/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006638 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006639 * @hdd_ctx - handle to hdd context
6640 * @tx_packets - transmit packet count
6641 * @rx_packets - receive packet count
6642 *
6643 * The function controls the bus bandwidth and dynamic control of
6644 * tcp delayed ack configuration
6645 *
6646 * Returns: None
6647 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006648
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006649static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006650 const uint64_t tx_packets,
6651 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006652{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006653 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006654 uint64_t temp_rx = 0;
6655 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006656 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006657 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006658 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006659 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006660 uint16_t index = 0;
6661 bool vote_level_change = false;
6662 bool rx_level_change = false;
6663 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006664
Mohit Khannaca4173b2017-09-12 21:52:19 -07006665 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006666 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006667 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006668 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006669 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006670 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006671 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006672 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006674 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006675 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6676 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006678 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006679 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306680 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306681 if (hdd_ctx->hbw_requested) {
6682 pld_remove_pm_qos(hdd_ctx->parent_dev);
6683 hdd_ctx->hbw_requested = false;
6684 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306685 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006686 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006687 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306688 if (!hdd_ctx->hbw_requested) {
6689 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6690 hdd_ctx->hbw_requested = true;
6691 }
6692
Nirav Shah3bbfa512016-05-12 16:43:49 +05306693 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006694 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006695 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006696 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006697 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006698
Mohit Khannaf8f96822017-05-17 17:11:59 -07006699 qdf_dp_trace_throttle_live_mode(
6700 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6701
Mohit Khannae71e2262015-11-10 09:37:24 -08006702 /* fine-tuning parameters for RX Flows */
6703 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6704
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006705 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006706
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306707 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6708 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6709 else
6710 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6711
Ravi Joshifed83572016-10-07 16:20:37 -07006712 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6713 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6714 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6715 next_rx_level = WLAN_SVC_TP_HIGH;
6716 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006717 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006718 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006719 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006720 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006721
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006723 struct wlan_rx_tp_data rx_tp_data = {0};
6724
Ravi Joshie2331e82015-07-01 18:18:54 -07006725 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006726 next_rx_level, temp_rx);
6727 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006728 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006729 /* Send throughput indication only if it is enabled.
6730 * Disabling tcp_del_ack will revert the tcp stack behavior
6731 * to default delayed ack. Note that this will disable the
6732 * dynamic delayed ack mechanism across the system
6733 */
6734 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006735 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6736
Mohit Khanna6272fb682017-04-13 09:34:36 -07006737 if (hdd_ctx->config->enable_tcp_adv_win_scale)
6738 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6739
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006740 rx_tp_data.level = next_rx_level;
6741 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6742 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6743 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006744 }
6745
Mohit Khannae71e2262015-11-10 09:37:24 -08006746 /* fine-tuning parameters for TX Flows */
6747 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6748 hdd_ctx->prev_tx = tx_packets;
6749 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6750 next_tx_level = WLAN_SVC_TP_HIGH;
6751 else
6752 next_tx_level = WLAN_SVC_TP_LOW;
6753
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006754 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006755 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6756 next_tx_level, temp_tx);
6757 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006758 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306759 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6760 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006761 &next_tx_level,
6762 sizeof(next_tx_level));
6763 }
6764
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006765 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006766 if (vote_level_change || tx_level_change || rx_level_change) {
6767 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6768 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6769 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6770 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6771 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6772 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6773 hdd_ctx->hdd_txrx_hist_idx++;
6774 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6775 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07006776
6777 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778}
6779
6780#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306781static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006782{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006783 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306784 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006785 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306786 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306787 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6788 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006789 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306790 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006791 bool connected = false;
6792 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6793
Prashanth Bhattaab004382016-10-11 16:08:11 -07006794 if (wlan_hdd_validate_context(hdd_ctx))
6795 return;
6796
Jeff Johnson214671b2017-10-30 19:45:23 -07006797 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006798 goto restart_timer;
6799
Dustin Brown920397d2017-12-13 16:27:50 -08006800 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05306801 /*
6802 * Validate magic so we don't end up accessing
6803 * an invalid adapter.
6804 */
6805 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6806 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006808 if ((adapter->device_mode == QDF_STA_MODE ||
6809 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006810 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6811 != eConnectionState_Associated) {
6812
6813 continue;
6814 }
6815
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006816 if ((adapter->device_mode == QDF_SAP_MODE ||
6817 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006818 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006819
6820 continue;
6821 }
6822
6823 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6824 adapter->prev_tx_packets);
6825 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6826 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306827
6828 if (adapter->device_mode == QDF_SAP_MODE ||
6829 adapter->device_mode == QDF_P2P_GO_MODE ||
6830 adapter->device_mode == QDF_IBSS_MODE) {
6831
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006832 ret = cdp_get_intra_bss_fwd_pkts_count(
6833 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006834 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306835 &fwd_tx_packets, &fwd_rx_packets);
6836 if (ret == A_OK) {
6837 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6838 fwd_tx_packets,
6839 adapter->prev_fwd_tx_packets);
6840 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6841 fwd_tx_packets,
6842 adapter->prev_fwd_rx_packets);
6843 }
6844 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006845
6846 total_rx += adapter->stats.rx_packets;
6847 total_tx += adapter->stats.tx_packets;
6848
6849 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6850 adapter->prev_tx_packets = adapter->stats.tx_packets;
6851 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306852 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6853 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006854 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6855 connected = true;
6856 }
6857
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306858 /* add intra bss forwarded tx and rx packets */
6859 tx_packets += fwd_tx_packets_diff;
6860 rx_packets += fwd_rx_packets_diff;
6861
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6863 tx_packets += (uint64_t)ipa_tx_packets;
6864 rx_packets += (uint64_t)ipa_rx_packets;
6865
Yun Park2aa880c2017-08-22 10:58:10 -07006866 if (adapter) {
6867 adapter->stats.tx_packets += ipa_tx_packets;
6868 adapter->stats.rx_packets += ipa_rx_packets;
6869 }
6870
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006871 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006872 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006873 return;
6874 }
6875
Yuanyuan Liu13738502016-04-06 17:41:37 -07006876 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006877
6878 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6879 hdd_ipa_uc_stat_request(adapter, 2);
6880
Jingxiang Gec64e1932017-08-22 14:38:59 +08006881restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006882 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006883 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006884 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306885 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006886 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006887 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006889
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306890/**
6891 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6892 * @arg: Argument of timer function
6893 *
6894 * Schedule a workqueue in this function where all the processing is done.
6895 *
6896 * Return: None.
6897 */
6898static void __hdd_bus_bw_cbk(void *arg)
6899{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006900 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306901
6902 if (wlan_hdd_validate_context(hdd_ctx))
6903 return;
6904
6905 schedule_work(&hdd_ctx->bus_bw_work);
6906}
6907
6908/**
6909 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6910 * @arg: Argument of timer function
6911 *
6912 * Return: None.
6913 */
6914static void hdd_bus_bw_cbk(void *arg)
6915{
6916 cds_ssr_protect(__func__);
6917 __hdd_bus_bw_cbk(arg);
6918 cds_ssr_unprotect(__func__);
6919}
6920
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006921int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006922{
6923 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306924 INIT_WORK(&hdd_ctx->bus_bw_work,
6925 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006926 hdd_ctx->bus_bw_timer_running = false;
6927 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306928 qdf_timer_init(NULL,
6929 &hdd_ctx->bus_bw_timer,
6930 hdd_bus_bw_cbk, (void *)hdd_ctx,
6931 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006932
6933 return 0;
6934}
6935
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006936void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006937{
Dustin Brownfce08d12017-01-17 16:29:38 -08006938 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006939 hdd_reset_tcp_delack(hdd_ctx);
6940
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006941 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306942 cancel_work_sync(&hdd_ctx->bus_bw_work);
6943 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006944 hdd_ctx->bus_bw_timer_running = false;
6945 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006946}
Lin Baic5c06882017-09-21 13:58:43 +08006947
6948void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6949{
6950 if (hdd_ctx)
6951 cancel_work_sync(&hdd_ctx->bus_bw_work);
6952}
jiadcdaf9bd2017-10-26 12:20:21 +08006953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006954#endif
6955
6956/**
Nirav Shahed34b212016-04-25 10:59:16 +05306957 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6958 * @hdd_ctx: hdd context
6959 *
6960 * Return: 0 for success or error code
6961 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006962static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306963{
6964 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6965 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6966 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006967 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306968 return -ENOMEM;
6969 }
6970 return 0;
6971}
6972
6973/**
6974 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6975 * @hdd_ctx: hdd context
6976 *
6977 * Return: none
6978 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006979void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306980{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306981 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6982 return;
6983
6984 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6985 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306986}
6987
Nirav Shahda008342016-05-17 18:50:40 +05306988static uint8_t *convert_level_to_string(uint32_t level)
6989{
6990 switch (level) {
6991 /* initialize the wlan sub system */
6992 case WLAN_SVC_TP_NONE:
6993 return "NONE";
6994 case WLAN_SVC_TP_LOW:
6995 return "LOW";
6996 case WLAN_SVC_TP_MEDIUM:
6997 return "MED";
6998 case WLAN_SVC_TP_HIGH:
6999 return "HIGH";
7000 default:
7001 return "INVAL";
7002 }
7003}
7004
Nirav Shahed34b212016-04-25 10:59:16 +05307005
7006/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7008 * @hdd_ctx: hdd context
7009 *
7010 * Return: none
7011 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007012void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007013{
7014 int i;
7015
7016#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007017 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307018 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007019 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007020 hdd_ctx->config->busBandwidthHighThreshold,
7021 hdd_ctx->config->busBandwidthMediumThreshold,
7022 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007023 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307024 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007025 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007026 hdd_ctx->config->tcpDelackThresholdHigh,
7027 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007028 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307029 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007030#endif
7031
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007032 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307033 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7034
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007035 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007036
7037 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007038 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007039 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07007040 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007041 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7042 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007043 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007044 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7045 convert_level_to_string(
7046 hdd_ctx->hdd_txrx_hist[i].
7047 next_vote_level),
7048 convert_level_to_string(
7049 hdd_ctx->hdd_txrx_hist[i].
7050 next_rx_level),
7051 convert_level_to_string(
7052 hdd_ctx->hdd_txrx_hist[i].
7053 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007054 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007055}
7056
7057/**
7058 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7059 * @hdd_ctx: hdd context
7060 *
7061 * Return: none
7062 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007063void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007064{
7065 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307066 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7067 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007068}
7069
Mohit Khannaca4173b2017-09-12 21:52:19 -07007070/* length of the netif queue log needed per adapter */
7071#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7072
7073/**
7074 *
7075 * hdd_display_netif_queue_history_compact() - display compact netifq history
7076 * @hdd_ctx: hdd context
7077 *
7078 * Return: none
7079 */
7080static void
7081hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7082{
7083 int adapter_num = 0;
7084 int i;
7085 int bytes_written;
7086 u32 tbytes;
7087 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007088 char temp_str[20 * WLAN_REASON_TYPE_MAX];
7089 char comb_log_str[(ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1];
7090 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007091
7092 bytes_written = 0;
7093 qdf_mem_set(comb_log_str, 0, sizeof(comb_log_str));
Mohit Khannaca4173b2017-09-12 21:52:19 -07007094
Dustin Brown920397d2017-12-13 16:27:50 -08007095 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007096 curr_time = qdf_system_ticks();
7097 total = curr_time - adapter->start_time;
7098 delta = curr_time - adapter->last_time;
7099
7100 if (adapter->pause_map) {
7101 pause = adapter->total_pause_time + delta;
7102 unpause = adapter->total_unpause_time;
7103 } else {
7104 unpause = adapter->total_unpause_time + delta;
7105 pause = adapter->total_pause_time;
7106 }
7107
7108 tbytes = 0;
7109 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7110 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7111 if (adapter->queue_oper_stats[i].pause_count == 0)
7112 continue;
7113 tbytes +=
7114 snprintf(
7115 &temp_str[tbytes],
7116 (tbytes >= sizeof(temp_str) ?
7117 0 : sizeof(temp_str) - tbytes),
7118 "%d(%d,%d) ",
7119 i,
7120 adapter->queue_oper_stats[i].
7121 pause_count,
7122 adapter->queue_oper_stats[i].
7123 unpause_count);
7124 }
7125 if (tbytes >= sizeof(temp_str))
7126 hdd_warn("log truncated");
7127
7128 bytes_written += snprintf(&comb_log_str[bytes_written],
7129 bytes_written >= sizeof(comb_log_str) ? 0 :
7130 sizeof(comb_log_str) - bytes_written,
7131 "[%d %d] (%d) %u/%ums %s|",
7132 adapter->session_id, adapter->device_mode,
7133 adapter->pause_map,
7134 qdf_system_ticks_to_msecs(pause),
7135 qdf_system_ticks_to_msecs(total),
7136 temp_str);
7137
Mohit Khannaca4173b2017-09-12 21:52:19 -07007138 adapter_num++;
7139 }
7140
7141 /* using QDF_TRACE to avoid printing function name */
7142 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7143 "STATS |%s", comb_log_str);
7144
7145 if (bytes_written >= sizeof(comb_log_str))
7146 hdd_warn("log string truncated");
7147}
7148
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007149/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007150 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007151 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007152 *
7153 * Return: none
7154 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007155void
7156wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7157 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007158{
7159
Jeff Johnson9d295242017-08-29 14:39:48 -07007160 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007161 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307162 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007163
Mohit Khannaca4173b2017-09-12 21:52:19 -07007164 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7165 hdd_display_netif_queue_history_compact(hdd_ctx);
7166 return;
7167 }
7168
Dustin Brown920397d2017-12-13 16:27:50 -08007169 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007170 hdd_debug("Netif queue operation statistics:");
7171 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007172 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007173 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307174 curr_time = qdf_system_ticks();
7175 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307176 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307177 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307178 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307179 unpause = adapter->total_unpause_time;
7180 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307181 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307182 pause = adapter->total_pause_time;
7183 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007184 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307185 qdf_system_ticks_to_msecs(total),
7186 qdf_system_ticks_to_msecs(pause),
7187 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007188 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007189
Nirav Shahda008342016-05-17 18:50:40 +05307190 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7191 qdf_time_t pause_delta = 0;
7192
7193 if (adapter->pause_map & (1 << i))
7194 pause_delta = delta;
7195
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007196 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07007197 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007198 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007199 hdd_reason_type_to_string(i),
7200 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05307201 adapter->queue_oper_stats[i].unpause_count,
7202 qdf_system_ticks_to_msecs(
7203 adapter->queue_oper_stats[i].total_pause_time +
7204 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007205 }
7206
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007207 hdd_debug("Netif queue operation history:");
7208 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307209 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7210
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007211 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007212
7213 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007214 /* using hdd_log to avoid printing function name */
7215 if (adapter->queue_oper_history[i].time == 0)
7216 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07007217 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007218 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05307219 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007220 adapter->queue_oper_history[i].time),
7221 hdd_action_type_to_string(
7222 adapter->queue_oper_history[i].netif_action),
7223 hdd_reason_type_to_string(
7224 adapter->queue_oper_history[i].netif_reason),
7225 adapter->queue_oper_history[i].pause_map);
7226 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007227 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007228}
7229
7230/**
7231 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7232 * @hdd_ctx: hdd context
7233 *
7234 * Return: none
7235 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007236void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007237{
Jeff Johnson9d295242017-08-29 14:39:48 -07007238 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007239
Dustin Brown920397d2017-12-13 16:27:50 -08007240 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307241 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007242 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307243 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007244 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307245 adapter->history_index = 0;
7246 adapter->start_time = adapter->last_time = qdf_system_ticks();
7247 adapter->total_pause_time = 0;
7248 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007249 }
7250}
7251
7252/**
7253 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7254 * @halHandle: Hal handle
7255 * @pContext: Pointer to the context
7256 * @sessionId: Session ID
7257 * @scanId: Scan ID
7258 * @status: Status
7259 *
7260 * This is the callback to be executed when 11d scan is completed to flush out
7261 * the scan results
7262 *
7263 * 11d scan is done during driver load and is a passive scan on all
7264 * channels supported by the device, 11d scans may find some APs on
7265 * frequencies which are forbidden to be used in the regulatory domain
7266 * the device is operating in. If these APs are notified to the supplicant
7267 * it may try to connect to these APs, thus flush out all the scan results
7268 * which are present in SME after 11d scan is done.
7269 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307270 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007271 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307272static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007273 uint8_t sessionId, uint32_t scanId,
7274 eCsrScanStatus status)
7275{
7276 ENTER();
7277
7278 sme_scan_flush_result(halHandle);
7279
7280 EXIT();
7281
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307282 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007283}
7284
7285#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7286/**
7287 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7288 * @hdd_ctx: hdd global context
7289 *
7290 * Return: none
7291 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007292static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007293{
7294 uint8_t i;
7295
7296 mutex_init(&hdd_ctx->op_ctx.op_lock);
7297 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7298 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7299 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7300 }
7301}
7302#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007303static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007304{
7305}
7306#endif
7307
Yingying Tang95409972016-10-20 15:16:15 +08007308#ifdef WLAN_FEATURE_WOW_PULSE
7309/**
7310 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007311 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007312 * @enable: enable or disable this behaviour
7313 *
7314 * Return: int
7315 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007316static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007317{
7318 struct hdd_config *pcfg_ini = phddctx->config;
7319 struct wow_pulse_mode wow_pulse_set_info;
7320 QDF_STATUS status;
7321
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007322 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007323
7324 if (false == phddctx->config->wow_pulse_support)
7325 return 0;
7326
7327 /* prepare the request to send to SME */
7328 if (enable == true) {
7329 wow_pulse_set_info.wow_pulse_enable = true;
7330 wow_pulse_set_info.wow_pulse_pin =
7331 pcfg_ini->wow_pulse_pin;
7332 wow_pulse_set_info.wow_pulse_interval_low =
7333 pcfg_ini->wow_pulse_interval_low;
7334 wow_pulse_set_info.wow_pulse_interval_high =
7335 pcfg_ini->wow_pulse_interval_high;
7336 } else {
7337 wow_pulse_set_info.wow_pulse_enable = false;
7338 wow_pulse_set_info.wow_pulse_pin = 0;
7339 wow_pulse_set_info.wow_pulse_interval_low = 0;
7340 wow_pulse_set_info.wow_pulse_interval_high = 0;
7341 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007342 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007343 wow_pulse_set_info.wow_pulse_enable,
7344 wow_pulse_set_info.wow_pulse_pin,
7345 wow_pulse_set_info.wow_pulse_interval_low,
7346 wow_pulse_set_info.wow_pulse_interval_high);
7347
7348 status = sme_set_wow_pulse(&wow_pulse_set_info);
7349 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007350 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007351 return -EIO;
7352 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007353 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007354 return 0;
7355}
7356#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007357static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007358{
7359 return 0;
7360}
7361#endif
7362
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007363#ifdef WLAN_FEATURE_FASTPATH
7364/**
7365 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7366 * @hdd_cfg: hdd config
7367 * @context: lower layer context
7368 *
7369 * Return: none
7370 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307371void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007372 void *context)
7373{
7374 if (hdd_cfg->fastpath_enable)
7375 hif_enable_fastpath(context);
7376}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007377#endif
7378
Yuanyuan Liu13738502016-04-06 17:41:37 -07007379#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007380/**
7381 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007382 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007383 * @level: thermal level
7384 *
7385 * Change IPA data path to SW path when the thermal throttle level greater
7386 * than 0, and restore the original data path when throttle level is 0
7387 *
7388 * Return: none
7389 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007390static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007391{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007392 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007393
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007394 /* Change IPA to SW path when throttle level greater than 0 */
7395 if (level > THROTTLE_LEVEL_0)
7396 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7397 else
7398 /* restore original concurrency mode */
7399 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7400}
7401
7402/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307403 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7404 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307405 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007406 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307407 * Get a safe channel to restart SAP. PCL already takes into account the
7408 * unsafe channels. So, the PCL is validated with the ACS range to provide
7409 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007410 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307411 * Return: Channel number to restart SAP in case of success. In case of any
7412 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007413 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307414static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007415 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007416{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307417 struct sir_pcl_list pcl;
7418 QDF_STATUS status;
7419 uint32_t i, j;
7420 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007421 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307422 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007423
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307424 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7425 if (!hdd_ctx) {
7426 hdd_err("invalid HDD context");
7427 return INVALID_CHANNEL_ID;
7428 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007429
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307430 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7431 if (!hal_handle) {
7432 hdd_err("invalid HAL handle");
7433 return INVALID_CHANNEL_ID;
7434 }
7435
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007436 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7437 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007438 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7439 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307440 if (QDF_IS_STATUS_ERROR(status)) {
7441 hdd_err("Get PCL failed");
7442 return INVALID_CHANNEL_ID;
7443 }
7444
Frank Liudc2cefb2017-06-21 15:38:18 +08007445 /*
7446 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7447 * channel is unsafe channel, the pcl may be empty, instead of return,
7448 * try to choose a safe channel from acs range.
7449 */
7450 if (!pcl.pcl_len)
7451 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307452
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007453 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007454 adapter->session.ap.sap_config.acs_cfg.start_ch,
7455 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307456
7457 /* PCL already takes unsafe channel into account */
7458 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007459 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307460 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007461 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307462 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007463 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007464 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307465 return pcl.pcl_list[i];
7466 }
7467 }
7468
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007469 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307470
7471 /* Try for safe channel from all valid channel */
7472 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007473 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307474 &pcl.pcl_len);
7475 if (QDF_IS_STATUS_ERROR(status)) {
7476 hdd_err("error in getting valid channel list");
7477 return INVALID_CHANNEL_ID;
7478 }
7479
7480 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007481 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307482 found = false;
7483 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007484 if (pcl.pcl_list[i] ==
7485 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007486 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307487 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007488 break;
7489 }
7490 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307491
7492 if (found)
7493 continue;
7494
7495 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007496 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307497 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007498 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007499 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307500 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007501 }
7502 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307503
7504 return INVALID_CHANNEL_ID;
7505}
7506
7507/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007508 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307509 * @adapter: AP adapter
7510 * @channel: Channel
7511 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007512 * Moves the SAP interface by invoking the function which
7513 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307514 *
7515 * Return: None
7516 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007517void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307518{
Jeff Johnson87251032017-08-29 13:31:11 -07007519 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307520 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007521 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307522
7523 if (!adapter) {
7524 hdd_err("invalid adapter");
7525 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007526 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307527
7528 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7529
7530 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7531 if (!hal_handle) {
7532 hdd_err("invalid HAL handle");
7533 return;
7534 }
7535
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007536 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7537
Jeff Johnson91df29d2017-10-27 19:29:50 -07007538 hdd_ap_ctx->sap_config.channel = channel;
7539 hdd_ap_ctx->sap_config.ch_params.ch_width =
7540 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307541
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007542 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007543 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307544
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007545 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007546 hdd_ap_ctx->sap_config.channel,
7547 hdd_ap_ctx->sap_config.sec_ch,
7548 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307549
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007550 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007551 adapter->session_id, channel,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007552 hdd_ap_ctx->sap_config.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007553}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307554
Jeff Johnson9d295242017-08-29 14:39:48 -07007555int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307556{
7557 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307558 int status;
7559 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307560
7561 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7562
7563 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007564 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307565 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007566 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307567 }
7568 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007569 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307570 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307571 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007572 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307573 WLAN_VENDOR_ACS_WAIT_TIME);
7574 if (qdf_status != QDF_STATUS_SUCCESS) {
7575 hdd_err("failed to start external acs timer");
7576 return -ENOSPC;
7577 }
7578 /* Update config to application */
7579 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307580 hdd_notice("Updated ACS config to nl with reason %d", reason);
7581
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307582 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307583}
7584
Agrawal Ashish467dde42016-09-08 18:44:22 +05307585/**
7586 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7587 * @hdd_ctx: hdd context pointer
7588 *
7589 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7590 * and if ACS is enabled, driver will ask userspace to restart the
7591 * sap. User space on LTE coex indication restart driver.
7592 *
7593 * Return - none
7594 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007595void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307596{
Dustin Brown920397d2017-12-13 16:27:50 -08007597 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307598 uint32_t i;
7599 bool found = false;
7600 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007601
Dustin Brown920397d2017-12-13 16:27:50 -08007602 hdd_for_each_adapter(hdd_ctxt, adapter) {
7603 if (!(adapter->device_mode == QDF_SAP_MODE &&
7604 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007605 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007606 adapter->device_mode,
7607 adapter->session.ap.sap_config.
7608 acs_cfg.acs_mode);
7609 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307610 }
7611
7612 found = false;
7613 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007614 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307615 hdd_ctxt->unsafe_channel_list[i]) {
7616 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007617 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007618 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307619 break;
7620 }
7621 }
7622
7623 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007624 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007625 adapter->session.ap.operating_channel);
7626 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307627 }
7628
Kapil Gupta8878ad92017-02-13 11:56:04 +05307629 if (hdd_ctxt->config->vendor_acs_support &&
7630 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007631 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307632 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007633 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307634 } else
7635 restart_chan =
7636 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007637 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307638 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007639 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307640 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007641 /*
7642 * SAP restart due to unsafe channel. While
7643 * restarting the SAP, make sure to clear
7644 * acs_channel, channel to reset to
7645 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307646 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007647 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307648 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007649 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307650 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007651 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307652 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7653 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007654 hdd_debug("driver to start sap: %d",
7655 hdd_ctxt->config->sap_internal_restart);
7656 if (hdd_ctxt->config->sap_internal_restart)
Dustin Brown920397d2017-12-13 16:27:50 -08007657 hdd_switch_sap_channel(adapter, restart_chan);
Liangwei Dong6663d162017-07-10 03:29:36 -04007658 else
7659 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307660 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307661 }
7662}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307663
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007664/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007665 * hdd_init_channel_avoidance() - Initialize channel avoidance
7666 * @hdd_ctx: HDD global context
7667 *
7668 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007669 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007670 * down to the lower layers. Then subscribe to subsequent channel
7671 * avoidance events.
7672 *
7673 * Return: None
7674 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007675static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007676{
7677 uint16_t unsafe_channel_count;
7678 int index;
7679
Yuanyuan Liu13738502016-04-06 17:41:37 -07007680 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7681 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007682 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007683 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007684
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007685 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007686 hdd_ctx->unsafe_channel_count);
7687
Anurag Chouhan6d760662016-02-20 16:05:43 +05307688 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007689 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007690
7691 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007692 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007693 hdd_ctx->unsafe_channel_list[index]);
7694
7695 }
7696
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007697}
Dustin Brown676a2322017-08-15 13:16:13 -07007698
Jeff Johnson9d295242017-08-29 14:39:48 -07007699static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007700 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007701{
7702 uint8_t restart_chan;
7703
7704 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7705 if (!restart_chan) {
7706 hdd_alert("fail to restart SAP");
7707 return;
7708 }
7709
7710 /* SAP restart due to unsafe channel. While restarting
7711 * the SAP, make sure to clear acs_channel, channel to
7712 * reset to 0. Otherwise these settings will override
7713 * the ACS while restart.
7714 */
7715 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007716 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007717
7718 hdd_debug("sending coex indication");
7719
7720 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7721 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7722 hdd_switch_sap_channel(adapter, restart_chan);
7723}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007724
7725int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7726 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7727{
7728 uint32_t size;
7729 uint16_t *unsafe_list;
7730 uint16_t chan_count;
7731
7732 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7733 return -EINVAL;
7734
7735 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7736 NUM_CHANNELS);
7737 if (chan_count) {
7738 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7739 unsafe_list = qdf_mem_malloc(size);
7740 if (!unsafe_list) {
7741 hdd_err("No memory for unsafe chan list size%d",
7742 size);
7743 return -ENOMEM;
7744 }
7745 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7746 } else {
7747 unsafe_list = NULL;
7748 }
7749
7750 *local_unsafe_list = unsafe_list;
7751 *local_unsafe_list_count = chan_count;
7752
7753 return 0;
7754}
7755
7756bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7757 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7758{
7759 int i, j;
7760
7761 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7762 return true;
7763 if (local_unsafe_list_count == 0)
7764 return false;
7765 for (i = 0; i < local_unsafe_list_count; i++) {
7766 for (j = 0; j < local_unsafe_list_count; j++)
7767 if (local_unsafe_list[i] ==
7768 hdd_ctx->unsafe_channel_list[j])
7769 break;
7770 if (j >= local_unsafe_list_count)
7771 break;
7772 }
7773 if (i >= local_unsafe_list_count) {
7774 hdd_info("unsafe chan list same");
7775 return false;
7776 }
7777
7778 return true;
7779}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007780#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007781static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007782{
7783}
Dustin Brown676a2322017-08-15 13:16:13 -07007784
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007785static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007786{
7787}
Dustin Brown676a2322017-08-15 13:16:13 -07007788
Jeff Johnson9d295242017-08-29 14:39:48 -07007789static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007790 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007791{
7792 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7793}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007794#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007795
7796/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007797 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7798 * user space
7799 * @frame_ind: Management frame data to be informed.
7800 *
7801 * This function is used to indicate management frame to
7802 * user space
7803 *
7804 * Return: None
7805 *
7806 */
7807void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7808{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007809 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007810 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007811 int i;
7812
Rajeev Kumard004abc2016-02-17 12:09:56 -08007813 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007814 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007815
7816 if (0 != wlan_hdd_validate_context(hdd_ctx))
7817 return;
7818
7819 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7820 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7821 adapter =
7822 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7823 if (adapter)
7824 break;
7825 }
Wu Gaoa0230a62018-01-04 20:56:57 +08007826 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
7827 hdd_for_each_adapter(hdd_ctx, adapter) {
7828 if ((NULL != adapter) &&
7829 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
7830 __hdd_indicate_mgmt_frame(adapter,
7831 frame_ind->frame_len,
7832 frame_ind->frameBuf,
7833 frame_ind->frameType,
7834 frame_ind->rxChan,
7835 frame_ind->rxRssi);
7836 }
7837 }
7838 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007839 } else {
7840 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7841 frame_ind->sessionId);
7842 }
7843
7844 if ((NULL != adapter) &&
7845 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7846 __hdd_indicate_mgmt_frame(adapter,
7847 frame_ind->frame_len,
7848 frame_ind->frameBuf,
7849 frame_ind->frameType,
7850 frame_ind->rxChan,
7851 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007852}
7853
Kapil Gupta8878ad92017-02-13 11:56:04 +05307854void hdd_acs_response_timeout_handler(void *context)
7855{
7856 struct hdd_external_acs_timer_context *timer_context =
7857 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007858 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007859 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307860 uint8_t reason;
7861
7862 ENTER();
7863 if (!timer_context) {
7864 hdd_err("invlaid timer context");
7865 return;
7866 }
7867 adapter = timer_context->adapter;
7868 reason = timer_context->reason;
7869
7870
7871 if ((!adapter) ||
7872 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7873 hdd_err("invalid adapter or adapter has invalid magic");
7874 return;
7875 }
7876 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7877 if (wlan_hdd_validate_context(hdd_ctx))
7878 return;
7879
7880 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7881 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7882 else
7883 return;
7884
7885 hdd_err("ACS timeout happened for %s reason %d",
7886 adapter->dev->name, reason);
7887 switch (reason) {
7888 /* SAP init case */
7889 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7890 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7891 false);
7892 wlan_hdd_cfg80211_start_acs(adapter);
7893 break;
7894 /* DFS detected on current channel */
7895 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7896 wlan_sap_update_next_channel(
7897 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7898 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007899 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307900 break;
7901 /* LTE coex event on current channel */
7902 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7903 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7904 break;
7905 default:
7906 hdd_info("invalid reason for timer invoke");
7907
7908 }
7909}
7910
Rajeev Kumard004abc2016-02-17 12:09:56 -08007911/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007912 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7913 * @hdd_ctx: HDD context
7914 *
7915 * Disables all the dual mac features like DBS, Agile DFS etc.
7916 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307917 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007918 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007919static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007920{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007921 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307922 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007923
7924 if (!hdd_ctx) {
7925 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307926 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007927 }
7928
7929 cfg.scan_config = 0;
7930 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007931 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007932
7933 hdd_debug("Disabling all dual mac features...");
7934
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007935 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307936 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007937 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7938 return status;
7939 }
7940
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307941 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007942}
7943
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007944static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007945wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007946{
7947 struct policy_mgr_dual_mac_config cfg = {0};
7948 QDF_STATUS status;
7949
7950 if (!hdd_ctx) {
7951 hdd_err("HDD context is NULL");
7952 return QDF_STATUS_E_FAILURE;
7953 }
7954
7955 cfg.scan_config = 0;
7956 cfg.fw_mode_config = 0;
7957 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7958 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7959 hdd_ctx->hdd_psoc, &cfg.scan_config,
7960 &cfg.fw_mode_config,
7961 hdd_ctx->config->dual_mac_feature_disable);
7962
7963 if (status != QDF_STATUS_SUCCESS) {
7964 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7965 status);
7966 return status;
7967 }
7968
7969 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7970 cfg.scan_config, cfg.fw_mode_config);
7971
7972 status = sme_soc_set_dual_mac_config(cfg);
7973 if (status != QDF_STATUS_SUCCESS) {
7974 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7975 return status;
7976 }
7977
7978 return QDF_STATUS_SUCCESS;
7979}
7980
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007981/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007982 * hdd_override_ini_config - Override INI config
7983 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007984 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007985 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007986 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007987 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007988 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007989static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007990{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007991
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007992 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7993 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007994 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007995 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007996 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007997 if (0 == enable_11d || 1 == enable_11d) {
7998 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007999 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008000 }
Leo Chang11545d62016-10-17 14:53:50 -07008001
8002 if (!hdd_ipa_is_present(hdd_ctx))
8003 hdd_ctx->config->IpaConfig = 0;
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308004
8005 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8006 !hdd_ctx->config->enable_bcast_probe_rsp) {
8007 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8008 hdd_ctx->config->rssi_assoc_reject_enabled,
8009 hdd_ctx->config->enable_bcast_probe_rsp);
8010 hdd_ctx->config->oce_sta_enabled = 0;
8011 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008012}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008013
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008014/**
8015 * hdd_set_trace_level_for_each - Set trace level for each INI config
8016 * @hdd_ctx - HDD context
8017 *
8018 * Set trace level for each module based on INI config.
8019 *
8020 * Return: None
8021 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008022static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008023{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308024 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8025 hdd_ctx->config->qdf_trace_enable_wdi);
8026 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8027 hdd_ctx->config->qdf_trace_enable_hdd);
8028 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8029 hdd_ctx->config->qdf_trace_enable_sme);
8030 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8031 hdd_ctx->config->qdf_trace_enable_pe);
8032 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8033 hdd_ctx->config->qdf_trace_enable_wma);
8034 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8035 hdd_ctx->config->qdf_trace_enable_sys);
8036 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8037 hdd_ctx->config->qdf_trace_enable_qdf);
8038 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8039 hdd_ctx->config->qdf_trace_enable_sap);
8040 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8041 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8042 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8043 hdd_ctx->config->qdf_trace_enable_bmi);
8044 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8045 hdd_ctx->config->qdf_trace_enable_cfg);
8046 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8047 hdd_ctx->config->qdf_trace_enable_epping);
8048 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8049 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8050 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008051 hdd_ctx->config->qdf_trace_enable_txrx);
8052 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8053 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308054 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8055 hdd_ctx->config->qdf_trace_enable_htc);
8056 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8057 hdd_ctx->config->qdf_trace_enable_hif);
8058 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8059 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8060 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8061 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008062 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8063 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008064 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8065 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008066 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8067 hdd_ctx->config->qdf_trace_enable_regulatory);
8068
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008069 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008070}
8071
8072/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008073 * hdd_context_init() - Initialize HDD context
8074 * @hdd_ctx: HDD context.
8075 *
8076 * Initialize HDD context along with all the feature specific contexts.
8077 *
8078 * return: 0 on success and errno on failure.
8079 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008080static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008081{
8082 int ret;
8083
8084 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8085 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8086
8087 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308088 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008089
8090 init_completion(&hdd_ctx->mc_sus_event_var);
8091 init_completion(&hdd_ctx->ready_to_suspend);
8092
8093 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308094 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008095 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308096
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008097 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008098
8099 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8100
8101 ret = hdd_scan_context_init(hdd_ctx);
8102 if (ret)
8103 goto list_destroy;
8104
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008105 hdd_rx_wake_lock_create(hdd_ctx);
8106
8107 ret = hdd_sap_context_init(hdd_ctx);
8108 if (ret)
8109 goto scan_destroy;
8110
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008111 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8112
8113 hdd_init_offloaded_packets_ctx(hdd_ctx);
8114
8115 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8116 hdd_ctx->config);
8117 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008118 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008119
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308120 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8121 "monitor_mode_wakelock");
8122
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008123 return 0;
8124
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008125sap_destroy:
8126 hdd_sap_context_destroy(hdd_ctx);
8127
8128scan_destroy:
8129 hdd_scan_context_destroy(hdd_ctx);
8130 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008131list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008132 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008133
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008134 return ret;
8135}
8136
8137/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308138 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8139 * @hdd_ctx: pointer to hdd context
8140 *
8141 * Return: status of initialization
8142 * 0 - success
8143 * negative value - failure
8144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008145static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308146{
8147 int ret;
8148
8149 if (!hdd_ctx->config->probe_req_ie_whitelist)
8150 return 0;
8151
8152 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8153 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8154 hdd_ctx->config->probe_req_ie_whitelist = false;
8155 return -EINVAL;
8156 }
8157
8158 /* parse ini string probe req oui */
8159 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8160 if (ret) {
8161 hdd_err("parsing error: disable ie whitelisting");
8162 hdd_ctx->config->probe_req_ie_whitelist = false;
8163 }
8164
8165 return ret;
8166}
8167
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308168
8169/**
8170 * hdd_iface_change_callback() - Function invoked when stop modules expires
8171 * @priv: pointer to hdd context
8172 *
8173 * This function is invoked when the timer waiting for the interface change
8174 * expires, it shall cut-down the power to wlan and stop all the modules.
8175 *
8176 * Return: void
8177 */
8178static void hdd_iface_change_callback(void *priv)
8179{
8180 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8181 int ret;
8182 int status = wlan_hdd_validate_context(hdd_ctx);
8183
8184 if (status)
8185 return;
8186
8187 ENTER();
8188 hdd_debug("Interface change timer expired close the modules!");
8189 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8190 if (ret)
8191 hdd_err("Failed to stop modules");
8192 EXIT();
8193}
8194
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308195/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008196 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308197 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008198 *
8199 * Allocate and initialize HDD context. HDD context is allocated as part of
8200 * wiphy allocation and then context is initialized.
8201 *
8202 * Return: HDD context on success and ERR_PTR on failure
8203 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008204static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008205{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308206 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008207 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008208 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008209
8210 ENTER();
8211
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008212 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008213 if (hdd_ctx == NULL) {
8214 ret = -ENOMEM;
8215 goto err_out;
8216 }
8217
Dustin Brown6f427922017-09-19 12:19:00 -07008218 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8219 hdd_iface_change_callback,
8220 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308221
8222 mutex_init(&hdd_ctx->iface_change_lock);
8223
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008224 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308225 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008226
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308227 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008228 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008229 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008230 ret = -ENOMEM;
8231 goto err_free_hdd_context;
8232 }
8233
8234 /* Read and parse the qcom_cfg.ini file */
8235 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308236 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308237 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008238 WLAN_INI_FILE);
8239 ret = -EINVAL;
8240 goto err_free_config;
8241 }
8242
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308243 ie_whitelist_attrs_init(hdd_ctx);
8244
Dustin Brown7f939932017-05-18 15:02:17 -07008245 hdd_debug("setting timer multiplier: %u",
8246 hdd_ctx->config->timer_multiplier);
8247 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8248
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008249
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308250 if (hdd_ctx->config->fhostNSOffload)
8251 hdd_ctx->ns_offload_enable = true;
8252
Abhishek Singh5ea86532016-04-27 14:10:53 +05308253 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8254
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008255 hdd_override_ini_config(hdd_ctx);
8256
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008257 ret = hdd_context_init(hdd_ctx);
8258
8259 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008260 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008261
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008262 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308263 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008264
Anurag Chouhan6d760662016-02-20 16:05:43 +05308265 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008266 goto skip_multicast_logging;
8267
8268 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8269
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008270 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8271 if (ret)
8272 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308273
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008274 ret = hdd_init_netlink_services(hdd_ctx);
8275 if (ret)
8276 goto err_deinit_txrx_histogram;
8277
Dustin Brown7b3dea22017-07-10 13:02:47 -07008278 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
8279 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05308280
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008281skip_multicast_logging:
8282 hdd_set_trace_level_for_each(hdd_ctx);
8283
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008284 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8285
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008286 EXIT();
8287
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008288 return hdd_ctx;
8289
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008290err_deinit_txrx_histogram:
8291 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8292
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008293err_deinit_hdd_context:
8294 hdd_context_deinit(hdd_ctx);
8295
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008296err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308297 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008298
8299err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308300 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008301 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008302
8303err_out:
8304 return ERR_PTR(ret);
8305}
8306
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008307#ifdef WLAN_OPEN_P2P_INTERFACE
8308/**
8309 * hdd_open_p2p_interface - Open P2P interface
8310 * @hdd_ctx: HDD context
8311 * @rtnl_held: True if RTNL lock held
8312 *
8313 * Open P2P interface during probe. This function called to open the P2P
8314 * interface at probe along with STA interface.
8315 *
8316 * Return: 0 on success and errno on failure
8317 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008318static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008319{
Jeff Johnson9d295242017-08-29 14:39:48 -07008320 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008321 uint8_t *p2p_dev_addr;
8322
8323 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8324 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008325 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008326 hdd_ctx->config->intfMacAddr[0].bytes,
8327 sizeof(tSirMacAddr));
8328
8329 /*
8330 * Generate the P2P Device Address. This consists of
8331 * the device's primary MAC address with the locally
8332 * administered bit set.
8333 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008334 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008335 } else {
8336 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8337 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008338 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008339 return -ENOSPC;
8340 }
8341
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008342 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8343 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008344 }
8345
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008346 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008347 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008348 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008349
8350 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008351 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008352 return -ENOSPC;
8353 }
8354
8355 return 0;
8356}
8357#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008358static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008359 bool rtnl_held)
8360{
8361 return 0;
8362}
8363#endif
8364
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008365static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008366{
Jeff Johnson9d295242017-08-29 14:39:48 -07008367 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008368 int ret = 0;
8369
8370 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8371 wlan_hdd_get_intf_addr(hdd_ctx),
8372 NET_NAME_UNKNOWN, rtnl_held);
8373 if (adapter == NULL) {
8374 hdd_err("Failed to open 802.11p interface");
8375 ret = -ENOSPC;
8376 }
8377
8378 return ret;
8379}
8380
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008381/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308382 * hdd_start_station_adapter()- Start the Station Adapter
8383 * @adapter: HDD adapter
8384 *
8385 * This function initializes the adapter for the station mode.
8386 *
8387 * Return: 0 on success or errno on failure.
8388 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008389int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308390{
8391 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008392 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308393
8394 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008395 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8396 hdd_err("session is already opened, %d",
8397 adapter->session_id);
8398 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8399 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308400
Krunal Sonib51eec72017-11-20 21:53:01 -08008401 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8402 if (ret) {
8403 hdd_err("failed to create vdev: %d", ret);
8404 return ret;
8405 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308406 status = hdd_init_station_mode(adapter);
8407
8408 if (QDF_STATUS_SUCCESS != status) {
8409 hdd_err("Error Initializing station mode: %d", status);
8410 return qdf_status_to_os_return(status);
8411 }
8412
Arun Khandavallifae92942016-08-01 13:31:08 +05308413 hdd_register_tx_flow_control(adapter,
8414 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008415 hdd_tx_resume_cb,
8416 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308417
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308418 EXIT();
8419 return 0;
8420}
8421
8422/**
8423 * hdd_start_ap_adapter()- Start AP Adapter
8424 * @adapter: HDD adapter
8425 *
8426 * This function initializes the adapter for the AP mode.
8427 *
8428 * Return: 0 on success errno on failure.
8429 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008430int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308431{
8432 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008433 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008434 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308435
8436 ENTER();
8437
Krunal Sonib51eec72017-11-20 21:53:01 -08008438 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8439 hdd_err("session is already opened, %d",
8440 adapter->session_id);
8441 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8442 }
8443 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008444 * In SSR case no need to create new sap context.
8445 * Otherwise create sap context first and then create
8446 * vdev as while creating the vdev, driver needs to
8447 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008448 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008449 if (adapter->session.ap.sap_context) {
8450 is_ssr = true;
8451 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008452 hdd_err("sap creation failed");
8453 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8454 }
8455
8456 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8457 adapter->session.ap.sap_context);
8458 if (ret) {
8459 hdd_err("failed to create vdev, status:%d", ret);
8460 hdd_sap_destroy_ctx(adapter);
8461 return ret;
8462 }
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008463 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308464
8465 if (QDF_STATUS_SUCCESS != status) {
8466 hdd_err("Error Initializing the AP mode: %d", status);
8467 return qdf_status_to_os_return(status);
8468 }
8469
Arun Khandavallifae92942016-08-01 13:31:08 +05308470 hdd_register_tx_flow_control(adapter,
8471 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008472 hdd_softap_tx_resume_cb,
8473 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308474
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308475 EXIT();
8476 return 0;
8477}
8478
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308479static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8480 bool rtnl_held)
8481{
8482 struct hdd_adapter *adapter;
8483
8484 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8485 hdd_ctx->config->enableConcurrentSTA,
8486 wlan_hdd_get_intf_addr(hdd_ctx),
8487 NET_NAME_UNKNOWN, rtnl_held);
8488
8489 if (!adapter)
8490 return -ENOSPC;
8491
8492 return 0;
8493}
8494
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308495/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008496 * hdd_open_interfaces - Open all required interfaces
8497 * hdd_ctx: HDD context
8498 * rtnl_held: True if RTNL lock is held
8499 *
8500 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8501 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008502 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008503 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008504static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008505{
Jeff Johnson9d295242017-08-29 14:39:48 -07008506 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008507 int ret;
8508
Ravi Joshia307f632017-07-17 23:41:41 -07008509 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008510 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8511 con_mode == QDF_GLOBAL_FTM_MODE) {
8512 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8513 QDF_MONITOR_MODE : QDF_FTM_MODE;
8514
8515 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8516 wlan_hdd_get_intf_addr(hdd_ctx),
8517 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008518 if (!adapter) {
8519 hdd_err("open adapter failed");
8520 return -ENOSPC;
8521 }
Lin Bai1c678482017-12-18 18:29:11 +08008522
Ravi Joshia307f632017-07-17 23:41:41 -07008523 return 0;
8524 }
8525
Jeff Johnson957bc272017-02-02 08:54:48 -08008526 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308527 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008528 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008529
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008530 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008531 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008532 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008533
8534 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008535 return -ENOSPC;
8536
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008537 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8538 adapter->fast_roaming_allowed = true;
8539
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308540 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8541 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8542 if (ret)
8543 hdd_err("Cannot create concurrent STA interface");
8544 }
8545
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008546 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8547 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008548 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008549
8550 /* Open 802.11p Interface */
8551 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008552 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8553 if (ret)
8554 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008555 }
8556
Jeff Johnson957bc272017-02-02 08:54:48 -08008557 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008558
Jeff Johnson957bc272017-02-02 08:54:48 -08008559err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008560 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008561 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008562}
8563
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008564/**
8565 * hdd_update_country_code - Update country code
8566 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008567 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008568 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008569 *
8570 * Return: 0 on success and errno on failure
8571 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008572static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008573{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008574 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008575 return 0;
8576
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008577 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008578}
8579
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308580#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8581/**
8582 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8583 * @cds_cfg: CDS Configuration
8584 * @hdd_ctx: Pointer to hdd context
8585 *
8586 * Return: none
8587 */
8588static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8589 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008590 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308591{
8592 cds_cfg->tx_flow_stop_queue_th =
8593 hdd_ctx->config->TxFlowStopQueueThreshold;
8594 cds_cfg->tx_flow_start_queue_offset =
8595 hdd_ctx->config->TxFlowStartQueueOffset;
8596}
8597#else
8598static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8599 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008600 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308601{
8602}
8603#endif
8604
8605#ifdef FEATURE_WLAN_RA_FILTERING
8606/**
8607 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8608 * @cds_cfg: CDS Configuration
8609 * @hdd_ctx: Pointer to hdd context
8610 *
8611 * Return: none
8612 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308613static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008614 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308615{
8616 cds_cfg->ra_ratelimit_interval =
8617 hdd_ctx->config->RArateLimitInterval;
8618 cds_cfg->is_ra_ratelimit_enabled =
8619 hdd_ctx->config->IsRArateLimitEnabled;
8620}
8621#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308622static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008623 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308624{
8625}
8626#endif
8627
8628/**
8629 * hdd_update_cds_config() - API to update cds configuration parameters
8630 * @hdd_ctx: HDD Context
8631 *
8632 * Return: 0 for Success, errno on failure
8633 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008634static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308635{
8636 struct cds_config_info *cds_cfg;
8637
8638 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8639 if (!cds_cfg) {
8640 hdd_err("failed to allocate cds config");
8641 return -ENOMEM;
8642 }
8643
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008644 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008645 if (!hdd_ctx->config->nMaxPsPoll ||
8646 !hdd_ctx->config->enablePowersaveOffload) {
8647 cds_cfg->powersave_offload_enabled =
8648 hdd_ctx->config->enablePowersaveOffload;
8649 } else {
8650 if ((hdd_ctx->config->enablePowersaveOffload ==
8651 PS_QPOWER_NODEEPSLEEP) ||
8652 (hdd_ctx->config->enablePowersaveOffload ==
8653 PS_LEGACY_NODEEPSLEEP))
8654 cds_cfg->powersave_offload_enabled =
8655 PS_LEGACY_NODEEPSLEEP;
8656 else
8657 cds_cfg->powersave_offload_enabled =
8658 PS_LEGACY_DEEPSLEEP;
8659 hdd_info("Qpower disabled in cds config, %d",
8660 cds_cfg->powersave_offload_enabled);
8661 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308662 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8663 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8664 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8665 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8666 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8667
8668 /* Here ol_ini_info is used to store ini status of arp offload
8669 * ns offload and others. Currently 1st bit is used for arp
8670 * off load and 2nd bit for ns offload currently, rest bits are unused
8671 */
8672 if (hdd_ctx->config->fhostArpOffload)
8673 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8674 if (hdd_ctx->config->fhostNSOffload)
8675 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8676
8677 /*
8678 * Copy the DFS Phyerr Filtering Offload status.
8679 * This parameter reflects the value of the
8680 * dfs_phyerr_filter_offload flag as set in the ini.
8681 */
8682 cds_cfg->dfs_phyerr_filter_offload =
8683 hdd_ctx->config->fDfsPhyerrFilterOffload;
8684 if (hdd_ctx->config->ssdp)
8685 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8686
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308687 cds_cfg->force_target_assert_enabled =
8688 hdd_ctx->config->crash_inject_enabled;
8689
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308690 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8691 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8692
8693 cds_cfg->ap_maxoffload_reorderbuffs =
8694 hdd_ctx->config->apMaxOffloadReorderBuffs;
8695
8696 cds_cfg->ap_disable_intrabss_fwd =
8697 hdd_ctx->config->apDisableIntraBssFwd;
8698
8699 cds_cfg->dfs_pri_multiplier =
8700 hdd_ctx->config->dfsRadarPriMultiplier;
8701 cds_cfg->reorder_offload =
8702 hdd_ctx->config->reorderOffloadSupport;
8703
8704 /* IPA micro controller data path offload resource config item */
8705 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008706 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8707 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008708 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008709 hdd_ctx->config->IpaUcTxBufCount);
8710 hdd_ctx->config->IpaUcTxBufCount =
8711 rounddown_pow_of_two(
8712 hdd_ctx->config->IpaUcTxBufCount);
8713 if (!hdd_ctx->config->IpaUcTxBufCount) {
8714 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308715 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008716 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008717 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008718 hdd_ctx->config->IpaUcTxBufCount);
8719 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308720 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8721 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008722 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8723 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008724 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008725 hdd_ctx->config->IpaUcRxIndRingCount);
8726 hdd_ctx->config->IpaUcRxIndRingCount =
8727 rounddown_pow_of_two(
8728 hdd_ctx->config->IpaUcRxIndRingCount);
8729 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8730 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308731 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008732 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008733 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008734 hdd_ctx->config->IpaUcRxIndRingCount);
8735 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308736 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008737 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308738 cds_cfg->uc_tx_partition_base =
8739 hdd_ctx->config->IpaUcTxPartitionBase;
8740 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8741
8742 cds_cfg->ip_tcp_udp_checksum_offload =
8743 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008744 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308745 cds_cfg->ce_classify_enabled =
8746 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008747 cds_cfg->bpf_packet_filter_enable =
8748 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308749 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8750 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8751 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008752 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008753 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008754 cds_cfg->max_msdus_per_rxinorderind =
8755 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008756 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008757 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308758 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8759 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308760 cds_cfg->auto_power_save_fail_mode =
8761 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308762
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308763 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008764 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308765
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308766 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8767 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8768 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008769 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308770 cds_init_ini_config(cds_cfg);
8771 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308772
8773exit:
8774 qdf_mem_free(cds_cfg);
8775 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308776}
8777
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008778/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008779 * hdd_update_user_config() - API to update user configuration
8780 * parameters to obj mgr which are used by multiple components
8781 * @hdd_ctx: HDD Context
8782 *
8783 * Return: 0 for Success, errno on failure
8784 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008785static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008786{
8787 struct wlan_objmgr_psoc_user_config *user_config;
8788
8789 user_config = qdf_mem_malloc(sizeof(*user_config));
8790 if (user_config == NULL) {
8791 hdd_alert("Failed to alloc memory for user_config!");
8792 return -ENOMEM;
8793 }
8794
8795 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8796 user_config->dual_mac_feature_disable =
8797 hdd_ctx->config->dual_mac_feature_disable;
8798 user_config->indoor_channel_support =
8799 hdd_ctx->config->indoor_channel_support;
8800 user_config->is_11d_support_enabled =
8801 hdd_ctx->config->Is11dSupportEnabled;
8802 user_config->is_11h_support_enabled =
8803 hdd_ctx->config->Is11hSupportEnabled;
8804 user_config->optimize_chan_avoid_event =
8805 hdd_ctx->config->goptimize_chan_avoid_event;
8806 user_config->skip_dfs_chnl_in_p2p_search =
8807 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008808 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008809 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8810
8811 qdf_mem_free(user_config);
8812 return 0;
8813}
8814
8815/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008816 * hdd_init_thermal_info - Initialize thermal level
8817 * @hdd_ctx: HDD context
8818 *
8819 * Initialize thermal level at SME layer and set the thermal level callback
8820 * which would be called when a configured thermal threshold is hit.
8821 *
8822 * Return: 0 on success and errno on failure
8823 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008824static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008825{
8826 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308827 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008828
8829 thermal_param.smeThermalMgmtEnabled =
8830 hdd_ctx->config->thermalMitigationEnable;
8831 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8832
Poddar, Siddarth83905022016-04-16 17:56:08 -07008833 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8834 hdd_ctx->config->throttle_dutycycle_level0;
8835 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8836 hdd_ctx->config->throttle_dutycycle_level1;
8837 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8838 hdd_ctx->config->throttle_dutycycle_level2;
8839 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8840 hdd_ctx->config->throttle_dutycycle_level3;
8841
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008842 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8843 hdd_ctx->config->thermalTempMinLevel0;
8844 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8845 hdd_ctx->config->thermalTempMaxLevel0;
8846 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8847 hdd_ctx->config->thermalTempMinLevel1;
8848 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8849 hdd_ctx->config->thermalTempMaxLevel1;
8850 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8851 hdd_ctx->config->thermalTempMinLevel2;
8852 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8853 hdd_ctx->config->thermalTempMaxLevel2;
8854 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8855 hdd_ctx->config->thermalTempMinLevel3;
8856 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8857 hdd_ctx->config->thermalTempMaxLevel3;
8858
8859 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8860
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308861 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308862 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008863
8864 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8865 hdd_set_thermal_level_cb);
8866
8867 return 0;
8868
8869}
8870
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008871#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8872/**
8873 * hdd_hold_rtnl_lock - Hold RTNL lock
8874 *
8875 * Hold RTNL lock
8876 *
8877 * Return: True if held and false otherwise
8878 */
8879static inline bool hdd_hold_rtnl_lock(void)
8880{
8881 rtnl_lock();
8882 return true;
8883}
8884
8885/**
8886 * hdd_release_rtnl_lock - Release RTNL lock
8887 *
8888 * Release RTNL lock
8889 *
8890 * Return: None
8891 */
8892static inline void hdd_release_rtnl_lock(void)
8893{
8894 rtnl_unlock();
8895}
8896#else
8897static inline bool hdd_hold_rtnl_lock(void) { return false; }
8898static inline void hdd_release_rtnl_lock(void) { }
8899#endif
8900
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008901#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008902
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308903/* MAX iwpriv command support */
8904#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308905#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308906#define MAX_PKTLOG_SIZE 16
8907
8908/**
8909 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8910 * @hdd_ctx: hdd context
8911 * @set_value2: pktlog buffer size value
8912 *
8913 *
8914 * Return: 0 for success or error.
8915 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008916static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308917{
8918 struct sir_wifi_start_log start_log = { 0 };
8919 QDF_STATUS status;
8920
8921 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8922 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8923 start_log.ini_triggered = cds_is_packet_log_enabled();
8924 start_log.user_triggered = 1;
8925 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308926 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308927
8928 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8929 if (!QDF_IS_STATUS_SUCCESS(status)) {
8930 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8931 EXIT();
8932 return -EINVAL;
8933 }
8934
8935 return 0;
8936}
8937
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008938/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308939 * hdd_pktlog_clear_buff() - clear pktlog buffer
8940 * @hdd_ctx: hdd context
8941 *
8942 * Return: 0 for success or error.
8943 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008944static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308945{
8946 struct sir_wifi_start_log start_log;
8947 QDF_STATUS status;
8948
8949 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8950 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8951 start_log.ini_triggered = cds_is_packet_log_enabled();
8952 start_log.user_triggered = 1;
8953 start_log.size = 0;
8954 start_log.is_pktlog_buff_clear = true;
8955
8956 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8957 if (!QDF_IS_STATUS_SUCCESS(status)) {
8958 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8959 EXIT();
8960 return -EINVAL;
8961 }
8962
8963 return 0;
8964}
8965
8966
8967/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008968 * hdd_process_pktlog_command() - process pktlog command
8969 * @hdd_ctx: hdd context
8970 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308971 * @set_value2: pktlog buffer size value
8972 *
8973 * This function process pktlog command.
8974 * set_value2 only matters when set_value is 3 (set buff size)
8975 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008976 *
8977 * Return: 0 for success or error.
8978 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008979int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308980 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008981{
8982 int ret;
8983 bool enable;
8984 uint8_t user_triggered = 0;
8985
8986 ret = wlan_hdd_validate_context(hdd_ctx);
8987 if (0 != ret)
8988 return ret;
8989
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008990 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008991
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308992 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008993 hdd_err("invalid pktlog value %d", set_value);
8994 return -EINVAL;
8995 }
8996
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308997 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8998 if (set_value2 <= 0) {
8999 hdd_err("invalid pktlog size %d", set_value2);
9000 return -EINVAL;
9001 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9002 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9003 return -EINVAL;
9004 }
9005 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309006 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9007 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309008 }
9009
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009010 /*
9011 * set_value = 0 then disable packetlog
9012 * set_value = 1 enable packetlog forcefully
9013 * set_vlaue = 2 then disable packetlog if disabled through ini or
9014 * enable packetlog with AUTO type.
9015 */
9016 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9017 true : false;
9018
9019 if (1 == set_value) {
9020 enable = true;
9021 user_triggered = 1;
9022 }
9023
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309024 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009025}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009026
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009027/**
9028 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9029 * @hdd_ctx: HDD context
9030 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309031 * @user_triggered: triggered through iwpriv
9032 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009033 *
9034 * Return: 0 on success; error number otherwise
9035 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009036int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309037 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009038{
9039 struct sir_wifi_start_log start_log;
9040 QDF_STATUS status;
9041
9042 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9043 start_log.verbose_level =
9044 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009045 start_log.ini_triggered = cds_is_packet_log_enabled();
9046 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309047 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309048 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309049 /*
9050 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9051 * commands. Host uses this flag to decide whether to send pktlog
9052 * disable command to fw without sending pktlog enable command
9053 * previously. For eg, If vendor sends pktlog disable command without
9054 * sending pktlog enable command, then host discards the packet
9055 * but for iwpriv command, host will send it to fw.
9056 */
9057 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009058 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9059 if (!QDF_IS_STATUS_SUCCESS(status)) {
9060 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9061 EXIT();
9062 return -EINVAL;
9063 }
9064
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309065 if (enable == true)
9066 hdd_ctx->is_pktlog_enabled = 1;
9067 else
9068 hdd_ctx->is_pktlog_enabled = 0;
9069
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009070 return 0;
9071}
9072#endif /* REMOVE_PKT_LOG */
9073
Komal Seelam92fff912016-03-24 11:51:41 +05309074/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009075 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9076 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309077 * @dev: Device Pointer
9078 * @num: Number of Valid Mac address
9079 *
9080 * Return: Pointer to MAC address buffer
9081 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009082static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9083 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309084{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009085 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309086}
Komal Seelam92fff912016-03-24 11:51:41 +05309087
9088/**
9089 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9090 * @hdd_ctx: HDD Context
9091 * @num: Number of random mac addresses needed
9092 *
9093 * Generate random addresses using bit manipulation on the base mac address
9094 *
9095 * Return: None
9096 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009097void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309098{
9099 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9100 uint32_t iter;
9101 struct hdd_config *ini = hdd_ctx->config;
9102 uint8_t *buf = NULL;
9103 uint8_t macaddr_b3, tmp_br3;
9104 uint8_t *src = ini->intfMacAddr[0].bytes;
9105
9106 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9107 buf = ini->intfMacAddr[iter].bytes;
9108 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9109 macaddr_b3 = buf[3];
9110 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9111 INTF_MACADDR_MASK;
9112 macaddr_b3 += tmp_br3;
9113 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9114 buf[0] |= 0x02;
9115 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009116 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309117 }
9118}
9119
9120/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009121 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309122 * @hdd_ctx: HDD Context
9123 *
9124 * API to get mac addresses from platform driver and update the driver
9125 * structures and configure FW with the base mac address.
9126 * Return: int
9127 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009128static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309129{
9130 uint32_t no_of_mac_addr, iter;
9131 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9132 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9133 uint8_t *addr, *buf;
9134 struct device *dev = hdd_ctx->parent_dev;
9135 struct hdd_config *ini = hdd_ctx->config;
9136 tSirMacAddr mac_addr;
9137 QDF_STATUS status;
9138
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009139 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309140
9141 if (no_of_mac_addr == 0 || !addr) {
9142 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9143 return -EINVAL;
9144 }
9145
9146 if (no_of_mac_addr > max_mac_addr)
9147 no_of_mac_addr = max_mac_addr;
9148
9149 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9150
9151 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9152 buf = ini->intfMacAddr[iter].bytes;
9153 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009154 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309155 }
9156
9157 status = sme_set_custom_mac_addr(mac_addr);
9158
9159 if (!QDF_IS_STATUS_SUCCESS(status))
9160 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009161
Komal Seelam92fff912016-03-24 11:51:41 +05309162 if (no_of_mac_addr < max_mac_addr)
9163 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9164 no_of_mac_addr);
9165 return 0;
9166}
9167
9168/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009169 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9170 * @hdd_ctx: HDD Context
9171 *
9172 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9173 * will generate its own MAC and update it to FW.
9174 *
9175 * Return: 0 for success
9176 * Non-zero error code for failure
9177 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009178static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009179{
9180 tSirMacAddr customMacAddr;
9181 QDF_STATUS status;
9182
9183 qdf_mem_copy(&customMacAddr,
9184 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9185 sizeof(tSirMacAddr));
9186 status = sme_set_custom_mac_addr(customMacAddr);
9187 if (!QDF_IS_STATUS_SUCCESS(status))
9188 return -EAGAIN;
9189 return 0;
9190}
9191
9192/**
Komal Seelam92fff912016-03-24 11:51:41 +05309193 * hdd_initialize_mac_address() - API to get wlan mac addresses
9194 * @hdd_ctx: HDD Context
9195 *
9196 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9197 * is provisioned with mac addresses, driver uses it, else it will use
9198 * wlan_mac.bin to update HW MAC addresses.
9199 *
9200 * Return: None
9201 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009202static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309203{
9204 QDF_STATUS status;
9205 int ret;
9206
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009207 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309208 if (ret == 0)
9209 return;
9210
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009211 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9212 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309213
9214 status = hdd_update_mac_config(hdd_ctx);
9215
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009216 if (QDF_IS_STATUS_SUCCESS(status))
9217 return;
9218
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009219 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9220 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009221
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009222 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009223 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009224 if (ret != 0) {
9225 hdd_err("MAC address out-of-sync, ret:%d", ret);
9226 QDF_ASSERT(ret);
9227 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009228 }
Komal Seelam92fff912016-03-24 11:51:41 +05309229}
9230
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009231static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009232{
9233 int vdev_id = 0;
9234 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9235 int value = hdd_ctx->config->smart_chainmask_enabled;
9236 int vpdev = PDEV_CMD;
9237 int ret;
9238
Naveen Rawat247a8682017-06-05 15:00:31 -07009239 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009240 if (ret)
9241 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9242
9243 return ret;
9244}
9245
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009246static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009247{
9248 int vdev_id = 0;
9249 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9250 int value = hdd_ctx->config->alternative_chainmask_enabled;
9251 int vpdev = PDEV_CMD;
9252 int ret;
9253
Naveen Rawat247a8682017-06-05 15:00:31 -07009254 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009255 if (ret)
9256 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9257 ret);
9258
9259 return ret;
9260}
9261
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009262static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009263{
9264 int vdev_id = 0;
9265 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9266 int value = hdd_ctx->config->ani_enabled;
9267 int vpdev = PDEV_CMD;
9268 int ret;
9269
Naveen Rawat247a8682017-06-05 15:00:31 -07009270 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009271 if (ret)
9272 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9273
9274 return ret;
9275}
9276
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009277/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009278 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9279 * @hdd_ctx: HDD context
9280 *
9281 * Pre configurations to be done at lower layer before calling cds enable.
9282 *
9283 * Return: 0 on success and errno on failure.
9284 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009285static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009286{
9287 int ret;
9288 QDF_STATUS status;
9289 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009290 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009291
Leo Changfdb45c32016-10-28 11:09:23 -07009292 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009293 /*
9294 * Set 802.11p config
9295 * TODO-OCB: This has been temporarily added here to ensure this
9296 * parameter is set in CSR when we init the channel list. This should
9297 * be removed once the 5.9 GHz channels are added to the regulatory
9298 * domain.
9299 */
9300 hdd_set_dot11p_config(hdd_ctx);
9301
9302 /*
9303 * Note that the cds_pre_enable() sequence triggers the cfg download.
9304 * The cfg download must occur before we update the SME config
9305 * since the SME config operation must access the cfg database
9306 */
9307 status = hdd_set_sme_config(hdd_ctx);
9308
9309 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009310 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009311 ret = qdf_status_to_os_return(status);
9312 goto out;
9313 }
9314
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009315 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9316 if (QDF_STATUS_SUCCESS != status) {
9317 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9318 ret = qdf_status_to_os_return(status);
9319 goto out;
9320 }
9321
Naveen Rawat247a8682017-06-05 15:00:31 -07009322 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009323 hdd_ctx->config->tx_chain_mask_1ss,
9324 PDEV_CMD);
9325 if (0 != ret) {
9326 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9327 goto out;
9328 }
9329
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009330 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9331 if (ret)
9332 goto out;
9333
9334 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9335 if (ret)
9336 goto out;
9337
Jeff Johnson12a744b2017-04-04 08:19:37 -07009338 ret = hdd_set_ani_enabled(hdd_ctx);
9339 if (ret)
9340 goto out;
9341
Naveen Rawat247a8682017-06-05 15:00:31 -07009342 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009343 hdd_ctx->config->arp_ac_category,
9344 PDEV_CMD);
9345 if (0 != ret) {
9346 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9347 hdd_ctx->config->arp_ac_category, ret);
9348 goto out;
9349 }
9350
Prashanth Bhatta07998752016-04-28 12:35:33 -07009351 status = hdd_set_sme_chan_list(hdd_ctx);
9352 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009353 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009354 ret = qdf_status_to_os_return(status);
9355 goto out;
9356 }
9357
9358 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009359 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009360 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009361 ret = -EINVAL;
9362 goto out;
9363 }
9364
Prashanth Bhatta07998752016-04-28 12:35:33 -07009365 /*
9366 * Set the MAC Address Currently this is used by HAL to add self sta.
9367 * Remove this once self sta is added as part of session open.
9368 */
9369 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9370 hdd_ctx->config->intfMacAddr[0].bytes,
9371 sizeof(hdd_ctx->config->intfMacAddr[0]));
9372
9373 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9374 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9375 hal_status, hal_status);
9376 ret = -EINVAL;
9377 goto out;
9378 }
9379
9380 hdd_init_channel_avoidance(hdd_ctx);
9381
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309382 /* update enable sap mandatory chan list */
9383 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9384 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009385out:
9386 return ret;
9387}
9388
9389/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009390 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9391 * @context_ptr - hdd context pointer
9392 * @event_ptr - event structure pointer
9393 *
9394 * This is the p2p listen offload stop event handler, it sends vendor
9395 * event back to supplicant to notify the stop reason.
9396 *
9397 * Return: None
9398 */
9399static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9400 void *event_ptr)
9401{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009402 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009403 struct sir_p2p_lo_event *evt = event_ptr;
9404 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009405 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009406
9407 ENTER();
9408
9409 if (hdd_ctx == NULL) {
9410 hdd_err("Invalid HDD context pointer");
9411 return;
9412 }
9413
Peng Xu5c682812017-08-06 07:39:13 -07009414 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9415 if (!adapter) {
9416 hdd_err("Cannot find adapter by vdev_id = %d",
9417 evt->vdev_id);
9418 return;
9419 }
9420
Peng Xu8fdaa492016-06-22 10:20:47 -07009421 vendor_event =
9422 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009423 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009424 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9425 GFP_KERNEL);
9426
9427 if (!vendor_event) {
9428 hdd_err("cfg80211_vendor_event_alloc failed");
9429 return;
9430 }
9431
9432 if (nla_put_u32(vendor_event,
9433 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9434 evt->reason_code)) {
9435 hdd_err("nla put failed");
9436 kfree_skb(vendor_event);
9437 return;
9438 }
9439
9440 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009441 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9442 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009443}
9444
9445/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309446 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9447 * @hdd_ctx: HDD context
9448 *
9449 * This function sends the adaptive dwell time config configuration to the
9450 * firmware via WMA
9451 *
9452 * Return: 0 - success, < 0 - failure
9453 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009454static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309455{
9456 QDF_STATUS status;
9457 struct adaptive_dwelltime_params dwelltime_params;
9458
9459 dwelltime_params.is_enabled =
9460 hdd_ctx->config->adaptive_dwell_mode_enabled;
9461 dwelltime_params.dwelltime_mode =
9462 hdd_ctx->config->global_adapt_dwelltime_mode;
9463 dwelltime_params.lpf_weight =
9464 hdd_ctx->config->adapt_dwell_lpf_weight;
9465 dwelltime_params.passive_mon_intval =
9466 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9467 dwelltime_params.wifi_act_threshold =
9468 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9469
9470 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9471 &dwelltime_params);
9472
9473 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9474 if (!QDF_IS_STATUS_SUCCESS(status)) {
9475 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9476 return -EAGAIN;
9477 }
9478 return 0;
9479}
9480
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009481int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309482{
9483 QDF_STATUS status;
9484 struct wmi_dbs_scan_sel_params dbs_scan_params;
9485 uint32_t i = 0;
9486 uint8_t count = 0, numentries = 0;
9487 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9488 * CDS_DBS_SCAN_CLIENTS_MAX];
9489
9490 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009491 if (hdd_ctx->config->dual_mac_feature_disable ==
9492 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309493 return -EINVAL;
9494
9495 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9496 dbs_scan_config, &numentries,
9497 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9498 * CDS_DBS_SCAN_CLIENTS_MAX));
9499
9500 hdd_info("numentries %hu", numentries);
9501 if (!numentries) {
9502 hdd_info("Donot send scan_selection_config");
9503 return 0;
9504 }
9505
9506 /* hdd_set_fw_log_params */
9507 dbs_scan_params.num_clients = 0;
9508 while (count < (numentries - 2)) {
9509 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9510 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9511 dbs_scan_params.num_non_dbs_scans[i] =
9512 dbs_scan_config[count + 2];
9513 dbs_scan_params.num_clients++;
9514 hdd_debug("module:%d NDS:%d NNDS:%d",
9515 dbs_scan_params.module_id[i],
9516 dbs_scan_params.num_dbs_scans[i],
9517 dbs_scan_params.num_non_dbs_scans[i]);
9518 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9519 i++;
9520 }
9521
9522 dbs_scan_params.pdev_id = 0;
9523
9524 hdd_debug("clients:%d pdev:%d",
9525 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9526
9527 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9528 &dbs_scan_params);
9529 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9530 if (!QDF_IS_STATUS_SUCCESS(status)) {
9531 hdd_err("Failed to send DBS Scan selection configuration!");
9532 return -EAGAIN;
9533 }
9534 return 0;
9535}
9536
Arun Khandavallid4349a92016-07-25 11:10:43 +05309537#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9538/**
9539 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9540 * @hdd_ctx: HDD context
9541 *
9542 * Set auto shutdown callback to get indications from firmware to indicate
9543 * userspace to shutdown WLAN after a configured amount of inactivity.
9544 *
9545 * Return: 0 on success and errno on failure.
9546 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009547static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309548{
9549 QDF_STATUS status;
9550
9551 if (!hdd_ctx->config->WlanAutoShutdown)
9552 return 0;
9553
9554 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9555 wlan_hdd_auto_shutdown_cb);
9556 if (status != QDF_STATUS_SUCCESS)
9557 hdd_err("Auto shutdown feature could not be enabled: %d",
9558 status);
9559
9560 return qdf_status_to_os_return(status);
9561}
9562#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009563static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309564{
9565 return 0;
9566}
9567#endif
9568
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009569static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009570{
9571 QDF_STATUS status = QDF_STATUS_SUCCESS;
9572
9573 switch (hdd_ctx->config->dual_mac_feature_disable) {
9574 case DISABLE_DBS_CXN_AND_SCAN:
9575 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9576 if (status != QDF_STATUS_SUCCESS)
9577 hdd_err("Failed to disable dual mac features");
9578 break;
9579 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9580 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9581 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9582 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9583 if (status != QDF_STATUS_SUCCESS)
9584 hdd_err("Failed to set dbs scan and fw mode config");
9585 break;
9586 default:
9587 break;
9588 }
9589
9590 return status;
9591}
9592
Arun Khandavallid4349a92016-07-25 11:10:43 +05309593/**
9594 * hdd_features_init() - Init features
9595 * @hdd_ctx: HDD context
9596 * @adapter: Primary adapter context
9597 *
9598 * Initialize features and their feature context after WLAN firmware is up.
9599 *
9600 * Return: 0 on success and errno on failure.
9601 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009602static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309603{
9604 tSirTxPowerLimit hddtxlimit;
9605 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309606 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309607 int ret;
9608
9609 ENTER();
9610
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009611 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309612 if (ret) {
9613 hdd_err("Failed to update country code: %d", ret);
9614 goto out;
9615 }
9616
9617 /* FW capabilities received, Set the Dot11 mode */
9618 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009619 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9620 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309621
Arun Khandavallid4349a92016-07-25 11:10:43 +05309622
9623 if (hdd_ctx->config->fIsImpsEnabled)
9624 hdd_set_idle_ps_config(hdd_ctx, true);
9625 else
9626 hdd_set_idle_ps_config(hdd_ctx, false);
9627
Poddar, Siddarth37033032017-10-11 15:47:40 +05309628 /* Send Enable/Disable data stall detection cmd to FW */
9629 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9630 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9631
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309632 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009633 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309634
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309635 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9636 hdd_warn("Error in setting Voltage Corner mode config to FW");
9637
Arun Khandavallid4349a92016-07-25 11:10:43 +05309638 if (hdd_lro_init(hdd_ctx))
9639 hdd_err("Unable to initialize LRO in fw");
9640
9641 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9642 hdd_err("Unable to send adaptive dwelltime setting to FW");
9643
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309644 if (hdd_dbs_scan_selection_init(hdd_ctx))
9645 hdd_err("Unable to send DBS scan selection setting to FW");
9646
Arun Khandavallid4349a92016-07-25 11:10:43 +05309647 ret = hdd_init_thermal_info(hdd_ctx);
9648 if (ret) {
9649 hdd_err("Error while initializing thermal information");
9650 goto deregister_frames;
9651 }
9652
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309653 /**
9654 * In case of SSR/PDR, if pktlog was enabled manually before
9655 * SSR/PDR, Then enabled it again automatically after Wlan
9656 * device up.
9657 */
9658 if (cds_is_driver_recovering()) {
9659 if (hdd_ctx->is_pktlog_enabled)
9660 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9661 } else if (cds_is_packet_log_enabled())
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309662 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9663
Arun Khandavallid4349a92016-07-25 11:10:43 +05309664 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9665 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9666 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9667 if (!QDF_IS_STATUS_SUCCESS(status))
9668 hdd_err("Error setting txlimit in sme: %d", status);
9669
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009670 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309671
Arun Khandavallid4349a92016-07-25 11:10:43 +05309672 ret = hdd_register_cb(hdd_ctx);
9673 if (ret) {
9674 hdd_err("Failed to register HDD callbacks!");
9675 goto deregister_frames;
9676 }
9677
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009678 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9679 if (!QDF_IS_STATUS_SUCCESS(status)) {
9680 hdd_err("Failed to set dbs scan and fw mode cfg");
9681 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309682 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009683
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309684 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9685 status = sme_enable_disable_chanavoidind_event(
9686 hdd_ctx->hHal, 0);
9687 if (!QDF_IS_STATUS_SUCCESS(status)) {
9688 hdd_err("Failed to disable Chan Avoidance Indication");
9689 goto deregister_cb;
9690 }
9691 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309692
Manjeet Singha9cae432017-02-28 11:58:22 +05309693 if (hdd_ctx->config->enable_5g_band_pref) {
9694 band_pref_params.rssi_boost_threshold_5g =
9695 hdd_ctx->config->rssi_boost_threshold_5g;
9696 band_pref_params.rssi_boost_factor_5g =
9697 hdd_ctx->config->rssi_boost_factor_5g;
9698 band_pref_params.max_rssi_boost_5g =
9699 hdd_ctx->config->max_rssi_boost_5g;
9700 band_pref_params.rssi_penalize_threshold_5g =
9701 hdd_ctx->config->rssi_penalize_threshold_5g;
9702 band_pref_params.rssi_penalize_factor_5g =
9703 hdd_ctx->config->rssi_penalize_factor_5g;
9704 band_pref_params.max_rssi_penalize_5g =
9705 hdd_ctx->config->max_rssi_penalize_5g;
9706 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9707 }
9708
Arun Khandavallid4349a92016-07-25 11:10:43 +05309709 /* register P2P Listen Offload event callback */
9710 if (wma_is_p2p_lo_capable())
9711 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9712 wlan_hdd_p2p_lo_event_callback);
9713
9714 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9715
9716 if (ret)
9717 goto deregister_cb;
9718
9719 EXIT();
9720 return 0;
9721
9722deregister_cb:
9723 hdd_deregister_cb(hdd_ctx);
9724deregister_frames:
9725 wlan_hdd_cfg80211_deregister_frames(adapter);
9726out:
9727 return -EINVAL;
9728
9729}
9730
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009731/**
9732 * hdd_features_deinit() - Deinit features
9733 * @hdd_ctx: HDD context
9734 *
9735 * De-Initialize features and their feature context.
9736 *
9737 * Return: none.
9738 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009739static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009740{
9741 wlan_hdd_tsf_deinit(hdd_ctx);
9742}
9743
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309744/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009745 * hdd_register_bcn_cb() - register scan beacon callback
9746 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309747 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009748 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309749 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009750static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309751{
9752 QDF_STATUS status;
9753
9754 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9755 wlan_cfg80211_inform_bss_frame,
9756 SCAN_CB_TYPE_INFORM_BCN);
9757 if (!QDF_IS_STATUS_SUCCESS(status)) {
9758 hdd_err("failed with status code %08d [x%08x]",
9759 status, status);
9760 return status;
9761 }
9762
9763 return QDF_STATUS_SUCCESS;
9764}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309765
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309766/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309767 * hdd_configure_cds() - Configure cds modules
9768 * @hdd_ctx: HDD context
9769 * @adapter: Primary adapter context
9770 *
9771 * Enable Cds modules after WLAN firmware is up.
9772 *
9773 * Return: 0 on success and errno on failure.
9774 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009775int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309776{
9777 int ret;
9778 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309779 int set_value;
9780 uint32_t num_abg_tx_chains = 0;
9781 uint32_t num_11b_tx_chains = 0;
9782 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009783 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309784
9785 if (hdd_ctx->config->sifs_burst_duration) {
9786 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9787 hdd_ctx->config->sifs_burst_duration;
9788
9789 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9790 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9791 set_value, PDEV_CMD);
9792 }
9793
9794 if (hdd_ctx->config->is_force_1x1)
9795 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9796 1, PDEV_CMD);
9797 /* set chip power save failure detected callback */
9798 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9799 hdd_chip_pwr_save_fail_detected_cb);
9800
9801 if (hdd_ctx->config->max_mpdus_inampdu) {
9802 set_value = hdd_ctx->config->max_mpdus_inampdu;
9803 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9804 set_value, PDEV_CMD);
9805 }
9806
9807 if (hdd_ctx->config->enable_rts_sifsbursting) {
9808 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9809 sme_cli_set_command(0,
9810 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9811 set_value, PDEV_CMD);
9812 }
9813
9814 if (hdd_ctx->config->sap_get_peer_info) {
9815 set_value = hdd_ctx->config->sap_get_peer_info;
9816 sme_cli_set_command(0,
9817 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9818 set_value, PDEV_CMD);
9819 }
9820
9821 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9822 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9823 if (!hdd_ctx->config->enable2x2) {
9824 if (num_11b_tx_chains > 1)
9825 num_11b_tx_chains = 1;
9826 if (num_11ag_tx_chains > 1)
9827 num_11ag_tx_chains = 1;
9828 }
9829 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9830 num_11b_tx_chains);
9831 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9832 num_11ag_tx_chains);
9833 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9834 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309835
9836 ret = hdd_pre_enable_configure(hdd_ctx);
9837 if (ret) {
9838 hdd_err("Failed to pre-configure cds");
9839 goto out;
9840 }
9841
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009842 /* Always get latest IPA resources allocated from cds_open and configure
9843 * IPA module before configuring them to FW. Sequence required as crash
9844 * observed otherwise.
9845 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009846 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9847 hdd_err("Failed to setup pipes");
9848 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009849 }
9850
Arun Khandavallifae92942016-08-01 13:31:08 +05309851 /*
9852 * Start CDS which starts up the SME/MAC/HAL modules and everything
9853 * else
9854 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009855 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309856
9857 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009858 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309859 goto out;
9860 }
9861
9862 status = hdd_post_cds_enable_config(hdd_ctx);
9863 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009864 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009865 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309866 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309867 status = hdd_register_bcn_cb(hdd_ctx);
9868 if (!QDF_IS_STATUS_SUCCESS(status)) {
9869 hdd_alert("hdd_post_cds_enable_config failed");
9870 goto cds_disable;
9871 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309872
9873 ret = hdd_features_init(hdd_ctx, adapter);
9874 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009875 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309876
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009877 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009878 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009879 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9880 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009881 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009882 goto cds_disable;
9883 }
9884
Himanshu Agarwalb229a142017-12-21 10:16:45 +05309885 if (ucfg_green_ap_enable_egap(hdd_ctx->hdd_pdev))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309886 hdd_debug("enhance green ap is not enabled");
9887
Nachiket Kukadedd302662017-07-13 17:31:44 +05309888 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9889 hdd_debug("Failed to set wow pulse");
9890
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309891 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9892 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9893
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309894
9895 if (hdd_ctx->config->enable_phy_reg_retention)
9896 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9897 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9898
Arun Khandavallifae92942016-08-01 13:31:08 +05309899 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009900
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009901cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009902 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009903
Arun Khandavallifae92942016-08-01 13:31:08 +05309904out:
9905 return -EINVAL;
9906}
9907
9908/**
9909 * hdd_deconfigure_cds() -De-Configure cds
9910 * @hdd_ctx: HDD context
9911 *
9912 * Deconfigure Cds modules before WLAN firmware is down.
9913 *
9914 * Return: 0 on success and errno on failure.
9915 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009916static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309917{
9918 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009919 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309920
9921 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009922
9923 /* De-init features */
9924 hdd_features_deinit(hdd_ctx);
9925
Arun Khandavallifae92942016-08-01 13:31:08 +05309926 /* De-register the SME callbacks */
9927 hdd_deregister_cb(hdd_ctx);
9928
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009929 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309930 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9931 hdd_err("Failed to Disable the CDS Modules! :%d",
9932 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009933 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309934 }
9935
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309936 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9937 hdd_err("Failed to disconnect pipes");
9938 ret = -EINVAL;
9939 }
9940
Arun Khandavallifae92942016-08-01 13:31:08 +05309941 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009942 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309943}
9944
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009945#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9946static void hdd_deregister_policy_manager_callback(
9947 struct wlan_objmgr_psoc *psoc)
9948{
9949 if (QDF_STATUS_SUCCESS !=
9950 policy_mgr_deregister_hdd_cb(psoc)) {
9951 hdd_err("HDD callback deregister with policy manager failed");
9952 }
9953}
9954#else
9955static void hdd_deregister_policy_manager_callback(
9956 struct wlan_objmgr_psoc *psoc)
9957{
9958}
9959#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309960
9961/**
9962 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9963 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009964 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309965 *
9966 * This function maintains the driver state machine it will be invoked from
9967 * exit, shutdown and con_mode change handler. Depending on the driver state
9968 * shall perform the stopping/closing of the modules.
9969 *
9970 * Return: 0 for success; non-zero for failure
9971 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009972int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309973{
9974 void *hif_ctx;
9975 qdf_device_t qdf_ctx;
9976 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309977 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -08009978 bool is_recovery_stop = cds_is_driver_recovering();
9979 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop;
Dustin Brown70111822017-03-30 15:31:40 -07009980 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309981
9982 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009983 hdd_alert("stop WLAN module: entering driver status=%d",
9984 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309985
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009986 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9987
Arun Khandavallifae92942016-08-01 13:31:08 +05309988 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9989 if (!qdf_ctx) {
9990 hdd_err("QDF device context NULL");
9991 return -EINVAL;
9992 }
9993
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309994 mutex_lock(&hdd_ctx->iface_change_lock);
9995 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009996 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +05309997
Dustin Brown70111822017-03-30 15:31:40 -07009998 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -07009999 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010000 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010001 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010002
10003 cds_print_external_threads();
10004
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010005 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010006 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010007 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10008 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010009 hdd_prevent_suspend_timeout(
10010 hdd_ctx->config->iface_change_wait_time,
10011 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010012 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010013 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010014 return 0;
10015 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010016 }
10017
Arun Khandavallifae92942016-08-01 13:31:08 +053010018 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10019
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010020 /* free user wowl patterns */
10021 hdd_free_user_wowl_ptrns();
10022
Arun Khandavallifae92942016-08-01 13:31:08 +053010023 switch (hdd_ctx->driver_status) {
10024 case DRIVER_MODULES_UNINITIALIZED:
10025 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010026 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010027 case DRIVER_MODULES_CLOSED:
10028 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010029 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010030 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010031 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10032
Komal Seelamf2136bb2016-09-28 18:30:44 +053010033 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010034 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010035 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010036 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010037 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010038 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010039 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010040
Arun Khandavallifae92942016-08-01 13:31:08 +053010041 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010042 hdd_info("Wlan transitioned (now OPENED)");
10043
10044 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010045 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010046 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010047 break;
10048 default:
10049 hdd_err("Trying to stop wlan in a wrong state: %d",
10050 hdd_ctx->driver_status);
10051 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010052 ret = -EINVAL;
10053 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010054 }
10055
Dustin Brown550f6d22017-12-14 15:44:01 -080010056 hdd_debug("Closing CDS modules!");
Rajeev Kumarbe021242017-02-16 16:12:23 -080010057 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010058 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10059 hdd_err("Failed to process post CDS disable Modules! :%d",
10060 qdf_status);
10061 ret = -EINVAL;
10062 QDF_ASSERT(0);
10063 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010064
psimhadeea0a12017-12-18 14:50:02 -080010065 hdd_runtime_suspend_context_deinit(hdd_ctx);
10066
Dustin Brownbd68fe12017-11-21 15:28:52 -080010067 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10068 if (ret) {
10069 hdd_err("Failed to destroy pdev; errno:%d", ret);
10070 QDF_ASSERT(0);
10071 }
10072
10073 /*
10074 * Reset total mac phy during module stop such that during
10075 * next module start same psoc is used to populate new service
10076 * ready data
10077 */
10078 hdd_ctx->hdd_psoc->total_mac_phy = 0;
10079
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010080 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10081 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10082 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10083 ret = -EINVAL;
10084 QDF_ASSERT(0);
10085 }
10086
Jeff Johnsone4b14592017-09-13 14:23:33 -070010087 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010088 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010089 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010090 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010091 QDF_ASSERT(0);
10092 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010093
Arun Khandavallifae92942016-08-01 13:31:08 +053010094 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10095 if (!hif_ctx) {
10096 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010097 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010098 }
10099
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010100 if (hdd_ctx->target_hw_name) {
10101 qdf_mem_free(hdd_ctx->target_hw_name);
10102 hdd_ctx->target_hw_name = NULL;
10103 }
10104
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010105 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010106
10107 ol_cds_free();
10108
Dustin Brown70111822017-03-30 15:31:40 -070010109 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010110 ret = pld_power_off(qdf_ctx->dev);
10111 if (ret)
10112 hdd_err("CNSS power down failed put device into Low power mode:%d",
10113 ret);
10114 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010115
Dustin Brown4bc0a622017-12-06 15:56:50 -080010116 /* many adapter resources are not freed by design in SSR case */
10117 if (!is_recovery_stop)
10118 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010119 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010120
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010121 /* Once the firmware sequence is completed reset this flag */
10122 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010123 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010124 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010125
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010126done:
10127 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010128 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010129 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010130 hdd_alert("stop WLAN module: exit driver status=%d",
10131 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010132
Arun Khandavallifae92942016-08-01 13:31:08 +053010133 EXIT();
10134
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010135 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010136}
10137
Arun Khandavallifae92942016-08-01 13:31:08 +053010138
10139/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010140 * hdd_state_info_dump() - prints state information of hdd layer
10141 * @buf: buffer pointer
10142 * @size: size of buffer to be filled
10143 *
10144 * This function is used to dump state information of hdd layer
10145 *
10146 * Return: None
10147 */
10148static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10149{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010150 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010151 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010152 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010153 uint16_t len = 0;
10154 char *buf = *buf_ptr;
10155
10156 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10157 if (!hdd_ctx) {
10158 hdd_err("Failed to get hdd context ");
10159 return;
10160 }
10161
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010162 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010163
10164 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010165 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010166 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010167 "\n is_scheduler_suspended %d",
10168 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010169
Dustin Brown920397d2017-12-13 16:27:50 -080010170 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010171 if (adapter->dev)
10172 len += scnprintf(buf + len, *size - len,
10173 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010174 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010175 "\n device_mode: %d", adapter->device_mode);
10176 switch (adapter->device_mode) {
10177 case QDF_STA_MODE:
10178 case QDF_P2P_CLIENT_MODE:
10179 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10180 len += scnprintf(buf + len, *size - len,
10181 "\n connState: %d",
10182 hdd_sta_ctx->conn_info.connState);
10183 break;
10184
10185 default:
10186 break;
10187 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010188 }
10189
10190 *size -= len;
10191 *buf_ptr += len;
10192}
10193
10194/**
10195 * hdd_register_debug_callback() - registration function for hdd layer
10196 * to print hdd state information
10197 *
10198 * Return: None
10199 */
10200static void hdd_register_debug_callback(void)
10201{
10202 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10203}
10204
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010205/*
10206 * wlan_init_bug_report_lock() - Initialize bug report lock
10207 *
10208 * This function is used to create bug report lock
10209 *
10210 * Return: None
10211 */
10212static void wlan_init_bug_report_lock(void)
10213{
10214 p_cds_contextType p_cds_context;
10215
10216 p_cds_context = cds_get_global_context();
10217 if (!p_cds_context) {
10218 hdd_err("cds context is NULL");
10219 return;
10220 }
10221
10222 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10223}
10224
Mohit Khannaf8f96822017-05-17 17:11:59 -070010225void hdd_dp_trace_init(struct hdd_config *config)
10226{
10227
10228 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10229 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10230 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10231 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10232 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10233 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10234 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010235 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010236
10237 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10238 &num_entries, sizeof(config_params));
10239
10240 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010241 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010242 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010243 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010244 else if (bw_compute_interval > 1000) {
10245 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10246 thresh_time_limit = 1;
10247 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010248 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10249
10250 switch (num_entries) {
10251 case 4:
10252 proto_bitmap = config_params[3];
10253 case 3:
10254 verbosity = config_params[2];
10255 case 2:
10256 thresh = config_params[1];
10257 case 1:
10258 live_mode = config_params[0];
10259 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010260 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010261 live_mode, thresh, thresh_time_limit,
10262 verbosity, proto_bitmap);
10263 };
10264
10265 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10266 verbosity, proto_bitmap);
10267
10268}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010269/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010270 * hdd_wlan_startup() - HDD init function
10271 * @dev: Pointer to the underlying device
10272 *
10273 * This is the driver startup code executed once a WLAN device has been detected
10274 *
10275 * Return: 0 for success, < 0 for failure
10276 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010277int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010278{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010279 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010280 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010281 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010282 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010283
10284 ENTER();
10285
Arun Khandavallifae92942016-08-01 13:31:08 +053010286 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010287
10288 if (IS_ERR(hdd_ctx))
10289 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010290
Abhishek Singhe9068f12017-03-31 14:14:52 +053010291 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10292 DEFAULT_PSOC_ID);
10293 if (ret) {
10294 hdd_err("Psoc creation fails!");
10295 QDF_BUG(0);
10296 goto err_hdd_free_context;
10297 }
10298
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010299 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010300#ifdef FEATURE_WLAN_CH_AVOID
10301 mutex_init(&hdd_ctx->avoid_freq_lock);
10302#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010303
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010304 hdd_request_manager_init();
Arun Khandavallifae92942016-08-01 13:31:08 +053010305
Dustin Brown021cecd2017-12-11 13:56:43 -080010306 hdd_driver_memdump_init();
10307
Jeff Johnson957bc272017-02-02 08:54:48 -080010308 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010309 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010310 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010311 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010312 }
10313
Yingying Tang80e15f32016-09-27 18:23:01 +080010314 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010315
Anurag Chouhan6d760662016-02-20 16:05:43 +053010316 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010317
10318 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010319 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010320 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010321 }
10322
Prashanth Bhatta07998752016-04-28 12:35:33 -070010323 ret = hdd_wiphy_init(hdd_ctx);
10324 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010325 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010326 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010327 }
10328
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010329 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010330 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010331
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010332 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010333 goto err_wiphy_unregister;
10334
Kapil Gupta4f0c0c12017-02-07 15:21:15 +053010335 wlan_hdd_init_chan_info(hdd_ctx);
10336
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010337 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010338
Paul Zhangfb02f452017-12-22 11:58:43 +080010339 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10340 if (ret) {
10341 hdd_err("register_netdevice_notifier failed: %d", ret);
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010342 goto err_ipa_cleanup;
Paul Zhangfb02f452017-12-22 11:58:43 +080010343 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010344
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010345 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010346
Jeff Johnson957bc272017-02-02 08:54:48 -080010347 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10348 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010349 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010350 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010351 }
10352
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010353 hdd_release_rtnl_lock();
10354 rtnl_held = false;
10355
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010356 wlan_hdd_update_11n_mode(hdd_ctx->config);
10357
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010358#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010359 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010360 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010361 hdd_skip_acs_scan_timer_handler,
10362 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010363 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010364 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010365 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010366#endif
10367
Prashanth Bhattaab004382016-10-11 16:08:11 -070010368 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010369
Jeff Johnson9afc5012016-09-23 13:56:27 -070010370 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010371
Nirav Shahbd36b062016-07-18 11:12:59 +053010372 if (hdd_ctx->rps)
10373 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010374
Paul Zhangfb02f452017-12-22 11:58:43 +080010375 ret = hdd_register_notifiers(hdd_ctx);
10376 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010377 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010378
Paul Zhangfb02f452017-12-22 11:58:43 +080010379 status = wlansap_global_init();
10380 if (QDF_IS_STATUS_ERROR(status)) {
10381 hdd_unregister_notifiers(hdd_ctx);
10382 goto err_close_adapters;
10383 }
10384
Arun Khandavallifae92942016-08-01 13:31:08 +053010385 if (hdd_ctx->config->fIsImpsEnabled)
10386 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010387 else
10388 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010389
Mukul Sharma07bd8752017-10-10 16:58:14 +053010390 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010391 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10392 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010393 hdd_prevent_suspend_timeout(
10394 hdd_ctx->config->iface_change_wait_time,
10395 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10396 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010397
Sachin Ahujadddd2632017-03-07 19:07:24 +053010398 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010399 goto success;
10400
Jeff Johnson957bc272017-02-02 08:54:48 -080010401err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010402 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010403
Jeff Johnson46bde382017-02-01 15:31:16 -080010404err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010405 if (rtnl_held)
10406 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010407
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010408 unregister_netdevice_notifier(&hdd_netdev_notifier);
10409
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010410err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010411 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010412
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010413err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010414 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010415
Arun Khandavallifae92942016-08-01 13:31:08 +053010416err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010417 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010418
Dustin Brown021cecd2017-12-11 13:56:43 -080010419err_memdump_deinit:
10420 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010421
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010422 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010423 hdd_exit_netlink_services(hdd_ctx);
10424
Dustin Brown20912462017-06-07 13:48:25 -070010425 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10426
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010427err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010428 if (cds_is_fw_down())
10429 hdd_err("Not setting the complete event as fw is down");
10430 else
10431 hdd_start_complete(ret);
10432
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010433 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010434 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010435 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010436
10437success:
10438 EXIT();
10439 return 0;
10440}
10441
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010442/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010443 * hdd_wlan_update_target_info() - update target type info
10444 * @hdd_ctx: HDD context
10445 * @context: hif context
10446 *
10447 * Update target info received from firmware in hdd context
10448 * Return:None
10449 */
10450
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010451void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010452{
10453 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10454
10455 if (!tgt_info) {
10456 hdd_err("Target info is Null");
10457 return;
10458 }
10459
10460 hdd_ctx->target_type = tgt_info->target_type;
10461}
10462
10463/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010464 * hdd_get_nud_stats_cb() - callback api to update the stats
10465 * received from the firmware
10466 * @data: pointer to adapter.
10467 * @rsp: pointer to data received from FW.
10468 *
10469 * This is called when wlan driver received response event for
10470 * get arp stats to firmware.
10471 *
10472 * Return: None
10473 */
10474static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10475{
10476 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10477 struct hdd_nud_stats_context *context;
10478 int status;
10479 struct hdd_adapter *adapter = NULL;
10480
10481 ENTER();
10482
10483 if (!rsp) {
10484 hdd_err("data is null");
10485 return;
10486 }
10487
10488 status = wlan_hdd_validate_context(hdd_ctx);
10489 if (0 != status)
10490 return;
10491
10492 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10493 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10494 hdd_err("Invalid adapter or adapter has invalid magic");
10495 return;
10496 }
10497
10498 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10499 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10500 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10501 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10502 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10503 rsp->out_of_order_arp_rsp_drop_cnt);
10504 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10505 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10506 hdd_notice("rsp->ba_session_establishment_status :%x",
10507 rsp->ba_session_establishment_status);
10508
10509 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10510 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10511 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10512 adapter->dad |= rsp->dad_detected;
10513 adapter->con_status = rsp->connect_status;
10514
10515 spin_lock(&hdd_context_lock);
10516 context = &hdd_ctx->nud_stats_context;
10517 complete(&context->response_event);
10518 spin_unlock(&hdd_context_lock);
10519
10520 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010521}
10522
10523/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010524 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010525 * @hdd_ctx: HDD context
10526 *
10527 * Register the HDD callbacks to CDS/SME.
10528 *
10529 * Return: 0 for success or Error code for failure
10530 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010531int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010532{
10533 QDF_STATUS status;
10534 int ret = 0;
10535
10536 ENTER();
10537
10538 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10539
10540 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10541 hdd_send_oem_data_rsp_msg);
10542
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010543 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10544 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010545 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10546 sme_nan_register_callback(hdd_ctx->hHal,
10547 wlan_hdd_cfg80211_nan_callback);
10548 sme_stats_ext_register_callback(hdd_ctx->hHal,
10549 wlan_hdd_cfg80211_stats_ext_callback);
10550
10551 sme_ext_scan_register_callback(hdd_ctx->hHal,
10552 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010553 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10554 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010555
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010556 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10557 hdd_rssi_threshold_breached);
10558
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010559 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10560
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010561 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10562 wlan_hdd_cfg80211_link_layer_stats_callback);
10563
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010564 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10565
Zhang Qianca38fb12016-12-23 11:10:48 +080010566 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10567 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10568
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010569 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10570 hdd_lost_link_info_cb);
10571 /* print error and not block the startup process */
10572 if (!QDF_IS_STATUS_SUCCESS(status))
10573 hdd_err("set lost link info callback failed");
10574
Poddar, Siddarth34872782017-08-10 14:08:51 +053010575 ret = hdd_register_data_stall_detect_cb();
10576 if (ret) {
10577 hdd_err("Register data stall detect detect callback failed.");
10578 return ret;
10579 }
10580
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010581 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10582
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010583 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010584 hdd_set_connection_in_progress,
10585 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010586
10587 status = sme_congestion_register_callback(hdd_ctx->hHal,
10588 hdd_update_cca_info_cb);
10589 if (!QDF_IS_STATUS_SUCCESS(status))
10590 hdd_err("set congestion callback failed");
10591
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010592 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10593 hdd_bt_activity_cb);
10594 if (!QDF_IS_STATUS_SUCCESS(status))
10595 hdd_err("set bt activity info callback failed");
10596
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010597 EXIT();
10598
10599 return ret;
10600}
10601
10602/**
10603 * hdd_deregister_cb() - De-Register HDD callbacks.
10604 * @hdd_ctx: HDD context
10605 *
10606 * De-Register the HDD callbacks to CDS/SME.
10607 *
10608 * Return: void
10609 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010610void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010611{
10612 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010613 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010614
10615 ENTER();
10616
10617 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10618 if (!QDF_IS_STATUS_SUCCESS(status))
10619 hdd_err("De-register of dcc stats callback failed: %d",
10620 status);
10621
10622 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010623 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10624
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010625 sme_stats_ext_register_callback(hdd_ctx->hHal,
10626 wlan_hdd_cfg80211_stats_ext_callback);
10627
10628 sme_nan_deregister_callback(hdd_ctx->hHal);
10629 status = sme_reset_tsfcb(hdd_ctx->hHal);
10630 if (!QDF_IS_STATUS_SUCCESS(status))
10631 hdd_err("Failed to de-register tsfcb the callback:%d",
10632 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010633
Poddar, Siddarth34872782017-08-10 14:08:51 +053010634 ret = hdd_deregister_data_stall_detect_cb();
10635 if (ret)
10636 hdd_err("Failed to de-register data stall detect event callback");
10637
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010638 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10639 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10640
10641 EXIT();
10642}
10643
10644/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010645 * hdd_softap_sta_deauth() - handle deauth req from HDD
10646 * @adapter: Pointer to the HDD
10647 * @enable: bool value
10648 *
10649 * This to take counter measure to handle deauth req from HDD
10650 *
10651 * Return: None
10652 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010653QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010654 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010655{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010656 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010657
10658 ENTER();
10659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010660 /* Ignore request to deauth bcmc station */
10661 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010662 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010663
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010664 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010665 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10666 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010667
10668 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010669 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010670}
10671
10672/**
10673 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10674 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010675 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010676 *
10677 * This to take counter measure to handle deauth req from HDD
10678 *
10679 * Return: None
10680 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010681void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010682 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010683{
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010684 struct sir_peer_sta_info peer_sta_info;
10685 struct hdd_station_info *stainfo;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010686 ENTER();
10687
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010688 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010689 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010690 return;
10691
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010692 wlan_hdd_get_peer_rssi(adapter, &pDelStaParams->peerMacAddr,
10693 &peer_sta_info);
10694 stainfo = hdd_get_stainfo(adapter->cache_sta_info,
10695 pDelStaParams->peerMacAddr);
10696 if (stainfo) {
10697 stainfo->rssi = peer_sta_info.info[0].rssi;
10698 stainfo->tx_rate = peer_sta_info.info[0].tx_rate;
10699 stainfo->rx_rate = peer_sta_info.info[0].rx_rate;
10700 }
10701
10702 stainfo->reason_code = pDelStaParams->reason_code;
10703
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010704 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010705 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010706}
10707
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010708/**
10709 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10710 * @hdd_ctx: HDD Context
10711 *
10712 * API to find if there is any STA or P2P-Client is connected
10713 *
10714 * Return: true if connected; false otherwise
10715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010716QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010717{
10718 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10719}
10720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010721/**
10722 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10723 * @adapter: HDD adapter pointer
10724 *
10725 * This function loop through each adapter and disable roaming on each STA
10726 * device mode except the input adapter.
10727 *
10728 * Note: On the input adapter roaming is not enabled yet hence no need to
10729 * disable.
10730 *
10731 * Return: None
10732 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010733void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010734{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010735 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010736 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010737
10738 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010739 hdd_ctx->config->isRoamOffloadScanEnabled &&
10740 QDF_STA_MODE == adapter->device_mode &&
10741 policy_mgr_is_sta_active_connection_exists(
10742 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010743 hdd_debug("Connect received on STA session Id(%d)",
10744 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010745 /*
10746 * Loop through adapter and disable roaming for each STA device
10747 * mode except the input adapter.
10748 */
Dustin Brown920397d2017-12-13 16:27:50 -080010749 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010750 if (QDF_STA_MODE == adapterIdx->device_mode &&
10751 adapter->session_id != adapterIdx->session_id) {
10752 hdd_debug("Disable Roaming on session Id(%d)",
10753 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010754 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10755 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010756 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010757 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010758 }
10759 }
10760}
10761
10762/**
10763 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10764 * @adapter: HDD adapter pointer
10765 *
10766 * This function loop through each adapter and enable roaming on each STA
10767 * device mode except the input adapter.
10768 * Note: On the input adapter no need to enable roaming because link got
10769 * disconnected on this.
10770 *
10771 * Return: None
10772 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010773void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010774{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010775 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010776 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010777
10778 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010779 hdd_ctx->config->isRoamOffloadScanEnabled &&
10780 QDF_STA_MODE == adapter->device_mode &&
10781 policy_mgr_is_sta_active_connection_exists(
10782 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010783 hdd_debug("Disconnect received on STA session Id(%d)",
10784 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010785 /*
10786 * Loop through adapter and enable roaming for each STA device
10787 * mode except the input adapter.
10788 */
Dustin Brown920397d2017-12-13 16:27:50 -080010789 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010790 if (QDF_STA_MODE == adapterIdx->device_mode &&
10791 adapter->session_id != adapterIdx->session_id) {
10792 hdd_debug("Enabling Roaming on session Id(%d)",
10793 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010794 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10795 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010796 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010797 REASON_CONNECT);
10798 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010799 }
10800 }
10801}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010802
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010803/**
10804 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10805 * @skb: sk buffer pointer
10806 *
10807 * Sends the bcast message to SVC multicast group with generic nl socket
10808 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10809 *
10810 * Return: None
10811 */
10812static void nl_srv_bcast_svc(struct sk_buff *skb)
10813{
10814#ifdef CNSS_GENL
10815 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10816#else
10817 nl_srv_bcast(skb);
10818#endif
10819}
10820
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010821void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010822{
10823 struct sk_buff *skb;
10824 struct nlmsghdr *nlh;
10825 tAniMsgHdr *ani_hdr;
10826 void *nl_data = NULL;
10827 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010828 struct radio_index_tlv *radio_info;
10829 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010830
10831 if (in_interrupt() || irqs_disabled() || in_atomic())
10832 flags = GFP_ATOMIC;
10833
10834 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10835
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010836 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010837 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010838
10839 nlh = (struct nlmsghdr *)skb->data;
10840 nlh->nlmsg_pid = 0; /* from kernel */
10841 nlh->nlmsg_flags = 0;
10842 nlh->nlmsg_seq = 0;
10843 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10844
10845 ani_hdr = NLMSG_DATA(nlh);
10846 ani_hdr->type = type;
10847
10848 switch (type) {
10849 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010850 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010851 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010852 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010853 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010854 ani_hdr->length = 0;
10855 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010856 break;
10857 case WLAN_SVC_WLAN_STATUS_IND:
10858 case WLAN_SVC_WLAN_VERSION_IND:
10859 case WLAN_SVC_DFS_CAC_START_IND:
10860 case WLAN_SVC_DFS_CAC_END_IND:
10861 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10862 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10863 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010864 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010865 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010866 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010867 ani_hdr->length = len;
10868 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10869 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10870 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010871 break;
10872
10873 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010874 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010875 type);
10876 kfree_skb(skb);
10877 return;
10878 }
10879
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010880 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010881 * Add radio index at the end of the svc event in TLV format
10882 * to maintain the backward compatibility with userspace
10883 * applications.
10884 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010885
10886 tlv_len = 0;
10887
10888 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10889 < WLAN_NL_MAX_PAYLOAD) {
10890 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10891 sizeof(*ani_hdr) + len);
10892 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10893 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10894 radio_info->radio = radio;
10895 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010896 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010897 "Added radio index tlv - radio index %d",
10898 radio_info->radio);
10899 }
10900
10901 nlh->nlmsg_len += tlv_len;
10902 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10903
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010904 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010905}
10906
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010907#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10908void wlan_hdd_auto_shutdown_cb(void)
10909{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010910 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010911
10912 if (!hdd_ctx)
10913 return;
10914
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010915 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010916 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10917 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010918}
10919
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010920void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010921{
Jeff Johnson9d295242017-08-29 14:39:48 -070010922 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010923 bool ap_connected = false, sta_connected = false;
10924 tHalHandle hal_handle;
10925
10926 hal_handle = hdd_ctx->hHal;
10927 if (hal_handle == NULL)
10928 return;
10929
10930 if (hdd_ctx->config->WlanAutoShutdown == 0)
10931 return;
10932
10933 if (enable == false) {
10934 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010935 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010936 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010937 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010938 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010939 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010940 return;
10941 }
10942
10943 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080010944 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
10945 hdd_for_each_adapter(hdd_ctx, adapter) {
10946 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010947 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10948 conn_info.connState ==
10949 eConnectionState_Associated) {
10950 sta_connected = true;
10951 break;
10952 }
10953 }
Dustin Brown920397d2017-12-13 16:27:50 -080010954
10955 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010956 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070010957 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010958 ap_connected = true;
10959 break;
10960 }
10961 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010962 }
10963 }
10964
10965 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010966 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010967 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010968 }
Jeff Johnson68755312017-02-10 11:46:55 -080010969
10970 if (sme_set_auto_shutdown_timer(hal_handle,
10971 hdd_ctx->config->WlanAutoShutdown)
10972 != QDF_STATUS_SUCCESS)
10973 hdd_err("Failed to start wlan auto shutdown timer");
10974 else
10975 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10976 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010977}
10978#endif
10979
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010980struct hdd_adapter *
10981hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10982 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010983{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010984 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010985 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010986
10987 con_sap_adapter = NULL;
10988
Dustin Brown920397d2017-12-13 16:27:50 -080010989 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010990 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10991 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010992 adapter != this_sap_adapter) {
10993 if (check_start_bss) {
10994 if (test_bit(SOFTAP_BSS_STARTED,
10995 &adapter->event_flags)) {
10996 con_sap_adapter = adapter;
10997 break;
10998 }
10999 } else {
11000 con_sap_adapter = adapter;
11001 break;
11002 }
11003 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011004 }
11005
11006 return con_sap_adapter;
11007}
11008
11009#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011010static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011011{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011012 return adapter->device_mode == QDF_STA_MODE ||
11013 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011014}
11015
Jeff Johnson9d295242017-08-29 14:39:48 -070011016static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011017{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011018 return adapter->device_mode == QDF_SAP_MODE ||
11019 adapter->device_mode == QDF_P2P_GO_MODE;
11020}
11021
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011022static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011023{
Dustin Brown920397d2017-12-13 16:27:50 -080011024 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011025
Dustin Brown920397d2017-12-13 16:27:50 -080011026 hdd_for_each_adapter(hdd_ctx, adapter) {
11027 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011028 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11029 conn_info.connState == eConnectionState_Associated) {
11030 return true;
11031 }
11032
Dustin Brown920397d2017-12-13 16:27:50 -080011033 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011034 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011035 return true;
11036 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011037 }
11038
11039 return false;
11040}
11041
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011042static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011043{
11044 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011045
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011046 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011047 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011048 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011049
Dustin Brown5ec6b552017-03-31 12:11:40 -070011050 return is_running;
11051}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011052
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011053static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011054{
11055 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11056 hdd_ctx->bus_bw_timer_running = true;
11057 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11058 hdd_ctx->config->busBandwidthComputeInterval);
11059 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11060}
11061
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011062void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011063{
11064 ENTER();
11065
11066 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11067 hdd_debug("Bandwidth compute timer already started");
11068 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011069 }
11070
Dustin Brown5ec6b552017-03-31 12:11:40 -070011071 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11072
11073 EXIT();
11074}
11075
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011076void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011077{
11078 ENTER();
11079
11080 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11081 hdd_debug("Bandwidth compute timer already started");
11082 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011083 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011084
11085 if (hdd_any_adapter_is_assoc(hdd_ctx))
11086 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11087
11088 EXIT();
11089}
11090
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011091static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011092{
11093 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
11094
11095 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11096 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11097 hdd_ctx->bus_bw_timer_running = false;
11098 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11099
11100 hdd_reset_tcp_delack(hdd_ctx);
11101}
11102
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011103void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011104{
11105 ENTER();
11106
11107 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11108 hdd_debug("Bandwidth compute timer already stopped");
11109 return;
11110 }
11111
11112 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11113
11114 EXIT();
11115}
11116
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011117void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011118{
11119 ENTER();
11120
11121 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11122 hdd_debug("Bandwidth compute timer already stopped");
11123 return;
11124 }
11125
11126 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11127 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11128
11129 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011130}
11131#endif
11132
11133/**
11134 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11135 * and sta's operating channel.
11136 * @sta_adapter: Describe the first argument to foobar.
11137 * @ap_adapter: Describe the second argument to foobar.
11138 * @roam_profile: Roam profile of AP to which STA wants to connect.
11139 * @concurrent_chnl_same: If both SAP and STA channels are same then
11140 * set this flag to true else false.
11141 *
11142 * This function checks the sap's operating channel and sta's operating channel.
11143 * if both are same then it will return false else it will restart the sap in
11144 * sta's channel and return true.
11145 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011146 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011147 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011148QDF_STATUS
11149wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11150 struct hdd_adapter *ap_adapter,
11151 tCsrRoamProfile *roam_profile,
11152 tScanResultHandle *scan_cache,
11153 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011154{
Jeff Johnson87251032017-08-29 13:31:11 -070011155 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011156 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011157 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011158 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011159 *concurrent_chnl_same = true;
11160
11161 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11162 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011163 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011164 scan_cache,
11165 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011166 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011167 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011168 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011169 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011170 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011171 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011172 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011173 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011174 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011175 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011176 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011177 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011178 }
11179 }
11180 } else {
11181 /*
11182 * Lets handle worst case scenario here, Scan cache lookup is
11183 * failed so we have to stop the SAP to avoid any channel
11184 * discrepancy between SAP's channel and STA's channel.
11185 * Return the status as failure so caller function could know
11186 * that scan look up is failed.
11187 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011188 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011189 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011190 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011191 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011192}
11193
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011194/**
11195 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11196 * @ap_adapter: SAP adapter
11197 *
11198 * This function will process the stopping of sap adapter.
11199 *
11200 * Return: None
11201 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011202void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011203{
Jeff Johnson87251032017-08-29 13:31:11 -070011204 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011205 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011206 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011207 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011208
11209 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011210 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011211 return;
11212 }
11213
11214 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11215 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011216 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011217 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011219 mutex_lock(&hdd_ctx->sap_lock);
11220 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011221 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011222 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011223 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011224 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011225 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011226 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011227 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011228 qdf_stop_bss_event,
11229 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011230 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011231 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011232 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011233 return;
11234 }
11235 }
11236 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011237 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11238 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011239 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011240 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011241 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011242 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011243 }
11244 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011245}
11246
11247/**
11248 * wlan_hdd_start_sap() - this function starts bss of SAP.
11249 * @ap_adapter: SAP adapter
11250 *
11251 * This function will process the starting of sap adapter.
11252 *
11253 * Return: None
11254 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011255void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011256{
Jeff Johnson87251032017-08-29 13:31:11 -070011257 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011258 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011259 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011260 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011261 tsap_Config_t *sap_config;
11262
11263 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011264 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011265 return;
11266 }
11267
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011268 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011269 hdd_err("SoftAp role has not been enabled");
11270 return;
11271 }
11272
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011273 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11274 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11275 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011276 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011277
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011278 mutex_lock(&hdd_ctx->sap_lock);
11279 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11280 goto end;
11281
11282 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011283 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011284 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
11285 goto end;
11286 }
11287
Wei Song2f76f642016-11-18 16:32:53 +080011288 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011289 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011290 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011291 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011292 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011293 goto end;
11294
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011295 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011296 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011297 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011298 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011299 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011300 goto end;
11301 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011302 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011303 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011304 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011305 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11306 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011307 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011308 mutex_unlock(&hdd_ctx->sap_lock);
11309
11310 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011311end:
11312 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011313 /* SAP context and beacon cleanup will happen during driver unload
11314 * in hdd_stop_adapter
11315 */
11316 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11317
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011318}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011319
11320/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011321 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11322 * mac scan config
11323 * @status: Status of set antenna mode
11324 *
11325 * Callback on setting the dual mac configuration
11326 *
11327 * Return: None
11328 */
11329void wlan_hdd_soc_set_antenna_mode_cb(
11330 enum set_antenna_mode_status status)
11331{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011332 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011333
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011334 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011335
11336 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11337 if (0 != wlan_hdd_validate_context(hdd_ctx))
11338 return;
11339
11340 /* Signal the completion of set dual mac config */
11341 complete(&hdd_ctx->set_antenna_mode_cmpl);
11342}
11343
11344/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011345 * hdd_get_fw_version() - Get FW version
11346 * @hdd_ctx: pointer to HDD context.
11347 * @major_spid: FW version - major spid.
11348 * @minor_spid: FW version - minor spid
11349 * @ssid: FW version - ssid
11350 * @crmid: FW version - crmid
11351 *
11352 * This function is called to get the firmware build version stored
11353 * as part of the HDD context
11354 *
11355 * Return: None
11356 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011357void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011358 uint32_t *major_spid, uint32_t *minor_spid,
11359 uint32_t *siid, uint32_t *crmid)
11360{
11361 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11362 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11363 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11364 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11365}
11366
11367#ifdef QCA_CONFIG_SMP
11368/**
11369 * wlan_hdd_get_cpu() - get cpu_index
11370 *
11371 * Return: cpu_index
11372 */
11373int wlan_hdd_get_cpu(void)
11374{
11375 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011376
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011377 put_cpu();
11378 return cpu_index;
11379}
11380#endif
11381
11382/**
11383 * hdd_get_fwpath() - get framework path
11384 *
11385 * This function is used to get the string written by
11386 * userspace to start the wlan driver
11387 *
11388 * Return: string
11389 */
11390const char *hdd_get_fwpath(void)
11391{
11392 return fwpath.string;
11393}
11394
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011395static int hdd_qdf_print_init(void)
11396{
11397 int qdf_print_idx;
11398 QDF_STATUS status;
11399
11400 status = qdf_print_setup();
11401 if (status != QDF_STATUS_SUCCESS) {
11402 pr_err("qdf_print_setup failed\n");
11403 return -EINVAL;
11404 }
11405
11406 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11407
11408 if (qdf_print_idx < 0) {
11409 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11410 qdf_print_idx);
11411 return -EINVAL;
11412 }
11413
11414 qdf_set_pidx(qdf_print_idx);
11415
11416 return 0;
11417}
11418
11419static void hdd_qdf_print_deinit(void)
11420{
11421 int qdf_print_idx;
11422
11423 qdf_print_idx = qdf_get_pidx();
11424 qdf_print_ctrl_cleanup(qdf_print_idx);
11425}
11426
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011427/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011428 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011429 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011430 * This function initilizes CDS global context with the help of cds_init. This
11431 * has to be the first function called after probe to get a valid global
11432 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011433 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011434 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011435 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011436int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011437{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011438 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011439 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011440
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011441 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011442 if (QDF_IS_STATUS_ERROR(status)) {
11443 hdd_err("Failed to allocate CDS context");
11444 ret = -ENOMEM;
11445 goto err_out;
11446 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011447
11448 wlan_init_bug_report_lock();
11449
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011450#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11451 wlan_logging_sock_init_svc();
11452#endif
11453
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011454 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11455 (void *)hdd_drv_ops_inactivity_handler, NULL,
11456 QDF_TIMER_TYPE_SW);
11457
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011458 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011459 hdd_qdf_print_init();
11460
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011461 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011462
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011463err_out:
11464 return ret;
11465}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011466
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011467/**
11468 * hdd_deinit() - Deinitialize Driver
11469 *
11470 * This function frees CDS global context with the help of cds_deinit. This
11471 * has to be the last function call in remove callback to free the global
11472 * context.
11473 */
11474void hdd_deinit(void)
11475{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011476 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011477
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011478 wlan_destroy_bug_report_lock();
11479 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011480
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011481 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011482#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11483 wlan_logging_sock_deinit_svc();
11484#endif
11485}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011486
Yue Ma6e7b1a02017-04-03 14:17:46 -070011487#ifdef QCA_WIFI_NAPIER_EMULATION
11488#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11489#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011490#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011491#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011492
Sachin Ahujadddd2632017-03-07 19:07:24 +053011493static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11494 struct file *file)
11495{
11496 return 0;
11497}
11498
11499static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11500 const char __user *user_buf,
11501 size_t count,
11502 loff_t *f_pos)
11503{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011504 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011505 static const char wlan_off_str[] = "OFF";
11506 static const char wlan_on_str[] = "ON";
11507 int ret;
11508 unsigned long rc;
11509
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011510 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011511 pr_err("Failed to read buffer\n");
11512 return -EINVAL;
11513 }
11514
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011515 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011516 pr_debug("Wifi turning off from UI\n");
11517 goto exit;
11518 }
11519
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011520 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011521 pr_err("Invalid value received from framework");
11522 goto exit;
11523 }
11524
11525 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011526 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011527 rc = wait_for_completion_timeout(&wlan_start_comp,
11528 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11529 if (!rc) {
11530 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11531 ret = -EINVAL;
11532 hdd_start_complete(ret);
11533 return ret;
11534 }
11535
11536 hdd_start_complete(0);
11537 }
11538
11539exit:
11540 return count;
11541}
11542
11543
11544const struct file_operations wlan_hdd_state_fops = {
11545 .owner = THIS_MODULE,
11546 .open = wlan_hdd_state_ctrl_param_open,
11547 .write = wlan_hdd_state_ctrl_param_write,
11548};
11549
11550static int wlan_hdd_state_ctrl_param_create(void)
11551{
11552 unsigned int wlan_hdd_state_major = 0;
11553 int ret;
11554 struct device *dev;
11555
11556 device = MKDEV(wlan_hdd_state_major, 0);
11557
11558 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11559 if (ret) {
11560 pr_err("Failed to register qcwlanstate");
11561 goto dev_alloc_err;
11562 }
11563 wlan_hdd_state_major = MAJOR(device);
11564
11565 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11566 if (IS_ERR(class)) {
11567 pr_err("wlan_hdd_state class_create error");
11568 goto class_err;
11569 }
11570
11571 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11572 if (IS_ERR(dev)) {
11573 pr_err("wlan_hdd_statedevice_create error");
11574 goto err_class_destroy;
11575 }
11576
11577 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11578 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11579 if (ret) {
11580 pr_err("Failed to add cdev error");
11581 goto cdev_add_err;
11582 }
11583
11584 pr_info("wlan_hdd_state %s major(%d) initialized",
11585 WLAN_MODULE_NAME, wlan_hdd_state_major);
11586
11587 return 0;
11588
11589cdev_add_err:
11590 device_destroy(class, device);
11591err_class_destroy:
11592 class_destroy(class);
11593class_err:
11594 unregister_chrdev_region(device, dev_num);
11595dev_alloc_err:
11596 return -ENODEV;
11597}
11598
11599static void wlan_hdd_state_ctrl_param_destroy(void)
11600{
11601 cdev_del(&wlan_hdd_state_cdev);
11602 device_destroy(class, device);
11603 class_destroy(class);
11604 unregister_chrdev_region(device, dev_num);
11605
11606 pr_info("Device node unregistered");
11607}
11608
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011609/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011610 * component_init - API to init cld component's
11611 *
11612 * Return: None
11613 */
11614static void component_init(void)
11615{
11616 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011617 disa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011618}
11619
11620/**
11621 * component_deinit - API to deinit cld component's
11622 *
11623 * Return: None
11624 */
11625static void component_deinit(void)
11626{
11627 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011628 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011629}
11630
11631void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11632{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011633 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011634}
11635
11636void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11637{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011638 disa_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011639}
11640
11641/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011642 * __hdd_module_init - Module init helper
11643 *
11644 * Module init helper function used by both module and static driver.
11645 *
11646 * Return: 0 for success, errno on failure
11647 */
11648static int __hdd_module_init(void)
11649{
11650 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011651
Dustin Brown96cd9632017-11-13 12:45:04 -080011652 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011653 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011654 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011655 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011656
Sachin Ahujadddd2632017-03-07 19:07:24 +053011657 ret = wlan_hdd_state_ctrl_param_create();
11658 if (ret) {
11659 pr_err("wlan_hdd_state_create:%x\n", ret);
11660 goto err_dev_state;
11661 }
11662
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011663 pld_init();
11664
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011665 ret = hdd_init();
11666 if (ret) {
11667 pr_err("hdd_init failed %x\n", ret);
11668 goto err_hdd_init;
11669 }
11670
Rajeev Kumar97767a02016-11-30 11:20:40 -080011671 dispatcher_init();
11672
Mukul Sharmad75a6672017-06-22 15:40:53 +053011673 /* Ensure to call post objmgr init */
11674 component_init();
11675
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011676 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011677
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011678 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011679
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011680 ret = wlan_hdd_register_driver();
11681 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011682 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11683 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011684 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011685 }
11686
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011687 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011688
11689 return 0;
11690out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011691 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011692 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011693 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011694 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011695
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011696err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011697 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011698 wlan_hdd_state_ctrl_param_destroy();
11699err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011700 return ret;
11701}
11702
11703/**
11704 * __hdd_module_exit - Module exit helper
11705 *
11706 * Module exit helper function used by both module and static driver.
11707 */
11708static void __hdd_module_exit(void)
11709{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011710
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011711 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11712 QWLAN_VERSIONSTR);
11713
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011714 hdd_wait_for_recovery_completion();
11715
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011716 wlan_hdd_unregister_driver();
11717
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011718 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011719
Mukul Sharmad75a6672017-06-22 15:40:53 +053011720 /* Ensure to call prior to objmgr deinit */
11721 component_deinit();
11722
Rajeev Kumar97767a02016-11-30 11:20:40 -080011723 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011724
11725 hdd_sysfs_destroy_version_interface();
11726
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011727 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011728 pld_deinit();
11729
Sachin Ahujadddd2632017-03-07 19:07:24 +053011730 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011731}
11732
Arun Khandavallifae92942016-08-01 13:31:08 +053011733#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011734/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011735 * wlan_boot_cb() - Wlan boot callback
11736 * @kobj: object whose directory we're creating the link in.
11737 * @attr: attribute the user is interacting with
11738 * @buff: the buffer containing the user data
11739 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011740 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011741 * This callback is invoked when the fs is ready to start the
11742 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011743 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011744 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011745 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011746static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011747 struct kobj_attribute *attr,
11748 const char *buf,
11749 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011750{
Arun Khandavallifae92942016-08-01 13:31:08 +053011751
Arun Khandavallifae92942016-08-01 13:31:08 +053011752 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011753 pr_err("%s: wlan driver already initialized\n", __func__);
11754 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011755 }
11756
Arun Khandavallifae92942016-08-01 13:31:08 +053011757 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011758 pr_err("%s: wlan driver initialization failed\n", __func__);
11759 return -EIO;
11760 }
11761
11762 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011763
11764 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011765}
Arun Khandavallifae92942016-08-01 13:31:08 +053011766
11767/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011768 * hdd_sysfs_cleanup() - cleanup sysfs
11769 *
11770 * Return: None
11771 *
11772 */
11773static void hdd_sysfs_cleanup(void)
11774{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011775 /* remove from group */
11776 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11777 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11778 wlan_loader->attr_group);
11779
11780 /* unlink the object from parent */
11781 kobject_del(wlan_loader->boot_wlan_obj);
11782
11783 /* free the object */
11784 kobject_put(wlan_loader->boot_wlan_obj);
11785
11786 kfree(wlan_loader->attr_group);
11787 kfree(wlan_loader);
11788
11789 wlan_loader = NULL;
11790}
11791
11792/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011793 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11794 * ready
11795 *
11796 * This is creates the syfs entry boot_wlan. Which shall be invoked
11797 * when the filesystem is ready.
11798 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011799 * QDF API cannot be used here since this function is called even before
11800 * initializing WLAN driver.
11801 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011802 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011803 */
11804static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011805{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011806 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011807
11808 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011809 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011810 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011811
11812 wlan_loader->boot_wlan_obj = NULL;
11813 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11814 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011815 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011816 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011817
11818 wlan_loader->loaded_state = 0;
11819 wlan_loader->attr_group->attrs = attrs;
11820
11821 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11822 kernel_kobj);
11823 if (!wlan_loader->boot_wlan_obj) {
11824 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011825 goto error_return;
11826 }
11827
11828 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11829 wlan_loader->attr_group);
11830 if (ret) {
11831 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11832 goto error_return;
11833 }
11834
11835 return 0;
11836
11837error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011838 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011839
11840 return ret;
11841}
11842
11843/**
11844 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11845 *
11846 * Return: 0 on success or errno on failure
11847 */
11848static int wlan_deinit_sysfs(void)
11849{
Arun Khandavallifae92942016-08-01 13:31:08 +053011850 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011851 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011852 return -EINVAL;
11853 }
11854
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011855 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011856 return 0;
11857}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011858
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011859#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011860
11861#ifdef MODULE
11862/**
11863 * __hdd_module_init - Module init helper
11864 *
11865 * Module init helper function used by both module and static driver.
11866 *
11867 * Return: 0 for success, errno on failure
11868 */
11869static int hdd_module_init(void)
11870{
Arun Khandavallifae92942016-08-01 13:31:08 +053011871 if (__hdd_module_init()) {
11872 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011873 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011874 }
11875
Dustin Brownab482ac2017-06-09 17:00:44 -070011876 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011877}
11878#else
11879static int __init hdd_module_init(void)
11880{
11881 int ret = -EINVAL;
11882
11883 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011884 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011885 pr_err("Failed to create sysfs entry for loading wlan");
11886
11887 return ret;
11888}
11889#endif
11890
11891
11892#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011893/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011894 * hdd_module_exit() - Exit function
11895 *
11896 * This is the driver exit point (invoked when module is unloaded using rmmod)
11897 *
11898 * Return: None
11899 */
11900static void __exit hdd_module_exit(void)
11901{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011902 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011903}
Arun Khandavallifae92942016-08-01 13:31:08 +053011904#else
11905static void __exit hdd_module_exit(void)
11906{
11907 __hdd_module_exit();
11908 wlan_deinit_sysfs();
11909}
11910#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011911
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011912static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11913{
11914 return param_set_copystring(kmessage, kp);
11915}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011916
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011917/**
11918 * is_con_mode_valid() check con mode is valid or not
11919 * @mode: global con mode
11920 *
11921 * Return: TRUE on success FALSE on failure
11922 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080011923static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011924{
11925 switch (mode) {
11926 case QDF_GLOBAL_MONITOR_MODE:
11927 case QDF_GLOBAL_FTM_MODE:
11928 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011929 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011930 return true;
11931 default:
11932 return false;
11933 }
11934}
11935
11936/**
11937 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11938 * @mode: global con mode
11939 *
11940 * Return: adapter mode
11941 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011942static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080011943 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011944{
11945
11946 switch (mode) {
11947 case QDF_GLOBAL_MISSION_MODE:
11948 return QDF_STA_MODE;
11949 case QDF_GLOBAL_MONITOR_MODE:
11950 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011951 case QDF_GLOBAL_EPPING_MODE:
11952 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011953 case QDF_GLOBAL_FTM_MODE:
11954 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011955 case QDF_GLOBAL_QVIT_MODE:
11956 return QDF_QVIT_MODE;
11957 default:
11958 return QDF_MAX_NO_OF_MODE;
11959 }
11960}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011961
Dustin Brown27cd9942017-09-27 16:11:44 -070011962static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080011963 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070011964{
11965 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11966 return;
11967
11968 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070011969 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053011970 hdd_info("Release wakelock for monitor mode!");
11971 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
11972 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
11973 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070011974 case QDF_GLOBAL_FTM_MODE:
11975 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11976 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Dustin Browndb2a8be2017-12-20 11:49:56 -080011977 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070011978
Dustin Brown27cd9942017-09-27 16:11:44 -070011979 break;
11980 default:
11981 break;
11982 }
11983}
11984
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011985static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080011986 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011987{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011988 int driver_status;
11989
11990 driver_status = hdd_ctx->driver_status;
11991
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011992 switch (curr_mode) {
11993 case QDF_GLOBAL_MISSION_MODE:
11994 case QDF_GLOBAL_MONITOR_MODE:
11995 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011996 hdd_deinit_all_adapters(hdd_ctx, false);
11997 hdd_close_all_adapters(hdd_ctx, false);
11998 break;
11999 case QDF_GLOBAL_EPPING_MODE:
12000 epping_disable();
12001 epping_close();
12002 break;
12003 default:
12004 return;
12005 }
12006}
12007
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012008static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012009 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012010{
Jeff Johnson9d295242017-08-29 14:39:48 -070012011 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012012 int ret = 0;
12013 bool rtnl_held;
12014 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12015 QDF_STATUS status;
12016
12017 if (!qdf_dev) {
12018 hdd_err("qdf device context is Null return!");
12019 return -EINVAL;
12020 }
12021
12022 rtnl_held = hdd_hold_rtnl_lock();
12023 switch (mode) {
12024 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012025 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12026 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012027 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012028 break;
12029 case QDF_GLOBAL_FTM_MODE:
12030 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12031 wlan_hdd_get_intf_addr(hdd_ctx),
12032 NET_NAME_UNKNOWN, rtnl_held);
12033 if (adapter == NULL)
12034 ret = -EINVAL;
12035 break;
12036 case QDF_GLOBAL_MONITOR_MODE:
12037 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12038 wlan_hdd_get_intf_addr(hdd_ctx),
12039 NET_NAME_UNKNOWN, rtnl_held);
12040 if (adapter == NULL)
12041 ret = -EINVAL;
12042 break;
12043 case QDF_GLOBAL_EPPING_MODE:
12044 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012045 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012046 hdd_err("Failed to open in eeping mode: %d", status);
12047 ret = -EINVAL;
12048 break;
12049 }
12050 ret = epping_enable(qdf_dev->dev);
12051 if (ret) {
12052 hdd_err("Failed to enable in epping mode : %d", ret);
12053 epping_close();
12054 }
12055 break;
12056 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012057 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012058 ret = -ENOTSUPP;
12059 break;
12060 }
12061 hdd_release_rtnl_lock();
12062 rtnl_held = false;
12063 return ret;
12064}
12065
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012066/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012067 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012068 * @kmessage: con mode name on which driver to be bring up
12069 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012070 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012071 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012072 * This function is invoked when user updates con mode using sys entry,
12073 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012074 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012075 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012076 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012077static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012078 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012079{
12080 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012081 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012082 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012083 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012084 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012085
Dustin Brownab6029b2017-05-24 13:04:19 -070012086 hdd_info("con_mode handler: %s", kmessage);
12087
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012088 ret = wlan_hdd_validate_context(hdd_ctx);
12089 if (ret)
12090 return ret;
12091
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012092 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012093
Dustin Brown20024e32018-01-03 12:34:58 -080012094 ret = kstrtoint(kmessage, 0, &new_con_mode);
12095 if (ret) {
12096 hdd_err("Failed to parse con_mode '%s'", kmessage);
12097 goto reset_flags;
12098 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012099
Dustin Brown20024e32018-01-03 12:34:58 -080012100 if (!is_con_mode_valid(new_con_mode)) {
12101 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012102 ret = -EINVAL;
12103 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012104 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012105
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012106 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012107 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012108 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012109 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012110 ret = 0;
12111 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012112 }
12113
Sourav Mohapatra3bc5e982017-11-24 15:53:49 +053012114 if (!cds_wait_for_external_threads_completion(__func__))
12115 hdd_warn("Waiting for monitor mode: External threads are active");
12116
Dustin Brown27cd9942017-09-27 16:11:44 -070012117 /* ensure adapters are stopped */
12118 hdd_stop_present_mode(hdd_ctx, curr_mode);
12119
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012120 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012121 if (ret) {
12122 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012123 goto reset_flags;
12124 }
12125
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012126 /* Cleanup present mode before switching to new mode */
12127 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12128
Dustin Brown20024e32018-01-03 12:34:58 -080012129 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012130
12131 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012132 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012133 if (ret) {
12134 hdd_err("Failed to register for new mode");
12135 goto reset_flags;
12136 }
12137
Dustin Brown20024e32018-01-03 12:34:58 -080012138 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012139 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12140 hdd_err("invalid adapter");
12141 ret = -EINVAL;
12142 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012143 }
12144
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012145 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012146 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012147 hdd_err("Failed to get adapter:%d", adapter_mode);
12148 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012149 }
12150
12151 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12152 if (ret) {
12153 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012154 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012155 }
12156
Dustin Brown20024e32018-01-03 12:34:58 -080012157 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012158 if (hdd_start_adapter(adapter)) {
12159 hdd_err("Failed to start %s adapter", kmessage);
12160 ret = -EINVAL;
12161 goto reset_flags;
12162 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012163
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012164 hdd_info("Acquire wakelock for monitor mode!");
12165 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12166 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12167 }
12168
Dustin Brown20024e32018-01-03 12:34:58 -080012169 /* con_mode is a global module parameter */
12170 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012171 hdd_info("Mode successfully changed to %s", kmessage);
12172 ret = 0;
12173
12174reset_flags:
12175 cds_set_load_in_progress(false);
Dustin Brown20024e32018-01-03 12:34:58 -080012176
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012177 return ret;
12178}
12179
12180
12181static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12182{
12183 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012184 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012185
12186 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12187 ret = wlan_hdd_validate_context(hdd_ctx);
12188 if (ret)
12189 return ret;
12190
12191 cds_ssr_protect(__func__);
12192 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12193 cds_ssr_unprotect(__func__);
12194
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012195 return ret;
12196}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012197
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012198static int con_mode_handler_ftm(const char *kmessage,
12199 struct kernel_param *kp)
12200{
12201 int ret;
12202
12203 ret = param_set_int(kmessage, kp);
12204
12205 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12206 pr_err("Only FTM mode supported!");
12207 return -ENOTSUPP;
12208 }
12209
12210 hdd_set_conparam(con_mode_ftm);
12211 con_mode = con_mode_ftm;
12212
12213 return ret;
12214}
12215
Ravi Joshia307f632017-07-17 23:41:41 -070012216static int con_mode_handler_monitor(const char *kmessage,
12217 struct kernel_param *kp)
12218{
12219 int ret;
12220
12221 ret = param_set_int(kmessage, kp);
12222
12223 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12224 pr_err("Only Monitor mode supported!");
12225 return -ENOTSUPP;
12226 }
12227
12228 hdd_set_conparam(con_mode_monitor);
12229 con_mode = con_mode_monitor;
12230
12231 return ret;
12232}
12233
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012234/**
12235 * hdd_get_conparam() - driver exit point
12236 *
12237 * This is the driver exit point (invoked when module is unloaded using rmmod)
12238 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012239 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012240 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012241enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012242{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012243 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012244}
12245
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012246void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012247{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012248 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012249}
12250
Komal Seelamc11bb222016-01-27 18:57:10 +053012251/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012252 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12253 * @hdd_ctx: HDD context
12254 *
12255 * Cleans up the pre cac interface, if it exists
12256 *
12257 * Return: None
12258 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012259void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012260{
12261 uint8_t session_id;
12262 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012263 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012264
12265 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12266 if (QDF_IS_STATUS_ERROR(status)) {
12267 hdd_err("failed to get pre cac vdev id");
12268 return;
12269 }
12270
12271 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12272 if (!precac_adapter) {
12273 hdd_err("invalid pre cac adapater");
12274 return;
12275 }
12276
12277 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12278 wlan_hdd_sap_pre_cac_failure,
12279 (void *)precac_adapter);
12280 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12281
12282}
12283
12284/**
Komal Seelamec702b02016-02-24 18:42:16 +053012285 * hdd_update_ol_config - API to update ol configuration parameters
12286 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012287 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012288 * Return: void
12289 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012290static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012291{
Komal Seelamec702b02016-02-24 18:42:16 +053012292 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012293 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012294
Komal Seelamec702b02016-02-24 18:42:16 +053012295 if (!ol_ctx)
12296 return;
12297
12298 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12299 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12300 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12301 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012302 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012303
12304 ol_init_ini_config(ol_ctx, &cfg);
12305}
12306
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012307#ifdef FEATURE_RUNTIME_PM
12308/**
12309 * hdd_populate_runtime_cfg() - populate runtime configuration
12310 * @hdd_ctx: hdd context
12311 * @cfg: pointer to the configuration memory being populated
12312 *
12313 * Return: void
12314 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012315static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012316 struct hif_config_info *cfg)
12317{
12318 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12319 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12320}
12321#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012322static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012323 struct hif_config_info *cfg)
12324{
12325}
12326#endif
12327
Komal Seelamec702b02016-02-24 18:42:16 +053012328/**
12329 * hdd_update_hif_config - API to update HIF configuration parameters
12330 * @hdd_ctx: HDD Context
12331 *
12332 * Return: void
12333 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012334static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012335{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012336 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012337 struct hif_config_info cfg;
12338
12339 if (!scn)
12340 return;
12341
12342 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012343 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012344 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012345
12346 if (hdd_ctx->config->prevent_link_down)
12347 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012348}
12349
12350/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012351 * hdd_update_dp_config() - Propagate config parameters to Lithium
12352 * datapath
12353 * @hdd_ctx: HDD Context
12354 *
12355 * Return: 0 for success/errno for failure
12356 */
12357static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12358{
12359 struct cdp_config_params params;
12360 QDF_STATUS status;
12361
12362 params.tso_enable = hdd_ctx->config->tso_enable;
12363 params.lro_enable = hdd_ctx->config->lro_enable;
12364#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12365 params.tx_flow_stop_queue_threshold =
12366 hdd_ctx->config->TxFlowStopQueueThreshold;
12367 params.tx_flow_start_queue_offset =
12368 hdd_ctx->config->TxFlowStartQueueOffset;
12369#endif
12370 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12371 params.napi_enable = hdd_ctx->napi_enable;
12372 params.tcp_udp_checksumoffload =
12373 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12374
12375 status = cdp_update_config_parameters(
12376 cds_get_context(QDF_MODULE_ID_SOC),
12377 &params);
12378 if (status) {
12379 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12380 "%s: Failed to attach config parameters", __func__);
12381 return status;
12382 }
12383
12384 return 0;
12385}
12386
12387/**
Komal Seelamec702b02016-02-24 18:42:16 +053012388 * hdd_update_config() - Initialize driver per module ini parameters
12389 * @hdd_ctx: HDD Context
12390 *
12391 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012392 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012393 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012394int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012395{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012396 int ret;
12397
Komal Seelamec702b02016-02-24 18:42:16 +053012398 hdd_update_ol_config(hdd_ctx);
12399 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012400 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12401 ret = hdd_update_cds_config_ftm(hdd_ctx);
12402 else
12403 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012404 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012405
12406 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012407}
12408
Mukul Sharma9d797a02017-01-05 20:26:03 +053012409#ifdef FEATURE_WLAN_RA_FILTERING
12410/**
12411 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12412 * @psoc_cfg: pmo psoc Configuration
12413 * @hdd_ctx: Pointer to hdd context
12414 *
12415 * Return: none
12416 */
12417static inline void hdd_ra_populate_pmo_config(
12418 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012419 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012420{
12421 psoc_cfg->ra_ratelimit_interval =
12422 hdd_ctx->config->RArateLimitInterval;
12423 psoc_cfg->ra_ratelimit_enable =
12424 hdd_ctx->config->IsRArateLimitEnabled;
12425}
12426#else
12427static inline void hdd_ra_populate_pmo_config(
12428 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012429 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012430{
12431}
12432#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012433
Mukul Sharma9d797a02017-01-05 20:26:03 +053012434/**
12435 * hdd_update_pmo_config - API to update pmo configuration parameters
12436 * @hdd_ctx: HDD context
12437 *
12438 * Return: void
12439 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012440static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012441{
12442 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12443 struct pmo_psoc_cfg psoc_cfg;
12444 QDF_STATUS status;
12445
12446 /*
12447 * Value of hdd_ctx->wowEnable can be,
12448 * 0 - Disable both magic pattern match and pattern byte match.
12449 * 1 - Enable magic pattern match on all interfaces.
12450 * 2 - Enable pattern byte match on all interfaces.
12451 * 3 - Enable both magic patter and pattern byte match on
12452 * all interfaces.
12453 */
12454 psoc_cfg.magic_ptrn_enable =
12455 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12456 psoc_cfg.ptrn_match_enable_all_vdev =
12457 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012458 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12459 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012460 psoc_cfg.bpf_enable =
12461 hdd_ctx->config->bpf_packet_filter_enable;
12462 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012463 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012464 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12465 if (hdd_ctx->config->fhostNSOffload)
12466 psoc_cfg.ns_offload_enable_dynamic = true;
12467 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12468 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12469 psoc_cfg.active_mode_offload =
12470 hdd_ctx->config->active_mode_offload;
12471 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012472 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012473 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012474 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12475 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12476 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12477 psoc_cfg.power_save_mode =
12478 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012479 psoc_cfg.auto_power_save_fail_mode =
12480 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012481
12482 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012483 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12484 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012485 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012486 if (status != QDF_STATUS_SUCCESS) {
12487 hdd_err("failed pmo psoc configuration");
12488 return -EINVAL;
12489 }
12490
12491 return 0;
12492}
12493
Abhishek Singhb20db962017-03-03 21:28:46 +053012494#ifdef FEATURE_WLAN_SCAN_PNO
12495static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12496 struct hdd_config *cfg)
12497{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012498 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12499
Abhishek Singhb20db962017-03-03 21:28:46 +053012500 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12501 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12502 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12503 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12504 pno_cfg->channel_prediction_full_scan =
12505 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012506 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12507 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12508 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12509 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012510}
12511#else
12512static inline void
12513hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012514 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012515{
Abhishek Singhb20db962017-03-03 21:28:46 +053012516}
12517#endif
12518
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012519void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12520 struct hdd_config *cfg)
12521{
12522 uint8_t i = 0;
12523
12524 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12525 if (!ie_whitelist->white_list)
12526 return;
12527
12528 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12529 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12530 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12531 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12532 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12533 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12534 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12535 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12536
12537 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12538 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12539 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12540}
12541
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012542uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12543{
12544 uint8_t i, score;
12545
12546 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12547 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12548 if (score > MAX_INDEX_SCORE)
12549 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12550 MAX_INDEX_SCORE, i);
12551 }
12552
12553 return per_index_score;
12554}
12555
12556/**
12557 * hdd_update_score_config - API to update candidate scoring related params
12558 * configuration parameters
12559 * @score_config: score config to update
12560 * @cfg: config params
12561 *
12562 * Return: 0 if success else err
12563 */
12564static void hdd_update_score_config(
12565 struct scoring_config *score_config, struct hdd_config *cfg)
12566{
12567 int total_weight;
12568
12569 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12570 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12571 score_config->weight_cfg.vht_caps_weightage =
12572 cfg->vht_caps_weightage;
12573 score_config->weight_cfg.he_caps_weightage =
12574 cfg->he_caps_weightage;
12575 score_config->weight_cfg.chan_width_weightage =
12576 cfg->chan_width_weightage;
12577 score_config->weight_cfg.chan_band_weightage =
12578 cfg->chan_band_weightage;
12579 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12580 score_config->weight_cfg.beamforming_cap_weightage =
12581 cfg->beamforming_cap_weightage;
12582 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12583 score_config->weight_cfg.channel_congestion_weightage =
12584 cfg->channel_congestion_weightage;
12585 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12586
12587 total_weight = score_config->weight_cfg.rssi_weightage +
12588 score_config->weight_cfg.ht_caps_weightage +
12589 score_config->weight_cfg.vht_caps_weightage +
12590 score_config->weight_cfg.he_caps_weightage +
12591 score_config->weight_cfg.chan_width_weightage +
12592 score_config->weight_cfg.chan_band_weightage +
12593 score_config->weight_cfg.nss_weightage +
12594 score_config->weight_cfg.beamforming_cap_weightage +
12595 score_config->weight_cfg.pcl_weightage +
12596 score_config->weight_cfg.channel_congestion_weightage +
12597 score_config->weight_cfg.oce_wan_weightage;
12598
12599 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12600 hdd_err("total weight is greater than %d fallback to default values",
12601 BEST_CANDIDATE_MAX_WEIGHT);
12602
12603 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12604 score_config->weight_cfg.ht_caps_weightage =
12605 HT_CAPABILITY_WEIGHTAGE;
12606 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12607 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12608 score_config->weight_cfg.chan_width_weightage =
12609 CHAN_WIDTH_WEIGHTAGE;
12610 score_config->weight_cfg.chan_band_weightage =
12611 CHAN_BAND_WEIGHTAGE;
12612 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12613 score_config->weight_cfg.beamforming_cap_weightage =
12614 BEAMFORMING_CAP_WEIGHTAGE;
12615 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12616 score_config->weight_cfg.channel_congestion_weightage =
12617 CHANNEL_CONGESTION_WEIGHTAGE;
12618 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12619 }
12620
12621 score_config->bandwidth_weight_per_index =
12622 hdd_limit_max_per_index_score(
12623 cfg->bandwidth_weight_per_index);
12624 score_config->nss_weight_per_index =
12625 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12626 score_config->band_weight_per_index =
12627 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12628
12629 score_config->rssi_score.best_rssi_threshold =
12630 cfg->best_rssi_threshold;
12631 score_config->rssi_score.good_rssi_threshold =
12632 cfg->good_rssi_threshold;
12633 score_config->rssi_score.bad_rssi_threshold =
12634 cfg->bad_rssi_threshold;
12635 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12636 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12637 score_config->rssi_score.good_rssi_bucket_size =
12638 cfg->good_rssi_bucket_size;
12639 score_config->rssi_score.bad_rssi_bucket_size =
12640 cfg->bad_rssi_bucket_size;
12641 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12642 cfg->rssi_pref_5g_rssi_thresh;
12643
12644 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12645 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12646 hdd_limit_max_per_index_score(
12647 cfg->esp_qbss_score_slots3_to_0);
12648 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12649 hdd_limit_max_per_index_score(
12650 cfg->esp_qbss_score_slots7_to_4);
12651 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12652 hdd_limit_max_per_index_score(
12653 cfg->esp_qbss_score_slots11_to_8);
12654 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12655 hdd_limit_max_per_index_score(
12656 cfg->esp_qbss_score_slots15_to_12);
12657
12658 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12659 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12660 hdd_limit_max_per_index_score(
12661 cfg->oce_wan_score_slots3_to_0);
12662 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12663 hdd_limit_max_per_index_score(
12664 cfg->oce_wan_score_slots7_to_4);
12665 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12666 hdd_limit_max_per_index_score(
12667 cfg->oce_wan_score_slots11_to_8);
12668 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12669 hdd_limit_max_per_index_score(
12670 cfg->oce_wan_score_slots15_to_12);
12671
12672
12673 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12674 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12675 score_config->nss = cfg->enable2x2 ? 2 : 1;
12676
12677 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12678 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12679 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12680 score_config->he_cap = 1;
12681
12682 if (score_config->he_cap ||
12683 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12684 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12685 score_config->vht_cap = 1;
12686
12687 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12688 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12689 score_config->ht_cap = 1;
12690
12691 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12692 score_config->vht_24G_cap = 1;
12693
12694 if (cfg->enableTxBF)
12695 score_config->beamformee_cap = 1;
12696
12697}
12698
Abhishek Singh257a9482017-03-06 16:52:39 +053012699/**
12700 * hdd_update_scan_config - API to update scan configuration parameters
12701 * @hdd_ctx: HDD context
12702 *
12703 * Return: 0 if success else err
12704 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012705static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012706{
12707 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12708 struct scan_user_cfg scan_cfg;
12709 struct hdd_config *cfg = hdd_ctx->config;
12710 QDF_STATUS status;
12711
12712 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12713 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12714 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12715 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12716 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12717 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12718 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012719 /* convert to ms */
12720 scan_cfg.scan_cache_aging_time =
12721 cfg->scanAgingTimeout * 1000;
12722 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12723 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12724 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12725 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012726 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012727 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012728 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12729 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012730 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012731 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012732
Abhishek Singhb20db962017-03-03 21:28:46 +053012733 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012734 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012735 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012736
Abhishek Singh257a9482017-03-06 16:52:39 +053012737 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12738 if (status != QDF_STATUS_SUCCESS) {
12739 hdd_err("failed pmo psoc configuration");
12740 return -EINVAL;
12741 }
12742
12743 return 0;
12744}
Abhishek Singh257a9482017-03-06 16:52:39 +053012745
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012746int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012747{
12748 int ret;
12749
12750 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012751 if (ret)
12752 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012753
Abhishek Singh257a9482017-03-06 16:52:39 +053012754 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012755 if (ret)
12756 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012757
Frank Liud4b2fa02017-03-29 11:46:48 +080012758 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012759 if (ret)
12760 return ret;
12761
12762 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012763
12764 return ret;
12765}
12766
Agrawal Ashish65634612016-08-18 13:24:32 +053012767/**
12768 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12769 * @mode : cfg80211 DFS mode
12770 *
12771 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12772 */
12773enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12774{
12775 switch (mode) {
12776 case DFS_MODE_ENABLE:
12777 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012778 case DFS_MODE_DISABLE:
12779 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012780 case DFS_MODE_DEPRIORITIZE:
12781 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012782 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012783 hdd_debug("ACS dfs mode is NONE");
12784 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012785 }
12786}
12787
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012788/**
12789 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12790 * @hddctx: pointer to hdd context
12791 * @set_value: enable/disable
12792 *
12793 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12794 * Host(even though it is duplicate). When Host send vendor command
12795 * disable,FW doesn't perform any action. Whenever any change in
12796 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12797 *
12798 * return - 0 on success, appropriate error values on failure.
12799 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012800int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012801{
12802 QDF_STATUS status;
12803
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012804 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012805 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012806
12807 if (!hddctx->config->goptimize_chan_avoid_event) {
12808 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12809 return -EINVAL;
12810 }
12811
12812 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12813 if (!QDF_IS_STATUS_SUCCESS(status)) {
12814 hdd_err("Failed to send chan avoid command to SME");
12815 return -EINVAL;
12816 }
12817 return 0;
12818}
Agrawal Ashish65634612016-08-18 13:24:32 +053012819
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012820/**
12821 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12822 * @value: value to set
12823 *
12824 * This function will set the passed value to roaming in progress flag.
12825 *
12826 * Return: None
12827 */
12828void hdd_set_roaming_in_progress(bool value)
12829{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012830 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012831
12832 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12833 if (!hdd_ctx) {
12834 hdd_err("HDD context is NULL");
12835 return;
12836 }
12837
12838 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012839 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012840}
12841
12842/**
12843 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012844 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012845 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012846 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012847 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012848bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012849{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012850 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012851 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012852
12853 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12854 if (!hdd_ctx) {
12855 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012856 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012857 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012858 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12859 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012860 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12861 hdd_ctx->roaming_in_progress);
12862
12863 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012864}
12865
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012866/**
12867 * hdd_is_connection_in_progress() - check if connection is in
12868 * progress
12869 * @session_id: session id
12870 * @reason: scan reject reason
12871 *
12872 * Go through each adapter and check if Connection is in progress
12873 *
12874 * Return: true if connection is in progress else false
12875 */
12876bool hdd_is_connection_in_progress(uint8_t *session_id,
12877 enum scan_reject_states *reason)
12878{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012879 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012880 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012881 uint8_t sta_id = 0;
12882 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012883 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012884
12885 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12886 if (!hdd_ctx) {
12887 hdd_err("HDD context is NULL");
12888 return false;
12889 }
12890
Dustin Brown920397d2017-12-13 16:27:50 -080012891 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012892 hdd_info("Adapter with device mode %s(%d) exists",
12893 hdd_device_mode_to_string(adapter->device_mode),
12894 adapter->device_mode);
12895 if (((QDF_STA_MODE == adapter->device_mode)
12896 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12897 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12898 && (eConnectionState_Connecting ==
12899 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12900 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012901 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012902 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012903 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012904 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012905 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012906 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012907 }
12908 return true;
12909 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012910 /*
12911 * sme_neighbor_middle_of_roaming is for LFR2
12912 * hdd_is_roaming_in_progress is for LFR3
12913 */
12914 if (((QDF_STA_MODE == adapter->device_mode) &&
12915 sme_neighbor_middle_of_roaming(
12916 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012917 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012918 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012919 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012920 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012921 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012922 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012923 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012924 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012925 }
12926 return true;
12927 }
12928 if ((QDF_STA_MODE == adapter->device_mode) ||
12929 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12930 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12931 hdd_sta_ctx =
12932 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12933 if ((eConnectionState_Associated ==
12934 hdd_sta_ctx->conn_info.connState)
12935 && (false ==
12936 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12937 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070012938 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012939 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012940 " is in middle of WPS/EAPOL exchange.",
12941 MAC_ADDR_ARRAY(sta_mac));
12942 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012943 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012944 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012945 }
12946 return true;
12947 }
12948 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12949 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12950 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12951 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012952 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012953 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012954 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012955 continue;
12956
12957 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012958 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012959 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012960 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012961 " of SAP/GO is in middle of WPS/EAPOL exchange",
12962 MAC_ADDR_ARRAY(sta_mac));
12963 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012964 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012965 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012966 }
12967 return true;
12968 }
12969 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012970 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012971 return true;
12972 }
12973 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012974 }
Dustin Brown920397d2017-12-13 16:27:50 -080012975
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012976 return false;
12977}
12978
12979/**
12980 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012981 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012982 *
12983 * Return: None
12984 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012985void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012986{
Jeff Johnson87251032017-08-29 13:31:11 -070012987 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012988 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012989 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012990 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012991 tsap_Config_t *sap_config;
12992 void *sap_ctx;
12993
12994 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070012995 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012996 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012997
12998 mutex_lock(&hdd_ctx->sap_lock);
12999 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13000 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013001 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13002 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13003 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13004 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013005 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013006 qdf_stop_bss_event,
13007 SME_CMD_TIMEOUT_VALUE);
13008
13009 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013010 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013011 goto end;
13012 }
13013 }
13014 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013015 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013016 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013017 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013018
13019 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013020 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013021 wlansap_reset_sap_config_add_ie(sap_config,
13022 eUPDATE_IE_ALL);
13023 goto end;
13024 }
13025
13026 qdf_event_reset(&hostapd_state->qdf_event);
13027 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13028 sap_config,
13029 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013030 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013031 wlansap_reset_sap_config_add_ie(sap_config,
13032 eUPDATE_IE_ALL);
13033 goto end;
13034 }
13035
Jeff Johnson6867ec32017-09-29 20:30:20 -070013036 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013037 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013038 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013039 SME_CMD_TIMEOUT_VALUE);
13040 wlansap_reset_sap_config_add_ie(sap_config,
13041 eUPDATE_IE_ALL);
13042 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013043 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013044 goto end;
13045 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013046 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013047 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070013048 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013049 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13050 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013051 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013052 }
13053end:
13054 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013055}
13056
13057/**
13058 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13059 * with non dfs acs
13060 *
13061 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13062 *
13063 * Return: None
13064 */
13065void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13066{
Jeff Johnson9d295242017-08-29 14:39:48 -070013067 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013068 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013069 cds_context_type *cds_ctx;
13070
13071 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13072 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013073 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013074 return;
13075 }
13076
13077 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13078 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013079 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013080 return;
13081 }
13082
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013083 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13084 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013085 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013086 return;
13087 }
13088
13089 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013090 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13091 &ap_adapter->event_flags) &&
13092 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013093 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013094
Jeff Johnson6867ec32017-09-29 20:30:20 -070013095 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013096 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013097 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013098 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013099 acs_cfg.acs_mode = true;
13100
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013101 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013102 }
13103}
13104
13105/**
13106 * hdd_set_connection_in_progress() - to set the connection in
13107 * progress flag
13108 * @value: value to set
13109 *
13110 * This function will set the passed value to connection in progress flag.
13111 * If value is previously being set to true then no need to set it again.
13112 *
13113 * Return: true if value is being set correctly and false otherwise.
13114 */
13115bool hdd_set_connection_in_progress(bool value)
13116{
13117 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013118 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013119
13120 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13121 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013122 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013123 return false;
13124 }
13125
13126 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13127 /*
13128 * if the value is set to true previously and if someone is
13129 * trying to make it true again then it could be some race
13130 * condition being triggered. Avoid this situation by returning
13131 * false
13132 */
13133 if (hdd_ctx->connection_in_progress && value)
13134 status = false;
13135 else
13136 hdd_ctx->connection_in_progress = value;
13137 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13138 return status;
13139}
13140
Jeff Johnson9d295242017-08-29 14:39:48 -070013141int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013142{
13143 if (!adapter) {
13144 hdd_err("Invalid adapter");
13145 return -EINVAL;
13146 }
13147 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013148 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013149 WMA_VDEV_MCC_SET_TIME_QUOTA,
13150 set_value, VDEV_CMD);
13151 return 0;
13152
13153}
13154
Jeff Johnson9d295242017-08-29 14:39:48 -070013155int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013156{
13157 if (!adapter) {
13158 hdd_err("Invalid adapter");
13159 return -EINVAL;
13160 }
13161
13162 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013163 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013164 WMA_VDEV_MCC_SET_TIME_LATENCY,
13165 set_value, VDEV_CMD);
13166 return 0;
13167}
13168
Jeff Johnson9d295242017-08-29 14:39:48 -070013169struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013170 *psoc, uint8_t vdev_id)
13171{
Jeff Johnson9d295242017-08-29 14:39:48 -070013172 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013173 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013174
13175 /*
13176 * Currently PSOC is not being used. But this logic will
13177 * change once we have the converged implementation of
13178 * HDD context per PSOC in place. This would break if
13179 * multiple vdev objects reuse the vdev id.
13180 */
13181 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13182 if (!adapter)
13183 hdd_err("Get adapter by vdev id failed");
13184
13185 return adapter;
13186}
13187
Jeff Johnson9d295242017-08-29 14:39:48 -070013188int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013189 int8_t *rssi, int8_t *snr)
13190{
13191 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070013192 struct hdd_wext_state *wext_state =
13193 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013194 tCsrRoamProfile *profile = &wext_state->roamProfile;
13195
13196 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
13197 profile, bssid, rssi, snr);
13198 if (QDF_STATUS_SUCCESS != status) {
13199 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13200 return -EINVAL;
13201 }
13202
13203 return 0;
13204}
13205
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013206/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013207 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13208 * @adapter - HDD adapter
13209 * @tos - type of service
13210 * @status - status of the traffic
13211 *
13212 * Return: 0 on success and non zero value on failure
13213 */
13214
13215int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13216 bool is_tos_active)
13217{
13218 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013219 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013220 uint32_t max_off_chan_time = 0;
13221 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013222 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013223 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013224
13225 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13226 ret = wlan_hdd_validate_context(hdd_ctx);
13227
13228 if (ret < 0) {
13229 hdd_err("failed to set limit off chan params");
13230 return ret;
13231 }
13232
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013233 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13234
13235 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013236 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013237 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013238 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013239
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013240 if (adapter->active_ac) {
13241 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013242 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013243 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13244 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13245 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013246 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013247 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013248 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13249 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13250 PM_LATENCY);
13251 } else {
13252 /*ignore this command if only BE/BK is active */
13253 is_tos_active = false;
13254 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13255 hdd_ctx->config->conc_system_pref);
13256 }
13257 } else {
13258 /* No active tos */
13259 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13260 hdd_ctx->config->conc_system_pref);
13261 }
13262
Jeff Johnson1b780e42017-10-31 14:11:45 -070013263 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013264 is_tos_active, max_off_chan_time,
13265 hdd_ctx->config->nRestTimeConc, true);
13266 if (!QDF_IS_STATUS_SUCCESS(status)) {
13267 hdd_err("failed to set limit off chan params");
13268 ret = -EINVAL;
13269 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013270
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013271 return ret;
13272}
13273
13274/**
13275 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13276 * @adapter - HDD adapter
13277 *
13278 * Return: 0 on success and non zero value on failure
13279 */
13280int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13281{
13282 struct hdd_context *hdd_ctx;
13283 int ret;
13284 QDF_STATUS status;
13285 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13286
13287 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13288 ret = wlan_hdd_validate_context(hdd_ctx);
13289 if (ret < 0)
13290 return ret;
13291
13292 /* set the system preferece to default */
13293 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13294 hdd_ctx->config->conc_system_pref);
13295
13296 /* clear the bitmap */
13297 adapter->active_ac = 0;
13298
13299 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013300 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013301
Jeff Johnson1b780e42017-10-31 14:11:45 -070013302 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013303 false, 0, 0, false);
13304 if (!QDF_IS_STATUS_SUCCESS(status)) {
13305 hdd_err("failed to reset limit off chan params");
13306 ret = -EINVAL;
13307 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013308
13309 return ret;
13310}
13311
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013312/**
13313 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13314 * @drv_op: Enum indicating driver op
13315 *
13316 * Return: none
13317 */
13318void hdd_start_driver_ops_timer(int drv_op)
13319{
13320 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13321 switch (drv_op) {
13322 case eHDD_DRV_OP_PROBE:
13323 memcpy(drv_ops_string, "probe", sizeof("probe"));
13324 break;
13325 case eHDD_DRV_OP_REMOVE:
13326 memcpy(drv_ops_string, "remove", sizeof("remove"));
13327 break;
13328 case eHDD_DRV_OP_SHUTDOWN:
13329 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13330 break;
13331 case eHDD_DRV_OP_REINIT:
13332 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13333 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013334 case eHDD_DRV_OP_IFF_UP:
13335 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13336 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013337 }
13338
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013339 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013340 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13341 HDD_OPS_INACTIVITY_TIMEOUT);
13342}
13343
13344/**
13345 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13346 *
13347 * Return: none
13348 */
13349void hdd_stop_driver_ops_timer(void)
13350{
13351 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13352}
13353
13354/**
13355 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13356 * inactivity timer
13357 *
13358 * Return: None
13359 */
13360void hdd_drv_ops_inactivity_handler(void)
13361{
13362 hdd_err("%s: %d Sec timer expired while in .%s",
13363 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13364
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013365 if (hdd_drv_ops_task) {
13366 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13367 qdf_print_thread_trace(hdd_drv_ops_task);
13368 } else {
13369 hdd_err("hdd_drv_ops_task is null");
13370 }
13371
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013372 /* Driver shutdown is stuck, no recovery possible at this point */
13373 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13374 sizeof("shutdown")))
13375 QDF_BUG(0);
13376
13377 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013378 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013379 else
13380 QDF_BUG(0);
13381}
13382
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013383void hdd_pld_ipa_uc_shutdown_pipes(void)
13384{
13385 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13386
13387 if (!hdd_ctx)
13388 return;
13389
13390 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13391}
13392
Yun Parkff6a16a2017-09-26 16:38:18 -070013393/**
13394 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13395 * @struct hdd_context *hdd_ctx
13396 * @struct hdd_adapter *padapter
13397 * @bool enble
13398 *
13399 * Return: none
13400 */
13401void hdd_set_rx_mode_rps(bool enable)
13402{
13403 struct cds_config_info *cds_cfg = cds_get_ini_config();
13404 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13405 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13406
13407 if (adapter && hdd_ctx &&
13408 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13409 if (enable && !cds_cfg->rps_enabled)
13410 hdd_send_rps_ind(adapter);
13411 else if (!enable && cds_cfg->rps_enabled)
13412 hdd_send_rps_disable_ind(adapter);
13413 }
13414}
13415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013416/* Register the module init/exit functions */
13417module_init(hdd_module_init);
13418module_exit(hdd_module_exit);
13419
13420MODULE_LICENSE("Dual BSD/GPL");
13421MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13422MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013424module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13425 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013426
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013427module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13428 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13429
Ravi Joshia307f632017-07-17 23:41:41 -070013430module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13431 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13432
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013433module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13434 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13435
13436module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13437
13438module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13439
13440module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);