blob: f5a0122049189268a7bd283c79062c57861f6cf9 [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/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500376 * hdd_get_valid_chan() - return current chan list from regulatory.
377 * @hdd_ctx: HDD context
378 * @chan_list: buf hold returned chan list
379 * @chan_num: input buf size and output returned chan num
380 *
381 * This function helps get current available chan list from regulatory
382 * module. It excludes the "disabled" and "invalid" channels.
383 *
384 * Return: 0 for success.
385 */
386static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
387 uint8_t *chan_list,
388 uint32_t *chan_num)
389{
390 int i = 0, j = 0;
391 struct regulatory_channel *cur_chan_list;
392 struct wlan_objmgr_pdev *pdev;
393
394 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
395 return -EINVAL;
396
397 pdev = hdd_ctx->hdd_pdev;
398 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
399 sizeof(struct regulatory_channel));
400 if (!cur_chan_list)
401 return -ENOMEM;
402
403 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
404 QDF_STATUS_SUCCESS) {
405 qdf_mem_free(cur_chan_list);
406 return -EINVAL;
407 }
408
409 for (i = 0; i < NUM_CHANNELS; i++) {
410 uint32_t ch = cur_chan_list[i].chan_num;
411 enum channel_state state = wlan_reg_get_channel_state(pdev,
412 ch);
413
414 if (state != CHANNEL_STATE_DISABLE &&
415 state != CHANNEL_STATE_INVALID &&
416 j < *chan_num) {
417 chan_list[j] = (uint8_t)ch;
418 j++;
419 }
420 }
421 *chan_num = j;
422 qdf_mem_free(cur_chan_list);
423 return 0;
424}
425
426/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530427 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
428 * @adapter: HDD adapter
429 * @chan_number: Channel number
430 * @chan_bw: Bandwidth
431 *
432 * Checks if the given bandwidth is valid for the given channel number.
433 *
434 * Return: 0 for success, non-zero for failure
435 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700436int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530437 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800438 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530439{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500440 uint8_t chan[NUM_CHANNELS];
441 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530442 bool found = false;
443 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500444 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530445
446 hal = WLAN_HDD_GET_HAL_CTX(adapter);
447 if (!hal) {
448 hdd_err("Invalid HAL context");
449 return -EINVAL;
450 }
451
Liangwei Dong17bf2662018-01-05 02:02:05 -0500452 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
453 &len);
454 if (ret) {
455 hdd_err("error %d in getting valid channel list", ret);
456 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530457 }
458
459 for (i = 0; i < len; i++) {
460 if (chan[i] == chan_number) {
461 found = true;
462 break;
463 }
464 }
465
466 if (found == false) {
467 hdd_err("Channel not in driver's valid channel list");
468 return -EOPNOTSUPP;
469 }
470
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700471 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
472 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530473 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
474 return -EINVAL;
475 }
476
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700477 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530478 if (chan_bw == CH_WIDTH_80MHZ) {
479 hdd_err("BW80 not possible in 2.4GHz band");
480 return -EINVAL;
481 }
482 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
483 (chan_bw != CH_WIDTH_MAX)) {
484 hdd_err("Only BW20 possible on channel 14");
485 return -EINVAL;
486 }
487 }
488
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700489 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530490 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
491 (chan_bw != CH_WIDTH_MAX)) {
492 hdd_err("Only BW20 possible on channel 165");
493 return -EINVAL;
494 }
495 }
496
497 return 0;
498}
499
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530500/**
501 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
502 *
503 * Block the unloading of the driver (or) interface up until the
504 * cds recovery is completed
505 *
506 * Return: true for recovery completion else false
507 */
508static bool hdd_wait_for_recovery_completion(void)
509{
510 int retry = 0;
511
512 /* Wait for recovery to complete */
513 while (cds_is_driver_recovering()) {
514 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
515 hdd_err("Recovery in progress; wait here!!!");
516 msleep(1000);
517 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
518 hdd_err("SSR never completed, error");
519 /*
520 * Trigger the bug_on in the internal builds, in the
521 * customer builds self-recovery will be enabled
522 * in those cases just return error.
523 */
524 if (cds_is_self_recovery_enabled())
525 return false;
526 QDF_BUG(0);
527 }
528 }
529
530 hdd_info("Recovery completed successfully!");
531 return true;
532}
533
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800534static int __hdd_netdev_notifier_call(struct notifier_block *nb,
535 unsigned long state, void *data)
536{
537#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
538 struct netdev_notifier_info *dev_notif_info = data;
539 struct net_device *dev = dev_notif_info->dev;
540#else
541 struct net_device *dev = data;
542#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700543 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700544 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800545
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800546 ENTER_DEV(dev);
547
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548 /* Make sure that this callback corresponds to our device. */
549 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
550 return NOTIFY_DONE;
551
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530552 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800553 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700554 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800555 return NOTIFY_DONE;
556 }
557
558 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700559 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800560 return NOTIFY_DONE;
561 }
562
563 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
564 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800565 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530566 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800567 return NOTIFY_DONE;
568 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800569
570 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
571 hdd_err("%s: Driver module is closed", __func__);
572 return NOTIFY_DONE;
573 }
574
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530575 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800576 return NOTIFY_DONE;
577
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800578 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800579 dev->name, state);
580
581 switch (state) {
582 case NETDEV_REGISTER:
583 break;
584
585 case NETDEV_UNREGISTER:
586 break;
587
588 case NETDEV_UP:
589 sme_ch_avoid_update_req(hdd_ctx->hHal);
590 break;
591
592 case NETDEV_DOWN:
593 break;
594
595 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700596 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800597 complete(&adapter->linkup_event_var);
598 break;
599
600 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700601 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
602 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530603 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700604 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800605 } else {
hqueaa33ee2017-05-04 17:56:35 +0800606 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800607 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800608 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530609 /*
610 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
611 * of return status of hdd_stop call, kernel resets the IFF_UP
612 * flag after which driver does not send the cfg80211_scan_done.
613 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
614 */
615 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800616 break;
617
618 default:
619 break;
620 }
621
622 return NOTIFY_DONE;
623}
624
625/**
626 * hdd_netdev_notifier_call() - netdev notifier callback function
627 * @nb: pointer to notifier block
628 * @state: state
629 * @ndev: ndev pointer
630 *
631 * Return: 0 on success, error number otherwise.
632 */
633static int hdd_netdev_notifier_call(struct notifier_block *nb,
634 unsigned long state,
635 void *ndev)
636{
637 int ret;
638
639 cds_ssr_protect(__func__);
640 ret = __hdd_netdev_notifier_call(nb, state, ndev);
641 cds_ssr_unprotect(__func__);
642
643 return ret;
644}
645
646struct notifier_block hdd_netdev_notifier = {
647 .notifier_call = hdd_netdev_notifier_call,
648};
649
650/* variable to hold the insmod parameters */
651static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800652
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530653static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700654int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530655
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800656/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800657static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800658
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530659/**
660 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
661 * @ch_width: NL channel width
662 *
663 * Converts the NL channel width to the driver's internal representation
664 *
665 * Return: Converted channel width. In case of non matching NL channel width,
666 * CH_WIDTH_MAX will be returned.
667 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800668enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530669{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800670 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700671
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800672 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530673 switch (ch_width) {
674 case NL80211_CHAN_WIDTH_20_NOHT:
675 case NL80211_CHAN_WIDTH_20:
676 return CH_WIDTH_20MHZ;
677 case NL80211_CHAN_WIDTH_40:
678 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530679 case NL80211_CHAN_WIDTH_80:
680 return CH_WIDTH_80MHZ;
681 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800682 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
683 return CH_WIDTH_80P80MHZ;
684 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
685 return CH_WIDTH_160MHZ;
686 else
687 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530688 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800689 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
690 return CH_WIDTH_160MHZ;
691 else
692 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530693 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800694 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530695 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800696 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530697 default:
698 hdd_err("Invalid channel width %d, setting to default",
699 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800700 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530701 }
702}
703
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530704/* wlan_hdd_find_opclass() - Find operating class for a channel
705 * @hal: handler to HAL
706 * @channel: channel id
707 * @bw_offset: bandwidth offset
708 *
709 * Function invokes sme api to find the operating class
710 *
711 * Return: operating class
712 */
713uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
714 uint8_t bw_offset)
715{
716 uint8_t opclass = 0;
717
718 sme_get_opclass(hal, channel, bw_offset, &opclass);
719 return opclass;
720}
721
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800722/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530723 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530724 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800725 * @bitmask: Bitmask of log levels to be enabled
726 *
727 * Called immediately after the cfg.ini is read in order to configure
728 * the desired trace levels.
729 *
730 * Return: None
731 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530732int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530734 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530735 int qdf_print_idx = -1;
736 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800737 /*
738 * if the bitmask is the default value, then a bitmask was not
739 * specified in cfg.ini, so leave the logging level alone (it
740 * will remain at the "compiled in" default value)
741 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700742 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530743 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800744
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530745 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530747 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530748 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530749 QDF_TRACE_LEVEL_NONE, 0);
750
751 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530752 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800753 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530754 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800755 while (0 != bitmask) {
756 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530757 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530758 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530759 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530760 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700762
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800763 level++;
764 bitmask >>= 1;
765 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530766 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767}
768
769/**
Chris Guo1751acf2017-07-03 14:09:01 +0800770 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
771 * @hdd_ctx: HDD context pointer
772 *
773 * Return: 0 if the context is valid. Error code otherwise
774 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700775int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800776{
777 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
778 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
779 return -ENODEV;
780 }
781
782 if (cds_is_driver_recovering()) {
783 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
784 (void *)_RET_IP_, cds_get_driver_state());
785 return -EAGAIN;
786 }
787
788 if (hdd_ctx->start_modules_in_progress ||
789 hdd_ctx->stop_modules_in_progress) {
790 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
791 (void *)_RET_IP_);
792 return -EAGAIN;
793 }
794
795 return 0;
796}
797
798
799/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800 * wlan_hdd_validate_context() - check the HDD context
801 * @hdd_ctx: HDD context pointer
802 *
803 * Return: 0 if the context is valid. Error code otherwise
804 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700805int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800806{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800807 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530808 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809 return -ENODEV;
810 }
811
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800812 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800813 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530814 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800815 return -EAGAIN;
816 }
817
Yue Ma9f275d92017-09-14 16:58:41 -0700818 if (cds_is_load_or_unload_in_progress()) {
819 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
820 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700822 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530823
824 if (hdd_ctx->start_modules_in_progress ||
825 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800826 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530827 (void *)_RET_IP_);
828 return -EAGAIN;
829 }
830
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530831 if (cds_is_driver_in_bad_state()) {
832 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
833 (void *)_RET_IP_, cds_get_driver_state());
834 return -ENODEV;
835 }
836
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 return 0;
838}
839
Jeff Johnson9d295242017-08-29 14:39:48 -0700840int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700841{
842 if (!adapter) {
843 hdd_err("adapter is null");
844 return -EINVAL;
845 }
846
847 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
848 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
849 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
850 return -EINVAL;
851 }
852
853 if (!adapter->dev) {
854 hdd_err("adapter net_device is null");
855 return -EINVAL;
856 }
857
858 if (!(adapter->dev->flags & IFF_UP)) {
859 hdd_info("adapter net_device is not up");
860 return -EAGAIN;
861 }
862
Jeff Johnson1b780e42017-10-31 14:11:45 -0700863 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700864 hdd_info("adapter session is not open");
865 return -EAGAIN;
866 }
867
Jeff Johnson1b780e42017-10-31 14:11:45 -0700868 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
869 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700870 return -EINVAL;
871 }
872
873 return 0;
874}
875
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530877 * wlan_hdd_validate_modules_state() - Check modules status
878 * @hdd_ctx: HDD context pointer
879 *
880 * Check's the driver module's state and returns true if the
881 * modules are enabled returns false if modules are closed.
882 *
883 * Return: True if modules are enabled or false.
884 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700885bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530886{
887 mutex_lock(&hdd_ctx->iface_change_lock);
888 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
889 mutex_unlock(&hdd_ctx->iface_change_lock);
890 hdd_notice("Modules not enabled, Present status: %d",
891 hdd_ctx->driver_status);
892 return false;
893 }
894 mutex_unlock(&hdd_ctx->iface_change_lock);
895 return true;
896}
897
898/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800899 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700900 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 *
902 * This function sets the IBSS power save config parameters to WMA
903 * which will send it to firmware if FW supports IBSS power save
904 * before vdev start.
905 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530906 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907 * on failure.
908 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700909QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800910{
911 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700912 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800913
914 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700915 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530916 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 }
918
Jeff Johnson1b780e42017-10-31 14:11:45 -0700919 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
921 hdd_ctx->config->ibssATIMWinSize,
922 VDEV_CMD);
923 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700924 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530925 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800926 }
927
Jeff Johnson1b780e42017-10-31 14:11:45 -0700928 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800929 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
930 hdd_ctx->config->isIbssPowerSaveAllowed,
931 VDEV_CMD);
932 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700933 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
934 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530935 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800936 }
937
Jeff Johnson1b780e42017-10-31 14:11:45 -0700938 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800939 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
940 hdd_ctx->config->
941 isIbssPowerCollapseAllowed, VDEV_CMD);
942 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700943 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
944 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530945 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800946 }
947
Jeff Johnson1b780e42017-10-31 14:11:45 -0700948 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
950 hdd_ctx->config->isIbssAwakeOnTxRx,
951 VDEV_CMD);
952 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700953 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530954 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955 }
956
Jeff Johnson1b780e42017-10-31 14:11:45 -0700957 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
959 hdd_ctx->config->ibssInactivityCount,
960 VDEV_CMD);
961 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700962 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530963 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964 }
965
Jeff Johnson1b780e42017-10-31 14:11:45 -0700966 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800967 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
968 hdd_ctx->config->ibssTxSpEndInactivityTime,
969 VDEV_CMD);
970 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700971 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
972 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530973 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974 }
975
Jeff Johnson1b780e42017-10-31 14:11:45 -0700976 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
978 hdd_ctx->config->ibssPsWarmupTime,
979 VDEV_CMD);
980 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700981 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
982 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530983 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 }
985
Jeff Johnson1b780e42017-10-31 14:11:45 -0700986 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
988 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
989 VDEV_CMD);
990 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700991 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
992 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530993 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994 }
995
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530996 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997}
998
Yue Macd359b72017-10-03 15:21:00 -0700999#ifdef FEATURE_RUNTIME_PM
1000/**
1001 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1002 * @hdd_ctx: HDD context
1003 *
1004 * Return: None
1005 */
1006static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1007{
1008 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1009
Yue Macd359b72017-10-03 15:21:00 -07001010 qdf_runtime_lock_init(&ctx->dfs);
1011
1012 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1013}
1014
1015/**
1016 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1017 * @hdd_ctx: HDD Context
1018 *
1019 * Return: None
1020 */
1021static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1022{
1023 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1024
Yue Macd359b72017-10-03 15:21:00 -07001025 qdf_runtime_lock_deinit(&ctx->dfs);
1026
1027 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1028}
1029
1030static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
1031{
1032 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
1033
1034 qdf_runtime_lock_init(&ctx->connect);
1035}
1036
Yue Ma9e89e832017-11-14 11:40:23 -08001037static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter)
Yue Macd359b72017-10-03 15:21:00 -07001038{
1039 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
1040
1041 qdf_runtime_lock_deinit(&ctx->connect);
1042}
1043#else /* FEATURE_RUNTIME_PM */
1044static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1045static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
1046static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
Yue Ma9e89e832017-11-14 11:40:23 -08001047static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter) {}
Yue Macd359b72017-10-03 15:21:00 -07001048#endif /* FEATURE_RUNTIME_PM */
1049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050#define INTF_MACADDR_MASK 0x7
1051
1052/**
1053 * hdd_update_macaddr() - update mac address
1054 * @config: hdd configuration
1055 * @hw_macaddr: mac address
1056 *
1057 * Mac address for multiple virtual interface is found as following
1058 * i) The mac address of the first interface is just the actual hw mac address.
1059 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1060 * define the mac address for the remaining interfaces and locally
1061 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1062 * supported virtual interfaces, right now this is 0x07 (meaning 8
1063 * interface).
1064 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1065 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1066 *
1067 * Return: None
1068 */
1069void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301070 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001071{
1072 int8_t i;
1073 uint8_t macaddr_b3, tmp_br3;
1074
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301075 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301076 QDF_MAC_ADDR_SIZE);
1077 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301078 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301079 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1081 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1082 INTF_MACADDR_MASK;
1083 macaddr_b3 += tmp_br3;
1084
1085 /* XOR-ing bit-24 of the mac address. This will give enough
1086 * mac address range before collision
1087 */
1088 macaddr_b3 ^= (1 << 7);
1089
1090 /* Set locally administered bit */
1091 config->intfMacAddr[i].bytes[0] |= 0x02;
1092 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001093 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001094 MAC_ADDRESS_STR, i,
1095 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1096 }
1097}
1098
Kabilan Kannan44a58372017-12-06 18:16:11 -08001099static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1100{
1101 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1102 struct tdls_start_params tdls_cfg;
1103 struct tdls_user_config *config = &tdls_cfg.config;
1104 struct hdd_config *cfg = hdd_ctx->config;
1105 QDF_STATUS status;
1106
1107 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1108 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1109 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1110 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1111 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1112 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1113 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1114 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1115 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1116 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1117 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1118 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1119 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1120 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1121 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1122 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1123 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1124 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1125 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1126 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1127 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1128 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1129 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1130 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1131 (cfg->fEnableTDLSImplicitTrigger ?
1132 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1133 (cfg->fTDLSExternalControl ?
1134 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1135 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1136 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1137
1138 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1139 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1140 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1141 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1142 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1143 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1144 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1145 tdls_cfg.tdls_evt_cb_data = psoc;
1146 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
1147 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
1148 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
1149 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1150 tdls_cfg.tdls_wmm_cb_data = psoc;
1151 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1152 tdls_cfg.tdls_rx_cb_data = psoc;
1153 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1154
1155 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1156 if (status != QDF_STATUS_SUCCESS) {
1157 hdd_err("failed pmo psoc configuration");
1158 return -EINVAL;
1159 }
1160
1161 hdd_ctx->tdls_umac_comp_active = true;
1162 /* enable napier specific tdls data path */
1163 hdd_ctx->tdls_nap_active = true;
1164
1165 return 0;
1166}
1167
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001168static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001169 struct wma_tgt_services *cfg)
1170{
1171 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172
1173 /* Set up UAPSD */
1174 config->apUapsdEnabled &= cfg->uapsd;
1175
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001176 /* 11AX mode support */
1177 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1178 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1179 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1180
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001181 /* 11AC mode support */
1182 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1183 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1184 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001185
1186 /* ARP offload: override user setting if invalid */
1187 config->fhostArpOffload &= cfg->arp_offload;
1188
1189#ifdef FEATURE_WLAN_SCAN_PNO
1190 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001191 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192 if (cfg->pno_offload)
1193 config->PnoOffload = true;
1194#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195#ifdef FEATURE_WLAN_TDLS
1196 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301197 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1198 cfg->en_tdls_offchan;
1199 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1200 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001201 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001203 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001205#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001206#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1207 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1208#endif
Will Huang496b36c2017-07-11 16:38:50 +08001209 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001210 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001211 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001212 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001213
1214}
1215
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001216/**
1217 * hdd_update_vdev_nss() - sets the vdev nss
1218 * @hdd_ctx: HDD context
1219 *
1220 * Sets the Nss per vdev type based on INI
1221 *
1222 * Return: None
1223 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001224static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001225{
1226 struct hdd_config *cfg_ini = hdd_ctx->config;
1227 uint8_t max_supp_nss = 1;
1228
Naveen Rawat10b1c152017-01-18 11:16:06 -08001229 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001230 max_supp_nss = 2;
1231
1232 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001233 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001234
1235 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001236 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001237}
1238
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301239/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301240 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1241 * @hdd_ctx: HDD context
1242 *
1243 * Updates wiphy vhtcap fields
1244 *
1245 * Return: None
1246 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001247static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301248{
1249 struct ieee80211_supported_band *band_5g =
1250 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1251 uint32_t val;
1252
1253 if (!band_5g) {
1254 hdd_debug("5GHz band disabled, skipping capability population");
1255 return;
1256 }
1257
1258 val = hdd_ctx->config->txBFCsnValue;
1259 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1260
1261 val = NUM_OF_SOUNDING_DIMENSIONS;
1262 band_5g->vht_cap.cap |=
1263 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1264
1265 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1266 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1267}
1268
1269/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301270 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1271 * @hdd_ctx: HDD context
1272 *
1273 * Sets the DBS capability as per INI and firmware capability
1274 *
1275 * Return: None
1276 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001277static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301278{
1279 struct hdd_config *cfg_ini = hdd_ctx->config;
1280 uint8_t hw_dbs_capable = 0;
1281
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001282 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1283 ((cfg_ini->dual_mac_feature_disable ==
1284 ENABLE_DBS_CXN_AND_SCAN) ||
1285 (cfg_ini->dual_mac_feature_disable ==
1286 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301287 hw_dbs_capable = 1;
1288
1289 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1290}
1291
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001292static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001293 struct wma_tgt_ht_cap *cfg)
1294{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301295 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296 uint32_t value, val32;
1297 uint16_t val16;
1298 struct hdd_config *pconfig = hdd_ctx->config;
1299 tSirMacHTCapabilityInfo *phtCapInfo;
1300 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1301 uint8_t enable_tx_stbc;
1302
1303 /* check and update RX STBC */
1304 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1305 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1306
1307 /* get the MPDU density */
1308 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1309
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301310 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001311 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001312 value = 0;
1313 }
1314
1315 /*
1316 * MPDU density:
1317 * override user's setting if value is larger
1318 * than the one supported by target
1319 */
1320 if (value > cfg->mpdu_density) {
1321 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1322 cfg->mpdu_density);
1323
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301324 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001325 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001326 }
1327
1328 /* get the HT capability info */
1329 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301330 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001331 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001332 return;
1333 }
1334 val16 = (uint16_t) val32;
1335 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1336
1337 /* Set the LDPC capability */
1338 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1339
1340 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1341 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1342
1343 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1344 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1345
1346 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1347 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1348
1349 enable_tx_stbc = pconfig->enableTxSTBC;
1350
1351 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1352 pconfig->enable2x2 = 1;
1353 } else {
1354 pconfig->enable2x2 = 0;
1355 enable_tx_stbc = 0;
1356
1357 /* 1x1 */
1358 /* Update Rx Highest Long GI data Rate */
1359 if (sme_cfg_set_int(hdd_ctx->hHal,
1360 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001361 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301362 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001363 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364 }
1365
1366 /* Update Tx Highest Long GI data Rate */
1367 if (sme_cfg_set_int
1368 (hdd_ctx->hHal,
1369 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001370 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301371 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001372 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 }
1374 }
1375 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1376 enable_tx_stbc = 0;
1377 phtCapInfo->txSTBC = enable_tx_stbc;
1378
1379 val32 = val16;
1380 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301381 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001382 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1384 value = SIZE_OF_SUPPORTED_MCS_SET;
1385 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301386 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001387 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388
1389 if (pconfig->enable2x2) {
1390 for (value = 0; value < cfg->num_rf_chains; value++)
1391 mcs_set[value] =
1392 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1393
1394 status =
1395 sme_cfg_set_str(hdd_ctx->hHal,
1396 WNI_CFG_SUPPORTED_MCS_SET,
1397 mcs_set,
1398 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301399 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001400 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 }
1402 }
1403#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1404}
1405
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001406static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001407 struct wma_tgt_vht_cap *cfg)
1408{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301409 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001410 uint32_t value = 0;
1411 struct hdd_config *pconfig = hdd_ctx->config;
1412 struct wiphy *wiphy = hdd_ctx->wiphy;
1413 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001414 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001415 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001416 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001417 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001418
Dustin Brown5e06bd32016-10-04 12:49:10 -07001419 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001420 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001421 return;
1422 }
1423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001424 /* Get the current MPDU length */
1425 status =
1426 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1427 &value);
1428
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301429 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001430 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001431 value = 0;
1432 }
1433
1434 /*
1435 * VHT max MPDU length:
1436 * override if user configured value is too high
1437 * that the target cannot support
1438 */
1439 if (value > cfg->vht_max_mpdu) {
1440 status = sme_cfg_set_int(hdd_ctx->hHal,
1441 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1442 cfg->vht_max_mpdu);
1443
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001444 if (status == QDF_STATUS_E_FAILURE)
1445 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001446 }
1447
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001448 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1449 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1450
1451 if (pconfig->enable2x2)
1452 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1453
1454 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1455 QDF_STATUS_E_FAILURE) {
1456 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1457 }
1458
1459 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1460 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1461 if (pconfig->enable2x2)
1462 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1463
1464 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1465 QDF_STATUS_E_FAILURE) {
1466 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1467 }
1468
1469 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1470 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1471 if (pconfig->enable2x2)
1472 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1473
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001474 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001475 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1476
1477 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1478 QDF_STATUS_E_FAILURE) {
1479 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1480 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001482 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 &value);
1484
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301485 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001486 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001487 value = 0;
1488 }
1489
jiad4a7a33c2017-08-08 15:32:24 +08001490 /* Set HW RX LDPC capability */
1491 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1492 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493 status = sme_cfg_set_int(hdd_ctx->hHal,
1494 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001495 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001497 if (status == QDF_STATUS_E_FAILURE)
1498 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001499 }
1500
1501 /* Get current GI 80 value */
1502 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1503 &value);
1504
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301505 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001506 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507 value = 0;
1508 }
1509
1510 /* set the Guard interval 80MHz */
1511 if (value && !cfg->vht_short_gi_80) {
1512 status = sme_cfg_set_int(hdd_ctx->hHal,
1513 WNI_CFG_VHT_SHORT_GI_80MHZ,
1514 cfg->vht_short_gi_80);
1515
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001516 if (status == QDF_STATUS_E_FAILURE)
1517 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001518 }
1519
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001520 /* Get VHT TX STBC cap */
1521 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1522
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301523 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001524 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001525 value = 0;
1526 }
1527
1528 /* VHT TX STBC cap */
1529 if (value && !cfg->vht_tx_stbc) {
1530 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1531 cfg->vht_tx_stbc);
1532
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001533 if (status == QDF_STATUS_E_FAILURE)
1534 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001535 }
1536
1537 /* Get VHT RX STBC cap */
1538 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1539
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301540 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001541 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 value = 0;
1543 }
1544
1545 /* VHT RX STBC cap */
1546 if (value && !cfg->vht_rx_stbc) {
1547 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1548 cfg->vht_rx_stbc);
1549
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001550 if (status == QDF_STATUS_E_FAILURE)
1551 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552 }
1553
1554 /* Get VHT SU Beamformer cap */
1555 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1556 &value);
1557
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301558 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001559 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 value = 0;
1561 }
1562
1563 /* set VHT SU Beamformer cap */
1564 if (value && !cfg->vht_su_bformer) {
1565 status = sme_cfg_set_int(hdd_ctx->hHal,
1566 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1567 cfg->vht_su_bformer);
1568
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001569 if (status == QDF_STATUS_E_FAILURE)
1570 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001571 }
1572
1573 /* check and update SU BEAMFORMEE capabality */
1574 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1575 pconfig->enableTxBF = cfg->vht_su_bformee;
1576
1577 status = sme_cfg_set_int(hdd_ctx->hHal,
1578 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1579 pconfig->enableTxBF);
1580
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001581 if (status == QDF_STATUS_E_FAILURE)
1582 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001583
1584 /* Get VHT MU Beamformer cap */
1585 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1586 &value);
1587
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301588 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001589 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001590 value = 0;
1591 }
1592
1593 /* set VHT MU Beamformer cap */
1594 if (value && !cfg->vht_mu_bformer) {
1595 status = sme_cfg_set_int(hdd_ctx->hHal,
1596 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1597 cfg->vht_mu_bformer);
1598
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001599 if (status == QDF_STATUS_E_FAILURE)
1600 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001601 }
1602
1603 /* Get VHT MU Beamformee cap */
1604 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1605 &value);
1606
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301607 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001608 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001609 value = 0;
1610 }
1611
1612 /* set VHT MU Beamformee cap */
1613 if (value && !cfg->vht_mu_bformee) {
1614 status = sme_cfg_set_int(hdd_ctx->hHal,
1615 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1616 cfg->vht_mu_bformee);
1617
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001618 if (status == QDF_STATUS_E_FAILURE)
1619 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 }
1621
1622 /* Get VHT MAX AMPDU Len exp */
1623 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1624 &value);
1625
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301626 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001627 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628 value = 0;
1629 }
1630
1631 /*
1632 * VHT max AMPDU len exp:
1633 * override if user configured value is too high
1634 * that the target cannot support.
1635 * Even though Rome publish ampdu_len=7, it can
1636 * only support 4 because of some h/w bug.
1637 */
1638
1639 if (value > cfg->vht_max_ampdu_len_exp) {
1640 status = sme_cfg_set_int(hdd_ctx->hHal,
1641 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1642 cfg->vht_max_ampdu_len_exp);
1643
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001644 if (status == QDF_STATUS_E_FAILURE)
1645 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001646 }
1647
1648 /* Get VHT TXOP PS CAP */
1649 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1650
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301651 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001652 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001653 value = 0;
1654 }
1655
1656 /* set VHT TXOP PS cap */
1657 if (value && !cfg->vht_txop_ps) {
1658 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1659 cfg->vht_txop_ps);
1660
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001661 if (status == QDF_STATUS_E_FAILURE)
1662 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 }
1664
1665 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1666 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1667 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1668 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1669 else
1670 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1671
1672
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001673 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1674 status = sme_cfg_set_int(hdd_ctx->hHal,
1675 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1676 VHT_CAP_160_AND_80P80_SUPP);
1677 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001678 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001679 band_5g->vht_cap.cap |=
1680 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001681 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1682 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1683 status = sme_cfg_set_int(hdd_ctx->hHal,
1684 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1685 VHT_CAP_160_SUPP);
1686 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001687 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688 band_5g->vht_cap.cap |=
1689 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001690 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1691 }
1692 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1693 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301694 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001695 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301696 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001697 &value);
1698 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301699 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001700 value = 0;
1701 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301702 /* set the Guard interval 160MHz */
1703 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001704 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301705 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1706 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001707
1708 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301709 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001710 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001711
1712 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1713 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1714
1715 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1716 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1717 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1718 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1719
1720 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1721 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1722
1723 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1724 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1725 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1726 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1727 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1728 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1729
1730 band_5g->vht_cap.cap |=
1731 (cfg->vht_max_ampdu_len_exp <<
1732 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1733
1734 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1735 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1736 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1737 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1738 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1739 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1740 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1741 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1742
1743 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1744 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1745
1746}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001747
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001748/**
1749 * hdd_generate_macaddr_auto() - Auto-generate mac address
1750 * @hdd_ctx: Pointer to the HDD context
1751 *
1752 * Auto-generate mac address using device serial number.
1753 * Keep the first 3 bytes of OUI as before and replace
1754 * the last 3 bytes with the lower 3 bytes of serial number.
1755 *
1756 * Return: 0 for success
1757 * Non zero failure code for errors
1758 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001759static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001760{
1761 unsigned int serialno = 0;
1762 struct qdf_mac_addr mac_addr = {
1763 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1764 };
1765
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001766 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001767 if (serialno == 0)
1768 return -EINVAL;
1769
1770 serialno &= 0x00ffffff;
1771
1772 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1773 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1774 mac_addr.bytes[5] = serialno & 0xff;
1775
1776 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1777 return 0;
1778}
1779
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301780/**
1781 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1782 * configuration to cfg_ini in HDD
1783 * @hdd_ctx: Pointer to hdd_ctx
1784 * @cfg: target configuration
1785 *
1786 * Return: None
1787 */
1788#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001789static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301790 struct wma_tgt_cfg *cfg)
1791{
1792 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1793}
1794#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001795static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301796 struct wma_tgt_cfg *cfg)
1797{
1798}
1799#endif
1800
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301801uint8_t hdd_check_green_ap_enable(struct hdd_context *hdd_ctx,
1802 bool *is_enabled)
1803{
1804 struct hdd_config *cfg;
1805 uint32_t concurrency_mode;
1806
1807 cfg = hdd_ctx->config;
1808 if (!cfg) {
1809 hdd_err("NULL hdd config");
1810 return -EINVAL;
1811 }
1812
1813 concurrency_mode = policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc);
1814
1815 if (cfg->enable2x2 && cfg->enableGreenAP) {
1816 if ((concurrency_mode & (1 << QDF_SAP_MODE)) &&
1817 !(concurrency_mode & (~(1 << QDF_SAP_MODE))))
1818 *is_enabled = true;
1819 }
1820 return 0;
1821}
1822
1823static int hdd_update_green_ap_config(struct hdd_context *hdd_ctx)
1824{
1825 struct green_ap_user_cfg green_ap_cfg;
1826 struct hdd_config *cfg = hdd_ctx->config;
1827 QDF_STATUS status;
1828
1829 green_ap_cfg.host_enable_egap = cfg->enable_egap;
1830 green_ap_cfg.egap_inactivity_time = cfg->egap_inact_time;
1831 green_ap_cfg.egap_wait_time = cfg->egap_wait_time;
1832 green_ap_cfg.egap_feature_flags = cfg->egap_feature_flag;
1833
1834 status = ucfg_green_ap_update_user_config(hdd_ctx->hdd_pdev,
1835 &green_ap_cfg);
1836 if (status != QDF_STATUS_SUCCESS) {
1837 hdd_err("failed to update green ap user configuration");
1838 return -EINVAL;
1839 }
1840
1841 return 0;
1842}
1843
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001844void hdd_update_tgt_cfg(void *context, void *param)
1845{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001846 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001847 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848 struct wma_tgt_cfg *cfg = param;
1849 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001850 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301851 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301852
Dustin Brownbd68fe12017-11-21 15:28:52 -08001853 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1854 if (ret) {
1855 hdd_err("Failed to create pdev; errno:%d", ret);
1856 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001857 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001858 hdd_debug("New pdev has been created with pdev_id = %u",
1859 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301860 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001861
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301862 ret = hdd_update_green_ap_config(hdd_ctx);
1863
Naveen Rawat64e477e2016-05-20 10:34:56 -07001864 if (cds_cfg) {
1865 if (hdd_ctx->config->enable_sub_20_channel_width !=
1866 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1867 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1868 cds_cfg->sub_20_channel_width =
1869 WLAN_SUB_20_CH_WIDTH_NONE;
1870 } else {
1871 cds_cfg->sub_20_channel_width =
1872 hdd_ctx->config->enable_sub_20_channel_width;
1873 }
1874 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001875
1876 /* first store the INI band capability */
1877 temp_band_cap = hdd_ctx->config->nBandCapability;
1878
1879 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301880 hdd_ctx->is_fils_roaming_supported =
1881 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001882
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001883 /*
1884 * now overwrite the target band capability with INI
1885 * setting if INI setting is a subset
1886 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001887
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001888 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1889 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001890 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001891 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1892 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001894 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001895 }
1896
Amar Singhal58b45ef2017-08-01 13:43:54 -07001897 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1898
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301899 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1901 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1902 }
1903
1904 /* This can be extended to other configurations like ht, vht cap... */
1905
Anurag Chouhanc5548422016-02-24 18:33:27 +05301906 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001908 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001909 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001910 static struct qdf_mac_addr default_mac_addr = {
1911 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1912 };
1913 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1914 &default_mac_addr)) {
1915 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1916 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1917 MAC_ADDRESS_STR,
1918 MAC_ADDR_ARRAY(hdd_ctx->config->
1919 intfMacAddr[0].bytes));
1920 } else {
1921 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1922 MAC_ADDRESS_STR,
1923 MAC_ADDR_ARRAY(hdd_ctx->config->
1924 intfMacAddr[0].bytes));
1925 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001926 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001927 }
1928
1929 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001930 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001931
1932 hdd_ctx->max_intf_count = cfg->max_intf_count;
1933
Jeff Johnsonc875e242016-09-23 18:12:34 -07001934 hdd_lpass_target_config(hdd_ctx, cfg);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301935 ucfg_green_ap_target_config(hdd_ctx->hdd_pdev, cfg->egap_support);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001936
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001937 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1938 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1939
1940 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1941
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001942 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001943 if (cfg->services.en_11ax) {
1944 hdd_info("11AX: 11ax is enabled - update HDD config");
1945 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1946 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001947
1948 hdd_update_vdev_nss(hdd_ctx);
1949
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301950 hdd_update_hw_dbs_capable(hdd_ctx);
1951
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001952 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001953 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001954 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001955 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001956
Nitesh Shahe50711f2017-04-26 16:30:45 +05301957 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1958 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1959 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001960 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001961 hdd_ctx->current_antenna_mode);
1962
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001963 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1964 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301965 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301966 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301967
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301968 if ((hdd_ctx->config->txBFCsnValue >
1969 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1970 !cfg->tx_bfee_8ss_enabled)
1971 hdd_ctx->config->txBFCsnValue =
1972 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1973
1974 if (sme_cfg_set_int(hdd_ctx->hHal,
1975 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1976 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1977 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1978
1979
1980 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1981 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1982 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301983
1984 /*
1985 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1986 */
1987 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301988
Arun Khandavallid454d422016-08-17 12:47:05 +05301989 /*
1990 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1991 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1992 * configure the STA mode wow pattern.
1993 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301994 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301995 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301996
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301997 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1998
Yue Macd359b72017-10-03 15:21:00 -07001999 /*
2000 * This needs to be done after HDD pdev is created and stored since
2001 * it will access the HDD pdev object lock.
2002 */
2003 hdd_runtime_suspend_context_init(hdd_ctx);
2004
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002005 /* Configure NAN datapath features */
2006 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002007 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002008 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002009}
2010
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002011bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002012{
Jeff Johnson9d295242017-08-29 14:39:48 -07002013 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002014 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015
Arif Hussaincd151632017-02-11 16:57:19 -08002016 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002017 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002018 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302019 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002020 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002021
Dustin Brown920397d2017-12-13 16:27:50 -08002022 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002023 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2024
2025 if ((QDF_SAP_MODE == adapter->device_mode ||
2026 QDF_P2P_GO_MODE == adapter->device_mode) &&
2027 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002028 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002029 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2030 true;
2031 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002032 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302033 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002034 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302035
2036 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002037}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002038
2039/**
2040 * hdd_is_valid_mac_address() - validate MAC address
2041 * @pMacAddr: Pointer to the input MAC address
2042 *
2043 * This function validates whether the given MAC address is valid or not
2044 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2045 * where X is the hexa decimal digit character and separated by ':'
2046 * This algorithm works even if MAC address is not separated by ':'
2047 *
2048 * This code checks given input string mac contains exactly 12 hexadecimal
2049 * digits and a separator colon : appears in the input string only after
2050 * an even number of hex digits.
2051 *
2052 * Return: 1 for valid and 0 for invalid
2053 */
2054bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2055{
2056 int xdigit = 0;
2057 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002058
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002059 while (*pMacAddr) {
2060 if (isxdigit(*pMacAddr)) {
2061 xdigit++;
2062 } else if (':' == *pMacAddr) {
2063 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2064 break;
2065
2066 ++separator;
2067 } else {
2068 /* Invalid MAC found */
2069 return 0;
2070 }
2071 ++pMacAddr;
2072 }
2073 return xdigit == 12 && (separator == 5 || separator == 0);
2074}
2075
2076/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302077 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2078 * @dev: Handle to struct net_device to be updated.
2079 *
2080 * Return: None
2081 */
2082static void hdd_mon_mode_ether_setup(struct net_device *dev)
2083{
2084 dev->header_ops = NULL;
2085 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2086 dev->hard_header_len = ETH_HLEN;
2087 dev->mtu = ETH_DATA_LEN;
2088 dev->addr_len = ETH_ALEN;
2089 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2090 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2091 dev->priv_flags |= IFF_TX_SKB_SHARING;
2092
2093 memset(dev->broadcast, 0xFF, ETH_ALEN);
2094}
2095
2096/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002097 * __hdd__mon_open() - HDD Open function
2098 * @dev: Pointer to net_device structure
2099 *
2100 * This is called in response to ifconfig up
2101 *
2102 * Return: 0 for success; non-zero for failure
2103 */
2104static int __hdd_mon_open(struct net_device *dev)
2105{
2106 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002107 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2108 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002109
2110 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002111
2112 ret = wlan_hdd_validate_context(hdd_ctx);
2113 if (ret)
2114 return ret;
2115
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302116 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002117
2118 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2119 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2120 if (ret) {
2121 hdd_err("Failed to start WLAN modules return");
2122 return ret;
2123 }
2124 hdd_err("hdd_wlan_start_modules() successful !");
2125
2126 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2127 ret = hdd_start_adapter(adapter);
2128 if (ret) {
2129 hdd_err("Failed to start adapter :%d",
2130 adapter->device_mode);
2131 return ret;
2132 }
2133 hdd_err("hdd_start_adapters() successful !");
2134 }
2135 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2136 }
2137
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002138 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002139
2140 if (!ret)
2141 ret = hdd_enable_monitor_mode(dev);
2142
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002143 return ret;
2144}
2145
2146/**
2147 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2148 * @dev: Pointer to net_device structure
2149 *
2150 * This is called in response to ifconfig up
2151 *
2152 * Return: 0 for success; non-zero for failure
2153 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002154static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002155{
2156 int ret;
2157
2158 cds_ssr_protect(__func__);
2159 ret = __hdd_mon_open(dev);
2160 cds_ssr_unprotect(__func__);
2161
2162 return ret;
2163}
2164
2165/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302166 * hdd_start_adapter() - Wrapper function for device specific adapter
2167 * @adapter: pointer to HDD adapter
2168 *
2169 * This function is called to start the device specific adapter for
2170 * the mode passed in the adapter's device_mode.
2171 *
2172 * Return: 0 for success; non-zero for failure
2173 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002174int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302175{
2176
2177 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002178 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302179
2180 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002181 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302182
2183 switch (device_mode) {
2184 case QDF_P2P_CLIENT_MODE:
2185 case QDF_P2P_DEVICE_MODE:
2186 case QDF_OCB_MODE:
2187 case QDF_STA_MODE:
2188 case QDF_MONITOR_MODE:
2189 ret = hdd_start_station_adapter(adapter);
2190 if (ret)
2191 goto err_start_adapter;
2192 break;
2193 case QDF_P2P_GO_MODE:
2194 case QDF_SAP_MODE:
2195 ret = hdd_start_ap_adapter(adapter);
2196 if (ret)
2197 goto err_start_adapter;
2198 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302199 case QDF_IBSS_MODE:
2200 /*
2201 * For IBSS interface is initialized as part of
2202 * hdd_init_station_mode()
2203 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002204 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302205 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002206 /* vdevs are dynamically managed by firmware in FTM */
2207 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302208 default:
2209 hdd_err("Invalid session type %d", device_mode);
2210 QDF_ASSERT(0);
2211 goto err_start_adapter;
2212 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002213
Arun Khandavallifae92942016-08-01 13:31:08 +05302214 if (hdd_set_fw_params(adapter))
2215 hdd_err("Failed to set the FW params for the adapter!");
2216
2217 /*
2218 * Action frame registered in one adapter which will
2219 * applicable to all interfaces
2220 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302221 ret = wlan_hdd_cfg80211_register_frames(adapter);
2222 if (ret < 0) {
2223 hdd_err("Failed to register frames - ret %d", ret);
2224 goto err_start_adapter;
2225 }
2226
Dustin Browndb2a8be2017-12-20 11:49:56 -08002227exit_with_success:
Arun Khandavallifae92942016-08-01 13:31:08 +05302228 EXIT();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002229
Arun Khandavallifae92942016-08-01 13:31:08 +05302230 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002231
Arun Khandavallifae92942016-08-01 13:31:08 +05302232err_start_adapter:
2233 return -EINVAL;
2234}
2235
2236/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302237 * hdd_enable_power_management() - API to Enable Power Management
2238 *
2239 * API invokes Bus Interface Layer power management functionality
2240 *
2241 * Return: None
2242 */
2243static void hdd_enable_power_management(void)
2244{
2245 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2246
2247 if (!hif_ctx) {
2248 hdd_err("Bus Interface Context is Invalid");
2249 return;
2250 }
2251
2252 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2253}
2254
2255/**
2256 * hdd_disable_power_management() - API to disable Power Management
2257 *
2258 * API disable Bus Interface Layer Power management functionality
2259 *
2260 * Return: None
2261 */
2262static void hdd_disable_power_management(void)
2263{
2264 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2265
2266 if (!hif_ctx) {
2267 hdd_err("Bus Interface Context is Invalid");
2268 return;
2269 }
2270
2271 hif_disable_power_management(hif_ctx);
2272}
2273
2274/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302275 * hdd_update_hw_sw_info() - API to update the HW/SW information
2276 *
2277 * API to update the HW and SW information in the driver
2278 *
2279 * Return: None
2280 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002281static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302282{
2283 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002284 size_t target_hw_name_len;
2285 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302286
2287 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2288 if (!hif_sc) {
2289 hdd_err("HIF context is NULL");
2290 return;
2291 }
2292
2293 /*
2294 * target hw version/revision would only be retrieved after firmware
2295 * download
2296 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002297 hif_get_hw_info(hif_sc,
2298 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302299 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002300 &target_hw_name);
2301
2302 if (hdd_ctx->target_hw_name)
2303 qdf_mem_free(hdd_ctx->target_hw_name);
2304
2305 target_hw_name_len = strlen(target_hw_name) + 1;
2306 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2307 if (hdd_ctx->target_hw_name)
2308 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2309 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302310
2311 /* Get the wlan hw/fw version */
2312 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302313}
2314
2315/**
gbian62edd7e2017-03-07 13:12:13 +08002316 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2317 * @hdd_ctx: Pointer to hdd context
2318 *
2319 * Return: none
2320 */
2321static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002322hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002323{
2324 uint8_t num_entries = 0;
2325 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2326 uint8_t *tx_sched_wrr_ac;
2327 int i;
2328 cds_context_type *cds_ctx;
2329
2330 if (NULL == hdd_ctx)
2331 return;
2332
2333 if (NULL == hdd_ctx->config) {
2334 /* Do nothing if hdd_ctx is invalid */
2335 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2336 return;
2337 }
2338
2339 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2340
2341 if (!cds_ctx) {
2342 hdd_err("Invalid CDS Context");
2343 return;
2344 }
2345
2346 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2347 switch (i) {
2348 case OL_TX_WMM_AC_BE:
2349 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2350 break;
2351 case OL_TX_WMM_AC_BK:
2352 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2353 break;
2354 case OL_TX_WMM_AC_VI:
2355 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2356 break;
2357 case OL_TX_WMM_AC_VO:
2358 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2359 break;
2360 default:
2361 tx_sched_wrr_ac = NULL;
2362 break;
2363 }
2364
2365 hdd_string_to_u8_array(tx_sched_wrr_ac,
2366 tx_sched_wrr_param,
2367 &num_entries,
2368 sizeof(tx_sched_wrr_param));
2369
2370 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2371 cds_ctx->ac_specs[i].wrr_skip_weight =
2372 tx_sched_wrr_param[0];
2373 cds_ctx->ac_specs[i].credit_threshold =
2374 tx_sched_wrr_param[1];
2375 cds_ctx->ac_specs[i].send_limit =
2376 tx_sched_wrr_param[2];
2377 cds_ctx->ac_specs[i].credit_reserve =
2378 tx_sched_wrr_param[3];
2379 cds_ctx->ac_specs[i].discard_weight =
2380 tx_sched_wrr_param[4];
2381 }
2382
2383 num_entries = 0;
2384 }
2385}
2386
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002387#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002388static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2389 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2390{
Jeff Johnson9d295242017-08-29 14:39:48 -07002391 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002392 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002393
2394 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2395 if (!adapter) {
2396 hdd_err("Adapter is NULL");
2397 return PM_MAX_NUM_OF_MODE;
2398 }
2399
2400 return policy_mgr_convert_device_mode_to_qdf_type(
2401 adapter->device_mode);
2402}
2403
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002404static void hdd_register_policy_manager_callback(
2405 struct wlan_objmgr_psoc *psoc)
2406{
2407 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002408
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002409 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002410 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002411 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2412 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002413 hdd_cbacks.get_mode_for_non_connected_vdev =
2414 wlan_hdd_get_mode_for_non_connected_vdev;
2415
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002416 if (QDF_STATUS_SUCCESS !=
2417 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2418 hdd_err("HDD callback registration with policy manager failed");
2419 }
2420}
2421#else
2422static void hdd_register_policy_manager_callback(
2423 struct wlan_objmgr_psoc *psoc)
2424{
2425}
2426#endif
2427
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002428#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002429static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002430{
2431 struct nan_callbacks cb_obj = {0};
2432
2433 cb_obj.ndi_open = hdd_ndi_open;
2434 cb_obj.ndi_close = hdd_ndi_close;
2435 cb_obj.ndi_start = hdd_ndi_start;
2436 cb_obj.ndi_delete = hdd_ndi_delete;
2437 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2438 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2439
Naveen Rawat37f62c82017-03-26 22:24:43 -07002440 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2441 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002442 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002443
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002444 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2445}
2446#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002447static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002448{
2449}
2450#endif
2451
Dustin Brown26b3d042017-12-21 11:13:27 -08002452#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002453/**
2454 * hdd_check_for_leaks() - Perform runtime memory leak checks
2455 *
2456 * This API triggers runtime memory leak detection. This feature enforces the
2457 * policy that any memory allocated at runtime must also be released at runtime.
2458 *
2459 * Allocating memory at runtime and releasing it at unload is effectively a
2460 * memory leak for configurations which never unload (e.g. LONU, statically
2461 * compiled driver). Such memory leaks are NOT false positives, and must be
2462 * fixed.
2463 *
2464 * Return: None
2465 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002466static void hdd_check_for_leaks(void)
2467{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002468 /* DO NOT REMOVE these checks; for false positives, read above first */
2469
Dustin Brown677e0862017-10-10 16:30:09 -07002470 qdf_mc_timer_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002471 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002472}
2473
Dustin Brown26b3d042017-12-21 11:13:27 -08002474#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2475#else
2476static inline void hdd_check_for_leaks(void) {}
2477
2478#define hdd_debug_domain_set(domain)
2479#endif /* CONFIG_LEAK_DETECTION */
2480
gbian62edd7e2017-03-07 13:12:13 +08002481/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302482 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2483 * @hdd_ctx: HDD context
2484 * @adapter: HDD adapter
2485 * @reinit: flag to indicate from SSR or normal path
2486 *
2487 * This function maintains the driver state machine it will be invoked from
2488 * startup, reinit and change interface. Depending on the driver state shall
2489 * perform the opening of the modules.
2490 *
2491 * Return: 0 for success; non-zero for failure
2492 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002493int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2494 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302495 bool reinit)
2496{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002497 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302498 qdf_device_t qdf_dev;
2499 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302500 bool unint = false;
2501 void *hif_ctx;
2502
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002503 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302504
2505 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2506 if (!qdf_dev) {
2507 hdd_err("QDF Device Context is Invalid return");
2508 return -EINVAL;
2509 }
2510
Dustin Brown6f427922017-09-19 12:19:00 -07002511 hdd_set_idle_ps_config(hdd_ctx, false);
2512 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302513
Dustin Brown1fe30a82017-10-03 16:13:36 -07002514 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302515 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2516 mutex_unlock(&hdd_ctx->iface_change_lock);
2517 hdd_info("Driver modules already Enabled");
2518 EXIT();
2519 return 0;
2520 }
2521
Dustin Brown1fe30a82017-10-03 16:13:36 -07002522 hdd_ctx->start_modules_in_progress = true;
2523
Arun Khandavallifae92942016-08-01 13:31:08 +05302524 switch (hdd_ctx->driver_status) {
2525 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002526 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302527 unint = true;
2528 /* Fall through dont add break here */
2529 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002530 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2531
Dustin Brown26b3d042017-12-21 11:13:27 -08002532 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002533
Arun Khandavallifae92942016-08-01 13:31:08 +05302534 if (!reinit && !unint) {
2535 ret = pld_power_on(qdf_dev->dev);
2536 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002537 hdd_err("Failed to Powerup the device; errno: %d",
2538 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302539 goto release_lock;
2540 }
2541 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002542
2543 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2544 hdd_ctx->config->enable_fw_log);
2545
Arun Khandavallifae92942016-08-01 13:31:08 +05302546 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2547 qdf_dev->bus_type,
2548 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2549 HIF_ENABLE_TYPE_PROBE);
2550 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002551 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302552 goto power_down;
2553 }
2554
2555 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302556 if (!hif_ctx) {
2557 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002558 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302559 goto power_down;
2560 }
2561
Arun Khandavallifae92942016-08-01 13:31:08 +05302562 status = ol_cds_init(qdf_dev, hif_ctx);
2563 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002564 hdd_err("No Memory to Create BMI Context; status: %d",
2565 status);
2566 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302567 goto hif_close;
2568 }
2569
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002570 ret = hdd_update_config(hdd_ctx);
2571 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002572 hdd_err("Failed to update configuration; errno: %d",
2573 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002574 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002575 }
2576
gbian62edd7e2017-03-07 13:12:13 +08002577 hdd_update_cds_ac_specs_params(hdd_ctx);
2578
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302579 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002580 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002581 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002582 ret = qdf_status_to_os_return(status);
2583 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302584 }
2585
Mukul Sharma9d797a02017-01-05 20:26:03 +05302586 /* initalize components configurations after psoc open */
2587 ret = hdd_update_components_config(hdd_ctx);
2588 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002589 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302590 ret);
2591 goto close;
2592 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002593 status = cds_dp_open(hdd_ctx->hdd_psoc);
2594 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002595 hdd_err("Failed to Open cds post open; status: %d",
2596 status);
2597 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002598 goto close;
2599 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302600
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002601 /*
2602 * NAN compoenet requires certian operations like, open adapter,
2603 * close adapter, etc. to be initiated by HDD, for those
2604 * register HDD callbacks with UMAC's NAN componenet.
2605 */
2606 hdd_nan_register_callbacks(hdd_ctx);
2607
Arun Khandavallifae92942016-08-01 13:31:08 +05302608 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2609
Jeff Johnson3a280122017-09-13 07:42:00 -07002610 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302611 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002612 hdd_err("Failed to pre-enable CDS; status: %d", status);
2613 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002614 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302615 }
2616
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002617 hdd_register_policy_manager_callback(
2618 hdd_ctx->hdd_psoc);
2619
Amar Singhal0928b192017-12-01 10:50:54 -08002620 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2621
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302622 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302623 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002624 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302625
Arun Khandavallifae92942016-08-01 13:31:08 +05302626 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002627 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302628 break;
2629 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302630
2631 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002632 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2633 if (ret) {
2634 hdd_err("HDD IPA UC reinit failed; errno: %d",
2635 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002636 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002637 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302638 }
2639
Arun Khandavallifae92942016-08-01 13:31:08 +05302640 /* Fall through dont add break here */
2641 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002642 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2643
Arun Khandavallifae92942016-08-01 13:31:08 +05302644 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002645 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002646 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002647 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302648 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302649 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2650 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002651 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302652 break;
2653 }
Dustin Browndca39692017-11-09 15:30:25 -08002654
2655 ret = hdd_configure_cds(hdd_ctx, adapter);
2656 if (ret) {
2657 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002658 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302659 }
Dustin Browndca39692017-11-09 15:30:25 -08002660
Komal Seelamf2136bb2016-09-28 18:30:44 +05302661 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002662
Arun Khandavallifae92942016-08-01 13:31:08 +05302663 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002664 hdd_info("Wlan transitioned (now ENABLED)");
2665
Arun Khandavallifae92942016-08-01 13:31:08 +05302666 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002667
Arun Khandavallifae92942016-08-01 13:31:08 +05302668 default:
2669 hdd_err("WLAN start invoked in wrong state! :%d\n",
2670 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002671 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302672 goto release_lock;
2673 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002674
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302675 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302676 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002677
Arun Khandavallifae92942016-08-01 13:31:08 +05302678 EXIT();
Dustin Brown550f6d22017-12-14 15:44:01 -08002679
Arun Khandavallifae92942016-08-01 13:31:08 +05302680 return 0;
2681
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002682post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002683 cds_post_disable();
Dustin Brownbd68fe12017-11-21 15:28:52 -08002684 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002685
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002686cds_txrx_free:
2687 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002688
Arun Khandavallifae92942016-08-01 13:31:08 +05302689close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002690 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002691 hdd_info("Wlan transition aborted (now CLOSED)");
2692
Jeff Johnsone4b14592017-09-13 14:23:33 -07002693 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302694
Dustin Brown28b17892017-10-10 13:29:38 -07002695deinit_config:
2696 cds_deinit_ini_config();
2697
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002698cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302699 ol_cds_free();
2700
2701hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002702 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2703 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302704power_down:
2705 if (!reinit && !unint)
2706 pld_power_off(qdf_dev->dev);
2707release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302708 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302709 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002710
2711 /* many adapter resources are not freed by design in SSR case */
2712 if (!reinit)
2713 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002714 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002715
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302716 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002717
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002718 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302719}
2720
Naveen Rawat910726a2017-03-06 11:42:51 -08002721#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002722static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002723{
2724 int ret = os_if_wifi_pos_register_nl();
2725
2726 if (ret)
2727 hdd_err("os_if_wifi_pos_register_nl failed");
2728
2729 return ret;
2730}
2731
2732static int hdd_deactivate_wifi_pos(void)
2733{
2734 int ret = os_if_wifi_pos_deregister_nl();
2735
2736 if (ret)
2737 hdd_err("os_if_wifi_pos_deregister_nl failed");
2738
2739 return ret;
2740}
2741
2742/**
2743 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2744 * @hdd_ctx: hdd context
2745 *
2746 * Return: status of operation
2747 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002748static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002749{
2750 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2751 struct hdd_config *cfg = hdd_ctx->config;
2752
2753 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2754 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2755 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2756 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2757 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2758 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2759 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2760 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2761}
2762#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002763static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002764{
2765 return oem_activate_service(hdd_ctx);
2766}
2767
2768static int hdd_deactivate_wifi_pos(void)
2769{
2770 return 0;
2771}
2772
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002773static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002774{
2775}
2776#endif
2777
Arun Khandavallifae92942016-08-01 13:31:08 +05302778/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002779 * __hdd_open() - HDD Open function
2780 * @dev: Pointer to net_device structure
2781 *
2782 * This is called in response to ifconfig up
2783 *
2784 * Return: 0 for success; non-zero for failure
2785 */
2786static int __hdd_open(struct net_device *dev)
2787{
Jeff Johnson9d295242017-08-29 14:39:48 -07002788 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002789 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002790 int ret;
2791
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002792 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302793 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002794 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002795
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302796 /* Nothing to be done if device is unloading */
2797 if (cds_is_driver_unloading()) {
2798 hdd_err("Driver is unloading can not open the hdd");
2799 return -EBUSY;
2800 }
2801
Dustin Brown01847752017-10-25 13:56:27 -07002802 if (cds_is_driver_recovering()) {
2803 hdd_err("WLAN is currently recovering; Please try again.");
2804 return -EBUSY;
2805 }
2806
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302807 mutex_lock(&hdd_init_deinit_lock);
2808
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302809 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2810
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302811 /*
2812 * This scenario can be hit in cases where in the wlan driver after
2813 * registering the netdevices and there is a failure in driver
2814 * initialization. So return error gracefully because the netdevices
2815 * will be de-registered as part of the load failure.
2816 */
2817
2818 if (!cds_is_driver_loaded()) {
2819 hdd_err("Failed to start the wlan driver!!");
2820 ret = -EIO;
2821 goto err_hdd_hdd_init_deinit_lock;
2822 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302823
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002824
Arun Khandavallifae92942016-08-01 13:31:08 +05302825 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2826 if (ret) {
2827 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302828 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302829 }
2830
2831
2832 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2833 ret = hdd_start_adapter(adapter);
2834 if (ret) {
2835 hdd_err("Failed to start adapter :%d",
2836 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302837 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302838 }
2839 }
2840
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002841 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2842 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002843 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002844 /* Enable TX queues only when we are connected */
2845 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302846 WLAN_START_ALL_NETIF_QUEUE,
2847 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002848 }
2849
Naveen Rawat286def52016-09-23 15:38:02 -07002850 /* Enable carrier and transmit queues for NDI */
2851 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002852 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002853 wlan_hdd_netif_queue_control(adapter,
2854 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2855 WLAN_CONTROL_PATH);
2856 }
2857
Naveen Rawat910726a2017-03-06 11:42:51 -08002858 hdd_populate_wifi_pos_cfg(hdd_ctx);
2859
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302860err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302861 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302862 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002863 return ret;
2864}
2865
Arun Khandavallifae92942016-08-01 13:31:08 +05302866
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002867/**
2868 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2869 * @dev: Pointer to net_device structure
2870 *
2871 * This is called in response to ifconfig up
2872 *
2873 * Return: 0 for success; non-zero for failure
2874 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002875static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002876{
2877 int ret;
2878
2879 cds_ssr_protect(__func__);
2880 ret = __hdd_open(dev);
2881 cds_ssr_unprotect(__func__);
2882
2883 return ret;
2884}
2885
2886/**
2887 * __hdd_stop() - HDD stop function
2888 * @dev: Pointer to net_device structure
2889 *
2890 * This is called in response to ifconfig down
2891 *
2892 * Return: 0 for success; non-zero for failure
2893 */
2894static int __hdd_stop(struct net_device *dev)
2895{
Jeff Johnson9d295242017-08-29 14:39:48 -07002896 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002897 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002898 int ret;
2899
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002900 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002901
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302902 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002903 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002904
2905 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302906 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002907 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002908
2909 /* Nothing to be done if the interface is not opened */
2910 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002911 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002912 return -ENODEV;
2913 }
2914
2915 /* Make sure the interface is marked as closed */
2916 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302917
2918 hdd_debug("Disabling Auto Power save timer");
2919 sme_ps_disable_auto_ps_timer(
2920 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002921 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302922
2923 /*
2924 * Disable TX on the interface, after this hard_start_xmit() will not
2925 * be called on that interface
2926 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002927 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2928 hdd_device_mode_to_string(adapter->device_mode),
2929 adapter->device_mode);
2930
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302931 wlan_hdd_netif_queue_control(adapter,
2932 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2933 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002934
2935 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002936 * NAN data interface is different in some sense. The traffic on NDI is
2937 * bursty in nature and depends on the need to transfer. The service
2938 * layer may down the interface after the usage and up again when
2939 * required. In some sense, the NDI is expected to be available
2940 * (like SAP) iface until NDI delete request is issued by the service
2941 * layer. Skip BSS termination and adapter deletion for NAN Data
2942 * interface (NDI).
2943 */
2944 if (WLAN_HDD_IS_NDI(adapter))
2945 return 0;
2946
2947 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002948 * The interface is marked as down for outside world (aka kernel)
2949 * But the driver is pretty much alive inside. The driver needs to
2950 * tear down the existing connection on the netdev (session)
2951 * cleanup the data pipes and wait until the control plane is stabilized
2952 * for this interface. The call also needs to wait until the above
2953 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002954 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002955 * That is intentional to be able to scan if it is a STA/P2P interface
2956 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002957 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002958
2959 /* DeInit the adapter. This ensures datapath cleanup as well */
2960 hdd_deinit_adapter(hdd_ctx, adapter, true);
2961
Arun Khandavallifae92942016-08-01 13:31:08 +05302962
2963 /*
2964 * Find if any iface is up. If any iface is up then can't put device to
2965 * sleep/power save mode
2966 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302967 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002968 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07002969 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
2970 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302971 hdd_prevent_suspend_timeout(
2972 hdd_ctx->config->iface_change_wait_time,
2973 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302974 }
2975
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002976 EXIT();
2977 return 0;
2978}
2979
2980/**
2981 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2982 * @dev: pointer to net_device structure
2983 *
2984 * This is called in response to ifconfig down
2985 *
2986 * Return: 0 for success and error number for failure
2987 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002988static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002989{
2990 int ret;
2991
2992 cds_ssr_protect(__func__);
2993 ret = __hdd_stop(dev);
2994 cds_ssr_unprotect(__func__);
2995
2996 return ret;
2997}
2998
2999/**
3000 * __hdd_uninit() - HDD uninit function
3001 * @dev: Pointer to net_device structure
3002 *
3003 * This is called during the netdev unregister to uninitialize all data
3004 * associated with the device
3005 *
3006 * Return: None
3007 */
3008static void __hdd_uninit(struct net_device *dev)
3009{
Jeff Johnson9d295242017-08-29 14:39:48 -07003010 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003011 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003012
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003013 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003014
3015 do {
3016 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003017 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003018 break;
3019 }
3020
Jeff Johnson399c6272017-08-30 10:51:00 -07003021 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3022 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003023 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003024 break;
3025 }
3026
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003027 if (dev != adapter->dev)
3028 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029
Jeff Johnson399c6272017-08-30 10:51:00 -07003030 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003031
3032 /* after uninit our adapter structure will no longer be valid */
3033 adapter->dev = NULL;
3034 adapter->magic = 0;
3035 } while (0);
3036
3037 EXIT();
3038}
3039
3040/**
3041 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3042 * @dev: pointer to net_device structure
3043 *
3044 * This is called during the netdev unregister to uninitialize all data
3045 * associated with the device
3046 *
3047 * Return: none
3048 */
3049static void hdd_uninit(struct net_device *dev)
3050{
3051 cds_ssr_protect(__func__);
3052 __hdd_uninit(dev);
3053 cds_ssr_unprotect(__func__);
3054}
3055
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003056static int hdd_open_cesium_nl_sock(void)
3057{
3058#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3059 struct netlink_kernel_cfg cfg = {
3060 .groups = WLAN_NLINK_MCAST_GRP_ID,
3061 .input = NULL
3062 };
3063#endif
3064 int ret = 0;
3065
3066#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3067 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3068#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3069 THIS_MODULE,
3070#endif
3071 &cfg);
3072#else
3073 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3074 WLAN_NLINK_MCAST_GRP_ID,
3075 NULL, NULL, THIS_MODULE);
3076#endif
3077
3078 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003079 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003080 ret = -ECONNREFUSED;
3081 }
3082
3083 return ret;
3084}
3085
3086static void hdd_close_cesium_nl_sock(void)
3087{
3088 if (NULL != cesium_nl_srv_sock) {
3089 netlink_kernel_release(cesium_nl_srv_sock);
3090 cesium_nl_srv_sock = NULL;
3091 }
3092}
3093
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003094/**
3095 * __hdd_set_mac_address() - set the user specified mac address
3096 * @dev: Pointer to the net device.
3097 * @addr: Pointer to the sockaddr.
3098 *
3099 * This function sets the user specified mac address using
3100 * the command ifconfig wlanX hw ether <mac adress>.
3101 *
3102 * Return: 0 for success, non zero for failure
3103 */
3104static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3105{
Jeff Johnson9d295242017-08-29 14:39:48 -07003106 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003107 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303109 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110 int ret;
3111
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003112 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003113
3114 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3115 ret = wlan_hdd_validate_context(hdd_ctx);
3116 if (0 != ret)
3117 return ret;
3118
Jeff Johnson1e851a12017-10-28 14:36:12 -07003119 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003120 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3121
3122 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303123 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124}
3125
3126/**
3127 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3128 * function from SSR
3129 * @dev: pointer to net_device structure
3130 * @addr: Pointer to the sockaddr
3131 *
3132 * This function sets the user specified mac address using
3133 * the command ifconfig wlanX hw ether <mac adress>.
3134 *
3135 * Return: 0 for success.
3136 */
3137static int hdd_set_mac_address(struct net_device *dev, void *addr)
3138{
3139 int ret;
3140
3141 cds_ssr_protect(__func__);
3142 ret = __hdd_set_mac_address(dev, addr);
3143 cds_ssr_unprotect(__func__);
3144
3145 return ret;
3146}
3147
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003148uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003149{
3150 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003151
Anurag Chouhan6d760662016-02-20 16:05:43 +05303152 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3154 break;
3155 }
3156
Anurag Chouhan6d760662016-02-20 16:05:43 +05303157 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158 return NULL;
3159
3160 hdd_ctx->config->intfAddrMask |= (1 << i);
3161 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3162}
3163
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003164void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3165 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166{
3167 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003168
Anurag Chouhan6d760662016-02-20 16:05:43 +05303169 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003170 if (!memcmp(releaseAddr,
3171 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3172 6)) {
3173 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3174 break;
3175 }
3176 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177}
3178
3179#ifdef WLAN_FEATURE_PACKET_FILTERING
3180/**
3181 * __hdd_set_multicast_list() - set the multicast address list
3182 * @dev: Pointer to the WLAN device.
3183 * @skb: Pointer to OS packet (sk_buff).
3184 *
3185 * This funciton sets the multicast address list.
3186 *
3187 * Return: None
3188 */
3189static void __hdd_set_multicast_list(struct net_device *dev)
3190{
Jeff Johnson9d295242017-08-29 14:39:48 -07003191 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192 int i = 0, status;
3193 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003194 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303195 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3196 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3197 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003199 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303200 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303201 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303202
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003203 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303204 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303205 goto out;
3206
Dustin Brownc788acb2017-08-01 17:43:51 -07003207 status = hdd_validate_adapter(adapter);
3208 if (status)
3209 goto out;
3210
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303211 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3212 hdd_err("%s: Driver module is closed", __func__);
3213 return;
3214 }
3215
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303216 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3217 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003218 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303219 goto out;
3220 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003221
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303222 /* Delete already configured multicast address list */
3223 if (adapter->mc_addr_list.mc_cnt > 0) {
3224 hdd_info("clear previously configured MC address list");
3225 hdd_disable_and_flush_mc_addr_list(adapter,
3226 pmo_mc_list_change_notify);
3227 }
3228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003229 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003230 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303231 hdd_disable_and_flush_mc_addr_list(adapter,
3232 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003233 } else {
3234 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303235 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003236 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303237 pmo_ucfg_max_mc_addr_supported(psoc));
3238 hdd_disable_and_flush_mc_addr_list(adapter,
3239 pmo_mc_list_change_notify);
3240 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003242 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003243 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303244 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003245 if (i == mc_count)
3246 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303247 memset(&(mc_list_request->mc_addr[i].bytes),
3248 0, ETH_ALEN);
3249 memcpy(&(mc_list_request->mc_addr[i].bytes),
3250 ha->addr, ETH_ALEN);
3251 hdd_info("mlist[%d] = %pM", i,
3252 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253 i++;
3254 }
3255 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303256
3257 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003258 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303259 mc_list_request->count = mc_count;
3260 status = hdd_cache_mc_addr_list(mc_list_request);
3261 if (status == 0) {
3262 hdd_enable_mc_addr_filtering(adapter,
3263 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303265 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003266 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303267out:
3268 if (mc_list_request)
3269 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303270 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003271}
3272
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303273
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003274/**
3275 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3276 * @dev: pointer to net_device
3277 *
3278 * Return: none
3279 */
3280static void hdd_set_multicast_list(struct net_device *dev)
3281{
3282 cds_ssr_protect(__func__);
3283 __hdd_set_multicast_list(dev);
3284 cds_ssr_unprotect(__func__);
3285}
3286#endif
3287
3288/**
3289 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3290 * @dev: Pointer to the WLAN device.
3291 * @skb: Pointer to OS packet (sk_buff).
3292 *
3293 * This function is registered with the Linux OS for network
3294 * core to decide which queue to use first.
3295 *
3296 * Return: ac, Queue Index/access category corresponding to UP in IP header
3297 */
3298static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3299#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3300 , void *accel_priv
3301#endif
3302#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3303 , select_queue_fallback_t fallback
3304#endif
3305)
3306{
3307 return hdd_wmm_select_queue(dev, skb);
3308}
3309
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003310static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003311 .ndo_open = hdd_open,
3312 .ndo_stop = hdd_stop,
3313 .ndo_uninit = hdd_uninit,
3314 .ndo_start_xmit = hdd_hard_start_xmit,
3315 .ndo_tx_timeout = hdd_tx_timeout,
3316 .ndo_get_stats = hdd_get_stats,
3317 .ndo_do_ioctl = hdd_ioctl,
3318 .ndo_set_mac_address = hdd_set_mac_address,
3319 .ndo_select_queue = hdd_select_queue,
3320#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003321 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003322#endif
3323};
3324
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003325/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003326static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003327 .ndo_open = hdd_mon_open,
3328 .ndo_stop = hdd_stop,
3329 .ndo_get_stats = hdd_get_stats,
3330};
3331
3332/**
3333 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003334 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003335 * Return: None
3336 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003337void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003338{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003339 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003340 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003341 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003342 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003343}
3344
3345/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003346 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3347 * @hdd_ctx: global hdd context
3348 * @macAddr: mac address to assign to the interface
3349 * @name: User-visible name of the interface
3350 *
3351 * hdd adapter pointer would point to the netdev->priv space, this function
3352 * would retrive the pointer, and setup the hdd adapter configuration.
3353 *
3354 * Return: the pointer to hdd adapter, otherwise NULL
3355 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003356static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003357 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003358 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359 const char *name)
3360{
Jeff Johnson5505db82017-11-02 21:19:23 -07003361 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003362 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003363 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303364 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003365 /*
3366 * cfg80211 initialization and registration....
3367 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003368 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003369#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3370 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003372 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3373 hdd_mon_mode_ether_setup : ether_setup),
3374 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375
Jeff Johnson5505db82017-11-02 21:19:23 -07003376 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003377
3378 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003379 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003380
Jeff Johnson9d295242017-08-29 14:39:48 -07003381 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003382 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303383 qdf_mem_set(sta_ctx->conn_info.staId,
3384 sizeof(sta_ctx->conn_info.staId),
3385 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003386 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003387 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003388 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003389 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003390
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303391 qdf_status = qdf_event_create(
3392 &adapter->qdf_session_open_event);
3393 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3394 hdd_err("Session open QDF event init failed!");
3395 free_netdev(adapter->dev);
3396 return NULL;
3397 }
3398
3399 qdf_status = qdf_event_create(
3400 &adapter->qdf_session_close_event);
3401 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3402 hdd_err("Session close QDF event init failed!");
3403 free_netdev(adapter->dev);
3404 return NULL;
3405 }
3406
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303408 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409 init_completion(&adapter->linkup_event_var);
3410 init_completion(&adapter->cancel_rem_on_chan_var);
3411 init_completion(&adapter->rem_on_chan_ready_event);
3412 init_completion(&adapter->sta_authorized_event);
3413 init_completion(&adapter->offchannel_tx_event);
3414 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003415 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303417 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003418
3419 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003420 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003422 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423
Jeff Johnson5505db82017-11-02 21:19:23 -07003424 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003425 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003426 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003427 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003428 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429
3430 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003431 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003433 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434
Jeff Johnson5505db82017-11-02 21:19:23 -07003435 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437 hdd_set_station_ops(adapter->dev);
3438
Jeff Johnson5505db82017-11-02 21:19:23 -07003439 hdd_dev_setup_destructor(dev);
3440 dev->ieee80211_ptr = &adapter->wdev;
3441 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003442 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003443 adapter->wdev.netdev = dev;
3444 /* set dev's parent to underlying device */
3445 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003446 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303447 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003448 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303449 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 }
3451
3452 return adapter;
3453}
3454
Jeff Johnson9d295242017-08-29 14:39:48 -07003455static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003456{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003457 struct net_device *dev = adapter->dev;
3458 int ret;
3459
3460 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003462 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003463 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3464
3465 ret = dev_alloc_name(dev, dev->name);
3466 if (ret < 0) {
3467 hdd_err(
3468 "unable to get dev name: %s, err = 0x%x",
3469 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303470 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 }
3472 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003473
3474 ret = register_netdevice(dev);
3475 if (ret) {
3476 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3477 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303478 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 }
3480 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003481 ret = register_netdev(dev);
3482 if (ret) {
3483 hdd_err("register_netdev(%s) failed, err = 0x%x",
3484 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303485 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003486 }
3487 }
3488 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3489
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003490 EXIT();
3491
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303492 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493}
3494
Krunal Sonib51eec72017-11-20 21:53:01 -08003495QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003496{
Krunal Sonib51eec72017-11-20 21:53:01 -08003497 struct hdd_adapter *adapter;
3498 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499
Krunal Sonib51eec72017-11-20 21:53:01 -08003500 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3501 if (!hdd_ctx) {
3502 hdd_err("Invalid HDD_CTX");
3503 return QDF_STATUS_E_FAILURE;
3504 }
3505
3506 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3507 if (NULL == adapter) {
3508 hdd_err("NULL adapter");
3509 return QDF_STATUS_E_INVAL;
3510 }
3511 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303512 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003513 hdd_debug("session %d opened", adapter->session_id);
3514
3515 return QDF_STATUS_SUCCESS;
3516}
3517
3518QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3519{
3520 struct hdd_adapter *adapter;
3521 struct hdd_context *hdd_ctx;
3522
3523 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3524 if (!hdd_ctx) {
3525 hdd_err("Invalid HDD_CTX");
3526 return QDF_STATUS_E_FAILURE;
3527 }
3528
3529 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003531 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303532 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003533 }
3534
3535 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003536 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303537 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538 }
3539
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003540 /*
3541 * For NAN Data interface, the close session results in the final
3542 * indication to the userspace
3543 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003544 if (adapter->device_mode == QDF_NDI_MODE)
3545 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003546
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003547 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3548
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003549 /*
3550 * We can be blocked while waiting for scheduled work to be
3551 * flushed, and the adapter structure can potentially be freed, in
3552 * which case the magic will have been reset. So make sure the
3553 * magic is still good, and hence the adapter structure is still
3554 * valid, before signaling completion
3555 */
3556 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303557 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003558
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303559 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560}
3561
Jeff Johnson9d295242017-08-29 14:39:48 -07003562int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003563{
Dustin Brownd28772b2017-03-17 14:16:07 -07003564 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003565
Dustin Brownd28772b2017-03-17 14:16:07 -07003566 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003567 if (QDF_IS_STATUS_ERROR(status))
3568 return qdf_status_to_os_return(status);
3569
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003570 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003571 if (QDF_IS_STATUS_ERROR(status))
3572 return qdf_status_to_os_return(status);
3573
3574 if (wma_capability_enhanced_mcast_filter())
3575 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3576 else
3577 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003578
3579 return qdf_status_to_os_return(status);
3580}
3581
Jeff Johnson9d295242017-08-29 14:39:48 -07003582int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003583{
3584 QDF_STATUS status;
3585 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003586 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003587 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003588
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003589 vdev_id = adapter->session_id;
3590 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003591
3592 /* vdev created sanity check */
3593 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003594 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003595 return -EINVAL;
3596 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003597 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003598 /*
3599 * In SSR case, there is no need to destroy vdev in firmware since
3600 * it has already asserted. vdev can be released directly.
3601 */
Krunal Sonib51eec72017-11-20 21:53:01 -08003602 if (cds_is_driver_recovering()) {
3603 hdd_debug("SSR: silently release the vdev for session-id: %d",
3604 adapter->session_id);
3605 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Yue Maf9782842017-05-08 12:49:49 -07003606 goto release_vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08003607 }
Yue Maf9782842017-05-08 12:49:49 -07003608
Dustin Brownd28772b2017-03-17 14:16:07 -07003609 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303610 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003611 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003612 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003613 if (QDF_IS_STATUS_ERROR(status)) {
3614 hdd_err("failed to close sme session: %d", status);
3615 return qdf_status_to_os_return(status);
3616 }
3617
3618 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303619 status = qdf_wait_for_event_completion(
3620 &adapter->qdf_session_close_event,
3621 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3622 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003623 if (adapter->device_mode == QDF_NDI_MODE)
3624 hdd_ndp_session_end_handler(adapter);
3625 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303626 adapter->session_id = HDD_SESSION_ID_INVALID;
3627 if (QDF_STATUS_E_TIMEOUT != status) {
3628 hdd_err("timed out waiting for close sme session: %u", status);
3629 return -ETIMEDOUT;
3630 } else if (adapter->qdf_session_close_event.force_set) {
3631 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
3632 return -EINVAL;
3633 } else {
3634 hdd_err("Failed to close sme session (%u)", status);
3635 return -EINVAL;
3636 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003637 }
Yue Maf9782842017-05-08 12:49:49 -07003638release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003639 /* do vdev logical destroy via objmgr */
3640 errno = hdd_objmgr_destroy_vdev(adapter);
3641 if (errno) {
3642 hdd_err("failed to destroy objmgr vdev: %d", errno);
3643 return errno;
3644 }
3645
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003646 /* now that sme session is closed, allow physical vdev destroy */
3647 errno = hdd_objmgr_release_vdev(adapter);
3648 if (errno) {
3649 hdd_err("failed to release objmgr vdev: %d", errno);
3650 return errno;
3651 }
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003652 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003653
3654 return 0;
3655}
3656
Krunal Sonib51eec72017-11-20 21:53:01 -08003657static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3658 struct sme_session_params *session_param,
3659 csr_roam_completeCallback callback,
3660 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003661{
Dustin Brownd28772b2017-03-17 14:16:07 -07003662 uint32_t type;
3663 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003664 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003665
3666 /* determine vdev (sub)type */
3667 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303668 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003669 hdd_err("failed to get vdev type: %d", status);
3670 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003671 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003672 session_param->sme_session_id = adapter->session_id;
3673 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3674 session_param->type_of_persona = type;
3675 session_param->subtype_of_persona = sub_type;
3676 session_param->session_open_cb = hdd_sme_open_session_callback;
3677 session_param->session_close_cb = hdd_sme_close_session_callback;
3678 session_param->callback = callback;
3679 session_param->callback_ctx = callback_ctx;
3680
3681 return 0;
3682}
3683
3684int hdd_vdev_create(struct hdd_adapter *adapter,
3685 csr_roam_completeCallback callback, void *ctx)
3686{
3687 QDF_STATUS status;
3688 int errno;
3689 struct hdd_context *hdd_ctx;
3690 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003691
3692 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003693
3694 /* do vdev create via objmgr */
3695 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003696 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003697 if (errno) {
3698 hdd_err("failed to create objmgr vdev: %d", errno);
3699 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003701
3702 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303703 status = qdf_event_reset(&adapter->qdf_session_open_event);
3704 if (QDF_STATUS_SUCCESS != status) {
3705 hdd_err("failed to reinit session open event");
3706 return -EINVAL;
3707 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003708 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3709 callback, ctx);
3710 if (errno) {
3711 hdd_err("failed to populating SME params");
3712 goto objmgr_vdev_destroy_procedure;
3713 }
3714
3715 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003716 if (QDF_IS_STATUS_ERROR(status)) {
3717 hdd_err("failed to open sme session: %d", status);
3718 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003719 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003720 }
3721
3722 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303723 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3724 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3725 if (QDF_STATUS_SUCCESS != status) {
3726 if (adapter->qdf_session_open_event.force_set) {
3727 /*
3728 * SSR/PDR has caused shutdown, which has forcefully
3729 * set the event. Return without the closing session.
3730 */
3731 adapter->session_id = HDD_SESSION_ID_INVALID;
3732 hdd_err("Session open event forcefully set");
3733 return -EINVAL;
3734 } else {
3735 if (QDF_STATUS_E_TIMEOUT == status)
3736 hdd_err("Session failed to open within timeout period");
3737 else
3738 hdd_err("Failed to wait for session open event(status-%d)",
3739 status);
3740 errno = -ETIMEDOUT;
3741 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3742 goto hdd_vdev_destroy_procedure;
3743 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003744 }
3745
3746 /* firmware ready for component communication, raise vdev_ready event */
3747 errno = hdd_vdev_ready(adapter);
3748 if (errno) {
3749 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003750 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003751 }
3752
Jeff Johnson1b780e42017-10-31 14:11:45 -07003753 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003754
3755 return 0;
3756
3757 /*
3758 * Due to legacy constraints, we need to destroy in the same order as
3759 * create. So, split error handling into 2 cases to accommodate.
3760 */
3761
Krunal Soni4a020c72017-10-30 20:58:40 -07003762objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003763 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003764
3765 return errno;
3766
Krunal Soni4a020c72017-10-30 20:58:40 -07003767hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003768 QDF_BUG(!hdd_vdev_destroy(adapter));
3769
3770 return errno;
3771}
3772
Jeff Johnson9d295242017-08-29 14:39:48 -07003773QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003774{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003775 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003776 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003777 QDF_STATUS status;
3778 int ret_val;
3779
Dustin Brownd28772b2017-03-17 14:16:07 -07003780 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3781 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3782 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003783 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003784
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003786 status = hdd_register_wext(adapter->dev);
3787 if (QDF_IS_STATUS_ERROR(status)) {
3788 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003789 goto error_register_wext;
3790 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003791 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003792
Himanshu Agarwalb229a142017-12-21 10:16:45 +05303793 hdd_debug("Disabling Green AP");
3794 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev, false);
3795 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
3796
Jeff Johnsond377dce2017-10-04 10:32:42 -07003797 qdf_mem_set(sta_ctx->conn_info.staId,
3798 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303799
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003800 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003801 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303802 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003803 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003804 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003805 hdd_ctx->config->OperatingChannel;
3806
3807 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003808 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003809
3810 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303811 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003812 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 status, status);
3814 goto error_init_txrx;
3815 }
3816
3817 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3818
3819 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303820 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003821 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003822 status, status);
3823 goto error_wmm_init;
3824 }
3825
3826 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3827
Jeff Johnson1b780e42017-10-31 14:11:45 -07003828 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003829 WMI_PDEV_PARAM_BURST_ENABLE,
3830 hdd_ctx->config->enableSifsBurst,
3831 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003832 if (ret_val)
3833 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003834
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303835 /*
3836 * In case of USB tethering, LRO is disabled. If SSR happened
3837 * during that time, then as part of SSR init, do not enable
3838 * the LRO again. Keep the LRO state same as before SSR.
3839 */
3840 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003841 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303842
3843 /* rcpi info initialization */
3844 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3845
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303846 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003847
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003848error_wmm_init:
3849 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3850 hdd_deinit_tx_rx(adapter);
3851error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003852 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003853error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003854 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003856 return status;
3857}
3858
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303859/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003860 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303861 * @hdd_ctx: global hdd context
3862 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003863 * @rtnl_held: Used to indicate whether or not the caller is holding
3864 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303865 *
3866 * This function De-initializes the STA/P2P/OCB adapter.
3867 *
3868 * Return: None.
3869 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003870static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003871 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003872 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303873{
3874 ENTER_DEV(adapter->dev);
3875
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303876 if (adapter->dev) {
3877 if (rtnl_held)
3878 adapter->dev->wireless_handlers = NULL;
3879 else {
3880 rtnl_lock();
3881 adapter->dev->wireless_handlers = NULL;
3882 rtnl_unlock();
3883 }
3884 }
3885
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303886 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3887 hdd_deinit_tx_rx(adapter);
3888 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3889 }
3890
3891 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3892 hdd_wmm_adapter_close(adapter);
3893 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3894 }
3895
Krunal Sonib51eec72017-11-20 21:53:01 -08003896
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303897 EXIT();
3898}
3899
Krunal Sonib51eec72017-11-20 21:53:01 -08003900void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3901 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003902 bool rtnl_held)
3903{
3904 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303905
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003907 case QDF_STA_MODE:
3908 case QDF_P2P_CLIENT_MODE:
3909 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003910 case QDF_IBSS_MODE:
3911 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003912 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003913 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 break;
3915 }
3916
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003917 case QDF_SAP_MODE:
3918 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003919 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003920 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003921 break;
3922 }
3923
3924 default:
3925 break;
3926 }
3927
3928 EXIT();
3929}
3930
Jeff Johnson9d295242017-08-29 14:39:48 -07003931static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003932 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933{
Jeff Johnson5505db82017-11-02 21:19:23 -07003934 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935
3936 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003937 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003939 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940 return;
3941 }
3942
Rajeev Kumardca5f812016-02-04 17:28:06 -08003943 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303944
Yue Ma9e89e832017-11-14 11:40:23 -08003945 hdd_adapter_runtime_suspend_deinit(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947 /*
3948 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3949 * the driver is almost closed and cannot handle either control
3950 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003951 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3952 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953 * is not right. Setting this flag helps hdd_stop() to recognize that
3954 * the interface is closed and restricts any operations on that
3955 */
3956 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3957
3958 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003959 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003960 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003961 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003962 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963 /*
3964 * Note that the adapter is no longer valid at this point
3965 * since the memory has been reclaimed
3966 */
3967 }
3968}
3969
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003970static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003971 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972{
Jeff Johnson9d295242017-08-29 14:39:48 -07003973 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003974
Dustin Brown920397d2017-12-13 16:27:50 -08003975 hdd_for_each_adapter(hdd_ctx, adapter) {
3976 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
3977 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303978 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 }
Dustin Brown920397d2017-12-13 16:27:50 -08003981
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303982 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003984
Arun Khandavalli2358d522016-05-16 18:05:37 +05303985#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3986/**
3987 * hdd_set_fw_log_params() - Set log parameters to FW
3988 * @hdd_ctx: HDD Context
3989 * @adapter: HDD Adapter
3990 *
3991 * This function set the FW Debug log level based on the INI.
3992 *
3993 * Return: None
3994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003995static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003996 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303997{
3998 uint8_t count = 0, numentries = 0,
3999 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4000 uint32_t value = 0;
4001 int ret;
4002
Arun Khandavallifae92942016-08-01 13:31:08 +05304003 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4004 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004005 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304006 return;
4007 }
4008
Arun Khandavallifae92942016-08-01 13:31:08 +05304009 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304010 hdd_ctx->fw_log_settings.dl_type =
4011 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004012 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304013 WMI_DBGLOG_TYPE,
4014 hdd_ctx->config->enableFwLogType,
4015 DBG_CMD);
4016 if (ret != 0)
4017 hdd_err("Failed to enable FW log type ret %d",
4018 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304019
4020 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304021 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004022 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304023 WMI_DBGLOG_LOG_LEVEL,
4024 hdd_ctx->config->enableFwLogLevel,
4025 DBG_CMD);
4026 if (ret != 0)
4027 hdd_err("Failed to enable FW log level ret %d",
4028 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304029
4030 hdd_string_to_u8_array(
4031 hdd_ctx->config->enableFwModuleLogLevel,
4032 moduleloglevel,
4033 &numentries,
4034 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4035
4036 while (count < numentries) {
4037 /*
4038 * FW module log level input string looks like
4039 * below:
4040 * gFwDebugModuleLoglevel=<FW Module ID>,
4041 * <Log Level>,...
4042 * For example:
4043 * gFwDebugModuleLoglevel=
4044 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4045 * Above input string means :
4046 * For FW module ID 1 enable log level 0
4047 * For FW module ID 2 enable log level 1
4048 * For FW module ID 3 enable log level 2
4049 * For FW module ID 4 enable log level 3
4050 * For FW module ID 5 enable log level 4
4051 * For FW module ID 6 enable log level 5
4052 * For FW module ID 7 enable log level 6
4053 */
4054
Nishank Aggarwale239d962017-03-03 12:26:02 +05304055 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4056 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4057 hdd_err("Module id %d and dbglog level %d input length is more than max",
4058 moduleloglevel[count],
4059 moduleloglevel[count + 1]);
4060 return;
4061 }
4062
4063 value = moduleloglevel[count] << 16;
4064 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004065 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304066 WMI_DBGLOG_MOD_LOG_LEVEL,
4067 value, DBG_CMD);
4068 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304069 hdd_err("Failed to enable FW module log level %d ret %d",
4070 value, ret);
4071
4072 count += 2;
4073 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304074
Arun Khandavalli2358d522016-05-16 18:05:37 +05304075}
4076#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004077static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004078 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304079{
4080}
4081
4082#endif
4083
4084/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004085 * hdd_configure_chain_mask() - programs chain mask to firmware
4086 * @adapter: HDD adapter
4087 *
4088 * Return: 0 on success or errno on failure
4089 */
4090static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4091{
4092 int ret_val;
4093 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4094
4095 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4096 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4097 hdd_ctx->config->txchainmask1x1,
4098 hdd_ctx->config->rxchainmask1x1);
4099 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4100 hdd_ctx->config->dual_mac_feature_disable,
4101 hdd_ctx->config->tx_chain_mask_2g,
4102 hdd_ctx->config->rx_chain_mask_2g);
4103 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4104 hdd_ctx->config->tx_chain_mask_5g,
4105 hdd_ctx->config->rx_chain_mask_5g);
4106
4107 if (hdd_ctx->config->enable2x2) {
4108 hdd_info("2x2 enabled. skip chain mask programming");
4109 return 0;
4110 }
4111
4112 if (hdd_ctx->config->txchainmask1x1) {
4113 ret_val = sme_cli_set_command(adapter->session_id,
4114 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4115 hdd_ctx->config->txchainmask1x1,
4116 PDEV_CMD);
4117 if (ret_val)
4118 goto error;
4119 }
4120
4121 if (hdd_ctx->config->rxchainmask1x1) {
4122 ret_val = sme_cli_set_command(adapter->session_id,
4123 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4124 hdd_ctx->config->rxchainmask1x1,
4125 PDEV_CMD);
4126 if (ret_val)
4127 goto error;
4128 }
4129
4130 if (hdd_ctx->lte_coex_ant_share) {
4131 hdd_info("lte ant sharing enabled. skip per band chain mask");
4132 return 0;
4133 }
4134
4135 if (hdd_ctx->config->txchainmask1x1 ||
4136 hdd_ctx->config->rxchainmask1x1) {
4137 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4138 return 0;
4139 }
4140
4141 if (!hdd_ctx->config->dual_mac_feature_disable) {
4142 hdd_info("DBS enabled. skip per band chain mask");
4143 return 0;
4144 }
4145
4146 if (hdd_ctx->config->tx_chain_mask_2g) {
4147 ret_val = sme_cli_set_command(adapter->session_id,
4148 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4149 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4150 if (0 != ret_val)
4151 goto error;
4152 }
4153
4154 if (hdd_ctx->config->rx_chain_mask_2g) {
4155 ret_val = sme_cli_set_command(adapter->session_id,
4156 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4157 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4158 if (0 != ret_val)
4159 goto error;
4160 }
4161
4162 if (hdd_ctx->config->tx_chain_mask_5g) {
4163 ret_val = sme_cli_set_command(adapter->session_id,
4164 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4165 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4166 if (0 != ret_val)
4167 goto error;
4168 }
4169
4170 if (hdd_ctx->config->rx_chain_mask_5g) {
4171 ret_val = sme_cli_set_command(adapter->session_id,
4172 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4173 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4174 if (0 != ret_val)
4175 goto error;
4176 }
4177
4178 return 0;
4179
4180error:
4181 hdd_err("WMI PDEV set param failed %d", ret_val);
4182 return -EINVAL;
4183}
4184
4185/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304186 * hdd_set_fw_params() - Set parameters to firmware
4187 * @adapter: HDD adapter
4188 *
4189 * This function Sets various parameters to fw once the
4190 * adapter is started.
4191 *
4192 * Return: 0 on success or errno on failure
4193 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004194int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304195{
4196 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004197 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304198
4199 ENTER_DEV(adapter->dev);
4200
4201 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4202 if (!hdd_ctx)
4203 return -EINVAL;
4204
Dustin Brown732ab9c2017-06-15 13:24:09 -07004205 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4206 hdd_debug("FTM Mode is active; nothing to do");
4207 return 0;
4208 }
4209
Jeff Johnson1b780e42017-10-31 14:11:45 -07004210 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304211 WMI_PDEV_PARAM_DTIM_SYNTH,
4212 hdd_ctx->config->enable_lprx, PDEV_CMD);
4213 if (ret) {
4214 hdd_err("Failed to set LPRx");
4215 goto error;
4216 }
4217
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304218 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004219 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304220 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4221 hdd_ctx->config->upper_brssi_thresh);
4222
Jeff Johnson1b780e42017-10-31 14:11:45 -07004223 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304224 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4225 hdd_ctx->config->lower_brssi_thresh);
4226
Jeff Johnson1b780e42017-10-31 14:11:45 -07004227 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304228 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4229 hdd_ctx->config->enable_dtim_1chrx);
4230 }
4231
Dustin Brown732ab9c2017-06-15 13:24:09 -07004232 if (hdd_ctx->config->enable2x2) {
4233 hdd_debug("configuring 2x2 mode fw params");
4234
Jeff Johnson1b780e42017-10-31 14:11:45 -07004235 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004236 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4237 hdd_ctx->config->enable_cck_tx_fir_override,
4238 PDEV_CMD);
4239 if (ret) {
4240 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4241 ret);
4242 goto error;
4243 }
4244 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304245#define HDD_DTIM_1CHAIN_RX_ID 0x5
4246#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004247 hdd_debug("configuring 1x1 mode fw params");
4248
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004249 /*
4250 * Disable DTIM 1 chain Rx when in 1x1,
4251 * we are passing two value
4252 * as param_id << 29 | param_value.
4253 * Below param_value = 0(disable)
4254 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004255 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004256 WMI_STA_SMPS_PARAM_CMDID,
4257 HDD_DTIM_1CHAIN_RX_ID <<
4258 HDD_SMPS_PARAM_VALUE_S,
4259 VDEV_CMD);
4260 if (ret) {
4261 hdd_err("DTIM 1 chain set failed %d", ret);
4262 goto error;
4263 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304264
Arun Khandavalli2358d522016-05-16 18:05:37 +05304265#undef HDD_DTIM_1CHAIN_RX_ID
4266#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004267
4268 if (hdd_configure_chain_mask(adapter))
4269 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004270 }
4271
Jeff Johnson1b780e42017-10-31 14:11:45 -07004272 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004273 WMI_PDEV_PARAM_HYST_EN,
4274 hdd_ctx->config->enableMemDeepSleep,
4275 PDEV_CMD);
4276 if (ret) {
4277 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4278 goto error;
4279 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304280
Jeff Johnson1b780e42017-10-31 14:11:45 -07004281 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004282 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4283 hdd_ctx->config->rts_profile,
4284 VDEV_CMD);
4285 if (ret) {
4286 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4287 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304288 }
4289
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004290 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4291
Jeff Johnson1b780e42017-10-31 14:11:45 -07004292 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004293 GEN_VDEV_PARAM_AMSDU,
4294 hdd_ctx->config->max_amsdu_num,
4295 GEN_CMD);
4296 if (ret != 0) {
4297 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4298 goto error;
4299 }
4300
Arun Khandavalli2358d522016-05-16 18:05:37 +05304301 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304302 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004303
Arun Khandavalli2358d522016-05-16 18:05:37 +05304304 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304305
Arun Khandavalli2358d522016-05-16 18:05:37 +05304306error:
4307 return -EINVAL;
4308}
4309
Ryan Hsu07495ea2016-01-21 15:25:39 -08004310/**
4311 * hdd_open_adapter() - open and setup the hdd adatper
4312 * @hdd_ctx: global hdd context
4313 * @session_type: type of the interface to be created
4314 * @iface_name: User-visible name of the interface
4315 * @macAddr: MAC address to assign to the interface
4316 * @name_assign_type: the name of assign type of the netdev
4317 * @rtnl_held: the rtnl lock hold flag
4318 *
4319 * This function open and setup the hdd adpater according to the device
4320 * type request, assign the name, the mac address assigned, and then prepared
4321 * the hdd related parameters, queue, lock and ready to start.
4322 *
4323 * Return: the pointer of hdd adapter, otherwise NULL.
4324 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004325struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004326 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004327 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004328 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004329{
Jeff Johnson9d295242017-08-29 14:39:48 -07004330 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304331 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004332
4333 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4334 /*
4335 * Max limit reached on the number of vdevs configured by the
4336 * host. Return error
4337 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304338 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4339 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 return NULL;
4341 }
4342
4343 if (macAddr == NULL) {
4344 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304345 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004346 return NULL;
4347 }
4348 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304349 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304350 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4351 " already exists",
4352 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353 return NULL;
4354 }
4355
4356 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004357 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358 /* Reset locally administered bit if the device mode is STA */
4359 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304360 hdd_info("locally administered bit reset in sta mode: "
4361 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004362 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004363 case QDF_P2P_CLIENT_MODE:
4364 case QDF_P2P_DEVICE_MODE:
4365 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004366 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304367 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004368 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4369 name_assign_type,
4370 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004371
4372 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304373 hdd_err("failed to allocate adapter for session %d",
4374 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375 return NULL;
4376 }
4377
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004378 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004379 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004380 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304382 else if (QDF_MONITOR_MODE == session_type)
4383 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384 else
4385 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4386
4387 adapter->device_mode = session_type;
4388
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004390 /*
4391 * Workqueue which gets scheduled in IPv4 notification
4392 * callback
4393 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004394 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004395 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396
4397#ifdef WLAN_NS_OFFLOAD
4398 /*
4399 * Workqueue which gets scheduled in IPv6
4400 * notification callback.
4401 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004402 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004403 hdd_ipv6_notifier_work_queue);
4404#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004406 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004407 goto err_deinit_adapter_runtime_pm;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004408
4409 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004410 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004411 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304412 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4413 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304414
Ravi Joshi1a292562017-05-18 16:28:54 -07004415 /* Initialize NAN Data Interface */
4416 if (QDF_NDI_MODE == session_type) {
4417 status = hdd_init_nan_data_mode(adapter);
4418 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004419 goto err_deinit_adapter_runtime_pm;
Ravi Joshi1a292562017-05-18 16:28:54 -07004420 }
4421
4422 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004423
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004424 case QDF_P2P_GO_MODE:
4425 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004426 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4427 name_assign_type,
4428 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004430 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304431 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432 return NULL;
4433 }
4434
4435 adapter->wdev.iftype =
4436 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004437 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438 NL80211_IFTYPE_P2P_GO;
4439 adapter->device_mode = session_type;
4440
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004441 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004442 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004444
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004445 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304447 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4448 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304449
4450 /*
4451 * Workqueue which gets scheduled in IPv4 notification
4452 * callback
4453 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004454 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304455 hdd_ipv4_notifier_work_queue);
4456
4457#ifdef WLAN_NS_OFFLOAD
4458 /*
4459 * Workqueue which gets scheduled in IPv6
4460 * notification callback.
4461 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004462 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304463 hdd_ipv6_notifier_work_queue);
4464#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004465 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304466 case QDF_FTM_MODE:
4467 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4468 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004469 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304470 if (NULL == adapter) {
4471 hdd_err("Failed to allocate adapter for FTM mode");
4472 return NULL;
4473 }
4474 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4475 adapter->device_mode = session_type;
4476 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004477 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004478 goto err_deinit_adapter_runtime_pm;
Krunal Sonib51eec72017-11-20 21:53:01 -08004479
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304480 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004481 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304482 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304483 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4484 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304485 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004487 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304488 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004489 return NULL;
4490 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004491
hqueaa33ee2017-05-04 17:56:35 +08004492 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4493
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304494 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004496 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004497 }
4498
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304499 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 if (NULL != adapter) {
4501 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4502 adapter = NULL;
4503 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004504
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004505 return NULL;
4506 }
4507
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304508 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004509 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4510 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004512 /* Adapter successfully added. Increment the vdev count */
4513 hdd_ctx->current_intf_count++;
4514
Jeff Johnson5880d792016-08-15 13:32:30 -07004515 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004516 hdd_ctx->current_intf_count);
4517
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004518 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004519 }
4520
Rajeev Kumardca5f812016-02-04 17:28:06 -08004521 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004522 hdd_err("Interface %s wow debug_fs init failed",
4523 netdev_name(adapter->dev));
4524
4525 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4526 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527
4528 return adapter;
4529
Yue Ma9e89e832017-11-14 11:40:23 -08004530err_deinit_adapter_runtime_pm:
4531 /*
4532 * For certain error cases that hdd_alloc_station_adapter()
4533 * is used to allocate the adapter.
4534 */
4535 hdd_adapter_runtime_suspend_deinit(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004536err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004537 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304538 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004539
4540 return NULL;
4541}
4542
Jeff Johnson9d295242017-08-29 14:39:48 -07004543QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004544 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004545{
Dustin Brown920397d2017-12-13 16:27:50 -08004546 /*
4547 * Here we are stopping global bus_bw timer & work per adapter.
4548 *
4549 * The reason is to fix one race condition between
4550 * bus bandwidth work and cleaning up an adapter.
4551 * Under some conditions, it is possible for the bus bandwidth
4552 * work to access a particularly destroyed adapter, leading to
4553 * use-after-free.
4554 */
4555 hdd_debug("wait for bus bw work to flush");
4556 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4557 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004558
Dustin Brown920397d2017-12-13 16:27:50 -08004559 /* cleanup adapter */
4560 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4561 adapter->device_mode);
4562 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4563 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004564
Dustin Brown920397d2017-12-13 16:27:50 -08004565 /* conditionally restart the bw timer */
4566 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004567
Dustin Brown920397d2017-12-13 16:27:50 -08004568 /* Adapter removed. Decrement vdev count */
4569 if (hdd_ctx->current_intf_count != 0)
4570 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004571
Dustin Brown920397d2017-12-13 16:27:50 -08004572 /* Fw will take care incase of concurrency */
4573 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574}
4575
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004576/**
4577 * hdd_close_all_adapters - Close all open adapters
4578 * @hdd_ctx: Hdd context
4579 * rtnl_held: True if RTNL lock held
4580 *
4581 * Close all open adapters.
4582 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304583 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004584 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004585QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004586{
Dustin Brown920397d2017-12-13 16:27:50 -08004587 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304588 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004589
4590 ENTER();
4591
4592 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004593 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4594 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304595 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004596 adapter->mac_addr.bytes);
4597 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4598
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304599 /* Adapter removed. Decrement vdev count */
4600 if (hdd_ctx->current_intf_count != 0)
4601 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004602 }
Dustin Brown920397d2017-12-13 16:27:50 -08004603 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004604
4605 EXIT();
4606
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304607 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004608}
4609
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004610void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004611{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304612 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004613 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004614
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004615 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004616 case QDF_STA_MODE:
4617 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004619 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004620 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004621 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004622 break;
4623 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004624 case QDF_SAP_MODE:
4625 case QDF_P2P_GO_MODE:
4626 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004627 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004628 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004629 break;
4630 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004631 case QDF_FTM_MODE:
4632 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004633 default:
4634 /*
4635 * wlan_hdd_reset_prob_rspies should not have been called
4636 * for these kind of devices
4637 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004638 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004639 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004640 return;
4641 }
4642
Anurag Chouhanc5548422016-02-24 18:33:27 +05304643 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004644 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004645 updateIE.ieBufferlength = 0;
4646 updateIE.pAdditionIEBuffer = NULL;
4647 updateIE.append = true;
4648 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004649 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004650 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304651 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004652 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653 }
4654}
4655
Dustin Browndb2a8be2017-12-20 11:49:56 -08004656QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4657 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004658{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304659 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004660 struct hdd_wext_state *pWextState =
4661 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 union iwreq_data wrqu;
4663 tSirUpdateIE updateIE;
4664 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304665 tsap_Config_t *sap_config;
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304666 bool is_enabled = false;
4667 uint8_t ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004668
4669 ENTER();
4670
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004671 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304672 wlan_hdd_netif_queue_control(adapter,
4673 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4674 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004675 /*
4676 * if this is the last active connection check & stop the
4677 * opportunistic timer first
4678 */
4679 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4680 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4681 policy_mgr_convert_device_mode_to_qdf_type(
4682 adapter->device_mode), NULL) == 1)) ||
4683 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4684 policy_mgr_check_and_stop_opportunistic_timer(
4685 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004686 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004687 case QDF_STA_MODE:
4688 case QDF_P2P_CLIENT_MODE:
4689 case QDF_IBSS_MODE:
4690 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004691 case QDF_NDI_MODE:
4692 if ((QDF_NDI_MODE == adapter->device_mode) ||
4693 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004694 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4695 hdd_is_connecting(
4696 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004697 INIT_COMPLETION(adapter->disconnect_comp_var);
4698 /*
4699 * For NDI do not use pWextState from sta_ctx, if needed
4700 * extract from ndi_ctx.
4701 */
4702 if (QDF_NDI_MODE == adapter->device_mode)
4703 qdf_ret_status = sme_roam_disconnect(
4704 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004705 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004706 eCSR_DISCONNECT_REASON_NDI_DELETE);
4707 else if (pWextState->roamProfile.BSSType ==
4708 eCSR_BSS_TYPE_START_IBSS)
4709 qdf_ret_status = sme_roam_disconnect(
4710 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004711 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004712 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004713 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004714 qdf_ret_status =
4715 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004716 hdd_debug("Send disconnected event to userspace");
4717 wlan_hdd_cfg80211_indicate_disconnect(
4718 adapter->dev, true,
4719 WLAN_REASON_UNSPECIFIED);
4720 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004721 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004722 qdf_ret_status = sme_roam_disconnect(
4723 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004724 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004725 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004726 /* success implies disconnect command got
4727 * queued up successfully
4728 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004729 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4730 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004731 rc = wait_for_completion_timeout(
4732 &adapter->disconnect_comp_var,
4733 msecs_to_jiffies
4734 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004735 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004736 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004737 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004738 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4739 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004740 memset(&wrqu, '\0', sizeof(wrqu));
4741 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4742 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4743 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4744 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304745 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004746 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004747
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304748 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304749 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004750
4751#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004752 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004753#endif
4754
4755 hdd_deregister_tx_flow_control(adapter);
4756
4757#ifdef WLAN_NS_OFFLOAD
4758#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004759 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004760#endif
4761#endif
4762
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304763 if (adapter->device_mode == QDF_STA_MODE)
4764 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4765 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004766
4767 if (wlan_hdd_try_disconnect(adapter)) {
4768 hdd_err("Error: Can't disconnect adapter");
4769 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004770 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004771
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304772 ret = hdd_check_green_ap_enable(hdd_ctx, &is_enabled);
4773 if (!ret) {
4774 hdd_debug("Green AP enable status: %d", is_enabled);
4775 if (is_enabled) {
4776 hdd_debug("Enabling Green AP");
4777 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
4778 true);
4779 wlan_green_ap_start(hdd_ctx->hdd_pdev);
4780 }
4781 } else {
4782 hdd_err("Failed to check if Green AP should be enabled or not");
4783 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004784
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304785 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004786 break;
4787
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004788 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004789 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304790 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304791 sap_config = &adapter->session.ap.sap_config;
4792 if (sap_config)
4793 wlansap_reset_sap_config_add_ie(sap_config,
4794 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304795 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004796 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004797
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004798 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004799 if (QDF_SAP_MODE == adapter->device_mode) {
4800 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4801 cds_flush_delayed_work(
4802 &adapter->acs_pending_work);
4803 clear_bit(ACS_PENDING, &adapter->event_flags);
4804 }
4805 }
Krunal Soni22208392017-09-29 18:10:34 -07004806 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004809 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004810 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004811 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4812
4813 hdd_deregister_tx_flow_control(adapter);
4814
Kapil Guptac1224bf2017-06-22 21:22:40 +05304815 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004816 mutex_lock(&hdd_ctx->sap_lock);
4817 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304818 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304819 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004820
4821 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004822 status = wlansap_stop_bss(
4823 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004824
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304825 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004826 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004827 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304828 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304829 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304830 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304831 qdf_wait_for_event_completion(
4832 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004833 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004834
Anurag Chouhance0dc992016-02-16 18:18:03 +05304835 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004836 hdd_err("failure waiting for wlansap_stop_bss %d",
4837 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004838 }
4839 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004840 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004841 }
4842 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004843 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4844 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004845 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846
Anurag Chouhanc5548422016-02-24 18:33:27 +05304847 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004848 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004849 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850 updateIE.ieBufferlength = 0;
4851 updateIE.pAdditionIEBuffer = NULL;
4852 updateIE.append = false;
4853 updateIE.notify = false;
4854 /* Probe bcn reset */
4855 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4856 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304857 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004858 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004859 }
4860 /* Assoc resp reset */
4861 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4862 &updateIE,
4863 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304864 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004865 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004866 }
4867 /* Reset WNI_CFG_PROBE_RSP Flags */
4868 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004869 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004870 qdf_mem_free(adapter->session.ap.beacon);
4871 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304872 /*
4873 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4874 */
4875 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4876 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4877
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304878#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004879 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304880#endif
4881
4882#ifdef WLAN_NS_OFFLOAD
4883#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004884 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304885#endif
4886#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08004887
4888 hdd_vdev_destroy(adapter);
4889
Krunal Sonib51eec72017-11-20 21:53:01 -08004890 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004891 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004892 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004893 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004894 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004895 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004896 break;
4897 default:
4898 break;
4899 }
4900
Dustin Brown04348372017-12-14 16:13:39 -08004901 if (adapter->scan_info.default_scan_ies) {
4902 qdf_mem_free(adapter->scan_info.default_scan_ies);
4903 adapter->scan_info.default_scan_ies = NULL;
4904 }
4905
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004906 EXIT();
Dustin Brown04348372017-12-14 16:13:39 -08004907
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304908 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004909}
4910
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304911/**
4912 * hdd_deinit_all_adapters - deinit all adapters
4913 * @hdd_ctx: HDD context
4914 * @rtnl_held: True if RTNL lock held
4915 *
4916 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004917void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304918{
Jeff Johnson9d295242017-08-29 14:39:48 -07004919 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304920
4921 ENTER();
4922
Dustin Brown920397d2017-12-13 16:27:50 -08004923 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304924 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304925
4926 EXIT();
4927}
4928
Dustin Browndb2a8be2017-12-20 11:49:56 -08004929QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004930{
Jeff Johnson9d295242017-08-29 14:39:48 -07004931 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004932
4933 ENTER();
4934
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304935 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4936
Dustin Brown920397d2017-12-13 16:27:50 -08004937 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08004938 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004939
4940 EXIT();
4941
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304942 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004943}
4944
Paul Zhang84fa9382017-11-10 21:18:21 +08004945static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4946 struct hdd_adapter *adapter)
4947{
4948 switch (adapter->device_mode) {
4949 case QDF_STA_MODE:
4950 case QDF_P2P_CLIENT_MODE:
4951 case QDF_IBSS_MODE:
4952 case QDF_P2P_DEVICE_MODE:
4953 case QDF_NDI_MODE:
4954 wlan_hdd_scan_abort(adapter);
4955 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4956 if (adapter->device_mode == QDF_STA_MODE)
4957 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4958 adapter->dev);
4959 break;
4960 case QDF_P2P_GO_MODE:
4961 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4962 break;
4963 case QDF_SAP_MODE:
4964 wlan_hdd_undo_acs(adapter);
4965 break;
4966 default:
4967 break;
4968 }
4969}
4970
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004971QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004972{
Jeff Johnson9d295242017-08-29 14:39:48 -07004973 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004974 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004975 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08004976 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004977
4978 ENTER();
4979
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304980 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4981
Dustin Brown920397d2017-12-13 16:27:50 -08004982 hdd_for_each_adapter(hdd_ctx, adapter) {
Yue Ma42654682018-01-11 16:55:24 -08004983 hdd_notice("[SSR] reset adapter with device mode %s(%d)",
4984 hdd_device_mode_to_string(adapter->device_mode),
Yue Mad5b4b9f2017-05-26 16:23:40 -07004985 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304986
4987 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004988 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304989 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004990 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304991
Arun Khandavallicc544b32017-01-30 19:52:16 +05304992 if (hdd_ctx->config->sap_internal_restart &&
4993 adapter->device_mode == QDF_SAP_MODE) {
4994 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304995 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304996 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004997 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08004998 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004999 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005000 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5001 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305002 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305003 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005004 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005005 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005006
Paul Zhang84fa9382017-11-10 21:18:21 +08005007 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005008 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005009
5010 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005011 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005012 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005013 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5014 hdd_wmm_adapter_close(adapter);
5015 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5016 }
5017
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305018 if (adapter->device_mode == QDF_STA_MODE)
5019 hdd_clear_fils_connection_info(adapter);
5020
Wu Gao3545e642017-07-14 19:24:41 +08005021 if (adapter->device_mode == QDF_SAP_MODE) {
5022 /*
5023 * If adapter is SAP, set session ID to invalid
5024 * since SAP session will be cleanup during SSR.
5025 */
Wu Gao36717432016-11-21 15:09:48 +08005026 wlansap_set_invalid_session(
5027 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5028
Wu Gao3545e642017-07-14 19:24:41 +08005029 wlansap_cleanup_cac_timer(
5030 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5031 }
5032
Yue Ma42654682018-01-11 16:55:24 -08005033 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005034 if (adapter->device_mode == QDF_STA_MODE ||
5035 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005036 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005037 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005038 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005039
5040 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5041 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005042 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5043 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5044 if (adapter->sta_info[sta_id].in_use) {
5045 hdd_debug("[SSR] deregister STA with ID %d",
5046 sta_id);
5047 hdd_softap_deregister_sta(adapter,
5048 sta_id);
5049 adapter->sta_info[sta_id].in_use = 0;
5050 }
5051 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005052 }
5053
Yue Maf9782842017-05-08 12:49:49 -07005054 /* Destroy vdev which will be recreated during reinit. */
5055 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 }
5057
5058 EXIT();
5059
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305060 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005061}
5062
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005063bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305064{
Dustin Brown920397d2017-12-13 16:27:50 -08005065 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305066 bool close_modules = true;
5067
Arun Khandavalliba479c42017-07-26 21:29:40 +05305068 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5069 hdd_info("FTM mode, don't close the module");
5070 return false;
5071 }
5072
Dustin Brown920397d2017-12-13 16:27:50 -08005073 hdd_for_each_adapter(hdd_ctx, adapter) {
5074 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5075 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005076 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305077 close_modules = false;
5078 break;
5079 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305080 }
5081
5082 return close_modules;
5083}
5084
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305085bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305086{
5087 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5088 return true;
5089 else
5090 return false;
5091}
5092
Anurag Chouhanc4092922016-09-08 15:56:11 +05305093#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005094 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305095struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5096 struct ieee80211_channel *channel,
5097 const u8 *bssid, const u8 *ssid,
5098 size_t ssid_len)
5099{
5100 return cfg80211_get_bss(wiphy, channel, bssid,
5101 ssid, ssid_len,
5102 WLAN_CAPABILITY_ESS,
5103 WLAN_CAPABILITY_ESS);
5104}
5105#else
5106struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5107 struct ieee80211_channel *channel,
5108 const u8 *bssid, const u8 *ssid,
5109 size_t ssid_len)
5110{
5111 return cfg80211_get_bss(wiphy, channel, bssid,
5112 ssid, ssid_len,
5113 IEEE80211_BSS_TYPE_ESS,
5114 IEEE80211_PRIVACY_ANY);
5115}
5116#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305117
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305118#if defined CFG80211_CONNECT_BSS || \
5119 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305120#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305121 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305122/**
5123 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5124 * @timeout_reason: reason for connect timeout
5125 *
5126 * This function is used to convert host timeout
5127 * reason enum to kernel specific enum.
5128 *
5129 * Return: nl timeout enum
5130 */
5131static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5132 tSirResultCodes timeout_reason)
5133{
5134 switch (timeout_reason) {
5135 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5136 return NL80211_TIMEOUT_SCAN;
5137 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5138 return NL80211_TIMEOUT_AUTH;
5139 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5140 return NL80211_TIMEOUT_ASSOC;
5141 default:
5142 return NL80211_TIMEOUT_UNSPECIFIED;
5143 }
5144}
5145
5146/**
5147 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5148 * @dev: network device
5149 * @bssid: bssid to which we want to associate
5150 * @timeout_reason: reason for connect timeout
5151 *
5152 * This API is used to send connection timeout reason to supplicant
5153 *
5154 * Return: void
5155 */
5156static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5157 const u8 *bssid,
5158 tSirResultCodes timeout_reason)
5159{
5160 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005161
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305162 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5163
5164 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5165 nl_timeout_reason);
5166}
5167
5168/**
5169 * __hdd_connect_bss() - API to send connection status to supplicant
5170 * @dev: network device
5171 * @bssid: bssid to which we want to associate
5172 * @req_ie: Request Information Element
5173 * @req_ie_len: len of the req IE
5174 * @resp_ie: Response IE
5175 * @resp_ie_len: len of ht response IE
5176 * @status: status
5177 * @gfp: Kernel Flag
5178 * @timeout_reason: reason for connect timeout
5179 *
5180 * Return: void
5181 */
5182static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5183 struct cfg80211_bss *bss, const u8 *req_ie,
5184 size_t req_ie_len, const u8 *resp_ie,
5185 size_t resp_ie_len, int status, gfp_t gfp,
5186 tSirResultCodes timeout_reason)
5187{
5188 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005189
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305190 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5191
5192 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5193 resp_ie, resp_ie_len, status, gfp,
5194 nl_timeout_reason);
5195}
5196#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305197#if defined CFG80211_CONNECT_TIMEOUT || \
5198 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305199static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5200 const u8 *bssid,
5201 tSirResultCodes timeout_reason)
5202{
5203 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5204}
5205#endif
5206
5207static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5208 struct cfg80211_bss *bss, const u8 *req_ie,
5209 size_t req_ie_len, const u8 *resp_ie,
5210 size_t resp_ie_len, int status, gfp_t gfp,
5211 tSirResultCodes timeout_reason)
5212{
5213 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5214 resp_ie, resp_ie_len, status, gfp);
5215}
5216#endif
5217
Abhishek Singha84d3952016-09-13 13:45:05 +05305218/**
5219 * hdd_connect_bss() - API to send connection status to supplicant
5220 * @dev: network device
5221 * @bssid: bssid to which we want to associate
5222 * @req_ie: Request Information Element
5223 * @req_ie_len: len of the req IE
5224 * @resp_ie: Response IE
5225 * @resp_ie_len: len of ht response IE
5226 * @status: status
5227 * @gfp: Kernel Flag
5228 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305229 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305230 *
5231 * The API is a wrapper to send connection status to supplicant
5232 *
5233 * Return: Void
5234 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305235#if defined CFG80211_CONNECT_TIMEOUT || \
5236 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305237static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5238 struct cfg80211_bss *bss, const u8 *req_ie,
5239 size_t req_ie_len, const u8 *resp_ie,
5240 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305241 bool connect_timeout,
5242 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305243{
5244 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305245 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305246 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305247 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5248 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305249}
5250#else
5251static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5252 struct cfg80211_bss *bss, const u8 *req_ie,
5253 size_t req_ie_len, const u8 *resp_ie,
5254 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305255 bool connect_timeout,
5256 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305257{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305258 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5259 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305260}
5261#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305262
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305263#if defined(WLAN_FEATURE_FILS_SK)
5264#if defined(CFG80211_CONNECT_DONE) || \
5265 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5266#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5267 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305268/**
5269 * hdd_populate_fils_params() - Populate FILS keys to connect response
5270 * @fils_params: connect response to supplicant
5271 * @fils_kek: FILS kek
5272 * @fils_kek_len: FILS kek length
5273 * @pmk: FILS PMK
5274 * @pmk_len: FILS PMK length
5275 * @pmkid: PMKID
5276 * @fils_seq_num: FILS Seq number
5277 *
5278 * Return: None
5279 */
5280static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5281 *fils_params, const uint8_t *fils_kek,
5282 size_t fils_kek_len, const uint8_t *pmk,
5283 size_t pmk_len, const uint8_t *pmkid,
5284 uint16_t fils_seq_num)
5285{
5286 /* Increament seq number to be used for next FILS */
5287 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5288 fils_params->update_erp_next_seq_num = true;
5289 fils_params->fils_kek = fils_kek;
5290 fils_params->fils_kek_len = fils_kek_len;
5291 fils_params->pmk = pmk;
5292 fils_params->pmk_len = pmk_len;
5293 fils_params->pmkid = pmkid;
5294}
5295#else
5296static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5297 *fils_params, const uint8_t
5298 *fils_kek, size_t fils_kek_len,
5299 const uint8_t *pmk, size_t pmk_len,
5300 const uint8_t *pmkid,
5301 uint16_t fils_seq_num)
5302{ }
5303#endif
5304
Jeff Johnson172237b2017-11-07 15:32:59 -08005305void hdd_update_hlp_info(struct net_device *dev,
5306 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305307{
5308 struct sk_buff *skb;
5309 uint16_t skb_len;
5310 struct llc_snap_hdr_t *llc_hdr;
5311 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305312 uint8_t *hlp_data;
5313 uint16_t hlp_data_len;
5314 struct fils_join_rsp_params *roam_fils_params
5315 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305316 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5317
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305318 if (!roam_fils_params) {
5319 hdd_err("FILS Roam Param NULL");
5320 return;
5321 }
5322
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005323 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305324 hdd_err("FILS HLP Data NULL, len %d",
5325 roam_fils_params->hlp_data_len);
5326 return;
5327 }
5328
5329 hlp_data = roam_fils_params->hlp_data;
5330 hlp_data_len = roam_fils_params->hlp_data_len;
5331
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305332 /* Calculate skb length */
5333 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5334 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5335 if (skb == NULL) {
5336 hdd_err("HLP packet nbuf alloc fails");
5337 return;
5338 }
5339
5340 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5341 QDF_MAC_ADDR_SIZE);
5342 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5343 QDF_MAC_ADDR_SIZE);
5344
5345 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5346 if (IS_SNAP(llc_hdr)) {
5347 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5348 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5349 }
5350
5351 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5352
5353 /*
5354 * This HLP packet is formed from HLP info encapsulated
5355 * in assoc response frame which is AEAD encrypted.
5356 * Hence, this checksum validation can be set unnecessary.
5357 * i.e. network layer need not worry about checksum.
5358 */
5359 skb->ip_summed = CHECKSUM_UNNECESSARY;
5360
5361 status = hdd_rx_packet_cbk(padapter, skb);
5362 if (QDF_IS_STATUS_ERROR(status)) {
5363 hdd_err("Sending HLP packet fails");
5364 return;
5365 }
5366 hdd_debug("send HLP packet to netif successfully");
5367}
5368
5369/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305370 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5371 * @dev: network device
5372 * @bssid: bssid to which we want to associate
5373 * @bss: cfg80211 bss info
5374 * @roam_info: information about connected bss
5375 * @req_ie: Request Information Element
5376 * @req_ie_len: len of the req IE
5377 * @resp_ie: Response IE
5378 * @resp_ie_len: len of ht response IE
5379 * @status: status
5380 * @gfp: allocation flags
5381 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5382 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305383 *
5384 * This API is used as wrapper to send FILS key/sequence number
5385 * params etc. to supplicant in case of FILS connection
5386 *
5387 * Return: None
5388 */
5389static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005390 struct cfg80211_bss *bss,
5391 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305392 const u8 *req_ie, size_t req_ie_len,
5393 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005394 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305395 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305396{
5397 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305398 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5399 struct fils_join_rsp_params *roam_fils_params =
5400 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005401
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305402 qdf_mem_zero(&fils_params, sizeof(fils_params));
5403
5404 if (!roam_fils_params) {
5405 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5406 } else {
5407 fils_params.status = status;
5408 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005409 fils_params.timeout_reason =
5410 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305411 fils_params.req_ie = req_ie;
5412 fils_params.req_ie_len = req_ie_len;
5413 fils_params.resp_ie = resp_ie;
5414 fils_params.resp_ie_len = resp_ie_len;
5415 fils_params.bss = bss;
5416 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5417 roam_fils_params->kek_len,
5418 roam_fils_params->fils_pmk,
5419 roam_fils_params->fils_pmk_len,
5420 roam_fils_params->fils_pmkid,
5421 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305422 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305423 }
5424 hdd_debug("FILS indicate connect status %d seq no %d",
5425 fils_params.status,
5426 fils_params.fils_erp_next_seq_num);
5427
5428 cfg80211_connect_done(dev, &fils_params, gfp);
5429
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305430 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305431 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305432
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305433 /* Clear all the FILS key info */
5434 if (roam_fils_params && roam_fils_params->fils_pmk)
5435 qdf_mem_free(roam_fils_params->fils_pmk);
5436 if (roam_fils_params)
5437 qdf_mem_free(roam_fils_params);
5438 roam_info->fils_join_rsp = NULL;
5439}
5440#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005441static inline void
5442hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005443 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005444 const u8 *req_ie, size_t req_ie_len,
5445 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5446 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305447 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305448{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305449#endif
5450#endif
5451
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305452#if defined(WLAN_FEATURE_FILS_SK) && \
5453 (defined(CFG80211_CONNECT_DONE) || \
5454 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305455/**
5456 * hdd_fils_update_connect_results() - API to send fils connection status to
5457 * supplicant.
5458 * @dev: network device
5459 * @bssid: bssid to which we want to associate
5460 * @bss: cfg80211 bss info
5461 * @roam_info: information about connected bss
5462 * @req_ie: Request Information Element
5463 * @req_ie_len: len of the req IE
5464 * @resp_ie: Response IE
5465 * @resp_ie_len: len of ht response IE
5466 * @status: status
5467 * @gfp: allocation flags
5468 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5469 * @timeout_reason: reason for connect timeout
5470 *
5471 * The API is a wrapper to send connection status to supplicant
5472 *
5473 * Return: 0 if success else failure
5474 */
5475static int hdd_fils_update_connect_results(struct net_device *dev,
5476 const u8 *bssid,
5477 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005478 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305479 size_t req_ie_len, const u8 *resp_ie,
5480 size_t resp_ie_len, u16 status, gfp_t gfp,
5481 bool connect_timeout,
5482 tSirResultCodes timeout_reason)
5483{
5484 ENTER();
5485 if (!roam_info || !roam_info->is_fils_connection)
5486 return -EINVAL;
5487
5488 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5489 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305490 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305491 return 0;
5492}
5493#else
5494static inline int hdd_fils_update_connect_results(struct net_device *dev,
5495 const u8 *bssid,
5496 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005497 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305498 size_t req_ie_len, const u8 *resp_ie,
5499 size_t resp_ie_len, u16 status, gfp_t gfp,
5500 bool connect_timeout,
5501 tSirResultCodes timeout_reason)
5502{
5503 return -EINVAL;
5504}
5505#endif
5506
Anurag Chouhanc4092922016-09-08 15:56:11 +05305507/**
5508 * hdd_connect_result() - API to send connection status to supplicant
5509 * @dev: network device
5510 * @bssid: bssid to which we want to associate
5511 * @roam_info: information about connected bss
5512 * @req_ie: Request Information Element
5513 * @req_ie_len: len of the req IE
5514 * @resp_ie: Response IE
5515 * @resp_ie_len: len of ht response IE
5516 * @status: status
5517 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305518 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305519 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305520 *
5521 * The API is a wrapper to send connection status to supplicant
5522 * and allow runtime suspend
5523 *
5524 * Return: Void
5525 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305526void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005527 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305528 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305529 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305530 bool connect_timeout,
5531 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305532{
Jeff Johnson9d295242017-08-29 14:39:48 -07005533 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305534 struct cfg80211_bss *bss = NULL;
5535
5536 if (WLAN_STATUS_SUCCESS == status) {
5537 struct ieee80211_channel *chan;
5538 int freq;
5539 int chan_no = roam_info->pBssDesc->channelId;
5540
5541 if (chan_no <= 14)
5542 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005543 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305544 else
5545 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005546 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305547
5548 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5549 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5550 roam_info->u.pConnectedProfile->SSID.ssId,
5551 roam_info->u.pConnectedProfile->SSID.length);
5552 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305553
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305554 if (hdd_fils_update_connect_results(dev, bssid, bss,
5555 roam_info, req_ie, req_ie_len, resp_ie,
5556 resp_ie_len, status, gfp, connect_timeout,
5557 timeout_reason) != 0) {
5558 hdd_connect_bss(dev, bssid, bss, req_ie,
5559 req_ie_len, resp_ie, resp_ie_len,
5560 status, gfp, connect_timeout, timeout_reason);
5561 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305562
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005563 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005564 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305565}
5566#else
5567void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005568 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305569 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305570 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305571 bool connect_timeout,
5572 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305573{
Jeff Johnson9d295242017-08-29 14:39:48 -07005574 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305575
Anurag Chouhanc4092922016-09-08 15:56:11 +05305576 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5577 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005578
5579 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005580 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305581}
5582#endif
5583
5584
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005585QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005586{
Jeff Johnson9d295242017-08-29 14:39:48 -07005587 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005588#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305589 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005590#endif
5591 eConnectionState connState;
5592
5593 ENTER();
5594
Dustin Brown920397d2017-12-13 16:27:50 -08005595 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305596 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005597 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305598
Yue Ma42654682018-01-11 16:55:24 -08005599 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5600 hdd_device_mode_to_string(adapter->device_mode),
5601 adapter->device_mode);
5602
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005603 hdd_wmm_init(adapter);
5604
5605 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005606 case QDF_STA_MODE:
5607 case QDF_P2P_CLIENT_MODE:
5608 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005609
5610 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5611 ->conn_info.connState;
5612
Krunal Sonib51eec72017-11-20 21:53:01 -08005613 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005614 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005615 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005616
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005617 /* Indicate disconnect event to supplicant
5618 * if associated previously
5619 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005620 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005621 eConnectionState_IbssConnected == connState ||
5622 eConnectionState_NotConnected == connState ||
5623 eConnectionState_IbssDisconnected == connState ||
5624 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005625 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005626
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005627 memset(&wrqu, '\0', sizeof(wrqu));
5628 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5629 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5630 wireless_send_event(adapter->dev, SIOCGIWAP,
5631 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005632 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005633 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005634
5635 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305636 wlan_hdd_cfg80211_indicate_disconnect(
5637 adapter->dev, false,
5638 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639 } else if (eConnectionState_Connecting == connState) {
5640 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005641 * Indicate connect failure to supplicant if we
5642 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005643 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305644 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305645 NULL, 0, NULL, 0,
5646 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005647 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005648 }
5649
5650 hdd_register_tx_flow_control(adapter,
5651 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005652 hdd_tx_resume_cb,
5653 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005654
5655 break;
5656
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005657 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005658 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005659 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005661 break;
5662
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005663 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005664#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005665 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005666 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5667#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005668 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005669 /* event supplicant to restart */
5670 cfg80211_del_sta(adapter->dev,
5671 (const u8 *)&bcastMac.bytes[0],
5672 GFP_KERNEL);
5673#endif
5674 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305675 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005676 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305677 hdd_set_mon_rx_cb(adapter->dev);
5678 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5679 adapter->mon_bandwidth);
5680 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681 default:
5682 break;
5683 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005684 /*
5685 * Action frame registered in one adapter which will
5686 * applicable to all interfaces
5687 */
5688 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689 }
5690
5691 EXIT();
5692
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305693 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005694}
5695
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005696QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005697 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005698{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305699 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005700 qdf_list_node_t *node;
5701
5702 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005703
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005704 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005705 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005706 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005707
5708 if (QDF_IS_STATUS_ERROR(status))
5709 return status;
5710
5711 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5712
5713 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005714}
5715
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005716QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005717 struct hdd_adapter *current_adapter,
5718 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005719{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305720 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005721 qdf_list_node_t *node;
5722
5723 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005724
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005725 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005726 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005727 &current_adapter->node,
5728 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005729 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005730
5731 if (QDF_IS_STATUS_ERROR(status))
5732 return status;
5733
5734 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5735
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005736 return status;
5737}
5738
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005739QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005740 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005741{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305742 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005743
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005744 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005745 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005746 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005747
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005748 return status;
5749}
5750
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005751QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005752 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005753{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305754 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005755 qdf_list_node_t *node;
5756
5757 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005758
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005759 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005760 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005761 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005762
5763 if (QDF_IS_STATUS_ERROR(status))
5764 return status;
5765
5766 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5767
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005768 return status;
5769}
5770
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005771QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005772 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005773{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305774 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005775
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005776 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005777 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005778 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005779
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005780 return status;
5781}
5782
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005783QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005784 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005785{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305786 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005787
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005788 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005789 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005790 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005791
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005792 return status;
5793}
5794
Jeff Johnson9d295242017-08-29 14:39:48 -07005795struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005796 tSirMacAddr macAddr)
5797{
Jeff Johnson9d295242017-08-29 14:39:48 -07005798 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005799
Dustin Brown920397d2017-12-13 16:27:50 -08005800 hdd_for_each_adapter(hdd_ctx, adapter) {
5801 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5802 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005803 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005804 }
5805
5806 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005807}
5808
Jeff Johnson9d295242017-08-29 14:39:48 -07005809struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005810 uint32_t vdev_id)
5811{
Jeff Johnson9d295242017-08-29 14:39:48 -07005812 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005813
Dustin Brown920397d2017-12-13 16:27:50 -08005814 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005815 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005816 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005817 }
5818
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005819 return NULL;
5820}
5821
Abhishek Singh7996eb72015-12-30 17:24:02 +05305822/**
5823 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5824 * the sessionid
5825 * @hdd_ctx: hdd context.
5826 * @sme_session_id: sme session is for the adapter to get.
5827 *
5828 * This function is used to get the adapter with provided session id
5829 *
5830 * Return: adapter pointer if found
5831 *
5832 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005833struct hdd_adapter *
5834hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5835 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305836{
Jeff Johnson9d295242017-08-29 14:39:48 -07005837 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305838
Dustin Brown920397d2017-12-13 16:27:50 -08005839 hdd_for_each_adapter(hdd_ctx, adapter) {
5840 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305841 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305842 }
Dustin Brown920397d2017-12-13 16:27:50 -08005843
Abhishek Singh7996eb72015-12-30 17:24:02 +05305844 return NULL;
5845}
5846
Jeff Johnson9d295242017-08-29 14:39:48 -07005847struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005848 const char *iface_name)
5849{
Jeff Johnson9d295242017-08-29 14:39:48 -07005850 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005851
Dustin Brown920397d2017-12-13 16:27:50 -08005852 hdd_for_each_adapter(hdd_ctx, adapter) {
5853 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07005854 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005855 }
Dustin Brown920397d2017-12-13 16:27:50 -08005856
Naveen Rawat4edb6822017-04-12 10:09:17 -07005857 return NULL;
5858}
5859
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005860/**
5861 * hdd_get_adapter() - to get adapter matching the mode
5862 * @hdd_ctx: hdd context
5863 * @mode: adapter mode
5864 *
5865 * This routine will return the pointer to adapter matching
5866 * with the passed mode.
5867 *
5868 * Return: pointer to adapter or null
5869 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005870struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005871 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005872{
Jeff Johnson9d295242017-08-29 14:39:48 -07005873 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005874
Dustin Brown920397d2017-12-13 16:27:50 -08005875 hdd_for_each_adapter(hdd_ctx, adapter) {
5876 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005877 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005878 }
5879
5880 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005881}
5882
5883/**
5884 * hdd_get_operating_channel() - return operating channel of the device mode
5885 * @hdd_ctx: Pointer to the HDD context.
5886 * @mode: Device mode for which operating channel is required.
5887 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005888 * QDF_STA_MODE,
5889 * QDF_P2P_CLIENT_MODE,
5890 * QDF_SAP_MODE,
5891 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005892 *
5893 * This API returns the operating channel of the requested device mode
5894 *
5895 * Return: channel number. "0" id the requested device is not found OR it is
5896 * not connected.
5897 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005898uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005899 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005900{
Jeff Johnson9d295242017-08-29 14:39:48 -07005901 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005902 uint8_t operatingChannel = 0;
5903
Dustin Brown920397d2017-12-13 16:27:50 -08005904 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005905 if (mode == adapter->device_mode) {
5906 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005907 case QDF_STA_MODE:
5908 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005909 if (hdd_conn_is_connected
5910 (WLAN_HDD_GET_STATION_CTX_PTR
5911 (adapter))) {
5912 operatingChannel =
5913 (WLAN_HDD_GET_STATION_CTX_PTR
5914 (adapter))->conn_info.
5915 operationChannel;
5916 }
5917 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005918 case QDF_SAP_MODE:
5919 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005920 /* softap connection info */
5921 if (test_bit
5922 (SOFTAP_BSS_STARTED,
5923 &adapter->event_flags))
5924 operatingChannel =
5925 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005926 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005927 break;
5928 default:
5929 break;
5930 }
5931
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005932 /* Found the device of interest. break the loop */
5933 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005934 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005935 }
Dustin Brown920397d2017-12-13 16:27:50 -08005936
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005937 return operatingChannel;
5938}
5939
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005940static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005941 hdd_ctx)
5942{
Jeff Johnson9d295242017-08-29 14:39:48 -07005943 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005944
5945 ENTER();
5946
Dustin Brown920397d2017-12-13 16:27:50 -08005947 hdd_for_each_adapter(hdd_ctx, adapter) {
5948 if (adapter->device_mode == QDF_STA_MODE ||
5949 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5950 adapter->device_mode == QDF_IBSS_MODE ||
5951 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5952 adapter->device_mode == QDF_SAP_MODE ||
5953 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954 wlan_hdd_cfg80211_deregister_frames(adapter);
5955 hdd_unregister_wext(adapter->dev);
5956 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005957 }
5958
5959 EXIT();
5960
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305961 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005962}
5963
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005964QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005965{
Jeff Johnson9d295242017-08-29 14:39:48 -07005966 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005967
5968 ENTER();
5969
Dustin Brown920397d2017-12-13 16:27:50 -08005970 hdd_for_each_adapter(hdd_ctx, adapter) {
5971 if (adapter->device_mode == QDF_STA_MODE ||
5972 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5973 adapter->device_mode == QDF_IBSS_MODE ||
5974 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5975 adapter->device_mode == QDF_SAP_MODE ||
5976 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005977 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005978 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05305979 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005981 }
5982
5983 EXIT();
5984
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305985 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005986}
5987
Dustin Brownf27bce82016-11-03 12:52:27 -07005988/**
5989 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5990 * adapters
5991 * @hdd_ctx: The HDD context containing the adapters to operate on
5992 *
5993 * return: QDF_STATUS_SUCCESS
5994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005995static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005996{
Jeff Johnson9d295242017-08-29 14:39:48 -07005997 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005998 int err;
5999
6000 ENTER();
6001
Dustin Brown920397d2017-12-13 16:27:50 -08006002 hdd_for_each_adapter(hdd_ctx, adapter) {
6003 if (adapter->device_mode == QDF_STA_MODE ||
6004 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6005 adapter->device_mode == QDF_IBSS_MODE ||
6006 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6007 adapter->device_mode == QDF_SAP_MODE ||
6008 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006009 err = wlan_hdd_sched_scan_stop(adapter->dev);
6010 if (err)
6011 hdd_err("Unable to stop scheduled scan");
6012 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006013 }
6014
6015 EXIT();
6016
6017 return QDF_STATUS_SUCCESS;
6018}
6019
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006020#ifdef WLAN_NS_OFFLOAD
6021/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006022 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006023 * @hdd_ctx: Pointer to hdd context
6024 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006025 * Unregister for IPv6 address change notifications.
6026 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006027 * Return: None
6028 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006029static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006030{
6031 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006032}
6033
6034/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006035 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006036 * @hdd_ctx: Pointer to hdd context
6037 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006038 * Register for IPv6 address change notifications.
6039 *
6040 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006041 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006042static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006043{
6044 int ret;
6045
6046 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6047 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006048 if (ret) {
6049 hdd_err("Failed to register IPv6 notifier: %d", ret);
6050 goto out;
6051 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006052
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006053 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006054out:
6055 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006056}
6057#else
6058/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006059 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006060 * @hdd_ctx: Pointer to hdd context
6061 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006062 * Unregister for IPv6 address change notifications.
6063 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006064 * Return: None
6065 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006066static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006067{
6068}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006069
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006070/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006071 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006072 * @hdd_ctx: Pointer to hdd context
6073 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006074 * Register for IPv6 address change notifications.
6075 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006076 * Return: None
6077 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006078static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006079{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006080 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006081}
6082#endif
6083
6084/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006085 * hdd_register_notifiers - Register netdev notifiers.
6086 * @hdd_ctx: HDD context
6087 *
6088 * Register netdev notifiers like IPv4 and IPv6.
6089 *
6090 * Return: 0 on success and errno on failure
6091 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006092static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006093{
6094 int ret;
6095
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006096 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6097 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306098 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006099
6100 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6101 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6102 if (ret) {
6103 hdd_err("Failed to register IPv4 notifier: %d", ret);
6104 goto unregister_ip6_notifier;
6105 }
6106
6107 return 0;
6108
6109unregister_ip6_notifier:
6110 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006111out:
6112 return ret;
6113
6114}
6115
6116/**
6117 * hdd_unregister_notifiers - Unregister netdev notifiers.
6118 * @hdd_ctx: HDD context
6119 *
6120 * Unregister netdev notifiers like IPv4 and IPv6.
6121 *
6122 * Return: None.
6123 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006124void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006125{
6126 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6127
6128 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006129}
6130
6131/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006132 * hdd_exit_netlink_services - Exit netlink services
6133 * @hdd_ctx: HDD context
6134 *
6135 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6136 * nl service.
6137 *
6138 * Return: None.
6139 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006140static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006141{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006142 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006143 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006144 ptt_sock_deactivate_svc();
6145
6146 nl_srv_exit();
6147}
6148
6149/**
6150 * hdd_init_netlink_services- Init netlink services
6151 * @hdd_ctx: HDD context
6152 *
6153 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6154 * nl service.
6155 *
6156 * Return: 0 on success and errno on failure.
6157 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006158static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006159{
6160 int ret;
6161
Ryan Hsuceddceb2016-04-28 10:20:14 -07006162 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006163 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006164 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006165 goto out;
6166 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006167 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006168
Naveen Rawat910726a2017-03-06 11:42:51 -08006169 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006170 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006171 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006172 goto err_nl_srv;
6173 }
6174
6175 ret = ptt_sock_activate_svc();
6176 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006177 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006178 goto err_nl_srv;
6179 }
6180
6181 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006182 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006183 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006184
6185 ret = cnss_diag_activate_service();
6186 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006187 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006188 goto err_close_cesium;
6189 }
6190
6191 return 0;
6192
6193err_close_cesium:
6194 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006195 ptt_sock_deactivate_svc();
6196err_nl_srv:
6197 nl_srv_exit();
6198out:
6199 return ret;
6200}
6201
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006202/**
6203 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6204 * @hdd_ctx: HDD context.
6205 *
6206 * Destroy RX wakelock.
6207 *
6208 * Return: None.
6209 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006210static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006211{
6212 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6213}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006214
6215/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006216 * hdd_rx_wake_lock_create() - Create RX wakelock
6217 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006218 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006219 * Create RX wakelock.
6220 *
6221 * Return: None.
6222 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006223static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006224{
6225 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6226}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006227
6228/**
Houston Hoffman160db392016-10-10 17:37:51 -07006229 * hdd_context_deinit() - Deinitialize HDD context
6230 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006231 *
Houston Hoffman160db392016-10-10 17:37:51 -07006232 * Deinitialize HDD context along with all the feature specific contexts but
6233 * do not free hdd context itself. Caller of this API is supposed to free
6234 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006235 *
Houston Hoffman160db392016-10-10 17:37:51 -07006236 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006237 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006238static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006239{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306240 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6241
Houston Hoffman160db392016-10-10 17:37:51 -07006242 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006243
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006244 hdd_sap_context_destroy(hdd_ctx);
6245
6246 hdd_rx_wake_lock_destroy(hdd_ctx);
6247
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006248 hdd_scan_context_destroy(hdd_ctx);
6249
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006250 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006251
Houston Hoffman160db392016-10-10 17:37:51 -07006252 return 0;
6253}
6254
6255/**
6256 * hdd_context_destroy() - Destroy HDD context
6257 * @hdd_ctx: HDD context to be destroyed.
6258 *
6259 * Free config and HDD context as well as destroy all the resources.
6260 *
6261 * Return: None
6262 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006263static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006264{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006265 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306266
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306267 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6268
Houston Hoffman160db392016-10-10 17:37:51 -07006269 hdd_context_deinit(hdd_ctx);
6270
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306271 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006272 hdd_ctx->config = NULL;
6273
6274 wiphy_free(hdd_ctx->wiphy);
6275}
6276
6277/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306278 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6279 *
6280 * This function is used to destroy bug report lock
6281 *
6282 * Return: None
6283 */
6284static void wlan_destroy_bug_report_lock(void)
6285{
6286 p_cds_contextType p_cds_context;
6287
6288 p_cds_context = cds_get_global_context();
6289 if (!p_cds_context) {
6290 hdd_err("cds context is NULL");
6291 return;
6292 }
6293
6294 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6295}
6296
6297/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006298 * hdd_wlan_exit() - HDD WLAN exit function
6299 * @hdd_ctx: Pointer to the HDD Context
6300 *
6301 * This is the driver exit point (invoked during rmmod)
6302 *
6303 * Return: None
6304 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006305static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006306{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006307 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306308 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006309
6310 ENTER();
6311
Dustin Brown6f427922017-09-19 12:19:00 -07006312 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306313
6314 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315
Prashanth Bhattaab004382016-10-11 16:08:11 -07006316 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006317
6318#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306319 if (QDF_TIMER_STATE_RUNNING ==
6320 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6321 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006322 }
6323
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306324 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306325 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006326 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006328 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6329 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6330 hdd_ctx->last_acs_channel_list = NULL;
6331 hdd_ctx->num_of_channels = 0;
6332 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006333#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006334
Arun Khandavallifae92942016-08-01 13:31:08 +05306335 mutex_lock(&hdd_ctx->iface_change_lock);
6336 driver_status = hdd_ctx->driver_status;
6337 mutex_unlock(&hdd_ctx->iface_change_lock);
6338
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339 /*
6340 * Powersave Offload Case
6341 * Disable Idle Power Save Mode
6342 */
6343 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006344 /* clear the scan queue in all the scenarios */
6345 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346
Arun Khandavallifae92942016-08-01 13:31:08 +05306347 if (driver_status != DRIVER_MODULES_CLOSED) {
6348 hdd_unregister_wext_all_adapters(hdd_ctx);
6349 /*
6350 * Cancel any outstanding scan requests. We are about to close
6351 * all of our adapters, but an adapter structure is what SME
6352 * passes back to our callback function. Hence if there
6353 * are any outstanding scan requests then there is a
6354 * race condition between when the adapter is closed and
6355 * when the callback is invoked. We try to resolve that
6356 * race condition here by canceling any outstanding scans
6357 * before we close the adapters.
6358 * Note that the scans may be cancelled in an asynchronous
6359 * manner, so ideally there needs to be some kind of
6360 * synchronization. Rather than introduce a new
6361 * synchronization here, we will utilize the fact that we are
6362 * about to Request Full Power, and since that is synchronized,
6363 * the expectation is that by the time Request Full Power has
6364 * completed, all scans will be cancelled
6365 */
6366 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006367 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006368 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006369 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006370 }
6371
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306372 unregister_netdevice_notifier(&hdd_netdev_notifier);
6373
Dustin Brown36e24e22017-12-21 12:34:13 -08006374 hdd_close_all_adapters(hdd_ctx, false);
6375
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006376 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306377
Dustin Brown021cecd2017-12-11 13:56:43 -08006378 hdd_driver_memdump_deinit();
6379
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306380 qdf_nbuf_deinit_replenish_timer();
6381
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306382 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6383 hdd_info("Release wakelock for monitor mode!");
6384 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6385 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6386 }
6387
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306388 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6389 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6390 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6391
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006392 /*
6393 * Close CDS
6394 * This frees pMac(HAL) context. There should not be any call
6395 * that requires pMac access after this.
6396 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006397
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006398 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006399
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006400 hdd_ipa_cleanup(hdd_ctx);
6401
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306402 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306403 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306404 /*
6405 * If there is re_init failure wiphy would have already de-registered
6406 * check the wiphy status before un-registering again
6407 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306408 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306409 wiphy_unregister(wiphy);
6410 wlan_hdd_cfg80211_deinit(wiphy);
6411 hdd_lpass_notify_stop(hdd_ctx);
6412 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006413
Arun Khandavallifae92942016-08-01 13:31:08 +05306414 hdd_exit_netlink_services(hdd_ctx);
6415 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306416#ifdef FEATURE_WLAN_CH_AVOID
6417 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6418#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306419
Abhishek Singhe9068f12017-03-31 14:14:52 +05306420 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6421 if (driver_status)
6422 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006423
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006424 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006425}
6426
6427void __hdd_wlan_exit(void)
6428{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006429 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006430
6431 ENTER();
6432
Anurag Chouhan6d760662016-02-20 16:05:43 +05306433 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006434 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006435 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006436 EXIT();
6437 return;
6438 }
6439
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006440 /* Do all the cleanup before deregistering the driver */
6441 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006442
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006443 EXIT();
6444}
6445
6446#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006447/**
6448 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006449 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006450 *
6451 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6452 * Then new ACS request will do a fresh scan without reusing the cached
6453 * scan information.
6454 *
6455 * Return: void
6456 */
Tang Yingying523322d2017-01-17 23:28:43 +08006457static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006458{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006459 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006460
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006461 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006462 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006463 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6464 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6465 hdd_ctx->last_acs_channel_list = NULL;
6466 hdd_ctx->num_of_channels = 0;
6467 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006468
6469 if (!hdd_ctx->hHal)
6470 return;
6471 sme_scan_flush_result(hdd_ctx->hHal);
6472}
6473#endif
6474
6475#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006476int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6477 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006478{
6479 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306480 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006481 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006482
6483 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6484
6485 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306486 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006487 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306488
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006489 if (!hdd_ctx->hHal)
6490 return -EINVAL;
6491
Jeff Johnsone7672e72017-10-21 15:10:04 -07006492 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006493 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306494 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006495 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006496 return -EINVAL;
6497 }
6498
6499 return 0;
6500}
6501#endif
6502
6503/**
6504 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6505 * @state: state
6506 *
6507 * This function notifies FW with modem power status
6508 *
6509 * Return: 0 if successful, error number otherwise
6510 */
6511int hdd_wlan_notify_modem_power_state(int state)
6512{
6513 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306514 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006515 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006516
Anurag Chouhan6d760662016-02-20 16:05:43 +05306517 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006518 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306519 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006520 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306521
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522 if (!hdd_ctx->hHal)
6523 return -EINVAL;
6524
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306525 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6526 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006527 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006528 state);
6529 return -EINVAL;
6530 }
6531 return 0;
6532}
6533
6534/**
6535 *
6536 * hdd_post_cds_enable_config() - HDD post cds start config helper
6537 * @adapter - Pointer to the HDD
6538 *
6539 * Return: None
6540 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006541QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006542{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306543 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006544
6545 /*
6546 * Send ready indication to the HDD. This will kick off the MAC
6547 * into a 'running' state and should kick off an initial scan.
6548 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306549 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6550 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006551 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6552 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306553 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006554 }
6555
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306556 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006557}
6558
6559/* wake lock APIs for HDD */
6560void hdd_prevent_suspend(uint32_t reason)
6561{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306562 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006563}
6564
6565void hdd_allow_suspend(uint32_t reason)
6566{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306567 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006568}
6569
6570void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6571{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306572 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6573 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006574}
6575
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006576/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006577QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006578{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006579
Amar Singhal6f8592b2017-04-26 14:31:58 -07006580 return sme_init_chan_list(hdd_ctx->hHal,
6581 hdd_ctx->reg.alpha2,
6582 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006583}
6584
6585/**
6586 * hdd_is_5g_supported() - check if hardware supports 5GHz
6587 * @hdd_ctx: Pointer to the hdd context
6588 *
6589 * HDD function to know if hardware supports 5GHz
6590 *
6591 * Return: true if hardware supports 5GHz
6592 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006593bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006595 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006596 return true;
6597
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006598 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006599 return true;
6600 else
6601 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006602}
6603
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006604static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006605{
6606 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006607 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006608
6609 wiphy = hdd_ctx->wiphy;
6610
6611 /*
6612 * The channel information in
6613 * wiphy needs to be initialized before wiphy registration
6614 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006615 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6616 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006617 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006618 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006619 }
6620
6621#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6622 wiphy->wowlan = &wowlan_support_reg_init;
6623#else
6624 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6625 WIPHY_WOWLAN_MAGIC_PKT |
6626 WIPHY_WOWLAN_DISCONNECT |
6627 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6628 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6629 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6630 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6631 WIPHY_WOWLAN_RFKILL_RELEASE;
6632
6633 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6634 WOW_MAX_FILTERS_PER_LIST);
6635 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6636 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6637#endif
6638
6639 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006640 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306641 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006642 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306643 return ret_val;
6644 }
6645
Amar Singhal5cccafe2017-02-15 12:42:58 -08006646 if (!hdd_ctx->reg_offload)
6647 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648
Amar Singhale4f28ee2015-10-21 14:36:56 -07006649 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650}
6651
Mohit Khannaca4173b2017-09-12 21:52:19 -07006652#ifdef MSM_PLATFORM
6653/**
6654 * hdd_display_periodic_stats() - Function to display periodic stats
6655 * @hdd_ctx - handle to hdd context
6656 * @bool data_in_interval - true, if data detected in bw time interval
6657 *
6658 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6659 * Stats show up in wlan driver logs.
6660 *
6661 * Returns: None
6662 */
6663static inline
6664void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6665 bool data_in_interval)
6666{
6667 static u32 counter;
6668 static bool data_in_time_period;
6669 ol_txrx_pdev_handle pdev;
6670
6671 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6672 return;
6673
6674 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6675 if (!pdev) {
6676 hdd_err("pdev is NULL");
6677 return;
6678 }
6679
6680 counter++;
6681 if (data_in_interval)
6682 data_in_time_period = data_in_interval;
6683
6684 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6685 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6686 if (data_in_time_period) {
6687 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6688 CDP_TXRX_PATH_STATS,
6689 QDF_STATS_VERBOSITY_LEVEL_LOW);
6690 wlan_hdd_display_netif_queue_history
6691 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6692 qdf_dp_trace_dump_stats();
6693 }
6694 counter = 0;
6695 data_in_time_period = false;
6696 }
6697}
6698
Ravi Joshie2331e82015-07-01 18:18:54 -07006699/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006700 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006701 * @hdd_ctx - handle to hdd context
6702 * @tx_packets - transmit packet count
6703 * @rx_packets - receive packet count
6704 *
6705 * The function controls the bus bandwidth and dynamic control of
6706 * tcp delayed ack configuration
6707 *
6708 * Returns: None
6709 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006710
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006711static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006712 const uint64_t tx_packets,
6713 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006714{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006715 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006716 uint64_t temp_rx = 0;
6717 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006718 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006719 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006720 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006721 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006722 uint16_t index = 0;
6723 bool vote_level_change = false;
6724 bool rx_level_change = false;
6725 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006726
Mohit Khannaca4173b2017-09-12 21:52:19 -07006727 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006728 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006729 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006730 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006731 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006732 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006733 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006734 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006735
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006736 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006737 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6738 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006739 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006740 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006741 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306742 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306743 if (hdd_ctx->hbw_requested) {
6744 pld_remove_pm_qos(hdd_ctx->parent_dev);
6745 hdd_ctx->hbw_requested = false;
6746 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306747 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006748 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006749 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306750 if (!hdd_ctx->hbw_requested) {
6751 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6752 hdd_ctx->hbw_requested = true;
6753 }
6754
Nirav Shah3bbfa512016-05-12 16:43:49 +05306755 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006756 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006757 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006758 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006759 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006760
Mohit Khannaf8f96822017-05-17 17:11:59 -07006761 qdf_dp_trace_throttle_live_mode(
6762 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6763
Mohit Khannae71e2262015-11-10 09:37:24 -08006764 /* fine-tuning parameters for RX Flows */
6765 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006767 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006768
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306769 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6770 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6771 else
6772 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6773
Ravi Joshifed83572016-10-07 16:20:37 -07006774 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6775 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6776 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6777 next_rx_level = WLAN_SVC_TP_HIGH;
6778 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006779 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006780 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006781 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006782 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006783
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006784 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006785 struct wlan_rx_tp_data rx_tp_data = {0};
6786
Ravi Joshie2331e82015-07-01 18:18:54 -07006787 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788 next_rx_level, temp_rx);
6789 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006790 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006791 /* Send throughput indication only if it is enabled.
6792 * Disabling tcp_del_ack will revert the tcp stack behavior
6793 * to default delayed ack. Note that this will disable the
6794 * dynamic delayed ack mechanism across the system
6795 */
6796 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006797 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6798
Mohit Khanna6272fb682017-04-13 09:34:36 -07006799 if (hdd_ctx->config->enable_tcp_adv_win_scale)
6800 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6801
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006802 rx_tp_data.level = next_rx_level;
6803 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6804 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6805 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006806 }
6807
Mohit Khannae71e2262015-11-10 09:37:24 -08006808 /* fine-tuning parameters for TX Flows */
6809 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6810 hdd_ctx->prev_tx = tx_packets;
6811 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6812 next_tx_level = WLAN_SVC_TP_HIGH;
6813 else
6814 next_tx_level = WLAN_SVC_TP_LOW;
6815
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006816 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006817 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6818 next_tx_level, temp_tx);
6819 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006820 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306821 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6822 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006823 &next_tx_level,
6824 sizeof(next_tx_level));
6825 }
6826
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006827 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006828 if (vote_level_change || tx_level_change || rx_level_change) {
6829 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6830 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6831 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6832 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6833 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6834 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6835 hdd_ctx->hdd_txrx_hist_idx++;
6836 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6837 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07006838
6839 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006840}
6841
6842#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306843static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006844{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006845 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306846 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006847 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306848 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306849 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6850 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006851 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306852 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006853 bool connected = false;
6854 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6855
Prashanth Bhattaab004382016-10-11 16:08:11 -07006856 if (wlan_hdd_validate_context(hdd_ctx))
6857 return;
6858
Jeff Johnson214671b2017-10-30 19:45:23 -07006859 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006860 goto restart_timer;
6861
Dustin Brown920397d2017-12-13 16:27:50 -08006862 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05306863 /*
6864 * Validate magic so we don't end up accessing
6865 * an invalid adapter.
6866 */
6867 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6868 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006870 if ((adapter->device_mode == QDF_STA_MODE ||
6871 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006872 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6873 != eConnectionState_Associated) {
6874
6875 continue;
6876 }
6877
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006878 if ((adapter->device_mode == QDF_SAP_MODE ||
6879 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006880 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006881
6882 continue;
6883 }
6884
6885 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6886 adapter->prev_tx_packets);
6887 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6888 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306889
6890 if (adapter->device_mode == QDF_SAP_MODE ||
6891 adapter->device_mode == QDF_P2P_GO_MODE ||
6892 adapter->device_mode == QDF_IBSS_MODE) {
6893
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006894 ret = cdp_get_intra_bss_fwd_pkts_count(
6895 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006896 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306897 &fwd_tx_packets, &fwd_rx_packets);
6898 if (ret == A_OK) {
6899 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6900 fwd_tx_packets,
6901 adapter->prev_fwd_tx_packets);
6902 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6903 fwd_tx_packets,
6904 adapter->prev_fwd_rx_packets);
6905 }
6906 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006907
6908 total_rx += adapter->stats.rx_packets;
6909 total_tx += adapter->stats.tx_packets;
6910
6911 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6912 adapter->prev_tx_packets = adapter->stats.tx_packets;
6913 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306914 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6915 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006916 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6917 connected = true;
6918 }
6919
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306920 /* add intra bss forwarded tx and rx packets */
6921 tx_packets += fwd_tx_packets_diff;
6922 rx_packets += fwd_rx_packets_diff;
6923
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006924 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6925 tx_packets += (uint64_t)ipa_tx_packets;
6926 rx_packets += (uint64_t)ipa_rx_packets;
6927
Yun Park2aa880c2017-08-22 10:58:10 -07006928 if (adapter) {
6929 adapter->stats.tx_packets += ipa_tx_packets;
6930 adapter->stats.rx_packets += ipa_rx_packets;
6931 }
6932
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006933 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006934 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006935 return;
6936 }
6937
Yuanyuan Liu13738502016-04-06 17:41:37 -07006938 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006939
6940 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6941 hdd_ipa_uc_stat_request(adapter, 2);
6942
Jingxiang Gec64e1932017-08-22 14:38:59 +08006943restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006944 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006945 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006946 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306947 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006948 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006949 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006950}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006951
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306952/**
6953 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6954 * @arg: Argument of timer function
6955 *
6956 * Schedule a workqueue in this function where all the processing is done.
6957 *
6958 * Return: None.
6959 */
6960static void __hdd_bus_bw_cbk(void *arg)
6961{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006962 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306963
6964 if (wlan_hdd_validate_context(hdd_ctx))
6965 return;
6966
6967 schedule_work(&hdd_ctx->bus_bw_work);
6968}
6969
6970/**
6971 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6972 * @arg: Argument of timer function
6973 *
6974 * Return: None.
6975 */
6976static void hdd_bus_bw_cbk(void *arg)
6977{
6978 cds_ssr_protect(__func__);
6979 __hdd_bus_bw_cbk(arg);
6980 cds_ssr_unprotect(__func__);
6981}
6982
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006983int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006984{
6985 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306986 INIT_WORK(&hdd_ctx->bus_bw_work,
6987 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006988 hdd_ctx->bus_bw_timer_running = false;
6989 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306990 qdf_timer_init(NULL,
6991 &hdd_ctx->bus_bw_timer,
6992 hdd_bus_bw_cbk, (void *)hdd_ctx,
6993 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006994
6995 return 0;
6996}
6997
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006998void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006999{
Dustin Brownfce08d12017-01-17 16:29:38 -08007000 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007001 hdd_reset_tcp_delack(hdd_ctx);
7002
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007003 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307004 cancel_work_sync(&hdd_ctx->bus_bw_work);
7005 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007006 hdd_ctx->bus_bw_timer_running = false;
7007 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007008}
Lin Baic5c06882017-09-21 13:58:43 +08007009
7010void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7011{
7012 if (hdd_ctx)
7013 cancel_work_sync(&hdd_ctx->bus_bw_work);
7014}
jiadcdaf9bd2017-10-26 12:20:21 +08007015
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007016#endif
7017
7018/**
Nirav Shahed34b212016-04-25 10:59:16 +05307019 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7020 * @hdd_ctx: hdd context
7021 *
7022 * Return: 0 for success or error code
7023 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007024static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307025{
7026 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7027 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7028 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007029 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307030 return -ENOMEM;
7031 }
7032 return 0;
7033}
7034
7035/**
7036 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7037 * @hdd_ctx: hdd context
7038 *
7039 * Return: none
7040 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007041void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307042{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307043 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7044 return;
7045
7046 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7047 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307048}
7049
Nirav Shahda008342016-05-17 18:50:40 +05307050static uint8_t *convert_level_to_string(uint32_t level)
7051{
7052 switch (level) {
7053 /* initialize the wlan sub system */
7054 case WLAN_SVC_TP_NONE:
7055 return "NONE";
7056 case WLAN_SVC_TP_LOW:
7057 return "LOW";
7058 case WLAN_SVC_TP_MEDIUM:
7059 return "MED";
7060 case WLAN_SVC_TP_HIGH:
7061 return "HIGH";
7062 default:
7063 return "INVAL";
7064 }
7065}
7066
Nirav Shahed34b212016-04-25 10:59:16 +05307067
7068/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007069 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7070 * @hdd_ctx: hdd context
7071 *
7072 * Return: none
7073 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007074void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007075{
7076 int i;
7077
7078#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007079 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307080 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007081 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007082 hdd_ctx->config->busBandwidthHighThreshold,
7083 hdd_ctx->config->busBandwidthMediumThreshold,
7084 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007085 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307086 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007087 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007088 hdd_ctx->config->tcpDelackThresholdHigh,
7089 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007090 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307091 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007092#endif
7093
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007094 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307095 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7096
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007097 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007098
7099 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007100 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007101 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07007102 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007103 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7104 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007105 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007106 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7107 convert_level_to_string(
7108 hdd_ctx->hdd_txrx_hist[i].
7109 next_vote_level),
7110 convert_level_to_string(
7111 hdd_ctx->hdd_txrx_hist[i].
7112 next_rx_level),
7113 convert_level_to_string(
7114 hdd_ctx->hdd_txrx_hist[i].
7115 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007116 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007117}
7118
7119/**
7120 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7121 * @hdd_ctx: hdd context
7122 *
7123 * Return: none
7124 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007125void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007126{
7127 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307128 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7129 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130}
7131
Mohit Khannaca4173b2017-09-12 21:52:19 -07007132/* length of the netif queue log needed per adapter */
7133#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7134
7135/**
7136 *
7137 * hdd_display_netif_queue_history_compact() - display compact netifq history
7138 * @hdd_ctx: hdd context
7139 *
7140 * Return: none
7141 */
7142static void
7143hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7144{
7145 int adapter_num = 0;
7146 int i;
7147 int bytes_written;
7148 u32 tbytes;
7149 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007150 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007151 char *comb_log_str;
7152 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007153 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007154
jiadbdefb252018-01-03 14:27:06 +08007155 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7156 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7157 if (!comb_log_str) {
7158 hdd_err("failed to alloc comb_log_str");
7159 return;
7160 }
7161
Mohit Khannaca4173b2017-09-12 21:52:19 -07007162 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007163
Dustin Brown920397d2017-12-13 16:27:50 -08007164 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007165 curr_time = qdf_system_ticks();
7166 total = curr_time - adapter->start_time;
7167 delta = curr_time - adapter->last_time;
7168
7169 if (adapter->pause_map) {
7170 pause = adapter->total_pause_time + delta;
7171 unpause = adapter->total_unpause_time;
7172 } else {
7173 unpause = adapter->total_unpause_time + delta;
7174 pause = adapter->total_pause_time;
7175 }
7176
7177 tbytes = 0;
7178 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7179 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7180 if (adapter->queue_oper_stats[i].pause_count == 0)
7181 continue;
7182 tbytes +=
7183 snprintf(
7184 &temp_str[tbytes],
7185 (tbytes >= sizeof(temp_str) ?
7186 0 : sizeof(temp_str) - tbytes),
7187 "%d(%d,%d) ",
7188 i,
7189 adapter->queue_oper_stats[i].
7190 pause_count,
7191 adapter->queue_oper_stats[i].
7192 unpause_count);
7193 }
7194 if (tbytes >= sizeof(temp_str))
7195 hdd_warn("log truncated");
7196
7197 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007198 bytes_written >= comb_log_str_size ? 0 :
7199 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007200 "[%d %d] (%d) %u/%ums %s|",
7201 adapter->session_id, adapter->device_mode,
7202 adapter->pause_map,
7203 qdf_system_ticks_to_msecs(pause),
7204 qdf_system_ticks_to_msecs(total),
7205 temp_str);
7206
Mohit Khannaca4173b2017-09-12 21:52:19 -07007207 adapter_num++;
7208 }
7209
7210 /* using QDF_TRACE to avoid printing function name */
7211 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7212 "STATS |%s", comb_log_str);
7213
jiadbdefb252018-01-03 14:27:06 +08007214 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007215 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007216
7217 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007218}
7219
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007220/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007221 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007222 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007223 *
7224 * Return: none
7225 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007226void
7227wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7228 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007229{
7230
Jeff Johnson9d295242017-08-29 14:39:48 -07007231 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007232 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307233 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007234
Mohit Khannaca4173b2017-09-12 21:52:19 -07007235 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7236 hdd_display_netif_queue_history_compact(hdd_ctx);
7237 return;
7238 }
7239
Dustin Brown920397d2017-12-13 16:27:50 -08007240 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007241 hdd_debug("Netif queue operation statistics:");
7242 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007243 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007244 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307245 curr_time = qdf_system_ticks();
7246 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307247 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307248 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307249 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307250 unpause = adapter->total_unpause_time;
7251 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307252 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307253 pause = adapter->total_pause_time;
7254 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007255 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307256 qdf_system_ticks_to_msecs(total),
7257 qdf_system_ticks_to_msecs(pause),
7258 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007259 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007260
Nirav Shahda008342016-05-17 18:50:40 +05307261 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7262 qdf_time_t pause_delta = 0;
7263
7264 if (adapter->pause_map & (1 << i))
7265 pause_delta = delta;
7266
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007267 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07007268 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007269 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007270 hdd_reason_type_to_string(i),
7271 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05307272 adapter->queue_oper_stats[i].unpause_count,
7273 qdf_system_ticks_to_msecs(
7274 adapter->queue_oper_stats[i].total_pause_time +
7275 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007276 }
7277
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007278 hdd_debug("Netif queue operation history:");
7279 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307280 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7281
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007282 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007283
7284 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007285 /* using hdd_log to avoid printing function name */
7286 if (adapter->queue_oper_history[i].time == 0)
7287 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07007288 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007289 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05307290 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007291 adapter->queue_oper_history[i].time),
7292 hdd_action_type_to_string(
7293 adapter->queue_oper_history[i].netif_action),
7294 hdd_reason_type_to_string(
7295 adapter->queue_oper_history[i].netif_reason),
7296 adapter->queue_oper_history[i].pause_map);
7297 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007298 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007299}
7300
7301/**
7302 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7303 * @hdd_ctx: hdd context
7304 *
7305 * Return: none
7306 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007307void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007308{
Jeff Johnson9d295242017-08-29 14:39:48 -07007309 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007310
Dustin Brown920397d2017-12-13 16:27:50 -08007311 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307312 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007313 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307314 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007315 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307316 adapter->history_index = 0;
7317 adapter->start_time = adapter->last_time = qdf_system_ticks();
7318 adapter->total_pause_time = 0;
7319 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007320 }
7321}
7322
7323/**
7324 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7325 * @halHandle: Hal handle
7326 * @pContext: Pointer to the context
7327 * @sessionId: Session ID
7328 * @scanId: Scan ID
7329 * @status: Status
7330 *
7331 * This is the callback to be executed when 11d scan is completed to flush out
7332 * the scan results
7333 *
7334 * 11d scan is done during driver load and is a passive scan on all
7335 * channels supported by the device, 11d scans may find some APs on
7336 * frequencies which are forbidden to be used in the regulatory domain
7337 * the device is operating in. If these APs are notified to the supplicant
7338 * it may try to connect to these APs, thus flush out all the scan results
7339 * which are present in SME after 11d scan is done.
7340 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307341 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307343static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007344 uint8_t sessionId, uint32_t scanId,
7345 eCsrScanStatus status)
7346{
7347 ENTER();
7348
7349 sme_scan_flush_result(halHandle);
7350
7351 EXIT();
7352
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307353 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007354}
7355
7356#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7357/**
7358 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7359 * @hdd_ctx: hdd global context
7360 *
7361 * Return: none
7362 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007363static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007364{
7365 uint8_t i;
7366
7367 mutex_init(&hdd_ctx->op_ctx.op_lock);
7368 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7369 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7370 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7371 }
7372}
7373#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007374static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007375{
7376}
7377#endif
7378
Yingying Tang95409972016-10-20 15:16:15 +08007379#ifdef WLAN_FEATURE_WOW_PULSE
7380/**
7381 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007382 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007383 * @enable: enable or disable this behaviour
7384 *
7385 * Return: int
7386 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007387static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007388{
7389 struct hdd_config *pcfg_ini = phddctx->config;
7390 struct wow_pulse_mode wow_pulse_set_info;
7391 QDF_STATUS status;
7392
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007393 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007394
7395 if (false == phddctx->config->wow_pulse_support)
7396 return 0;
7397
7398 /* prepare the request to send to SME */
7399 if (enable == true) {
7400 wow_pulse_set_info.wow_pulse_enable = true;
7401 wow_pulse_set_info.wow_pulse_pin =
7402 pcfg_ini->wow_pulse_pin;
7403 wow_pulse_set_info.wow_pulse_interval_low =
7404 pcfg_ini->wow_pulse_interval_low;
7405 wow_pulse_set_info.wow_pulse_interval_high =
7406 pcfg_ini->wow_pulse_interval_high;
7407 } else {
7408 wow_pulse_set_info.wow_pulse_enable = false;
7409 wow_pulse_set_info.wow_pulse_pin = 0;
7410 wow_pulse_set_info.wow_pulse_interval_low = 0;
7411 wow_pulse_set_info.wow_pulse_interval_high = 0;
7412 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007413 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007414 wow_pulse_set_info.wow_pulse_enable,
7415 wow_pulse_set_info.wow_pulse_pin,
7416 wow_pulse_set_info.wow_pulse_interval_low,
7417 wow_pulse_set_info.wow_pulse_interval_high);
7418
7419 status = sme_set_wow_pulse(&wow_pulse_set_info);
7420 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007421 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007422 return -EIO;
7423 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007424 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007425 return 0;
7426}
7427#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007428static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007429{
7430 return 0;
7431}
7432#endif
7433
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007434#ifdef WLAN_FEATURE_FASTPATH
7435/**
7436 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7437 * @hdd_cfg: hdd config
7438 * @context: lower layer context
7439 *
7440 * Return: none
7441 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307442void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007443 void *context)
7444{
7445 if (hdd_cfg->fastpath_enable)
7446 hif_enable_fastpath(context);
7447}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007448#endif
7449
Yuanyuan Liu13738502016-04-06 17:41:37 -07007450#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007451/**
7452 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007453 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007454 * @level: thermal level
7455 *
7456 * Change IPA data path to SW path when the thermal throttle level greater
7457 * than 0, and restore the original data path when throttle level is 0
7458 *
7459 * Return: none
7460 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007461static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007462{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007463 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007464
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007465 /* Change IPA to SW path when throttle level greater than 0 */
7466 if (level > THROTTLE_LEVEL_0)
7467 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7468 else
7469 /* restore original concurrency mode */
7470 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7471}
7472
7473/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307474 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7475 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307476 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007477 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307478 * Get a safe channel to restart SAP. PCL already takes into account the
7479 * unsafe channels. So, the PCL is validated with the ACS range to provide
7480 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007481 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307482 * Return: Channel number to restart SAP in case of success. In case of any
7483 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007484 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307485static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007486 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007487{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307488 struct sir_pcl_list pcl;
7489 QDF_STATUS status;
7490 uint32_t i, j;
7491 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007492 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307493 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007494 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007495
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307496 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7497 if (!hdd_ctx) {
7498 hdd_err("invalid HDD context");
7499 return INVALID_CHANNEL_ID;
7500 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007501
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307502 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7503 if (!hal_handle) {
7504 hdd_err("invalid HAL handle");
7505 return INVALID_CHANNEL_ID;
7506 }
7507
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007508 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7509 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007510 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7511 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307512 if (QDF_IS_STATUS_ERROR(status)) {
7513 hdd_err("Get PCL failed");
7514 return INVALID_CHANNEL_ID;
7515 }
7516
Frank Liudc2cefb2017-06-21 15:38:18 +08007517 /*
7518 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7519 * channel is unsafe channel, the pcl may be empty, instead of return,
7520 * try to choose a safe channel from acs range.
7521 */
7522 if (!pcl.pcl_len)
7523 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307524
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007525 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007526 adapter->session.ap.sap_config.acs_cfg.start_ch,
7527 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307528
7529 /* PCL already takes unsafe channel into account */
7530 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007531 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307532 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007533 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307534 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007535 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007536 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307537 return pcl.pcl_list[i];
7538 }
7539 }
7540
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007541 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307542
7543 /* Try for safe channel from all valid channel */
7544 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007545 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7546 &pcl.pcl_len);
7547 if (ret) {
7548 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307549 return INVALID_CHANNEL_ID;
7550 }
7551
7552 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007553 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307554 found = false;
7555 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007556 if (pcl.pcl_list[i] ==
7557 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007558 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307559 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560 break;
7561 }
7562 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307563
7564 if (found)
7565 continue;
7566
7567 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007568 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307569 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007570 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007571 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307572 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007573 }
7574 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307575
7576 return INVALID_CHANNEL_ID;
7577}
7578
7579/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007580 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307581 * @adapter: AP adapter
7582 * @channel: Channel
7583 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007584 * Moves the SAP interface by invoking the function which
7585 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307586 *
7587 * Return: None
7588 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007589void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307590{
Jeff Johnson87251032017-08-29 13:31:11 -07007591 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307592 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007593 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307594
7595 if (!adapter) {
7596 hdd_err("invalid adapter");
7597 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007598 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307599
7600 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7601
7602 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7603 if (!hal_handle) {
7604 hdd_err("invalid HAL handle");
7605 return;
7606 }
7607
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007608 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7609
Jeff Johnson91df29d2017-10-27 19:29:50 -07007610 hdd_ap_ctx->sap_config.channel = channel;
7611 hdd_ap_ctx->sap_config.ch_params.ch_width =
7612 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307613
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007614 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007615 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307616
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007617 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007618 hdd_ap_ctx->sap_config.channel,
7619 hdd_ap_ctx->sap_config.sec_ch,
7620 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307621
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007622 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007623 adapter->session_id, channel,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007624 hdd_ap_ctx->sap_config.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007625}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307626
Jeff Johnson9d295242017-08-29 14:39:48 -07007627int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307628{
7629 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307630 int status;
7631 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307632
7633 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7634
7635 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007636 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307637 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007638 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307639 }
7640 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007641 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307642 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307643 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007644 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307645 WLAN_VENDOR_ACS_WAIT_TIME);
7646 if (qdf_status != QDF_STATUS_SUCCESS) {
7647 hdd_err("failed to start external acs timer");
7648 return -ENOSPC;
7649 }
7650 /* Update config to application */
7651 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307652 hdd_notice("Updated ACS config to nl with reason %d", reason);
7653
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307654 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307655}
7656
Agrawal Ashish467dde42016-09-08 18:44:22 +05307657/**
7658 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7659 * @hdd_ctx: hdd context pointer
7660 *
7661 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7662 * and if ACS is enabled, driver will ask userspace to restart the
7663 * sap. User space on LTE coex indication restart driver.
7664 *
7665 * Return - none
7666 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007667void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307668{
Dustin Brown920397d2017-12-13 16:27:50 -08007669 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307670 uint32_t i;
7671 bool found = false;
7672 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007673
Dustin Brown920397d2017-12-13 16:27:50 -08007674 hdd_for_each_adapter(hdd_ctxt, adapter) {
7675 if (!(adapter->device_mode == QDF_SAP_MODE &&
7676 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007677 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007678 adapter->device_mode,
7679 adapter->session.ap.sap_config.
7680 acs_cfg.acs_mode);
7681 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307682 }
7683
7684 found = false;
7685 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007686 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307687 hdd_ctxt->unsafe_channel_list[i]) {
7688 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007689 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007690 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307691 break;
7692 }
7693 }
7694
7695 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007696 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007697 adapter->session.ap.operating_channel);
7698 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307699 }
7700
Kapil Gupta8878ad92017-02-13 11:56:04 +05307701 if (hdd_ctxt->config->vendor_acs_support &&
7702 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007703 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307704 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007705 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307706 } else
7707 restart_chan =
7708 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007709 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307710 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007711 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307712 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007713 /*
7714 * SAP restart due to unsafe channel. While
7715 * restarting the SAP, make sure to clear
7716 * acs_channel, channel to reset to
7717 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307718 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007719 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307720 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007721 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307722 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007723 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307724 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7725 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007726 hdd_debug("driver to start sap: %d",
7727 hdd_ctxt->config->sap_internal_restart);
7728 if (hdd_ctxt->config->sap_internal_restart)
Dustin Brown920397d2017-12-13 16:27:50 -08007729 hdd_switch_sap_channel(adapter, restart_chan);
Liangwei Dong6663d162017-07-10 03:29:36 -04007730 else
7731 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307732 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307733 }
7734}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307735
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007736/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007737 * hdd_init_channel_avoidance() - Initialize channel avoidance
7738 * @hdd_ctx: HDD global context
7739 *
7740 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007741 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007742 * down to the lower layers. Then subscribe to subsequent channel
7743 * avoidance events.
7744 *
7745 * Return: None
7746 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007747static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007748{
7749 uint16_t unsafe_channel_count;
7750 int index;
7751
Yuanyuan Liu13738502016-04-06 17:41:37 -07007752 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7753 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007754 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007755 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007756
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007757 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007758 hdd_ctx->unsafe_channel_count);
7759
Anurag Chouhan6d760662016-02-20 16:05:43 +05307760 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007761 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007762
7763 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007764 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007765 hdd_ctx->unsafe_channel_list[index]);
7766
7767 }
7768
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007769}
Dustin Brown676a2322017-08-15 13:16:13 -07007770
Jeff Johnson9d295242017-08-29 14:39:48 -07007771static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007772 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007773{
7774 uint8_t restart_chan;
7775
7776 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7777 if (!restart_chan) {
7778 hdd_alert("fail to restart SAP");
7779 return;
7780 }
7781
7782 /* SAP restart due to unsafe channel. While restarting
7783 * the SAP, make sure to clear acs_channel, channel to
7784 * reset to 0. Otherwise these settings will override
7785 * the ACS while restart.
7786 */
7787 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007788 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007789
7790 hdd_debug("sending coex indication");
7791
7792 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7793 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7794 hdd_switch_sap_channel(adapter, restart_chan);
7795}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007796
7797int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7798 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7799{
7800 uint32_t size;
7801 uint16_t *unsafe_list;
7802 uint16_t chan_count;
7803
7804 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7805 return -EINVAL;
7806
7807 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7808 NUM_CHANNELS);
7809 if (chan_count) {
7810 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7811 unsafe_list = qdf_mem_malloc(size);
7812 if (!unsafe_list) {
7813 hdd_err("No memory for unsafe chan list size%d",
7814 size);
7815 return -ENOMEM;
7816 }
7817 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7818 } else {
7819 unsafe_list = NULL;
7820 }
7821
7822 *local_unsafe_list = unsafe_list;
7823 *local_unsafe_list_count = chan_count;
7824
7825 return 0;
7826}
7827
7828bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7829 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7830{
7831 int i, j;
7832
7833 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7834 return true;
7835 if (local_unsafe_list_count == 0)
7836 return false;
7837 for (i = 0; i < local_unsafe_list_count; i++) {
7838 for (j = 0; j < local_unsafe_list_count; j++)
7839 if (local_unsafe_list[i] ==
7840 hdd_ctx->unsafe_channel_list[j])
7841 break;
7842 if (j >= local_unsafe_list_count)
7843 break;
7844 }
7845 if (i >= local_unsafe_list_count) {
7846 hdd_info("unsafe chan list same");
7847 return false;
7848 }
7849
7850 return true;
7851}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007852#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007853static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007854{
7855}
Dustin Brown676a2322017-08-15 13:16:13 -07007856
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007857static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007858{
7859}
Dustin Brown676a2322017-08-15 13:16:13 -07007860
Jeff Johnson9d295242017-08-29 14:39:48 -07007861static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007862 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007863{
7864 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7865}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007866#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007867
7868/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007869 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7870 * user space
7871 * @frame_ind: Management frame data to be informed.
7872 *
7873 * This function is used to indicate management frame to
7874 * user space
7875 *
7876 * Return: None
7877 *
7878 */
7879void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7880{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007881 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007882 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007883 int i;
7884
Rajeev Kumard004abc2016-02-17 12:09:56 -08007885 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007886 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007887
7888 if (0 != wlan_hdd_validate_context(hdd_ctx))
7889 return;
7890
7891 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7892 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7893 adapter =
7894 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7895 if (adapter)
7896 break;
7897 }
Wu Gaoa0230a62018-01-04 20:56:57 +08007898 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
7899 hdd_for_each_adapter(hdd_ctx, adapter) {
7900 if ((NULL != adapter) &&
7901 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
7902 __hdd_indicate_mgmt_frame(adapter,
7903 frame_ind->frame_len,
7904 frame_ind->frameBuf,
7905 frame_ind->frameType,
7906 frame_ind->rxChan,
7907 frame_ind->rxRssi);
7908 }
7909 }
7910 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007911 } else {
7912 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7913 frame_ind->sessionId);
7914 }
7915
7916 if ((NULL != adapter) &&
7917 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7918 __hdd_indicate_mgmt_frame(adapter,
7919 frame_ind->frame_len,
7920 frame_ind->frameBuf,
7921 frame_ind->frameType,
7922 frame_ind->rxChan,
7923 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007924}
7925
Kapil Gupta8878ad92017-02-13 11:56:04 +05307926void hdd_acs_response_timeout_handler(void *context)
7927{
7928 struct hdd_external_acs_timer_context *timer_context =
7929 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007930 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007931 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307932 uint8_t reason;
7933
7934 ENTER();
7935 if (!timer_context) {
7936 hdd_err("invlaid timer context");
7937 return;
7938 }
7939 adapter = timer_context->adapter;
7940 reason = timer_context->reason;
7941
7942
7943 if ((!adapter) ||
7944 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7945 hdd_err("invalid adapter or adapter has invalid magic");
7946 return;
7947 }
7948 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7949 if (wlan_hdd_validate_context(hdd_ctx))
7950 return;
7951
7952 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7953 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7954 else
7955 return;
7956
7957 hdd_err("ACS timeout happened for %s reason %d",
7958 adapter->dev->name, reason);
7959 switch (reason) {
7960 /* SAP init case */
7961 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7962 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7963 false);
7964 wlan_hdd_cfg80211_start_acs(adapter);
7965 break;
7966 /* DFS detected on current channel */
7967 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7968 wlan_sap_update_next_channel(
7969 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7970 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007971 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307972 break;
7973 /* LTE coex event on current channel */
7974 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7975 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7976 break;
7977 default:
7978 hdd_info("invalid reason for timer invoke");
7979
7980 }
7981}
7982
Rajeev Kumard004abc2016-02-17 12:09:56 -08007983/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007984 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7985 * @hdd_ctx: HDD context
7986 *
7987 * Disables all the dual mac features like DBS, Agile DFS etc.
7988 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307989 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007990 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007991static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007992{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007993 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307994 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007995
7996 if (!hdd_ctx) {
7997 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307998 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007999 }
8000
8001 cfg.scan_config = 0;
8002 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008003 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008004
8005 hdd_debug("Disabling all dual mac features...");
8006
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008007 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308008 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008009 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8010 return status;
8011 }
8012
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308013 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008014}
8015
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008016static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008017wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008018{
8019 struct policy_mgr_dual_mac_config cfg = {0};
8020 QDF_STATUS status;
8021
8022 if (!hdd_ctx) {
8023 hdd_err("HDD context is NULL");
8024 return QDF_STATUS_E_FAILURE;
8025 }
8026
8027 cfg.scan_config = 0;
8028 cfg.fw_mode_config = 0;
8029 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
8030 status = policy_mgr_get_updated_scan_and_fw_mode_config(
8031 hdd_ctx->hdd_psoc, &cfg.scan_config,
8032 &cfg.fw_mode_config,
8033 hdd_ctx->config->dual_mac_feature_disable);
8034
8035 if (status != QDF_STATUS_SUCCESS) {
8036 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
8037 status);
8038 return status;
8039 }
8040
8041 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
8042 cfg.scan_config, cfg.fw_mode_config);
8043
8044 status = sme_soc_set_dual_mac_config(cfg);
8045 if (status != QDF_STATUS_SUCCESS) {
8046 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8047 return status;
8048 }
8049
8050 return QDF_STATUS_SUCCESS;
8051}
8052
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008053/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008054 * hdd_override_ini_config - Override INI config
8055 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008056 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008057 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008058 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008059 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008060 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008061static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008062{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008063
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008064 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8065 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008066 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008067 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008068 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008069 if (0 == enable_11d || 1 == enable_11d) {
8070 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008071 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008072 }
Leo Chang11545d62016-10-17 14:53:50 -07008073
8074 if (!hdd_ipa_is_present(hdd_ctx))
8075 hdd_ctx->config->IpaConfig = 0;
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308076
8077 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8078 !hdd_ctx->config->enable_bcast_probe_rsp) {
8079 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8080 hdd_ctx->config->rssi_assoc_reject_enabled,
8081 hdd_ctx->config->enable_bcast_probe_rsp);
8082 hdd_ctx->config->oce_sta_enabled = 0;
8083 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008084}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008085
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008086/**
8087 * hdd_set_trace_level_for_each - Set trace level for each INI config
8088 * @hdd_ctx - HDD context
8089 *
8090 * Set trace level for each module based on INI config.
8091 *
8092 * Return: None
8093 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008094static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008095{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308096 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8097 hdd_ctx->config->qdf_trace_enable_wdi);
8098 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8099 hdd_ctx->config->qdf_trace_enable_hdd);
8100 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8101 hdd_ctx->config->qdf_trace_enable_sme);
8102 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8103 hdd_ctx->config->qdf_trace_enable_pe);
8104 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8105 hdd_ctx->config->qdf_trace_enable_wma);
8106 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8107 hdd_ctx->config->qdf_trace_enable_sys);
8108 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8109 hdd_ctx->config->qdf_trace_enable_qdf);
8110 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8111 hdd_ctx->config->qdf_trace_enable_sap);
8112 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8113 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8114 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8115 hdd_ctx->config->qdf_trace_enable_bmi);
8116 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8117 hdd_ctx->config->qdf_trace_enable_cfg);
8118 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8119 hdd_ctx->config->qdf_trace_enable_epping);
8120 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8121 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8122 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008123 hdd_ctx->config->qdf_trace_enable_txrx);
8124 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8125 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308126 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8127 hdd_ctx->config->qdf_trace_enable_htc);
8128 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8129 hdd_ctx->config->qdf_trace_enable_hif);
8130 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8131 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8132 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8133 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008134 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8135 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008136 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8137 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008138 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8139 hdd_ctx->config->qdf_trace_enable_regulatory);
8140
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008141 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008142}
8143
8144/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008145 * hdd_context_init() - Initialize HDD context
8146 * @hdd_ctx: HDD context.
8147 *
8148 * Initialize HDD context along with all the feature specific contexts.
8149 *
8150 * return: 0 on success and errno on failure.
8151 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008152static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008153{
8154 int ret;
8155
8156 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8157 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8158
8159 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308160 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008161
8162 init_completion(&hdd_ctx->mc_sus_event_var);
8163 init_completion(&hdd_ctx->ready_to_suspend);
8164
8165 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308166 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008167 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308168
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008169 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008170
8171 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8172
8173 ret = hdd_scan_context_init(hdd_ctx);
8174 if (ret)
8175 goto list_destroy;
8176
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008177 hdd_rx_wake_lock_create(hdd_ctx);
8178
8179 ret = hdd_sap_context_init(hdd_ctx);
8180 if (ret)
8181 goto scan_destroy;
8182
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008183 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8184
8185 hdd_init_offloaded_packets_ctx(hdd_ctx);
8186
8187 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8188 hdd_ctx->config);
8189 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008190 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008191
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308192 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8193 "monitor_mode_wakelock");
8194
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008195 return 0;
8196
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008197sap_destroy:
8198 hdd_sap_context_destroy(hdd_ctx);
8199
8200scan_destroy:
8201 hdd_scan_context_destroy(hdd_ctx);
8202 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008203list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008204 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008205
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008206 return ret;
8207}
8208
8209/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308210 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8211 * @hdd_ctx: pointer to hdd context
8212 *
8213 * Return: status of initialization
8214 * 0 - success
8215 * negative value - failure
8216 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008217static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308218{
8219 int ret;
8220
8221 if (!hdd_ctx->config->probe_req_ie_whitelist)
8222 return 0;
8223
8224 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8225 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8226 hdd_ctx->config->probe_req_ie_whitelist = false;
8227 return -EINVAL;
8228 }
8229
8230 /* parse ini string probe req oui */
8231 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8232 if (ret) {
8233 hdd_err("parsing error: disable ie whitelisting");
8234 hdd_ctx->config->probe_req_ie_whitelist = false;
8235 }
8236
8237 return ret;
8238}
8239
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308240
8241/**
8242 * hdd_iface_change_callback() - Function invoked when stop modules expires
8243 * @priv: pointer to hdd context
8244 *
8245 * This function is invoked when the timer waiting for the interface change
8246 * expires, it shall cut-down the power to wlan and stop all the modules.
8247 *
8248 * Return: void
8249 */
8250static void hdd_iface_change_callback(void *priv)
8251{
8252 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8253 int ret;
8254 int status = wlan_hdd_validate_context(hdd_ctx);
8255
8256 if (status)
8257 return;
8258
8259 ENTER();
8260 hdd_debug("Interface change timer expired close the modules!");
8261 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8262 if (ret)
8263 hdd_err("Failed to stop modules");
8264 EXIT();
8265}
8266
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308267/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008268 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308269 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008270 *
8271 * Allocate and initialize HDD context. HDD context is allocated as part of
8272 * wiphy allocation and then context is initialized.
8273 *
8274 * Return: HDD context on success and ERR_PTR on failure
8275 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008276static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008277{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308278 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008279 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008280 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008281
8282 ENTER();
8283
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008284 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008285 if (hdd_ctx == NULL) {
8286 ret = -ENOMEM;
8287 goto err_out;
8288 }
8289
Dustin Brown6f427922017-09-19 12:19:00 -07008290 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8291 hdd_iface_change_callback,
8292 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308293
8294 mutex_init(&hdd_ctx->iface_change_lock);
8295
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008296 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308297 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008298
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308299 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008300 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008301 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008302 ret = -ENOMEM;
8303 goto err_free_hdd_context;
8304 }
8305
8306 /* Read and parse the qcom_cfg.ini file */
8307 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308308 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308309 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008310 WLAN_INI_FILE);
8311 ret = -EINVAL;
8312 goto err_free_config;
8313 }
8314
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308315 ie_whitelist_attrs_init(hdd_ctx);
8316
Dustin Brown7f939932017-05-18 15:02:17 -07008317 hdd_debug("setting timer multiplier: %u",
8318 hdd_ctx->config->timer_multiplier);
8319 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8320
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008321
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308322 if (hdd_ctx->config->fhostNSOffload)
8323 hdd_ctx->ns_offload_enable = true;
8324
Abhishek Singh5ea86532016-04-27 14:10:53 +05308325 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8326
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008327 hdd_override_ini_config(hdd_ctx);
8328
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008329 ret = hdd_context_init(hdd_ctx);
8330
8331 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008332 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008333
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008334 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308335 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008336
Anurag Chouhan6d760662016-02-20 16:05:43 +05308337 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008338 goto skip_multicast_logging;
8339
8340 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8341
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008342 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8343 if (ret)
8344 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308345
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008346 ret = hdd_init_netlink_services(hdd_ctx);
8347 if (ret)
8348 goto err_deinit_txrx_histogram;
8349
Dustin Brown7b3dea22017-07-10 13:02:47 -07008350 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
8351 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05308352
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008353skip_multicast_logging:
8354 hdd_set_trace_level_for_each(hdd_ctx);
8355
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008356 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8357
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008358 EXIT();
8359
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008360 return hdd_ctx;
8361
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008362err_deinit_txrx_histogram:
8363 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8364
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008365err_deinit_hdd_context:
8366 hdd_context_deinit(hdd_ctx);
8367
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008368err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308369 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008370
8371err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308372 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008373 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008374
8375err_out:
8376 return ERR_PTR(ret);
8377}
8378
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008379#ifdef WLAN_OPEN_P2P_INTERFACE
8380/**
8381 * hdd_open_p2p_interface - Open P2P interface
8382 * @hdd_ctx: HDD context
8383 * @rtnl_held: True if RTNL lock held
8384 *
8385 * Open P2P interface during probe. This function called to open the P2P
8386 * interface at probe along with STA interface.
8387 *
8388 * Return: 0 on success and errno on failure
8389 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008390static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008391{
Jeff Johnson9d295242017-08-29 14:39:48 -07008392 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008393 uint8_t *p2p_dev_addr;
8394
8395 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8396 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008397 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008398 hdd_ctx->config->intfMacAddr[0].bytes,
8399 sizeof(tSirMacAddr));
8400
8401 /*
8402 * Generate the P2P Device Address. This consists of
8403 * the device's primary MAC address with the locally
8404 * administered bit set.
8405 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008406 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008407 } else {
8408 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8409 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008410 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008411 return -ENOSPC;
8412 }
8413
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008414 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8415 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008416 }
8417
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008418 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008419 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008420 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008421
8422 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008423 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008424 return -ENOSPC;
8425 }
8426
8427 return 0;
8428}
8429#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008430static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008431 bool rtnl_held)
8432{
8433 return 0;
8434}
8435#endif
8436
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008437static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008438{
Jeff Johnson9d295242017-08-29 14:39:48 -07008439 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008440 int ret = 0;
8441
8442 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8443 wlan_hdd_get_intf_addr(hdd_ctx),
8444 NET_NAME_UNKNOWN, rtnl_held);
8445 if (adapter == NULL) {
8446 hdd_err("Failed to open 802.11p interface");
8447 ret = -ENOSPC;
8448 }
8449
8450 return ret;
8451}
8452
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008453/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308454 * hdd_start_station_adapter()- Start the Station Adapter
8455 * @adapter: HDD adapter
8456 *
8457 * This function initializes the adapter for the station mode.
8458 *
8459 * Return: 0 on success or errno on failure.
8460 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008461int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308462{
8463 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008464 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308465
8466 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008467 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8468 hdd_err("session is already opened, %d",
8469 adapter->session_id);
8470 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8471 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308472
Krunal Sonib51eec72017-11-20 21:53:01 -08008473 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8474 if (ret) {
8475 hdd_err("failed to create vdev: %d", ret);
8476 return ret;
8477 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308478 status = hdd_init_station_mode(adapter);
8479
8480 if (QDF_STATUS_SUCCESS != status) {
8481 hdd_err("Error Initializing station mode: %d", status);
8482 return qdf_status_to_os_return(status);
8483 }
8484
Arun Khandavallifae92942016-08-01 13:31:08 +05308485 hdd_register_tx_flow_control(adapter,
8486 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008487 hdd_tx_resume_cb,
8488 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308489
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308490 EXIT();
8491 return 0;
8492}
8493
8494/**
8495 * hdd_start_ap_adapter()- Start AP Adapter
8496 * @adapter: HDD adapter
8497 *
8498 * This function initializes the adapter for the AP mode.
8499 *
8500 * Return: 0 on success errno on failure.
8501 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008502int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308503{
8504 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008505 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008506 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308507
8508 ENTER();
8509
Krunal Sonib51eec72017-11-20 21:53:01 -08008510 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8511 hdd_err("session is already opened, %d",
8512 adapter->session_id);
8513 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8514 }
8515 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008516 * In SSR case no need to create new sap context.
8517 * Otherwise create sap context first and then create
8518 * vdev as while creating the vdev, driver needs to
8519 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008520 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008521 if (adapter->session.ap.sap_context) {
8522 is_ssr = true;
8523 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008524 hdd_err("sap creation failed");
8525 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8526 }
8527
8528 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8529 adapter->session.ap.sap_context);
8530 if (ret) {
8531 hdd_err("failed to create vdev, status:%d", ret);
8532 hdd_sap_destroy_ctx(adapter);
8533 return ret;
8534 }
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008535 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308536
8537 if (QDF_STATUS_SUCCESS != status) {
8538 hdd_err("Error Initializing the AP mode: %d", status);
8539 return qdf_status_to_os_return(status);
8540 }
8541
Arun Khandavallifae92942016-08-01 13:31:08 +05308542 hdd_register_tx_flow_control(adapter,
8543 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008544 hdd_softap_tx_resume_cb,
8545 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308546
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308547 EXIT();
8548 return 0;
8549}
8550
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308551static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8552 bool rtnl_held)
8553{
8554 struct hdd_adapter *adapter;
8555
8556 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8557 hdd_ctx->config->enableConcurrentSTA,
8558 wlan_hdd_get_intf_addr(hdd_ctx),
8559 NET_NAME_UNKNOWN, rtnl_held);
8560
8561 if (!adapter)
8562 return -ENOSPC;
8563
8564 return 0;
8565}
8566
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308567/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008568 * hdd_open_interfaces - Open all required interfaces
8569 * hdd_ctx: HDD context
8570 * rtnl_held: True if RTNL lock is held
8571 *
8572 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8573 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008574 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008575 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008576static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008577{
Jeff Johnson9d295242017-08-29 14:39:48 -07008578 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008579 int ret;
8580
Ravi Joshia307f632017-07-17 23:41:41 -07008581 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008582 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8583 con_mode == QDF_GLOBAL_FTM_MODE) {
8584 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8585 QDF_MONITOR_MODE : QDF_FTM_MODE;
8586
8587 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8588 wlan_hdd_get_intf_addr(hdd_ctx),
8589 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008590 if (!adapter) {
8591 hdd_err("open adapter failed");
8592 return -ENOSPC;
8593 }
Lin Bai1c678482017-12-18 18:29:11 +08008594
Ravi Joshia307f632017-07-17 23:41:41 -07008595 return 0;
8596 }
8597
Jeff Johnson957bc272017-02-02 08:54:48 -08008598 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308599 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008600 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008601
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008602 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008603 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008604 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008605
8606 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008607 return -ENOSPC;
8608
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308609 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8610 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8611 if (ret)
8612 hdd_err("Cannot create concurrent STA interface");
8613 }
8614
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008615 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8616 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008617 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008618
8619 /* Open 802.11p Interface */
8620 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008621 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8622 if (ret)
8623 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008624 }
8625
Jeff Johnson957bc272017-02-02 08:54:48 -08008626 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008627
Jeff Johnson957bc272017-02-02 08:54:48 -08008628err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008629 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008630 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008631}
8632
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008633/**
8634 * hdd_update_country_code - Update country code
8635 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008636 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008637 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008638 *
8639 * Return: 0 on success and errno on failure
8640 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008641static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008642{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008643 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008644 return 0;
8645
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008646 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008647}
8648
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308649#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8650/**
8651 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8652 * @cds_cfg: CDS Configuration
8653 * @hdd_ctx: Pointer to hdd context
8654 *
8655 * Return: none
8656 */
8657static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8658 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008659 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308660{
8661 cds_cfg->tx_flow_stop_queue_th =
8662 hdd_ctx->config->TxFlowStopQueueThreshold;
8663 cds_cfg->tx_flow_start_queue_offset =
8664 hdd_ctx->config->TxFlowStartQueueOffset;
8665}
8666#else
8667static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8668 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008669 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308670{
8671}
8672#endif
8673
8674#ifdef FEATURE_WLAN_RA_FILTERING
8675/**
8676 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8677 * @cds_cfg: CDS Configuration
8678 * @hdd_ctx: Pointer to hdd context
8679 *
8680 * Return: none
8681 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308682static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008683 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308684{
8685 cds_cfg->ra_ratelimit_interval =
8686 hdd_ctx->config->RArateLimitInterval;
8687 cds_cfg->is_ra_ratelimit_enabled =
8688 hdd_ctx->config->IsRArateLimitEnabled;
8689}
8690#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308691static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008692 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308693{
8694}
8695#endif
8696
8697/**
8698 * hdd_update_cds_config() - API to update cds configuration parameters
8699 * @hdd_ctx: HDD Context
8700 *
8701 * Return: 0 for Success, errno on failure
8702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008703static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308704{
8705 struct cds_config_info *cds_cfg;
8706
8707 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8708 if (!cds_cfg) {
8709 hdd_err("failed to allocate cds config");
8710 return -ENOMEM;
8711 }
8712
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008713 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008714 if (!hdd_ctx->config->nMaxPsPoll ||
8715 !hdd_ctx->config->enablePowersaveOffload) {
8716 cds_cfg->powersave_offload_enabled =
8717 hdd_ctx->config->enablePowersaveOffload;
8718 } else {
8719 if ((hdd_ctx->config->enablePowersaveOffload ==
8720 PS_QPOWER_NODEEPSLEEP) ||
8721 (hdd_ctx->config->enablePowersaveOffload ==
8722 PS_LEGACY_NODEEPSLEEP))
8723 cds_cfg->powersave_offload_enabled =
8724 PS_LEGACY_NODEEPSLEEP;
8725 else
8726 cds_cfg->powersave_offload_enabled =
8727 PS_LEGACY_DEEPSLEEP;
8728 hdd_info("Qpower disabled in cds config, %d",
8729 cds_cfg->powersave_offload_enabled);
8730 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308731 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8732 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8733 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8734 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8735 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8736
8737 /* Here ol_ini_info is used to store ini status of arp offload
8738 * ns offload and others. Currently 1st bit is used for arp
8739 * off load and 2nd bit for ns offload currently, rest bits are unused
8740 */
8741 if (hdd_ctx->config->fhostArpOffload)
8742 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8743 if (hdd_ctx->config->fhostNSOffload)
8744 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8745
8746 /*
8747 * Copy the DFS Phyerr Filtering Offload status.
8748 * This parameter reflects the value of the
8749 * dfs_phyerr_filter_offload flag as set in the ini.
8750 */
8751 cds_cfg->dfs_phyerr_filter_offload =
8752 hdd_ctx->config->fDfsPhyerrFilterOffload;
8753 if (hdd_ctx->config->ssdp)
8754 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8755
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308756 cds_cfg->force_target_assert_enabled =
8757 hdd_ctx->config->crash_inject_enabled;
8758
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308759 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8760 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8761
8762 cds_cfg->ap_maxoffload_reorderbuffs =
8763 hdd_ctx->config->apMaxOffloadReorderBuffs;
8764
8765 cds_cfg->ap_disable_intrabss_fwd =
8766 hdd_ctx->config->apDisableIntraBssFwd;
8767
8768 cds_cfg->dfs_pri_multiplier =
8769 hdd_ctx->config->dfsRadarPriMultiplier;
8770 cds_cfg->reorder_offload =
8771 hdd_ctx->config->reorderOffloadSupport;
8772
8773 /* IPA micro controller data path offload resource config item */
8774 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008775 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8776 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008777 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008778 hdd_ctx->config->IpaUcTxBufCount);
8779 hdd_ctx->config->IpaUcTxBufCount =
8780 rounddown_pow_of_two(
8781 hdd_ctx->config->IpaUcTxBufCount);
8782 if (!hdd_ctx->config->IpaUcTxBufCount) {
8783 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308784 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008785 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008786 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008787 hdd_ctx->config->IpaUcTxBufCount);
8788 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308789 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8790 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008791 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8792 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008793 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008794 hdd_ctx->config->IpaUcRxIndRingCount);
8795 hdd_ctx->config->IpaUcRxIndRingCount =
8796 rounddown_pow_of_two(
8797 hdd_ctx->config->IpaUcRxIndRingCount);
8798 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8799 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308800 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008801 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008802 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008803 hdd_ctx->config->IpaUcRxIndRingCount);
8804 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308805 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008806 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308807 cds_cfg->uc_tx_partition_base =
8808 hdd_ctx->config->IpaUcTxPartitionBase;
8809 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8810
8811 cds_cfg->ip_tcp_udp_checksum_offload =
8812 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008813 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308814 cds_cfg->ce_classify_enabled =
8815 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008816 cds_cfg->bpf_packet_filter_enable =
8817 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308818 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8819 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8820 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008821 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008822 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008823 cds_cfg->max_msdus_per_rxinorderind =
8824 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008825 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008826 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308827 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8828 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308829 cds_cfg->auto_power_save_fail_mode =
8830 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308831
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308832 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008833 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308834
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308835 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8836 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8837 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008838 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308839 cds_init_ini_config(cds_cfg);
8840 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308841
8842exit:
8843 qdf_mem_free(cds_cfg);
8844 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308845}
8846
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008847/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008848 * hdd_update_user_config() - API to update user configuration
8849 * parameters to obj mgr which are used by multiple components
8850 * @hdd_ctx: HDD Context
8851 *
8852 * Return: 0 for Success, errno on failure
8853 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008854static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008855{
8856 struct wlan_objmgr_psoc_user_config *user_config;
8857
8858 user_config = qdf_mem_malloc(sizeof(*user_config));
8859 if (user_config == NULL) {
8860 hdd_alert("Failed to alloc memory for user_config!");
8861 return -ENOMEM;
8862 }
8863
8864 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8865 user_config->dual_mac_feature_disable =
8866 hdd_ctx->config->dual_mac_feature_disable;
8867 user_config->indoor_channel_support =
8868 hdd_ctx->config->indoor_channel_support;
8869 user_config->is_11d_support_enabled =
8870 hdd_ctx->config->Is11dSupportEnabled;
8871 user_config->is_11h_support_enabled =
8872 hdd_ctx->config->Is11hSupportEnabled;
8873 user_config->optimize_chan_avoid_event =
8874 hdd_ctx->config->goptimize_chan_avoid_event;
8875 user_config->skip_dfs_chnl_in_p2p_search =
8876 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008877 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008878 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8879
8880 qdf_mem_free(user_config);
8881 return 0;
8882}
8883
8884/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008885 * hdd_init_thermal_info - Initialize thermal level
8886 * @hdd_ctx: HDD context
8887 *
8888 * Initialize thermal level at SME layer and set the thermal level callback
8889 * which would be called when a configured thermal threshold is hit.
8890 *
8891 * Return: 0 on success and errno on failure
8892 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008893static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008894{
8895 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308896 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008897
8898 thermal_param.smeThermalMgmtEnabled =
8899 hdd_ctx->config->thermalMitigationEnable;
8900 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8901
Poddar, Siddarth83905022016-04-16 17:56:08 -07008902 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8903 hdd_ctx->config->throttle_dutycycle_level0;
8904 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8905 hdd_ctx->config->throttle_dutycycle_level1;
8906 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8907 hdd_ctx->config->throttle_dutycycle_level2;
8908 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8909 hdd_ctx->config->throttle_dutycycle_level3;
8910
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008911 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8912 hdd_ctx->config->thermalTempMinLevel0;
8913 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8914 hdd_ctx->config->thermalTempMaxLevel0;
8915 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8916 hdd_ctx->config->thermalTempMinLevel1;
8917 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8918 hdd_ctx->config->thermalTempMaxLevel1;
8919 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8920 hdd_ctx->config->thermalTempMinLevel2;
8921 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8922 hdd_ctx->config->thermalTempMaxLevel2;
8923 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8924 hdd_ctx->config->thermalTempMinLevel3;
8925 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8926 hdd_ctx->config->thermalTempMaxLevel3;
8927
8928 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8929
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308930 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308931 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008932
8933 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8934 hdd_set_thermal_level_cb);
8935
8936 return 0;
8937
8938}
8939
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008940#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8941/**
8942 * hdd_hold_rtnl_lock - Hold RTNL lock
8943 *
8944 * Hold RTNL lock
8945 *
8946 * Return: True if held and false otherwise
8947 */
8948static inline bool hdd_hold_rtnl_lock(void)
8949{
8950 rtnl_lock();
8951 return true;
8952}
8953
8954/**
8955 * hdd_release_rtnl_lock - Release RTNL lock
8956 *
8957 * Release RTNL lock
8958 *
8959 * Return: None
8960 */
8961static inline void hdd_release_rtnl_lock(void)
8962{
8963 rtnl_unlock();
8964}
8965#else
8966static inline bool hdd_hold_rtnl_lock(void) { return false; }
8967static inline void hdd_release_rtnl_lock(void) { }
8968#endif
8969
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008970#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008971
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308972/* MAX iwpriv command support */
8973#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308974#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308975#define MAX_PKTLOG_SIZE 16
8976
8977/**
8978 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8979 * @hdd_ctx: hdd context
8980 * @set_value2: pktlog buffer size value
8981 *
8982 *
8983 * Return: 0 for success or error.
8984 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008985static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308986{
8987 struct sir_wifi_start_log start_log = { 0 };
8988 QDF_STATUS status;
8989
8990 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8991 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8992 start_log.ini_triggered = cds_is_packet_log_enabled();
8993 start_log.user_triggered = 1;
8994 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308995 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308996
8997 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8998 if (!QDF_IS_STATUS_SUCCESS(status)) {
8999 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9000 EXIT();
9001 return -EINVAL;
9002 }
9003
9004 return 0;
9005}
9006
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009007/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309008 * hdd_pktlog_clear_buff() - clear pktlog buffer
9009 * @hdd_ctx: hdd context
9010 *
9011 * Return: 0 for success or error.
9012 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009013static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309014{
9015 struct sir_wifi_start_log start_log;
9016 QDF_STATUS status;
9017
9018 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9019 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9020 start_log.ini_triggered = cds_is_packet_log_enabled();
9021 start_log.user_triggered = 1;
9022 start_log.size = 0;
9023 start_log.is_pktlog_buff_clear = true;
9024
9025 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9026 if (!QDF_IS_STATUS_SUCCESS(status)) {
9027 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9028 EXIT();
9029 return -EINVAL;
9030 }
9031
9032 return 0;
9033}
9034
9035
9036/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009037 * hdd_process_pktlog_command() - process pktlog command
9038 * @hdd_ctx: hdd context
9039 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309040 * @set_value2: pktlog buffer size value
9041 *
9042 * This function process pktlog command.
9043 * set_value2 only matters when set_value is 3 (set buff size)
9044 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009045 *
9046 * Return: 0 for success or error.
9047 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009048int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309049 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009050{
9051 int ret;
9052 bool enable;
9053 uint8_t user_triggered = 0;
9054
9055 ret = wlan_hdd_validate_context(hdd_ctx);
9056 if (0 != ret)
9057 return ret;
9058
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009059 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009060
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309061 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009062 hdd_err("invalid pktlog value %d", set_value);
9063 return -EINVAL;
9064 }
9065
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309066 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9067 if (set_value2 <= 0) {
9068 hdd_err("invalid pktlog size %d", set_value2);
9069 return -EINVAL;
9070 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9071 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9072 return -EINVAL;
9073 }
9074 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309075 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9076 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309077 }
9078
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009079 /*
9080 * set_value = 0 then disable packetlog
9081 * set_value = 1 enable packetlog forcefully
9082 * set_vlaue = 2 then disable packetlog if disabled through ini or
9083 * enable packetlog with AUTO type.
9084 */
9085 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9086 true : false;
9087
9088 if (1 == set_value) {
9089 enable = true;
9090 user_triggered = 1;
9091 }
9092
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309093 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009094}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009095
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009096/**
9097 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9098 * @hdd_ctx: HDD context
9099 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309100 * @user_triggered: triggered through iwpriv
9101 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009102 *
9103 * Return: 0 on success; error number otherwise
9104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009105int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309106 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009107{
9108 struct sir_wifi_start_log start_log;
9109 QDF_STATUS status;
9110
9111 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9112 start_log.verbose_level =
9113 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009114 start_log.ini_triggered = cds_is_packet_log_enabled();
9115 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309116 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309117 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309118 /*
9119 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9120 * commands. Host uses this flag to decide whether to send pktlog
9121 * disable command to fw without sending pktlog enable command
9122 * previously. For eg, If vendor sends pktlog disable command without
9123 * sending pktlog enable command, then host discards the packet
9124 * but for iwpriv command, host will send it to fw.
9125 */
9126 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009127 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9128 if (!QDF_IS_STATUS_SUCCESS(status)) {
9129 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9130 EXIT();
9131 return -EINVAL;
9132 }
9133
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309134 if (enable == true)
9135 hdd_ctx->is_pktlog_enabled = 1;
9136 else
9137 hdd_ctx->is_pktlog_enabled = 0;
9138
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009139 return 0;
9140}
9141#endif /* REMOVE_PKT_LOG */
9142
Komal Seelam92fff912016-03-24 11:51:41 +05309143/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009144 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9145 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309146 * @dev: Device Pointer
9147 * @num: Number of Valid Mac address
9148 *
9149 * Return: Pointer to MAC address buffer
9150 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009151static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9152 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309153{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009154 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309155}
Komal Seelam92fff912016-03-24 11:51:41 +05309156
9157/**
9158 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9159 * @hdd_ctx: HDD Context
9160 * @num: Number of random mac addresses needed
9161 *
9162 * Generate random addresses using bit manipulation on the base mac address
9163 *
9164 * Return: None
9165 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009166void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309167{
9168 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9169 uint32_t iter;
9170 struct hdd_config *ini = hdd_ctx->config;
9171 uint8_t *buf = NULL;
9172 uint8_t macaddr_b3, tmp_br3;
9173 uint8_t *src = ini->intfMacAddr[0].bytes;
9174
9175 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9176 buf = ini->intfMacAddr[iter].bytes;
9177 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9178 macaddr_b3 = buf[3];
9179 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9180 INTF_MACADDR_MASK;
9181 macaddr_b3 += tmp_br3;
9182 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9183 buf[0] |= 0x02;
9184 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009185 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309186 }
9187}
9188
9189/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009190 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309191 * @hdd_ctx: HDD Context
9192 *
9193 * API to get mac addresses from platform driver and update the driver
9194 * structures and configure FW with the base mac address.
9195 * Return: int
9196 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009197static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309198{
9199 uint32_t no_of_mac_addr, iter;
9200 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9201 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9202 uint8_t *addr, *buf;
9203 struct device *dev = hdd_ctx->parent_dev;
9204 struct hdd_config *ini = hdd_ctx->config;
9205 tSirMacAddr mac_addr;
9206 QDF_STATUS status;
9207
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009208 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309209
9210 if (no_of_mac_addr == 0 || !addr) {
9211 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9212 return -EINVAL;
9213 }
9214
9215 if (no_of_mac_addr > max_mac_addr)
9216 no_of_mac_addr = max_mac_addr;
9217
9218 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9219
9220 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9221 buf = ini->intfMacAddr[iter].bytes;
9222 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009223 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309224 }
9225
9226 status = sme_set_custom_mac_addr(mac_addr);
9227
9228 if (!QDF_IS_STATUS_SUCCESS(status))
9229 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009230
Komal Seelam92fff912016-03-24 11:51:41 +05309231 if (no_of_mac_addr < max_mac_addr)
9232 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9233 no_of_mac_addr);
9234 return 0;
9235}
9236
9237/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009238 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9239 * @hdd_ctx: HDD Context
9240 *
9241 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9242 * will generate its own MAC and update it to FW.
9243 *
9244 * Return: 0 for success
9245 * Non-zero error code for failure
9246 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009247static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009248{
9249 tSirMacAddr customMacAddr;
9250 QDF_STATUS status;
9251
9252 qdf_mem_copy(&customMacAddr,
9253 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9254 sizeof(tSirMacAddr));
9255 status = sme_set_custom_mac_addr(customMacAddr);
9256 if (!QDF_IS_STATUS_SUCCESS(status))
9257 return -EAGAIN;
9258 return 0;
9259}
9260
9261/**
Komal Seelam92fff912016-03-24 11:51:41 +05309262 * hdd_initialize_mac_address() - API to get wlan mac addresses
9263 * @hdd_ctx: HDD Context
9264 *
9265 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9266 * is provisioned with mac addresses, driver uses it, else it will use
9267 * wlan_mac.bin to update HW MAC addresses.
9268 *
9269 * Return: None
9270 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009271static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309272{
9273 QDF_STATUS status;
9274 int ret;
9275
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009276 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309277 if (ret == 0)
9278 return;
9279
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009280 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9281 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309282
9283 status = hdd_update_mac_config(hdd_ctx);
9284
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009285 if (QDF_IS_STATUS_SUCCESS(status))
9286 return;
9287
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009288 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9289 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009290
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009291 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009292 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009293 if (ret != 0) {
9294 hdd_err("MAC address out-of-sync, ret:%d", ret);
9295 QDF_ASSERT(ret);
9296 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009297 }
Komal Seelam92fff912016-03-24 11:51:41 +05309298}
9299
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009300static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009301{
9302 int vdev_id = 0;
9303 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9304 int value = hdd_ctx->config->smart_chainmask_enabled;
9305 int vpdev = PDEV_CMD;
9306 int ret;
9307
Naveen Rawat247a8682017-06-05 15:00:31 -07009308 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009309 if (ret)
9310 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9311
9312 return ret;
9313}
9314
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009315static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009316{
9317 int vdev_id = 0;
9318 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9319 int value = hdd_ctx->config->alternative_chainmask_enabled;
9320 int vpdev = PDEV_CMD;
9321 int ret;
9322
Naveen Rawat247a8682017-06-05 15:00:31 -07009323 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009324 if (ret)
9325 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9326 ret);
9327
9328 return ret;
9329}
9330
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009331static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009332{
9333 int vdev_id = 0;
9334 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9335 int value = hdd_ctx->config->ani_enabled;
9336 int vpdev = PDEV_CMD;
9337 int ret;
9338
Naveen Rawat247a8682017-06-05 15:00:31 -07009339 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009340 if (ret)
9341 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9342
9343 return ret;
9344}
9345
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009346/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009347 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9348 * @hdd_ctx: HDD context
9349 *
9350 * Pre configurations to be done at lower layer before calling cds enable.
9351 *
9352 * Return: 0 on success and errno on failure.
9353 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009354static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009355{
9356 int ret;
9357 QDF_STATUS status;
9358 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009359 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009360
Leo Changfdb45c32016-10-28 11:09:23 -07009361 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009362 /*
9363 * Set 802.11p config
9364 * TODO-OCB: This has been temporarily added here to ensure this
9365 * parameter is set in CSR when we init the channel list. This should
9366 * be removed once the 5.9 GHz channels are added to the regulatory
9367 * domain.
9368 */
9369 hdd_set_dot11p_config(hdd_ctx);
9370
9371 /*
9372 * Note that the cds_pre_enable() sequence triggers the cfg download.
9373 * The cfg download must occur before we update the SME config
9374 * since the SME config operation must access the cfg database
9375 */
9376 status = hdd_set_sme_config(hdd_ctx);
9377
9378 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009379 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009380 ret = qdf_status_to_os_return(status);
9381 goto out;
9382 }
9383
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009384 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9385 if (QDF_STATUS_SUCCESS != status) {
9386 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9387 ret = qdf_status_to_os_return(status);
9388 goto out;
9389 }
9390
Naveen Rawat247a8682017-06-05 15:00:31 -07009391 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009392 hdd_ctx->config->tx_chain_mask_1ss,
9393 PDEV_CMD);
9394 if (0 != ret) {
9395 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9396 goto out;
9397 }
9398
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009399 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9400 if (ret)
9401 goto out;
9402
9403 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9404 if (ret)
9405 goto out;
9406
Jeff Johnson12a744b2017-04-04 08:19:37 -07009407 ret = hdd_set_ani_enabled(hdd_ctx);
9408 if (ret)
9409 goto out;
9410
Naveen Rawat247a8682017-06-05 15:00:31 -07009411 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009412 hdd_ctx->config->arp_ac_category,
9413 PDEV_CMD);
9414 if (0 != ret) {
9415 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9416 hdd_ctx->config->arp_ac_category, ret);
9417 goto out;
9418 }
9419
Prashanth Bhatta07998752016-04-28 12:35:33 -07009420 status = hdd_set_sme_chan_list(hdd_ctx);
9421 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009422 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009423 ret = qdf_status_to_os_return(status);
9424 goto out;
9425 }
9426
9427 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009428 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009429 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009430 ret = -EINVAL;
9431 goto out;
9432 }
9433
Prashanth Bhatta07998752016-04-28 12:35:33 -07009434 /*
9435 * Set the MAC Address Currently this is used by HAL to add self sta.
9436 * Remove this once self sta is added as part of session open.
9437 */
9438 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9439 hdd_ctx->config->intfMacAddr[0].bytes,
9440 sizeof(hdd_ctx->config->intfMacAddr[0]));
9441
9442 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9443 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9444 hal_status, hal_status);
9445 ret = -EINVAL;
9446 goto out;
9447 }
9448
9449 hdd_init_channel_avoidance(hdd_ctx);
9450
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309451 /* update enable sap mandatory chan list */
9452 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9453 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009454out:
9455 return ret;
9456}
9457
9458/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009459 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9460 * @context_ptr - hdd context pointer
9461 * @event_ptr - event structure pointer
9462 *
9463 * This is the p2p listen offload stop event handler, it sends vendor
9464 * event back to supplicant to notify the stop reason.
9465 *
9466 * Return: None
9467 */
9468static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9469 void *event_ptr)
9470{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009471 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009472 struct sir_p2p_lo_event *evt = event_ptr;
9473 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009474 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009475
9476 ENTER();
9477
9478 if (hdd_ctx == NULL) {
9479 hdd_err("Invalid HDD context pointer");
9480 return;
9481 }
9482
Peng Xu5c682812017-08-06 07:39:13 -07009483 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9484 if (!adapter) {
9485 hdd_err("Cannot find adapter by vdev_id = %d",
9486 evt->vdev_id);
9487 return;
9488 }
9489
Peng Xu8fdaa492016-06-22 10:20:47 -07009490 vendor_event =
9491 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009492 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009493 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9494 GFP_KERNEL);
9495
9496 if (!vendor_event) {
9497 hdd_err("cfg80211_vendor_event_alloc failed");
9498 return;
9499 }
9500
9501 if (nla_put_u32(vendor_event,
9502 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9503 evt->reason_code)) {
9504 hdd_err("nla put failed");
9505 kfree_skb(vendor_event);
9506 return;
9507 }
9508
9509 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009510 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9511 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009512}
9513
9514/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309515 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9516 * @hdd_ctx: HDD context
9517 *
9518 * This function sends the adaptive dwell time config configuration to the
9519 * firmware via WMA
9520 *
9521 * Return: 0 - success, < 0 - failure
9522 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009523static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309524{
9525 QDF_STATUS status;
9526 struct adaptive_dwelltime_params dwelltime_params;
9527
9528 dwelltime_params.is_enabled =
9529 hdd_ctx->config->adaptive_dwell_mode_enabled;
9530 dwelltime_params.dwelltime_mode =
9531 hdd_ctx->config->global_adapt_dwelltime_mode;
9532 dwelltime_params.lpf_weight =
9533 hdd_ctx->config->adapt_dwell_lpf_weight;
9534 dwelltime_params.passive_mon_intval =
9535 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9536 dwelltime_params.wifi_act_threshold =
9537 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9538
9539 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9540 &dwelltime_params);
9541
9542 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9543 if (!QDF_IS_STATUS_SUCCESS(status)) {
9544 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9545 return -EAGAIN;
9546 }
9547 return 0;
9548}
9549
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009550int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309551{
9552 QDF_STATUS status;
9553 struct wmi_dbs_scan_sel_params dbs_scan_params;
9554 uint32_t i = 0;
9555 uint8_t count = 0, numentries = 0;
9556 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9557 * CDS_DBS_SCAN_CLIENTS_MAX];
9558
9559 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009560 if (hdd_ctx->config->dual_mac_feature_disable ==
9561 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309562 return -EINVAL;
9563
9564 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9565 dbs_scan_config, &numentries,
9566 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9567 * CDS_DBS_SCAN_CLIENTS_MAX));
9568
9569 hdd_info("numentries %hu", numentries);
9570 if (!numentries) {
9571 hdd_info("Donot send scan_selection_config");
9572 return 0;
9573 }
9574
9575 /* hdd_set_fw_log_params */
9576 dbs_scan_params.num_clients = 0;
9577 while (count < (numentries - 2)) {
9578 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9579 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9580 dbs_scan_params.num_non_dbs_scans[i] =
9581 dbs_scan_config[count + 2];
9582 dbs_scan_params.num_clients++;
9583 hdd_debug("module:%d NDS:%d NNDS:%d",
9584 dbs_scan_params.module_id[i],
9585 dbs_scan_params.num_dbs_scans[i],
9586 dbs_scan_params.num_non_dbs_scans[i]);
9587 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9588 i++;
9589 }
9590
9591 dbs_scan_params.pdev_id = 0;
9592
9593 hdd_debug("clients:%d pdev:%d",
9594 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9595
9596 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9597 &dbs_scan_params);
9598 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9599 if (!QDF_IS_STATUS_SUCCESS(status)) {
9600 hdd_err("Failed to send DBS Scan selection configuration!");
9601 return -EAGAIN;
9602 }
9603 return 0;
9604}
9605
Arun Khandavallid4349a92016-07-25 11:10:43 +05309606#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9607/**
9608 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9609 * @hdd_ctx: HDD context
9610 *
9611 * Set auto shutdown callback to get indications from firmware to indicate
9612 * userspace to shutdown WLAN after a configured amount of inactivity.
9613 *
9614 * Return: 0 on success and errno on failure.
9615 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009616static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309617{
9618 QDF_STATUS status;
9619
9620 if (!hdd_ctx->config->WlanAutoShutdown)
9621 return 0;
9622
9623 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9624 wlan_hdd_auto_shutdown_cb);
9625 if (status != QDF_STATUS_SUCCESS)
9626 hdd_err("Auto shutdown feature could not be enabled: %d",
9627 status);
9628
9629 return qdf_status_to_os_return(status);
9630}
9631#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009632static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309633{
9634 return 0;
9635}
9636#endif
9637
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009638static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009639{
9640 QDF_STATUS status = QDF_STATUS_SUCCESS;
9641
9642 switch (hdd_ctx->config->dual_mac_feature_disable) {
9643 case DISABLE_DBS_CXN_AND_SCAN:
9644 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9645 if (status != QDF_STATUS_SUCCESS)
9646 hdd_err("Failed to disable dual mac features");
9647 break;
9648 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9649 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9650 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9651 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9652 if (status != QDF_STATUS_SUCCESS)
9653 hdd_err("Failed to set dbs scan and fw mode config");
9654 break;
9655 default:
9656 break;
9657 }
9658
9659 return status;
9660}
9661
Arun Khandavallid4349a92016-07-25 11:10:43 +05309662/**
9663 * hdd_features_init() - Init features
9664 * @hdd_ctx: HDD context
9665 * @adapter: Primary adapter context
9666 *
9667 * Initialize features and their feature context after WLAN firmware is up.
9668 *
9669 * Return: 0 on success and errno on failure.
9670 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009671static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309672{
9673 tSirTxPowerLimit hddtxlimit;
9674 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309675 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309676 int ret;
9677
9678 ENTER();
9679
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009680 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309681 if (ret) {
9682 hdd_err("Failed to update country code: %d", ret);
9683 goto out;
9684 }
9685
9686 /* FW capabilities received, Set the Dot11 mode */
9687 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009688 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9689 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309690
Arun Khandavallid4349a92016-07-25 11:10:43 +05309691
9692 if (hdd_ctx->config->fIsImpsEnabled)
9693 hdd_set_idle_ps_config(hdd_ctx, true);
9694 else
9695 hdd_set_idle_ps_config(hdd_ctx, false);
9696
Poddar, Siddarth37033032017-10-11 15:47:40 +05309697 /* Send Enable/Disable data stall detection cmd to FW */
9698 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9699 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9700
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309701 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009702 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309703
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309704 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9705 hdd_warn("Error in setting Voltage Corner mode config to FW");
9706
Arun Khandavallid4349a92016-07-25 11:10:43 +05309707 if (hdd_lro_init(hdd_ctx))
9708 hdd_err("Unable to initialize LRO in fw");
9709
9710 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9711 hdd_err("Unable to send adaptive dwelltime setting to FW");
9712
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309713 if (hdd_dbs_scan_selection_init(hdd_ctx))
9714 hdd_err("Unable to send DBS scan selection setting to FW");
9715
Arun Khandavallid4349a92016-07-25 11:10:43 +05309716 ret = hdd_init_thermal_info(hdd_ctx);
9717 if (ret) {
9718 hdd_err("Error while initializing thermal information");
9719 goto deregister_frames;
9720 }
9721
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309722 /**
9723 * In case of SSR/PDR, if pktlog was enabled manually before
9724 * SSR/PDR, Then enabled it again automatically after Wlan
9725 * device up.
9726 */
9727 if (cds_is_driver_recovering()) {
9728 if (hdd_ctx->is_pktlog_enabled)
9729 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9730 } else if (cds_is_packet_log_enabled())
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309731 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9732
Arun Khandavallid4349a92016-07-25 11:10:43 +05309733 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9734 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9735 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9736 if (!QDF_IS_STATUS_SUCCESS(status))
9737 hdd_err("Error setting txlimit in sme: %d", status);
9738
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009739 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309740
Arun Khandavallid4349a92016-07-25 11:10:43 +05309741 ret = hdd_register_cb(hdd_ctx);
9742 if (ret) {
9743 hdd_err("Failed to register HDD callbacks!");
9744 goto deregister_frames;
9745 }
9746
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009747 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9748 if (!QDF_IS_STATUS_SUCCESS(status)) {
9749 hdd_err("Failed to set dbs scan and fw mode cfg");
9750 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309751 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009752
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309753 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9754 status = sme_enable_disable_chanavoidind_event(
9755 hdd_ctx->hHal, 0);
9756 if (!QDF_IS_STATUS_SUCCESS(status)) {
9757 hdd_err("Failed to disable Chan Avoidance Indication");
9758 goto deregister_cb;
9759 }
9760 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309761
Manjeet Singha9cae432017-02-28 11:58:22 +05309762 if (hdd_ctx->config->enable_5g_band_pref) {
9763 band_pref_params.rssi_boost_threshold_5g =
9764 hdd_ctx->config->rssi_boost_threshold_5g;
9765 band_pref_params.rssi_boost_factor_5g =
9766 hdd_ctx->config->rssi_boost_factor_5g;
9767 band_pref_params.max_rssi_boost_5g =
9768 hdd_ctx->config->max_rssi_boost_5g;
9769 band_pref_params.rssi_penalize_threshold_5g =
9770 hdd_ctx->config->rssi_penalize_threshold_5g;
9771 band_pref_params.rssi_penalize_factor_5g =
9772 hdd_ctx->config->rssi_penalize_factor_5g;
9773 band_pref_params.max_rssi_penalize_5g =
9774 hdd_ctx->config->max_rssi_penalize_5g;
9775 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9776 }
9777
Arun Khandavallid4349a92016-07-25 11:10:43 +05309778 /* register P2P Listen Offload event callback */
9779 if (wma_is_p2p_lo_capable())
9780 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9781 wlan_hdd_p2p_lo_event_callback);
9782
9783 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9784
9785 if (ret)
9786 goto deregister_cb;
9787
9788 EXIT();
9789 return 0;
9790
9791deregister_cb:
9792 hdd_deregister_cb(hdd_ctx);
9793deregister_frames:
9794 wlan_hdd_cfg80211_deregister_frames(adapter);
9795out:
9796 return -EINVAL;
9797
9798}
9799
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009800/**
9801 * hdd_features_deinit() - Deinit features
9802 * @hdd_ctx: HDD context
9803 *
9804 * De-Initialize features and their feature context.
9805 *
9806 * Return: none.
9807 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009808static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009809{
9810 wlan_hdd_tsf_deinit(hdd_ctx);
9811}
9812
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309813/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009814 * hdd_register_bcn_cb() - register scan beacon callback
9815 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309816 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009817 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309818 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009819static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309820{
9821 QDF_STATUS status;
9822
9823 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9824 wlan_cfg80211_inform_bss_frame,
9825 SCAN_CB_TYPE_INFORM_BCN);
9826 if (!QDF_IS_STATUS_SUCCESS(status)) {
9827 hdd_err("failed with status code %08d [x%08x]",
9828 status, status);
9829 return status;
9830 }
9831
9832 return QDF_STATUS_SUCCESS;
9833}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309834
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309835/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309836 * hdd_configure_cds() - Configure cds modules
9837 * @hdd_ctx: HDD context
9838 * @adapter: Primary adapter context
9839 *
9840 * Enable Cds modules after WLAN firmware is up.
9841 *
9842 * Return: 0 on success and errno on failure.
9843 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009844int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309845{
9846 int ret;
9847 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309848 int set_value;
9849 uint32_t num_abg_tx_chains = 0;
9850 uint32_t num_11b_tx_chains = 0;
9851 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009852 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309853
9854 if (hdd_ctx->config->sifs_burst_duration) {
9855 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9856 hdd_ctx->config->sifs_burst_duration;
9857
9858 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9859 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9860 set_value, PDEV_CMD);
9861 }
9862
9863 if (hdd_ctx->config->is_force_1x1)
9864 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9865 1, PDEV_CMD);
9866 /* set chip power save failure detected callback */
9867 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9868 hdd_chip_pwr_save_fail_detected_cb);
9869
9870 if (hdd_ctx->config->max_mpdus_inampdu) {
9871 set_value = hdd_ctx->config->max_mpdus_inampdu;
9872 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9873 set_value, PDEV_CMD);
9874 }
9875
9876 if (hdd_ctx->config->enable_rts_sifsbursting) {
9877 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9878 sme_cli_set_command(0,
9879 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9880 set_value, PDEV_CMD);
9881 }
9882
9883 if (hdd_ctx->config->sap_get_peer_info) {
9884 set_value = hdd_ctx->config->sap_get_peer_info;
9885 sme_cli_set_command(0,
9886 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9887 set_value, PDEV_CMD);
9888 }
9889
9890 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9891 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9892 if (!hdd_ctx->config->enable2x2) {
9893 if (num_11b_tx_chains > 1)
9894 num_11b_tx_chains = 1;
9895 if (num_11ag_tx_chains > 1)
9896 num_11ag_tx_chains = 1;
9897 }
9898 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9899 num_11b_tx_chains);
9900 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9901 num_11ag_tx_chains);
9902 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9903 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309904
9905 ret = hdd_pre_enable_configure(hdd_ctx);
9906 if (ret) {
9907 hdd_err("Failed to pre-configure cds");
9908 goto out;
9909 }
9910
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009911 /* Always get latest IPA resources allocated from cds_open and configure
9912 * IPA module before configuring them to FW. Sequence required as crash
9913 * observed otherwise.
9914 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009915 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9916 hdd_err("Failed to setup pipes");
9917 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009918 }
9919
Arun Khandavallifae92942016-08-01 13:31:08 +05309920 /*
9921 * Start CDS which starts up the SME/MAC/HAL modules and everything
9922 * else
9923 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009924 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309925
9926 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009927 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309928 goto out;
9929 }
9930
9931 status = hdd_post_cds_enable_config(hdd_ctx);
9932 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009933 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009934 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309935 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309936 status = hdd_register_bcn_cb(hdd_ctx);
9937 if (!QDF_IS_STATUS_SUCCESS(status)) {
9938 hdd_alert("hdd_post_cds_enable_config failed");
9939 goto cds_disable;
9940 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309941
9942 ret = hdd_features_init(hdd_ctx, adapter);
9943 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009944 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309945
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009946 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009947 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009948 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9949 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009950 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009951 goto cds_disable;
9952 }
9953
Himanshu Agarwalb229a142017-12-21 10:16:45 +05309954 if (ucfg_green_ap_enable_egap(hdd_ctx->hdd_pdev))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309955 hdd_debug("enhance green ap is not enabled");
9956
Nachiket Kukadedd302662017-07-13 17:31:44 +05309957 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9958 hdd_debug("Failed to set wow pulse");
9959
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309960 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9961 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9962
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309963
9964 if (hdd_ctx->config->enable_phy_reg_retention)
9965 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9966 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9967
Arun Khandavallifae92942016-08-01 13:31:08 +05309968 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009969
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009970cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009971 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009972
Arun Khandavallifae92942016-08-01 13:31:08 +05309973out:
9974 return -EINVAL;
9975}
9976
9977/**
9978 * hdd_deconfigure_cds() -De-Configure cds
9979 * @hdd_ctx: HDD context
9980 *
9981 * Deconfigure Cds modules before WLAN firmware is down.
9982 *
9983 * Return: 0 on success and errno on failure.
9984 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009985static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309986{
9987 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009988 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309989
9990 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009991
9992 /* De-init features */
9993 hdd_features_deinit(hdd_ctx);
9994
Arun Khandavallifae92942016-08-01 13:31:08 +05309995 /* De-register the SME callbacks */
9996 hdd_deregister_cb(hdd_ctx);
9997
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009998 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309999 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10000 hdd_err("Failed to Disable the CDS Modules! :%d",
10001 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010002 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010003 }
10004
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010005 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
10006 hdd_err("Failed to disconnect pipes");
10007 ret = -EINVAL;
10008 }
10009
Arun Khandavallifae92942016-08-01 13:31:08 +053010010 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010011 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010012}
10013
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010014#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10015static void hdd_deregister_policy_manager_callback(
10016 struct wlan_objmgr_psoc *psoc)
10017{
10018 if (QDF_STATUS_SUCCESS !=
10019 policy_mgr_deregister_hdd_cb(psoc)) {
10020 hdd_err("HDD callback deregister with policy manager failed");
10021 }
10022}
10023#else
10024static void hdd_deregister_policy_manager_callback(
10025 struct wlan_objmgr_psoc *psoc)
10026{
10027}
10028#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010029
10030/**
10031 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10032 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010033 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010034 *
10035 * This function maintains the driver state machine it will be invoked from
10036 * exit, shutdown and con_mode change handler. Depending on the driver state
10037 * shall perform the stopping/closing of the modules.
10038 *
10039 * Return: 0 for success; non-zero for failure
10040 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010041int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010042{
10043 void *hif_ctx;
10044 qdf_device_t qdf_ctx;
10045 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010046 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010047 bool is_recovery_stop = cds_is_driver_recovering();
10048 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop;
Dustin Brown70111822017-03-30 15:31:40 -070010049 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +053010050
10051 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -070010052 hdd_alert("stop WLAN module: entering driver status=%d",
10053 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010054
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010055 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10056
Arun Khandavallifae92942016-08-01 13:31:08 +053010057 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10058 if (!qdf_ctx) {
10059 hdd_err("QDF device context NULL");
10060 return -EINVAL;
10061 }
10062
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010063 mutex_lock(&hdd_ctx->iface_change_lock);
10064 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010065 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010066
Dustin Brown70111822017-03-30 15:31:40 -070010067 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010068 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010069 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010070 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010071
10072 cds_print_external_threads();
10073
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010074 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010075 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010076 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10077 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010078 hdd_prevent_suspend_timeout(
10079 hdd_ctx->config->iface_change_wait_time,
10080 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010081 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010082 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010083 return 0;
10084 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010085 }
10086
Arun Khandavallifae92942016-08-01 13:31:08 +053010087 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10088
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010089 /* free user wowl patterns */
10090 hdd_free_user_wowl_ptrns();
10091
Arun Khandavallifae92942016-08-01 13:31:08 +053010092 switch (hdd_ctx->driver_status) {
10093 case DRIVER_MODULES_UNINITIALIZED:
10094 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010095 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010096 case DRIVER_MODULES_CLOSED:
10097 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010098 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010099 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010100 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10101
Komal Seelamf2136bb2016-09-28 18:30:44 +053010102 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010103 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010104 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010105 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010106 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010107 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010108 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010109
Arun Khandavallifae92942016-08-01 13:31:08 +053010110 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010111 hdd_info("Wlan transitioned (now OPENED)");
10112
10113 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010114 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010115 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010116 break;
10117 default:
10118 hdd_err("Trying to stop wlan in a wrong state: %d",
10119 hdd_ctx->driver_status);
10120 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010121 ret = -EINVAL;
10122 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010123 }
10124
Dustin Brown550f6d22017-12-14 15:44:01 -080010125 hdd_debug("Closing CDS modules!");
Rajeev Kumarbe021242017-02-16 16:12:23 -080010126 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010127 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10128 hdd_err("Failed to process post CDS disable Modules! :%d",
10129 qdf_status);
10130 ret = -EINVAL;
10131 QDF_ASSERT(0);
10132 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010133
psimhadeea0a12017-12-18 14:50:02 -080010134 hdd_runtime_suspend_context_deinit(hdd_ctx);
10135
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010136 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10137 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10138 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10139 ret = -EINVAL;
10140 QDF_ASSERT(0);
10141 }
10142
Jeff Johnsone4b14592017-09-13 14:23:33 -070010143 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010144 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010145 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010146 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010147 QDF_ASSERT(0);
10148 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010149
Liangwei Dong50a64a72018-01-11 01:17:00 -050010150 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10151 if (ret) {
10152 hdd_err("Failed to destroy pdev; errno:%d", ret);
10153 QDF_ASSERT(0);
10154 }
10155
10156 /*
10157 * Reset total mac phy during module stop such that during
10158 * next module start same psoc is used to populate new service
10159 * ready data
10160 */
10161 hdd_ctx->hdd_psoc->total_mac_phy = 0;
10162
Arun Khandavallifae92942016-08-01 13:31:08 +053010163 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10164 if (!hif_ctx) {
10165 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010166 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010167 }
10168
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010169 if (hdd_ctx->target_hw_name) {
10170 qdf_mem_free(hdd_ctx->target_hw_name);
10171 hdd_ctx->target_hw_name = NULL;
10172 }
10173
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010174 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010175
10176 ol_cds_free();
10177
Dustin Brown70111822017-03-30 15:31:40 -070010178 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010179 ret = pld_power_off(qdf_ctx->dev);
10180 if (ret)
10181 hdd_err("CNSS power down failed put device into Low power mode:%d",
10182 ret);
10183 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010184
Dustin Brown4bc0a622017-12-06 15:56:50 -080010185 /* many adapter resources are not freed by design in SSR case */
10186 if (!is_recovery_stop)
10187 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010188 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010189
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010190 /* Once the firmware sequence is completed reset this flag */
10191 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010192 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010193 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010194
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010195done:
10196 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010197 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010198 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010199 hdd_alert("stop WLAN module: exit driver status=%d",
10200 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010201
Arun Khandavallifae92942016-08-01 13:31:08 +053010202 EXIT();
10203
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010204 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010205}
10206
Arun Khandavallifae92942016-08-01 13:31:08 +053010207
10208/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010209 * hdd_state_info_dump() - prints state information of hdd layer
10210 * @buf: buffer pointer
10211 * @size: size of buffer to be filled
10212 *
10213 * This function is used to dump state information of hdd layer
10214 *
10215 * Return: None
10216 */
10217static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10218{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010219 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010220 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010221 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010222 uint16_t len = 0;
10223 char *buf = *buf_ptr;
10224
10225 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10226 if (!hdd_ctx) {
10227 hdd_err("Failed to get hdd context ");
10228 return;
10229 }
10230
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010231 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010232
10233 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010234 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010235 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010236 "\n is_scheduler_suspended %d",
10237 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010238
Dustin Brown920397d2017-12-13 16:27:50 -080010239 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010240 if (adapter->dev)
10241 len += scnprintf(buf + len, *size - len,
10242 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010243 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010244 "\n device_mode: %d", adapter->device_mode);
10245 switch (adapter->device_mode) {
10246 case QDF_STA_MODE:
10247 case QDF_P2P_CLIENT_MODE:
10248 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10249 len += scnprintf(buf + len, *size - len,
10250 "\n connState: %d",
10251 hdd_sta_ctx->conn_info.connState);
10252 break;
10253
10254 default:
10255 break;
10256 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010257 }
10258
10259 *size -= len;
10260 *buf_ptr += len;
10261}
10262
10263/**
10264 * hdd_register_debug_callback() - registration function for hdd layer
10265 * to print hdd state information
10266 *
10267 * Return: None
10268 */
10269static void hdd_register_debug_callback(void)
10270{
10271 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10272}
10273
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010274/*
10275 * wlan_init_bug_report_lock() - Initialize bug report lock
10276 *
10277 * This function is used to create bug report lock
10278 *
10279 * Return: None
10280 */
10281static void wlan_init_bug_report_lock(void)
10282{
10283 p_cds_contextType p_cds_context;
10284
10285 p_cds_context = cds_get_global_context();
10286 if (!p_cds_context) {
10287 hdd_err("cds context is NULL");
10288 return;
10289 }
10290
10291 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10292}
10293
Mohit Khannaf8f96822017-05-17 17:11:59 -070010294void hdd_dp_trace_init(struct hdd_config *config)
10295{
10296
10297 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10298 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10299 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10300 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10301 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10302 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10303 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010304 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010305
10306 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10307 &num_entries, sizeof(config_params));
10308
10309 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010310 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010311 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010312 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010313 else if (bw_compute_interval > 1000) {
10314 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10315 thresh_time_limit = 1;
10316 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010317 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10318
10319 switch (num_entries) {
10320 case 4:
10321 proto_bitmap = config_params[3];
10322 case 3:
10323 verbosity = config_params[2];
10324 case 2:
10325 thresh = config_params[1];
10326 case 1:
10327 live_mode = config_params[0];
10328 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010329 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010330 live_mode, thresh, thresh_time_limit,
10331 verbosity, proto_bitmap);
10332 };
10333
10334 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10335 verbosity, proto_bitmap);
10336
10337}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010338/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010339 * hdd_wlan_startup() - HDD init function
10340 * @dev: Pointer to the underlying device
10341 *
10342 * This is the driver startup code executed once a WLAN device has been detected
10343 *
10344 * Return: 0 for success, < 0 for failure
10345 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010346int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010347{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010348 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010349 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010350 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010351 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010352
10353 ENTER();
10354
Arun Khandavallifae92942016-08-01 13:31:08 +053010355 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010356
10357 if (IS_ERR(hdd_ctx))
10358 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010359
Abhishek Singhe9068f12017-03-31 14:14:52 +053010360 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10361 DEFAULT_PSOC_ID);
10362 if (ret) {
10363 hdd_err("Psoc creation fails!");
10364 QDF_BUG(0);
10365 goto err_hdd_free_context;
10366 }
10367
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010368 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010369#ifdef FEATURE_WLAN_CH_AVOID
10370 mutex_init(&hdd_ctx->avoid_freq_lock);
10371#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010372
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010373 hdd_request_manager_init();
Arun Khandavallifae92942016-08-01 13:31:08 +053010374
Dustin Brown021cecd2017-12-11 13:56:43 -080010375 hdd_driver_memdump_init();
10376
Jeff Johnson957bc272017-02-02 08:54:48 -080010377 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010378 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010379 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010380 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010381 }
10382
Yingying Tang80e15f32016-09-27 18:23:01 +080010383 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010384
Anurag Chouhan6d760662016-02-20 16:05:43 +053010385 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010386
10387 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010388 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010389 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010390 }
10391
Prashanth Bhatta07998752016-04-28 12:35:33 -070010392 ret = hdd_wiphy_init(hdd_ctx);
10393 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010394 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010395 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010396 }
10397
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010398 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010399 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010400
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010401 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010402 goto err_wiphy_unregister;
10403
Kapil Gupta4f0c0c12017-02-07 15:21:15 +053010404 wlan_hdd_init_chan_info(hdd_ctx);
10405
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010406 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010407
Paul Zhangfb02f452017-12-22 11:58:43 +080010408 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10409 if (ret) {
10410 hdd_err("register_netdevice_notifier failed: %d", ret);
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010411 goto err_ipa_cleanup;
Paul Zhangfb02f452017-12-22 11:58:43 +080010412 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010413
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010414 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010415
Jeff Johnson957bc272017-02-02 08:54:48 -080010416 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10417 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010418 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010419 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010420 }
10421
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010422 hdd_release_rtnl_lock();
10423 rtnl_held = false;
10424
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010425 wlan_hdd_update_11n_mode(hdd_ctx->config);
10426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010427#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010428 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010429 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010430 hdd_skip_acs_scan_timer_handler,
10431 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010432 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010433 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010434 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010435#endif
10436
Prashanth Bhattaab004382016-10-11 16:08:11 -070010437 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010438
Jeff Johnson9afc5012016-09-23 13:56:27 -070010439 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010440
Nirav Shahbd36b062016-07-18 11:12:59 +053010441 if (hdd_ctx->rps)
10442 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010443
Paul Zhangfb02f452017-12-22 11:58:43 +080010444 ret = hdd_register_notifiers(hdd_ctx);
10445 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010446 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010447
Paul Zhangfb02f452017-12-22 11:58:43 +080010448 status = wlansap_global_init();
10449 if (QDF_IS_STATUS_ERROR(status)) {
10450 hdd_unregister_notifiers(hdd_ctx);
10451 goto err_close_adapters;
10452 }
10453
Arun Khandavallifae92942016-08-01 13:31:08 +053010454 if (hdd_ctx->config->fIsImpsEnabled)
10455 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010456 else
10457 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010458
Mukul Sharma07bd8752017-10-10 16:58:14 +053010459 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010460 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10461 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010462 hdd_prevent_suspend_timeout(
10463 hdd_ctx->config->iface_change_wait_time,
10464 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10465 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010466
Sachin Ahujadddd2632017-03-07 19:07:24 +053010467 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010468 goto success;
10469
Jeff Johnson957bc272017-02-02 08:54:48 -080010470err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010471 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010472
Jeff Johnson46bde382017-02-01 15:31:16 -080010473err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010474 if (rtnl_held)
10475 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010476
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010477 unregister_netdevice_notifier(&hdd_netdev_notifier);
10478
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010479err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010480 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010481
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010482err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010483 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010484
Arun Khandavallifae92942016-08-01 13:31:08 +053010485err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010486 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010487
Dustin Brown021cecd2017-12-11 13:56:43 -080010488err_memdump_deinit:
10489 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010490
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010491 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010492 hdd_exit_netlink_services(hdd_ctx);
10493
Dustin Brown20912462017-06-07 13:48:25 -070010494 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10495
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010496err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010497 if (cds_is_fw_down())
10498 hdd_err("Not setting the complete event as fw is down");
10499 else
10500 hdd_start_complete(ret);
10501
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010502 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010503 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010504 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010505
10506success:
10507 EXIT();
10508 return 0;
10509}
10510
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010511/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010512 * hdd_wlan_update_target_info() - update target type info
10513 * @hdd_ctx: HDD context
10514 * @context: hif context
10515 *
10516 * Update target info received from firmware in hdd context
10517 * Return:None
10518 */
10519
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010520void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010521{
10522 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10523
10524 if (!tgt_info) {
10525 hdd_err("Target info is Null");
10526 return;
10527 }
10528
10529 hdd_ctx->target_type = tgt_info->target_type;
10530}
10531
10532/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010533 * hdd_get_nud_stats_cb() - callback api to update the stats
10534 * received from the firmware
10535 * @data: pointer to adapter.
10536 * @rsp: pointer to data received from FW.
10537 *
10538 * This is called when wlan driver received response event for
10539 * get arp stats to firmware.
10540 *
10541 * Return: None
10542 */
10543static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10544{
10545 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10546 struct hdd_nud_stats_context *context;
10547 int status;
10548 struct hdd_adapter *adapter = NULL;
10549
10550 ENTER();
10551
10552 if (!rsp) {
10553 hdd_err("data is null");
10554 return;
10555 }
10556
10557 status = wlan_hdd_validate_context(hdd_ctx);
10558 if (0 != status)
10559 return;
10560
10561 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10562 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10563 hdd_err("Invalid adapter or adapter has invalid magic");
10564 return;
10565 }
10566
10567 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10568 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10569 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10570 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10571 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10572 rsp->out_of_order_arp_rsp_drop_cnt);
10573 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10574 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10575 hdd_notice("rsp->ba_session_establishment_status :%x",
10576 rsp->ba_session_establishment_status);
10577
10578 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10579 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10580 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10581 adapter->dad |= rsp->dad_detected;
10582 adapter->con_status = rsp->connect_status;
10583
10584 spin_lock(&hdd_context_lock);
10585 context = &hdd_ctx->nud_stats_context;
10586 complete(&context->response_event);
10587 spin_unlock(&hdd_context_lock);
10588
10589 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010590}
10591
10592/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010593 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010594 * @hdd_ctx: HDD context
10595 *
10596 * Register the HDD callbacks to CDS/SME.
10597 *
10598 * Return: 0 for success or Error code for failure
10599 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010600int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010601{
10602 QDF_STATUS status;
10603 int ret = 0;
10604
10605 ENTER();
10606
10607 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10608
10609 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10610 hdd_send_oem_data_rsp_msg);
10611
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010612 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10613 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010614 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10615 sme_nan_register_callback(hdd_ctx->hHal,
10616 wlan_hdd_cfg80211_nan_callback);
10617 sme_stats_ext_register_callback(hdd_ctx->hHal,
10618 wlan_hdd_cfg80211_stats_ext_callback);
10619
10620 sme_ext_scan_register_callback(hdd_ctx->hHal,
10621 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010622 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10623 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010624
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010625 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10626 hdd_rssi_threshold_breached);
10627
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010628 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10629
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010630 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10631 wlan_hdd_cfg80211_link_layer_stats_callback);
10632
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010633 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10634
Zhang Qianca38fb12016-12-23 11:10:48 +080010635 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10636 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10637
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010638 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10639 hdd_lost_link_info_cb);
10640 /* print error and not block the startup process */
10641 if (!QDF_IS_STATUS_SUCCESS(status))
10642 hdd_err("set lost link info callback failed");
10643
Poddar, Siddarth34872782017-08-10 14:08:51 +053010644 ret = hdd_register_data_stall_detect_cb();
10645 if (ret) {
10646 hdd_err("Register data stall detect detect callback failed.");
10647 return ret;
10648 }
10649
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010650 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10651
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010652 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010653 hdd_set_connection_in_progress,
10654 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010655
10656 status = sme_congestion_register_callback(hdd_ctx->hHal,
10657 hdd_update_cca_info_cb);
10658 if (!QDF_IS_STATUS_SUCCESS(status))
10659 hdd_err("set congestion callback failed");
10660
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010661 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10662 hdd_bt_activity_cb);
10663 if (!QDF_IS_STATUS_SUCCESS(status))
10664 hdd_err("set bt activity info callback failed");
10665
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010666 EXIT();
10667
10668 return ret;
10669}
10670
10671/**
10672 * hdd_deregister_cb() - De-Register HDD callbacks.
10673 * @hdd_ctx: HDD context
10674 *
10675 * De-Register the HDD callbacks to CDS/SME.
10676 *
10677 * Return: void
10678 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010679void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010680{
10681 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010682 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010683
10684 ENTER();
10685
10686 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10687 if (!QDF_IS_STATUS_SUCCESS(status))
10688 hdd_err("De-register of dcc stats callback failed: %d",
10689 status);
10690
10691 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010692 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10693
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010694 sme_stats_ext_register_callback(hdd_ctx->hHal,
10695 wlan_hdd_cfg80211_stats_ext_callback);
10696
10697 sme_nan_deregister_callback(hdd_ctx->hHal);
10698 status = sme_reset_tsfcb(hdd_ctx->hHal);
10699 if (!QDF_IS_STATUS_SUCCESS(status))
10700 hdd_err("Failed to de-register tsfcb the callback:%d",
10701 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010702
Poddar, Siddarth34872782017-08-10 14:08:51 +053010703 ret = hdd_deregister_data_stall_detect_cb();
10704 if (ret)
10705 hdd_err("Failed to de-register data stall detect event callback");
10706
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010707 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10708 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10709
10710 EXIT();
10711}
10712
10713/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010714 * hdd_softap_sta_deauth() - handle deauth req from HDD
10715 * @adapter: Pointer to the HDD
10716 * @enable: bool value
10717 *
10718 * This to take counter measure to handle deauth req from HDD
10719 *
10720 * Return: None
10721 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010722QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010723 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010724{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010725 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010726
10727 ENTER();
10728
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010729 /* Ignore request to deauth bcmc station */
10730 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010731 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010732
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010733 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010734 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10735 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010736
10737 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010738 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010739}
10740
10741/**
10742 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10743 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010744 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010745 *
10746 * This to take counter measure to handle deauth req from HDD
10747 *
10748 * Return: None
10749 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010750void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010751 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010752{
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010753 struct sir_peer_sta_info peer_sta_info;
10754 struct hdd_station_info *stainfo;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010755 ENTER();
10756
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010757 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010758 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010759 return;
10760
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010761 wlan_hdd_get_peer_rssi(adapter, &pDelStaParams->peerMacAddr,
10762 &peer_sta_info);
10763 stainfo = hdd_get_stainfo(adapter->cache_sta_info,
10764 pDelStaParams->peerMacAddr);
10765 if (stainfo) {
10766 stainfo->rssi = peer_sta_info.info[0].rssi;
10767 stainfo->tx_rate = peer_sta_info.info[0].tx_rate;
10768 stainfo->rx_rate = peer_sta_info.info[0].rx_rate;
10769 }
10770
10771 stainfo->reason_code = pDelStaParams->reason_code;
10772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010773 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010774 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010775}
10776
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010777/**
10778 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10779 * @hdd_ctx: HDD Context
10780 *
10781 * API to find if there is any STA or P2P-Client is connected
10782 *
10783 * Return: true if connected; false otherwise
10784 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010785QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010786{
10787 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10788}
10789
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010790/**
10791 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10792 * @adapter: HDD adapter pointer
10793 *
10794 * This function loop through each adapter and disable roaming on each STA
10795 * device mode except the input adapter.
10796 *
10797 * Note: On the input adapter roaming is not enabled yet hence no need to
10798 * disable.
10799 *
10800 * Return: None
10801 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010802void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010803{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010804 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010805 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010806
10807 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010808 hdd_ctx->config->isRoamOffloadScanEnabled &&
10809 QDF_STA_MODE == adapter->device_mode &&
10810 policy_mgr_is_sta_active_connection_exists(
10811 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010812 hdd_debug("Connect received on STA session Id(%d)",
10813 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010814 /*
10815 * Loop through adapter and disable roaming for each STA device
10816 * mode except the input adapter.
10817 */
Dustin Brown920397d2017-12-13 16:27:50 -080010818 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010819 if (QDF_STA_MODE == adapterIdx->device_mode &&
10820 adapter->session_id != adapterIdx->session_id) {
10821 hdd_debug("Disable Roaming on session Id(%d)",
10822 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010823 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10824 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010825 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010826 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010827 }
10828 }
10829}
10830
10831/**
10832 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10833 * @adapter: HDD adapter pointer
10834 *
10835 * This function loop through each adapter and enable roaming on each STA
10836 * device mode except the input adapter.
10837 * Note: On the input adapter no need to enable roaming because link got
10838 * disconnected on this.
10839 *
10840 * Return: None
10841 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010842void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010843{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010844 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010845 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010846
10847 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010848 hdd_ctx->config->isRoamOffloadScanEnabled &&
10849 QDF_STA_MODE == adapter->device_mode &&
10850 policy_mgr_is_sta_active_connection_exists(
10851 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010852 hdd_debug("Disconnect received on STA session Id(%d)",
10853 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010854 /*
10855 * Loop through adapter and enable roaming for each STA device
10856 * mode except the input adapter.
10857 */
Dustin Brown920397d2017-12-13 16:27:50 -080010858 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010859 if (QDF_STA_MODE == adapterIdx->device_mode &&
10860 adapter->session_id != adapterIdx->session_id) {
10861 hdd_debug("Enabling Roaming on session Id(%d)",
10862 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010863 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10864 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010865 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010866 REASON_CONNECT);
10867 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010868 }
10869 }
10870}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010871
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010872/**
10873 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10874 * @skb: sk buffer pointer
10875 *
10876 * Sends the bcast message to SVC multicast group with generic nl socket
10877 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10878 *
10879 * Return: None
10880 */
10881static void nl_srv_bcast_svc(struct sk_buff *skb)
10882{
10883#ifdef CNSS_GENL
10884 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10885#else
10886 nl_srv_bcast(skb);
10887#endif
10888}
10889
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010890void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010891{
10892 struct sk_buff *skb;
10893 struct nlmsghdr *nlh;
10894 tAniMsgHdr *ani_hdr;
10895 void *nl_data = NULL;
10896 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010897 struct radio_index_tlv *radio_info;
10898 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010899
10900 if (in_interrupt() || irqs_disabled() || in_atomic())
10901 flags = GFP_ATOMIC;
10902
10903 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10904
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010905 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010906 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010907
10908 nlh = (struct nlmsghdr *)skb->data;
10909 nlh->nlmsg_pid = 0; /* from kernel */
10910 nlh->nlmsg_flags = 0;
10911 nlh->nlmsg_seq = 0;
10912 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10913
10914 ani_hdr = NLMSG_DATA(nlh);
10915 ani_hdr->type = type;
10916
10917 switch (type) {
10918 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010919 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010920 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010921 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010922 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010923 ani_hdr->length = 0;
10924 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010925 break;
10926 case WLAN_SVC_WLAN_STATUS_IND:
10927 case WLAN_SVC_WLAN_VERSION_IND:
10928 case WLAN_SVC_DFS_CAC_START_IND:
10929 case WLAN_SVC_DFS_CAC_END_IND:
10930 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10931 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10932 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010933 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010934 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010935 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010936 ani_hdr->length = len;
10937 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10938 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10939 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010940 break;
10941
10942 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010943 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010944 type);
10945 kfree_skb(skb);
10946 return;
10947 }
10948
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010949 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010950 * Add radio index at the end of the svc event in TLV format
10951 * to maintain the backward compatibility with userspace
10952 * applications.
10953 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010954
10955 tlv_len = 0;
10956
10957 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10958 < WLAN_NL_MAX_PAYLOAD) {
10959 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10960 sizeof(*ani_hdr) + len);
10961 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10962 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10963 radio_info->radio = radio;
10964 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010965 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010966 "Added radio index tlv - radio index %d",
10967 radio_info->radio);
10968 }
10969
10970 nlh->nlmsg_len += tlv_len;
10971 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10972
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010973 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010974}
10975
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010976#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10977void wlan_hdd_auto_shutdown_cb(void)
10978{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010979 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010980
10981 if (!hdd_ctx)
10982 return;
10983
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010984 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010985 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10986 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010987}
10988
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010989void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010990{
Jeff Johnson9d295242017-08-29 14:39:48 -070010991 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010992 bool ap_connected = false, sta_connected = false;
10993 tHalHandle hal_handle;
10994
10995 hal_handle = hdd_ctx->hHal;
10996 if (hal_handle == NULL)
10997 return;
10998
10999 if (hdd_ctx->config->WlanAutoShutdown == 0)
11000 return;
11001
11002 if (enable == false) {
11003 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011004 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011005 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011006 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011007 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011008 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011009 return;
11010 }
11011
11012 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011013 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11014 hdd_for_each_adapter(hdd_ctx, adapter) {
11015 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011016 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11017 conn_info.connState ==
11018 eConnectionState_Associated) {
11019 sta_connected = true;
11020 break;
11021 }
11022 }
Dustin Brown920397d2017-12-13 16:27:50 -080011023
11024 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011025 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011026 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011027 ap_connected = true;
11028 break;
11029 }
11030 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011031 }
11032 }
11033
11034 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011035 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011036 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011037 }
Jeff Johnson68755312017-02-10 11:46:55 -080011038
11039 if (sme_set_auto_shutdown_timer(hal_handle,
11040 hdd_ctx->config->WlanAutoShutdown)
11041 != QDF_STATUS_SUCCESS)
11042 hdd_err("Failed to start wlan auto shutdown timer");
11043 else
11044 hdd_notice("Auto Shutdown timer for %d seconds enabled",
11045 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011046}
11047#endif
11048
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011049struct hdd_adapter *
11050hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11051 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011052{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011053 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011054 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011055
11056 con_sap_adapter = NULL;
11057
Dustin Brown920397d2017-12-13 16:27:50 -080011058 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011059 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11060 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011061 adapter != this_sap_adapter) {
11062 if (check_start_bss) {
11063 if (test_bit(SOFTAP_BSS_STARTED,
11064 &adapter->event_flags)) {
11065 con_sap_adapter = adapter;
11066 break;
11067 }
11068 } else {
11069 con_sap_adapter = adapter;
11070 break;
11071 }
11072 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011073 }
11074
11075 return con_sap_adapter;
11076}
11077
11078#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011079static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011080{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011081 return adapter->device_mode == QDF_STA_MODE ||
11082 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011083}
11084
Jeff Johnson9d295242017-08-29 14:39:48 -070011085static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011086{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011087 return adapter->device_mode == QDF_SAP_MODE ||
11088 adapter->device_mode == QDF_P2P_GO_MODE;
11089}
11090
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011091static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011092{
Dustin Brown920397d2017-12-13 16:27:50 -080011093 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011094
Dustin Brown920397d2017-12-13 16:27:50 -080011095 hdd_for_each_adapter(hdd_ctx, adapter) {
11096 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011097 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11098 conn_info.connState == eConnectionState_Associated) {
11099 return true;
11100 }
11101
Dustin Brown920397d2017-12-13 16:27:50 -080011102 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011103 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011104 return true;
11105 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011106 }
11107
11108 return false;
11109}
11110
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011111static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011112{
11113 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011114
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011115 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011116 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011117 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011118
Dustin Brown5ec6b552017-03-31 12:11:40 -070011119 return is_running;
11120}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011121
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011122static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011123{
11124 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11125 hdd_ctx->bus_bw_timer_running = true;
11126 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11127 hdd_ctx->config->busBandwidthComputeInterval);
11128 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11129}
11130
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011131void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011132{
11133 ENTER();
11134
11135 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11136 hdd_debug("Bandwidth compute timer already started");
11137 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011138 }
11139
Dustin Brown5ec6b552017-03-31 12:11:40 -070011140 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11141
11142 EXIT();
11143}
11144
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011145void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011146{
11147 ENTER();
11148
11149 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11150 hdd_debug("Bandwidth compute timer already started");
11151 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011152 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011153
11154 if (hdd_any_adapter_is_assoc(hdd_ctx))
11155 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11156
11157 EXIT();
11158}
11159
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011160static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011161{
11162 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
11163
11164 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11165 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11166 hdd_ctx->bus_bw_timer_running = false;
11167 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11168
11169 hdd_reset_tcp_delack(hdd_ctx);
11170}
11171
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011172void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011173{
11174 ENTER();
11175
11176 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11177 hdd_debug("Bandwidth compute timer already stopped");
11178 return;
11179 }
11180
11181 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11182
11183 EXIT();
11184}
11185
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011186void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011187{
11188 ENTER();
11189
11190 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11191 hdd_debug("Bandwidth compute timer already stopped");
11192 return;
11193 }
11194
11195 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11196 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11197
11198 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011199}
11200#endif
11201
11202/**
11203 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11204 * and sta's operating channel.
11205 * @sta_adapter: Describe the first argument to foobar.
11206 * @ap_adapter: Describe the second argument to foobar.
11207 * @roam_profile: Roam profile of AP to which STA wants to connect.
11208 * @concurrent_chnl_same: If both SAP and STA channels are same then
11209 * set this flag to true else false.
11210 *
11211 * This function checks the sap's operating channel and sta's operating channel.
11212 * if both are same then it will return false else it will restart the sap in
11213 * sta's channel and return true.
11214 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011215 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011216 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011217QDF_STATUS
11218wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11219 struct hdd_adapter *ap_adapter,
11220 tCsrRoamProfile *roam_profile,
11221 tScanResultHandle *scan_cache,
11222 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011223{
Jeff Johnson87251032017-08-29 13:31:11 -070011224 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011225 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011226 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011227 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011228 *concurrent_chnl_same = true;
11229
11230 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11231 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011232 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011233 scan_cache,
11234 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011235 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011236 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011237 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011238 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011239 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011240 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011241 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011242 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011243 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011244 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011245 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011246 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011247 }
11248 }
11249 } else {
11250 /*
11251 * Lets handle worst case scenario here, Scan cache lookup is
11252 * failed so we have to stop the SAP to avoid any channel
11253 * discrepancy between SAP's channel and STA's channel.
11254 * Return the status as failure so caller function could know
11255 * that scan look up is failed.
11256 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011257 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011258 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011259 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011260 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011261}
11262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011263/**
11264 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11265 * @ap_adapter: SAP adapter
11266 *
11267 * This function will process the stopping of sap adapter.
11268 *
11269 * Return: None
11270 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011271void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011272{
Jeff Johnson87251032017-08-29 13:31:11 -070011273 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011274 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011275 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011276 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011277
11278 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011279 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011280 return;
11281 }
11282
11283 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11284 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011285 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011286 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011287
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011288 mutex_lock(&hdd_ctx->sap_lock);
11289 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011290 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011291 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011292 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011293 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011294 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011295 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011296 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011297 qdf_stop_bss_event,
11298 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011299 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011300 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011301 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011302 return;
11303 }
11304 }
11305 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011306 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11307 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011308 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011309 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011310 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011311 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011312 }
11313 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011314}
11315
11316/**
11317 * wlan_hdd_start_sap() - this function starts bss of SAP.
11318 * @ap_adapter: SAP adapter
11319 *
11320 * This function will process the starting of sap adapter.
11321 *
11322 * Return: None
11323 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011324void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011325{
Jeff Johnson87251032017-08-29 13:31:11 -070011326 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011327 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011328 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011329 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011330 tsap_Config_t *sap_config;
11331
11332 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011333 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011334 return;
11335 }
11336
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011337 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011338 hdd_err("SoftAp role has not been enabled");
11339 return;
11340 }
11341
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011342 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11343 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11344 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011345 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011346
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011347 mutex_lock(&hdd_ctx->sap_lock);
11348 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11349 goto end;
11350
11351 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011352 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011353 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
11354 goto end;
11355 }
11356
Wei Song2f76f642016-11-18 16:32:53 +080011357 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011358 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011359 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011360 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011361 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011362 goto end;
11363
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011364 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011365 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011366 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011367 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011368 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011369 goto end;
11370 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011371 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011372 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011373 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011374 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11375 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011376 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011377 mutex_unlock(&hdd_ctx->sap_lock);
11378
11379 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011380end:
11381 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011382 /* SAP context and beacon cleanup will happen during driver unload
11383 * in hdd_stop_adapter
11384 */
11385 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11386
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011387}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011388
11389/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011390 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11391 * mac scan config
11392 * @status: Status of set antenna mode
11393 *
11394 * Callback on setting the dual mac configuration
11395 *
11396 * Return: None
11397 */
11398void wlan_hdd_soc_set_antenna_mode_cb(
11399 enum set_antenna_mode_status status)
11400{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011401 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011402
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011403 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011404
11405 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11406 if (0 != wlan_hdd_validate_context(hdd_ctx))
11407 return;
11408
11409 /* Signal the completion of set dual mac config */
11410 complete(&hdd_ctx->set_antenna_mode_cmpl);
11411}
11412
11413/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011414 * hdd_get_fw_version() - Get FW version
11415 * @hdd_ctx: pointer to HDD context.
11416 * @major_spid: FW version - major spid.
11417 * @minor_spid: FW version - minor spid
11418 * @ssid: FW version - ssid
11419 * @crmid: FW version - crmid
11420 *
11421 * This function is called to get the firmware build version stored
11422 * as part of the HDD context
11423 *
11424 * Return: None
11425 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011426void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011427 uint32_t *major_spid, uint32_t *minor_spid,
11428 uint32_t *siid, uint32_t *crmid)
11429{
11430 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11431 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11432 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11433 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11434}
11435
11436#ifdef QCA_CONFIG_SMP
11437/**
11438 * wlan_hdd_get_cpu() - get cpu_index
11439 *
11440 * Return: cpu_index
11441 */
11442int wlan_hdd_get_cpu(void)
11443{
11444 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011445
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011446 put_cpu();
11447 return cpu_index;
11448}
11449#endif
11450
11451/**
11452 * hdd_get_fwpath() - get framework path
11453 *
11454 * This function is used to get the string written by
11455 * userspace to start the wlan driver
11456 *
11457 * Return: string
11458 */
11459const char *hdd_get_fwpath(void)
11460{
11461 return fwpath.string;
11462}
11463
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011464static int hdd_qdf_print_init(void)
11465{
11466 int qdf_print_idx;
11467 QDF_STATUS status;
11468
11469 status = qdf_print_setup();
11470 if (status != QDF_STATUS_SUCCESS) {
11471 pr_err("qdf_print_setup failed\n");
11472 return -EINVAL;
11473 }
11474
11475 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11476
11477 if (qdf_print_idx < 0) {
11478 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11479 qdf_print_idx);
11480 return -EINVAL;
11481 }
11482
11483 qdf_set_pidx(qdf_print_idx);
11484
11485 return 0;
11486}
11487
11488static void hdd_qdf_print_deinit(void)
11489{
11490 int qdf_print_idx;
11491
11492 qdf_print_idx = qdf_get_pidx();
11493 qdf_print_ctrl_cleanup(qdf_print_idx);
11494}
11495
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011496/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011497 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011498 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011499 * This function initilizes CDS global context with the help of cds_init. This
11500 * has to be the first function called after probe to get a valid global
11501 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011502 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011503 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011504 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011505int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011506{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011507 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011508 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011509
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011510 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011511 if (QDF_IS_STATUS_ERROR(status)) {
11512 hdd_err("Failed to allocate CDS context");
11513 ret = -ENOMEM;
11514 goto err_out;
11515 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011516
11517 wlan_init_bug_report_lock();
11518
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011519#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11520 wlan_logging_sock_init_svc();
11521#endif
11522
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011523 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11524 (void *)hdd_drv_ops_inactivity_handler, NULL,
11525 QDF_TIMER_TYPE_SW);
11526
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011527 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011528 hdd_qdf_print_init();
11529
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011530 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011531
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011532err_out:
11533 return ret;
11534}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011535
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011536/**
11537 * hdd_deinit() - Deinitialize Driver
11538 *
11539 * This function frees CDS global context with the help of cds_deinit. This
11540 * has to be the last function call in remove callback to free the global
11541 * context.
11542 */
11543void hdd_deinit(void)
11544{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011545 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011546
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011547 wlan_destroy_bug_report_lock();
11548 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011549
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011550 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011551#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11552 wlan_logging_sock_deinit_svc();
11553#endif
11554}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011555
Yue Ma6e7b1a02017-04-03 14:17:46 -070011556#ifdef QCA_WIFI_NAPIER_EMULATION
11557#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11558#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011559#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011560#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011561
Sachin Ahujadddd2632017-03-07 19:07:24 +053011562static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11563 struct file *file)
11564{
11565 return 0;
11566}
11567
11568static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11569 const char __user *user_buf,
11570 size_t count,
11571 loff_t *f_pos)
11572{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011573 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011574 static const char wlan_off_str[] = "OFF";
11575 static const char wlan_on_str[] = "ON";
11576 int ret;
11577 unsigned long rc;
11578
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011579 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011580 pr_err("Failed to read buffer\n");
11581 return -EINVAL;
11582 }
11583
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011584 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011585 pr_debug("Wifi turning off from UI\n");
11586 goto exit;
11587 }
11588
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011589 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011590 pr_err("Invalid value received from framework");
11591 goto exit;
11592 }
11593
11594 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011595 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011596 rc = wait_for_completion_timeout(&wlan_start_comp,
11597 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11598 if (!rc) {
11599 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11600 ret = -EINVAL;
11601 hdd_start_complete(ret);
11602 return ret;
11603 }
11604
11605 hdd_start_complete(0);
11606 }
11607
11608exit:
11609 return count;
11610}
11611
11612
11613const struct file_operations wlan_hdd_state_fops = {
11614 .owner = THIS_MODULE,
11615 .open = wlan_hdd_state_ctrl_param_open,
11616 .write = wlan_hdd_state_ctrl_param_write,
11617};
11618
11619static int wlan_hdd_state_ctrl_param_create(void)
11620{
11621 unsigned int wlan_hdd_state_major = 0;
11622 int ret;
11623 struct device *dev;
11624
11625 device = MKDEV(wlan_hdd_state_major, 0);
11626
11627 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11628 if (ret) {
11629 pr_err("Failed to register qcwlanstate");
11630 goto dev_alloc_err;
11631 }
11632 wlan_hdd_state_major = MAJOR(device);
11633
11634 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11635 if (IS_ERR(class)) {
11636 pr_err("wlan_hdd_state class_create error");
11637 goto class_err;
11638 }
11639
11640 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11641 if (IS_ERR(dev)) {
11642 pr_err("wlan_hdd_statedevice_create error");
11643 goto err_class_destroy;
11644 }
11645
11646 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11647 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11648 if (ret) {
11649 pr_err("Failed to add cdev error");
11650 goto cdev_add_err;
11651 }
11652
11653 pr_info("wlan_hdd_state %s major(%d) initialized",
11654 WLAN_MODULE_NAME, wlan_hdd_state_major);
11655
11656 return 0;
11657
11658cdev_add_err:
11659 device_destroy(class, device);
11660err_class_destroy:
11661 class_destroy(class);
11662class_err:
11663 unregister_chrdev_region(device, dev_num);
11664dev_alloc_err:
11665 return -ENODEV;
11666}
11667
11668static void wlan_hdd_state_ctrl_param_destroy(void)
11669{
11670 cdev_del(&wlan_hdd_state_cdev);
11671 device_destroy(class, device);
11672 class_destroy(class);
11673 unregister_chrdev_region(device, dev_num);
11674
11675 pr_info("Device node unregistered");
11676}
11677
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011678/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011679 * component_init - API to init cld component's
11680 *
11681 * Return: None
11682 */
11683static void component_init(void)
11684{
11685 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011686 disa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011687}
11688
11689/**
11690 * component_deinit - API to deinit cld component's
11691 *
11692 * Return: None
11693 */
11694static void component_deinit(void)
11695{
11696 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011697 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011698}
11699
11700void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11701{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011702 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011703}
11704
11705void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11706{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011707 disa_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011708}
11709
11710/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011711 * __hdd_module_init - Module init helper
11712 *
11713 * Module init helper function used by both module and static driver.
11714 *
11715 * Return: 0 for success, errno on failure
11716 */
11717static int __hdd_module_init(void)
11718{
11719 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011720
Dustin Brown96cd9632017-11-13 12:45:04 -080011721 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011722 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011723 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011724 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011725
Sachin Ahujadddd2632017-03-07 19:07:24 +053011726 ret = wlan_hdd_state_ctrl_param_create();
11727 if (ret) {
11728 pr_err("wlan_hdd_state_create:%x\n", ret);
11729 goto err_dev_state;
11730 }
11731
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011732 pld_init();
11733
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011734 ret = hdd_init();
11735 if (ret) {
11736 pr_err("hdd_init failed %x\n", ret);
11737 goto err_hdd_init;
11738 }
11739
Rajeev Kumar97767a02016-11-30 11:20:40 -080011740 dispatcher_init();
11741
Mukul Sharmad75a6672017-06-22 15:40:53 +053011742 /* Ensure to call post objmgr init */
11743 component_init();
11744
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011745 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011746
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011747 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011748
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011749 ret = wlan_hdd_register_driver();
11750 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011751 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11752 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011753 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011754 }
11755
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011756 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011757
11758 return 0;
11759out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011760 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011761 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011762 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011763 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011764
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011765err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011766 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011767 wlan_hdd_state_ctrl_param_destroy();
11768err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011769 return ret;
11770}
11771
11772/**
11773 * __hdd_module_exit - Module exit helper
11774 *
11775 * Module exit helper function used by both module and static driver.
11776 */
11777static void __hdd_module_exit(void)
11778{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011779
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011780 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11781 QWLAN_VERSIONSTR);
11782
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011783 hdd_wait_for_recovery_completion();
11784
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011785 wlan_hdd_unregister_driver();
11786
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011787 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011788
Mukul Sharmad75a6672017-06-22 15:40:53 +053011789 /* Ensure to call prior to objmgr deinit */
11790 component_deinit();
11791
Rajeev Kumar97767a02016-11-30 11:20:40 -080011792 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011793
11794 hdd_sysfs_destroy_version_interface();
11795
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011796 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011797 pld_deinit();
11798
Sachin Ahujadddd2632017-03-07 19:07:24 +053011799 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011800}
11801
Arun Khandavallifae92942016-08-01 13:31:08 +053011802#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011803/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011804 * wlan_boot_cb() - Wlan boot callback
11805 * @kobj: object whose directory we're creating the link in.
11806 * @attr: attribute the user is interacting with
11807 * @buff: the buffer containing the user data
11808 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011809 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011810 * This callback is invoked when the fs is ready to start the
11811 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011812 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011813 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011814 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011815static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011816 struct kobj_attribute *attr,
11817 const char *buf,
11818 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011819{
Arun Khandavallifae92942016-08-01 13:31:08 +053011820
Arun Khandavallifae92942016-08-01 13:31:08 +053011821 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011822 pr_err("%s: wlan driver already initialized\n", __func__);
11823 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011824 }
11825
Arun Khandavallifae92942016-08-01 13:31:08 +053011826 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011827 pr_err("%s: wlan driver initialization failed\n", __func__);
11828 return -EIO;
11829 }
11830
11831 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011832
11833 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011834}
Arun Khandavallifae92942016-08-01 13:31:08 +053011835
11836/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011837 * hdd_sysfs_cleanup() - cleanup sysfs
11838 *
11839 * Return: None
11840 *
11841 */
11842static void hdd_sysfs_cleanup(void)
11843{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011844 /* remove from group */
11845 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11846 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11847 wlan_loader->attr_group);
11848
11849 /* unlink the object from parent */
11850 kobject_del(wlan_loader->boot_wlan_obj);
11851
11852 /* free the object */
11853 kobject_put(wlan_loader->boot_wlan_obj);
11854
11855 kfree(wlan_loader->attr_group);
11856 kfree(wlan_loader);
11857
11858 wlan_loader = NULL;
11859}
11860
11861/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011862 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11863 * ready
11864 *
11865 * This is creates the syfs entry boot_wlan. Which shall be invoked
11866 * when the filesystem is ready.
11867 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011868 * QDF API cannot be used here since this function is called even before
11869 * initializing WLAN driver.
11870 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011871 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011872 */
11873static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011874{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011875 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011876
11877 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011878 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011879 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011880
11881 wlan_loader->boot_wlan_obj = NULL;
11882 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11883 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011884 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011885 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011886
11887 wlan_loader->loaded_state = 0;
11888 wlan_loader->attr_group->attrs = attrs;
11889
11890 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11891 kernel_kobj);
11892 if (!wlan_loader->boot_wlan_obj) {
11893 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011894 goto error_return;
11895 }
11896
11897 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11898 wlan_loader->attr_group);
11899 if (ret) {
11900 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11901 goto error_return;
11902 }
11903
11904 return 0;
11905
11906error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011907 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011908
11909 return ret;
11910}
11911
11912/**
11913 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11914 *
11915 * Return: 0 on success or errno on failure
11916 */
11917static int wlan_deinit_sysfs(void)
11918{
Arun Khandavallifae92942016-08-01 13:31:08 +053011919 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011920 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011921 return -EINVAL;
11922 }
11923
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011924 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011925 return 0;
11926}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011927
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011928#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011929
11930#ifdef MODULE
11931/**
11932 * __hdd_module_init - Module init helper
11933 *
11934 * Module init helper function used by both module and static driver.
11935 *
11936 * Return: 0 for success, errno on failure
11937 */
11938static int hdd_module_init(void)
11939{
Arun Khandavallifae92942016-08-01 13:31:08 +053011940 if (__hdd_module_init()) {
11941 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011942 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011943 }
11944
Dustin Brownab482ac2017-06-09 17:00:44 -070011945 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011946}
11947#else
11948static int __init hdd_module_init(void)
11949{
11950 int ret = -EINVAL;
11951
11952 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011953 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011954 pr_err("Failed to create sysfs entry for loading wlan");
11955
11956 return ret;
11957}
11958#endif
11959
11960
11961#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011962/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011963 * hdd_module_exit() - Exit function
11964 *
11965 * This is the driver exit point (invoked when module is unloaded using rmmod)
11966 *
11967 * Return: None
11968 */
11969static void __exit hdd_module_exit(void)
11970{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011971 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011972}
Arun Khandavallifae92942016-08-01 13:31:08 +053011973#else
11974static void __exit hdd_module_exit(void)
11975{
11976 __hdd_module_exit();
11977 wlan_deinit_sysfs();
11978}
11979#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011980
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011981static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11982{
11983 return param_set_copystring(kmessage, kp);
11984}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011985
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011986/**
11987 * is_con_mode_valid() check con mode is valid or not
11988 * @mode: global con mode
11989 *
11990 * Return: TRUE on success FALSE on failure
11991 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080011992static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011993{
11994 switch (mode) {
11995 case QDF_GLOBAL_MONITOR_MODE:
11996 case QDF_GLOBAL_FTM_MODE:
11997 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011998 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011999 return true;
12000 default:
12001 return false;
12002 }
12003}
12004
12005/**
12006 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12007 * @mode: global con mode
12008 *
12009 * Return: adapter mode
12010 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012011static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012012 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012013{
12014
12015 switch (mode) {
12016 case QDF_GLOBAL_MISSION_MODE:
12017 return QDF_STA_MODE;
12018 case QDF_GLOBAL_MONITOR_MODE:
12019 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012020 case QDF_GLOBAL_EPPING_MODE:
12021 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012022 case QDF_GLOBAL_FTM_MODE:
12023 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012024 case QDF_GLOBAL_QVIT_MODE:
12025 return QDF_QVIT_MODE;
12026 default:
12027 return QDF_MAX_NO_OF_MODE;
12028 }
12029}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012030
Dustin Brown27cd9942017-09-27 16:11:44 -070012031static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012032 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012033{
12034 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12035 return;
12036
12037 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012038 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012039 hdd_info("Release wakelock for monitor mode!");
12040 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12041 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12042 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012043 case QDF_GLOBAL_FTM_MODE:
12044 hdd_abort_mac_scan_all_adapters(hdd_ctx);
12045 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012046 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012047
Dustin Brown27cd9942017-09-27 16:11:44 -070012048 break;
12049 default:
12050 break;
12051 }
12052}
12053
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012054static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012055 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012056{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012057 int driver_status;
12058
12059 driver_status = hdd_ctx->driver_status;
12060
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012061 switch (curr_mode) {
12062 case QDF_GLOBAL_MISSION_MODE:
12063 case QDF_GLOBAL_MONITOR_MODE:
12064 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012065 hdd_deinit_all_adapters(hdd_ctx, false);
12066 hdd_close_all_adapters(hdd_ctx, false);
12067 break;
12068 case QDF_GLOBAL_EPPING_MODE:
12069 epping_disable();
12070 epping_close();
12071 break;
12072 default:
12073 return;
12074 }
12075}
12076
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012077static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012078 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012079{
Jeff Johnson9d295242017-08-29 14:39:48 -070012080 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012081 int ret = 0;
12082 bool rtnl_held;
12083 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12084 QDF_STATUS status;
12085
12086 if (!qdf_dev) {
12087 hdd_err("qdf device context is Null return!");
12088 return -EINVAL;
12089 }
12090
12091 rtnl_held = hdd_hold_rtnl_lock();
12092 switch (mode) {
12093 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012094 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12095 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012096 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012097 break;
12098 case QDF_GLOBAL_FTM_MODE:
12099 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12100 wlan_hdd_get_intf_addr(hdd_ctx),
12101 NET_NAME_UNKNOWN, rtnl_held);
12102 if (adapter == NULL)
12103 ret = -EINVAL;
12104 break;
12105 case QDF_GLOBAL_MONITOR_MODE:
12106 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12107 wlan_hdd_get_intf_addr(hdd_ctx),
12108 NET_NAME_UNKNOWN, rtnl_held);
12109 if (adapter == NULL)
12110 ret = -EINVAL;
12111 break;
12112 case QDF_GLOBAL_EPPING_MODE:
12113 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012114 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012115 hdd_err("Failed to open in eeping mode: %d", status);
12116 ret = -EINVAL;
12117 break;
12118 }
12119 ret = epping_enable(qdf_dev->dev);
12120 if (ret) {
12121 hdd_err("Failed to enable in epping mode : %d", ret);
12122 epping_close();
12123 }
12124 break;
12125 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012126 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012127 ret = -ENOTSUPP;
12128 break;
12129 }
12130 hdd_release_rtnl_lock();
12131 rtnl_held = false;
12132 return ret;
12133}
12134
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012135/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012136 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012137 * @kmessage: con mode name on which driver to be bring up
12138 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012139 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012140 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012141 * This function is invoked when user updates con mode using sys entry,
12142 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012143 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012144 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012145 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012146static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012147 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012148{
12149 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012150 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012151 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012152 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012153 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012154
Dustin Brownab6029b2017-05-24 13:04:19 -070012155 hdd_info("con_mode handler: %s", kmessage);
12156
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012157 ret = wlan_hdd_validate_context(hdd_ctx);
12158 if (ret)
12159 return ret;
12160
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012161 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012162
Dustin Brown20024e32018-01-03 12:34:58 -080012163 ret = kstrtoint(kmessage, 0, &new_con_mode);
12164 if (ret) {
12165 hdd_err("Failed to parse con_mode '%s'", kmessage);
12166 goto reset_flags;
12167 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012168
Dustin Brown20024e32018-01-03 12:34:58 -080012169 if (!is_con_mode_valid(new_con_mode)) {
12170 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012171 ret = -EINVAL;
12172 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012173 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012174
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012175 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012176 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012177 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012178 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012179 ret = 0;
12180 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012181 }
12182
Sourav Mohapatra3bc5e982017-11-24 15:53:49 +053012183 if (!cds_wait_for_external_threads_completion(__func__))
12184 hdd_warn("Waiting for monitor mode: External threads are active");
12185
Dustin Brown27cd9942017-09-27 16:11:44 -070012186 /* ensure adapters are stopped */
12187 hdd_stop_present_mode(hdd_ctx, curr_mode);
12188
Frank Liu6666f832018-01-04 10:06:05 +080012189 /* Cleanup present mode before switching to new mode */
12190 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12191
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012192 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012193 if (ret) {
12194 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012195 goto reset_flags;
12196 }
12197
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012198
Dustin Brown20024e32018-01-03 12:34:58 -080012199 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012200
Frank Liu6666f832018-01-04 10:06:05 +080012201 /*
12202 * Set ACTIVE domain before adapters created, otherwise check domain
12203 * match will fail when cleanup adapters.
12204 */
12205 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012206 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012207 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012208 if (ret) {
12209 hdd_err("Failed to register for new mode");
12210 goto reset_flags;
12211 }
12212
Dustin Brown20024e32018-01-03 12:34:58 -080012213 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012214 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12215 hdd_err("invalid adapter");
12216 ret = -EINVAL;
12217 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012218 }
12219
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012220 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012221 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012222 hdd_err("Failed to get adapter:%d", adapter_mode);
12223 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012224 }
12225
12226 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12227 if (ret) {
12228 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012229 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012230 }
12231
Dustin Brown20024e32018-01-03 12:34:58 -080012232 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012233 if (hdd_start_adapter(adapter)) {
12234 hdd_err("Failed to start %s adapter", kmessage);
12235 ret = -EINVAL;
12236 goto reset_flags;
12237 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012238
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012239 hdd_info("Acquire wakelock for monitor mode!");
12240 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12241 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12242 }
12243
Dustin Brown20024e32018-01-03 12:34:58 -080012244 /* con_mode is a global module parameter */
12245 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012246 hdd_info("Mode successfully changed to %s", kmessage);
12247 ret = 0;
12248
12249reset_flags:
12250 cds_set_load_in_progress(false);
Dustin Brown20024e32018-01-03 12:34:58 -080012251
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012252 return ret;
12253}
12254
12255
12256static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12257{
12258 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012259 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012260
12261 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12262 ret = wlan_hdd_validate_context(hdd_ctx);
12263 if (ret)
12264 return ret;
12265
12266 cds_ssr_protect(__func__);
12267 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12268 cds_ssr_unprotect(__func__);
12269
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012270 return ret;
12271}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012272
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012273static int con_mode_handler_ftm(const char *kmessage,
12274 struct kernel_param *kp)
12275{
12276 int ret;
12277
12278 ret = param_set_int(kmessage, kp);
12279
12280 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12281 pr_err("Only FTM mode supported!");
12282 return -ENOTSUPP;
12283 }
12284
12285 hdd_set_conparam(con_mode_ftm);
12286 con_mode = con_mode_ftm;
12287
12288 return ret;
12289}
12290
Ravi Joshia307f632017-07-17 23:41:41 -070012291static int con_mode_handler_monitor(const char *kmessage,
12292 struct kernel_param *kp)
12293{
12294 int ret;
12295
12296 ret = param_set_int(kmessage, kp);
12297
12298 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12299 pr_err("Only Monitor mode supported!");
12300 return -ENOTSUPP;
12301 }
12302
12303 hdd_set_conparam(con_mode_monitor);
12304 con_mode = con_mode_monitor;
12305
12306 return ret;
12307}
12308
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012309/**
12310 * hdd_get_conparam() - driver exit point
12311 *
12312 * This is the driver exit point (invoked when module is unloaded using rmmod)
12313 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012314 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012315 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012316enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012317{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012318 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012319}
12320
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012321void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012322{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012323 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012324}
12325
Komal Seelamc11bb222016-01-27 18:57:10 +053012326/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012327 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12328 * @hdd_ctx: HDD context
12329 *
12330 * Cleans up the pre cac interface, if it exists
12331 *
12332 * Return: None
12333 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012334void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012335{
12336 uint8_t session_id;
12337 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012338 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012339
12340 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12341 if (QDF_IS_STATUS_ERROR(status)) {
12342 hdd_err("failed to get pre cac vdev id");
12343 return;
12344 }
12345
12346 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12347 if (!precac_adapter) {
12348 hdd_err("invalid pre cac adapater");
12349 return;
12350 }
12351
12352 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12353 wlan_hdd_sap_pre_cac_failure,
12354 (void *)precac_adapter);
12355 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12356
12357}
12358
12359/**
Komal Seelamec702b02016-02-24 18:42:16 +053012360 * hdd_update_ol_config - API to update ol configuration parameters
12361 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012362 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012363 * Return: void
12364 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012365static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012366{
Komal Seelamec702b02016-02-24 18:42:16 +053012367 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012368 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012369
Komal Seelamec702b02016-02-24 18:42:16 +053012370 if (!ol_ctx)
12371 return;
12372
12373 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12374 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12375 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12376 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012377 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012378
12379 ol_init_ini_config(ol_ctx, &cfg);
12380}
12381
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012382#ifdef FEATURE_RUNTIME_PM
12383/**
12384 * hdd_populate_runtime_cfg() - populate runtime configuration
12385 * @hdd_ctx: hdd context
12386 * @cfg: pointer to the configuration memory being populated
12387 *
12388 * Return: void
12389 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012390static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012391 struct hif_config_info *cfg)
12392{
12393 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12394 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12395}
12396#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012397static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012398 struct hif_config_info *cfg)
12399{
12400}
12401#endif
12402
Komal Seelamec702b02016-02-24 18:42:16 +053012403/**
12404 * hdd_update_hif_config - API to update HIF configuration parameters
12405 * @hdd_ctx: HDD Context
12406 *
12407 * Return: void
12408 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012409static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012410{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012411 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012412 struct hif_config_info cfg;
12413
12414 if (!scn)
12415 return;
12416
12417 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012418 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012419 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012420
12421 if (hdd_ctx->config->prevent_link_down)
12422 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012423}
12424
12425/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012426 * hdd_update_dp_config() - Propagate config parameters to Lithium
12427 * datapath
12428 * @hdd_ctx: HDD Context
12429 *
12430 * Return: 0 for success/errno for failure
12431 */
12432static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12433{
12434 struct cdp_config_params params;
12435 QDF_STATUS status;
12436
12437 params.tso_enable = hdd_ctx->config->tso_enable;
12438 params.lro_enable = hdd_ctx->config->lro_enable;
12439#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12440 params.tx_flow_stop_queue_threshold =
12441 hdd_ctx->config->TxFlowStopQueueThreshold;
12442 params.tx_flow_start_queue_offset =
12443 hdd_ctx->config->TxFlowStartQueueOffset;
12444#endif
12445 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12446 params.napi_enable = hdd_ctx->napi_enable;
12447 params.tcp_udp_checksumoffload =
12448 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12449
12450 status = cdp_update_config_parameters(
12451 cds_get_context(QDF_MODULE_ID_SOC),
12452 &params);
12453 if (status) {
12454 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12455 "%s: Failed to attach config parameters", __func__);
12456 return status;
12457 }
12458
12459 return 0;
12460}
12461
12462/**
Komal Seelamec702b02016-02-24 18:42:16 +053012463 * hdd_update_config() - Initialize driver per module ini parameters
12464 * @hdd_ctx: HDD Context
12465 *
12466 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012467 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012468 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012469int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012470{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012471 int ret;
12472
Komal Seelamec702b02016-02-24 18:42:16 +053012473 hdd_update_ol_config(hdd_ctx);
12474 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012475 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12476 ret = hdd_update_cds_config_ftm(hdd_ctx);
12477 else
12478 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012479 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012480
12481 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012482}
12483
Mukul Sharma9d797a02017-01-05 20:26:03 +053012484#ifdef FEATURE_WLAN_RA_FILTERING
12485/**
12486 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12487 * @psoc_cfg: pmo psoc Configuration
12488 * @hdd_ctx: Pointer to hdd context
12489 *
12490 * Return: none
12491 */
12492static inline void hdd_ra_populate_pmo_config(
12493 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012494 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012495{
12496 psoc_cfg->ra_ratelimit_interval =
12497 hdd_ctx->config->RArateLimitInterval;
12498 psoc_cfg->ra_ratelimit_enable =
12499 hdd_ctx->config->IsRArateLimitEnabled;
12500}
12501#else
12502static inline void hdd_ra_populate_pmo_config(
12503 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012504 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012505{
12506}
12507#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012508
Mukul Sharma9d797a02017-01-05 20:26:03 +053012509/**
12510 * hdd_update_pmo_config - API to update pmo configuration parameters
12511 * @hdd_ctx: HDD context
12512 *
12513 * Return: void
12514 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012515static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012516{
12517 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12518 struct pmo_psoc_cfg psoc_cfg;
12519 QDF_STATUS status;
12520
12521 /*
12522 * Value of hdd_ctx->wowEnable can be,
12523 * 0 - Disable both magic pattern match and pattern byte match.
12524 * 1 - Enable magic pattern match on all interfaces.
12525 * 2 - Enable pattern byte match on all interfaces.
12526 * 3 - Enable both magic patter and pattern byte match on
12527 * all interfaces.
12528 */
12529 psoc_cfg.magic_ptrn_enable =
12530 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12531 psoc_cfg.ptrn_match_enable_all_vdev =
12532 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012533 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12534 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012535 psoc_cfg.bpf_enable =
12536 hdd_ctx->config->bpf_packet_filter_enable;
12537 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012538 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012539 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12540 if (hdd_ctx->config->fhostNSOffload)
12541 psoc_cfg.ns_offload_enable_dynamic = true;
12542 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12543 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12544 psoc_cfg.active_mode_offload =
12545 hdd_ctx->config->active_mode_offload;
12546 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012547 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012548 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012549 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12550 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12551 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12552 psoc_cfg.power_save_mode =
12553 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012554 psoc_cfg.auto_power_save_fail_mode =
12555 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012556
12557 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012558 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12559 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012560 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012561 if (status != QDF_STATUS_SUCCESS) {
12562 hdd_err("failed pmo psoc configuration");
12563 return -EINVAL;
12564 }
12565
12566 return 0;
12567}
12568
Abhishek Singhb20db962017-03-03 21:28:46 +053012569#ifdef FEATURE_WLAN_SCAN_PNO
12570static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12571 struct hdd_config *cfg)
12572{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012573 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12574
Abhishek Singhb20db962017-03-03 21:28:46 +053012575 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12576 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12577 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12578 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12579 pno_cfg->channel_prediction_full_scan =
12580 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012581 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12582 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12583 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12584 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012585}
12586#else
12587static inline void
12588hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012589 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012590{
Abhishek Singhb20db962017-03-03 21:28:46 +053012591}
12592#endif
12593
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012594void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12595 struct hdd_config *cfg)
12596{
12597 uint8_t i = 0;
12598
12599 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12600 if (!ie_whitelist->white_list)
12601 return;
12602
12603 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12604 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12605 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12606 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12607 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12608 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12609 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12610 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12611
12612 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12613 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12614 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12615}
12616
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012617uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12618{
12619 uint8_t i, score;
12620
12621 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12622 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12623 if (score > MAX_INDEX_SCORE)
12624 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12625 MAX_INDEX_SCORE, i);
12626 }
12627
12628 return per_index_score;
12629}
12630
12631/**
12632 * hdd_update_score_config - API to update candidate scoring related params
12633 * configuration parameters
12634 * @score_config: score config to update
12635 * @cfg: config params
12636 *
12637 * Return: 0 if success else err
12638 */
12639static void hdd_update_score_config(
12640 struct scoring_config *score_config, struct hdd_config *cfg)
12641{
12642 int total_weight;
12643
12644 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12645 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12646 score_config->weight_cfg.vht_caps_weightage =
12647 cfg->vht_caps_weightage;
12648 score_config->weight_cfg.he_caps_weightage =
12649 cfg->he_caps_weightage;
12650 score_config->weight_cfg.chan_width_weightage =
12651 cfg->chan_width_weightage;
12652 score_config->weight_cfg.chan_band_weightage =
12653 cfg->chan_band_weightage;
12654 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12655 score_config->weight_cfg.beamforming_cap_weightage =
12656 cfg->beamforming_cap_weightage;
12657 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12658 score_config->weight_cfg.channel_congestion_weightage =
12659 cfg->channel_congestion_weightage;
12660 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12661
12662 total_weight = score_config->weight_cfg.rssi_weightage +
12663 score_config->weight_cfg.ht_caps_weightage +
12664 score_config->weight_cfg.vht_caps_weightage +
12665 score_config->weight_cfg.he_caps_weightage +
12666 score_config->weight_cfg.chan_width_weightage +
12667 score_config->weight_cfg.chan_band_weightage +
12668 score_config->weight_cfg.nss_weightage +
12669 score_config->weight_cfg.beamforming_cap_weightage +
12670 score_config->weight_cfg.pcl_weightage +
12671 score_config->weight_cfg.channel_congestion_weightage +
12672 score_config->weight_cfg.oce_wan_weightage;
12673
12674 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12675 hdd_err("total weight is greater than %d fallback to default values",
12676 BEST_CANDIDATE_MAX_WEIGHT);
12677
12678 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12679 score_config->weight_cfg.ht_caps_weightage =
12680 HT_CAPABILITY_WEIGHTAGE;
12681 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12682 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12683 score_config->weight_cfg.chan_width_weightage =
12684 CHAN_WIDTH_WEIGHTAGE;
12685 score_config->weight_cfg.chan_band_weightage =
12686 CHAN_BAND_WEIGHTAGE;
12687 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12688 score_config->weight_cfg.beamforming_cap_weightage =
12689 BEAMFORMING_CAP_WEIGHTAGE;
12690 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12691 score_config->weight_cfg.channel_congestion_weightage =
12692 CHANNEL_CONGESTION_WEIGHTAGE;
12693 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12694 }
12695
12696 score_config->bandwidth_weight_per_index =
12697 hdd_limit_max_per_index_score(
12698 cfg->bandwidth_weight_per_index);
12699 score_config->nss_weight_per_index =
12700 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12701 score_config->band_weight_per_index =
12702 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12703
12704 score_config->rssi_score.best_rssi_threshold =
12705 cfg->best_rssi_threshold;
12706 score_config->rssi_score.good_rssi_threshold =
12707 cfg->good_rssi_threshold;
12708 score_config->rssi_score.bad_rssi_threshold =
12709 cfg->bad_rssi_threshold;
12710 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12711 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12712 score_config->rssi_score.good_rssi_bucket_size =
12713 cfg->good_rssi_bucket_size;
12714 score_config->rssi_score.bad_rssi_bucket_size =
12715 cfg->bad_rssi_bucket_size;
12716 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12717 cfg->rssi_pref_5g_rssi_thresh;
12718
12719 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12720 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12721 hdd_limit_max_per_index_score(
12722 cfg->esp_qbss_score_slots3_to_0);
12723 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12724 hdd_limit_max_per_index_score(
12725 cfg->esp_qbss_score_slots7_to_4);
12726 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12727 hdd_limit_max_per_index_score(
12728 cfg->esp_qbss_score_slots11_to_8);
12729 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12730 hdd_limit_max_per_index_score(
12731 cfg->esp_qbss_score_slots15_to_12);
12732
12733 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12734 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12735 hdd_limit_max_per_index_score(
12736 cfg->oce_wan_score_slots3_to_0);
12737 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12738 hdd_limit_max_per_index_score(
12739 cfg->oce_wan_score_slots7_to_4);
12740 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12741 hdd_limit_max_per_index_score(
12742 cfg->oce_wan_score_slots11_to_8);
12743 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12744 hdd_limit_max_per_index_score(
12745 cfg->oce_wan_score_slots15_to_12);
12746
12747
12748 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12749 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12750 score_config->nss = cfg->enable2x2 ? 2 : 1;
12751
12752 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12753 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12754 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12755 score_config->he_cap = 1;
12756
12757 if (score_config->he_cap ||
12758 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12759 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12760 score_config->vht_cap = 1;
12761
12762 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12763 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12764 score_config->ht_cap = 1;
12765
12766 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12767 score_config->vht_24G_cap = 1;
12768
12769 if (cfg->enableTxBF)
12770 score_config->beamformee_cap = 1;
12771
12772}
12773
Abhishek Singh257a9482017-03-06 16:52:39 +053012774/**
12775 * hdd_update_scan_config - API to update scan configuration parameters
12776 * @hdd_ctx: HDD context
12777 *
12778 * Return: 0 if success else err
12779 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012780static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012781{
12782 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12783 struct scan_user_cfg scan_cfg;
12784 struct hdd_config *cfg = hdd_ctx->config;
12785 QDF_STATUS status;
12786
12787 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12788 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12789 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12790 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12791 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12792 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12793 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012794 /* convert to ms */
12795 scan_cfg.scan_cache_aging_time =
12796 cfg->scanAgingTimeout * 1000;
12797 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12798 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12799 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12800 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012801 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012802 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012803 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12804 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012805 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012806 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012807
Abhishek Singhb20db962017-03-03 21:28:46 +053012808 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012809 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012810 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012811
Abhishek Singh257a9482017-03-06 16:52:39 +053012812 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12813 if (status != QDF_STATUS_SUCCESS) {
12814 hdd_err("failed pmo psoc configuration");
12815 return -EINVAL;
12816 }
12817
12818 return 0;
12819}
Abhishek Singh257a9482017-03-06 16:52:39 +053012820
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012821int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012822{
12823 int ret;
12824
12825 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012826 if (ret)
12827 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012828
Abhishek Singh257a9482017-03-06 16:52:39 +053012829 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012830 if (ret)
12831 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012832
Frank Liud4b2fa02017-03-29 11:46:48 +080012833 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012834 if (ret)
12835 return ret;
12836
12837 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012838
12839 return ret;
12840}
12841
Agrawal Ashish65634612016-08-18 13:24:32 +053012842/**
12843 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12844 * @mode : cfg80211 DFS mode
12845 *
12846 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12847 */
12848enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12849{
12850 switch (mode) {
12851 case DFS_MODE_ENABLE:
12852 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012853 case DFS_MODE_DISABLE:
12854 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012855 case DFS_MODE_DEPRIORITIZE:
12856 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012857 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012858 hdd_debug("ACS dfs mode is NONE");
12859 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012860 }
12861}
12862
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012863/**
12864 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12865 * @hddctx: pointer to hdd context
12866 * @set_value: enable/disable
12867 *
12868 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12869 * Host(even though it is duplicate). When Host send vendor command
12870 * disable,FW doesn't perform any action. Whenever any change in
12871 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12872 *
12873 * return - 0 on success, appropriate error values on failure.
12874 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012875int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012876{
12877 QDF_STATUS status;
12878
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012879 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012880 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012881
12882 if (!hddctx->config->goptimize_chan_avoid_event) {
12883 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12884 return -EINVAL;
12885 }
12886
12887 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12888 if (!QDF_IS_STATUS_SUCCESS(status)) {
12889 hdd_err("Failed to send chan avoid command to SME");
12890 return -EINVAL;
12891 }
12892 return 0;
12893}
Agrawal Ashish65634612016-08-18 13:24:32 +053012894
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012895/**
12896 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12897 * @value: value to set
12898 *
12899 * This function will set the passed value to roaming in progress flag.
12900 *
12901 * Return: None
12902 */
12903void hdd_set_roaming_in_progress(bool value)
12904{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012905 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012906
12907 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12908 if (!hdd_ctx) {
12909 hdd_err("HDD context is NULL");
12910 return;
12911 }
12912
12913 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012914 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012915}
12916
12917/**
12918 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012919 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012920 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012921 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012922 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012923bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012924{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012925 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012926 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012927
12928 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12929 if (!hdd_ctx) {
12930 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012931 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012932 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012933 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12934 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012935 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12936 hdd_ctx->roaming_in_progress);
12937
12938 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012939}
12940
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012941/**
12942 * hdd_is_connection_in_progress() - check if connection is in
12943 * progress
12944 * @session_id: session id
12945 * @reason: scan reject reason
12946 *
12947 * Go through each adapter and check if Connection is in progress
12948 *
12949 * Return: true if connection is in progress else false
12950 */
12951bool hdd_is_connection_in_progress(uint8_t *session_id,
12952 enum scan_reject_states *reason)
12953{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012954 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012955 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012956 uint8_t sta_id = 0;
12957 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012958 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012959
12960 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12961 if (!hdd_ctx) {
12962 hdd_err("HDD context is NULL");
12963 return false;
12964 }
12965
Dustin Brown920397d2017-12-13 16:27:50 -080012966 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012967 hdd_info("Adapter with device mode %s(%d) exists",
12968 hdd_device_mode_to_string(adapter->device_mode),
12969 adapter->device_mode);
12970 if (((QDF_STA_MODE == adapter->device_mode)
12971 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12972 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12973 && (eConnectionState_Connecting ==
12974 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12975 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012976 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012977 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012978 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012979 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012980 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012981 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012982 }
12983 return true;
12984 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012985 /*
12986 * sme_neighbor_middle_of_roaming is for LFR2
12987 * hdd_is_roaming_in_progress is for LFR3
12988 */
12989 if (((QDF_STA_MODE == adapter->device_mode) &&
12990 sme_neighbor_middle_of_roaming(
12991 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012992 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012993 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012994 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012995 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012996 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012997 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012998 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012999 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013000 }
13001 return true;
13002 }
13003 if ((QDF_STA_MODE == adapter->device_mode) ||
13004 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13005 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13006 hdd_sta_ctx =
13007 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13008 if ((eConnectionState_Associated ==
13009 hdd_sta_ctx->conn_info.connState)
13010 && (false ==
13011 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
13012 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013013 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013014 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013015 " is in middle of WPS/EAPOL exchange.",
13016 MAC_ADDR_ARRAY(sta_mac));
13017 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013018 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013019 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013020 }
13021 return true;
13022 }
13023 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13024 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13025 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13026 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013027 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013028 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013029 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013030 continue;
13031
13032 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013033 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013034 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013035 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013036 " of SAP/GO is in middle of WPS/EAPOL exchange",
13037 MAC_ADDR_ARRAY(sta_mac));
13038 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013039 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013040 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013041 }
13042 return true;
13043 }
13044 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013045 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013046 return true;
13047 }
13048 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013049 }
Dustin Brown920397d2017-12-13 16:27:50 -080013050
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013051 return false;
13052}
13053
13054/**
13055 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013056 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013057 *
13058 * Return: None
13059 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013060void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013061{
Jeff Johnson87251032017-08-29 13:31:11 -070013062 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013063 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013064 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013065 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013066 tsap_Config_t *sap_config;
13067 void *sap_ctx;
13068
13069 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013070 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013071 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013072
13073 mutex_lock(&hdd_ctx->sap_lock);
13074 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13075 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013076 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13077 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13078 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13079 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013080 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013081 qdf_stop_bss_event,
13082 SME_CMD_TIMEOUT_VALUE);
13083
13084 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013085 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013086 goto end;
13087 }
13088 }
13089 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013090 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013091 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013092 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013093
13094 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013095 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013096 wlansap_reset_sap_config_add_ie(sap_config,
13097 eUPDATE_IE_ALL);
13098 goto end;
13099 }
13100
13101 qdf_event_reset(&hostapd_state->qdf_event);
13102 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13103 sap_config,
13104 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013105 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013106 wlansap_reset_sap_config_add_ie(sap_config,
13107 eUPDATE_IE_ALL);
13108 goto end;
13109 }
13110
Jeff Johnson6867ec32017-09-29 20:30:20 -070013111 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013112 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013113 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013114 SME_CMD_TIMEOUT_VALUE);
13115 wlansap_reset_sap_config_add_ie(sap_config,
13116 eUPDATE_IE_ALL);
13117 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013118 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013119 goto end;
13120 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013121 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013122 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070013123 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013124 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13125 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013126 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013127 }
13128end:
13129 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013130}
13131
13132/**
13133 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13134 * with non dfs acs
13135 *
13136 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13137 *
13138 * Return: None
13139 */
13140void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13141{
Jeff Johnson9d295242017-08-29 14:39:48 -070013142 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013143 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013144 cds_context_type *cds_ctx;
13145
13146 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13147 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013148 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013149 return;
13150 }
13151
13152 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13153 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013154 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013155 return;
13156 }
13157
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013158 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13159 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013160 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013161 return;
13162 }
13163
13164 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013165 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13166 &ap_adapter->event_flags) &&
13167 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013168 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013169
Jeff Johnson6867ec32017-09-29 20:30:20 -070013170 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013171 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013172 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013173 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013174 acs_cfg.acs_mode = true;
13175
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013176 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013177 }
13178}
13179
13180/**
13181 * hdd_set_connection_in_progress() - to set the connection in
13182 * progress flag
13183 * @value: value to set
13184 *
13185 * This function will set the passed value to connection in progress flag.
13186 * If value is previously being set to true then no need to set it again.
13187 *
13188 * Return: true if value is being set correctly and false otherwise.
13189 */
13190bool hdd_set_connection_in_progress(bool value)
13191{
13192 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013193 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013194
13195 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13196 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013197 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013198 return false;
13199 }
13200
13201 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13202 /*
13203 * if the value is set to true previously and if someone is
13204 * trying to make it true again then it could be some race
13205 * condition being triggered. Avoid this situation by returning
13206 * false
13207 */
13208 if (hdd_ctx->connection_in_progress && value)
13209 status = false;
13210 else
13211 hdd_ctx->connection_in_progress = value;
13212 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13213 return status;
13214}
13215
Jeff Johnson9d295242017-08-29 14:39:48 -070013216int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013217{
13218 if (!adapter) {
13219 hdd_err("Invalid adapter");
13220 return -EINVAL;
13221 }
13222 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013223 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013224 WMA_VDEV_MCC_SET_TIME_QUOTA,
13225 set_value, VDEV_CMD);
13226 return 0;
13227
13228}
13229
Jeff Johnson9d295242017-08-29 14:39:48 -070013230int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013231{
13232 if (!adapter) {
13233 hdd_err("Invalid adapter");
13234 return -EINVAL;
13235 }
13236
13237 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013238 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013239 WMA_VDEV_MCC_SET_TIME_LATENCY,
13240 set_value, VDEV_CMD);
13241 return 0;
13242}
13243
Jeff Johnson9d295242017-08-29 14:39:48 -070013244struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013245 *psoc, uint8_t vdev_id)
13246{
Jeff Johnson9d295242017-08-29 14:39:48 -070013247 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013248 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013249
13250 /*
13251 * Currently PSOC is not being used. But this logic will
13252 * change once we have the converged implementation of
13253 * HDD context per PSOC in place. This would break if
13254 * multiple vdev objects reuse the vdev id.
13255 */
13256 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13257 if (!adapter)
13258 hdd_err("Get adapter by vdev id failed");
13259
13260 return adapter;
13261}
13262
Jeff Johnson9d295242017-08-29 14:39:48 -070013263int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013264 int8_t *rssi, int8_t *snr)
13265{
13266 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070013267 struct hdd_wext_state *wext_state =
13268 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013269 tCsrRoamProfile *profile = &wext_state->roamProfile;
13270
13271 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
13272 profile, bssid, rssi, snr);
13273 if (QDF_STATUS_SUCCESS != status) {
13274 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13275 return -EINVAL;
13276 }
13277
13278 return 0;
13279}
13280
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013281/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013282 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13283 * @adapter - HDD adapter
13284 * @tos - type of service
13285 * @status - status of the traffic
13286 *
13287 * Return: 0 on success and non zero value on failure
13288 */
13289
13290int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13291 bool is_tos_active)
13292{
13293 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013294 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013295 uint32_t max_off_chan_time = 0;
13296 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013297 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013298 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013299
13300 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13301 ret = wlan_hdd_validate_context(hdd_ctx);
13302
13303 if (ret < 0) {
13304 hdd_err("failed to set limit off chan params");
13305 return ret;
13306 }
13307
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013308 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13309
13310 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013311 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013312 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013313 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013314
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013315 if (adapter->active_ac) {
13316 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013317 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013318 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13319 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13320 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013321 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013322 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013323 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13324 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13325 PM_LATENCY);
13326 } else {
13327 /*ignore this command if only BE/BK is active */
13328 is_tos_active = false;
13329 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13330 hdd_ctx->config->conc_system_pref);
13331 }
13332 } else {
13333 /* No active tos */
13334 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13335 hdd_ctx->config->conc_system_pref);
13336 }
13337
Jeff Johnson1b780e42017-10-31 14:11:45 -070013338 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013339 is_tos_active, max_off_chan_time,
13340 hdd_ctx->config->nRestTimeConc, true);
13341 if (!QDF_IS_STATUS_SUCCESS(status)) {
13342 hdd_err("failed to set limit off chan params");
13343 ret = -EINVAL;
13344 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013345
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013346 return ret;
13347}
13348
13349/**
13350 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13351 * @adapter - HDD adapter
13352 *
13353 * Return: 0 on success and non zero value on failure
13354 */
13355int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13356{
13357 struct hdd_context *hdd_ctx;
13358 int ret;
13359 QDF_STATUS status;
13360 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13361
13362 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13363 ret = wlan_hdd_validate_context(hdd_ctx);
13364 if (ret < 0)
13365 return ret;
13366
13367 /* set the system preferece to default */
13368 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13369 hdd_ctx->config->conc_system_pref);
13370
13371 /* clear the bitmap */
13372 adapter->active_ac = 0;
13373
13374 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013375 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013376
Jeff Johnson1b780e42017-10-31 14:11:45 -070013377 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013378 false, 0, 0, false);
13379 if (!QDF_IS_STATUS_SUCCESS(status)) {
13380 hdd_err("failed to reset limit off chan params");
13381 ret = -EINVAL;
13382 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013383
13384 return ret;
13385}
13386
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013387/**
13388 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13389 * @drv_op: Enum indicating driver op
13390 *
13391 * Return: none
13392 */
13393void hdd_start_driver_ops_timer(int drv_op)
13394{
13395 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13396 switch (drv_op) {
13397 case eHDD_DRV_OP_PROBE:
13398 memcpy(drv_ops_string, "probe", sizeof("probe"));
13399 break;
13400 case eHDD_DRV_OP_REMOVE:
13401 memcpy(drv_ops_string, "remove", sizeof("remove"));
13402 break;
13403 case eHDD_DRV_OP_SHUTDOWN:
13404 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13405 break;
13406 case eHDD_DRV_OP_REINIT:
13407 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13408 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013409 case eHDD_DRV_OP_IFF_UP:
13410 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13411 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013412 }
13413
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013414 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013415 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13416 HDD_OPS_INACTIVITY_TIMEOUT);
13417}
13418
13419/**
13420 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13421 *
13422 * Return: none
13423 */
13424void hdd_stop_driver_ops_timer(void)
13425{
13426 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13427}
13428
13429/**
13430 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13431 * inactivity timer
13432 *
13433 * Return: None
13434 */
13435void hdd_drv_ops_inactivity_handler(void)
13436{
13437 hdd_err("%s: %d Sec timer expired while in .%s",
13438 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13439
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013440 if (hdd_drv_ops_task) {
13441 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13442 qdf_print_thread_trace(hdd_drv_ops_task);
13443 } else {
13444 hdd_err("hdd_drv_ops_task is null");
13445 }
13446
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013447 /* Driver shutdown is stuck, no recovery possible at this point */
13448 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13449 sizeof("shutdown")))
13450 QDF_BUG(0);
13451
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013452 if (cds_is_fw_down()) {
13453 hdd_err("FW is down");
13454 return;
13455 }
13456
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013457 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013458 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013459 else
13460 QDF_BUG(0);
13461}
13462
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013463void hdd_pld_ipa_uc_shutdown_pipes(void)
13464{
13465 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13466
13467 if (!hdd_ctx)
13468 return;
13469
13470 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13471}
13472
Yun Parkff6a16a2017-09-26 16:38:18 -070013473/**
13474 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13475 * @struct hdd_context *hdd_ctx
13476 * @struct hdd_adapter *padapter
13477 * @bool enble
13478 *
13479 * Return: none
13480 */
13481void hdd_set_rx_mode_rps(bool enable)
13482{
13483 struct cds_config_info *cds_cfg = cds_get_ini_config();
13484 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13485 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13486
13487 if (adapter && hdd_ctx &&
13488 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13489 if (enable && !cds_cfg->rps_enabled)
13490 hdd_send_rps_ind(adapter);
13491 else if (!enable && cds_cfg->rps_enabled)
13492 hdd_send_rps_disable_ind(adapter);
13493 }
13494}
13495
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013496/* Register the module init/exit functions */
13497module_init(hdd_module_init);
13498module_exit(hdd_module_exit);
13499
13500MODULE_LICENSE("Dual BSD/GPL");
13501MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13502MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013504module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13505 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013506
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013507module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13508 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13509
Ravi Joshia307f632017-07-17 23:41:41 -070013510module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13511 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13512
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013513module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13514 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13515
13516module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13517
13518module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13519
13520module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);