blob: d0ae4c159850093df1491cc1c16bc0e396ffdd50 [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);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001011 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001012
1013 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1014}
1015
1016/**
1017 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1018 * @hdd_ctx: HDD Context
1019 *
1020 * Return: None
1021 */
1022static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1023{
1024 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1025
Yue Macd359b72017-10-03 15:21:00 -07001026 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001027 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001028
1029 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1030}
1031
Yue Macd359b72017-10-03 15:21:00 -07001032#else /* FEATURE_RUNTIME_PM */
1033static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1034static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001035#endif /* FEATURE_RUNTIME_PM */
1036
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037#define INTF_MACADDR_MASK 0x7
1038
1039/**
1040 * hdd_update_macaddr() - update mac address
1041 * @config: hdd configuration
1042 * @hw_macaddr: mac address
1043 *
1044 * Mac address for multiple virtual interface is found as following
1045 * i) The mac address of the first interface is just the actual hw mac address.
1046 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1047 * define the mac address for the remaining interfaces and locally
1048 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1049 * supported virtual interfaces, right now this is 0x07 (meaning 8
1050 * interface).
1051 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1052 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1053 *
1054 * Return: None
1055 */
1056void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301057 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058{
1059 int8_t i;
1060 uint8_t macaddr_b3, tmp_br3;
1061
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301062 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301063 QDF_MAC_ADDR_SIZE);
1064 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301065 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301066 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1068 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1069 INTF_MACADDR_MASK;
1070 macaddr_b3 += tmp_br3;
1071
1072 /* XOR-ing bit-24 of the mac address. This will give enough
1073 * mac address range before collision
1074 */
1075 macaddr_b3 ^= (1 << 7);
1076
1077 /* Set locally administered bit */
1078 config->intfMacAddr[i].bytes[0] |= 0x02;
1079 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001080 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081 MAC_ADDRESS_STR, i,
1082 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1083 }
1084}
1085
Kabilan Kannan44a58372017-12-06 18:16:11 -08001086static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1087{
1088 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1089 struct tdls_start_params tdls_cfg;
1090 struct tdls_user_config *config = &tdls_cfg.config;
1091 struct hdd_config *cfg = hdd_ctx->config;
1092 QDF_STATUS status;
1093
1094 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1095 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1096 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1097 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1098 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1099 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1100 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1101 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1102 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1103 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1104 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1105 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1106 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1107 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1108 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1109 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1110 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1111 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1112 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1113 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1114 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1115 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1116 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1117 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1118 (cfg->fEnableTDLSImplicitTrigger ?
1119 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1120 (cfg->fTDLSExternalControl ?
1121 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1122 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1123 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1124
1125 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1126 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1127 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1128 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1129 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1130 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1131 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1132 tdls_cfg.tdls_evt_cb_data = psoc;
1133 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
1134 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
1135 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
1136 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1137 tdls_cfg.tdls_wmm_cb_data = psoc;
1138 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1139 tdls_cfg.tdls_rx_cb_data = psoc;
1140 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1141
1142 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1143 if (status != QDF_STATUS_SUCCESS) {
1144 hdd_err("failed pmo psoc configuration");
1145 return -EINVAL;
1146 }
1147
1148 hdd_ctx->tdls_umac_comp_active = true;
1149 /* enable napier specific tdls data path */
1150 hdd_ctx->tdls_nap_active = true;
1151
1152 return 0;
1153}
1154
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001155static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001156 struct wma_tgt_services *cfg)
1157{
1158 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001159
1160 /* Set up UAPSD */
1161 config->apUapsdEnabled &= cfg->uapsd;
1162
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001163 /* 11AX mode support */
1164 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1165 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1166 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1167
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001168 /* 11AC mode support */
1169 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1170 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1171 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172
1173 /* ARP offload: override user setting if invalid */
1174 config->fhostArpOffload &= cfg->arp_offload;
1175
1176#ifdef FEATURE_WLAN_SCAN_PNO
1177 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001178 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001179 if (cfg->pno_offload)
1180 config->PnoOffload = true;
1181#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001182#ifdef FEATURE_WLAN_TDLS
1183 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301184 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1185 cfg->en_tdls_offchan;
1186 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1187 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001188 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001189 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001190 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001191 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1194 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1195#endif
Will Huang496b36c2017-07-11 16:38:50 +08001196 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001197 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001198 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001199 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001200
1201}
1202
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001203/**
1204 * hdd_update_vdev_nss() - sets the vdev nss
1205 * @hdd_ctx: HDD context
1206 *
1207 * Sets the Nss per vdev type based on INI
1208 *
1209 * Return: None
1210 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001211static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001212{
1213 struct hdd_config *cfg_ini = hdd_ctx->config;
1214 uint8_t max_supp_nss = 1;
1215
Naveen Rawat10b1c152017-01-18 11:16:06 -08001216 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001217 max_supp_nss = 2;
1218
1219 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001220 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001221
1222 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001223 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001224}
1225
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301226/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301227 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1228 * @hdd_ctx: HDD context
1229 *
1230 * Updates wiphy vhtcap fields
1231 *
1232 * Return: None
1233 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001234static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301235{
1236 struct ieee80211_supported_band *band_5g =
1237 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1238 uint32_t val;
1239
1240 if (!band_5g) {
1241 hdd_debug("5GHz band disabled, skipping capability population");
1242 return;
1243 }
1244
1245 val = hdd_ctx->config->txBFCsnValue;
1246 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1247
1248 val = NUM_OF_SOUNDING_DIMENSIONS;
1249 band_5g->vht_cap.cap |=
1250 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1251
1252 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1253 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1254}
1255
1256/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301257 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1258 * @hdd_ctx: HDD context
1259 *
1260 * Sets the DBS capability as per INI and firmware capability
1261 *
1262 * Return: None
1263 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001264static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301265{
1266 struct hdd_config *cfg_ini = hdd_ctx->config;
1267 uint8_t hw_dbs_capable = 0;
1268
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001269 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1270 ((cfg_ini->dual_mac_feature_disable ==
1271 ENABLE_DBS_CXN_AND_SCAN) ||
1272 (cfg_ini->dual_mac_feature_disable ==
1273 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301274 hw_dbs_capable = 1;
1275
1276 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1277}
1278
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001279static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001280 struct wma_tgt_ht_cap *cfg)
1281{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301282 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001283 uint32_t value, val32;
1284 uint16_t val16;
1285 struct hdd_config *pconfig = hdd_ctx->config;
1286 tSirMacHTCapabilityInfo *phtCapInfo;
1287 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1288 uint8_t enable_tx_stbc;
1289
1290 /* check and update RX STBC */
1291 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1292 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1293
1294 /* get the MPDU density */
1295 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1296
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301297 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001298 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 value = 0;
1300 }
1301
1302 /*
1303 * MPDU density:
1304 * override user's setting if value is larger
1305 * than the one supported by target
1306 */
1307 if (value > cfg->mpdu_density) {
1308 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1309 cfg->mpdu_density);
1310
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301311 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001312 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313 }
1314
1315 /* get the HT capability info */
1316 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301317 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001318 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319 return;
1320 }
1321 val16 = (uint16_t) val32;
1322 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1323
1324 /* Set the LDPC capability */
1325 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1326
1327 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1328 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1329
1330 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1331 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1332
1333 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1334 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1335
1336 enable_tx_stbc = pconfig->enableTxSTBC;
1337
1338 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1339 pconfig->enable2x2 = 1;
1340 } else {
1341 pconfig->enable2x2 = 0;
1342 enable_tx_stbc = 0;
1343
1344 /* 1x1 */
1345 /* Update Rx Highest Long GI data Rate */
1346 if (sme_cfg_set_int(hdd_ctx->hHal,
1347 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001348 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301349 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001350 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 }
1352
1353 /* Update Tx Highest Long GI data Rate */
1354 if (sme_cfg_set_int
1355 (hdd_ctx->hHal,
1356 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001357 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301358 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001359 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 }
1361 }
1362 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1363 enable_tx_stbc = 0;
1364 phtCapInfo->txSTBC = enable_tx_stbc;
1365
1366 val32 = val16;
1367 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301368 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001369 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1371 value = SIZE_OF_SUPPORTED_MCS_SET;
1372 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301373 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001374 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001375
1376 if (pconfig->enable2x2) {
1377 for (value = 0; value < cfg->num_rf_chains; value++)
1378 mcs_set[value] =
1379 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1380
1381 status =
1382 sme_cfg_set_str(hdd_ctx->hHal,
1383 WNI_CFG_SUPPORTED_MCS_SET,
1384 mcs_set,
1385 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301386 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001387 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388 }
1389 }
1390#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1391}
1392
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001393static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001394 struct wma_tgt_vht_cap *cfg)
1395{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301396 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001397 uint32_t value = 0;
1398 struct hdd_config *pconfig = hdd_ctx->config;
1399 struct wiphy *wiphy = hdd_ctx->wiphy;
1400 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001401 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001402 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001403 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001404 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001405
Dustin Brown5e06bd32016-10-04 12:49:10 -07001406 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001407 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001408 return;
1409 }
1410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001411 /* Get the current MPDU length */
1412 status =
1413 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1414 &value);
1415
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301416 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001417 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001418 value = 0;
1419 }
1420
1421 /*
1422 * VHT max MPDU length:
1423 * override if user configured value is too high
1424 * that the target cannot support
1425 */
1426 if (value > cfg->vht_max_mpdu) {
1427 status = sme_cfg_set_int(hdd_ctx->hHal,
1428 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1429 cfg->vht_max_mpdu);
1430
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001431 if (status == QDF_STATUS_E_FAILURE)
1432 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001433 }
1434
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001435 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1436 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1437
1438 if (pconfig->enable2x2)
1439 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1440
1441 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1442 QDF_STATUS_E_FAILURE) {
1443 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1444 }
1445
1446 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1447 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1448 if (pconfig->enable2x2)
1449 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1450
1451 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1452 QDF_STATUS_E_FAILURE) {
1453 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1454 }
1455
1456 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1457 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1458 if (pconfig->enable2x2)
1459 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1460
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001461 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001462 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1463
1464 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1465 QDF_STATUS_E_FAILURE) {
1466 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1467 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001469 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001470 &value);
1471
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301472 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001473 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001474 value = 0;
1475 }
1476
jiad4a7a33c2017-08-08 15:32:24 +08001477 /* Set HW RX LDPC capability */
1478 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1479 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001480 status = sme_cfg_set_int(hdd_ctx->hHal,
1481 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001482 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001484 if (status == QDF_STATUS_E_FAILURE)
1485 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001486 }
1487
1488 /* Get current GI 80 value */
1489 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1490 &value);
1491
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301492 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001493 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001494 value = 0;
1495 }
1496
1497 /* set the Guard interval 80MHz */
1498 if (value && !cfg->vht_short_gi_80) {
1499 status = sme_cfg_set_int(hdd_ctx->hHal,
1500 WNI_CFG_VHT_SHORT_GI_80MHZ,
1501 cfg->vht_short_gi_80);
1502
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001503 if (status == QDF_STATUS_E_FAILURE)
1504 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001505 }
1506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507 /* Get VHT TX STBC cap */
1508 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1509
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301510 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001511 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001512 value = 0;
1513 }
1514
1515 /* VHT TX STBC cap */
1516 if (value && !cfg->vht_tx_stbc) {
1517 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1518 cfg->vht_tx_stbc);
1519
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001520 if (status == QDF_STATUS_E_FAILURE)
1521 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001522 }
1523
1524 /* Get VHT RX STBC cap */
1525 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1526
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301527 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001528 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529 value = 0;
1530 }
1531
1532 /* VHT RX STBC cap */
1533 if (value && !cfg->vht_rx_stbc) {
1534 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1535 cfg->vht_rx_stbc);
1536
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001537 if (status == QDF_STATUS_E_FAILURE)
1538 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001539 }
1540
1541 /* Get VHT SU Beamformer cap */
1542 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1543 &value);
1544
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301545 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001546 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001547 value = 0;
1548 }
1549
1550 /* set VHT SU Beamformer cap */
1551 if (value && !cfg->vht_su_bformer) {
1552 status = sme_cfg_set_int(hdd_ctx->hHal,
1553 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1554 cfg->vht_su_bformer);
1555
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001556 if (status == QDF_STATUS_E_FAILURE)
1557 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001558 }
1559
1560 /* check and update SU BEAMFORMEE capabality */
1561 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1562 pconfig->enableTxBF = cfg->vht_su_bformee;
1563
1564 status = sme_cfg_set_int(hdd_ctx->hHal,
1565 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1566 pconfig->enableTxBF);
1567
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001568 if (status == QDF_STATUS_E_FAILURE)
1569 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001570
1571 /* Get VHT MU Beamformer cap */
1572 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1573 &value);
1574
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301575 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001576 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577 value = 0;
1578 }
1579
1580 /* set VHT MU Beamformer cap */
1581 if (value && !cfg->vht_mu_bformer) {
1582 status = sme_cfg_set_int(hdd_ctx->hHal,
1583 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1584 cfg->vht_mu_bformer);
1585
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001586 if (status == QDF_STATUS_E_FAILURE)
1587 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001588 }
1589
1590 /* Get VHT MU Beamformee cap */
1591 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1592 &value);
1593
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301594 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001595 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001596 value = 0;
1597 }
1598
1599 /* set VHT MU Beamformee cap */
1600 if (value && !cfg->vht_mu_bformee) {
1601 status = sme_cfg_set_int(hdd_ctx->hHal,
1602 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1603 cfg->vht_mu_bformee);
1604
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001605 if (status == QDF_STATUS_E_FAILURE)
1606 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001607 }
1608
1609 /* Get VHT MAX AMPDU Len exp */
1610 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1611 &value);
1612
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301613 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001614 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615 value = 0;
1616 }
1617
1618 /*
1619 * VHT max AMPDU len exp:
1620 * override if user configured value is too high
1621 * that the target cannot support.
1622 * Even though Rome publish ampdu_len=7, it can
1623 * only support 4 because of some h/w bug.
1624 */
1625
1626 if (value > cfg->vht_max_ampdu_len_exp) {
1627 status = sme_cfg_set_int(hdd_ctx->hHal,
1628 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1629 cfg->vht_max_ampdu_len_exp);
1630
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001631 if (status == QDF_STATUS_E_FAILURE)
1632 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001633 }
1634
1635 /* Get VHT TXOP PS CAP */
1636 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1637
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301638 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001639 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001640 value = 0;
1641 }
1642
1643 /* set VHT TXOP PS cap */
1644 if (value && !cfg->vht_txop_ps) {
1645 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1646 cfg->vht_txop_ps);
1647
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001648 if (status == QDF_STATUS_E_FAILURE)
1649 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001650 }
1651
1652 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1653 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1654 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1655 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1656 else
1657 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1658
1659
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001660 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1661 status = sme_cfg_set_int(hdd_ctx->hHal,
1662 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1663 VHT_CAP_160_AND_80P80_SUPP);
1664 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001665 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 band_5g->vht_cap.cap |=
1667 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001668 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1669 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1670 status = sme_cfg_set_int(hdd_ctx->hHal,
1671 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1672 VHT_CAP_160_SUPP);
1673 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001674 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001675 band_5g->vht_cap.cap |=
1676 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001677 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1678 }
1679 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1680 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301681 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001682 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301683 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001684 &value);
1685 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301686 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001687 value = 0;
1688 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301689 /* set the Guard interval 160MHz */
1690 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001691 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301692 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1693 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001694
1695 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301696 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001697 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001698
1699 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1700 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1701
1702 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1703 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1704 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1705 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1706
1707 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1708 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1709
1710 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1711 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1712 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1713 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1714 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1715 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1716
1717 band_5g->vht_cap.cap |=
1718 (cfg->vht_max_ampdu_len_exp <<
1719 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1720
1721 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1722 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1723 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1724 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1725 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1726 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1727 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1728 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1729
1730 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1731 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1732
1733}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001734
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001735/**
1736 * hdd_generate_macaddr_auto() - Auto-generate mac address
1737 * @hdd_ctx: Pointer to the HDD context
1738 *
1739 * Auto-generate mac address using device serial number.
1740 * Keep the first 3 bytes of OUI as before and replace
1741 * the last 3 bytes with the lower 3 bytes of serial number.
1742 *
1743 * Return: 0 for success
1744 * Non zero failure code for errors
1745 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001746static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001747{
1748 unsigned int serialno = 0;
1749 struct qdf_mac_addr mac_addr = {
1750 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1751 };
1752
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001753 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001754 if (serialno == 0)
1755 return -EINVAL;
1756
1757 serialno &= 0x00ffffff;
1758
1759 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1760 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1761 mac_addr.bytes[5] = serialno & 0xff;
1762
1763 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1764 return 0;
1765}
1766
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301767/**
1768 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1769 * configuration to cfg_ini in HDD
1770 * @hdd_ctx: Pointer to hdd_ctx
1771 * @cfg: target configuration
1772 *
1773 * Return: None
1774 */
1775#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001776static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301777 struct wma_tgt_cfg *cfg)
1778{
1779 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1780}
1781#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001782static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301783 struct wma_tgt_cfg *cfg)
1784{
1785}
1786#endif
1787
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301788uint8_t hdd_check_green_ap_enable(struct hdd_context *hdd_ctx,
1789 bool *is_enabled)
1790{
1791 struct hdd_config *cfg;
1792 uint32_t concurrency_mode;
1793
1794 cfg = hdd_ctx->config;
1795 if (!cfg) {
1796 hdd_err("NULL hdd config");
1797 return -EINVAL;
1798 }
1799
1800 concurrency_mode = policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc);
1801
1802 if (cfg->enable2x2 && cfg->enableGreenAP) {
1803 if ((concurrency_mode & (1 << QDF_SAP_MODE)) &&
1804 !(concurrency_mode & (~(1 << QDF_SAP_MODE))))
1805 *is_enabled = true;
1806 }
1807 return 0;
1808}
1809
1810static int hdd_update_green_ap_config(struct hdd_context *hdd_ctx)
1811{
1812 struct green_ap_user_cfg green_ap_cfg;
1813 struct hdd_config *cfg = hdd_ctx->config;
1814 QDF_STATUS status;
1815
1816 green_ap_cfg.host_enable_egap = cfg->enable_egap;
1817 green_ap_cfg.egap_inactivity_time = cfg->egap_inact_time;
1818 green_ap_cfg.egap_wait_time = cfg->egap_wait_time;
1819 green_ap_cfg.egap_feature_flags = cfg->egap_feature_flag;
1820
1821 status = ucfg_green_ap_update_user_config(hdd_ctx->hdd_pdev,
1822 &green_ap_cfg);
1823 if (status != QDF_STATUS_SUCCESS) {
1824 hdd_err("failed to update green ap user configuration");
1825 return -EINVAL;
1826 }
1827
1828 return 0;
1829}
1830
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001831void hdd_update_tgt_cfg(void *context, void *param)
1832{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001833 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001834 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001835 struct wma_tgt_cfg *cfg = param;
1836 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001837 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301838 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001839 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301840
Dustin Brownbd68fe12017-11-21 15:28:52 -08001841 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1842 if (ret) {
1843 hdd_err("Failed to create pdev; errno:%d", ret);
1844 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001845 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001846 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001847 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301848 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001849
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301850 ret = hdd_update_green_ap_config(hdd_ctx);
1851
Naveen Rawat64e477e2016-05-20 10:34:56 -07001852 if (cds_cfg) {
1853 if (hdd_ctx->config->enable_sub_20_channel_width !=
1854 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1855 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1856 cds_cfg->sub_20_channel_width =
1857 WLAN_SUB_20_CH_WIDTH_NONE;
1858 } else {
1859 cds_cfg->sub_20_channel_width =
1860 hdd_ctx->config->enable_sub_20_channel_width;
1861 }
1862 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863
1864 /* first store the INI band capability */
1865 temp_band_cap = hdd_ctx->config->nBandCapability;
1866
1867 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301868 hdd_ctx->is_fils_roaming_supported =
1869 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001870
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001871 /*
1872 * now overwrite the target band capability with INI
1873 * setting if INI setting is a subset
1874 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001875
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001876 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1877 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001879 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1880 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001881 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001882 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001883 }
1884
Amar Singhal58b45ef2017-08-01 13:43:54 -07001885 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1886
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301887 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001888 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1889 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1890 }
1891
1892 /* This can be extended to other configurations like ht, vht cap... */
1893
Anurag Chouhanc5548422016-02-24 18:33:27 +05301894 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001895 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001896 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001897 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001898 static struct qdf_mac_addr default_mac_addr = {
1899 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1900 };
1901 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1902 &default_mac_addr)) {
1903 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1904 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1905 MAC_ADDRESS_STR,
1906 MAC_ADDR_ARRAY(hdd_ctx->config->
1907 intfMacAddr[0].bytes));
1908 } else {
1909 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1910 MAC_ADDRESS_STR,
1911 MAC_ADDR_ARRAY(hdd_ctx->config->
1912 intfMacAddr[0].bytes));
1913 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001914 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001915 }
1916
1917 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001918 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001919
1920 hdd_ctx->max_intf_count = cfg->max_intf_count;
1921
Jeff Johnsonc875e242016-09-23 18:12:34 -07001922 hdd_lpass_target_config(hdd_ctx, cfg);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301923 ucfg_green_ap_target_config(hdd_ctx->hdd_pdev, cfg->egap_support);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1926 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1927
1928 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1929
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001931 if (cfg->services.en_11ax) {
1932 hdd_info("11AX: 11ax is enabled - update HDD config");
1933 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1934 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001935
1936 hdd_update_vdev_nss(hdd_ctx);
1937
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301938 hdd_update_hw_dbs_capable(hdd_ctx);
1939
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001940 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001941 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001942 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001943 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001944
Nitesh Shahe50711f2017-04-26 16:30:45 +05301945 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1946 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1947 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001948 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001949 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001950
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001951 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1952 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301953 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301954 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301955
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301956 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001957 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1958 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301959 hdd_ctx->config->txBFCsnValue =
1960 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1961
Arif Hussainee10f902017-12-27 16:30:17 -08001962 status = sme_cfg_set_int(hdd_ctx->hHal,
1963 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1964 hdd_ctx->config->txBFCsnValue);
1965 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301966 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1967
1968
1969 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001970 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1971 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301972
1973 /*
1974 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1975 */
1976 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301977
Arun Khandavallid454d422016-08-17 12:47:05 +05301978 /*
1979 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1980 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1981 * configure the STA mode wow pattern.
1982 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301983 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301984 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301985
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301986 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1987
Yue Macd359b72017-10-03 15:21:00 -07001988 /*
1989 * This needs to be done after HDD pdev is created and stored since
1990 * it will access the HDD pdev object lock.
1991 */
1992 hdd_runtime_suspend_context_init(hdd_ctx);
1993
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001994 /* Configure NAN datapath features */
1995 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001996 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08001997 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08001998 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
1999 cfg->obss_detection_offloaded);
2000 if (QDF_IS_STATUS_ERROR(status))
2001 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002002}
2003
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002004bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002005{
Jeff Johnson9d295242017-08-29 14:39:48 -07002006 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002007 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002008
Arif Hussaincd151632017-02-11 16:57:19 -08002009 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002010 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002011 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302012 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002013 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002014
Dustin Brown920397d2017-12-13 16:27:50 -08002015 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002016 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2017
2018 if ((QDF_SAP_MODE == adapter->device_mode ||
2019 QDF_P2P_GO_MODE == adapter->device_mode) &&
2020 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002021 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002022 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2023 true;
2024 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002025 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302026 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002027 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302028
2029 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002030}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002031
2032/**
2033 * hdd_is_valid_mac_address() - validate MAC address
2034 * @pMacAddr: Pointer to the input MAC address
2035 *
2036 * This function validates whether the given MAC address is valid or not
2037 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2038 * where X is the hexa decimal digit character and separated by ':'
2039 * This algorithm works even if MAC address is not separated by ':'
2040 *
2041 * This code checks given input string mac contains exactly 12 hexadecimal
2042 * digits and a separator colon : appears in the input string only after
2043 * an even number of hex digits.
2044 *
2045 * Return: 1 for valid and 0 for invalid
2046 */
2047bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2048{
2049 int xdigit = 0;
2050 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002051
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002052 while (*pMacAddr) {
2053 if (isxdigit(*pMacAddr)) {
2054 xdigit++;
2055 } else if (':' == *pMacAddr) {
2056 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2057 break;
2058
2059 ++separator;
2060 } else {
2061 /* Invalid MAC found */
2062 return 0;
2063 }
2064 ++pMacAddr;
2065 }
2066 return xdigit == 12 && (separator == 5 || separator == 0);
2067}
2068
2069/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302070 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2071 * @dev: Handle to struct net_device to be updated.
2072 *
2073 * Return: None
2074 */
2075static void hdd_mon_mode_ether_setup(struct net_device *dev)
2076{
2077 dev->header_ops = NULL;
2078 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2079 dev->hard_header_len = ETH_HLEN;
2080 dev->mtu = ETH_DATA_LEN;
2081 dev->addr_len = ETH_ALEN;
2082 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2083 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2084 dev->priv_flags |= IFF_TX_SKB_SHARING;
2085
2086 memset(dev->broadcast, 0xFF, ETH_ALEN);
2087}
2088
2089/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002090 * __hdd__mon_open() - HDD Open function
2091 * @dev: Pointer to net_device structure
2092 *
2093 * This is called in response to ifconfig up
2094 *
2095 * Return: 0 for success; non-zero for failure
2096 */
2097static int __hdd_mon_open(struct net_device *dev)
2098{
2099 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002100 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2101 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002102
2103 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002104
2105 ret = wlan_hdd_validate_context(hdd_ctx);
2106 if (ret)
2107 return ret;
2108
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302109 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002110
2111 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2112 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2113 if (ret) {
2114 hdd_err("Failed to start WLAN modules return");
2115 return ret;
2116 }
2117 hdd_err("hdd_wlan_start_modules() successful !");
2118
2119 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2120 ret = hdd_start_adapter(adapter);
2121 if (ret) {
2122 hdd_err("Failed to start adapter :%d",
2123 adapter->device_mode);
2124 return ret;
2125 }
2126 hdd_err("hdd_start_adapters() successful !");
2127 }
2128 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2129 }
2130
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002131 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002132
2133 if (!ret)
2134 ret = hdd_enable_monitor_mode(dev);
2135
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002136 return ret;
2137}
2138
2139/**
2140 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2141 * @dev: Pointer to net_device structure
2142 *
2143 * This is called in response to ifconfig up
2144 *
2145 * Return: 0 for success; non-zero for failure
2146 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002147static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002148{
2149 int ret;
2150
2151 cds_ssr_protect(__func__);
2152 ret = __hdd_mon_open(dev);
2153 cds_ssr_unprotect(__func__);
2154
2155 return ret;
2156}
2157
2158/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302159 * hdd_start_adapter() - Wrapper function for device specific adapter
2160 * @adapter: pointer to HDD adapter
2161 *
2162 * This function is called to start the device specific adapter for
2163 * the mode passed in the adapter's device_mode.
2164 *
2165 * Return: 0 for success; non-zero for failure
2166 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002167int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302168{
2169
2170 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002171 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302172
2173 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002174 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302175
2176 switch (device_mode) {
2177 case QDF_P2P_CLIENT_MODE:
2178 case QDF_P2P_DEVICE_MODE:
2179 case QDF_OCB_MODE:
2180 case QDF_STA_MODE:
2181 case QDF_MONITOR_MODE:
2182 ret = hdd_start_station_adapter(adapter);
2183 if (ret)
2184 goto err_start_adapter;
2185 break;
2186 case QDF_P2P_GO_MODE:
2187 case QDF_SAP_MODE:
2188 ret = hdd_start_ap_adapter(adapter);
2189 if (ret)
2190 goto err_start_adapter;
2191 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302192 case QDF_IBSS_MODE:
2193 /*
2194 * For IBSS interface is initialized as part of
2195 * hdd_init_station_mode()
2196 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002197 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302198 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002199 /* vdevs are dynamically managed by firmware in FTM */
2200 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302201 default:
2202 hdd_err("Invalid session type %d", device_mode);
2203 QDF_ASSERT(0);
2204 goto err_start_adapter;
2205 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002206
Arun Khandavallifae92942016-08-01 13:31:08 +05302207 if (hdd_set_fw_params(adapter))
2208 hdd_err("Failed to set the FW params for the adapter!");
2209
2210 /*
2211 * Action frame registered in one adapter which will
2212 * applicable to all interfaces
2213 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302214 ret = wlan_hdd_cfg80211_register_frames(adapter);
2215 if (ret < 0) {
2216 hdd_err("Failed to register frames - ret %d", ret);
2217 goto err_start_adapter;
2218 }
2219
Dustin Browndb2a8be2017-12-20 11:49:56 -08002220exit_with_success:
Arun Khandavallifae92942016-08-01 13:31:08 +05302221 EXIT();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002222
Arun Khandavallifae92942016-08-01 13:31:08 +05302223 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002224
Arun Khandavallifae92942016-08-01 13:31:08 +05302225err_start_adapter:
2226 return -EINVAL;
2227}
2228
2229/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302230 * hdd_enable_power_management() - API to Enable Power Management
2231 *
2232 * API invokes Bus Interface Layer power management functionality
2233 *
2234 * Return: None
2235 */
2236static void hdd_enable_power_management(void)
2237{
2238 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2239
2240 if (!hif_ctx) {
2241 hdd_err("Bus Interface Context is Invalid");
2242 return;
2243 }
2244
2245 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2246}
2247
2248/**
2249 * hdd_disable_power_management() - API to disable Power Management
2250 *
2251 * API disable Bus Interface Layer Power management functionality
2252 *
2253 * Return: None
2254 */
2255static void hdd_disable_power_management(void)
2256{
2257 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2258
2259 if (!hif_ctx) {
2260 hdd_err("Bus Interface Context is Invalid");
2261 return;
2262 }
2263
2264 hif_disable_power_management(hif_ctx);
2265}
2266
2267/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302268 * hdd_update_hw_sw_info() - API to update the HW/SW information
2269 *
2270 * API to update the HW and SW information in the driver
2271 *
2272 * Return: None
2273 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002274static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302275{
2276 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002277 size_t target_hw_name_len;
2278 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302279
2280 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2281 if (!hif_sc) {
2282 hdd_err("HIF context is NULL");
2283 return;
2284 }
2285
2286 /*
2287 * target hw version/revision would only be retrieved after firmware
2288 * download
2289 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002290 hif_get_hw_info(hif_sc,
2291 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302292 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002293 &target_hw_name);
2294
2295 if (hdd_ctx->target_hw_name)
2296 qdf_mem_free(hdd_ctx->target_hw_name);
2297
2298 target_hw_name_len = strlen(target_hw_name) + 1;
2299 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2300 if (hdd_ctx->target_hw_name)
2301 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2302 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302303
2304 /* Get the wlan hw/fw version */
2305 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302306}
2307
2308/**
gbian62edd7e2017-03-07 13:12:13 +08002309 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2310 * @hdd_ctx: Pointer to hdd context
2311 *
2312 * Return: none
2313 */
2314static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002315hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002316{
2317 uint8_t num_entries = 0;
2318 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2319 uint8_t *tx_sched_wrr_ac;
2320 int i;
2321 cds_context_type *cds_ctx;
2322
2323 if (NULL == hdd_ctx)
2324 return;
2325
2326 if (NULL == hdd_ctx->config) {
2327 /* Do nothing if hdd_ctx is invalid */
2328 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2329 return;
2330 }
2331
2332 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2333
2334 if (!cds_ctx) {
2335 hdd_err("Invalid CDS Context");
2336 return;
2337 }
2338
2339 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2340 switch (i) {
2341 case OL_TX_WMM_AC_BE:
2342 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2343 break;
2344 case OL_TX_WMM_AC_BK:
2345 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2346 break;
2347 case OL_TX_WMM_AC_VI:
2348 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2349 break;
2350 case OL_TX_WMM_AC_VO:
2351 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2352 break;
2353 default:
2354 tx_sched_wrr_ac = NULL;
2355 break;
2356 }
2357
2358 hdd_string_to_u8_array(tx_sched_wrr_ac,
2359 tx_sched_wrr_param,
2360 &num_entries,
2361 sizeof(tx_sched_wrr_param));
2362
2363 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2364 cds_ctx->ac_specs[i].wrr_skip_weight =
2365 tx_sched_wrr_param[0];
2366 cds_ctx->ac_specs[i].credit_threshold =
2367 tx_sched_wrr_param[1];
2368 cds_ctx->ac_specs[i].send_limit =
2369 tx_sched_wrr_param[2];
2370 cds_ctx->ac_specs[i].credit_reserve =
2371 tx_sched_wrr_param[3];
2372 cds_ctx->ac_specs[i].discard_weight =
2373 tx_sched_wrr_param[4];
2374 }
2375
2376 num_entries = 0;
2377 }
2378}
2379
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002380#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002381static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2382 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2383{
Jeff Johnson9d295242017-08-29 14:39:48 -07002384 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002385 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002386
2387 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2388 if (!adapter) {
2389 hdd_err("Adapter is NULL");
2390 return PM_MAX_NUM_OF_MODE;
2391 }
2392
2393 return policy_mgr_convert_device_mode_to_qdf_type(
2394 adapter->device_mode);
2395}
2396
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002397static void hdd_register_policy_manager_callback(
2398 struct wlan_objmgr_psoc *psoc)
2399{
2400 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002401
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002402 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002403 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002404 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2405 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002406 hdd_cbacks.get_mode_for_non_connected_vdev =
2407 wlan_hdd_get_mode_for_non_connected_vdev;
2408
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002409 if (QDF_STATUS_SUCCESS !=
2410 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2411 hdd_err("HDD callback registration with policy manager failed");
2412 }
2413}
2414#else
2415static void hdd_register_policy_manager_callback(
2416 struct wlan_objmgr_psoc *psoc)
2417{
2418}
2419#endif
2420
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002421#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002422static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002423{
2424 struct nan_callbacks cb_obj = {0};
2425
2426 cb_obj.ndi_open = hdd_ndi_open;
2427 cb_obj.ndi_close = hdd_ndi_close;
2428 cb_obj.ndi_start = hdd_ndi_start;
2429 cb_obj.ndi_delete = hdd_ndi_delete;
2430 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2431 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2432
Naveen Rawat37f62c82017-03-26 22:24:43 -07002433 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2434 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002435 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002436
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002437 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2438}
2439#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002440static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002441{
2442}
2443#endif
2444
Dustin Brown26b3d042017-12-21 11:13:27 -08002445#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002446/**
2447 * hdd_check_for_leaks() - Perform runtime memory leak checks
2448 *
2449 * This API triggers runtime memory leak detection. This feature enforces the
2450 * policy that any memory allocated at runtime must also be released at runtime.
2451 *
2452 * Allocating memory at runtime and releasing it at unload is effectively a
2453 * memory leak for configurations which never unload (e.g. LONU, statically
2454 * compiled driver). Such memory leaks are NOT false positives, and must be
2455 * fixed.
2456 *
2457 * Return: None
2458 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002459static void hdd_check_for_leaks(void)
2460{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002461 /* DO NOT REMOVE these checks; for false positives, read above first */
2462
Dustin Brown677e0862017-10-10 16:30:09 -07002463 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002464 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002465 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002466}
2467
Dustin Brown26b3d042017-12-21 11:13:27 -08002468#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2469#else
2470static inline void hdd_check_for_leaks(void) {}
2471
2472#define hdd_debug_domain_set(domain)
2473#endif /* CONFIG_LEAK_DETECTION */
2474
gbian62edd7e2017-03-07 13:12:13 +08002475/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302476 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2477 * @hdd_ctx: HDD context
2478 * @adapter: HDD adapter
2479 * @reinit: flag to indicate from SSR or normal path
2480 *
2481 * This function maintains the driver state machine it will be invoked from
2482 * startup, reinit and change interface. Depending on the driver state shall
2483 * perform the opening of the modules.
2484 *
2485 * Return: 0 for success; non-zero for failure
2486 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002487int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2488 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302489 bool reinit)
2490{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002491 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302492 qdf_device_t qdf_dev;
2493 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302494 bool unint = false;
2495 void *hif_ctx;
2496
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002497 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302498
2499 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2500 if (!qdf_dev) {
2501 hdd_err("QDF Device Context is Invalid return");
2502 return -EINVAL;
2503 }
2504
Dustin Brown6f427922017-09-19 12:19:00 -07002505 hdd_set_idle_ps_config(hdd_ctx, false);
2506 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302507
Dustin Brown1fe30a82017-10-03 16:13:36 -07002508 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302509 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2510 mutex_unlock(&hdd_ctx->iface_change_lock);
2511 hdd_info("Driver modules already Enabled");
2512 EXIT();
2513 return 0;
2514 }
2515
Dustin Brown1fe30a82017-10-03 16:13:36 -07002516 hdd_ctx->start_modules_in_progress = true;
2517
Arun Khandavallifae92942016-08-01 13:31:08 +05302518 switch (hdd_ctx->driver_status) {
2519 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002520 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302521 unint = true;
2522 /* Fall through dont add break here */
2523 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002524 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2525
Dustin Brown26b3d042017-12-21 11:13:27 -08002526 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002527
Arun Khandavallifae92942016-08-01 13:31:08 +05302528 if (!reinit && !unint) {
2529 ret = pld_power_on(qdf_dev->dev);
2530 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002531 hdd_err("Failed to Powerup the device; errno: %d",
2532 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302533 goto release_lock;
2534 }
2535 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002536
2537 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2538 hdd_ctx->config->enable_fw_log);
2539
Arun Khandavallifae92942016-08-01 13:31:08 +05302540 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2541 qdf_dev->bus_type,
2542 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2543 HIF_ENABLE_TYPE_PROBE);
2544 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002545 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302546 goto power_down;
2547 }
2548
2549 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302550 if (!hif_ctx) {
2551 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002552 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302553 goto power_down;
2554 }
2555
Arun Khandavallifae92942016-08-01 13:31:08 +05302556 status = ol_cds_init(qdf_dev, hif_ctx);
2557 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002558 hdd_err("No Memory to Create BMI Context; status: %d",
2559 status);
2560 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302561 goto hif_close;
2562 }
2563
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002564 ret = hdd_update_config(hdd_ctx);
2565 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002566 hdd_err("Failed to update configuration; errno: %d",
2567 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002568 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002569 }
2570
gbian62edd7e2017-03-07 13:12:13 +08002571 hdd_update_cds_ac_specs_params(hdd_ctx);
2572
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302573 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002574 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002575 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002576 ret = qdf_status_to_os_return(status);
2577 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302578 }
2579
Mukul Sharma9d797a02017-01-05 20:26:03 +05302580 /* initalize components configurations after psoc open */
2581 ret = hdd_update_components_config(hdd_ctx);
2582 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002583 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302584 ret);
2585 goto close;
2586 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002587 status = cds_dp_open(hdd_ctx->hdd_psoc);
2588 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002589 hdd_err("Failed to Open cds post open; status: %d",
2590 status);
2591 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002592 goto close;
2593 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302594
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002595 /*
2596 * NAN compoenet requires certian operations like, open adapter,
2597 * close adapter, etc. to be initiated by HDD, for those
2598 * register HDD callbacks with UMAC's NAN componenet.
2599 */
2600 hdd_nan_register_callbacks(hdd_ctx);
2601
Arun Khandavallifae92942016-08-01 13:31:08 +05302602 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2603
Jeff Johnson3a280122017-09-13 07:42:00 -07002604 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302605 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002606 hdd_err("Failed to pre-enable CDS; status: %d", status);
2607 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002608 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302609 }
2610
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002611 hdd_register_policy_manager_callback(
2612 hdd_ctx->hdd_psoc);
2613
Amar Singhal0928b192017-12-01 10:50:54 -08002614 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2615
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302616 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302617 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002618 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302619
Arun Khandavallifae92942016-08-01 13:31:08 +05302620 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002621 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302622 break;
2623 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302624
2625 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002626 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2627 if (ret) {
2628 hdd_err("HDD IPA UC reinit failed; errno: %d",
2629 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002630 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002631 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302632 }
2633
Arun Khandavallifae92942016-08-01 13:31:08 +05302634 /* Fall through dont add break here */
2635 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002636 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2637
Arun Khandavallifae92942016-08-01 13:31:08 +05302638 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002639 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002640 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002641 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302642 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302643 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2644 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002645 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302646 break;
2647 }
Dustin Browndca39692017-11-09 15:30:25 -08002648
2649 ret = hdd_configure_cds(hdd_ctx, adapter);
2650 if (ret) {
2651 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002652 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302653 }
Dustin Browndca39692017-11-09 15:30:25 -08002654
Komal Seelamf2136bb2016-09-28 18:30:44 +05302655 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002656
Arun Khandavallifae92942016-08-01 13:31:08 +05302657 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002658 hdd_info("Wlan transitioned (now ENABLED)");
2659
Arun Khandavallifae92942016-08-01 13:31:08 +05302660 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002661
Arun Khandavallifae92942016-08-01 13:31:08 +05302662 default:
2663 hdd_err("WLAN start invoked in wrong state! :%d\n",
2664 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002665 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302666 goto release_lock;
2667 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002668
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302669 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302670 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002671
Arun Khandavallifae92942016-08-01 13:31:08 +05302672 EXIT();
Dustin Brown550f6d22017-12-14 15:44:01 -08002673
Arun Khandavallifae92942016-08-01 13:31:08 +05302674 return 0;
2675
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002676post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002677 cds_post_disable();
Dustin Brownbd68fe12017-11-21 15:28:52 -08002678 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002679
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002680cds_txrx_free:
2681 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002682
Arun Khandavallifae92942016-08-01 13:31:08 +05302683close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002684 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002685 hdd_info("Wlan transition aborted (now CLOSED)");
2686
Jeff Johnsone4b14592017-09-13 14:23:33 -07002687 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302688
Dustin Brown28b17892017-10-10 13:29:38 -07002689deinit_config:
2690 cds_deinit_ini_config();
2691
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002692cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302693 ol_cds_free();
2694
2695hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002696 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2697 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302698power_down:
2699 if (!reinit && !unint)
2700 pld_power_off(qdf_dev->dev);
2701release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302702 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302703 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002704
2705 /* many adapter resources are not freed by design in SSR case */
2706 if (!reinit)
2707 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002708 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002709
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302710 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002711
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002712 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302713}
2714
Naveen Rawat910726a2017-03-06 11:42:51 -08002715#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002716static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002717{
2718 int ret = os_if_wifi_pos_register_nl();
2719
2720 if (ret)
2721 hdd_err("os_if_wifi_pos_register_nl failed");
2722
2723 return ret;
2724}
2725
2726static int hdd_deactivate_wifi_pos(void)
2727{
2728 int ret = os_if_wifi_pos_deregister_nl();
2729
2730 if (ret)
2731 hdd_err("os_if_wifi_pos_deregister_nl failed");
2732
2733 return ret;
2734}
2735
2736/**
2737 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2738 * @hdd_ctx: hdd context
2739 *
2740 * Return: status of operation
2741 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002742static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002743{
2744 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2745 struct hdd_config *cfg = hdd_ctx->config;
2746
2747 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2748 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2749 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2750 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2751 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2752 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2753 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2754 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2755}
2756#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002757static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002758{
2759 return oem_activate_service(hdd_ctx);
2760}
2761
2762static int hdd_deactivate_wifi_pos(void)
2763{
2764 return 0;
2765}
2766
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002767static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002768{
2769}
2770#endif
2771
Arun Khandavallifae92942016-08-01 13:31:08 +05302772/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002773 * __hdd_open() - HDD Open function
2774 * @dev: Pointer to net_device structure
2775 *
2776 * This is called in response to ifconfig up
2777 *
2778 * Return: 0 for success; non-zero for failure
2779 */
2780static int __hdd_open(struct net_device *dev)
2781{
Jeff Johnson9d295242017-08-29 14:39:48 -07002782 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002783 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002784 int ret;
2785
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002786 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302787 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002788 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002789
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302790 /* Nothing to be done if device is unloading */
2791 if (cds_is_driver_unloading()) {
2792 hdd_err("Driver is unloading can not open the hdd");
2793 return -EBUSY;
2794 }
2795
Dustin Brown01847752017-10-25 13:56:27 -07002796 if (cds_is_driver_recovering()) {
2797 hdd_err("WLAN is currently recovering; Please try again.");
2798 return -EBUSY;
2799 }
2800
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302801 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2802 hdd_err("con_mode_handler is in progress; Please try again.");
2803 return -EBUSY;
2804 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302805
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302806 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302807 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2808
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302809 /*
2810 * This scenario can be hit in cases where in the wlan driver after
2811 * registering the netdevices and there is a failure in driver
2812 * initialization. So return error gracefully because the netdevices
2813 * will be de-registered as part of the load failure.
2814 */
2815
2816 if (!cds_is_driver_loaded()) {
2817 hdd_err("Failed to start the wlan driver!!");
2818 ret = -EIO;
2819 goto err_hdd_hdd_init_deinit_lock;
2820 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302821
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002822
Arun Khandavallifae92942016-08-01 13:31:08 +05302823 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2824 if (ret) {
2825 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302826 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302827 }
2828
2829
2830 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2831 ret = hdd_start_adapter(adapter);
2832 if (ret) {
2833 hdd_err("Failed to start adapter :%d",
2834 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302835 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302836 }
2837 }
2838
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002839 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2840 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002841 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002842 /* Enable TX queues only when we are connected */
2843 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302844 WLAN_START_ALL_NETIF_QUEUE,
2845 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002846 }
2847
Naveen Rawat286def52016-09-23 15:38:02 -07002848 /* Enable carrier and transmit queues for NDI */
2849 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002850 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002851 wlan_hdd_netif_queue_control(adapter,
2852 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2853 WLAN_CONTROL_PATH);
2854 }
2855
Naveen Rawat910726a2017-03-06 11:42:51 -08002856 hdd_populate_wifi_pos_cfg(hdd_ctx);
2857
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302858err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302859 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302860 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002861 return ret;
2862}
2863
Arun Khandavallifae92942016-08-01 13:31:08 +05302864
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002865/**
2866 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2867 * @dev: Pointer to net_device structure
2868 *
2869 * This is called in response to ifconfig up
2870 *
2871 * Return: 0 for success; non-zero for failure
2872 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002873static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002874{
2875 int ret;
2876
2877 cds_ssr_protect(__func__);
2878 ret = __hdd_open(dev);
2879 cds_ssr_unprotect(__func__);
2880
2881 return ret;
2882}
2883
2884/**
2885 * __hdd_stop() - HDD stop function
2886 * @dev: Pointer to net_device structure
2887 *
2888 * This is called in response to ifconfig down
2889 *
2890 * Return: 0 for success; non-zero for failure
2891 */
2892static int __hdd_stop(struct net_device *dev)
2893{
Jeff Johnson9d295242017-08-29 14:39:48 -07002894 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002895 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002896 int ret;
2897
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002898 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002899
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302900 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002901 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902
2903 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302904 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002905 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002906
2907 /* Nothing to be done if the interface is not opened */
2908 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002909 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002910 return -ENODEV;
2911 }
2912
2913 /* Make sure the interface is marked as closed */
2914 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302915
2916 hdd_debug("Disabling Auto Power save timer");
2917 sme_ps_disable_auto_ps_timer(
2918 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002919 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302920
2921 /*
2922 * Disable TX on the interface, after this hard_start_xmit() will not
2923 * be called on that interface
2924 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002925 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2926 hdd_device_mode_to_string(adapter->device_mode),
2927 adapter->device_mode);
2928
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302929 wlan_hdd_netif_queue_control(adapter,
2930 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2931 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002932
2933 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002934 * NAN data interface is different in some sense. The traffic on NDI is
2935 * bursty in nature and depends on the need to transfer. The service
2936 * layer may down the interface after the usage and up again when
2937 * required. In some sense, the NDI is expected to be available
2938 * (like SAP) iface until NDI delete request is issued by the service
2939 * layer. Skip BSS termination and adapter deletion for NAN Data
2940 * interface (NDI).
2941 */
2942 if (WLAN_HDD_IS_NDI(adapter))
2943 return 0;
2944
2945 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002946 * The interface is marked as down for outside world (aka kernel)
2947 * But the driver is pretty much alive inside. The driver needs to
2948 * tear down the existing connection on the netdev (session)
2949 * cleanup the data pipes and wait until the control plane is stabilized
2950 * for this interface. The call also needs to wait until the above
2951 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002952 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002953 * That is intentional to be able to scan if it is a STA/P2P interface
2954 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002955 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002956
2957 /* DeInit the adapter. This ensures datapath cleanup as well */
2958 hdd_deinit_adapter(hdd_ctx, adapter, true);
2959
Arun Khandavallifae92942016-08-01 13:31:08 +05302960
2961 /*
2962 * Find if any iface is up. If any iface is up then can't put device to
2963 * sleep/power save mode
2964 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302965 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002966 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07002967 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
2968 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302969 hdd_prevent_suspend_timeout(
2970 hdd_ctx->config->iface_change_wait_time,
2971 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302972 }
2973
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002974 EXIT();
2975 return 0;
2976}
2977
2978/**
2979 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2980 * @dev: pointer to net_device structure
2981 *
2982 * This is called in response to ifconfig down
2983 *
2984 * Return: 0 for success and error number for failure
2985 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002986static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002987{
2988 int ret;
2989
2990 cds_ssr_protect(__func__);
2991 ret = __hdd_stop(dev);
2992 cds_ssr_unprotect(__func__);
2993
2994 return ret;
2995}
2996
2997/**
2998 * __hdd_uninit() - HDD uninit function
2999 * @dev: Pointer to net_device structure
3000 *
3001 * This is called during the netdev unregister to uninitialize all data
3002 * associated with the device
3003 *
3004 * Return: None
3005 */
3006static void __hdd_uninit(struct net_device *dev)
3007{
Jeff Johnson9d295242017-08-29 14:39:48 -07003008 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003009 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003010
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003011 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003012
3013 do {
3014 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003015 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003016 break;
3017 }
3018
Jeff Johnson399c6272017-08-30 10:51:00 -07003019 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3020 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003021 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003022 break;
3023 }
3024
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003025 if (dev != adapter->dev)
3026 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003027
Jeff Johnson399c6272017-08-30 10:51:00 -07003028 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029
3030 /* after uninit our adapter structure will no longer be valid */
3031 adapter->dev = NULL;
3032 adapter->magic = 0;
3033 } while (0);
3034
3035 EXIT();
3036}
3037
3038/**
3039 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3040 * @dev: pointer to net_device structure
3041 *
3042 * This is called during the netdev unregister to uninitialize all data
3043 * associated with the device
3044 *
3045 * Return: none
3046 */
3047static void hdd_uninit(struct net_device *dev)
3048{
3049 cds_ssr_protect(__func__);
3050 __hdd_uninit(dev);
3051 cds_ssr_unprotect(__func__);
3052}
3053
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003054static int hdd_open_cesium_nl_sock(void)
3055{
3056#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3057 struct netlink_kernel_cfg cfg = {
3058 .groups = WLAN_NLINK_MCAST_GRP_ID,
3059 .input = NULL
3060 };
3061#endif
3062 int ret = 0;
3063
3064#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3065 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3066#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3067 THIS_MODULE,
3068#endif
3069 &cfg);
3070#else
3071 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3072 WLAN_NLINK_MCAST_GRP_ID,
3073 NULL, NULL, THIS_MODULE);
3074#endif
3075
3076 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003077 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003078 ret = -ECONNREFUSED;
3079 }
3080
3081 return ret;
3082}
3083
3084static void hdd_close_cesium_nl_sock(void)
3085{
3086 if (NULL != cesium_nl_srv_sock) {
3087 netlink_kernel_release(cesium_nl_srv_sock);
3088 cesium_nl_srv_sock = NULL;
3089 }
3090}
3091
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003092/**
3093 * __hdd_set_mac_address() - set the user specified mac address
3094 * @dev: Pointer to the net device.
3095 * @addr: Pointer to the sockaddr.
3096 *
3097 * This function sets the user specified mac address using
3098 * the command ifconfig wlanX hw ether <mac adress>.
3099 *
3100 * Return: 0 for success, non zero for failure
3101 */
3102static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3103{
Jeff Johnson9d295242017-08-29 14:39:48 -07003104 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003105 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303107 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108 int ret;
3109
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003110 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003111
3112 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3113 ret = wlan_hdd_validate_context(hdd_ctx);
3114 if (0 != ret)
3115 return ret;
3116
Jeff Johnson1e851a12017-10-28 14:36:12 -07003117 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3119
3120 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303121 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122}
3123
3124/**
3125 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3126 * function from SSR
3127 * @dev: pointer to net_device structure
3128 * @addr: Pointer to the sockaddr
3129 *
3130 * This function sets the user specified mac address using
3131 * the command ifconfig wlanX hw ether <mac adress>.
3132 *
3133 * Return: 0 for success.
3134 */
3135static int hdd_set_mac_address(struct net_device *dev, void *addr)
3136{
3137 int ret;
3138
3139 cds_ssr_protect(__func__);
3140 ret = __hdd_set_mac_address(dev, addr);
3141 cds_ssr_unprotect(__func__);
3142
3143 return ret;
3144}
3145
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003146uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003147{
3148 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003149
Anurag Chouhan6d760662016-02-20 16:05:43 +05303150 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003151 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3152 break;
3153 }
3154
Anurag Chouhan6d760662016-02-20 16:05:43 +05303155 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003156 return NULL;
3157
3158 hdd_ctx->config->intfAddrMask |= (1 << i);
3159 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3160}
3161
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003162void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3163 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164{
3165 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003166
Anurag Chouhan6d760662016-02-20 16:05:43 +05303167 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003168 if (!memcmp(releaseAddr,
3169 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3170 6)) {
3171 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3172 break;
3173 }
3174 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003175}
3176
3177#ifdef WLAN_FEATURE_PACKET_FILTERING
3178/**
3179 * __hdd_set_multicast_list() - set the multicast address list
3180 * @dev: Pointer to the WLAN device.
3181 * @skb: Pointer to OS packet (sk_buff).
3182 *
3183 * This funciton sets the multicast address list.
3184 *
3185 * Return: None
3186 */
3187static void __hdd_set_multicast_list(struct net_device *dev)
3188{
Jeff Johnson9d295242017-08-29 14:39:48 -07003189 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190 int i = 0, status;
3191 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003192 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303193 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3194 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3195 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003196
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003197 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303198 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303199 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303200
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003201 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303202 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303203 goto out;
3204
Dustin Brownc788acb2017-08-01 17:43:51 -07003205 status = hdd_validate_adapter(adapter);
3206 if (status)
3207 goto out;
3208
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303209 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3210 hdd_err("%s: Driver module is closed", __func__);
3211 return;
3212 }
3213
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303214 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3215 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003216 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303217 goto out;
3218 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003219
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303220 /* Delete already configured multicast address list */
3221 if (adapter->mc_addr_list.mc_cnt > 0) {
3222 hdd_info("clear previously configured MC address list");
3223 hdd_disable_and_flush_mc_addr_list(adapter,
3224 pmo_mc_list_change_notify);
3225 }
3226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003227 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003228 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303229 hdd_disable_and_flush_mc_addr_list(adapter,
3230 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231 } else {
3232 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303233 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003234 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303235 pmo_ucfg_max_mc_addr_supported(psoc));
3236 hdd_disable_and_flush_mc_addr_list(adapter,
3237 pmo_mc_list_change_notify);
3238 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003239 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003240 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003241 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303242 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243 if (i == mc_count)
3244 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303245 memset(&(mc_list_request->mc_addr[i].bytes),
3246 0, ETH_ALEN);
3247 memcpy(&(mc_list_request->mc_addr[i].bytes),
3248 ha->addr, ETH_ALEN);
3249 hdd_info("mlist[%d] = %pM", i,
3250 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251 i++;
3252 }
3253 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303254
3255 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003256 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303257 mc_list_request->count = mc_count;
3258 status = hdd_cache_mc_addr_list(mc_list_request);
3259 if (status == 0) {
3260 hdd_enable_mc_addr_filtering(adapter,
3261 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003262 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303263 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303265out:
3266 if (mc_list_request)
3267 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303268 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269}
3270
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303271
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272/**
3273 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3274 * @dev: pointer to net_device
3275 *
3276 * Return: none
3277 */
3278static void hdd_set_multicast_list(struct net_device *dev)
3279{
3280 cds_ssr_protect(__func__);
3281 __hdd_set_multicast_list(dev);
3282 cds_ssr_unprotect(__func__);
3283}
3284#endif
3285
3286/**
3287 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3288 * @dev: Pointer to the WLAN device.
3289 * @skb: Pointer to OS packet (sk_buff).
3290 *
3291 * This function is registered with the Linux OS for network
3292 * core to decide which queue to use first.
3293 *
3294 * Return: ac, Queue Index/access category corresponding to UP in IP header
3295 */
3296static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3297#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3298 , void *accel_priv
3299#endif
3300#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3301 , select_queue_fallback_t fallback
3302#endif
3303)
3304{
3305 return hdd_wmm_select_queue(dev, skb);
3306}
3307
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003308static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003309 .ndo_open = hdd_open,
3310 .ndo_stop = hdd_stop,
3311 .ndo_uninit = hdd_uninit,
3312 .ndo_start_xmit = hdd_hard_start_xmit,
3313 .ndo_tx_timeout = hdd_tx_timeout,
3314 .ndo_get_stats = hdd_get_stats,
3315 .ndo_do_ioctl = hdd_ioctl,
3316 .ndo_set_mac_address = hdd_set_mac_address,
3317 .ndo_select_queue = hdd_select_queue,
3318#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003319 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320#endif
3321};
3322
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003323/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003324static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003325 .ndo_open = hdd_mon_open,
3326 .ndo_stop = hdd_stop,
3327 .ndo_get_stats = hdd_get_stats,
3328};
3329
3330/**
3331 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003332 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003333 * Return: None
3334 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003335void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003337 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003338 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003339 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003340 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003341}
3342
3343/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003344 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3345 * @hdd_ctx: global hdd context
3346 * @macAddr: mac address to assign to the interface
3347 * @name: User-visible name of the interface
3348 *
3349 * hdd adapter pointer would point to the netdev->priv space, this function
3350 * would retrive the pointer, and setup the hdd adapter configuration.
3351 *
3352 * Return: the pointer to hdd adapter, otherwise NULL
3353 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003354static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003356 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003357 const char *name)
3358{
Jeff Johnson5505db82017-11-02 21:19:23 -07003359 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003360 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003361 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303362 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363 /*
3364 * cfg80211 initialization and registration....
3365 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003366 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003367#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3368 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003369#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003370 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3371 hdd_mon_mode_ether_setup : ether_setup),
3372 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373
Jeff Johnson5505db82017-11-02 21:19:23 -07003374 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375
3376 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003377 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378
Jeff Johnson9d295242017-08-29 14:39:48 -07003379 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003380 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303381 qdf_mem_set(sta_ctx->conn_info.staId,
3382 sizeof(sta_ctx->conn_info.staId),
3383 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003384 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003385 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003386 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003387 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003388
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303389 qdf_status = qdf_event_create(
3390 &adapter->qdf_session_open_event);
3391 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3392 hdd_err("Session open QDF event init failed!");
3393 free_netdev(adapter->dev);
3394 return NULL;
3395 }
3396
3397 qdf_status = qdf_event_create(
3398 &adapter->qdf_session_close_event);
3399 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3400 hdd_err("Session close QDF event init failed!");
3401 free_netdev(adapter->dev);
3402 return NULL;
3403 }
3404
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303406 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407 init_completion(&adapter->linkup_event_var);
3408 init_completion(&adapter->cancel_rem_on_chan_var);
3409 init_completion(&adapter->rem_on_chan_ready_event);
3410 init_completion(&adapter->sta_authorized_event);
3411 init_completion(&adapter->offchannel_tx_event);
3412 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003413 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003414 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303415 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416
3417 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003418 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003419 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003420 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421
Jeff Johnson5505db82017-11-02 21:19:23 -07003422 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003424 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003425 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003426 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003427
3428 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003429 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003431 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432
Jeff Johnson5505db82017-11-02 21:19:23 -07003433 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003434
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435 hdd_set_station_ops(adapter->dev);
3436
Jeff Johnson5505db82017-11-02 21:19:23 -07003437 hdd_dev_setup_destructor(dev);
3438 dev->ieee80211_ptr = &adapter->wdev;
3439 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003441 adapter->wdev.netdev = dev;
3442 /* set dev's parent to underlying device */
3443 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444 hdd_wmm_init(adapter);
3445 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303446 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003447 }
3448
3449 return adapter;
3450}
3451
Jeff Johnson9d295242017-08-29 14:39:48 -07003452static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003454 struct net_device *dev = adapter->dev;
3455 int ret;
3456
3457 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003459 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003460 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3461
3462 ret = dev_alloc_name(dev, dev->name);
3463 if (ret < 0) {
3464 hdd_err(
3465 "unable to get dev name: %s, err = 0x%x",
3466 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303467 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468 }
3469 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003470
3471 ret = register_netdevice(dev);
3472 if (ret) {
3473 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3474 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303475 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476 }
3477 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003478 ret = register_netdev(dev);
3479 if (ret) {
3480 hdd_err("register_netdev(%s) failed, err = 0x%x",
3481 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303482 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483 }
3484 }
3485 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3486
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003487 EXIT();
3488
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303489 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003490}
3491
Krunal Sonib51eec72017-11-20 21:53:01 -08003492QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493{
Krunal Sonib51eec72017-11-20 21:53:01 -08003494 struct hdd_adapter *adapter;
3495 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003496
Krunal Sonib51eec72017-11-20 21:53:01 -08003497 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3498 if (!hdd_ctx) {
3499 hdd_err("Invalid HDD_CTX");
3500 return QDF_STATUS_E_FAILURE;
3501 }
3502
3503 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3504 if (NULL == adapter) {
3505 hdd_err("NULL adapter");
3506 return QDF_STATUS_E_INVAL;
3507 }
3508 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303509 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003510 hdd_debug("session %d opened", adapter->session_id);
3511
3512 return QDF_STATUS_SUCCESS;
3513}
3514
3515QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3516{
3517 struct hdd_adapter *adapter;
3518 struct hdd_context *hdd_ctx;
3519
3520 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3521 if (!hdd_ctx) {
3522 hdd_err("Invalid HDD_CTX");
3523 return QDF_STATUS_E_FAILURE;
3524 }
3525
3526 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003527 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003528 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303529 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530 }
3531
3532 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003533 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303534 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003535 }
3536
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003537 /*
3538 * For NAN Data interface, the close session results in the final
3539 * indication to the userspace
3540 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003541 if (adapter->device_mode == QDF_NDI_MODE)
3542 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003543
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003544 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3545
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003546 /*
3547 * We can be blocked while waiting for scheduled work to be
3548 * flushed, and the adapter structure can potentially be freed, in
3549 * which case the magic will have been reset. So make sure the
3550 * magic is still good, and hence the adapter structure is still
3551 * valid, before signaling completion
3552 */
3553 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303554 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003555
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303556 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557}
3558
Jeff Johnson9d295242017-08-29 14:39:48 -07003559int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560{
Dustin Brownd28772b2017-03-17 14:16:07 -07003561 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562
Dustin Brownd28772b2017-03-17 14:16:07 -07003563 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003564 if (QDF_IS_STATUS_ERROR(status))
3565 return qdf_status_to_os_return(status);
3566
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003567 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003568 if (QDF_IS_STATUS_ERROR(status))
3569 return qdf_status_to_os_return(status);
3570
3571 if (wma_capability_enhanced_mcast_filter())
3572 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3573 else
3574 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003575
3576 return qdf_status_to_os_return(status);
3577}
3578
Jeff Johnson9d295242017-08-29 14:39:48 -07003579int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003580{
3581 QDF_STATUS status;
3582 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003583 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003584 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003585
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003586 vdev_id = adapter->session_id;
3587 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003588
3589 /* vdev created sanity check */
3590 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003591 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003592 return -EINVAL;
3593 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003594 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003595 /*
3596 * In SSR case, there is no need to destroy vdev in firmware since
3597 * it has already asserted. vdev can be released directly.
3598 */
Krunal Sonib51eec72017-11-20 21:53:01 -08003599 if (cds_is_driver_recovering()) {
3600 hdd_debug("SSR: silently release the vdev for session-id: %d",
3601 adapter->session_id);
3602 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Yue Maf9782842017-05-08 12:49:49 -07003603 goto release_vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08003604 }
Yue Maf9782842017-05-08 12:49:49 -07003605
Dustin Brownd28772b2017-03-17 14:16:07 -07003606 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303607 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003608 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003609 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003610 if (QDF_IS_STATUS_ERROR(status)) {
3611 hdd_err("failed to close sme session: %d", status);
3612 return qdf_status_to_os_return(status);
3613 }
3614
3615 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303616 status = qdf_wait_for_event_completion(
3617 &adapter->qdf_session_close_event,
3618 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3619 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003620 if (adapter->device_mode == QDF_NDI_MODE)
3621 hdd_ndp_session_end_handler(adapter);
3622 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303623 adapter->session_id = HDD_SESSION_ID_INVALID;
3624 if (QDF_STATUS_E_TIMEOUT != status) {
3625 hdd_err("timed out waiting for close sme session: %u", status);
3626 return -ETIMEDOUT;
3627 } else if (adapter->qdf_session_close_event.force_set) {
3628 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
3629 return -EINVAL;
3630 } else {
3631 hdd_err("Failed to close sme session (%u)", status);
3632 return -EINVAL;
3633 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003634 }
Yue Maf9782842017-05-08 12:49:49 -07003635release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003636 /* do vdev logical destroy via objmgr */
3637 errno = hdd_objmgr_destroy_vdev(adapter);
3638 if (errno) {
3639 hdd_err("failed to destroy objmgr vdev: %d", errno);
3640 return errno;
3641 }
3642
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003643 /* now that sme session is closed, allow physical vdev destroy */
3644 errno = hdd_objmgr_release_vdev(adapter);
3645 if (errno) {
3646 hdd_err("failed to release objmgr vdev: %d", errno);
3647 return errno;
3648 }
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003649 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003650
3651 return 0;
3652}
3653
Krunal Sonib51eec72017-11-20 21:53:01 -08003654static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3655 struct sme_session_params *session_param,
3656 csr_roam_completeCallback callback,
3657 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003658{
Dustin Brownd28772b2017-03-17 14:16:07 -07003659 uint32_t type;
3660 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003661 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003662
3663 /* determine vdev (sub)type */
3664 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303665 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003666 hdd_err("failed to get vdev type: %d", status);
3667 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003668 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003669 session_param->sme_session_id = adapter->session_id;
3670 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3671 session_param->type_of_persona = type;
3672 session_param->subtype_of_persona = sub_type;
3673 session_param->session_open_cb = hdd_sme_open_session_callback;
3674 session_param->session_close_cb = hdd_sme_close_session_callback;
3675 session_param->callback = callback;
3676 session_param->callback_ctx = callback_ctx;
3677
3678 return 0;
3679}
3680
3681int hdd_vdev_create(struct hdd_adapter *adapter,
3682 csr_roam_completeCallback callback, void *ctx)
3683{
3684 QDF_STATUS status;
3685 int errno;
3686 struct hdd_context *hdd_ctx;
3687 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003688
3689 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003690
3691 /* do vdev create via objmgr */
3692 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003693 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003694 if (errno) {
3695 hdd_err("failed to create objmgr vdev: %d", errno);
3696 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003698
3699 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303700 status = qdf_event_reset(&adapter->qdf_session_open_event);
3701 if (QDF_STATUS_SUCCESS != status) {
3702 hdd_err("failed to reinit session open event");
3703 return -EINVAL;
3704 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003705 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3706 callback, ctx);
3707 if (errno) {
3708 hdd_err("failed to populating SME params");
3709 goto objmgr_vdev_destroy_procedure;
3710 }
3711
3712 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003713 if (QDF_IS_STATUS_ERROR(status)) {
3714 hdd_err("failed to open sme session: %d", status);
3715 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003716 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003717 }
3718
3719 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303720 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3721 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3722 if (QDF_STATUS_SUCCESS != status) {
3723 if (adapter->qdf_session_open_event.force_set) {
3724 /*
3725 * SSR/PDR has caused shutdown, which has forcefully
3726 * set the event. Return without the closing session.
3727 */
3728 adapter->session_id = HDD_SESSION_ID_INVALID;
3729 hdd_err("Session open event forcefully set");
3730 return -EINVAL;
3731 } else {
3732 if (QDF_STATUS_E_TIMEOUT == status)
3733 hdd_err("Session failed to open within timeout period");
3734 else
3735 hdd_err("Failed to wait for session open event(status-%d)",
3736 status);
3737 errno = -ETIMEDOUT;
3738 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3739 goto hdd_vdev_destroy_procedure;
3740 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003741 }
3742
3743 /* firmware ready for component communication, raise vdev_ready event */
3744 errno = hdd_vdev_ready(adapter);
3745 if (errno) {
3746 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003747 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003748 }
3749
Jeff Johnson1b780e42017-10-31 14:11:45 -07003750 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003751
3752 return 0;
3753
3754 /*
3755 * Due to legacy constraints, we need to destroy in the same order as
3756 * create. So, split error handling into 2 cases to accommodate.
3757 */
3758
Krunal Soni4a020c72017-10-30 20:58:40 -07003759objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003760 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003761
3762 return errno;
3763
Krunal Soni4a020c72017-10-30 20:58:40 -07003764hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003765 QDF_BUG(!hdd_vdev_destroy(adapter));
3766
3767 return errno;
3768}
3769
Jeff Johnson9d295242017-08-29 14:39:48 -07003770QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003771{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003772 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003773 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003774 QDF_STATUS status;
3775 int ret_val;
3776
Dustin Brownd28772b2017-03-17 14:16:07 -07003777 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3778 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3779 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003780 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003781
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003782 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003783 status = hdd_register_wext(adapter->dev);
3784 if (QDF_IS_STATUS_ERROR(status)) {
3785 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003786 goto error_register_wext;
3787 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003788 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003789
Himanshu Agarwalb229a142017-12-21 10:16:45 +05303790 hdd_debug("Disabling Green AP");
3791 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev, false);
3792 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
3793
Jeff Johnsond377dce2017-10-04 10:32:42 -07003794 qdf_mem_set(sta_ctx->conn_info.staId,
3795 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303796
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003797 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003798 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303799 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003800 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003801 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003802 hdd_ctx->config->OperatingChannel;
3803
3804 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003805 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806
3807 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303808 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003809 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003810 status, status);
3811 goto error_init_txrx;
3812 }
3813
3814 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3815
3816 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303817 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003818 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003819 status, status);
3820 goto error_wmm_init;
3821 }
3822
3823 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3824
Jeff Johnson1b780e42017-10-31 14:11:45 -07003825 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 WMI_PDEV_PARAM_BURST_ENABLE,
3827 hdd_ctx->config->enableSifsBurst,
3828 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003829 if (ret_val)
3830 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003831
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303832 /*
3833 * In case of USB tethering, LRO is disabled. If SSR happened
3834 * during that time, then as part of SSR init, do not enable
3835 * the LRO again. Keep the LRO state same as before SSR.
3836 */
3837 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003838 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303839
3840 /* rcpi info initialization */
3841 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3842
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303843 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845error_wmm_init:
3846 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3847 hdd_deinit_tx_rx(adapter);
3848error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003849 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003851 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003852
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003853 return status;
3854}
3855
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303856/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003857 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303858 * @hdd_ctx: global hdd context
3859 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003860 * @rtnl_held: Used to indicate whether or not the caller is holding
3861 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303862 *
3863 * This function De-initializes the STA/P2P/OCB adapter.
3864 *
3865 * Return: None.
3866 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003867static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003868 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003869 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303870{
3871 ENTER_DEV(adapter->dev);
3872
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303873 if (adapter->dev) {
3874 if (rtnl_held)
3875 adapter->dev->wireless_handlers = NULL;
3876 else {
3877 rtnl_lock();
3878 adapter->dev->wireless_handlers = NULL;
3879 rtnl_unlock();
3880 }
3881 }
3882
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303883 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3884 hdd_deinit_tx_rx(adapter);
3885 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3886 }
3887
3888 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3889 hdd_wmm_adapter_close(adapter);
3890 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3891 }
3892
Krunal Sonib51eec72017-11-20 21:53:01 -08003893
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303894 EXIT();
3895}
3896
Krunal Sonib51eec72017-11-20 21:53:01 -08003897void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3898 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003899 bool rtnl_held)
3900{
3901 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303902
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003903 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003904 case QDF_STA_MODE:
3905 case QDF_P2P_CLIENT_MODE:
3906 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003907 case QDF_IBSS_MODE:
3908 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003910 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003911 break;
3912 }
3913
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003914 case QDF_SAP_MODE:
3915 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003917 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003918 break;
3919 }
3920
3921 default:
3922 break;
3923 }
3924
3925 EXIT();
3926}
3927
Jeff Johnson9d295242017-08-29 14:39:48 -07003928static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003929 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930{
Jeff Johnson5505db82017-11-02 21:19:23 -07003931 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932
3933 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003934 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003936 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 return;
3938 }
3939
Rajeev Kumardca5f812016-02-04 17:28:06 -08003940 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303941
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 /*
3943 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3944 * the driver is almost closed and cannot handle either control
3945 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003946 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3947 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948 * is not right. Setting this flag helps hdd_stop() to recognize that
3949 * the interface is closed and restricts any operations on that
3950 */
3951 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3952
3953 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003954 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003955 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003956 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003957 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 /*
3959 * Note that the adapter is no longer valid at this point
3960 * since the memory has been reclaimed
3961 */
3962 }
3963}
3964
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003965static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003966 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967{
Jeff Johnson9d295242017-08-29 14:39:48 -07003968 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003969
Dustin Brown920397d2017-12-13 16:27:50 -08003970 hdd_for_each_adapter(hdd_ctx, adapter) {
3971 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
3972 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303973 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 }
Dustin Brown920397d2017-12-13 16:27:50 -08003976
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303977 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003979
Arun Khandavalli2358d522016-05-16 18:05:37 +05303980#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3981/**
3982 * hdd_set_fw_log_params() - Set log parameters to FW
3983 * @hdd_ctx: HDD Context
3984 * @adapter: HDD Adapter
3985 *
3986 * This function set the FW Debug log level based on the INI.
3987 *
3988 * Return: None
3989 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003990static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003991 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303992{
3993 uint8_t count = 0, numentries = 0,
3994 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3995 uint32_t value = 0;
3996 int ret;
3997
Arun Khandavallifae92942016-08-01 13:31:08 +05303998 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3999 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004000 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304001 return;
4002 }
4003
Arun Khandavallifae92942016-08-01 13:31:08 +05304004 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304005 hdd_ctx->fw_log_settings.dl_type =
4006 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004007 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304008 WMI_DBGLOG_TYPE,
4009 hdd_ctx->config->enableFwLogType,
4010 DBG_CMD);
4011 if (ret != 0)
4012 hdd_err("Failed to enable FW log type ret %d",
4013 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304014
4015 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304016 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004017 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304018 WMI_DBGLOG_LOG_LEVEL,
4019 hdd_ctx->config->enableFwLogLevel,
4020 DBG_CMD);
4021 if (ret != 0)
4022 hdd_err("Failed to enable FW log level ret %d",
4023 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304024
4025 hdd_string_to_u8_array(
4026 hdd_ctx->config->enableFwModuleLogLevel,
4027 moduleloglevel,
4028 &numentries,
4029 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4030
4031 while (count < numentries) {
4032 /*
4033 * FW module log level input string looks like
4034 * below:
4035 * gFwDebugModuleLoglevel=<FW Module ID>,
4036 * <Log Level>,...
4037 * For example:
4038 * gFwDebugModuleLoglevel=
4039 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4040 * Above input string means :
4041 * For FW module ID 1 enable log level 0
4042 * For FW module ID 2 enable log level 1
4043 * For FW module ID 3 enable log level 2
4044 * For FW module ID 4 enable log level 3
4045 * For FW module ID 5 enable log level 4
4046 * For FW module ID 6 enable log level 5
4047 * For FW module ID 7 enable log level 6
4048 */
4049
Nishank Aggarwale239d962017-03-03 12:26:02 +05304050 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4051 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4052 hdd_err("Module id %d and dbglog level %d input length is more than max",
4053 moduleloglevel[count],
4054 moduleloglevel[count + 1]);
4055 return;
4056 }
4057
4058 value = moduleloglevel[count] << 16;
4059 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004060 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304061 WMI_DBGLOG_MOD_LOG_LEVEL,
4062 value, DBG_CMD);
4063 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304064 hdd_err("Failed to enable FW module log level %d ret %d",
4065 value, ret);
4066
4067 count += 2;
4068 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304069
Arun Khandavalli2358d522016-05-16 18:05:37 +05304070}
4071#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004072static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004073 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304074{
4075}
4076
4077#endif
4078
4079/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004080 * hdd_configure_chain_mask() - programs chain mask to firmware
4081 * @adapter: HDD adapter
4082 *
4083 * Return: 0 on success or errno on failure
4084 */
4085static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4086{
4087 int ret_val;
4088 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4089
4090 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4091 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4092 hdd_ctx->config->txchainmask1x1,
4093 hdd_ctx->config->rxchainmask1x1);
4094 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4095 hdd_ctx->config->dual_mac_feature_disable,
4096 hdd_ctx->config->tx_chain_mask_2g,
4097 hdd_ctx->config->rx_chain_mask_2g);
4098 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4099 hdd_ctx->config->tx_chain_mask_5g,
4100 hdd_ctx->config->rx_chain_mask_5g);
4101
4102 if (hdd_ctx->config->enable2x2) {
4103 hdd_info("2x2 enabled. skip chain mask programming");
4104 return 0;
4105 }
4106
4107 if (hdd_ctx->config->txchainmask1x1) {
4108 ret_val = sme_cli_set_command(adapter->session_id,
4109 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4110 hdd_ctx->config->txchainmask1x1,
4111 PDEV_CMD);
4112 if (ret_val)
4113 goto error;
4114 }
4115
4116 if (hdd_ctx->config->rxchainmask1x1) {
4117 ret_val = sme_cli_set_command(adapter->session_id,
4118 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4119 hdd_ctx->config->rxchainmask1x1,
4120 PDEV_CMD);
4121 if (ret_val)
4122 goto error;
4123 }
4124
4125 if (hdd_ctx->lte_coex_ant_share) {
4126 hdd_info("lte ant sharing enabled. skip per band chain mask");
4127 return 0;
4128 }
4129
4130 if (hdd_ctx->config->txchainmask1x1 ||
4131 hdd_ctx->config->rxchainmask1x1) {
4132 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4133 return 0;
4134 }
4135
4136 if (!hdd_ctx->config->dual_mac_feature_disable) {
4137 hdd_info("DBS enabled. skip per band chain mask");
4138 return 0;
4139 }
4140
4141 if (hdd_ctx->config->tx_chain_mask_2g) {
4142 ret_val = sme_cli_set_command(adapter->session_id,
4143 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4144 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4145 if (0 != ret_val)
4146 goto error;
4147 }
4148
4149 if (hdd_ctx->config->rx_chain_mask_2g) {
4150 ret_val = sme_cli_set_command(adapter->session_id,
4151 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4152 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4153 if (0 != ret_val)
4154 goto error;
4155 }
4156
4157 if (hdd_ctx->config->tx_chain_mask_5g) {
4158 ret_val = sme_cli_set_command(adapter->session_id,
4159 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4160 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4161 if (0 != ret_val)
4162 goto error;
4163 }
4164
4165 if (hdd_ctx->config->rx_chain_mask_5g) {
4166 ret_val = sme_cli_set_command(adapter->session_id,
4167 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4168 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4169 if (0 != ret_val)
4170 goto error;
4171 }
4172
4173 return 0;
4174
4175error:
4176 hdd_err("WMI PDEV set param failed %d", ret_val);
4177 return -EINVAL;
4178}
4179
4180/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304181 * hdd_set_fw_params() - Set parameters to firmware
4182 * @adapter: HDD adapter
4183 *
4184 * This function Sets various parameters to fw once the
4185 * adapter is started.
4186 *
4187 * Return: 0 on success or errno on failure
4188 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004189int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304190{
4191 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004192 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304193
4194 ENTER_DEV(adapter->dev);
4195
4196 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4197 if (!hdd_ctx)
4198 return -EINVAL;
4199
Dustin Brown732ab9c2017-06-15 13:24:09 -07004200 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4201 hdd_debug("FTM Mode is active; nothing to do");
4202 return 0;
4203 }
4204
Jeff Johnson1b780e42017-10-31 14:11:45 -07004205 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304206 WMI_PDEV_PARAM_DTIM_SYNTH,
4207 hdd_ctx->config->enable_lprx, PDEV_CMD);
4208 if (ret) {
4209 hdd_err("Failed to set LPRx");
4210 goto error;
4211 }
4212
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304213 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004214 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304215 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4216 hdd_ctx->config->upper_brssi_thresh);
4217
Jeff Johnson1b780e42017-10-31 14:11:45 -07004218 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304219 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4220 hdd_ctx->config->lower_brssi_thresh);
4221
Jeff Johnson1b780e42017-10-31 14:11:45 -07004222 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304223 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4224 hdd_ctx->config->enable_dtim_1chrx);
4225 }
4226
Dustin Brown732ab9c2017-06-15 13:24:09 -07004227 if (hdd_ctx->config->enable2x2) {
4228 hdd_debug("configuring 2x2 mode fw params");
4229
Jeff Johnson1b780e42017-10-31 14:11:45 -07004230 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004231 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4232 hdd_ctx->config->enable_cck_tx_fir_override,
4233 PDEV_CMD);
4234 if (ret) {
4235 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4236 ret);
4237 goto error;
4238 }
4239 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304240#define HDD_DTIM_1CHAIN_RX_ID 0x5
4241#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004242 hdd_debug("configuring 1x1 mode fw params");
4243
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004244 /*
4245 * Disable DTIM 1 chain Rx when in 1x1,
4246 * we are passing two value
4247 * as param_id << 29 | param_value.
4248 * Below param_value = 0(disable)
4249 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004250 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004251 WMI_STA_SMPS_PARAM_CMDID,
4252 HDD_DTIM_1CHAIN_RX_ID <<
4253 HDD_SMPS_PARAM_VALUE_S,
4254 VDEV_CMD);
4255 if (ret) {
4256 hdd_err("DTIM 1 chain set failed %d", ret);
4257 goto error;
4258 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304259
Arun Khandavalli2358d522016-05-16 18:05:37 +05304260#undef HDD_DTIM_1CHAIN_RX_ID
4261#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004262
4263 if (hdd_configure_chain_mask(adapter))
4264 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004265 }
4266
Jeff Johnson1b780e42017-10-31 14:11:45 -07004267 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004268 WMI_PDEV_PARAM_HYST_EN,
4269 hdd_ctx->config->enableMemDeepSleep,
4270 PDEV_CMD);
4271 if (ret) {
4272 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4273 goto error;
4274 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304275
Jeff Johnson1b780e42017-10-31 14:11:45 -07004276 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004277 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4278 hdd_ctx->config->rts_profile,
4279 VDEV_CMD);
4280 if (ret) {
4281 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4282 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304283 }
4284
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004285 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4286
Jeff Johnson1b780e42017-10-31 14:11:45 -07004287 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004288 GEN_VDEV_PARAM_AMSDU,
4289 hdd_ctx->config->max_amsdu_num,
4290 GEN_CMD);
4291 if (ret != 0) {
4292 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4293 goto error;
4294 }
4295
Arun Khandavalli2358d522016-05-16 18:05:37 +05304296 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304297 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004298
Arun Khandavalli2358d522016-05-16 18:05:37 +05304299 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304300
Arun Khandavalli2358d522016-05-16 18:05:37 +05304301error:
4302 return -EINVAL;
4303}
4304
Ryan Hsu07495ea2016-01-21 15:25:39 -08004305/**
4306 * hdd_open_adapter() - open and setup the hdd adatper
4307 * @hdd_ctx: global hdd context
4308 * @session_type: type of the interface to be created
4309 * @iface_name: User-visible name of the interface
4310 * @macAddr: MAC address to assign to the interface
4311 * @name_assign_type: the name of assign type of the netdev
4312 * @rtnl_held: the rtnl lock hold flag
4313 *
4314 * This function open and setup the hdd adpater according to the device
4315 * type request, assign the name, the mac address assigned, and then prepared
4316 * the hdd related parameters, queue, lock and ready to start.
4317 *
4318 * Return: the pointer of hdd adapter, otherwise NULL.
4319 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004320struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004321 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004322 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004323 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004324{
Jeff Johnson9d295242017-08-29 14:39:48 -07004325 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304326 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327
4328 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4329 /*
4330 * Max limit reached on the number of vdevs configured by the
4331 * host. Return error
4332 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304333 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4334 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335 return NULL;
4336 }
4337
4338 if (macAddr == NULL) {
4339 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304340 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341 return NULL;
4342 }
4343 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304344 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304345 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4346 " already exists",
4347 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348 return NULL;
4349 }
4350
4351 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004352 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353 /* Reset locally administered bit if the device mode is STA */
4354 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304355 hdd_info("locally administered bit reset in sta mode: "
4356 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004357 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004358 case QDF_P2P_CLIENT_MODE:
4359 case QDF_P2P_DEVICE_MODE:
4360 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004361 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304362 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004363 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4364 name_assign_type,
4365 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004366
4367 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304368 hdd_err("failed to allocate adapter for session %d",
4369 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004370 return NULL;
4371 }
4372
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004373 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004374 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004375 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004376 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304377 else if (QDF_MONITOR_MODE == session_type)
4378 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004379 else
4380 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4381
4382 adapter->device_mode = session_type;
4383
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 /*
4386 * Workqueue which gets scheduled in IPv4 notification
4387 * callback
4388 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004389 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004390 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004391
4392#ifdef WLAN_NS_OFFLOAD
4393 /*
4394 * Workqueue which gets scheduled in IPv6
4395 * notification callback.
4396 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004397 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 hdd_ipv6_notifier_work_queue);
4399#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004401 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004402 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004403
4404 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004405 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004406 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304407 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4408 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304409
Ravi Joshi1a292562017-05-18 16:28:54 -07004410 /* Initialize NAN Data Interface */
4411 if (QDF_NDI_MODE == session_type) {
4412 status = hdd_init_nan_data_mode(adapter);
4413 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004414 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004415 }
4416
4417 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004418
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004419 case QDF_P2P_GO_MODE:
4420 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004421 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4422 name_assign_type,
4423 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004425 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304426 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427 return NULL;
4428 }
4429
4430 adapter->wdev.iftype =
4431 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004432 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004433 NL80211_IFTYPE_P2P_GO;
4434 adapter->device_mode = session_type;
4435
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004436 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004437 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004439
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004440 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304442 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4443 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304444
4445 /*
4446 * Workqueue which gets scheduled in IPv4 notification
4447 * callback
4448 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004449 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304450 hdd_ipv4_notifier_work_queue);
4451
4452#ifdef WLAN_NS_OFFLOAD
4453 /*
4454 * Workqueue which gets scheduled in IPv6
4455 * notification callback.
4456 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004457 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304458 hdd_ipv6_notifier_work_queue);
4459#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004460 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304461 case QDF_FTM_MODE:
4462 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4463 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004464 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304465 if (NULL == adapter) {
4466 hdd_err("Failed to allocate adapter for FTM mode");
4467 return NULL;
4468 }
4469 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4470 adapter->device_mode = session_type;
4471 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004472 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004473 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004474
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304475 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004476 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304477 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304478 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4479 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304480 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004482 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304483 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004484 return NULL;
4485 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486
hqueaa33ee2017-05-04 17:56:35 +08004487 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4488
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304489 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004490 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004491 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004492 }
4493
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304494 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495 if (NULL != adapter) {
4496 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4497 adapter = NULL;
4498 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004499
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 return NULL;
4501 }
4502
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304503 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004504 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4505 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507 /* Adapter successfully added. Increment the vdev count */
4508 hdd_ctx->current_intf_count++;
4509
Jeff Johnson5880d792016-08-15 13:32:30 -07004510 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511 hdd_ctx->current_intf_count);
4512
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004513 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004514 }
4515
Rajeev Kumardca5f812016-02-04 17:28:06 -08004516 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004517 hdd_err("Interface %s wow debug_fs init failed",
4518 netdev_name(adapter->dev));
4519
4520 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4521 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004522
4523 return adapter;
4524
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004525err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004526 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304527 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528
4529 return NULL;
4530}
4531
Jeff Johnson9d295242017-08-29 14:39:48 -07004532QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004533 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004534{
Dustin Brown920397d2017-12-13 16:27:50 -08004535 /*
4536 * Here we are stopping global bus_bw timer & work per adapter.
4537 *
4538 * The reason is to fix one race condition between
4539 * bus bandwidth work and cleaning up an adapter.
4540 * Under some conditions, it is possible for the bus bandwidth
4541 * work to access a particularly destroyed adapter, leading to
4542 * use-after-free.
4543 */
4544 hdd_debug("wait for bus bw work to flush");
4545 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4546 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004547
Dustin Brown920397d2017-12-13 16:27:50 -08004548 /* cleanup adapter */
4549 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4550 adapter->device_mode);
4551 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4552 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004553
Dustin Brown920397d2017-12-13 16:27:50 -08004554 /* conditionally restart the bw timer */
4555 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004556
Dustin Brown920397d2017-12-13 16:27:50 -08004557 /* Adapter removed. Decrement vdev count */
4558 if (hdd_ctx->current_intf_count != 0)
4559 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004560
Dustin Brown920397d2017-12-13 16:27:50 -08004561 /* Fw will take care incase of concurrency */
4562 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004563}
4564
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004565/**
4566 * hdd_close_all_adapters - Close all open adapters
4567 * @hdd_ctx: Hdd context
4568 * rtnl_held: True if RTNL lock held
4569 *
4570 * Close all open adapters.
4571 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304572 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004573 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004574QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004575{
Dustin Brown920397d2017-12-13 16:27:50 -08004576 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304577 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004578
4579 ENTER();
4580
4581 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004582 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4583 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304584 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004585 adapter->mac_addr.bytes);
4586 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4587
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304588 /* Adapter removed. Decrement vdev count */
4589 if (hdd_ctx->current_intf_count != 0)
4590 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004591 }
Dustin Brown920397d2017-12-13 16:27:50 -08004592 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004593
4594 EXIT();
4595
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304596 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004597}
4598
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004599void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004600{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304601 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004602 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004603
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004604 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004605 case QDF_STA_MODE:
4606 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004607 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004608 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004609 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004610 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004611 break;
4612 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004613 case QDF_SAP_MODE:
4614 case QDF_P2P_GO_MODE:
4615 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004616 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004617 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618 break;
4619 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004620 case QDF_FTM_MODE:
4621 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004622 default:
4623 /*
4624 * wlan_hdd_reset_prob_rspies should not have been called
4625 * for these kind of devices
4626 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004627 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004628 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004629 return;
4630 }
4631
Anurag Chouhanc5548422016-02-24 18:33:27 +05304632 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004633 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004634 updateIE.ieBufferlength = 0;
4635 updateIE.pAdditionIEBuffer = NULL;
4636 updateIE.append = true;
4637 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004638 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004639 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304640 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004641 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004642 }
4643}
4644
Dustin Browndb2a8be2017-12-20 11:49:56 -08004645QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4646 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004647{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304648 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004649 struct hdd_wext_state *pWextState =
4650 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651 union iwreq_data wrqu;
4652 tSirUpdateIE updateIE;
4653 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304654 tsap_Config_t *sap_config;
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304655 bool is_enabled = false;
4656 uint8_t ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004657
4658 ENTER();
4659
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004660 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304661 wlan_hdd_netif_queue_control(adapter,
4662 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4663 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004664 /*
4665 * if this is the last active connection check & stop the
4666 * opportunistic timer first
4667 */
4668 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4669 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4670 policy_mgr_convert_device_mode_to_qdf_type(
4671 adapter->device_mode), NULL) == 1)) ||
4672 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4673 policy_mgr_check_and_stop_opportunistic_timer(
4674 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004675 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004676 case QDF_STA_MODE:
4677 case QDF_P2P_CLIENT_MODE:
4678 case QDF_IBSS_MODE:
4679 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004680 case QDF_NDI_MODE:
4681 if ((QDF_NDI_MODE == adapter->device_mode) ||
4682 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004683 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4684 hdd_is_connecting(
4685 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004686 INIT_COMPLETION(adapter->disconnect_comp_var);
4687 /*
4688 * For NDI do not use pWextState from sta_ctx, if needed
4689 * extract from ndi_ctx.
4690 */
4691 if (QDF_NDI_MODE == adapter->device_mode)
4692 qdf_ret_status = sme_roam_disconnect(
4693 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004694 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004695 eCSR_DISCONNECT_REASON_NDI_DELETE);
4696 else if (pWextState->roamProfile.BSSType ==
4697 eCSR_BSS_TYPE_START_IBSS)
4698 qdf_ret_status = sme_roam_disconnect(
4699 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004700 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004701 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004702 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004703 qdf_ret_status =
4704 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004705 hdd_debug("Send disconnected event to userspace");
4706 wlan_hdd_cfg80211_indicate_disconnect(
4707 adapter->dev, true,
4708 WLAN_REASON_UNSPECIFIED);
4709 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004710 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004711 qdf_ret_status = sme_roam_disconnect(
4712 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004713 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004714 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004715 /* success implies disconnect command got
4716 * queued up successfully
4717 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004718 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4719 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004720 rc = wait_for_completion_timeout(
4721 &adapter->disconnect_comp_var,
4722 msecs_to_jiffies
4723 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004724 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004725 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004726 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004727 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4728 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729 memset(&wrqu, '\0', sizeof(wrqu));
4730 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4731 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4732 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4733 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304734 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004735 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004736
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304737 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304738 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004739
4740#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004741 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004742#endif
4743
4744 hdd_deregister_tx_flow_control(adapter);
4745
4746#ifdef WLAN_NS_OFFLOAD
4747#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004748 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004749#endif
4750#endif
4751
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304752 if (adapter->device_mode == QDF_STA_MODE)
4753 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4754 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004755
4756 if (wlan_hdd_try_disconnect(adapter)) {
4757 hdd_err("Error: Can't disconnect adapter");
4758 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004759 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004760
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304761 ret = hdd_check_green_ap_enable(hdd_ctx, &is_enabled);
4762 if (!ret) {
4763 hdd_debug("Green AP enable status: %d", is_enabled);
4764 if (is_enabled) {
4765 hdd_debug("Enabling Green AP");
4766 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
4767 true);
4768 wlan_green_ap_start(hdd_ctx->hdd_pdev);
4769 }
4770 } else {
4771 hdd_err("Failed to check if Green AP should be enabled or not");
4772 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004773
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304774 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004775 break;
4776
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004777 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004778 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304779 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304780 sap_config = &adapter->session.ap.sap_config;
4781 if (sap_config)
4782 wlansap_reset_sap_config_add_ie(sap_config,
4783 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304784 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004785 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004786
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004787 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004788 if (QDF_SAP_MODE == adapter->device_mode) {
4789 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4790 cds_flush_delayed_work(
4791 &adapter->acs_pending_work);
4792 clear_bit(ACS_PENDING, &adapter->event_flags);
4793 }
4794 }
Krunal Soni22208392017-09-29 18:10:34 -07004795 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004796
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004797 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004798 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004799 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004800 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4801
4802 hdd_deregister_tx_flow_control(adapter);
4803
Kapil Guptac1224bf2017-06-22 21:22:40 +05304804 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004805 mutex_lock(&hdd_ctx->sap_lock);
4806 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304807 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304808 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004809
4810 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004811 status = wlansap_stop_bss(
4812 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004813
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304814 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004815 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004816 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304817 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304818 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304819 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304820 qdf_wait_for_event_completion(
4821 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004822 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004823
Anurag Chouhance0dc992016-02-16 18:18:03 +05304824 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004825 hdd_err("failure waiting for wlansap_stop_bss %d",
4826 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004827 }
4828 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004829 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004830 }
4831 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004832 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4833 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004834 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004835
Anurag Chouhanc5548422016-02-24 18:33:27 +05304836 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004837 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004838 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839 updateIE.ieBufferlength = 0;
4840 updateIE.pAdditionIEBuffer = NULL;
4841 updateIE.append = false;
4842 updateIE.notify = false;
4843 /* Probe bcn reset */
4844 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4845 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304846 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004847 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004848 }
4849 /* Assoc resp reset */
4850 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4851 &updateIE,
4852 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304853 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004854 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004855 }
4856 /* Reset WNI_CFG_PROBE_RSP Flags */
4857 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004858 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004859 qdf_mem_free(adapter->session.ap.beacon);
4860 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304861 /*
4862 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4863 */
4864 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4865 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4866
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304867#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004868 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304869#endif
4870
4871#ifdef WLAN_NS_OFFLOAD
4872#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004873 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304874#endif
4875#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08004876
4877 hdd_vdev_destroy(adapter);
4878
Krunal Sonib51eec72017-11-20 21:53:01 -08004879 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004880 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004881 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004882 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004883 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004884 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 break;
4886 default:
4887 break;
4888 }
4889
Dustin Brown04348372017-12-14 16:13:39 -08004890 if (adapter->scan_info.default_scan_ies) {
4891 qdf_mem_free(adapter->scan_info.default_scan_ies);
4892 adapter->scan_info.default_scan_ies = NULL;
4893 }
4894
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004895 EXIT();
Dustin Brown04348372017-12-14 16:13:39 -08004896
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304897 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004898}
4899
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304900/**
4901 * hdd_deinit_all_adapters - deinit all adapters
4902 * @hdd_ctx: HDD context
4903 * @rtnl_held: True if RTNL lock held
4904 *
4905 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004906void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304907{
Jeff Johnson9d295242017-08-29 14:39:48 -07004908 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304909
4910 ENTER();
4911
Dustin Brown920397d2017-12-13 16:27:50 -08004912 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304913 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304914
4915 EXIT();
4916}
4917
Dustin Browndb2a8be2017-12-20 11:49:56 -08004918QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004919{
Jeff Johnson9d295242017-08-29 14:39:48 -07004920 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004921
4922 ENTER();
4923
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304924 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4925
Dustin Brown920397d2017-12-13 16:27:50 -08004926 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08004927 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004928
4929 EXIT();
4930
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304931 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004932}
4933
Paul Zhang84fa9382017-11-10 21:18:21 +08004934static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4935 struct hdd_adapter *adapter)
4936{
4937 switch (adapter->device_mode) {
4938 case QDF_STA_MODE:
4939 case QDF_P2P_CLIENT_MODE:
4940 case QDF_IBSS_MODE:
4941 case QDF_P2P_DEVICE_MODE:
4942 case QDF_NDI_MODE:
4943 wlan_hdd_scan_abort(adapter);
4944 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4945 if (adapter->device_mode == QDF_STA_MODE)
4946 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4947 adapter->dev);
4948 break;
4949 case QDF_P2P_GO_MODE:
4950 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4951 break;
4952 case QDF_SAP_MODE:
4953 wlan_hdd_undo_acs(adapter);
4954 break;
4955 default:
4956 break;
4957 }
4958}
4959
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004960QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004961{
Jeff Johnson9d295242017-08-29 14:39:48 -07004962 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004963 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004964 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08004965 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004966
4967 ENTER();
4968
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304969 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4970
Dustin Brown920397d2017-12-13 16:27:50 -08004971 hdd_for_each_adapter(hdd_ctx, adapter) {
Yue Ma42654682018-01-11 16:55:24 -08004972 hdd_notice("[SSR] reset adapter with device mode %s(%d)",
4973 hdd_device_mode_to_string(adapter->device_mode),
Yue Mad5b4b9f2017-05-26 16:23:40 -07004974 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304975
4976 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004977 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304978 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004979 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304980
Arun Khandavallicc544b32017-01-30 19:52:16 +05304981 if (hdd_ctx->config->sap_internal_restart &&
4982 adapter->device_mode == QDF_SAP_MODE) {
4983 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304984 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304985 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004986 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08004987 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004988 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004989 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4990 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304991 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304992 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004993 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004994 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995
Paul Zhang84fa9382017-11-10 21:18:21 +08004996 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07004997 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998
4999 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005000 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005001 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5003 hdd_wmm_adapter_close(adapter);
5004 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5005 }
5006
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305007 if (adapter->device_mode == QDF_STA_MODE)
5008 hdd_clear_fils_connection_info(adapter);
5009
Wu Gao3545e642017-07-14 19:24:41 +08005010 if (adapter->device_mode == QDF_SAP_MODE) {
5011 /*
5012 * If adapter is SAP, set session ID to invalid
5013 * since SAP session will be cleanup during SSR.
5014 */
Wu Gao36717432016-11-21 15:09:48 +08005015 wlansap_set_invalid_session(
5016 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5017
Wu Gao3545e642017-07-14 19:24:41 +08005018 wlansap_cleanup_cac_timer(
5019 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5020 }
5021
Yue Ma42654682018-01-11 16:55:24 -08005022 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005023 if (adapter->device_mode == QDF_STA_MODE ||
5024 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005025 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005026 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005027 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005028
5029 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5030 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005031 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5032 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5033 if (adapter->sta_info[sta_id].in_use) {
5034 hdd_debug("[SSR] deregister STA with ID %d",
5035 sta_id);
5036 hdd_softap_deregister_sta(adapter,
5037 sta_id);
5038 adapter->sta_info[sta_id].in_use = 0;
5039 }
5040 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005041 }
5042
Yue Maf9782842017-05-08 12:49:49 -07005043 /* Destroy vdev which will be recreated during reinit. */
5044 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045 }
5046
5047 EXIT();
5048
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305049 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050}
5051
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005052bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305053{
Dustin Brown920397d2017-12-13 16:27:50 -08005054 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305055 bool close_modules = true;
5056
Arun Khandavalliba479c42017-07-26 21:29:40 +05305057 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5058 hdd_info("FTM mode, don't close the module");
5059 return false;
5060 }
5061
Dustin Brown920397d2017-12-13 16:27:50 -08005062 hdd_for_each_adapter(hdd_ctx, adapter) {
5063 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5064 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005065 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305066 close_modules = false;
5067 break;
5068 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305069 }
5070
5071 return close_modules;
5072}
5073
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305074bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305075{
5076 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5077 return true;
5078 else
5079 return false;
5080}
5081
Anurag Chouhanc4092922016-09-08 15:56:11 +05305082#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005083 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305084struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5085 struct ieee80211_channel *channel,
5086 const u8 *bssid, const u8 *ssid,
5087 size_t ssid_len)
5088{
5089 return cfg80211_get_bss(wiphy, channel, bssid,
5090 ssid, ssid_len,
5091 WLAN_CAPABILITY_ESS,
5092 WLAN_CAPABILITY_ESS);
5093}
5094#else
5095struct 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 IEEE80211_BSS_TYPE_ESS,
5103 IEEE80211_PRIVACY_ANY);
5104}
5105#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305106
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305107#if defined CFG80211_CONNECT_BSS || \
5108 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305109#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305110 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305111/**
5112 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5113 * @timeout_reason: reason for connect timeout
5114 *
5115 * This function is used to convert host timeout
5116 * reason enum to kernel specific enum.
5117 *
5118 * Return: nl timeout enum
5119 */
5120static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5121 tSirResultCodes timeout_reason)
5122{
5123 switch (timeout_reason) {
5124 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5125 return NL80211_TIMEOUT_SCAN;
5126 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5127 return NL80211_TIMEOUT_AUTH;
5128 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5129 return NL80211_TIMEOUT_ASSOC;
5130 default:
5131 return NL80211_TIMEOUT_UNSPECIFIED;
5132 }
5133}
5134
5135/**
5136 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5137 * @dev: network device
5138 * @bssid: bssid to which we want to associate
5139 * @timeout_reason: reason for connect timeout
5140 *
5141 * This API is used to send connection timeout reason to supplicant
5142 *
5143 * Return: void
5144 */
5145static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5146 const u8 *bssid,
5147 tSirResultCodes timeout_reason)
5148{
5149 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005150
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305151 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5152
5153 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5154 nl_timeout_reason);
5155}
5156
5157/**
5158 * __hdd_connect_bss() - API to send connection status to supplicant
5159 * @dev: network device
5160 * @bssid: bssid to which we want to associate
5161 * @req_ie: Request Information Element
5162 * @req_ie_len: len of the req IE
5163 * @resp_ie: Response IE
5164 * @resp_ie_len: len of ht response IE
5165 * @status: status
5166 * @gfp: Kernel Flag
5167 * @timeout_reason: reason for connect timeout
5168 *
5169 * Return: void
5170 */
5171static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5172 struct cfg80211_bss *bss, const u8 *req_ie,
5173 size_t req_ie_len, const u8 *resp_ie,
5174 size_t resp_ie_len, int status, gfp_t gfp,
5175 tSirResultCodes timeout_reason)
5176{
5177 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005178
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305179 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5180
5181 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5182 resp_ie, resp_ie_len, status, gfp,
5183 nl_timeout_reason);
5184}
5185#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305186#if defined CFG80211_CONNECT_TIMEOUT || \
5187 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305188static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5189 const u8 *bssid,
5190 tSirResultCodes timeout_reason)
5191{
5192 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5193}
5194#endif
5195
5196static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5197 struct cfg80211_bss *bss, const u8 *req_ie,
5198 size_t req_ie_len, const u8 *resp_ie,
5199 size_t resp_ie_len, int status, gfp_t gfp,
5200 tSirResultCodes timeout_reason)
5201{
5202 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5203 resp_ie, resp_ie_len, status, gfp);
5204}
5205#endif
5206
Abhishek Singha84d3952016-09-13 13:45:05 +05305207/**
5208 * hdd_connect_bss() - API to send connection status to supplicant
5209 * @dev: network device
5210 * @bssid: bssid to which we want to associate
5211 * @req_ie: Request Information Element
5212 * @req_ie_len: len of the req IE
5213 * @resp_ie: Response IE
5214 * @resp_ie_len: len of ht response IE
5215 * @status: status
5216 * @gfp: Kernel Flag
5217 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305218 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305219 *
5220 * The API is a wrapper to send connection status to supplicant
5221 *
5222 * Return: Void
5223 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305224#if defined CFG80211_CONNECT_TIMEOUT || \
5225 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305226static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5227 struct cfg80211_bss *bss, const u8 *req_ie,
5228 size_t req_ie_len, const u8 *resp_ie,
5229 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305230 bool connect_timeout,
5231 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305232{
5233 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305234 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305235 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305236 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5237 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305238}
5239#else
5240static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5241 struct cfg80211_bss *bss, const u8 *req_ie,
5242 size_t req_ie_len, const u8 *resp_ie,
5243 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305244 bool connect_timeout,
5245 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305246{
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#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305251
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305252#if defined(WLAN_FEATURE_FILS_SK)
5253#if defined(CFG80211_CONNECT_DONE) || \
5254 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5255#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5256 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305257/**
5258 * hdd_populate_fils_params() - Populate FILS keys to connect response
5259 * @fils_params: connect response to supplicant
5260 * @fils_kek: FILS kek
5261 * @fils_kek_len: FILS kek length
5262 * @pmk: FILS PMK
5263 * @pmk_len: FILS PMK length
5264 * @pmkid: PMKID
5265 * @fils_seq_num: FILS Seq number
5266 *
5267 * Return: None
5268 */
5269static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5270 *fils_params, const uint8_t *fils_kek,
5271 size_t fils_kek_len, const uint8_t *pmk,
5272 size_t pmk_len, const uint8_t *pmkid,
5273 uint16_t fils_seq_num)
5274{
5275 /* Increament seq number to be used for next FILS */
5276 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5277 fils_params->update_erp_next_seq_num = true;
5278 fils_params->fils_kek = fils_kek;
5279 fils_params->fils_kek_len = fils_kek_len;
5280 fils_params->pmk = pmk;
5281 fils_params->pmk_len = pmk_len;
5282 fils_params->pmkid = pmkid;
5283}
5284#else
5285static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5286 *fils_params, const uint8_t
5287 *fils_kek, size_t fils_kek_len,
5288 const uint8_t *pmk, size_t pmk_len,
5289 const uint8_t *pmkid,
5290 uint16_t fils_seq_num)
5291{ }
5292#endif
5293
Jeff Johnson172237b2017-11-07 15:32:59 -08005294void hdd_update_hlp_info(struct net_device *dev,
5295 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305296{
5297 struct sk_buff *skb;
5298 uint16_t skb_len;
5299 struct llc_snap_hdr_t *llc_hdr;
5300 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305301 uint8_t *hlp_data;
5302 uint16_t hlp_data_len;
5303 struct fils_join_rsp_params *roam_fils_params
5304 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305305 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5306
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305307 if (!roam_fils_params) {
5308 hdd_err("FILS Roam Param NULL");
5309 return;
5310 }
5311
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005312 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305313 hdd_err("FILS HLP Data NULL, len %d",
5314 roam_fils_params->hlp_data_len);
5315 return;
5316 }
5317
5318 hlp_data = roam_fils_params->hlp_data;
5319 hlp_data_len = roam_fils_params->hlp_data_len;
5320
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305321 /* Calculate skb length */
5322 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5323 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5324 if (skb == NULL) {
5325 hdd_err("HLP packet nbuf alloc fails");
5326 return;
5327 }
5328
5329 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5330 QDF_MAC_ADDR_SIZE);
5331 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5332 QDF_MAC_ADDR_SIZE);
5333
5334 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5335 if (IS_SNAP(llc_hdr)) {
5336 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5337 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5338 }
5339
5340 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5341
5342 /*
5343 * This HLP packet is formed from HLP info encapsulated
5344 * in assoc response frame which is AEAD encrypted.
5345 * Hence, this checksum validation can be set unnecessary.
5346 * i.e. network layer need not worry about checksum.
5347 */
5348 skb->ip_summed = CHECKSUM_UNNECESSARY;
5349
5350 status = hdd_rx_packet_cbk(padapter, skb);
5351 if (QDF_IS_STATUS_ERROR(status)) {
5352 hdd_err("Sending HLP packet fails");
5353 return;
5354 }
5355 hdd_debug("send HLP packet to netif successfully");
5356}
5357
5358/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305359 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5360 * @dev: network device
5361 * @bssid: bssid to which we want to associate
5362 * @bss: cfg80211 bss info
5363 * @roam_info: information about connected bss
5364 * @req_ie: Request Information Element
5365 * @req_ie_len: len of the req IE
5366 * @resp_ie: Response IE
5367 * @resp_ie_len: len of ht response IE
5368 * @status: status
5369 * @gfp: allocation flags
5370 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5371 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305372 *
5373 * This API is used as wrapper to send FILS key/sequence number
5374 * params etc. to supplicant in case of FILS connection
5375 *
5376 * Return: None
5377 */
5378static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005379 struct cfg80211_bss *bss,
5380 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305381 const u8 *req_ie, size_t req_ie_len,
5382 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005383 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305384 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305385{
5386 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305387 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5388 struct fils_join_rsp_params *roam_fils_params =
5389 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005390
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305391 qdf_mem_zero(&fils_params, sizeof(fils_params));
5392
5393 if (!roam_fils_params) {
5394 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5395 } else {
5396 fils_params.status = status;
5397 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005398 fils_params.timeout_reason =
5399 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305400 fils_params.req_ie = req_ie;
5401 fils_params.req_ie_len = req_ie_len;
5402 fils_params.resp_ie = resp_ie;
5403 fils_params.resp_ie_len = resp_ie_len;
5404 fils_params.bss = bss;
5405 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5406 roam_fils_params->kek_len,
5407 roam_fils_params->fils_pmk,
5408 roam_fils_params->fils_pmk_len,
5409 roam_fils_params->fils_pmkid,
5410 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305411 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305412 }
5413 hdd_debug("FILS indicate connect status %d seq no %d",
5414 fils_params.status,
5415 fils_params.fils_erp_next_seq_num);
5416
5417 cfg80211_connect_done(dev, &fils_params, gfp);
5418
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305419 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305420 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305421
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305422 /* Clear all the FILS key info */
5423 if (roam_fils_params && roam_fils_params->fils_pmk)
5424 qdf_mem_free(roam_fils_params->fils_pmk);
5425 if (roam_fils_params)
5426 qdf_mem_free(roam_fils_params);
5427 roam_info->fils_join_rsp = NULL;
5428}
5429#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005430static inline void
5431hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005432 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005433 const u8 *req_ie, size_t req_ie_len,
5434 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5435 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305436 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305437{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305438#endif
5439#endif
5440
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305441#if defined(WLAN_FEATURE_FILS_SK) && \
5442 (defined(CFG80211_CONNECT_DONE) || \
5443 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305444/**
5445 * hdd_fils_update_connect_results() - API to send fils connection status to
5446 * supplicant.
5447 * @dev: network device
5448 * @bssid: bssid to which we want to associate
5449 * @bss: cfg80211 bss info
5450 * @roam_info: information about connected bss
5451 * @req_ie: Request Information Element
5452 * @req_ie_len: len of the req IE
5453 * @resp_ie: Response IE
5454 * @resp_ie_len: len of ht response IE
5455 * @status: status
5456 * @gfp: allocation flags
5457 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5458 * @timeout_reason: reason for connect timeout
5459 *
5460 * The API is a wrapper to send connection status to supplicant
5461 *
5462 * Return: 0 if success else failure
5463 */
5464static int hdd_fils_update_connect_results(struct net_device *dev,
5465 const u8 *bssid,
5466 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005467 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305468 size_t req_ie_len, const u8 *resp_ie,
5469 size_t resp_ie_len, u16 status, gfp_t gfp,
5470 bool connect_timeout,
5471 tSirResultCodes timeout_reason)
5472{
5473 ENTER();
5474 if (!roam_info || !roam_info->is_fils_connection)
5475 return -EINVAL;
5476
5477 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5478 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305479 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305480 return 0;
5481}
5482#else
5483static inline int hdd_fils_update_connect_results(struct net_device *dev,
5484 const u8 *bssid,
5485 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005486 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305487 size_t req_ie_len, const u8 *resp_ie,
5488 size_t resp_ie_len, u16 status, gfp_t gfp,
5489 bool connect_timeout,
5490 tSirResultCodes timeout_reason)
5491{
5492 return -EINVAL;
5493}
5494#endif
5495
Anurag Chouhanc4092922016-09-08 15:56:11 +05305496/**
5497 * hdd_connect_result() - API to send connection status to supplicant
5498 * @dev: network device
5499 * @bssid: bssid to which we want to associate
5500 * @roam_info: information about connected bss
5501 * @req_ie: Request Information Element
5502 * @req_ie_len: len of the req IE
5503 * @resp_ie: Response IE
5504 * @resp_ie_len: len of ht response IE
5505 * @status: status
5506 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305507 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305508 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305509 *
5510 * The API is a wrapper to send connection status to supplicant
5511 * and allow runtime suspend
5512 *
5513 * Return: Void
5514 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305515void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005516 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305517 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305518 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305519 bool connect_timeout,
5520 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305521{
Jeff Johnson9d295242017-08-29 14:39:48 -07005522 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305523 struct cfg80211_bss *bss = NULL;
Jingxiang Geb49aa302018-01-17 20:54:15 +08005524 struct hdd_context *hdd_ctx;
5525
5526 hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305527
5528 if (WLAN_STATUS_SUCCESS == status) {
5529 struct ieee80211_channel *chan;
5530 int freq;
5531 int chan_no = roam_info->pBssDesc->channelId;
5532
5533 if (chan_no <= 14)
5534 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005535 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305536 else
5537 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005538 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305539
5540 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5541 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5542 roam_info->u.pConnectedProfile->SSID.ssId,
5543 roam_info->u.pConnectedProfile->SSID.length);
5544 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305545
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305546 if (hdd_fils_update_connect_results(dev, bssid, bss,
5547 roam_info, req_ie, req_ie_len, resp_ie,
5548 resp_ie_len, status, gfp, connect_timeout,
5549 timeout_reason) != 0) {
5550 hdd_connect_bss(dev, bssid, bss, req_ie,
5551 req_ie_len, resp_ie, resp_ie_len,
5552 status, gfp, connect_timeout, timeout_reason);
5553 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305554
Jingxiang Geb49aa302018-01-17 20:54:15 +08005555 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005556 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305557}
5558#else
5559void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005560 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305561 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305562 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305563 bool connect_timeout,
5564 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305565{
Jeff Johnson9d295242017-08-29 14:39:48 -07005566 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305567
Anurag Chouhanc4092922016-09-08 15:56:11 +05305568 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5569 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005570
Jingxiang Geb49aa302018-01-17 20:54:15 +08005571 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005572 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305573}
5574#endif
5575
5576
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005577QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005578{
Jeff Johnson9d295242017-08-29 14:39:48 -07005579 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005580#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305581 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005582#endif
5583 eConnectionState connState;
5584
5585 ENTER();
5586
Dustin Brown920397d2017-12-13 16:27:50 -08005587 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305588 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005589 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305590
Yue Ma42654682018-01-11 16:55:24 -08005591 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5592 hdd_device_mode_to_string(adapter->device_mode),
5593 adapter->device_mode);
5594
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005595 hdd_wmm_init(adapter);
5596
5597 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005598 case QDF_STA_MODE:
5599 case QDF_P2P_CLIENT_MODE:
5600 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005601
5602 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5603 ->conn_info.connState;
5604
Krunal Sonib51eec72017-11-20 21:53:01 -08005605 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005606 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005607 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005608
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005609 /* Indicate disconnect event to supplicant
5610 * if associated previously
5611 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005612 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005613 eConnectionState_IbssConnected == connState ||
5614 eConnectionState_NotConnected == connState ||
5615 eConnectionState_IbssDisconnected == connState ||
5616 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005617 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005618
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005619 memset(&wrqu, '\0', sizeof(wrqu));
5620 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5621 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5622 wireless_send_event(adapter->dev, SIOCGIWAP,
5623 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005624 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005625 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005626
5627 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305628 wlan_hdd_cfg80211_indicate_disconnect(
5629 adapter->dev, false,
5630 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631 } else if (eConnectionState_Connecting == connState) {
5632 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005633 * Indicate connect failure to supplicant if we
5634 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005635 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305636 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305637 NULL, 0, NULL, 0,
5638 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005639 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005640 }
5641
5642 hdd_register_tx_flow_control(adapter,
5643 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005644 hdd_tx_resume_cb,
5645 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646
5647 break;
5648
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005649 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005650 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005651 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305652
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005653 break;
5654
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005655 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005656#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005657 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005658 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5659#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005660 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005661 /* event supplicant to restart */
5662 cfg80211_del_sta(adapter->dev,
5663 (const u8 *)&bcastMac.bytes[0],
5664 GFP_KERNEL);
5665#endif
5666 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305667 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005668 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305669 hdd_set_mon_rx_cb(adapter->dev);
5670 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5671 adapter->mon_bandwidth);
5672 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673 default:
5674 break;
5675 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005676 /*
5677 * Action frame registered in one adapter which will
5678 * applicable to all interfaces
5679 */
5680 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681 }
5682
5683 EXIT();
5684
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305685 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005686}
5687
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005688QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005689 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005690{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305691 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005692 qdf_list_node_t *node;
5693
5694 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005695
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005696 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005697 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005698 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005699
5700 if (QDF_IS_STATUS_ERROR(status))
5701 return status;
5702
5703 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5704
5705 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005706}
5707
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005708QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005709 struct hdd_adapter *current_adapter,
5710 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005711{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305712 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005713 qdf_list_node_t *node;
5714
5715 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005716
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005717 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005718 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005719 &current_adapter->node,
5720 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005721 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005722
5723 if (QDF_IS_STATUS_ERROR(status))
5724 return status;
5725
5726 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5727
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005728 return status;
5729}
5730
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005731QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005732 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005733{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305734 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005735
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005736 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005737 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005738 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005739
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005740 return status;
5741}
5742
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005743QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005744 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005745{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305746 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005747 qdf_list_node_t *node;
5748
5749 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005750
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005751 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005752 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005753 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005754
5755 if (QDF_IS_STATUS_ERROR(status))
5756 return status;
5757
5758 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5759
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005760 return status;
5761}
5762
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005763QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005764 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005765{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305766 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005767
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005768 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005769 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005770 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005771
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005772 return status;
5773}
5774
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005775QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005776 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005777{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305778 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005779
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005780 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005781 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005782 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005783
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005784 return status;
5785}
5786
Jeff Johnson9d295242017-08-29 14:39:48 -07005787struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005788 tSirMacAddr macAddr)
5789{
Jeff Johnson9d295242017-08-29 14:39:48 -07005790 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005791
Dustin Brown920397d2017-12-13 16:27:50 -08005792 hdd_for_each_adapter(hdd_ctx, adapter) {
5793 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5794 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005795 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005796 }
5797
5798 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005799}
5800
Jeff Johnson9d295242017-08-29 14:39:48 -07005801struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005802 uint32_t vdev_id)
5803{
Jeff Johnson9d295242017-08-29 14:39:48 -07005804 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805
Dustin Brown920397d2017-12-13 16:27:50 -08005806 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005807 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005808 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005809 }
5810
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005811 return NULL;
5812}
5813
Abhishek Singh7996eb72015-12-30 17:24:02 +05305814/**
5815 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5816 * the sessionid
5817 * @hdd_ctx: hdd context.
5818 * @sme_session_id: sme session is for the adapter to get.
5819 *
5820 * This function is used to get the adapter with provided session id
5821 *
5822 * Return: adapter pointer if found
5823 *
5824 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005825struct hdd_adapter *
5826hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5827 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305828{
Jeff Johnson9d295242017-08-29 14:39:48 -07005829 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305830
Dustin Brown920397d2017-12-13 16:27:50 -08005831 hdd_for_each_adapter(hdd_ctx, adapter) {
5832 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305833 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305834 }
Dustin Brown920397d2017-12-13 16:27:50 -08005835
Abhishek Singh7996eb72015-12-30 17:24:02 +05305836 return NULL;
5837}
5838
Jeff Johnson9d295242017-08-29 14:39:48 -07005839struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005840 const char *iface_name)
5841{
Jeff Johnson9d295242017-08-29 14:39:48 -07005842 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005843
Dustin Brown920397d2017-12-13 16:27:50 -08005844 hdd_for_each_adapter(hdd_ctx, adapter) {
5845 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07005846 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005847 }
Dustin Brown920397d2017-12-13 16:27:50 -08005848
Naveen Rawat4edb6822017-04-12 10:09:17 -07005849 return NULL;
5850}
5851
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005852/**
5853 * hdd_get_adapter() - to get adapter matching the mode
5854 * @hdd_ctx: hdd context
5855 * @mode: adapter mode
5856 *
5857 * This routine will return the pointer to adapter matching
5858 * with the passed mode.
5859 *
5860 * Return: pointer to adapter or null
5861 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005862struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005863 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005864{
Jeff Johnson9d295242017-08-29 14:39:48 -07005865 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005866
Dustin Brown920397d2017-12-13 16:27:50 -08005867 hdd_for_each_adapter(hdd_ctx, adapter) {
5868 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005869 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005870 }
5871
5872 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005873}
5874
5875/**
5876 * hdd_get_operating_channel() - return operating channel of the device mode
5877 * @hdd_ctx: Pointer to the HDD context.
5878 * @mode: Device mode for which operating channel is required.
5879 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005880 * QDF_STA_MODE,
5881 * QDF_P2P_CLIENT_MODE,
5882 * QDF_SAP_MODE,
5883 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005884 *
5885 * This API returns the operating channel of the requested device mode
5886 *
5887 * Return: channel number. "0" id the requested device is not found OR it is
5888 * not connected.
5889 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005890uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005891 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005892{
Jeff Johnson9d295242017-08-29 14:39:48 -07005893 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005894 uint8_t operatingChannel = 0;
5895
Dustin Brown920397d2017-12-13 16:27:50 -08005896 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005897 if (mode == adapter->device_mode) {
5898 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005899 case QDF_STA_MODE:
5900 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005901 if (hdd_conn_is_connected
5902 (WLAN_HDD_GET_STATION_CTX_PTR
5903 (adapter))) {
5904 operatingChannel =
5905 (WLAN_HDD_GET_STATION_CTX_PTR
5906 (adapter))->conn_info.
5907 operationChannel;
5908 }
5909 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005910 case QDF_SAP_MODE:
5911 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005912 /* softap connection info */
5913 if (test_bit
5914 (SOFTAP_BSS_STARTED,
5915 &adapter->event_flags))
5916 operatingChannel =
5917 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005918 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005919 break;
5920 default:
5921 break;
5922 }
5923
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005924 /* Found the device of interest. break the loop */
5925 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005926 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005927 }
Dustin Brown920397d2017-12-13 16:27:50 -08005928
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005929 return operatingChannel;
5930}
5931
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005932static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005933 hdd_ctx)
5934{
Jeff Johnson9d295242017-08-29 14:39:48 -07005935 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005936
5937 ENTER();
5938
Dustin Brown920397d2017-12-13 16:27:50 -08005939 hdd_for_each_adapter(hdd_ctx, adapter) {
5940 if (adapter->device_mode == QDF_STA_MODE ||
5941 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5942 adapter->device_mode == QDF_IBSS_MODE ||
5943 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5944 adapter->device_mode == QDF_SAP_MODE ||
5945 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005946 wlan_hdd_cfg80211_deregister_frames(adapter);
5947 hdd_unregister_wext(adapter->dev);
5948 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005949 }
5950
5951 EXIT();
5952
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305953 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954}
5955
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005956QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005957{
Jeff Johnson9d295242017-08-29 14:39:48 -07005958 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005959
5960 ENTER();
5961
Dustin Brown920397d2017-12-13 16:27:50 -08005962 hdd_for_each_adapter(hdd_ctx, adapter) {
5963 if (adapter->device_mode == QDF_STA_MODE ||
5964 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5965 adapter->device_mode == QDF_IBSS_MODE ||
5966 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5967 adapter->device_mode == QDF_SAP_MODE ||
5968 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005969 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005970 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05305971 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005972 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005973 }
5974
5975 EXIT();
5976
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305977 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005978}
5979
Dustin Brownf27bce82016-11-03 12:52:27 -07005980/**
5981 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5982 * adapters
5983 * @hdd_ctx: The HDD context containing the adapters to operate on
5984 *
5985 * return: QDF_STATUS_SUCCESS
5986 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005987static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005988{
Jeff Johnson9d295242017-08-29 14:39:48 -07005989 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005990 int err;
5991
5992 ENTER();
5993
Dustin Brown920397d2017-12-13 16:27:50 -08005994 hdd_for_each_adapter(hdd_ctx, adapter) {
5995 if (adapter->device_mode == QDF_STA_MODE ||
5996 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5997 adapter->device_mode == QDF_IBSS_MODE ||
5998 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5999 adapter->device_mode == QDF_SAP_MODE ||
6000 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006001 err = wlan_hdd_sched_scan_stop(adapter->dev);
6002 if (err)
6003 hdd_err("Unable to stop scheduled scan");
6004 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006005 }
6006
6007 EXIT();
6008
6009 return QDF_STATUS_SUCCESS;
6010}
6011
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006012#ifdef WLAN_NS_OFFLOAD
6013/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006014 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015 * @hdd_ctx: Pointer to hdd context
6016 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006017 * Unregister for IPv6 address change notifications.
6018 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006019 * Return: None
6020 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006021static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006022{
6023 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006024}
6025
6026/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006027 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006028 * @hdd_ctx: Pointer to hdd context
6029 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006030 * Register for IPv6 address change notifications.
6031 *
6032 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006033 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006034static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006035{
6036 int ret;
6037
6038 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6039 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006040 if (ret) {
6041 hdd_err("Failed to register IPv6 notifier: %d", ret);
6042 goto out;
6043 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006045 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006046out:
6047 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006048}
6049#else
6050/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006051 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006052 * @hdd_ctx: Pointer to hdd context
6053 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006054 * Unregister for IPv6 address change notifications.
6055 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006056 * Return: None
6057 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006058static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006059{
6060}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006061
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006063 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006064 * @hdd_ctx: Pointer to hdd context
6065 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006066 * Register for IPv6 address change notifications.
6067 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006068 * Return: None
6069 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006070static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006071{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006072 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073}
6074#endif
6075
6076/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006077 * hdd_register_notifiers - Register netdev notifiers.
6078 * @hdd_ctx: HDD context
6079 *
6080 * Register netdev notifiers like IPv4 and IPv6.
6081 *
6082 * Return: 0 on success and errno on failure
6083 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006084static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006085{
6086 int ret;
6087
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006088 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6089 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306090 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006091
6092 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6093 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6094 if (ret) {
6095 hdd_err("Failed to register IPv4 notifier: %d", ret);
6096 goto unregister_ip6_notifier;
6097 }
6098
6099 return 0;
6100
6101unregister_ip6_notifier:
6102 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006103out:
6104 return ret;
6105
6106}
6107
6108/**
6109 * hdd_unregister_notifiers - Unregister netdev notifiers.
6110 * @hdd_ctx: HDD context
6111 *
6112 * Unregister netdev notifiers like IPv4 and IPv6.
6113 *
6114 * Return: None.
6115 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006116void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006117{
6118 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6119
6120 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006121}
6122
6123/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006124 * hdd_exit_netlink_services - Exit netlink services
6125 * @hdd_ctx: HDD context
6126 *
6127 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6128 * nl service.
6129 *
6130 * Return: None.
6131 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006132static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006133{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006134 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006135 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006136 ptt_sock_deactivate_svc();
6137
6138 nl_srv_exit();
6139}
6140
6141/**
6142 * hdd_init_netlink_services- Init netlink services
6143 * @hdd_ctx: HDD context
6144 *
6145 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6146 * nl service.
6147 *
6148 * Return: 0 on success and errno on failure.
6149 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006150static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006151{
6152 int ret;
6153
Ryan Hsuceddceb2016-04-28 10:20:14 -07006154 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006155 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006156 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006157 goto out;
6158 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006159 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006160
Naveen Rawat910726a2017-03-06 11:42:51 -08006161 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006162 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006163 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006164 goto err_nl_srv;
6165 }
6166
6167 ret = ptt_sock_activate_svc();
6168 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006169 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006170 goto err_nl_srv;
6171 }
6172
6173 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006174 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006175 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006176
6177 ret = cnss_diag_activate_service();
6178 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006179 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006180 goto err_close_cesium;
6181 }
6182
6183 return 0;
6184
6185err_close_cesium:
6186 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006187 ptt_sock_deactivate_svc();
6188err_nl_srv:
6189 nl_srv_exit();
6190out:
6191 return ret;
6192}
6193
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006194/**
6195 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6196 * @hdd_ctx: HDD context.
6197 *
6198 * Destroy RX wakelock.
6199 *
6200 * Return: None.
6201 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006202static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006203{
6204 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6205}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006206
6207/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006208 * hdd_rx_wake_lock_create() - Create RX wakelock
6209 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006210 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006211 * Create RX wakelock.
6212 *
6213 * Return: None.
6214 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006215static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006216{
6217 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6218}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006219
6220/**
Houston Hoffman160db392016-10-10 17:37:51 -07006221 * hdd_context_deinit() - Deinitialize HDD context
6222 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006223 *
Houston Hoffman160db392016-10-10 17:37:51 -07006224 * Deinitialize HDD context along with all the feature specific contexts but
6225 * do not free hdd context itself. Caller of this API is supposed to free
6226 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006227 *
Houston Hoffman160db392016-10-10 17:37:51 -07006228 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006229 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006230static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006231{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306232 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6233
Houston Hoffman160db392016-10-10 17:37:51 -07006234 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006235
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006236 hdd_sap_context_destroy(hdd_ctx);
6237
6238 hdd_rx_wake_lock_destroy(hdd_ctx);
6239
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006240 hdd_scan_context_destroy(hdd_ctx);
6241
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006242 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006243
Houston Hoffman160db392016-10-10 17:37:51 -07006244 return 0;
6245}
6246
6247/**
6248 * hdd_context_destroy() - Destroy HDD context
6249 * @hdd_ctx: HDD context to be destroyed.
6250 *
6251 * Free config and HDD context as well as destroy all the resources.
6252 *
6253 * Return: None
6254 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006255static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006256{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006257 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306258
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306259 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6260
Houston Hoffman160db392016-10-10 17:37:51 -07006261 hdd_context_deinit(hdd_ctx);
6262
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306263 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006264 hdd_ctx->config = NULL;
6265
6266 wiphy_free(hdd_ctx->wiphy);
6267}
6268
6269/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306270 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6271 *
6272 * This function is used to destroy bug report lock
6273 *
6274 * Return: None
6275 */
6276static void wlan_destroy_bug_report_lock(void)
6277{
6278 p_cds_contextType p_cds_context;
6279
6280 p_cds_context = cds_get_global_context();
6281 if (!p_cds_context) {
6282 hdd_err("cds context is NULL");
6283 return;
6284 }
6285
6286 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6287}
6288
6289/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006290 * hdd_wlan_exit() - HDD WLAN exit function
6291 * @hdd_ctx: Pointer to the HDD Context
6292 *
6293 * This is the driver exit point (invoked during rmmod)
6294 *
6295 * Return: None
6296 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006297static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006298{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006299 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306300 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301
6302 ENTER();
6303
Dustin Brown6f427922017-09-19 12:19:00 -07006304 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306305
6306 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006307
Prashanth Bhattaab004382016-10-11 16:08:11 -07006308 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006309
6310#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306311 if (QDF_TIMER_STATE_RUNNING ==
6312 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6313 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006314 }
6315
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306316 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306317 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006318 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006319 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006320 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6321 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6322 hdd_ctx->last_acs_channel_list = NULL;
6323 hdd_ctx->num_of_channels = 0;
6324 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006326
Arun Khandavallifae92942016-08-01 13:31:08 +05306327 mutex_lock(&hdd_ctx->iface_change_lock);
6328 driver_status = hdd_ctx->driver_status;
6329 mutex_unlock(&hdd_ctx->iface_change_lock);
6330
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006331 /*
6332 * Powersave Offload Case
6333 * Disable Idle Power Save Mode
6334 */
6335 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006336 /* clear the scan queue in all the scenarios */
6337 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006338
Arun Khandavallifae92942016-08-01 13:31:08 +05306339 if (driver_status != DRIVER_MODULES_CLOSED) {
6340 hdd_unregister_wext_all_adapters(hdd_ctx);
6341 /*
6342 * Cancel any outstanding scan requests. We are about to close
6343 * all of our adapters, but an adapter structure is what SME
6344 * passes back to our callback function. Hence if there
6345 * are any outstanding scan requests then there is a
6346 * race condition between when the adapter is closed and
6347 * when the callback is invoked. We try to resolve that
6348 * race condition here by canceling any outstanding scans
6349 * before we close the adapters.
6350 * Note that the scans may be cancelled in an asynchronous
6351 * manner, so ideally there needs to be some kind of
6352 * synchronization. Rather than introduce a new
6353 * synchronization here, we will utilize the fact that we are
6354 * about to Request Full Power, and since that is synchronized,
6355 * the expectation is that by the time Request Full Power has
6356 * completed, all scans will be cancelled
6357 */
6358 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006359 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006360 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006361 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006362 }
6363
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306364 unregister_netdevice_notifier(&hdd_netdev_notifier);
6365
Dustin Brown36e24e22017-12-21 12:34:13 -08006366 hdd_close_all_adapters(hdd_ctx, false);
6367
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006368 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306369
Dustin Brown021cecd2017-12-11 13:56:43 -08006370 hdd_driver_memdump_deinit();
6371
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306372 qdf_nbuf_deinit_replenish_timer();
6373
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306374 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6375 hdd_info("Release wakelock for monitor mode!");
6376 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6377 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6378 }
6379
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306380 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6381 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6382 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6383
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006384 /*
6385 * Close CDS
6386 * This frees pMac(HAL) context. There should not be any call
6387 * that requires pMac access after this.
6388 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006389
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006390 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006391
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006392 hdd_ipa_cleanup(hdd_ctx);
6393
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306394 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306395 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306396 /*
6397 * If there is re_init failure wiphy would have already de-registered
6398 * check the wiphy status before un-registering again
6399 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306400 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306401 wiphy_unregister(wiphy);
6402 wlan_hdd_cfg80211_deinit(wiphy);
6403 hdd_lpass_notify_stop(hdd_ctx);
6404 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006405
Arun Khandavallifae92942016-08-01 13:31:08 +05306406 hdd_exit_netlink_services(hdd_ctx);
6407 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306408#ifdef FEATURE_WLAN_CH_AVOID
6409 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6410#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306411
Abhishek Singhe9068f12017-03-31 14:14:52 +05306412 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6413 if (driver_status)
6414 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006415
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006416 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006417}
6418
6419void __hdd_wlan_exit(void)
6420{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006421 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006422
6423 ENTER();
6424
Anurag Chouhan6d760662016-02-20 16:05:43 +05306425 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006426 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006427 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006428 EXIT();
6429 return;
6430 }
6431
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006432 /* Do all the cleanup before deregistering the driver */
6433 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006434
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006435 EXIT();
6436}
6437
6438#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006439/**
6440 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006441 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006442 *
6443 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6444 * Then new ACS request will do a fresh scan without reusing the cached
6445 * scan information.
6446 *
6447 * Return: void
6448 */
Tang Yingying523322d2017-01-17 23:28:43 +08006449static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006451 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006452
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006453 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006454 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006455 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6456 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6457 hdd_ctx->last_acs_channel_list = NULL;
6458 hdd_ctx->num_of_channels = 0;
6459 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006460
6461 if (!hdd_ctx->hHal)
6462 return;
6463 sme_scan_flush_result(hdd_ctx->hHal);
6464}
6465#endif
6466
6467#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006468int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6469 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006470{
6471 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306472 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006473 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006474
6475 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6476
6477 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306478 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006479 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306480
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006481 if (!hdd_ctx->hHal)
6482 return -EINVAL;
6483
Jeff Johnsone7672e72017-10-21 15:10:04 -07006484 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006485 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306486 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006487 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006488 return -EINVAL;
6489 }
6490
6491 return 0;
6492}
6493#endif
6494
6495/**
6496 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6497 * @state: state
6498 *
6499 * This function notifies FW with modem power status
6500 *
6501 * Return: 0 if successful, error number otherwise
6502 */
6503int hdd_wlan_notify_modem_power_state(int state)
6504{
6505 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306506 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006507 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006508
Anurag Chouhan6d760662016-02-20 16:05:43 +05306509 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006510 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306511 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006512 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306513
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514 if (!hdd_ctx->hHal)
6515 return -EINVAL;
6516
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306517 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6518 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006519 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006520 state);
6521 return -EINVAL;
6522 }
6523 return 0;
6524}
6525
6526/**
6527 *
6528 * hdd_post_cds_enable_config() - HDD post cds start config helper
6529 * @adapter - Pointer to the HDD
6530 *
6531 * Return: None
6532 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006533QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006534{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306535 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006536
6537 /*
6538 * Send ready indication to the HDD. This will kick off the MAC
6539 * into a 'running' state and should kick off an initial scan.
6540 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306541 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6542 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006543 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6544 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306545 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006546 }
6547
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306548 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006549}
6550
6551/* wake lock APIs for HDD */
6552void hdd_prevent_suspend(uint32_t reason)
6553{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306554 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006555}
6556
6557void hdd_allow_suspend(uint32_t reason)
6558{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306559 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006560}
6561
6562void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6563{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306564 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6565 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006566}
6567
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006568/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006569QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006570{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006571
Amar Singhal6f8592b2017-04-26 14:31:58 -07006572 return sme_init_chan_list(hdd_ctx->hHal,
6573 hdd_ctx->reg.alpha2,
6574 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006575}
6576
6577/**
6578 * hdd_is_5g_supported() - check if hardware supports 5GHz
6579 * @hdd_ctx: Pointer to the hdd context
6580 *
6581 * HDD function to know if hardware supports 5GHz
6582 *
6583 * Return: true if hardware supports 5GHz
6584 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006585bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006586{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006587 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006588 return true;
6589
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006590 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006591 return true;
6592 else
6593 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594}
6595
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006596static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006597{
6598 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006599 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006600
6601 wiphy = hdd_ctx->wiphy;
6602
6603 /*
6604 * The channel information in
6605 * wiphy needs to be initialized before wiphy registration
6606 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006607 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6608 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006609 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006610 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006611 }
6612
6613#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6614 wiphy->wowlan = &wowlan_support_reg_init;
6615#else
6616 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6617 WIPHY_WOWLAN_MAGIC_PKT |
6618 WIPHY_WOWLAN_DISCONNECT |
6619 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6620 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6621 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6622 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6623 WIPHY_WOWLAN_RFKILL_RELEASE;
6624
6625 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6626 WOW_MAX_FILTERS_PER_LIST);
6627 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6628 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6629#endif
6630
6631 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006632 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306633 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006634 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306635 return ret_val;
6636 }
6637
Amar Singhal5cccafe2017-02-15 12:42:58 -08006638 if (!hdd_ctx->reg_offload)
6639 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006640
Amar Singhale4f28ee2015-10-21 14:36:56 -07006641 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006642}
6643
Mohit Khannaca4173b2017-09-12 21:52:19 -07006644#ifdef MSM_PLATFORM
6645/**
6646 * hdd_display_periodic_stats() - Function to display periodic stats
6647 * @hdd_ctx - handle to hdd context
6648 * @bool data_in_interval - true, if data detected in bw time interval
6649 *
6650 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6651 * Stats show up in wlan driver logs.
6652 *
6653 * Returns: None
6654 */
6655static inline
6656void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6657 bool data_in_interval)
6658{
6659 static u32 counter;
6660 static bool data_in_time_period;
6661 ol_txrx_pdev_handle pdev;
6662
6663 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6664 return;
6665
6666 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6667 if (!pdev) {
6668 hdd_err("pdev is NULL");
6669 return;
6670 }
6671
6672 counter++;
6673 if (data_in_interval)
6674 data_in_time_period = data_in_interval;
6675
6676 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6677 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6678 if (data_in_time_period) {
6679 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6680 CDP_TXRX_PATH_STATS,
6681 QDF_STATS_VERBOSITY_LEVEL_LOW);
6682 wlan_hdd_display_netif_queue_history
6683 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6684 qdf_dp_trace_dump_stats();
6685 }
6686 counter = 0;
6687 data_in_time_period = false;
6688 }
6689}
6690
Ravi Joshie2331e82015-07-01 18:18:54 -07006691/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006692 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006693 * @hdd_ctx - handle to hdd context
6694 * @tx_packets - transmit packet count
6695 * @rx_packets - receive packet count
6696 *
6697 * The function controls the bus bandwidth and dynamic control of
6698 * tcp delayed ack configuration
6699 *
6700 * Returns: None
6701 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006702
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006703static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006704 const uint64_t tx_packets,
6705 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006706{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006707 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006708 uint64_t temp_rx = 0;
6709 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006710 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006711 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006712 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006713 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006714 uint16_t index = 0;
6715 bool vote_level_change = false;
6716 bool rx_level_change = false;
6717 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006718
Mohit Khannaca4173b2017-09-12 21:52:19 -07006719 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006720 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006721 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006722 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006723 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006724 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006725 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006726 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006727
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006728 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006729 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6730 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006732 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006733 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306734 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306735 if (hdd_ctx->hbw_requested) {
6736 pld_remove_pm_qos(hdd_ctx->parent_dev);
6737 hdd_ctx->hbw_requested = false;
6738 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306739 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006740 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006741 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306742 if (!hdd_ctx->hbw_requested) {
6743 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6744 hdd_ctx->hbw_requested = true;
6745 }
6746
Nirav Shah3bbfa512016-05-12 16:43:49 +05306747 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006748 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006749 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006750 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006751 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006752
Mohit Khannaf8f96822017-05-17 17:11:59 -07006753 qdf_dp_trace_throttle_live_mode(
6754 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6755
Mohit Khannae71e2262015-11-10 09:37:24 -08006756 /* fine-tuning parameters for RX Flows */
6757 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6758
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006759 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006760
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306761 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6762 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6763 else
6764 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6765
Ravi Joshifed83572016-10-07 16:20:37 -07006766 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6767 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6768 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6769 next_rx_level = WLAN_SVC_TP_HIGH;
6770 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006771 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006772 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006773 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006774 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006776 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006777 struct wlan_rx_tp_data rx_tp_data = {0};
6778
Ravi Joshie2331e82015-07-01 18:18:54 -07006779 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006780 next_rx_level, temp_rx);
6781 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006782 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006783 /* Send throughput indication only if it is enabled.
6784 * Disabling tcp_del_ack will revert the tcp stack behavior
6785 * to default delayed ack. Note that this will disable the
6786 * dynamic delayed ack mechanism across the system
6787 */
6788 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006789 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6790
Mohit Khanna6272fb682017-04-13 09:34:36 -07006791 if (hdd_ctx->config->enable_tcp_adv_win_scale)
6792 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6793
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006794 rx_tp_data.level = next_rx_level;
6795 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6796 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6797 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798 }
6799
Mohit Khannae71e2262015-11-10 09:37:24 -08006800 /* fine-tuning parameters for TX Flows */
6801 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6802 hdd_ctx->prev_tx = tx_packets;
6803 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6804 next_tx_level = WLAN_SVC_TP_HIGH;
6805 else
6806 next_tx_level = WLAN_SVC_TP_LOW;
6807
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006808 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006809 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6810 next_tx_level, temp_tx);
6811 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006812 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306813 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6814 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006815 &next_tx_level,
6816 sizeof(next_tx_level));
6817 }
6818
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006819 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006820 if (vote_level_change || tx_level_change || rx_level_change) {
6821 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6822 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6823 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6824 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6825 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6826 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6827 hdd_ctx->hdd_txrx_hist_idx++;
6828 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6829 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07006830
6831 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006832}
6833
6834#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306835static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006836{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006837 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306838 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006839 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306840 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306841 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6842 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006843 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306844 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006845 bool connected = false;
6846 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6847
Prashanth Bhattaab004382016-10-11 16:08:11 -07006848 if (wlan_hdd_validate_context(hdd_ctx))
6849 return;
6850
Jeff Johnson214671b2017-10-30 19:45:23 -07006851 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006852 goto restart_timer;
6853
Dustin Brown920397d2017-12-13 16:27:50 -08006854 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05306855 /*
6856 * Validate magic so we don't end up accessing
6857 * an invalid adapter.
6858 */
6859 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6860 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006861
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006862 if ((adapter->device_mode == QDF_STA_MODE ||
6863 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6865 != eConnectionState_Associated) {
6866
6867 continue;
6868 }
6869
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006870 if ((adapter->device_mode == QDF_SAP_MODE ||
6871 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006872 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006873
6874 continue;
6875 }
6876
6877 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6878 adapter->prev_tx_packets);
6879 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6880 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306881
6882 if (adapter->device_mode == QDF_SAP_MODE ||
6883 adapter->device_mode == QDF_P2P_GO_MODE ||
6884 adapter->device_mode == QDF_IBSS_MODE) {
6885
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006886 ret = cdp_get_intra_bss_fwd_pkts_count(
6887 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006888 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306889 &fwd_tx_packets, &fwd_rx_packets);
6890 if (ret == A_OK) {
6891 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6892 fwd_tx_packets,
6893 adapter->prev_fwd_tx_packets);
6894 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6895 fwd_tx_packets,
6896 adapter->prev_fwd_rx_packets);
6897 }
6898 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006899
6900 total_rx += adapter->stats.rx_packets;
6901 total_tx += adapter->stats.tx_packets;
6902
6903 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6904 adapter->prev_tx_packets = adapter->stats.tx_packets;
6905 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306906 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6907 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006908 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6909 connected = true;
6910 }
6911
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306912 /* add intra bss forwarded tx and rx packets */
6913 tx_packets += fwd_tx_packets_diff;
6914 rx_packets += fwd_rx_packets_diff;
6915
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006916 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6917 tx_packets += (uint64_t)ipa_tx_packets;
6918 rx_packets += (uint64_t)ipa_rx_packets;
6919
Yun Park2aa880c2017-08-22 10:58:10 -07006920 if (adapter) {
6921 adapter->stats.tx_packets += ipa_tx_packets;
6922 adapter->stats.rx_packets += ipa_rx_packets;
6923 }
6924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006925 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006926 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006927 return;
6928 }
6929
Yuanyuan Liu13738502016-04-06 17:41:37 -07006930 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006931
6932 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6933 hdd_ipa_uc_stat_request(adapter, 2);
6934
Jingxiang Gec64e1932017-08-22 14:38:59 +08006935restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006936 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006937 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006938 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306939 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006940 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006941 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006942}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006943
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306944/**
6945 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6946 * @arg: Argument of timer function
6947 *
6948 * Schedule a workqueue in this function where all the processing is done.
6949 *
6950 * Return: None.
6951 */
6952static void __hdd_bus_bw_cbk(void *arg)
6953{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006954 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306955
6956 if (wlan_hdd_validate_context(hdd_ctx))
6957 return;
6958
6959 schedule_work(&hdd_ctx->bus_bw_work);
6960}
6961
6962/**
6963 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6964 * @arg: Argument of timer function
6965 *
6966 * Return: None.
6967 */
6968static void hdd_bus_bw_cbk(void *arg)
6969{
6970 cds_ssr_protect(__func__);
6971 __hdd_bus_bw_cbk(arg);
6972 cds_ssr_unprotect(__func__);
6973}
6974
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006975int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006976{
6977 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306978 INIT_WORK(&hdd_ctx->bus_bw_work,
6979 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006980 hdd_ctx->bus_bw_timer_running = false;
6981 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306982 qdf_timer_init(NULL,
6983 &hdd_ctx->bus_bw_timer,
6984 hdd_bus_bw_cbk, (void *)hdd_ctx,
6985 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006986
6987 return 0;
6988}
6989
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006990void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006991{
Dustin Brownfce08d12017-01-17 16:29:38 -08006992 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006993 hdd_reset_tcp_delack(hdd_ctx);
6994
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006995 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306996 cancel_work_sync(&hdd_ctx->bus_bw_work);
6997 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006998 hdd_ctx->bus_bw_timer_running = false;
6999 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007000}
Lin Baic5c06882017-09-21 13:58:43 +08007001
7002void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7003{
7004 if (hdd_ctx)
7005 cancel_work_sync(&hdd_ctx->bus_bw_work);
7006}
jiadcdaf9bd2017-10-26 12:20:21 +08007007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007008#endif
7009
7010/**
Nirav Shahed34b212016-04-25 10:59:16 +05307011 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7012 * @hdd_ctx: hdd context
7013 *
7014 * Return: 0 for success or error code
7015 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007016static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307017{
7018 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7019 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7020 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007021 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307022 return -ENOMEM;
7023 }
7024 return 0;
7025}
7026
7027/**
7028 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7029 * @hdd_ctx: hdd context
7030 *
7031 * Return: none
7032 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007033void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307034{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307035 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7036 return;
7037
7038 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7039 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307040}
7041
Nirav Shahda008342016-05-17 18:50:40 +05307042static uint8_t *convert_level_to_string(uint32_t level)
7043{
7044 switch (level) {
7045 /* initialize the wlan sub system */
7046 case WLAN_SVC_TP_NONE:
7047 return "NONE";
7048 case WLAN_SVC_TP_LOW:
7049 return "LOW";
7050 case WLAN_SVC_TP_MEDIUM:
7051 return "MED";
7052 case WLAN_SVC_TP_HIGH:
7053 return "HIGH";
7054 default:
7055 return "INVAL";
7056 }
7057}
7058
Nirav Shahed34b212016-04-25 10:59:16 +05307059
7060/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007061 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7062 * @hdd_ctx: hdd context
7063 *
7064 * Return: none
7065 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007066void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007067{
7068 int i;
7069
7070#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007071 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307072 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007073 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007074 hdd_ctx->config->busBandwidthHighThreshold,
7075 hdd_ctx->config->busBandwidthMediumThreshold,
7076 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007077 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307078 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007079 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007080 hdd_ctx->config->tcpDelackThresholdHigh,
7081 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007082 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307083 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007084#endif
7085
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007086 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307087 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7088
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007089 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007090
7091 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007092 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007093 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07007094 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007095 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7096 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007097 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007098 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7099 convert_level_to_string(
7100 hdd_ctx->hdd_txrx_hist[i].
7101 next_vote_level),
7102 convert_level_to_string(
7103 hdd_ctx->hdd_txrx_hist[i].
7104 next_rx_level),
7105 convert_level_to_string(
7106 hdd_ctx->hdd_txrx_hist[i].
7107 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007108 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007109}
7110
7111/**
7112 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7113 * @hdd_ctx: hdd context
7114 *
7115 * Return: none
7116 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007117void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007118{
7119 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307120 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7121 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007122}
7123
Mohit Khannaca4173b2017-09-12 21:52:19 -07007124/* length of the netif queue log needed per adapter */
7125#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7126
7127/**
7128 *
7129 * hdd_display_netif_queue_history_compact() - display compact netifq history
7130 * @hdd_ctx: hdd context
7131 *
7132 * Return: none
7133 */
7134static void
7135hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7136{
7137 int adapter_num = 0;
7138 int i;
7139 int bytes_written;
7140 u32 tbytes;
7141 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007142 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007143 char *comb_log_str;
7144 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007145 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007146
jiadbdefb252018-01-03 14:27:06 +08007147 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7148 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7149 if (!comb_log_str) {
7150 hdd_err("failed to alloc comb_log_str");
7151 return;
7152 }
7153
Mohit Khannaca4173b2017-09-12 21:52:19 -07007154 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007155
Dustin Brown920397d2017-12-13 16:27:50 -08007156 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007157 curr_time = qdf_system_ticks();
7158 total = curr_time - adapter->start_time;
7159 delta = curr_time - adapter->last_time;
7160
7161 if (adapter->pause_map) {
7162 pause = adapter->total_pause_time + delta;
7163 unpause = adapter->total_unpause_time;
7164 } else {
7165 unpause = adapter->total_unpause_time + delta;
7166 pause = adapter->total_pause_time;
7167 }
7168
7169 tbytes = 0;
7170 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7171 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7172 if (adapter->queue_oper_stats[i].pause_count == 0)
7173 continue;
7174 tbytes +=
7175 snprintf(
7176 &temp_str[tbytes],
7177 (tbytes >= sizeof(temp_str) ?
7178 0 : sizeof(temp_str) - tbytes),
7179 "%d(%d,%d) ",
7180 i,
7181 adapter->queue_oper_stats[i].
7182 pause_count,
7183 adapter->queue_oper_stats[i].
7184 unpause_count);
7185 }
7186 if (tbytes >= sizeof(temp_str))
7187 hdd_warn("log truncated");
7188
7189 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007190 bytes_written >= comb_log_str_size ? 0 :
7191 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007192 "[%d %d] (%d) %u/%ums %s|",
7193 adapter->session_id, adapter->device_mode,
7194 adapter->pause_map,
7195 qdf_system_ticks_to_msecs(pause),
7196 qdf_system_ticks_to_msecs(total),
7197 temp_str);
7198
Mohit Khannaca4173b2017-09-12 21:52:19 -07007199 adapter_num++;
7200 }
7201
7202 /* using QDF_TRACE to avoid printing function name */
7203 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7204 "STATS |%s", comb_log_str);
7205
jiadbdefb252018-01-03 14:27:06 +08007206 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007207 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007208
7209 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007210}
7211
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007212/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007213 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007214 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007215 *
7216 * Return: none
7217 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007218void
7219wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7220 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007221{
7222
Jeff Johnson9d295242017-08-29 14:39:48 -07007223 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007224 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307225 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007226
Mohit Khannaca4173b2017-09-12 21:52:19 -07007227 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7228 hdd_display_netif_queue_history_compact(hdd_ctx);
7229 return;
7230 }
7231
Dustin Brown920397d2017-12-13 16:27:50 -08007232 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007233 hdd_debug("Netif queue operation statistics:");
7234 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007235 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007236 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307237 curr_time = qdf_system_ticks();
7238 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307239 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307240 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307241 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307242 unpause = adapter->total_unpause_time;
7243 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307244 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307245 pause = adapter->total_pause_time;
7246 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007247 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307248 qdf_system_ticks_to_msecs(total),
7249 qdf_system_ticks_to_msecs(pause),
7250 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007251 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007252
Nirav Shahda008342016-05-17 18:50:40 +05307253 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7254 qdf_time_t pause_delta = 0;
7255
7256 if (adapter->pause_map & (1 << i))
7257 pause_delta = delta;
7258
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007259 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07007260 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007261 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007262 hdd_reason_type_to_string(i),
7263 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05307264 adapter->queue_oper_stats[i].unpause_count,
7265 qdf_system_ticks_to_msecs(
7266 adapter->queue_oper_stats[i].total_pause_time +
7267 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007268 }
7269
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007270 hdd_debug("Netif queue operation history:");
7271 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307272 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7273
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007274 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007275
7276 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007277 /* using hdd_log to avoid printing function name */
7278 if (adapter->queue_oper_history[i].time == 0)
7279 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07007280 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007281 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05307282 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007283 adapter->queue_oper_history[i].time),
7284 hdd_action_type_to_string(
7285 adapter->queue_oper_history[i].netif_action),
7286 hdd_reason_type_to_string(
7287 adapter->queue_oper_history[i].netif_reason),
7288 adapter->queue_oper_history[i].pause_map);
7289 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007290 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007291}
7292
7293/**
7294 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7295 * @hdd_ctx: hdd context
7296 *
7297 * Return: none
7298 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007299void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007300{
Jeff Johnson9d295242017-08-29 14:39:48 -07007301 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007302
Dustin Brown920397d2017-12-13 16:27:50 -08007303 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307304 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007305 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307306 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007307 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307308 adapter->history_index = 0;
7309 adapter->start_time = adapter->last_time = qdf_system_ticks();
7310 adapter->total_pause_time = 0;
7311 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007312 }
7313}
7314
7315/**
7316 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7317 * @halHandle: Hal handle
7318 * @pContext: Pointer to the context
7319 * @sessionId: Session ID
7320 * @scanId: Scan ID
7321 * @status: Status
7322 *
7323 * This is the callback to be executed when 11d scan is completed to flush out
7324 * the scan results
7325 *
7326 * 11d scan is done during driver load and is a passive scan on all
7327 * channels supported by the device, 11d scans may find some APs on
7328 * frequencies which are forbidden to be used in the regulatory domain
7329 * the device is operating in. If these APs are notified to the supplicant
7330 * it may try to connect to these APs, thus flush out all the scan results
7331 * which are present in SME after 11d scan is done.
7332 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307333 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007334 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307335static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007336 uint8_t sessionId, uint32_t scanId,
7337 eCsrScanStatus status)
7338{
7339 ENTER();
7340
7341 sme_scan_flush_result(halHandle);
7342
7343 EXIT();
7344
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307345 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007346}
7347
7348#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7349/**
7350 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7351 * @hdd_ctx: hdd global context
7352 *
7353 * Return: none
7354 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007355static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007356{
7357 uint8_t i;
7358
7359 mutex_init(&hdd_ctx->op_ctx.op_lock);
7360 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7361 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7362 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7363 }
7364}
7365#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007366static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007367{
7368}
7369#endif
7370
Yingying Tang95409972016-10-20 15:16:15 +08007371#ifdef WLAN_FEATURE_WOW_PULSE
7372/**
7373 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007374 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007375 * @enable: enable or disable this behaviour
7376 *
7377 * Return: int
7378 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007379static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007380{
7381 struct hdd_config *pcfg_ini = phddctx->config;
7382 struct wow_pulse_mode wow_pulse_set_info;
7383 QDF_STATUS status;
7384
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007385 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007386
7387 if (false == phddctx->config->wow_pulse_support)
7388 return 0;
7389
7390 /* prepare the request to send to SME */
7391 if (enable == true) {
7392 wow_pulse_set_info.wow_pulse_enable = true;
7393 wow_pulse_set_info.wow_pulse_pin =
7394 pcfg_ini->wow_pulse_pin;
7395 wow_pulse_set_info.wow_pulse_interval_low =
7396 pcfg_ini->wow_pulse_interval_low;
7397 wow_pulse_set_info.wow_pulse_interval_high =
7398 pcfg_ini->wow_pulse_interval_high;
7399 } else {
7400 wow_pulse_set_info.wow_pulse_enable = false;
7401 wow_pulse_set_info.wow_pulse_pin = 0;
7402 wow_pulse_set_info.wow_pulse_interval_low = 0;
7403 wow_pulse_set_info.wow_pulse_interval_high = 0;
7404 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007405 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007406 wow_pulse_set_info.wow_pulse_enable,
7407 wow_pulse_set_info.wow_pulse_pin,
7408 wow_pulse_set_info.wow_pulse_interval_low,
7409 wow_pulse_set_info.wow_pulse_interval_high);
7410
7411 status = sme_set_wow_pulse(&wow_pulse_set_info);
7412 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007413 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007414 return -EIO;
7415 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007416 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007417 return 0;
7418}
7419#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007420static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007421{
7422 return 0;
7423}
7424#endif
7425
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007426#ifdef WLAN_FEATURE_FASTPATH
7427/**
7428 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7429 * @hdd_cfg: hdd config
7430 * @context: lower layer context
7431 *
7432 * Return: none
7433 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307434void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435 void *context)
7436{
7437 if (hdd_cfg->fastpath_enable)
7438 hif_enable_fastpath(context);
7439}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007440#endif
7441
Yuanyuan Liu13738502016-04-06 17:41:37 -07007442#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007443/**
7444 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007445 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007446 * @level: thermal level
7447 *
7448 * Change IPA data path to SW path when the thermal throttle level greater
7449 * than 0, and restore the original data path when throttle level is 0
7450 *
7451 * Return: none
7452 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007453static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007454{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007455 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007456
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007457 /* Change IPA to SW path when throttle level greater than 0 */
7458 if (level > THROTTLE_LEVEL_0)
7459 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7460 else
7461 /* restore original concurrency mode */
7462 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7463}
7464
7465/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307466 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7467 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307468 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007469 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307470 * Get a safe channel to restart SAP. PCL already takes into account the
7471 * unsafe channels. So, the PCL is validated with the ACS range to provide
7472 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007473 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307474 * Return: Channel number to restart SAP in case of success. In case of any
7475 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007476 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307477static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007478 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007479{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307480 struct sir_pcl_list pcl;
7481 QDF_STATUS status;
7482 uint32_t i, j;
7483 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007484 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307485 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007486 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007487
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307488 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7489 if (!hdd_ctx) {
7490 hdd_err("invalid HDD context");
7491 return INVALID_CHANNEL_ID;
7492 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007493
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307494 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7495 if (!hal_handle) {
7496 hdd_err("invalid HAL handle");
7497 return INVALID_CHANNEL_ID;
7498 }
7499
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007500 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7501 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007502 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7503 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307504 if (QDF_IS_STATUS_ERROR(status)) {
7505 hdd_err("Get PCL failed");
7506 return INVALID_CHANNEL_ID;
7507 }
7508
Frank Liudc2cefb2017-06-21 15:38:18 +08007509 /*
7510 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7511 * channel is unsafe channel, the pcl may be empty, instead of return,
7512 * try to choose a safe channel from acs range.
7513 */
7514 if (!pcl.pcl_len)
7515 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307516
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007517 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007518 adapter->session.ap.sap_config.acs_cfg.start_ch,
7519 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307520
7521 /* PCL already takes unsafe channel into account */
7522 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007523 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307524 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007525 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307526 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007527 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007528 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307529 return pcl.pcl_list[i];
7530 }
7531 }
7532
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007533 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307534
7535 /* Try for safe channel from all valid channel */
7536 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007537 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7538 &pcl.pcl_len);
7539 if (ret) {
7540 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307541 return INVALID_CHANNEL_ID;
7542 }
7543
7544 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007545 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307546 found = false;
7547 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007548 if (pcl.pcl_list[i] ==
7549 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007550 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307551 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007552 break;
7553 }
7554 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307555
7556 if (found)
7557 continue;
7558
7559 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007560 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307561 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007562 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007563 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307564 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007565 }
7566 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307567
7568 return INVALID_CHANNEL_ID;
7569}
7570
7571/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007572 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307573 * @adapter: AP adapter
7574 * @channel: Channel
7575 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007576 * Moves the SAP interface by invoking the function which
7577 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307578 *
7579 * Return: None
7580 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007581void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307582{
Jeff Johnson87251032017-08-29 13:31:11 -07007583 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307584 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007585 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307586
7587 if (!adapter) {
7588 hdd_err("invalid adapter");
7589 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007590 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307591
7592 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7593
7594 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7595 if (!hal_handle) {
7596 hdd_err("invalid HAL handle");
7597 return;
7598 }
7599
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007600 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7601
Jeff Johnson91df29d2017-10-27 19:29:50 -07007602 hdd_ap_ctx->sap_config.channel = channel;
7603 hdd_ap_ctx->sap_config.ch_params.ch_width =
7604 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307605
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007606 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007607 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307608
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007609 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007610 hdd_ap_ctx->sap_config.channel,
7611 hdd_ap_ctx->sap_config.sec_ch,
7612 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307613
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007614 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007615 adapter->session_id, channel,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007616 hdd_ap_ctx->sap_config.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007617}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307618
Jeff Johnson9d295242017-08-29 14:39:48 -07007619int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307620{
7621 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307622 int status;
7623 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307624
7625 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7626
7627 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007628 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307629 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007630 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307631 }
7632 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007633 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307634 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307635 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007636 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307637 WLAN_VENDOR_ACS_WAIT_TIME);
7638 if (qdf_status != QDF_STATUS_SUCCESS) {
7639 hdd_err("failed to start external acs timer");
7640 return -ENOSPC;
7641 }
7642 /* Update config to application */
7643 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307644 hdd_notice("Updated ACS config to nl with reason %d", reason);
7645
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307646 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307647}
7648
Agrawal Ashish467dde42016-09-08 18:44:22 +05307649/**
7650 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7651 * @hdd_ctx: hdd context pointer
7652 *
7653 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7654 * and if ACS is enabled, driver will ask userspace to restart the
7655 * sap. User space on LTE coex indication restart driver.
7656 *
7657 * Return - none
7658 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007659void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307660{
Dustin Brown920397d2017-12-13 16:27:50 -08007661 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307662 uint32_t i;
7663 bool found = false;
7664 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007665
Dustin Brown920397d2017-12-13 16:27:50 -08007666 hdd_for_each_adapter(hdd_ctxt, adapter) {
7667 if (!(adapter->device_mode == QDF_SAP_MODE &&
7668 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007669 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007670 adapter->device_mode,
7671 adapter->session.ap.sap_config.
7672 acs_cfg.acs_mode);
7673 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307674 }
7675
7676 found = false;
7677 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007678 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307679 hdd_ctxt->unsafe_channel_list[i]) {
7680 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007681 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007682 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307683 break;
7684 }
7685 }
7686
7687 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007688 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007689 adapter->session.ap.operating_channel);
7690 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307691 }
7692
Kapil Gupta8878ad92017-02-13 11:56:04 +05307693 if (hdd_ctxt->config->vendor_acs_support &&
7694 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007695 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307696 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007697 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307698 } else
7699 restart_chan =
7700 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007701 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307702 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007703 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307704 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007705 /*
7706 * SAP restart due to unsafe channel. While
7707 * restarting the SAP, make sure to clear
7708 * acs_channel, channel to reset to
7709 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307710 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007711 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307712 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007713 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307714 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007715 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307716 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7717 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007718 hdd_debug("driver to start sap: %d",
7719 hdd_ctxt->config->sap_internal_restart);
7720 if (hdd_ctxt->config->sap_internal_restart)
Dustin Brown920397d2017-12-13 16:27:50 -08007721 hdd_switch_sap_channel(adapter, restart_chan);
Liangwei Dong6663d162017-07-10 03:29:36 -04007722 else
7723 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307724 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307725 }
7726}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307727
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007728/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007729 * hdd_init_channel_avoidance() - Initialize channel avoidance
7730 * @hdd_ctx: HDD global context
7731 *
7732 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007733 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007734 * down to the lower layers. Then subscribe to subsequent channel
7735 * avoidance events.
7736 *
7737 * Return: None
7738 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007739static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007740{
7741 uint16_t unsafe_channel_count;
7742 int index;
7743
Yuanyuan Liu13738502016-04-06 17:41:37 -07007744 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7745 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007746 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007747 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007748
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007749 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007750 hdd_ctx->unsafe_channel_count);
7751
Anurag Chouhan6d760662016-02-20 16:05:43 +05307752 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007753 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007754
7755 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007756 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007757 hdd_ctx->unsafe_channel_list[index]);
7758
7759 }
7760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007761}
Dustin Brown676a2322017-08-15 13:16:13 -07007762
Jeff Johnson9d295242017-08-29 14:39:48 -07007763static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007764 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007765{
7766 uint8_t restart_chan;
7767
7768 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7769 if (!restart_chan) {
7770 hdd_alert("fail to restart SAP");
7771 return;
7772 }
7773
7774 /* SAP restart due to unsafe channel. While restarting
7775 * the SAP, make sure to clear acs_channel, channel to
7776 * reset to 0. Otherwise these settings will override
7777 * the ACS while restart.
7778 */
7779 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007780 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007781
7782 hdd_debug("sending coex indication");
7783
7784 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7785 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7786 hdd_switch_sap_channel(adapter, restart_chan);
7787}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007788
7789int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7790 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7791{
7792 uint32_t size;
7793 uint16_t *unsafe_list;
7794 uint16_t chan_count;
7795
7796 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7797 return -EINVAL;
7798
7799 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7800 NUM_CHANNELS);
7801 if (chan_count) {
7802 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7803 unsafe_list = qdf_mem_malloc(size);
7804 if (!unsafe_list) {
7805 hdd_err("No memory for unsafe chan list size%d",
7806 size);
7807 return -ENOMEM;
7808 }
7809 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7810 } else {
7811 unsafe_list = NULL;
7812 }
7813
7814 *local_unsafe_list = unsafe_list;
7815 *local_unsafe_list_count = chan_count;
7816
7817 return 0;
7818}
7819
7820bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7821 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7822{
7823 int i, j;
7824
7825 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7826 return true;
7827 if (local_unsafe_list_count == 0)
7828 return false;
7829 for (i = 0; i < local_unsafe_list_count; i++) {
7830 for (j = 0; j < local_unsafe_list_count; j++)
7831 if (local_unsafe_list[i] ==
7832 hdd_ctx->unsafe_channel_list[j])
7833 break;
7834 if (j >= local_unsafe_list_count)
7835 break;
7836 }
7837 if (i >= local_unsafe_list_count) {
7838 hdd_info("unsafe chan list same");
7839 return false;
7840 }
7841
7842 return true;
7843}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007844#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007845static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007846{
7847}
Dustin Brown676a2322017-08-15 13:16:13 -07007848
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007849static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007850{
7851}
Dustin Brown676a2322017-08-15 13:16:13 -07007852
Jeff Johnson9d295242017-08-29 14:39:48 -07007853static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007854 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007855{
7856 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7857}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007858#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007859
7860/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007861 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7862 * user space
7863 * @frame_ind: Management frame data to be informed.
7864 *
7865 * This function is used to indicate management frame to
7866 * user space
7867 *
7868 * Return: None
7869 *
7870 */
7871void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7872{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007873 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007874 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007875 int i;
7876
Rajeev Kumard004abc2016-02-17 12:09:56 -08007877 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007878 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007879
7880 if (0 != wlan_hdd_validate_context(hdd_ctx))
7881 return;
7882
7883 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7884 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7885 adapter =
7886 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7887 if (adapter)
7888 break;
7889 }
Wu Gaoa0230a62018-01-04 20:56:57 +08007890 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
7891 hdd_for_each_adapter(hdd_ctx, adapter) {
7892 if ((NULL != adapter) &&
7893 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
7894 __hdd_indicate_mgmt_frame(adapter,
7895 frame_ind->frame_len,
7896 frame_ind->frameBuf,
7897 frame_ind->frameType,
7898 frame_ind->rxChan,
7899 frame_ind->rxRssi);
7900 }
7901 }
7902 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007903 } else {
7904 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7905 frame_ind->sessionId);
7906 }
7907
7908 if ((NULL != adapter) &&
7909 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7910 __hdd_indicate_mgmt_frame(adapter,
7911 frame_ind->frame_len,
7912 frame_ind->frameBuf,
7913 frame_ind->frameType,
7914 frame_ind->rxChan,
7915 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007916}
7917
Kapil Gupta8878ad92017-02-13 11:56:04 +05307918void hdd_acs_response_timeout_handler(void *context)
7919{
7920 struct hdd_external_acs_timer_context *timer_context =
7921 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007922 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007923 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307924 uint8_t reason;
7925
7926 ENTER();
7927 if (!timer_context) {
7928 hdd_err("invlaid timer context");
7929 return;
7930 }
7931 adapter = timer_context->adapter;
7932 reason = timer_context->reason;
7933
7934
7935 if ((!adapter) ||
7936 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7937 hdd_err("invalid adapter or adapter has invalid magic");
7938 return;
7939 }
7940 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7941 if (wlan_hdd_validate_context(hdd_ctx))
7942 return;
7943
7944 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7945 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7946 else
7947 return;
7948
7949 hdd_err("ACS timeout happened for %s reason %d",
7950 adapter->dev->name, reason);
7951 switch (reason) {
7952 /* SAP init case */
7953 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7954 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7955 false);
7956 wlan_hdd_cfg80211_start_acs(adapter);
7957 break;
7958 /* DFS detected on current channel */
7959 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7960 wlan_sap_update_next_channel(
7961 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7962 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007963 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307964 break;
7965 /* LTE coex event on current channel */
7966 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7967 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7968 break;
7969 default:
7970 hdd_info("invalid reason for timer invoke");
7971
7972 }
7973}
7974
Rajeev Kumard004abc2016-02-17 12:09:56 -08007975/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007976 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7977 * @hdd_ctx: HDD context
7978 *
7979 * Disables all the dual mac features like DBS, Agile DFS etc.
7980 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307981 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007982 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007983static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007984{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007985 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307986 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007987
7988 if (!hdd_ctx) {
7989 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307990 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007991 }
7992
7993 cfg.scan_config = 0;
7994 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007995 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007996
7997 hdd_debug("Disabling all dual mac features...");
7998
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007999 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308000 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008001 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8002 return status;
8003 }
8004
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308005 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008006}
8007
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008008static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008009wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008010{
8011 struct policy_mgr_dual_mac_config cfg = {0};
8012 QDF_STATUS status;
8013
8014 if (!hdd_ctx) {
8015 hdd_err("HDD context is NULL");
8016 return QDF_STATUS_E_FAILURE;
8017 }
8018
8019 cfg.scan_config = 0;
8020 cfg.fw_mode_config = 0;
8021 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
8022 status = policy_mgr_get_updated_scan_and_fw_mode_config(
8023 hdd_ctx->hdd_psoc, &cfg.scan_config,
8024 &cfg.fw_mode_config,
8025 hdd_ctx->config->dual_mac_feature_disable);
8026
8027 if (status != QDF_STATUS_SUCCESS) {
8028 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
8029 status);
8030 return status;
8031 }
8032
8033 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
8034 cfg.scan_config, cfg.fw_mode_config);
8035
8036 status = sme_soc_set_dual_mac_config(cfg);
8037 if (status != QDF_STATUS_SUCCESS) {
8038 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8039 return status;
8040 }
8041
8042 return QDF_STATUS_SUCCESS;
8043}
8044
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008045/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008046 * hdd_override_ini_config - Override INI config
8047 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008048 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008049 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008050 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008051 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008052 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008053static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008054{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008055
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008056 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8057 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008058 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008059 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008060 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008061 if (0 == enable_11d || 1 == enable_11d) {
8062 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008063 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008064 }
Leo Chang11545d62016-10-17 14:53:50 -07008065
8066 if (!hdd_ipa_is_present(hdd_ctx))
8067 hdd_ctx->config->IpaConfig = 0;
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308068
8069 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8070 !hdd_ctx->config->enable_bcast_probe_rsp) {
8071 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8072 hdd_ctx->config->rssi_assoc_reject_enabled,
8073 hdd_ctx->config->enable_bcast_probe_rsp);
8074 hdd_ctx->config->oce_sta_enabled = 0;
8075 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008076}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008077
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008078/**
8079 * hdd_set_trace_level_for_each - Set trace level for each INI config
8080 * @hdd_ctx - HDD context
8081 *
8082 * Set trace level for each module based on INI config.
8083 *
8084 * Return: None
8085 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008086static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008087{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308088 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8089 hdd_ctx->config->qdf_trace_enable_wdi);
8090 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8091 hdd_ctx->config->qdf_trace_enable_hdd);
8092 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8093 hdd_ctx->config->qdf_trace_enable_sme);
8094 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8095 hdd_ctx->config->qdf_trace_enable_pe);
8096 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8097 hdd_ctx->config->qdf_trace_enable_wma);
8098 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8099 hdd_ctx->config->qdf_trace_enable_sys);
8100 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8101 hdd_ctx->config->qdf_trace_enable_qdf);
8102 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8103 hdd_ctx->config->qdf_trace_enable_sap);
8104 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8105 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8106 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8107 hdd_ctx->config->qdf_trace_enable_bmi);
8108 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8109 hdd_ctx->config->qdf_trace_enable_cfg);
8110 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8111 hdd_ctx->config->qdf_trace_enable_epping);
8112 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8113 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8114 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008115 hdd_ctx->config->qdf_trace_enable_txrx);
8116 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8117 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308118 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8119 hdd_ctx->config->qdf_trace_enable_htc);
8120 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8121 hdd_ctx->config->qdf_trace_enable_hif);
8122 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8123 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8124 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8125 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008126 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8127 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008128 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8129 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008130 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8131 hdd_ctx->config->qdf_trace_enable_regulatory);
8132
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008133 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008134}
8135
8136/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008137 * hdd_context_init() - Initialize HDD context
8138 * @hdd_ctx: HDD context.
8139 *
8140 * Initialize HDD context along with all the feature specific contexts.
8141 *
8142 * return: 0 on success and errno on failure.
8143 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008144static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008145{
8146 int ret;
8147
8148 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8149 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8150
8151 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308152 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008153
8154 init_completion(&hdd_ctx->mc_sus_event_var);
8155 init_completion(&hdd_ctx->ready_to_suspend);
8156
8157 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308158 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008159 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308160
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008161 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008162
8163 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8164
8165 ret = hdd_scan_context_init(hdd_ctx);
8166 if (ret)
8167 goto list_destroy;
8168
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008169 hdd_rx_wake_lock_create(hdd_ctx);
8170
8171 ret = hdd_sap_context_init(hdd_ctx);
8172 if (ret)
8173 goto scan_destroy;
8174
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008175 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8176
8177 hdd_init_offloaded_packets_ctx(hdd_ctx);
8178
8179 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8180 hdd_ctx->config);
8181 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008182 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008183
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308184 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8185 "monitor_mode_wakelock");
8186
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008187 return 0;
8188
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008189sap_destroy:
8190 hdd_sap_context_destroy(hdd_ctx);
8191
8192scan_destroy:
8193 hdd_scan_context_destroy(hdd_ctx);
8194 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008195list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008196 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008197
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008198 return ret;
8199}
8200
8201/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308202 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8203 * @hdd_ctx: pointer to hdd context
8204 *
8205 * Return: status of initialization
8206 * 0 - success
8207 * negative value - failure
8208 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008209static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308210{
8211 int ret;
8212
8213 if (!hdd_ctx->config->probe_req_ie_whitelist)
8214 return 0;
8215
8216 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8217 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8218 hdd_ctx->config->probe_req_ie_whitelist = false;
8219 return -EINVAL;
8220 }
8221
8222 /* parse ini string probe req oui */
8223 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8224 if (ret) {
8225 hdd_err("parsing error: disable ie whitelisting");
8226 hdd_ctx->config->probe_req_ie_whitelist = false;
8227 }
8228
8229 return ret;
8230}
8231
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308232
8233/**
8234 * hdd_iface_change_callback() - Function invoked when stop modules expires
8235 * @priv: pointer to hdd context
8236 *
8237 * This function is invoked when the timer waiting for the interface change
8238 * expires, it shall cut-down the power to wlan and stop all the modules.
8239 *
8240 * Return: void
8241 */
8242static void hdd_iface_change_callback(void *priv)
8243{
8244 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8245 int ret;
8246 int status = wlan_hdd_validate_context(hdd_ctx);
8247
8248 if (status)
8249 return;
8250
8251 ENTER();
8252 hdd_debug("Interface change timer expired close the modules!");
8253 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8254 if (ret)
8255 hdd_err("Failed to stop modules");
8256 EXIT();
8257}
8258
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308259/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008260 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308261 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008262 *
8263 * Allocate and initialize HDD context. HDD context is allocated as part of
8264 * wiphy allocation and then context is initialized.
8265 *
8266 * Return: HDD context on success and ERR_PTR on failure
8267 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008268static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008269{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308270 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008271 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008272 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008273
8274 ENTER();
8275
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008276 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008277 if (hdd_ctx == NULL) {
8278 ret = -ENOMEM;
8279 goto err_out;
8280 }
8281
Dustin Brown6f427922017-09-19 12:19:00 -07008282 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8283 hdd_iface_change_callback,
8284 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308285
8286 mutex_init(&hdd_ctx->iface_change_lock);
8287
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008288 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308289 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008290
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308291 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008292 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008293 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008294 ret = -ENOMEM;
8295 goto err_free_hdd_context;
8296 }
8297
8298 /* Read and parse the qcom_cfg.ini file */
8299 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308300 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308301 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008302 WLAN_INI_FILE);
8303 ret = -EINVAL;
8304 goto err_free_config;
8305 }
8306
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308307 ie_whitelist_attrs_init(hdd_ctx);
8308
Dustin Brown7f939932017-05-18 15:02:17 -07008309 hdd_debug("setting timer multiplier: %u",
8310 hdd_ctx->config->timer_multiplier);
8311 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8312
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008313
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308314 if (hdd_ctx->config->fhostNSOffload)
8315 hdd_ctx->ns_offload_enable = true;
8316
Abhishek Singh5ea86532016-04-27 14:10:53 +05308317 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8318
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008319 hdd_override_ini_config(hdd_ctx);
8320
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008321 ret = hdd_context_init(hdd_ctx);
8322
8323 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008324 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008325
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008326 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308327 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008328
Anurag Chouhan6d760662016-02-20 16:05:43 +05308329 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008330 goto skip_multicast_logging;
8331
8332 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8333
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008334 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8335 if (ret)
8336 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308337
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008338 ret = hdd_init_netlink_services(hdd_ctx);
8339 if (ret)
8340 goto err_deinit_txrx_histogram;
8341
Dustin Brown7b3dea22017-07-10 13:02:47 -07008342 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
8343 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05308344
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008345skip_multicast_logging:
8346 hdd_set_trace_level_for_each(hdd_ctx);
8347
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008348 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8349
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008350 EXIT();
8351
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008352 return hdd_ctx;
8353
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008354err_deinit_txrx_histogram:
8355 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8356
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008357err_deinit_hdd_context:
8358 hdd_context_deinit(hdd_ctx);
8359
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008360err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308361 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008362
8363err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308364 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008365 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008366
8367err_out:
8368 return ERR_PTR(ret);
8369}
8370
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008371#ifdef WLAN_OPEN_P2P_INTERFACE
8372/**
8373 * hdd_open_p2p_interface - Open P2P interface
8374 * @hdd_ctx: HDD context
8375 * @rtnl_held: True if RTNL lock held
8376 *
8377 * Open P2P interface during probe. This function called to open the P2P
8378 * interface at probe along with STA interface.
8379 *
8380 * Return: 0 on success and errno on failure
8381 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008382static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008383{
Jeff Johnson9d295242017-08-29 14:39:48 -07008384 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008385 uint8_t *p2p_dev_addr;
8386
8387 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8388 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008389 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008390 hdd_ctx->config->intfMacAddr[0].bytes,
8391 sizeof(tSirMacAddr));
8392
8393 /*
8394 * Generate the P2P Device Address. This consists of
8395 * the device's primary MAC address with the locally
8396 * administered bit set.
8397 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008398 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008399 } else {
8400 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8401 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008402 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008403 return -ENOSPC;
8404 }
8405
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008406 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8407 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008408 }
8409
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008410 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008411 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008412 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008413
8414 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008415 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008416 return -ENOSPC;
8417 }
8418
8419 return 0;
8420}
8421#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008422static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008423 bool rtnl_held)
8424{
8425 return 0;
8426}
8427#endif
8428
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008429static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008430{
Jeff Johnson9d295242017-08-29 14:39:48 -07008431 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008432 int ret = 0;
8433
8434 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8435 wlan_hdd_get_intf_addr(hdd_ctx),
8436 NET_NAME_UNKNOWN, rtnl_held);
8437 if (adapter == NULL) {
8438 hdd_err("Failed to open 802.11p interface");
8439 ret = -ENOSPC;
8440 }
8441
8442 return ret;
8443}
8444
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008445/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308446 * hdd_start_station_adapter()- Start the Station Adapter
8447 * @adapter: HDD adapter
8448 *
8449 * This function initializes the adapter for the station mode.
8450 *
8451 * Return: 0 on success or errno on failure.
8452 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008453int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308454{
8455 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008456 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308457
8458 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008459 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8460 hdd_err("session is already opened, %d",
8461 adapter->session_id);
8462 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8463 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308464
Krunal Sonib51eec72017-11-20 21:53:01 -08008465 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8466 if (ret) {
8467 hdd_err("failed to create vdev: %d", ret);
8468 return ret;
8469 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308470 status = hdd_init_station_mode(adapter);
8471
8472 if (QDF_STATUS_SUCCESS != status) {
8473 hdd_err("Error Initializing station mode: %d", status);
8474 return qdf_status_to_os_return(status);
8475 }
8476
Arun Khandavallifae92942016-08-01 13:31:08 +05308477 hdd_register_tx_flow_control(adapter,
8478 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008479 hdd_tx_resume_cb,
8480 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308481
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308482 EXIT();
8483 return 0;
8484}
8485
8486/**
8487 * hdd_start_ap_adapter()- Start AP Adapter
8488 * @adapter: HDD adapter
8489 *
8490 * This function initializes the adapter for the AP mode.
8491 *
8492 * Return: 0 on success errno on failure.
8493 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008494int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308495{
8496 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008497 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008498 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308499
8500 ENTER();
8501
Krunal Sonib51eec72017-11-20 21:53:01 -08008502 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8503 hdd_err("session is already opened, %d",
8504 adapter->session_id);
8505 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8506 }
8507 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008508 * In SSR case no need to create new sap context.
8509 * Otherwise create sap context first and then create
8510 * vdev as while creating the vdev, driver needs to
8511 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008512 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008513 if (adapter->session.ap.sap_context) {
8514 is_ssr = true;
8515 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008516 hdd_err("sap creation failed");
8517 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8518 }
8519
8520 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8521 adapter->session.ap.sap_context);
8522 if (ret) {
8523 hdd_err("failed to create vdev, status:%d", ret);
8524 hdd_sap_destroy_ctx(adapter);
8525 return ret;
8526 }
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008527 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308528
8529 if (QDF_STATUS_SUCCESS != status) {
8530 hdd_err("Error Initializing the AP mode: %d", status);
8531 return qdf_status_to_os_return(status);
8532 }
8533
Arun Khandavallifae92942016-08-01 13:31:08 +05308534 hdd_register_tx_flow_control(adapter,
8535 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008536 hdd_softap_tx_resume_cb,
8537 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308538
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308539 EXIT();
8540 return 0;
8541}
8542
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308543static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8544 bool rtnl_held)
8545{
8546 struct hdd_adapter *adapter;
8547
8548 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8549 hdd_ctx->config->enableConcurrentSTA,
8550 wlan_hdd_get_intf_addr(hdd_ctx),
8551 NET_NAME_UNKNOWN, rtnl_held);
8552
8553 if (!adapter)
8554 return -ENOSPC;
8555
8556 return 0;
8557}
8558
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308559/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008560 * hdd_open_interfaces - Open all required interfaces
8561 * hdd_ctx: HDD context
8562 * rtnl_held: True if RTNL lock is held
8563 *
8564 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8565 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008566 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008567 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008568static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008569{
Jeff Johnson9d295242017-08-29 14:39:48 -07008570 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008571 int ret;
8572
Ravi Joshia307f632017-07-17 23:41:41 -07008573 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008574 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8575 con_mode == QDF_GLOBAL_FTM_MODE) {
8576 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8577 QDF_MONITOR_MODE : QDF_FTM_MODE;
8578
8579 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8580 wlan_hdd_get_intf_addr(hdd_ctx),
8581 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008582 if (!adapter) {
8583 hdd_err("open adapter failed");
8584 return -ENOSPC;
8585 }
Lin Bai1c678482017-12-18 18:29:11 +08008586
Ravi Joshia307f632017-07-17 23:41:41 -07008587 return 0;
8588 }
8589
Jeff Johnson957bc272017-02-02 08:54:48 -08008590 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308591 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008592 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008593
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008594 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008595 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008596 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008597
8598 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008599 return -ENOSPC;
8600
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308601 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8602 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8603 if (ret)
8604 hdd_err("Cannot create concurrent STA interface");
8605 }
8606
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008607 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8608 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008609 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008610
8611 /* Open 802.11p Interface */
8612 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008613 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8614 if (ret)
8615 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008616 }
8617
Jeff Johnson957bc272017-02-02 08:54:48 -08008618 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008619
Jeff Johnson957bc272017-02-02 08:54:48 -08008620err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008621 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008622 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008623}
8624
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008625/**
8626 * hdd_update_country_code - Update country code
8627 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008628 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008629 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008630 *
8631 * Return: 0 on success and errno on failure
8632 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008633static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008634{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008635 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008636 return 0;
8637
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008638 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008639}
8640
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308641#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8642/**
8643 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8644 * @cds_cfg: CDS Configuration
8645 * @hdd_ctx: Pointer to hdd context
8646 *
8647 * Return: none
8648 */
8649static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8650 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008651 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308652{
8653 cds_cfg->tx_flow_stop_queue_th =
8654 hdd_ctx->config->TxFlowStopQueueThreshold;
8655 cds_cfg->tx_flow_start_queue_offset =
8656 hdd_ctx->config->TxFlowStartQueueOffset;
8657}
8658#else
8659static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8660 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008661 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308662{
8663}
8664#endif
8665
8666#ifdef FEATURE_WLAN_RA_FILTERING
8667/**
8668 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8669 * @cds_cfg: CDS Configuration
8670 * @hdd_ctx: Pointer to hdd context
8671 *
8672 * Return: none
8673 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308674static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008675 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308676{
8677 cds_cfg->ra_ratelimit_interval =
8678 hdd_ctx->config->RArateLimitInterval;
8679 cds_cfg->is_ra_ratelimit_enabled =
8680 hdd_ctx->config->IsRArateLimitEnabled;
8681}
8682#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308683static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008684 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308685{
8686}
8687#endif
8688
8689/**
8690 * hdd_update_cds_config() - API to update cds configuration parameters
8691 * @hdd_ctx: HDD Context
8692 *
8693 * Return: 0 for Success, errno on failure
8694 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008695static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308696{
8697 struct cds_config_info *cds_cfg;
8698
8699 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8700 if (!cds_cfg) {
8701 hdd_err("failed to allocate cds config");
8702 return -ENOMEM;
8703 }
8704
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008705 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008706 if (!hdd_ctx->config->nMaxPsPoll ||
8707 !hdd_ctx->config->enablePowersaveOffload) {
8708 cds_cfg->powersave_offload_enabled =
8709 hdd_ctx->config->enablePowersaveOffload;
8710 } else {
8711 if ((hdd_ctx->config->enablePowersaveOffload ==
8712 PS_QPOWER_NODEEPSLEEP) ||
8713 (hdd_ctx->config->enablePowersaveOffload ==
8714 PS_LEGACY_NODEEPSLEEP))
8715 cds_cfg->powersave_offload_enabled =
8716 PS_LEGACY_NODEEPSLEEP;
8717 else
8718 cds_cfg->powersave_offload_enabled =
8719 PS_LEGACY_DEEPSLEEP;
8720 hdd_info("Qpower disabled in cds config, %d",
8721 cds_cfg->powersave_offload_enabled);
8722 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308723 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8724 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8725 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8726 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8727 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8728
8729 /* Here ol_ini_info is used to store ini status of arp offload
8730 * ns offload and others. Currently 1st bit is used for arp
8731 * off load and 2nd bit for ns offload currently, rest bits are unused
8732 */
8733 if (hdd_ctx->config->fhostArpOffload)
8734 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8735 if (hdd_ctx->config->fhostNSOffload)
8736 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8737
8738 /*
8739 * Copy the DFS Phyerr Filtering Offload status.
8740 * This parameter reflects the value of the
8741 * dfs_phyerr_filter_offload flag as set in the ini.
8742 */
8743 cds_cfg->dfs_phyerr_filter_offload =
8744 hdd_ctx->config->fDfsPhyerrFilterOffload;
8745 if (hdd_ctx->config->ssdp)
8746 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8747
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308748 cds_cfg->force_target_assert_enabled =
8749 hdd_ctx->config->crash_inject_enabled;
8750
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308751 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8752 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8753
8754 cds_cfg->ap_maxoffload_reorderbuffs =
8755 hdd_ctx->config->apMaxOffloadReorderBuffs;
8756
8757 cds_cfg->ap_disable_intrabss_fwd =
8758 hdd_ctx->config->apDisableIntraBssFwd;
8759
8760 cds_cfg->dfs_pri_multiplier =
8761 hdd_ctx->config->dfsRadarPriMultiplier;
8762 cds_cfg->reorder_offload =
8763 hdd_ctx->config->reorderOffloadSupport;
8764
8765 /* IPA micro controller data path offload resource config item */
8766 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008767 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8768 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008769 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008770 hdd_ctx->config->IpaUcTxBufCount);
8771 hdd_ctx->config->IpaUcTxBufCount =
8772 rounddown_pow_of_two(
8773 hdd_ctx->config->IpaUcTxBufCount);
8774 if (!hdd_ctx->config->IpaUcTxBufCount) {
8775 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308776 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008777 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008778 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008779 hdd_ctx->config->IpaUcTxBufCount);
8780 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308781 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8782 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008783 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8784 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008785 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008786 hdd_ctx->config->IpaUcRxIndRingCount);
8787 hdd_ctx->config->IpaUcRxIndRingCount =
8788 rounddown_pow_of_two(
8789 hdd_ctx->config->IpaUcRxIndRingCount);
8790 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8791 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308792 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008793 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008794 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008795 hdd_ctx->config->IpaUcRxIndRingCount);
8796 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308797 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008798 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308799 cds_cfg->uc_tx_partition_base =
8800 hdd_ctx->config->IpaUcTxPartitionBase;
8801 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8802
8803 cds_cfg->ip_tcp_udp_checksum_offload =
8804 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008805 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308806 cds_cfg->ce_classify_enabled =
8807 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008808 cds_cfg->bpf_packet_filter_enable =
8809 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308810 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8811 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8812 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008813 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008814 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008815 cds_cfg->max_msdus_per_rxinorderind =
8816 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008817 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008818 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308819 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8820 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308821 cds_cfg->auto_power_save_fail_mode =
8822 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308823
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308824 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008825 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308826
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308827 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8828 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8829 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008830 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308831 cds_init_ini_config(cds_cfg);
8832 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308833
8834exit:
8835 qdf_mem_free(cds_cfg);
8836 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308837}
8838
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008839/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008840 * hdd_update_user_config() - API to update user configuration
8841 * parameters to obj mgr which are used by multiple components
8842 * @hdd_ctx: HDD Context
8843 *
8844 * Return: 0 for Success, errno on failure
8845 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008846static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008847{
8848 struct wlan_objmgr_psoc_user_config *user_config;
8849
8850 user_config = qdf_mem_malloc(sizeof(*user_config));
8851 if (user_config == NULL) {
8852 hdd_alert("Failed to alloc memory for user_config!");
8853 return -ENOMEM;
8854 }
8855
8856 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8857 user_config->dual_mac_feature_disable =
8858 hdd_ctx->config->dual_mac_feature_disable;
8859 user_config->indoor_channel_support =
8860 hdd_ctx->config->indoor_channel_support;
8861 user_config->is_11d_support_enabled =
8862 hdd_ctx->config->Is11dSupportEnabled;
8863 user_config->is_11h_support_enabled =
8864 hdd_ctx->config->Is11hSupportEnabled;
8865 user_config->optimize_chan_avoid_event =
8866 hdd_ctx->config->goptimize_chan_avoid_event;
8867 user_config->skip_dfs_chnl_in_p2p_search =
8868 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008869 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008870 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8871
8872 qdf_mem_free(user_config);
8873 return 0;
8874}
8875
8876/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008877 * hdd_init_thermal_info - Initialize thermal level
8878 * @hdd_ctx: HDD context
8879 *
8880 * Initialize thermal level at SME layer and set the thermal level callback
8881 * which would be called when a configured thermal threshold is hit.
8882 *
8883 * Return: 0 on success and errno on failure
8884 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008885static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008886{
8887 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308888 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008889
8890 thermal_param.smeThermalMgmtEnabled =
8891 hdd_ctx->config->thermalMitigationEnable;
8892 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8893
Poddar, Siddarth83905022016-04-16 17:56:08 -07008894 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8895 hdd_ctx->config->throttle_dutycycle_level0;
8896 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8897 hdd_ctx->config->throttle_dutycycle_level1;
8898 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8899 hdd_ctx->config->throttle_dutycycle_level2;
8900 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8901 hdd_ctx->config->throttle_dutycycle_level3;
8902
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008903 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8904 hdd_ctx->config->thermalTempMinLevel0;
8905 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8906 hdd_ctx->config->thermalTempMaxLevel0;
8907 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8908 hdd_ctx->config->thermalTempMinLevel1;
8909 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8910 hdd_ctx->config->thermalTempMaxLevel1;
8911 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8912 hdd_ctx->config->thermalTempMinLevel2;
8913 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8914 hdd_ctx->config->thermalTempMaxLevel2;
8915 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8916 hdd_ctx->config->thermalTempMinLevel3;
8917 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8918 hdd_ctx->config->thermalTempMaxLevel3;
8919
8920 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8921
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308922 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308923 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008924
8925 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8926 hdd_set_thermal_level_cb);
8927
8928 return 0;
8929
8930}
8931
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008932#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8933/**
8934 * hdd_hold_rtnl_lock - Hold RTNL lock
8935 *
8936 * Hold RTNL lock
8937 *
8938 * Return: True if held and false otherwise
8939 */
8940static inline bool hdd_hold_rtnl_lock(void)
8941{
8942 rtnl_lock();
8943 return true;
8944}
8945
8946/**
8947 * hdd_release_rtnl_lock - Release RTNL lock
8948 *
8949 * Release RTNL lock
8950 *
8951 * Return: None
8952 */
8953static inline void hdd_release_rtnl_lock(void)
8954{
8955 rtnl_unlock();
8956}
8957#else
8958static inline bool hdd_hold_rtnl_lock(void) { return false; }
8959static inline void hdd_release_rtnl_lock(void) { }
8960#endif
8961
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008962#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008963
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308964/* MAX iwpriv command support */
8965#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308966#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308967#define MAX_PKTLOG_SIZE 16
8968
8969/**
8970 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8971 * @hdd_ctx: hdd context
8972 * @set_value2: pktlog buffer size value
8973 *
8974 *
8975 * Return: 0 for success or error.
8976 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008977static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308978{
8979 struct sir_wifi_start_log start_log = { 0 };
8980 QDF_STATUS status;
8981
8982 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8983 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8984 start_log.ini_triggered = cds_is_packet_log_enabled();
8985 start_log.user_triggered = 1;
8986 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308987 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308988
8989 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8990 if (!QDF_IS_STATUS_SUCCESS(status)) {
8991 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8992 EXIT();
8993 return -EINVAL;
8994 }
8995
8996 return 0;
8997}
8998
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008999/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309000 * hdd_pktlog_clear_buff() - clear pktlog buffer
9001 * @hdd_ctx: hdd context
9002 *
9003 * Return: 0 for success or error.
9004 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009005static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309006{
9007 struct sir_wifi_start_log start_log;
9008 QDF_STATUS status;
9009
9010 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9011 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9012 start_log.ini_triggered = cds_is_packet_log_enabled();
9013 start_log.user_triggered = 1;
9014 start_log.size = 0;
9015 start_log.is_pktlog_buff_clear = true;
9016
9017 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9018 if (!QDF_IS_STATUS_SUCCESS(status)) {
9019 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9020 EXIT();
9021 return -EINVAL;
9022 }
9023
9024 return 0;
9025}
9026
9027
9028/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009029 * hdd_process_pktlog_command() - process pktlog command
9030 * @hdd_ctx: hdd context
9031 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309032 * @set_value2: pktlog buffer size value
9033 *
9034 * This function process pktlog command.
9035 * set_value2 only matters when set_value is 3 (set buff size)
9036 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009037 *
9038 * Return: 0 for success or error.
9039 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009040int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309041 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009042{
9043 int ret;
9044 bool enable;
9045 uint8_t user_triggered = 0;
9046
9047 ret = wlan_hdd_validate_context(hdd_ctx);
9048 if (0 != ret)
9049 return ret;
9050
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009051 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009052
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309053 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009054 hdd_err("invalid pktlog value %d", set_value);
9055 return -EINVAL;
9056 }
9057
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309058 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9059 if (set_value2 <= 0) {
9060 hdd_err("invalid pktlog size %d", set_value2);
9061 return -EINVAL;
9062 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9063 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9064 return -EINVAL;
9065 }
9066 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309067 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9068 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309069 }
9070
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009071 /*
9072 * set_value = 0 then disable packetlog
9073 * set_value = 1 enable packetlog forcefully
9074 * set_vlaue = 2 then disable packetlog if disabled through ini or
9075 * enable packetlog with AUTO type.
9076 */
9077 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9078 true : false;
9079
9080 if (1 == set_value) {
9081 enable = true;
9082 user_triggered = 1;
9083 }
9084
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309085 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009086}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009087
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009088/**
9089 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9090 * @hdd_ctx: HDD context
9091 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309092 * @user_triggered: triggered through iwpriv
9093 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009094 *
9095 * Return: 0 on success; error number otherwise
9096 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009097int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309098 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009099{
9100 struct sir_wifi_start_log start_log;
9101 QDF_STATUS status;
9102
9103 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9104 start_log.verbose_level =
9105 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009106 start_log.ini_triggered = cds_is_packet_log_enabled();
9107 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309108 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309109 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309110 /*
9111 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9112 * commands. Host uses this flag to decide whether to send pktlog
9113 * disable command to fw without sending pktlog enable command
9114 * previously. For eg, If vendor sends pktlog disable command without
9115 * sending pktlog enable command, then host discards the packet
9116 * but for iwpriv command, host will send it to fw.
9117 */
9118 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009119 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9120 if (!QDF_IS_STATUS_SUCCESS(status)) {
9121 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9122 EXIT();
9123 return -EINVAL;
9124 }
9125
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309126 if (enable == true)
9127 hdd_ctx->is_pktlog_enabled = 1;
9128 else
9129 hdd_ctx->is_pktlog_enabled = 0;
9130
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009131 return 0;
9132}
9133#endif /* REMOVE_PKT_LOG */
9134
Komal Seelam92fff912016-03-24 11:51:41 +05309135/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009136 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9137 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309138 * @dev: Device Pointer
9139 * @num: Number of Valid Mac address
9140 *
9141 * Return: Pointer to MAC address buffer
9142 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009143static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9144 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309145{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009146 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309147}
Komal Seelam92fff912016-03-24 11:51:41 +05309148
9149/**
9150 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9151 * @hdd_ctx: HDD Context
9152 * @num: Number of random mac addresses needed
9153 *
9154 * Generate random addresses using bit manipulation on the base mac address
9155 *
9156 * Return: None
9157 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009158void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309159{
9160 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9161 uint32_t iter;
9162 struct hdd_config *ini = hdd_ctx->config;
9163 uint8_t *buf = NULL;
9164 uint8_t macaddr_b3, tmp_br3;
9165 uint8_t *src = ini->intfMacAddr[0].bytes;
9166
9167 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9168 buf = ini->intfMacAddr[iter].bytes;
9169 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9170 macaddr_b3 = buf[3];
9171 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9172 INTF_MACADDR_MASK;
9173 macaddr_b3 += tmp_br3;
9174 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9175 buf[0] |= 0x02;
9176 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009177 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309178 }
9179}
9180
9181/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009182 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309183 * @hdd_ctx: HDD Context
9184 *
9185 * API to get mac addresses from platform driver and update the driver
9186 * structures and configure FW with the base mac address.
9187 * Return: int
9188 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009189static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309190{
9191 uint32_t no_of_mac_addr, iter;
9192 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9193 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9194 uint8_t *addr, *buf;
9195 struct device *dev = hdd_ctx->parent_dev;
9196 struct hdd_config *ini = hdd_ctx->config;
9197 tSirMacAddr mac_addr;
9198 QDF_STATUS status;
9199
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009200 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309201
9202 if (no_of_mac_addr == 0 || !addr) {
9203 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9204 return -EINVAL;
9205 }
9206
9207 if (no_of_mac_addr > max_mac_addr)
9208 no_of_mac_addr = max_mac_addr;
9209
9210 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9211
9212 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9213 buf = ini->intfMacAddr[iter].bytes;
9214 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009215 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309216 }
9217
9218 status = sme_set_custom_mac_addr(mac_addr);
9219
9220 if (!QDF_IS_STATUS_SUCCESS(status))
9221 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009222
Komal Seelam92fff912016-03-24 11:51:41 +05309223 if (no_of_mac_addr < max_mac_addr)
9224 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9225 no_of_mac_addr);
9226 return 0;
9227}
9228
9229/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009230 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9231 * @hdd_ctx: HDD Context
9232 *
9233 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9234 * will generate its own MAC and update it to FW.
9235 *
9236 * Return: 0 for success
9237 * Non-zero error code for failure
9238 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009239static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009240{
9241 tSirMacAddr customMacAddr;
9242 QDF_STATUS status;
9243
9244 qdf_mem_copy(&customMacAddr,
9245 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9246 sizeof(tSirMacAddr));
9247 status = sme_set_custom_mac_addr(customMacAddr);
9248 if (!QDF_IS_STATUS_SUCCESS(status))
9249 return -EAGAIN;
9250 return 0;
9251}
9252
9253/**
Komal Seelam92fff912016-03-24 11:51:41 +05309254 * hdd_initialize_mac_address() - API to get wlan mac addresses
9255 * @hdd_ctx: HDD Context
9256 *
9257 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9258 * is provisioned with mac addresses, driver uses it, else it will use
9259 * wlan_mac.bin to update HW MAC addresses.
9260 *
9261 * Return: None
9262 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009263static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309264{
9265 QDF_STATUS status;
9266 int ret;
9267
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009268 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309269 if (ret == 0)
9270 return;
9271
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009272 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9273 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309274
9275 status = hdd_update_mac_config(hdd_ctx);
9276
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009277 if (QDF_IS_STATUS_SUCCESS(status))
9278 return;
9279
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009280 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9281 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009282
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009283 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009284 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009285 if (ret != 0) {
9286 hdd_err("MAC address out-of-sync, ret:%d", ret);
9287 QDF_ASSERT(ret);
9288 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009289 }
Komal Seelam92fff912016-03-24 11:51:41 +05309290}
9291
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009292static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009293{
9294 int vdev_id = 0;
9295 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9296 int value = hdd_ctx->config->smart_chainmask_enabled;
9297 int vpdev = PDEV_CMD;
9298 int ret;
9299
Naveen Rawat247a8682017-06-05 15:00:31 -07009300 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009301 if (ret)
9302 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9303
9304 return ret;
9305}
9306
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009307static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009308{
9309 int vdev_id = 0;
9310 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9311 int value = hdd_ctx->config->alternative_chainmask_enabled;
9312 int vpdev = PDEV_CMD;
9313 int ret;
9314
Naveen Rawat247a8682017-06-05 15:00:31 -07009315 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009316 if (ret)
9317 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9318 ret);
9319
9320 return ret;
9321}
9322
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009323static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009324{
9325 int vdev_id = 0;
9326 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9327 int value = hdd_ctx->config->ani_enabled;
9328 int vpdev = PDEV_CMD;
9329 int ret;
9330
Naveen Rawat247a8682017-06-05 15:00:31 -07009331 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009332 if (ret)
9333 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9334
9335 return ret;
9336}
9337
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009338/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009339 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9340 * @hdd_ctx: HDD context
9341 *
9342 * Pre configurations to be done at lower layer before calling cds enable.
9343 *
9344 * Return: 0 on success and errno on failure.
9345 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009346static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009347{
9348 int ret;
9349 QDF_STATUS status;
9350 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009351 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009352
Leo Changfdb45c32016-10-28 11:09:23 -07009353 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009354 /*
9355 * Set 802.11p config
9356 * TODO-OCB: This has been temporarily added here to ensure this
9357 * parameter is set in CSR when we init the channel list. This should
9358 * be removed once the 5.9 GHz channels are added to the regulatory
9359 * domain.
9360 */
9361 hdd_set_dot11p_config(hdd_ctx);
9362
9363 /*
9364 * Note that the cds_pre_enable() sequence triggers the cfg download.
9365 * The cfg download must occur before we update the SME config
9366 * since the SME config operation must access the cfg database
9367 */
9368 status = hdd_set_sme_config(hdd_ctx);
9369
9370 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009371 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009372 ret = qdf_status_to_os_return(status);
9373 goto out;
9374 }
9375
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009376 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9377 if (QDF_STATUS_SUCCESS != status) {
9378 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9379 ret = qdf_status_to_os_return(status);
9380 goto out;
9381 }
9382
Naveen Rawat247a8682017-06-05 15:00:31 -07009383 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009384 hdd_ctx->config->tx_chain_mask_1ss,
9385 PDEV_CMD);
9386 if (0 != ret) {
9387 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9388 goto out;
9389 }
9390
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009391 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9392 if (ret)
9393 goto out;
9394
9395 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9396 if (ret)
9397 goto out;
9398
Jeff Johnson12a744b2017-04-04 08:19:37 -07009399 ret = hdd_set_ani_enabled(hdd_ctx);
9400 if (ret)
9401 goto out;
9402
Naveen Rawat247a8682017-06-05 15:00:31 -07009403 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009404 hdd_ctx->config->arp_ac_category,
9405 PDEV_CMD);
9406 if (0 != ret) {
9407 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9408 hdd_ctx->config->arp_ac_category, ret);
9409 goto out;
9410 }
9411
Prashanth Bhatta07998752016-04-28 12:35:33 -07009412 status = hdd_set_sme_chan_list(hdd_ctx);
9413 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009414 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009415 ret = qdf_status_to_os_return(status);
9416 goto out;
9417 }
9418
9419 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009420 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009421 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009422 ret = -EINVAL;
9423 goto out;
9424 }
9425
Prashanth Bhatta07998752016-04-28 12:35:33 -07009426 /*
9427 * Set the MAC Address Currently this is used by HAL to add self sta.
9428 * Remove this once self sta is added as part of session open.
9429 */
9430 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9431 hdd_ctx->config->intfMacAddr[0].bytes,
9432 sizeof(hdd_ctx->config->intfMacAddr[0]));
9433
9434 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9435 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9436 hal_status, hal_status);
9437 ret = -EINVAL;
9438 goto out;
9439 }
9440
9441 hdd_init_channel_avoidance(hdd_ctx);
9442
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309443 /* update enable sap mandatory chan list */
9444 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9445 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009446out:
9447 return ret;
9448}
9449
9450/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009451 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9452 * @context_ptr - hdd context pointer
9453 * @event_ptr - event structure pointer
9454 *
9455 * This is the p2p listen offload stop event handler, it sends vendor
9456 * event back to supplicant to notify the stop reason.
9457 *
9458 * Return: None
9459 */
9460static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9461 void *event_ptr)
9462{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009463 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009464 struct sir_p2p_lo_event *evt = event_ptr;
9465 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009466 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009467
9468 ENTER();
9469
9470 if (hdd_ctx == NULL) {
9471 hdd_err("Invalid HDD context pointer");
9472 return;
9473 }
9474
Peng Xu5c682812017-08-06 07:39:13 -07009475 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9476 if (!adapter) {
9477 hdd_err("Cannot find adapter by vdev_id = %d",
9478 evt->vdev_id);
9479 return;
9480 }
9481
Peng Xu8fdaa492016-06-22 10:20:47 -07009482 vendor_event =
9483 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009484 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009485 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9486 GFP_KERNEL);
9487
9488 if (!vendor_event) {
9489 hdd_err("cfg80211_vendor_event_alloc failed");
9490 return;
9491 }
9492
9493 if (nla_put_u32(vendor_event,
9494 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9495 evt->reason_code)) {
9496 hdd_err("nla put failed");
9497 kfree_skb(vendor_event);
9498 return;
9499 }
9500
9501 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009502 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9503 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009504}
9505
9506/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309507 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9508 * @hdd_ctx: HDD context
9509 *
9510 * This function sends the adaptive dwell time config configuration to the
9511 * firmware via WMA
9512 *
9513 * Return: 0 - success, < 0 - failure
9514 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009515static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309516{
9517 QDF_STATUS status;
9518 struct adaptive_dwelltime_params dwelltime_params;
9519
9520 dwelltime_params.is_enabled =
9521 hdd_ctx->config->adaptive_dwell_mode_enabled;
9522 dwelltime_params.dwelltime_mode =
9523 hdd_ctx->config->global_adapt_dwelltime_mode;
9524 dwelltime_params.lpf_weight =
9525 hdd_ctx->config->adapt_dwell_lpf_weight;
9526 dwelltime_params.passive_mon_intval =
9527 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9528 dwelltime_params.wifi_act_threshold =
9529 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9530
9531 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9532 &dwelltime_params);
9533
9534 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9535 if (!QDF_IS_STATUS_SUCCESS(status)) {
9536 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9537 return -EAGAIN;
9538 }
9539 return 0;
9540}
9541
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009542int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309543{
9544 QDF_STATUS status;
9545 struct wmi_dbs_scan_sel_params dbs_scan_params;
9546 uint32_t i = 0;
9547 uint8_t count = 0, numentries = 0;
9548 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9549 * CDS_DBS_SCAN_CLIENTS_MAX];
9550
9551 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009552 if (hdd_ctx->config->dual_mac_feature_disable ==
9553 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309554 return -EINVAL;
9555
9556 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9557 dbs_scan_config, &numentries,
9558 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9559 * CDS_DBS_SCAN_CLIENTS_MAX));
9560
9561 hdd_info("numentries %hu", numentries);
9562 if (!numentries) {
9563 hdd_info("Donot send scan_selection_config");
9564 return 0;
9565 }
9566
9567 /* hdd_set_fw_log_params */
9568 dbs_scan_params.num_clients = 0;
9569 while (count < (numentries - 2)) {
9570 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9571 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9572 dbs_scan_params.num_non_dbs_scans[i] =
9573 dbs_scan_config[count + 2];
9574 dbs_scan_params.num_clients++;
9575 hdd_debug("module:%d NDS:%d NNDS:%d",
9576 dbs_scan_params.module_id[i],
9577 dbs_scan_params.num_dbs_scans[i],
9578 dbs_scan_params.num_non_dbs_scans[i]);
9579 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9580 i++;
9581 }
9582
9583 dbs_scan_params.pdev_id = 0;
9584
9585 hdd_debug("clients:%d pdev:%d",
9586 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9587
9588 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9589 &dbs_scan_params);
9590 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9591 if (!QDF_IS_STATUS_SUCCESS(status)) {
9592 hdd_err("Failed to send DBS Scan selection configuration!");
9593 return -EAGAIN;
9594 }
9595 return 0;
9596}
9597
Arun Khandavallid4349a92016-07-25 11:10:43 +05309598#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9599/**
9600 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9601 * @hdd_ctx: HDD context
9602 *
9603 * Set auto shutdown callback to get indications from firmware to indicate
9604 * userspace to shutdown WLAN after a configured amount of inactivity.
9605 *
9606 * Return: 0 on success and errno on failure.
9607 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009608static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309609{
9610 QDF_STATUS status;
9611
9612 if (!hdd_ctx->config->WlanAutoShutdown)
9613 return 0;
9614
9615 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9616 wlan_hdd_auto_shutdown_cb);
9617 if (status != QDF_STATUS_SUCCESS)
9618 hdd_err("Auto shutdown feature could not be enabled: %d",
9619 status);
9620
9621 return qdf_status_to_os_return(status);
9622}
9623#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009624static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309625{
9626 return 0;
9627}
9628#endif
9629
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009630static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009631{
9632 QDF_STATUS status = QDF_STATUS_SUCCESS;
9633
9634 switch (hdd_ctx->config->dual_mac_feature_disable) {
9635 case DISABLE_DBS_CXN_AND_SCAN:
9636 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9637 if (status != QDF_STATUS_SUCCESS)
9638 hdd_err("Failed to disable dual mac features");
9639 break;
9640 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9641 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9642 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9643 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9644 if (status != QDF_STATUS_SUCCESS)
9645 hdd_err("Failed to set dbs scan and fw mode config");
9646 break;
9647 default:
9648 break;
9649 }
9650
9651 return status;
9652}
9653
Arun Khandavallid4349a92016-07-25 11:10:43 +05309654/**
9655 * hdd_features_init() - Init features
9656 * @hdd_ctx: HDD context
9657 * @adapter: Primary adapter context
9658 *
9659 * Initialize features and their feature context after WLAN firmware is up.
9660 *
9661 * Return: 0 on success and errno on failure.
9662 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009663static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309664{
9665 tSirTxPowerLimit hddtxlimit;
9666 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309667 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309668 int ret;
9669
9670 ENTER();
9671
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009672 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309673 if (ret) {
9674 hdd_err("Failed to update country code: %d", ret);
9675 goto out;
9676 }
9677
9678 /* FW capabilities received, Set the Dot11 mode */
9679 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009680 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9681 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309682
Arun Khandavallid4349a92016-07-25 11:10:43 +05309683
9684 if (hdd_ctx->config->fIsImpsEnabled)
9685 hdd_set_idle_ps_config(hdd_ctx, true);
9686 else
9687 hdd_set_idle_ps_config(hdd_ctx, false);
9688
Poddar, Siddarth37033032017-10-11 15:47:40 +05309689 /* Send Enable/Disable data stall detection cmd to FW */
9690 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9691 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9692
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309693 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009694 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309695
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309696 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9697 hdd_warn("Error in setting Voltage Corner mode config to FW");
9698
Arun Khandavallid4349a92016-07-25 11:10:43 +05309699 if (hdd_lro_init(hdd_ctx))
9700 hdd_err("Unable to initialize LRO in fw");
9701
9702 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9703 hdd_err("Unable to send adaptive dwelltime setting to FW");
9704
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309705 if (hdd_dbs_scan_selection_init(hdd_ctx))
9706 hdd_err("Unable to send DBS scan selection setting to FW");
9707
Arun Khandavallid4349a92016-07-25 11:10:43 +05309708 ret = hdd_init_thermal_info(hdd_ctx);
9709 if (ret) {
9710 hdd_err("Error while initializing thermal information");
9711 goto deregister_frames;
9712 }
9713
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309714 /**
9715 * In case of SSR/PDR, if pktlog was enabled manually before
9716 * SSR/PDR, Then enabled it again automatically after Wlan
9717 * device up.
9718 */
9719 if (cds_is_driver_recovering()) {
9720 if (hdd_ctx->is_pktlog_enabled)
9721 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9722 } else if (cds_is_packet_log_enabled())
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309723 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9724
Arun Khandavallid4349a92016-07-25 11:10:43 +05309725 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9726 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9727 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9728 if (!QDF_IS_STATUS_SUCCESS(status))
9729 hdd_err("Error setting txlimit in sme: %d", status);
9730
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009731 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309732
Arun Khandavallid4349a92016-07-25 11:10:43 +05309733 ret = hdd_register_cb(hdd_ctx);
9734 if (ret) {
9735 hdd_err("Failed to register HDD callbacks!");
9736 goto deregister_frames;
9737 }
9738
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009739 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9740 if (!QDF_IS_STATUS_SUCCESS(status)) {
9741 hdd_err("Failed to set dbs scan and fw mode cfg");
9742 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309743 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009744
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309745 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9746 status = sme_enable_disable_chanavoidind_event(
9747 hdd_ctx->hHal, 0);
9748 if (!QDF_IS_STATUS_SUCCESS(status)) {
9749 hdd_err("Failed to disable Chan Avoidance Indication");
9750 goto deregister_cb;
9751 }
9752 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309753
Manjeet Singha9cae432017-02-28 11:58:22 +05309754 if (hdd_ctx->config->enable_5g_band_pref) {
9755 band_pref_params.rssi_boost_threshold_5g =
9756 hdd_ctx->config->rssi_boost_threshold_5g;
9757 band_pref_params.rssi_boost_factor_5g =
9758 hdd_ctx->config->rssi_boost_factor_5g;
9759 band_pref_params.max_rssi_boost_5g =
9760 hdd_ctx->config->max_rssi_boost_5g;
9761 band_pref_params.rssi_penalize_threshold_5g =
9762 hdd_ctx->config->rssi_penalize_threshold_5g;
9763 band_pref_params.rssi_penalize_factor_5g =
9764 hdd_ctx->config->rssi_penalize_factor_5g;
9765 band_pref_params.max_rssi_penalize_5g =
9766 hdd_ctx->config->max_rssi_penalize_5g;
9767 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9768 }
9769
Arun Khandavallid4349a92016-07-25 11:10:43 +05309770 /* register P2P Listen Offload event callback */
9771 if (wma_is_p2p_lo_capable())
9772 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9773 wlan_hdd_p2p_lo_event_callback);
9774
9775 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9776
9777 if (ret)
9778 goto deregister_cb;
9779
9780 EXIT();
9781 return 0;
9782
9783deregister_cb:
9784 hdd_deregister_cb(hdd_ctx);
9785deregister_frames:
9786 wlan_hdd_cfg80211_deregister_frames(adapter);
9787out:
9788 return -EINVAL;
9789
9790}
9791
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009792/**
9793 * hdd_features_deinit() - Deinit features
9794 * @hdd_ctx: HDD context
9795 *
9796 * De-Initialize features and their feature context.
9797 *
9798 * Return: none.
9799 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009800static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009801{
9802 wlan_hdd_tsf_deinit(hdd_ctx);
9803}
9804
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309805/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009806 * hdd_register_bcn_cb() - register scan beacon callback
9807 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309808 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009809 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309810 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009811static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309812{
9813 QDF_STATUS status;
9814
9815 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9816 wlan_cfg80211_inform_bss_frame,
9817 SCAN_CB_TYPE_INFORM_BCN);
9818 if (!QDF_IS_STATUS_SUCCESS(status)) {
9819 hdd_err("failed with status code %08d [x%08x]",
9820 status, status);
9821 return status;
9822 }
9823
9824 return QDF_STATUS_SUCCESS;
9825}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309826
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309827/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309828 * hdd_configure_cds() - Configure cds modules
9829 * @hdd_ctx: HDD context
9830 * @adapter: Primary adapter context
9831 *
9832 * Enable Cds modules after WLAN firmware is up.
9833 *
9834 * Return: 0 on success and errno on failure.
9835 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009836int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309837{
9838 int ret;
9839 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309840 int set_value;
9841 uint32_t num_abg_tx_chains = 0;
9842 uint32_t num_11b_tx_chains = 0;
9843 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009844 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309845
9846 if (hdd_ctx->config->sifs_burst_duration) {
9847 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9848 hdd_ctx->config->sifs_burst_duration;
9849
9850 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9851 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9852 set_value, PDEV_CMD);
9853 }
9854
9855 if (hdd_ctx->config->is_force_1x1)
9856 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9857 1, PDEV_CMD);
9858 /* set chip power save failure detected callback */
9859 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9860 hdd_chip_pwr_save_fail_detected_cb);
9861
9862 if (hdd_ctx->config->max_mpdus_inampdu) {
9863 set_value = hdd_ctx->config->max_mpdus_inampdu;
9864 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9865 set_value, PDEV_CMD);
9866 }
9867
9868 if (hdd_ctx->config->enable_rts_sifsbursting) {
9869 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9870 sme_cli_set_command(0,
9871 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9872 set_value, PDEV_CMD);
9873 }
9874
9875 if (hdd_ctx->config->sap_get_peer_info) {
9876 set_value = hdd_ctx->config->sap_get_peer_info;
9877 sme_cli_set_command(0,
9878 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9879 set_value, PDEV_CMD);
9880 }
9881
9882 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9883 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9884 if (!hdd_ctx->config->enable2x2) {
9885 if (num_11b_tx_chains > 1)
9886 num_11b_tx_chains = 1;
9887 if (num_11ag_tx_chains > 1)
9888 num_11ag_tx_chains = 1;
9889 }
9890 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9891 num_11b_tx_chains);
9892 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9893 num_11ag_tx_chains);
9894 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9895 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309896
9897 ret = hdd_pre_enable_configure(hdd_ctx);
9898 if (ret) {
9899 hdd_err("Failed to pre-configure cds");
9900 goto out;
9901 }
9902
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009903 /* Always get latest IPA resources allocated from cds_open and configure
9904 * IPA module before configuring them to FW. Sequence required as crash
9905 * observed otherwise.
9906 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009907 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9908 hdd_err("Failed to setup pipes");
9909 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009910 }
9911
Arun Khandavallifae92942016-08-01 13:31:08 +05309912 /*
9913 * Start CDS which starts up the SME/MAC/HAL modules and everything
9914 * else
9915 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009916 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309917
9918 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009919 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309920 goto out;
9921 }
9922
9923 status = hdd_post_cds_enable_config(hdd_ctx);
9924 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009925 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009926 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309927 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309928 status = hdd_register_bcn_cb(hdd_ctx);
9929 if (!QDF_IS_STATUS_SUCCESS(status)) {
9930 hdd_alert("hdd_post_cds_enable_config failed");
9931 goto cds_disable;
9932 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309933
9934 ret = hdd_features_init(hdd_ctx, adapter);
9935 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009936 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309937
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009938 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009939 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009940 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9941 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009942 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009943 goto cds_disable;
9944 }
9945
Himanshu Agarwalb229a142017-12-21 10:16:45 +05309946 if (ucfg_green_ap_enable_egap(hdd_ctx->hdd_pdev))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309947 hdd_debug("enhance green ap is not enabled");
9948
Nachiket Kukadedd302662017-07-13 17:31:44 +05309949 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9950 hdd_debug("Failed to set wow pulse");
9951
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309952 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9953 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9954
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309955
9956 if (hdd_ctx->config->enable_phy_reg_retention)
9957 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9958 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9959
Arun Khandavallifae92942016-08-01 13:31:08 +05309960 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009961
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009962cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009963 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009964
Arun Khandavallifae92942016-08-01 13:31:08 +05309965out:
9966 return -EINVAL;
9967}
9968
9969/**
9970 * hdd_deconfigure_cds() -De-Configure cds
9971 * @hdd_ctx: HDD context
9972 *
9973 * Deconfigure Cds modules before WLAN firmware is down.
9974 *
9975 * Return: 0 on success and errno on failure.
9976 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009977static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309978{
9979 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009980 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309981
9982 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009983
9984 /* De-init features */
9985 hdd_features_deinit(hdd_ctx);
9986
Arun Khandavallifae92942016-08-01 13:31:08 +05309987 /* De-register the SME callbacks */
9988 hdd_deregister_cb(hdd_ctx);
9989
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009990 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309991 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9992 hdd_err("Failed to Disable the CDS Modules! :%d",
9993 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009994 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309995 }
9996
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309997 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9998 hdd_err("Failed to disconnect pipes");
9999 ret = -EINVAL;
10000 }
10001
Arun Khandavallifae92942016-08-01 13:31:08 +053010002 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010003 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010004}
10005
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010006#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10007static void hdd_deregister_policy_manager_callback(
10008 struct wlan_objmgr_psoc *psoc)
10009{
10010 if (QDF_STATUS_SUCCESS !=
10011 policy_mgr_deregister_hdd_cb(psoc)) {
10012 hdd_err("HDD callback deregister with policy manager failed");
10013 }
10014}
10015#else
10016static void hdd_deregister_policy_manager_callback(
10017 struct wlan_objmgr_psoc *psoc)
10018{
10019}
10020#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010021
10022/**
10023 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10024 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010025 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010026 *
10027 * This function maintains the driver state machine it will be invoked from
10028 * exit, shutdown and con_mode change handler. Depending on the driver state
10029 * shall perform the stopping/closing of the modules.
10030 *
10031 * Return: 0 for success; non-zero for failure
10032 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010033int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010034{
10035 void *hif_ctx;
10036 qdf_device_t qdf_ctx;
10037 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010038 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010039 bool is_recovery_stop = cds_is_driver_recovering();
10040 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop;
Dustin Brown70111822017-03-30 15:31:40 -070010041 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +053010042
10043 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -070010044 hdd_alert("stop WLAN module: entering driver status=%d",
10045 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010046
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010047 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10048
Arun Khandavallifae92942016-08-01 13:31:08 +053010049 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10050 if (!qdf_ctx) {
10051 hdd_err("QDF device context NULL");
10052 return -EINVAL;
10053 }
10054
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010055 mutex_lock(&hdd_ctx->iface_change_lock);
10056 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010057 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010058
Dustin Brown70111822017-03-30 15:31:40 -070010059 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010060 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010061 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010062 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010063
10064 cds_print_external_threads();
10065
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010066 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010067 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010068 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10069 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010070 hdd_prevent_suspend_timeout(
10071 hdd_ctx->config->iface_change_wait_time,
10072 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010073 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010074 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010075 return 0;
10076 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010077 }
10078
Arun Khandavallifae92942016-08-01 13:31:08 +053010079 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10080
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010081 /* free user wowl patterns */
10082 hdd_free_user_wowl_ptrns();
10083
Arun Khandavallifae92942016-08-01 13:31:08 +053010084 switch (hdd_ctx->driver_status) {
10085 case DRIVER_MODULES_UNINITIALIZED:
10086 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010087 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010088 case DRIVER_MODULES_CLOSED:
10089 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010090 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010091 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010092 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10093
Komal Seelamf2136bb2016-09-28 18:30:44 +053010094 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010095 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010096 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010097 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010098 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010099 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010100 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010101
Arun Khandavallifae92942016-08-01 13:31:08 +053010102 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010103 hdd_info("Wlan transitioned (now OPENED)");
10104
10105 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010106 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010107 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010108 break;
10109 default:
10110 hdd_err("Trying to stop wlan in a wrong state: %d",
10111 hdd_ctx->driver_status);
10112 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010113 ret = -EINVAL;
10114 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010115 }
10116
Dustin Brown550f6d22017-12-14 15:44:01 -080010117 hdd_debug("Closing CDS modules!");
Rajeev Kumarbe021242017-02-16 16:12:23 -080010118 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010119 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10120 hdd_err("Failed to process post CDS disable Modules! :%d",
10121 qdf_status);
10122 ret = -EINVAL;
10123 QDF_ASSERT(0);
10124 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010125
psimhadeea0a12017-12-18 14:50:02 -080010126 hdd_runtime_suspend_context_deinit(hdd_ctx);
10127
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010128 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10129 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10130 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10131 ret = -EINVAL;
10132 QDF_ASSERT(0);
10133 }
10134
Jeff Johnsone4b14592017-09-13 14:23:33 -070010135 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010136 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010137 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010138 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010139 QDF_ASSERT(0);
10140 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010141
Liangwei Dong50a64a72018-01-11 01:17:00 -050010142 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10143 if (ret) {
10144 hdd_err("Failed to destroy pdev; errno:%d", ret);
10145 QDF_ASSERT(0);
10146 }
10147
10148 /*
10149 * Reset total mac phy during module stop such that during
10150 * next module start same psoc is used to populate new service
10151 * ready data
10152 */
10153 hdd_ctx->hdd_psoc->total_mac_phy = 0;
10154
Arun Khandavallifae92942016-08-01 13:31:08 +053010155 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10156 if (!hif_ctx) {
10157 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010158 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010159 }
10160
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010161 if (hdd_ctx->target_hw_name) {
10162 qdf_mem_free(hdd_ctx->target_hw_name);
10163 hdd_ctx->target_hw_name = NULL;
10164 }
10165
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010166 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010167
10168 ol_cds_free();
10169
Dustin Brown70111822017-03-30 15:31:40 -070010170 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010171 ret = pld_power_off(qdf_ctx->dev);
10172 if (ret)
10173 hdd_err("CNSS power down failed put device into Low power mode:%d",
10174 ret);
10175 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010176
Dustin Brown4bc0a622017-12-06 15:56:50 -080010177 /* many adapter resources are not freed by design in SSR case */
10178 if (!is_recovery_stop)
10179 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010180 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010181
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010182 /* Once the firmware sequence is completed reset this flag */
10183 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010184 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010185 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010186
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010187done:
10188 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010189 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010190 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010191 hdd_alert("stop WLAN module: exit driver status=%d",
10192 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010193
Arun Khandavallifae92942016-08-01 13:31:08 +053010194 EXIT();
10195
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010196 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010197}
10198
Arun Khandavallifae92942016-08-01 13:31:08 +053010199
10200/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010201 * hdd_state_info_dump() - prints state information of hdd layer
10202 * @buf: buffer pointer
10203 * @size: size of buffer to be filled
10204 *
10205 * This function is used to dump state information of hdd layer
10206 *
10207 * Return: None
10208 */
10209static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10210{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010211 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010212 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010213 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010214 uint16_t len = 0;
10215 char *buf = *buf_ptr;
10216
10217 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10218 if (!hdd_ctx) {
10219 hdd_err("Failed to get hdd context ");
10220 return;
10221 }
10222
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010223 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010224
10225 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010226 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010227 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010228 "\n is_scheduler_suspended %d",
10229 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010230
Dustin Brown920397d2017-12-13 16:27:50 -080010231 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010232 if (adapter->dev)
10233 len += scnprintf(buf + len, *size - len,
10234 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010235 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010236 "\n device_mode: %d", adapter->device_mode);
10237 switch (adapter->device_mode) {
10238 case QDF_STA_MODE:
10239 case QDF_P2P_CLIENT_MODE:
10240 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10241 len += scnprintf(buf + len, *size - len,
10242 "\n connState: %d",
10243 hdd_sta_ctx->conn_info.connState);
10244 break;
10245
10246 default:
10247 break;
10248 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010249 }
10250
10251 *size -= len;
10252 *buf_ptr += len;
10253}
10254
10255/**
10256 * hdd_register_debug_callback() - registration function for hdd layer
10257 * to print hdd state information
10258 *
10259 * Return: None
10260 */
10261static void hdd_register_debug_callback(void)
10262{
10263 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10264}
10265
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010266/*
10267 * wlan_init_bug_report_lock() - Initialize bug report lock
10268 *
10269 * This function is used to create bug report lock
10270 *
10271 * Return: None
10272 */
10273static void wlan_init_bug_report_lock(void)
10274{
10275 p_cds_contextType p_cds_context;
10276
10277 p_cds_context = cds_get_global_context();
10278 if (!p_cds_context) {
10279 hdd_err("cds context is NULL");
10280 return;
10281 }
10282
10283 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10284}
10285
Mohit Khannaf8f96822017-05-17 17:11:59 -070010286void hdd_dp_trace_init(struct hdd_config *config)
10287{
10288
10289 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10290 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10291 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10292 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10293 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10294 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10295 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010296 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010297
10298 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10299 &num_entries, sizeof(config_params));
10300
10301 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010302 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010303 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010304 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010305 else if (bw_compute_interval > 1000) {
10306 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10307 thresh_time_limit = 1;
10308 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010309 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10310
10311 switch (num_entries) {
10312 case 4:
10313 proto_bitmap = config_params[3];
10314 case 3:
10315 verbosity = config_params[2];
10316 case 2:
10317 thresh = config_params[1];
10318 case 1:
10319 live_mode = config_params[0];
10320 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010321 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010322 live_mode, thresh, thresh_time_limit,
10323 verbosity, proto_bitmap);
10324 };
10325
10326 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10327 verbosity, proto_bitmap);
10328
10329}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010330/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010331 * hdd_wlan_startup() - HDD init function
10332 * @dev: Pointer to the underlying device
10333 *
10334 * This is the driver startup code executed once a WLAN device has been detected
10335 *
10336 * Return: 0 for success, < 0 for failure
10337 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010338int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010339{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010340 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010341 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010342 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010343 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010344
10345 ENTER();
10346
Arun Khandavallifae92942016-08-01 13:31:08 +053010347 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010348
10349 if (IS_ERR(hdd_ctx))
10350 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010351
Abhishek Singhe9068f12017-03-31 14:14:52 +053010352 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10353 DEFAULT_PSOC_ID);
10354 if (ret) {
10355 hdd_err("Psoc creation fails!");
10356 QDF_BUG(0);
10357 goto err_hdd_free_context;
10358 }
10359
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010360 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010361#ifdef FEATURE_WLAN_CH_AVOID
10362 mutex_init(&hdd_ctx->avoid_freq_lock);
10363#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010364
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010365 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010366 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010367
Dustin Brown021cecd2017-12-11 13:56:43 -080010368 hdd_driver_memdump_init();
10369
Jeff Johnson957bc272017-02-02 08:54:48 -080010370 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010371 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010372 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010373 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010374 }
10375
Yingying Tang80e15f32016-09-27 18:23:01 +080010376 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010377
Anurag Chouhan6d760662016-02-20 16:05:43 +053010378 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010379
10380 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010381 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010382 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010383 }
10384
Prashanth Bhatta07998752016-04-28 12:35:33 -070010385 ret = hdd_wiphy_init(hdd_ctx);
10386 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010387 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010388 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010389 }
10390
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010391 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010392 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010393
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010394 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010395 goto err_wiphy_unregister;
10396
Kapil Gupta4f0c0c12017-02-07 15:21:15 +053010397 wlan_hdd_init_chan_info(hdd_ctx);
10398
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010399 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010400
Paul Zhangfb02f452017-12-22 11:58:43 +080010401 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10402 if (ret) {
10403 hdd_err("register_netdevice_notifier failed: %d", ret);
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010404 goto err_ipa_cleanup;
Paul Zhangfb02f452017-12-22 11:58:43 +080010405 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010406
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010407 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010408
Jeff Johnson957bc272017-02-02 08:54:48 -080010409 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10410 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010411 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010412 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010413 }
10414
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010415 hdd_release_rtnl_lock();
10416 rtnl_held = false;
10417
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010418 wlan_hdd_update_11n_mode(hdd_ctx->config);
10419
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010420#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010421 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010422 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010423 hdd_skip_acs_scan_timer_handler,
10424 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010425 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010426 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010427 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010428#endif
10429
Prashanth Bhattaab004382016-10-11 16:08:11 -070010430 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010431
Jeff Johnson9afc5012016-09-23 13:56:27 -070010432 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010433
Nirav Shahbd36b062016-07-18 11:12:59 +053010434 if (hdd_ctx->rps)
10435 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010436
Paul Zhangfb02f452017-12-22 11:58:43 +080010437 ret = hdd_register_notifiers(hdd_ctx);
10438 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010439 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010440
Paul Zhangfb02f452017-12-22 11:58:43 +080010441 status = wlansap_global_init();
10442 if (QDF_IS_STATUS_ERROR(status)) {
10443 hdd_unregister_notifiers(hdd_ctx);
10444 goto err_close_adapters;
10445 }
10446
Arun Khandavallifae92942016-08-01 13:31:08 +053010447 if (hdd_ctx->config->fIsImpsEnabled)
10448 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010449 else
10450 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010451
Mukul Sharma07bd8752017-10-10 16:58:14 +053010452 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010453 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10454 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010455 hdd_prevent_suspend_timeout(
10456 hdd_ctx->config->iface_change_wait_time,
10457 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10458 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010459
Sachin Ahujadddd2632017-03-07 19:07:24 +053010460 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010461 goto success;
10462
Jeff Johnson957bc272017-02-02 08:54:48 -080010463err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010464 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010465
Jeff Johnson46bde382017-02-01 15:31:16 -080010466err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010467 if (rtnl_held)
10468 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010469
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010470 unregister_netdevice_notifier(&hdd_netdev_notifier);
10471
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010472err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010473 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010474
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010475err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010476 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010477
Arun Khandavallifae92942016-08-01 13:31:08 +053010478err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010479 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010480
Dustin Brown021cecd2017-12-11 13:56:43 -080010481err_memdump_deinit:
10482 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010483
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010484 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010485 hdd_exit_netlink_services(hdd_ctx);
10486
Dustin Brown20912462017-06-07 13:48:25 -070010487 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10488
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010489err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010490 if (cds_is_fw_down())
10491 hdd_err("Not setting the complete event as fw is down");
10492 else
10493 hdd_start_complete(ret);
10494
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010495 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010496 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010497 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010498
10499success:
10500 EXIT();
10501 return 0;
10502}
10503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010504/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010505 * hdd_wlan_update_target_info() - update target type info
10506 * @hdd_ctx: HDD context
10507 * @context: hif context
10508 *
10509 * Update target info received from firmware in hdd context
10510 * Return:None
10511 */
10512
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010513void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010514{
10515 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10516
10517 if (!tgt_info) {
10518 hdd_err("Target info is Null");
10519 return;
10520 }
10521
10522 hdd_ctx->target_type = tgt_info->target_type;
10523}
10524
10525/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010526 * hdd_get_nud_stats_cb() - callback api to update the stats
10527 * received from the firmware
10528 * @data: pointer to adapter.
10529 * @rsp: pointer to data received from FW.
10530 *
10531 * This is called when wlan driver received response event for
10532 * get arp stats to firmware.
10533 *
10534 * Return: None
10535 */
10536static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10537{
10538 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10539 struct hdd_nud_stats_context *context;
10540 int status;
10541 struct hdd_adapter *adapter = NULL;
10542
10543 ENTER();
10544
10545 if (!rsp) {
10546 hdd_err("data is null");
10547 return;
10548 }
10549
10550 status = wlan_hdd_validate_context(hdd_ctx);
10551 if (0 != status)
10552 return;
10553
10554 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10555 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10556 hdd_err("Invalid adapter or adapter has invalid magic");
10557 return;
10558 }
10559
10560 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10561 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10562 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10563 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10564 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10565 rsp->out_of_order_arp_rsp_drop_cnt);
10566 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10567 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10568 hdd_notice("rsp->ba_session_establishment_status :%x",
10569 rsp->ba_session_establishment_status);
10570
10571 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10572 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10573 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10574 adapter->dad |= rsp->dad_detected;
10575 adapter->con_status = rsp->connect_status;
10576
10577 spin_lock(&hdd_context_lock);
10578 context = &hdd_ctx->nud_stats_context;
10579 complete(&context->response_event);
10580 spin_unlock(&hdd_context_lock);
10581
10582 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010583}
10584
10585/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010586 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010587 * @hdd_ctx: HDD context
10588 *
10589 * Register the HDD callbacks to CDS/SME.
10590 *
10591 * Return: 0 for success or Error code for failure
10592 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010593int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010594{
10595 QDF_STATUS status;
10596 int ret = 0;
10597
10598 ENTER();
10599
10600 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10601
10602 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10603 hdd_send_oem_data_rsp_msg);
10604
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010605 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10606 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010607 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10608 sme_nan_register_callback(hdd_ctx->hHal,
10609 wlan_hdd_cfg80211_nan_callback);
10610 sme_stats_ext_register_callback(hdd_ctx->hHal,
10611 wlan_hdd_cfg80211_stats_ext_callback);
10612
10613 sme_ext_scan_register_callback(hdd_ctx->hHal,
10614 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010615 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10616 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010617
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010618 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10619 hdd_rssi_threshold_breached);
10620
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010621 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10622
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010623 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10624 wlan_hdd_cfg80211_link_layer_stats_callback);
10625
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010626 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10627
Zhang Qianca38fb12016-12-23 11:10:48 +080010628 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10629 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10630
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010631 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10632 hdd_lost_link_info_cb);
10633 /* print error and not block the startup process */
10634 if (!QDF_IS_STATUS_SUCCESS(status))
10635 hdd_err("set lost link info callback failed");
10636
Poddar, Siddarth34872782017-08-10 14:08:51 +053010637 ret = hdd_register_data_stall_detect_cb();
10638 if (ret) {
10639 hdd_err("Register data stall detect detect callback failed.");
10640 return ret;
10641 }
10642
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010643 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10644
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010645 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010646 hdd_set_connection_in_progress,
10647 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010648
10649 status = sme_congestion_register_callback(hdd_ctx->hHal,
10650 hdd_update_cca_info_cb);
10651 if (!QDF_IS_STATUS_SUCCESS(status))
10652 hdd_err("set congestion callback failed");
10653
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010654 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10655 hdd_bt_activity_cb);
10656 if (!QDF_IS_STATUS_SUCCESS(status))
10657 hdd_err("set bt activity info callback failed");
10658
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010659 EXIT();
10660
10661 return ret;
10662}
10663
10664/**
10665 * hdd_deregister_cb() - De-Register HDD callbacks.
10666 * @hdd_ctx: HDD context
10667 *
10668 * De-Register the HDD callbacks to CDS/SME.
10669 *
10670 * Return: void
10671 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010672void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010673{
10674 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010675 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010676
10677 ENTER();
10678
10679 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10680 if (!QDF_IS_STATUS_SUCCESS(status))
10681 hdd_err("De-register of dcc stats callback failed: %d",
10682 status);
10683
10684 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010685 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10686
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010687 sme_stats_ext_register_callback(hdd_ctx->hHal,
10688 wlan_hdd_cfg80211_stats_ext_callback);
10689
10690 sme_nan_deregister_callback(hdd_ctx->hHal);
10691 status = sme_reset_tsfcb(hdd_ctx->hHal);
10692 if (!QDF_IS_STATUS_SUCCESS(status))
10693 hdd_err("Failed to de-register tsfcb the callback:%d",
10694 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010695
Poddar, Siddarth34872782017-08-10 14:08:51 +053010696 ret = hdd_deregister_data_stall_detect_cb();
10697 if (ret)
10698 hdd_err("Failed to de-register data stall detect event callback");
10699
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010700 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10701 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10702
10703 EXIT();
10704}
10705
10706/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010707 * hdd_softap_sta_deauth() - handle deauth req from HDD
10708 * @adapter: Pointer to the HDD
10709 * @enable: bool value
10710 *
10711 * This to take counter measure to handle deauth req from HDD
10712 *
10713 * Return: None
10714 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010715QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010716 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010717{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010718 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010719
10720 ENTER();
10721
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010722 /* Ignore request to deauth bcmc station */
10723 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010724 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010725
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010726 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010727 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10728 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010729
10730 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010731 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010732}
10733
10734/**
10735 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10736 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010737 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010738 *
10739 * This to take counter measure to handle deauth req from HDD
10740 *
10741 * Return: None
10742 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010743void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010744 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010745{
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010746 struct sir_peer_sta_info peer_sta_info;
10747 struct hdd_station_info *stainfo;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010748 ENTER();
10749
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010750 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010751 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010752 return;
10753
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010754 wlan_hdd_get_peer_rssi(adapter, &pDelStaParams->peerMacAddr,
10755 &peer_sta_info);
10756 stainfo = hdd_get_stainfo(adapter->cache_sta_info,
10757 pDelStaParams->peerMacAddr);
10758 if (stainfo) {
10759 stainfo->rssi = peer_sta_info.info[0].rssi;
10760 stainfo->tx_rate = peer_sta_info.info[0].tx_rate;
10761 stainfo->rx_rate = peer_sta_info.info[0].rx_rate;
10762 }
10763
10764 stainfo->reason_code = pDelStaParams->reason_code;
10765
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010766 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010767 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010768}
10769
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010770/**
10771 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10772 * @hdd_ctx: HDD Context
10773 *
10774 * API to find if there is any STA or P2P-Client is connected
10775 *
10776 * Return: true if connected; false otherwise
10777 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010778QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010779{
10780 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10781}
10782
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010783/**
10784 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10785 * @adapter: HDD adapter pointer
10786 *
10787 * This function loop through each adapter and disable roaming on each STA
10788 * device mode except the input adapter.
10789 *
10790 * Note: On the input adapter roaming is not enabled yet hence no need to
10791 * disable.
10792 *
10793 * Return: None
10794 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010795void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010796{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010797 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010798 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010799
10800 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010801 hdd_ctx->config->isRoamOffloadScanEnabled &&
10802 QDF_STA_MODE == adapter->device_mode &&
10803 policy_mgr_is_sta_active_connection_exists(
10804 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010805 hdd_debug("Connect received on STA session Id(%d)",
10806 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010807 /*
10808 * Loop through adapter and disable roaming for each STA device
10809 * mode except the input adapter.
10810 */
Dustin Brown920397d2017-12-13 16:27:50 -080010811 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010812 if (QDF_STA_MODE == adapterIdx->device_mode &&
10813 adapter->session_id != adapterIdx->session_id) {
10814 hdd_debug("Disable Roaming on session Id(%d)",
10815 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010816 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10817 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010818 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010819 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010820 }
10821 }
10822}
10823
10824/**
10825 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10826 * @adapter: HDD adapter pointer
10827 *
10828 * This function loop through each adapter and enable roaming on each STA
10829 * device mode except the input adapter.
10830 * Note: On the input adapter no need to enable roaming because link got
10831 * disconnected on this.
10832 *
10833 * Return: None
10834 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010835void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010836{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010837 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010838 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010839
10840 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010841 hdd_ctx->config->isRoamOffloadScanEnabled &&
10842 QDF_STA_MODE == adapter->device_mode &&
10843 policy_mgr_is_sta_active_connection_exists(
10844 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010845 hdd_debug("Disconnect received on STA session Id(%d)",
10846 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010847 /*
10848 * Loop through adapter and enable roaming for each STA device
10849 * mode except the input adapter.
10850 */
Dustin Brown920397d2017-12-13 16:27:50 -080010851 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010852 if (QDF_STA_MODE == adapterIdx->device_mode &&
10853 adapter->session_id != adapterIdx->session_id) {
10854 hdd_debug("Enabling Roaming on session Id(%d)",
10855 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010856 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10857 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010858 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010859 REASON_CONNECT);
10860 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010861 }
10862 }
10863}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010864
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010865/**
10866 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10867 * @skb: sk buffer pointer
10868 *
10869 * Sends the bcast message to SVC multicast group with generic nl socket
10870 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10871 *
10872 * Return: None
10873 */
10874static void nl_srv_bcast_svc(struct sk_buff *skb)
10875{
10876#ifdef CNSS_GENL
10877 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10878#else
10879 nl_srv_bcast(skb);
10880#endif
10881}
10882
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010883void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010884{
10885 struct sk_buff *skb;
10886 struct nlmsghdr *nlh;
10887 tAniMsgHdr *ani_hdr;
10888 void *nl_data = NULL;
10889 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010890 struct radio_index_tlv *radio_info;
10891 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010892
10893 if (in_interrupt() || irqs_disabled() || in_atomic())
10894 flags = GFP_ATOMIC;
10895
10896 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10897
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010898 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010899 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010900
10901 nlh = (struct nlmsghdr *)skb->data;
10902 nlh->nlmsg_pid = 0; /* from kernel */
10903 nlh->nlmsg_flags = 0;
10904 nlh->nlmsg_seq = 0;
10905 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10906
10907 ani_hdr = NLMSG_DATA(nlh);
10908 ani_hdr->type = type;
10909
10910 switch (type) {
10911 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010912 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010913 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010914 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010915 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010916 ani_hdr->length = 0;
10917 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010918 break;
10919 case WLAN_SVC_WLAN_STATUS_IND:
10920 case WLAN_SVC_WLAN_VERSION_IND:
10921 case WLAN_SVC_DFS_CAC_START_IND:
10922 case WLAN_SVC_DFS_CAC_END_IND:
10923 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10924 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10925 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010926 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010927 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010928 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010929 ani_hdr->length = len;
10930 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10931 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10932 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010933 break;
10934
10935 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010936 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010937 type);
10938 kfree_skb(skb);
10939 return;
10940 }
10941
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010942 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010943 * Add radio index at the end of the svc event in TLV format
10944 * to maintain the backward compatibility with userspace
10945 * applications.
10946 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010947
10948 tlv_len = 0;
10949
10950 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10951 < WLAN_NL_MAX_PAYLOAD) {
10952 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10953 sizeof(*ani_hdr) + len);
10954 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10955 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10956 radio_info->radio = radio;
10957 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010958 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010959 "Added radio index tlv - radio index %d",
10960 radio_info->radio);
10961 }
10962
10963 nlh->nlmsg_len += tlv_len;
10964 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10965
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010966 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010967}
10968
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010969#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10970void wlan_hdd_auto_shutdown_cb(void)
10971{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010972 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010973
10974 if (!hdd_ctx)
10975 return;
10976
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010977 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010978 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10979 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010980}
10981
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010982void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010983{
Jeff Johnson9d295242017-08-29 14:39:48 -070010984 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010985 bool ap_connected = false, sta_connected = false;
10986 tHalHandle hal_handle;
10987
10988 hal_handle = hdd_ctx->hHal;
10989 if (hal_handle == NULL)
10990 return;
10991
10992 if (hdd_ctx->config->WlanAutoShutdown == 0)
10993 return;
10994
10995 if (enable == false) {
10996 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010997 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010998 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010999 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011000 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011001 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011002 return;
11003 }
11004
11005 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011006 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11007 hdd_for_each_adapter(hdd_ctx, adapter) {
11008 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011009 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11010 conn_info.connState ==
11011 eConnectionState_Associated) {
11012 sta_connected = true;
11013 break;
11014 }
11015 }
Dustin Brown920397d2017-12-13 16:27:50 -080011016
11017 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011018 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011019 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011020 ap_connected = true;
11021 break;
11022 }
11023 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011024 }
11025 }
11026
11027 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011028 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011029 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011030 }
Jeff Johnson68755312017-02-10 11:46:55 -080011031
11032 if (sme_set_auto_shutdown_timer(hal_handle,
11033 hdd_ctx->config->WlanAutoShutdown)
11034 != QDF_STATUS_SUCCESS)
11035 hdd_err("Failed to start wlan auto shutdown timer");
11036 else
11037 hdd_notice("Auto Shutdown timer for %d seconds enabled",
11038 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011039}
11040#endif
11041
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011042struct hdd_adapter *
11043hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11044 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011045{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011046 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011047 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011048
11049 con_sap_adapter = NULL;
11050
Dustin Brown920397d2017-12-13 16:27:50 -080011051 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011052 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11053 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011054 adapter != this_sap_adapter) {
11055 if (check_start_bss) {
11056 if (test_bit(SOFTAP_BSS_STARTED,
11057 &adapter->event_flags)) {
11058 con_sap_adapter = adapter;
11059 break;
11060 }
11061 } else {
11062 con_sap_adapter = adapter;
11063 break;
11064 }
11065 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011066 }
11067
11068 return con_sap_adapter;
11069}
11070
11071#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011072static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011073{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011074 return adapter->device_mode == QDF_STA_MODE ||
11075 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011076}
11077
Jeff Johnson9d295242017-08-29 14:39:48 -070011078static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011079{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011080 return adapter->device_mode == QDF_SAP_MODE ||
11081 adapter->device_mode == QDF_P2P_GO_MODE;
11082}
11083
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011084static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011085{
Dustin Brown920397d2017-12-13 16:27:50 -080011086 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011087
Dustin Brown920397d2017-12-13 16:27:50 -080011088 hdd_for_each_adapter(hdd_ctx, adapter) {
11089 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011090 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11091 conn_info.connState == eConnectionState_Associated) {
11092 return true;
11093 }
11094
Dustin Brown920397d2017-12-13 16:27:50 -080011095 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011096 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011097 return true;
11098 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011099 }
11100
11101 return false;
11102}
11103
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011104static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011105{
11106 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011107
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011108 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011109 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011110 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011111
Dustin Brown5ec6b552017-03-31 12:11:40 -070011112 return is_running;
11113}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011114
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011115static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011116{
11117 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11118 hdd_ctx->bus_bw_timer_running = true;
11119 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11120 hdd_ctx->config->busBandwidthComputeInterval);
11121 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11122}
11123
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011124void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011125{
11126 ENTER();
11127
11128 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11129 hdd_debug("Bandwidth compute timer already started");
11130 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011131 }
11132
Dustin Brown5ec6b552017-03-31 12:11:40 -070011133 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11134
11135 EXIT();
11136}
11137
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011138void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011139{
11140 ENTER();
11141
11142 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11143 hdd_debug("Bandwidth compute timer already started");
11144 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011145 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011146
11147 if (hdd_any_adapter_is_assoc(hdd_ctx))
11148 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11149
11150 EXIT();
11151}
11152
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011153static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011154{
11155 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
11156
11157 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11158 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11159 hdd_ctx->bus_bw_timer_running = false;
11160 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11161
11162 hdd_reset_tcp_delack(hdd_ctx);
11163}
11164
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011165void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011166{
11167 ENTER();
11168
11169 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11170 hdd_debug("Bandwidth compute timer already stopped");
11171 return;
11172 }
11173
11174 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11175
11176 EXIT();
11177}
11178
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011179void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011180{
11181 ENTER();
11182
11183 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11184 hdd_debug("Bandwidth compute timer already stopped");
11185 return;
11186 }
11187
11188 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11189 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11190
11191 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011192}
11193#endif
11194
11195/**
11196 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11197 * and sta's operating channel.
11198 * @sta_adapter: Describe the first argument to foobar.
11199 * @ap_adapter: Describe the second argument to foobar.
11200 * @roam_profile: Roam profile of AP to which STA wants to connect.
11201 * @concurrent_chnl_same: If both SAP and STA channels are same then
11202 * set this flag to true else false.
11203 *
11204 * This function checks the sap's operating channel and sta's operating channel.
11205 * if both are same then it will return false else it will restart the sap in
11206 * sta's channel and return true.
11207 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011208 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011209 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011210QDF_STATUS
11211wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11212 struct hdd_adapter *ap_adapter,
11213 tCsrRoamProfile *roam_profile,
11214 tScanResultHandle *scan_cache,
11215 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011216{
Jeff Johnson87251032017-08-29 13:31:11 -070011217 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011218 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011219 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011220 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011221 *concurrent_chnl_same = true;
11222
11223 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11224 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011225 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011226 scan_cache,
11227 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011228 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011229 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011230 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011231 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011232 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011233 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011234 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011235 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011236 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011237 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011238 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011239 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011240 }
11241 }
11242 } else {
11243 /*
11244 * Lets handle worst case scenario here, Scan cache lookup is
11245 * failed so we have to stop the SAP to avoid any channel
11246 * discrepancy between SAP's channel and STA's channel.
11247 * Return the status as failure so caller function could know
11248 * that scan look up is failed.
11249 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011250 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011251 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011252 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011253 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011254}
11255
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011256/**
11257 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11258 * @ap_adapter: SAP adapter
11259 *
11260 * This function will process the stopping of sap adapter.
11261 *
11262 * Return: None
11263 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011264void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011265{
Jeff Johnson87251032017-08-29 13:31:11 -070011266 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011267 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011268 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011269 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011270
11271 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011272 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011273 return;
11274 }
11275
11276 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11277 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011278 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011279 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011280
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011281 mutex_lock(&hdd_ctx->sap_lock);
11282 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011283 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011284 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011285 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011286 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011287 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011288 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011289 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011290 qdf_stop_bss_event,
11291 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011292 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011293 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011294 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011295 return;
11296 }
11297 }
11298 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011299 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11300 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011301 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011302 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011303 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011304 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011305 }
11306 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011307}
11308
11309/**
11310 * wlan_hdd_start_sap() - this function starts bss of SAP.
11311 * @ap_adapter: SAP adapter
11312 *
11313 * This function will process the starting of sap adapter.
11314 *
11315 * Return: None
11316 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011317void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011318{
Jeff Johnson87251032017-08-29 13:31:11 -070011319 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011320 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011321 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011322 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011323 tsap_Config_t *sap_config;
11324
11325 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011326 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011327 return;
11328 }
11329
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011330 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011331 hdd_err("SoftAp role has not been enabled");
11332 return;
11333 }
11334
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011335 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11336 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11337 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011338 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011340 mutex_lock(&hdd_ctx->sap_lock);
11341 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11342 goto end;
11343
11344 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011345 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011346 goto end;
11347 }
11348
Wei Song2f76f642016-11-18 16:32:53 +080011349 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011350 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011351 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011352 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011353 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011354 goto end;
11355
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011356 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011357 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011358 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011359 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011360 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011361 goto end;
11362 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011363 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011364 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011365 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011366 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011367 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11368 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011369 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011370 mutex_unlock(&hdd_ctx->sap_lock);
11371
11372 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011373end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011374 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011375 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011376 /* SAP context and beacon cleanup will happen during driver unload
11377 * in hdd_stop_adapter
11378 */
11379 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11380
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011381}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011382
11383/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011384 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11385 * mac scan config
11386 * @status: Status of set antenna mode
11387 *
11388 * Callback on setting the dual mac configuration
11389 *
11390 * Return: None
11391 */
11392void wlan_hdd_soc_set_antenna_mode_cb(
11393 enum set_antenna_mode_status status)
11394{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011395 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011396
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011397 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011398
11399 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11400 if (0 != wlan_hdd_validate_context(hdd_ctx))
11401 return;
11402
11403 /* Signal the completion of set dual mac config */
11404 complete(&hdd_ctx->set_antenna_mode_cmpl);
11405}
11406
11407/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011408 * hdd_get_fw_version() - Get FW version
11409 * @hdd_ctx: pointer to HDD context.
11410 * @major_spid: FW version - major spid.
11411 * @minor_spid: FW version - minor spid
11412 * @ssid: FW version - ssid
11413 * @crmid: FW version - crmid
11414 *
11415 * This function is called to get the firmware build version stored
11416 * as part of the HDD context
11417 *
11418 * Return: None
11419 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011420void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011421 uint32_t *major_spid, uint32_t *minor_spid,
11422 uint32_t *siid, uint32_t *crmid)
11423{
11424 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11425 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11426 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11427 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11428}
11429
11430#ifdef QCA_CONFIG_SMP
11431/**
11432 * wlan_hdd_get_cpu() - get cpu_index
11433 *
11434 * Return: cpu_index
11435 */
11436int wlan_hdd_get_cpu(void)
11437{
11438 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011439
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011440 put_cpu();
11441 return cpu_index;
11442}
11443#endif
11444
11445/**
11446 * hdd_get_fwpath() - get framework path
11447 *
11448 * This function is used to get the string written by
11449 * userspace to start the wlan driver
11450 *
11451 * Return: string
11452 */
11453const char *hdd_get_fwpath(void)
11454{
11455 return fwpath.string;
11456}
11457
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011458static int hdd_qdf_print_init(void)
11459{
11460 int qdf_print_idx;
11461 QDF_STATUS status;
11462
11463 status = qdf_print_setup();
11464 if (status != QDF_STATUS_SUCCESS) {
11465 pr_err("qdf_print_setup failed\n");
11466 return -EINVAL;
11467 }
11468
11469 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11470
11471 if (qdf_print_idx < 0) {
11472 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11473 qdf_print_idx);
11474 return -EINVAL;
11475 }
11476
11477 qdf_set_pidx(qdf_print_idx);
11478
11479 return 0;
11480}
11481
11482static void hdd_qdf_print_deinit(void)
11483{
11484 int qdf_print_idx;
11485
11486 qdf_print_idx = qdf_get_pidx();
11487 qdf_print_ctrl_cleanup(qdf_print_idx);
11488}
11489
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011490/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011491 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011492 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011493 * This function initilizes CDS global context with the help of cds_init. This
11494 * has to be the first function called after probe to get a valid global
11495 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011496 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011497 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011498 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011499int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011500{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011501 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011502 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011503
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011504 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011505 if (QDF_IS_STATUS_ERROR(status)) {
11506 hdd_err("Failed to allocate CDS context");
11507 ret = -ENOMEM;
11508 goto err_out;
11509 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011510
11511 wlan_init_bug_report_lock();
11512
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011513#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11514 wlan_logging_sock_init_svc();
11515#endif
11516
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011517 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11518 (void *)hdd_drv_ops_inactivity_handler, NULL,
11519 QDF_TIMER_TYPE_SW);
11520
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011521 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011522 hdd_qdf_print_init();
11523
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011524 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011525
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011526err_out:
11527 return ret;
11528}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011529
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011530/**
11531 * hdd_deinit() - Deinitialize Driver
11532 *
11533 * This function frees CDS global context with the help of cds_deinit. This
11534 * has to be the last function call in remove callback to free the global
11535 * context.
11536 */
11537void hdd_deinit(void)
11538{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011539 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011540
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011541 wlan_destroy_bug_report_lock();
11542 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011543
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011544 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011545#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11546 wlan_logging_sock_deinit_svc();
11547#endif
11548}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011549
Yue Ma6e7b1a02017-04-03 14:17:46 -070011550#ifdef QCA_WIFI_NAPIER_EMULATION
11551#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11552#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011553#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011554#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011555
Sachin Ahujadddd2632017-03-07 19:07:24 +053011556static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11557 struct file *file)
11558{
11559 return 0;
11560}
11561
11562static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11563 const char __user *user_buf,
11564 size_t count,
11565 loff_t *f_pos)
11566{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011567 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011568 static const char wlan_off_str[] = "OFF";
11569 static const char wlan_on_str[] = "ON";
11570 int ret;
11571 unsigned long rc;
11572
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011573 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011574 pr_err("Failed to read buffer\n");
11575 return -EINVAL;
11576 }
11577
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011578 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011579 pr_debug("Wifi turning off from UI\n");
11580 goto exit;
11581 }
11582
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011583 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011584 pr_err("Invalid value received from framework");
11585 goto exit;
11586 }
11587
11588 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011589 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011590 rc = wait_for_completion_timeout(&wlan_start_comp,
11591 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11592 if (!rc) {
11593 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11594 ret = -EINVAL;
11595 hdd_start_complete(ret);
11596 return ret;
11597 }
11598
11599 hdd_start_complete(0);
11600 }
11601
11602exit:
11603 return count;
11604}
11605
11606
11607const struct file_operations wlan_hdd_state_fops = {
11608 .owner = THIS_MODULE,
11609 .open = wlan_hdd_state_ctrl_param_open,
11610 .write = wlan_hdd_state_ctrl_param_write,
11611};
11612
11613static int wlan_hdd_state_ctrl_param_create(void)
11614{
11615 unsigned int wlan_hdd_state_major = 0;
11616 int ret;
11617 struct device *dev;
11618
11619 device = MKDEV(wlan_hdd_state_major, 0);
11620
11621 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11622 if (ret) {
11623 pr_err("Failed to register qcwlanstate");
11624 goto dev_alloc_err;
11625 }
11626 wlan_hdd_state_major = MAJOR(device);
11627
11628 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11629 if (IS_ERR(class)) {
11630 pr_err("wlan_hdd_state class_create error");
11631 goto class_err;
11632 }
11633
11634 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11635 if (IS_ERR(dev)) {
11636 pr_err("wlan_hdd_statedevice_create error");
11637 goto err_class_destroy;
11638 }
11639
11640 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11641 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11642 if (ret) {
11643 pr_err("Failed to add cdev error");
11644 goto cdev_add_err;
11645 }
11646
11647 pr_info("wlan_hdd_state %s major(%d) initialized",
11648 WLAN_MODULE_NAME, wlan_hdd_state_major);
11649
11650 return 0;
11651
11652cdev_add_err:
11653 device_destroy(class, device);
11654err_class_destroy:
11655 class_destroy(class);
11656class_err:
11657 unregister_chrdev_region(device, dev_num);
11658dev_alloc_err:
11659 return -ENODEV;
11660}
11661
11662static void wlan_hdd_state_ctrl_param_destroy(void)
11663{
11664 cdev_del(&wlan_hdd_state_cdev);
11665 device_destroy(class, device);
11666 class_destroy(class);
11667 unregister_chrdev_region(device, dev_num);
11668
11669 pr_info("Device node unregistered");
11670}
11671
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011672/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011673 * component_init - API to init cld component's
11674 *
11675 * Return: None
11676 */
11677static void component_init(void)
11678{
11679 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011680 disa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011681}
11682
11683/**
11684 * component_deinit - API to deinit cld component's
11685 *
11686 * Return: None
11687 */
11688static void component_deinit(void)
11689{
11690 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011691 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011692}
11693
11694void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11695{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011696 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011697}
11698
11699void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11700{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011701 disa_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011702}
11703
11704/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011705 * __hdd_module_init - Module init helper
11706 *
11707 * Module init helper function used by both module and static driver.
11708 *
11709 * Return: 0 for success, errno on failure
11710 */
11711static int __hdd_module_init(void)
11712{
11713 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011714
Dustin Brown96cd9632017-11-13 12:45:04 -080011715 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011716 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011717 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011718 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011719
Sachin Ahujadddd2632017-03-07 19:07:24 +053011720 ret = wlan_hdd_state_ctrl_param_create();
11721 if (ret) {
11722 pr_err("wlan_hdd_state_create:%x\n", ret);
11723 goto err_dev_state;
11724 }
11725
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011726 pld_init();
11727
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011728 ret = hdd_init();
11729 if (ret) {
11730 pr_err("hdd_init failed %x\n", ret);
11731 goto err_hdd_init;
11732 }
11733
Rajeev Kumar97767a02016-11-30 11:20:40 -080011734 dispatcher_init();
11735
Mukul Sharmad75a6672017-06-22 15:40:53 +053011736 /* Ensure to call post objmgr init */
11737 component_init();
11738
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011739 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011740
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011741 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011742
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011743 ret = wlan_hdd_register_driver();
11744 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011745 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11746 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011747 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011748 }
11749
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011750 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011751
11752 return 0;
11753out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011754 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011755 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011756 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011757 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011758
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011759err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011760 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011761 wlan_hdd_state_ctrl_param_destroy();
11762err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011763 return ret;
11764}
11765
11766/**
11767 * __hdd_module_exit - Module exit helper
11768 *
11769 * Module exit helper function used by both module and static driver.
11770 */
11771static void __hdd_module_exit(void)
11772{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011773
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011774 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11775 QWLAN_VERSIONSTR);
11776
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011777 hdd_wait_for_recovery_completion();
11778
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011779 wlan_hdd_unregister_driver();
11780
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011781 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011782
Mukul Sharmad75a6672017-06-22 15:40:53 +053011783 /* Ensure to call prior to objmgr deinit */
11784 component_deinit();
11785
Rajeev Kumar97767a02016-11-30 11:20:40 -080011786 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011787
11788 hdd_sysfs_destroy_version_interface();
11789
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011790 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011791 pld_deinit();
11792
Sachin Ahujadddd2632017-03-07 19:07:24 +053011793 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011794}
11795
Arun Khandavallifae92942016-08-01 13:31:08 +053011796#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011797/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011798 * wlan_boot_cb() - Wlan boot callback
11799 * @kobj: object whose directory we're creating the link in.
11800 * @attr: attribute the user is interacting with
11801 * @buff: the buffer containing the user data
11802 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011803 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011804 * This callback is invoked when the fs is ready to start the
11805 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011806 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011807 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011808 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011809static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011810 struct kobj_attribute *attr,
11811 const char *buf,
11812 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011813{
Arun Khandavallifae92942016-08-01 13:31:08 +053011814
Arun Khandavallifae92942016-08-01 13:31:08 +053011815 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011816 pr_err("%s: wlan driver already initialized\n", __func__);
11817 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011818 }
11819
Arun Khandavallifae92942016-08-01 13:31:08 +053011820 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011821 pr_err("%s: wlan driver initialization failed\n", __func__);
11822 return -EIO;
11823 }
11824
11825 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011826
11827 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011828}
Arun Khandavallifae92942016-08-01 13:31:08 +053011829
11830/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011831 * hdd_sysfs_cleanup() - cleanup sysfs
11832 *
11833 * Return: None
11834 *
11835 */
11836static void hdd_sysfs_cleanup(void)
11837{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011838 /* remove from group */
11839 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11840 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11841 wlan_loader->attr_group);
11842
11843 /* unlink the object from parent */
11844 kobject_del(wlan_loader->boot_wlan_obj);
11845
11846 /* free the object */
11847 kobject_put(wlan_loader->boot_wlan_obj);
11848
11849 kfree(wlan_loader->attr_group);
11850 kfree(wlan_loader);
11851
11852 wlan_loader = NULL;
11853}
11854
11855/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011856 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11857 * ready
11858 *
11859 * This is creates the syfs entry boot_wlan. Which shall be invoked
11860 * when the filesystem is ready.
11861 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011862 * QDF API cannot be used here since this function is called even before
11863 * initializing WLAN driver.
11864 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011865 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011866 */
11867static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011868{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011869 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011870
11871 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011872 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011873 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011874
11875 wlan_loader->boot_wlan_obj = NULL;
11876 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11877 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011878 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011879 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011880
11881 wlan_loader->loaded_state = 0;
11882 wlan_loader->attr_group->attrs = attrs;
11883
11884 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11885 kernel_kobj);
11886 if (!wlan_loader->boot_wlan_obj) {
11887 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011888 goto error_return;
11889 }
11890
11891 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11892 wlan_loader->attr_group);
11893 if (ret) {
11894 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11895 goto error_return;
11896 }
11897
11898 return 0;
11899
11900error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011901 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011902
11903 return ret;
11904}
11905
11906/**
11907 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11908 *
11909 * Return: 0 on success or errno on failure
11910 */
11911static int wlan_deinit_sysfs(void)
11912{
Arun Khandavallifae92942016-08-01 13:31:08 +053011913 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011914 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011915 return -EINVAL;
11916 }
11917
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011918 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011919 return 0;
11920}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011921
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011922#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011923
11924#ifdef MODULE
11925/**
11926 * __hdd_module_init - Module init helper
11927 *
11928 * Module init helper function used by both module and static driver.
11929 *
11930 * Return: 0 for success, errno on failure
11931 */
11932static int hdd_module_init(void)
11933{
Arun Khandavallifae92942016-08-01 13:31:08 +053011934 if (__hdd_module_init()) {
11935 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011936 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011937 }
11938
Dustin Brownab482ac2017-06-09 17:00:44 -070011939 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011940}
11941#else
11942static int __init hdd_module_init(void)
11943{
11944 int ret = -EINVAL;
11945
11946 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011947 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011948 pr_err("Failed to create sysfs entry for loading wlan");
11949
11950 return ret;
11951}
11952#endif
11953
11954
11955#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011956/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011957 * hdd_module_exit() - Exit function
11958 *
11959 * This is the driver exit point (invoked when module is unloaded using rmmod)
11960 *
11961 * Return: None
11962 */
11963static void __exit hdd_module_exit(void)
11964{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011965 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011966}
Arun Khandavallifae92942016-08-01 13:31:08 +053011967#else
11968static void __exit hdd_module_exit(void)
11969{
11970 __hdd_module_exit();
11971 wlan_deinit_sysfs();
11972}
11973#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011974
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011975static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11976{
11977 return param_set_copystring(kmessage, kp);
11978}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011979
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011980/**
11981 * is_con_mode_valid() check con mode is valid or not
11982 * @mode: global con mode
11983 *
11984 * Return: TRUE on success FALSE on failure
11985 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080011986static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011987{
11988 switch (mode) {
11989 case QDF_GLOBAL_MONITOR_MODE:
11990 case QDF_GLOBAL_FTM_MODE:
11991 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011992 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011993 return true;
11994 default:
11995 return false;
11996 }
11997}
11998
11999/**
12000 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12001 * @mode: global con mode
12002 *
12003 * Return: adapter mode
12004 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012005static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012006 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012007{
12008
12009 switch (mode) {
12010 case QDF_GLOBAL_MISSION_MODE:
12011 return QDF_STA_MODE;
12012 case QDF_GLOBAL_MONITOR_MODE:
12013 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012014 case QDF_GLOBAL_EPPING_MODE:
12015 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012016 case QDF_GLOBAL_FTM_MODE:
12017 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012018 case QDF_GLOBAL_QVIT_MODE:
12019 return QDF_QVIT_MODE;
12020 default:
12021 return QDF_MAX_NO_OF_MODE;
12022 }
12023}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012024
Dustin Brown27cd9942017-09-27 16:11:44 -070012025static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012026 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012027{
12028 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12029 return;
12030
12031 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012032 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012033 hdd_info("Release wakelock for monitor mode!");
12034 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12035 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12036 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012037 case QDF_GLOBAL_FTM_MODE:
12038 hdd_abort_mac_scan_all_adapters(hdd_ctx);
12039 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012040 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012041
Dustin Brown27cd9942017-09-27 16:11:44 -070012042 break;
12043 default:
12044 break;
12045 }
12046}
12047
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012048static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012049 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012050{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012051 int driver_status;
12052
12053 driver_status = hdd_ctx->driver_status;
12054
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012055 switch (curr_mode) {
12056 case QDF_GLOBAL_MISSION_MODE:
12057 case QDF_GLOBAL_MONITOR_MODE:
12058 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012059 hdd_deinit_all_adapters(hdd_ctx, false);
12060 hdd_close_all_adapters(hdd_ctx, false);
12061 break;
12062 case QDF_GLOBAL_EPPING_MODE:
12063 epping_disable();
12064 epping_close();
12065 break;
12066 default:
12067 return;
12068 }
12069}
12070
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012071static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012072 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012073{
Jeff Johnson9d295242017-08-29 14:39:48 -070012074 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012075 int ret = 0;
12076 bool rtnl_held;
12077 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12078 QDF_STATUS status;
12079
12080 if (!qdf_dev) {
12081 hdd_err("qdf device context is Null return!");
12082 return -EINVAL;
12083 }
12084
12085 rtnl_held = hdd_hold_rtnl_lock();
12086 switch (mode) {
12087 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012088 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12089 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012090 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012091 break;
12092 case QDF_GLOBAL_FTM_MODE:
12093 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12094 wlan_hdd_get_intf_addr(hdd_ctx),
12095 NET_NAME_UNKNOWN, rtnl_held);
12096 if (adapter == NULL)
12097 ret = -EINVAL;
12098 break;
12099 case QDF_GLOBAL_MONITOR_MODE:
12100 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12101 wlan_hdd_get_intf_addr(hdd_ctx),
12102 NET_NAME_UNKNOWN, rtnl_held);
12103 if (adapter == NULL)
12104 ret = -EINVAL;
12105 break;
12106 case QDF_GLOBAL_EPPING_MODE:
12107 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012108 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012109 hdd_err("Failed to open in eeping mode: %d", status);
12110 ret = -EINVAL;
12111 break;
12112 }
12113 ret = epping_enable(qdf_dev->dev);
12114 if (ret) {
12115 hdd_err("Failed to enable in epping mode : %d", ret);
12116 epping_close();
12117 }
12118 break;
12119 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012120 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012121 ret = -ENOTSUPP;
12122 break;
12123 }
12124 hdd_release_rtnl_lock();
12125 rtnl_held = false;
12126 return ret;
12127}
12128
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012129/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012130 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012131 * @kmessage: con mode name on which driver to be bring up
12132 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012133 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012134 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012135 * This function is invoked when user updates con mode using sys entry,
12136 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012137 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012138 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012139 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012140static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012141 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012142{
12143 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012144 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012145 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012146 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012147 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012148
Dustin Brownab6029b2017-05-24 13:04:19 -070012149 hdd_info("con_mode handler: %s", kmessage);
12150
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012151 ret = wlan_hdd_validate_context(hdd_ctx);
12152 if (ret)
12153 return ret;
12154
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012155 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012156 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012157
Dustin Brown20024e32018-01-03 12:34:58 -080012158 ret = kstrtoint(kmessage, 0, &new_con_mode);
12159 if (ret) {
12160 hdd_err("Failed to parse con_mode '%s'", kmessage);
12161 goto reset_flags;
12162 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012163 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012164
Dustin Brown20024e32018-01-03 12:34:58 -080012165 if (!is_con_mode_valid(new_con_mode)) {
12166 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012167 ret = -EINVAL;
12168 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012169 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012170
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012171 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012172 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012173 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012174 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012175 ret = 0;
12176 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012177 }
12178
Dustin Brown27cd9942017-09-27 16:11:44 -070012179 /* ensure adapters are stopped */
12180 hdd_stop_present_mode(hdd_ctx, curr_mode);
12181
Frank Liu6666f832018-01-04 10:06:05 +080012182 /* Cleanup present mode before switching to new mode */
12183 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12184
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012185 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012186 if (ret) {
12187 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012188 goto reset_flags;
12189 }
12190
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012191
Dustin Brown20024e32018-01-03 12:34:58 -080012192 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012193
Frank Liu6666f832018-01-04 10:06:05 +080012194 /*
12195 * Set ACTIVE domain before adapters created, otherwise check domain
12196 * match will fail when cleanup adapters.
12197 */
12198 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012199 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012200 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012201 if (ret) {
12202 hdd_err("Failed to register for new mode");
12203 goto reset_flags;
12204 }
12205
Dustin Brown20024e32018-01-03 12:34:58 -080012206 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012207 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12208 hdd_err("invalid adapter");
12209 ret = -EINVAL;
12210 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012211 }
12212
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012213 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012214 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012215 hdd_err("Failed to get adapter:%d", adapter_mode);
12216 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012217 }
12218
12219 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12220 if (ret) {
12221 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012222 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012223 }
12224
Dustin Brown20024e32018-01-03 12:34:58 -080012225 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012226 if (hdd_start_adapter(adapter)) {
12227 hdd_err("Failed to start %s adapter", kmessage);
12228 ret = -EINVAL;
12229 goto reset_flags;
12230 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012231
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012232 hdd_info("Acquire wakelock for monitor mode!");
12233 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12234 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12235 }
12236
Dustin Brown20024e32018-01-03 12:34:58 -080012237 /* con_mode is a global module parameter */
12238 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012239 hdd_info("Mode successfully changed to %s", kmessage);
12240 ret = 0;
12241
12242reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012243 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012244 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012245 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012246 return ret;
12247}
12248
12249
12250static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12251{
12252 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012253 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012254
12255 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12256 ret = wlan_hdd_validate_context(hdd_ctx);
12257 if (ret)
12258 return ret;
12259
12260 cds_ssr_protect(__func__);
12261 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12262 cds_ssr_unprotect(__func__);
12263
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012264 return ret;
12265}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012266
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012267static int con_mode_handler_ftm(const char *kmessage,
12268 struct kernel_param *kp)
12269{
12270 int ret;
12271
12272 ret = param_set_int(kmessage, kp);
12273
12274 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12275 pr_err("Only FTM mode supported!");
12276 return -ENOTSUPP;
12277 }
12278
12279 hdd_set_conparam(con_mode_ftm);
12280 con_mode = con_mode_ftm;
12281
12282 return ret;
12283}
12284
Ravi Joshia307f632017-07-17 23:41:41 -070012285static int con_mode_handler_monitor(const char *kmessage,
12286 struct kernel_param *kp)
12287{
12288 int ret;
12289
12290 ret = param_set_int(kmessage, kp);
12291
12292 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12293 pr_err("Only Monitor mode supported!");
12294 return -ENOTSUPP;
12295 }
12296
12297 hdd_set_conparam(con_mode_monitor);
12298 con_mode = con_mode_monitor;
12299
12300 return ret;
12301}
12302
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012303/**
12304 * hdd_get_conparam() - driver exit point
12305 *
12306 * This is the driver exit point (invoked when module is unloaded using rmmod)
12307 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012308 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012309 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012310enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012311{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012312 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012313}
12314
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012315void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012316{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012317 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012318}
12319
Komal Seelamc11bb222016-01-27 18:57:10 +053012320/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012321 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12322 * @hdd_ctx: HDD context
12323 *
12324 * Cleans up the pre cac interface, if it exists
12325 *
12326 * Return: None
12327 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012328void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012329{
12330 uint8_t session_id;
12331 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012332 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012333
12334 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12335 if (QDF_IS_STATUS_ERROR(status)) {
12336 hdd_err("failed to get pre cac vdev id");
12337 return;
12338 }
12339
12340 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12341 if (!precac_adapter) {
12342 hdd_err("invalid pre cac adapater");
12343 return;
12344 }
12345
12346 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12347 wlan_hdd_sap_pre_cac_failure,
12348 (void *)precac_adapter);
12349 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12350
12351}
12352
12353/**
Komal Seelamec702b02016-02-24 18:42:16 +053012354 * hdd_update_ol_config - API to update ol configuration parameters
12355 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012356 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012357 * Return: void
12358 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012359static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012360{
Komal Seelamec702b02016-02-24 18:42:16 +053012361 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012362 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012363
Komal Seelamec702b02016-02-24 18:42:16 +053012364 if (!ol_ctx)
12365 return;
12366
12367 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12368 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12369 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12370 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012371 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012372
12373 ol_init_ini_config(ol_ctx, &cfg);
12374}
12375
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012376#ifdef FEATURE_RUNTIME_PM
12377/**
12378 * hdd_populate_runtime_cfg() - populate runtime configuration
12379 * @hdd_ctx: hdd context
12380 * @cfg: pointer to the configuration memory being populated
12381 *
12382 * Return: void
12383 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012384static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012385 struct hif_config_info *cfg)
12386{
12387 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12388 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12389}
12390#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012391static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012392 struct hif_config_info *cfg)
12393{
12394}
12395#endif
12396
Komal Seelamec702b02016-02-24 18:42:16 +053012397/**
12398 * hdd_update_hif_config - API to update HIF configuration parameters
12399 * @hdd_ctx: HDD Context
12400 *
12401 * Return: void
12402 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012403static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012404{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012405 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012406 struct hif_config_info cfg;
12407
12408 if (!scn)
12409 return;
12410
12411 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012412 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012413 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012414
12415 if (hdd_ctx->config->prevent_link_down)
12416 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012417}
12418
12419/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012420 * hdd_update_dp_config() - Propagate config parameters to Lithium
12421 * datapath
12422 * @hdd_ctx: HDD Context
12423 *
12424 * Return: 0 for success/errno for failure
12425 */
12426static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12427{
12428 struct cdp_config_params params;
12429 QDF_STATUS status;
12430
12431 params.tso_enable = hdd_ctx->config->tso_enable;
12432 params.lro_enable = hdd_ctx->config->lro_enable;
12433#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12434 params.tx_flow_stop_queue_threshold =
12435 hdd_ctx->config->TxFlowStopQueueThreshold;
12436 params.tx_flow_start_queue_offset =
12437 hdd_ctx->config->TxFlowStartQueueOffset;
12438#endif
12439 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12440 params.napi_enable = hdd_ctx->napi_enable;
12441 params.tcp_udp_checksumoffload =
12442 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12443
12444 status = cdp_update_config_parameters(
12445 cds_get_context(QDF_MODULE_ID_SOC),
12446 &params);
12447 if (status) {
12448 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12449 "%s: Failed to attach config parameters", __func__);
12450 return status;
12451 }
12452
12453 return 0;
12454}
12455
12456/**
Komal Seelamec702b02016-02-24 18:42:16 +053012457 * hdd_update_config() - Initialize driver per module ini parameters
12458 * @hdd_ctx: HDD Context
12459 *
12460 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012461 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012462 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012463int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012464{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012465 int ret;
12466
Komal Seelamec702b02016-02-24 18:42:16 +053012467 hdd_update_ol_config(hdd_ctx);
12468 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012469 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12470 ret = hdd_update_cds_config_ftm(hdd_ctx);
12471 else
12472 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012473 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012474
12475 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012476}
12477
Mukul Sharma9d797a02017-01-05 20:26:03 +053012478#ifdef FEATURE_WLAN_RA_FILTERING
12479/**
12480 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12481 * @psoc_cfg: pmo psoc Configuration
12482 * @hdd_ctx: Pointer to hdd context
12483 *
12484 * Return: none
12485 */
12486static inline void hdd_ra_populate_pmo_config(
12487 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012488 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012489{
12490 psoc_cfg->ra_ratelimit_interval =
12491 hdd_ctx->config->RArateLimitInterval;
12492 psoc_cfg->ra_ratelimit_enable =
12493 hdd_ctx->config->IsRArateLimitEnabled;
12494}
12495#else
12496static inline void hdd_ra_populate_pmo_config(
12497 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012498 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012499{
12500}
12501#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012502
Mukul Sharma9d797a02017-01-05 20:26:03 +053012503/**
12504 * hdd_update_pmo_config - API to update pmo configuration parameters
12505 * @hdd_ctx: HDD context
12506 *
12507 * Return: void
12508 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012509static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012510{
12511 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12512 struct pmo_psoc_cfg psoc_cfg;
12513 QDF_STATUS status;
12514
12515 /*
12516 * Value of hdd_ctx->wowEnable can be,
12517 * 0 - Disable both magic pattern match and pattern byte match.
12518 * 1 - Enable magic pattern match on all interfaces.
12519 * 2 - Enable pattern byte match on all interfaces.
12520 * 3 - Enable both magic patter and pattern byte match on
12521 * all interfaces.
12522 */
12523 psoc_cfg.magic_ptrn_enable =
12524 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12525 psoc_cfg.ptrn_match_enable_all_vdev =
12526 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012527 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12528 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012529 psoc_cfg.bpf_enable =
12530 hdd_ctx->config->bpf_packet_filter_enable;
12531 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012532 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012533 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12534 if (hdd_ctx->config->fhostNSOffload)
12535 psoc_cfg.ns_offload_enable_dynamic = true;
12536 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12537 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12538 psoc_cfg.active_mode_offload =
12539 hdd_ctx->config->active_mode_offload;
12540 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012541 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012542 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012543 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12544 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12545 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12546 psoc_cfg.power_save_mode =
12547 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012548 psoc_cfg.auto_power_save_fail_mode =
12549 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012550
12551 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012552 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12553 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012554 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012555 if (status != QDF_STATUS_SUCCESS) {
12556 hdd_err("failed pmo psoc configuration");
12557 return -EINVAL;
12558 }
12559
12560 return 0;
12561}
12562
Abhishek Singhb20db962017-03-03 21:28:46 +053012563#ifdef FEATURE_WLAN_SCAN_PNO
12564static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12565 struct hdd_config *cfg)
12566{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012567 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12568
Abhishek Singhb20db962017-03-03 21:28:46 +053012569 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12570 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12571 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12572 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12573 pno_cfg->channel_prediction_full_scan =
12574 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012575 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12576 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12577 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12578 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012579}
12580#else
12581static inline void
12582hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012583 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012584{
Abhishek Singhb20db962017-03-03 21:28:46 +053012585}
12586#endif
12587
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012588void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12589 struct hdd_config *cfg)
12590{
12591 uint8_t i = 0;
12592
12593 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12594 if (!ie_whitelist->white_list)
12595 return;
12596
12597 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12598 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12599 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12600 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12601 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12602 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12603 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12604 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12605
12606 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12607 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12608 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12609}
12610
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012611uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12612{
12613 uint8_t i, score;
12614
12615 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12616 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12617 if (score > MAX_INDEX_SCORE)
12618 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12619 MAX_INDEX_SCORE, i);
12620 }
12621
12622 return per_index_score;
12623}
12624
12625/**
12626 * hdd_update_score_config - API to update candidate scoring related params
12627 * configuration parameters
12628 * @score_config: score config to update
12629 * @cfg: config params
12630 *
12631 * Return: 0 if success else err
12632 */
12633static void hdd_update_score_config(
12634 struct scoring_config *score_config, struct hdd_config *cfg)
12635{
12636 int total_weight;
12637
12638 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12639 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12640 score_config->weight_cfg.vht_caps_weightage =
12641 cfg->vht_caps_weightage;
12642 score_config->weight_cfg.he_caps_weightage =
12643 cfg->he_caps_weightage;
12644 score_config->weight_cfg.chan_width_weightage =
12645 cfg->chan_width_weightage;
12646 score_config->weight_cfg.chan_band_weightage =
12647 cfg->chan_band_weightage;
12648 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12649 score_config->weight_cfg.beamforming_cap_weightage =
12650 cfg->beamforming_cap_weightage;
12651 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12652 score_config->weight_cfg.channel_congestion_weightage =
12653 cfg->channel_congestion_weightage;
12654 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12655
12656 total_weight = score_config->weight_cfg.rssi_weightage +
12657 score_config->weight_cfg.ht_caps_weightage +
12658 score_config->weight_cfg.vht_caps_weightage +
12659 score_config->weight_cfg.he_caps_weightage +
12660 score_config->weight_cfg.chan_width_weightage +
12661 score_config->weight_cfg.chan_band_weightage +
12662 score_config->weight_cfg.nss_weightage +
12663 score_config->weight_cfg.beamforming_cap_weightage +
12664 score_config->weight_cfg.pcl_weightage +
12665 score_config->weight_cfg.channel_congestion_weightage +
12666 score_config->weight_cfg.oce_wan_weightage;
12667
12668 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12669 hdd_err("total weight is greater than %d fallback to default values",
12670 BEST_CANDIDATE_MAX_WEIGHT);
12671
12672 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12673 score_config->weight_cfg.ht_caps_weightage =
12674 HT_CAPABILITY_WEIGHTAGE;
12675 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12676 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12677 score_config->weight_cfg.chan_width_weightage =
12678 CHAN_WIDTH_WEIGHTAGE;
12679 score_config->weight_cfg.chan_band_weightage =
12680 CHAN_BAND_WEIGHTAGE;
12681 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12682 score_config->weight_cfg.beamforming_cap_weightage =
12683 BEAMFORMING_CAP_WEIGHTAGE;
12684 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12685 score_config->weight_cfg.channel_congestion_weightage =
12686 CHANNEL_CONGESTION_WEIGHTAGE;
12687 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12688 }
12689
12690 score_config->bandwidth_weight_per_index =
12691 hdd_limit_max_per_index_score(
12692 cfg->bandwidth_weight_per_index);
12693 score_config->nss_weight_per_index =
12694 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12695 score_config->band_weight_per_index =
12696 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12697
12698 score_config->rssi_score.best_rssi_threshold =
12699 cfg->best_rssi_threshold;
12700 score_config->rssi_score.good_rssi_threshold =
12701 cfg->good_rssi_threshold;
12702 score_config->rssi_score.bad_rssi_threshold =
12703 cfg->bad_rssi_threshold;
12704 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12705 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12706 score_config->rssi_score.good_rssi_bucket_size =
12707 cfg->good_rssi_bucket_size;
12708 score_config->rssi_score.bad_rssi_bucket_size =
12709 cfg->bad_rssi_bucket_size;
12710 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12711 cfg->rssi_pref_5g_rssi_thresh;
12712
12713 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12714 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12715 hdd_limit_max_per_index_score(
12716 cfg->esp_qbss_score_slots3_to_0);
12717 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12718 hdd_limit_max_per_index_score(
12719 cfg->esp_qbss_score_slots7_to_4);
12720 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12721 hdd_limit_max_per_index_score(
12722 cfg->esp_qbss_score_slots11_to_8);
12723 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12724 hdd_limit_max_per_index_score(
12725 cfg->esp_qbss_score_slots15_to_12);
12726
12727 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12728 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12729 hdd_limit_max_per_index_score(
12730 cfg->oce_wan_score_slots3_to_0);
12731 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12732 hdd_limit_max_per_index_score(
12733 cfg->oce_wan_score_slots7_to_4);
12734 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12735 hdd_limit_max_per_index_score(
12736 cfg->oce_wan_score_slots11_to_8);
12737 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12738 hdd_limit_max_per_index_score(
12739 cfg->oce_wan_score_slots15_to_12);
12740
12741
12742 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12743 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12744 score_config->nss = cfg->enable2x2 ? 2 : 1;
12745
12746 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12747 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12748 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12749 score_config->he_cap = 1;
12750
12751 if (score_config->he_cap ||
12752 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12753 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12754 score_config->vht_cap = 1;
12755
12756 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12757 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12758 score_config->ht_cap = 1;
12759
12760 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12761 score_config->vht_24G_cap = 1;
12762
12763 if (cfg->enableTxBF)
12764 score_config->beamformee_cap = 1;
12765
12766}
12767
Abhishek Singh257a9482017-03-06 16:52:39 +053012768/**
12769 * hdd_update_scan_config - API to update scan configuration parameters
12770 * @hdd_ctx: HDD context
12771 *
12772 * Return: 0 if success else err
12773 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012774static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012775{
12776 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12777 struct scan_user_cfg scan_cfg;
12778 struct hdd_config *cfg = hdd_ctx->config;
12779 QDF_STATUS status;
12780
12781 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12782 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12783 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12784 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12785 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12786 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12787 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012788 /* convert to ms */
12789 scan_cfg.scan_cache_aging_time =
12790 cfg->scanAgingTimeout * 1000;
12791 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12792 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12793 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12794 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012795 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012796 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012797 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12798 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012799 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012800 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012801
Abhishek Singhb20db962017-03-03 21:28:46 +053012802 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012803 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012804 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012805
Abhishek Singh257a9482017-03-06 16:52:39 +053012806 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12807 if (status != QDF_STATUS_SUCCESS) {
12808 hdd_err("failed pmo psoc configuration");
12809 return -EINVAL;
12810 }
12811
12812 return 0;
12813}
Abhishek Singh257a9482017-03-06 16:52:39 +053012814
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012815int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012816{
12817 int ret;
12818
12819 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012820 if (ret)
12821 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012822
Abhishek Singh257a9482017-03-06 16:52:39 +053012823 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012824 if (ret)
12825 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012826
Frank Liud4b2fa02017-03-29 11:46:48 +080012827 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012828 if (ret)
12829 return ret;
12830
12831 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012832
12833 return ret;
12834}
12835
Agrawal Ashish65634612016-08-18 13:24:32 +053012836/**
12837 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12838 * @mode : cfg80211 DFS mode
12839 *
12840 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12841 */
12842enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12843{
12844 switch (mode) {
12845 case DFS_MODE_ENABLE:
12846 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012847 case DFS_MODE_DISABLE:
12848 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012849 case DFS_MODE_DEPRIORITIZE:
12850 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012851 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012852 hdd_debug("ACS dfs mode is NONE");
12853 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012854 }
12855}
12856
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012857/**
12858 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12859 * @hddctx: pointer to hdd context
12860 * @set_value: enable/disable
12861 *
12862 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12863 * Host(even though it is duplicate). When Host send vendor command
12864 * disable,FW doesn't perform any action. Whenever any change in
12865 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12866 *
12867 * return - 0 on success, appropriate error values on failure.
12868 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012869int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012870{
12871 QDF_STATUS status;
12872
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012873 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012874 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012875
12876 if (!hddctx->config->goptimize_chan_avoid_event) {
12877 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12878 return -EINVAL;
12879 }
12880
12881 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12882 if (!QDF_IS_STATUS_SUCCESS(status)) {
12883 hdd_err("Failed to send chan avoid command to SME");
12884 return -EINVAL;
12885 }
12886 return 0;
12887}
Agrawal Ashish65634612016-08-18 13:24:32 +053012888
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012889/**
12890 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12891 * @value: value to set
12892 *
12893 * This function will set the passed value to roaming in progress flag.
12894 *
12895 * Return: None
12896 */
12897void hdd_set_roaming_in_progress(bool value)
12898{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012899 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012900
12901 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12902 if (!hdd_ctx) {
12903 hdd_err("HDD context is NULL");
12904 return;
12905 }
12906
12907 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012908 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012909}
12910
12911/**
12912 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012913 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012914 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012915 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012916 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012917bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012918{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012919 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012920 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012921
12922 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12923 if (!hdd_ctx) {
12924 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012925 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012926 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012927 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12928 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012929 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12930 hdd_ctx->roaming_in_progress);
12931
12932 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012933}
12934
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012935/**
12936 * hdd_is_connection_in_progress() - check if connection is in
12937 * progress
12938 * @session_id: session id
12939 * @reason: scan reject reason
12940 *
12941 * Go through each adapter and check if Connection is in progress
12942 *
12943 * Return: true if connection is in progress else false
12944 */
12945bool hdd_is_connection_in_progress(uint8_t *session_id,
12946 enum scan_reject_states *reason)
12947{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012948 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012949 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012950 uint8_t sta_id = 0;
12951 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012952 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012953
12954 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12955 if (!hdd_ctx) {
12956 hdd_err("HDD context is NULL");
12957 return false;
12958 }
12959
Dustin Brown920397d2017-12-13 16:27:50 -080012960 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012961 hdd_info("Adapter with device mode %s(%d) exists",
12962 hdd_device_mode_to_string(adapter->device_mode),
12963 adapter->device_mode);
12964 if (((QDF_STA_MODE == adapter->device_mode)
12965 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12966 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12967 && (eConnectionState_Connecting ==
12968 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12969 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012970 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012971 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012972 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012973 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012974 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012975 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012976 }
12977 return true;
12978 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012979 /*
12980 * sme_neighbor_middle_of_roaming is for LFR2
12981 * hdd_is_roaming_in_progress is for LFR3
12982 */
12983 if (((QDF_STA_MODE == adapter->device_mode) &&
12984 sme_neighbor_middle_of_roaming(
12985 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012986 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012987 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012988 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012989 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012990 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012991 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012992 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012993 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012994 }
12995 return true;
12996 }
12997 if ((QDF_STA_MODE == adapter->device_mode) ||
12998 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12999 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13000 hdd_sta_ctx =
13001 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13002 if ((eConnectionState_Associated ==
13003 hdd_sta_ctx->conn_info.connState)
13004 && (false ==
13005 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
13006 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013007 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013008 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013009 " is in middle of WPS/EAPOL exchange.",
13010 MAC_ADDR_ARRAY(sta_mac));
13011 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013012 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013013 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013014 }
13015 return true;
13016 }
13017 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13018 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13019 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13020 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013021 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013022 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013023 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013024 continue;
13025
13026 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013027 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013028 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013029 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013030 " of SAP/GO is in middle of WPS/EAPOL exchange",
13031 MAC_ADDR_ARRAY(sta_mac));
13032 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013033 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013034 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013035 }
13036 return true;
13037 }
13038 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013039 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013040 return true;
13041 }
13042 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013043 }
Dustin Brown920397d2017-12-13 16:27:50 -080013044
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013045 return false;
13046}
13047
13048/**
13049 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013050 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013051 *
13052 * Return: None
13053 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013054void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013055{
Jeff Johnson87251032017-08-29 13:31:11 -070013056 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013057 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013058 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013059 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013060 tsap_Config_t *sap_config;
13061 void *sap_ctx;
13062
13063 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013064 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013065 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013066
13067 mutex_lock(&hdd_ctx->sap_lock);
13068 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13069 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013070 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13071 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13072 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13073 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013074 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013075 qdf_stop_bss_event,
13076 SME_CMD_TIMEOUT_VALUE);
13077
13078 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013079 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013080 goto end;
13081 }
13082 }
13083 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013084 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013085 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013086 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013087
13088 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013089 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013090 wlansap_reset_sap_config_add_ie(sap_config,
13091 eUPDATE_IE_ALL);
13092 goto end;
13093 }
13094
13095 qdf_event_reset(&hostapd_state->qdf_event);
13096 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13097 sap_config,
13098 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013099 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013100 wlansap_reset_sap_config_add_ie(sap_config,
13101 eUPDATE_IE_ALL);
13102 goto end;
13103 }
13104
Jeff Johnson6867ec32017-09-29 20:30:20 -070013105 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013106 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013107 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013108 SME_CMD_TIMEOUT_VALUE);
13109 wlansap_reset_sap_config_add_ie(sap_config,
13110 eUPDATE_IE_ALL);
13111 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013112 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013113 goto end;
13114 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013115 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013116 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070013117 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013118 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13119 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013120 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013121 }
13122end:
13123 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013124}
13125
13126/**
13127 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13128 * with non dfs acs
13129 *
13130 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13131 *
13132 * Return: None
13133 */
13134void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13135{
Jeff Johnson9d295242017-08-29 14:39:48 -070013136 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013137 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013138 cds_context_type *cds_ctx;
13139
13140 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13141 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013142 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013143 return;
13144 }
13145
13146 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13147 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013148 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013149 return;
13150 }
13151
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013152 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13153 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013154 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013155 return;
13156 }
13157
13158 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013159 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13160 &ap_adapter->event_flags) &&
13161 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013162 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013163
Jeff Johnson6867ec32017-09-29 20:30:20 -070013164 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013165 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013166 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013167 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013168 acs_cfg.acs_mode = true;
13169
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013170 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013171 }
13172}
13173
13174/**
13175 * hdd_set_connection_in_progress() - to set the connection in
13176 * progress flag
13177 * @value: value to set
13178 *
13179 * This function will set the passed value to connection in progress flag.
13180 * If value is previously being set to true then no need to set it again.
13181 *
13182 * Return: true if value is being set correctly and false otherwise.
13183 */
13184bool hdd_set_connection_in_progress(bool value)
13185{
13186 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013187 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013188
13189 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13190 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013191 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013192 return false;
13193 }
13194
13195 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13196 /*
13197 * if the value is set to true previously and if someone is
13198 * trying to make it true again then it could be some race
13199 * condition being triggered. Avoid this situation by returning
13200 * false
13201 */
13202 if (hdd_ctx->connection_in_progress && value)
13203 status = false;
13204 else
13205 hdd_ctx->connection_in_progress = value;
13206 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13207 return status;
13208}
13209
Jeff Johnson9d295242017-08-29 14:39:48 -070013210int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013211{
13212 if (!adapter) {
13213 hdd_err("Invalid adapter");
13214 return -EINVAL;
13215 }
13216 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013217 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013218 WMA_VDEV_MCC_SET_TIME_QUOTA,
13219 set_value, VDEV_CMD);
13220 return 0;
13221
13222}
13223
Jeff Johnson9d295242017-08-29 14:39:48 -070013224int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013225{
13226 if (!adapter) {
13227 hdd_err("Invalid adapter");
13228 return -EINVAL;
13229 }
13230
13231 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013232 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013233 WMA_VDEV_MCC_SET_TIME_LATENCY,
13234 set_value, VDEV_CMD);
13235 return 0;
13236}
13237
Jeff Johnson9d295242017-08-29 14:39:48 -070013238struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013239 *psoc, uint8_t vdev_id)
13240{
Jeff Johnson9d295242017-08-29 14:39:48 -070013241 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013242 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013243
13244 /*
13245 * Currently PSOC is not being used. But this logic will
13246 * change once we have the converged implementation of
13247 * HDD context per PSOC in place. This would break if
13248 * multiple vdev objects reuse the vdev id.
13249 */
13250 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13251 if (!adapter)
13252 hdd_err("Get adapter by vdev id failed");
13253
13254 return adapter;
13255}
13256
Jeff Johnson9d295242017-08-29 14:39:48 -070013257int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013258 int8_t *rssi, int8_t *snr)
13259{
13260 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070013261 struct hdd_wext_state *wext_state =
13262 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013263 tCsrRoamProfile *profile = &wext_state->roamProfile;
13264
13265 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
13266 profile, bssid, rssi, snr);
13267 if (QDF_STATUS_SUCCESS != status) {
13268 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13269 return -EINVAL;
13270 }
13271
13272 return 0;
13273}
13274
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013275/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013276 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13277 * @adapter - HDD adapter
13278 * @tos - type of service
13279 * @status - status of the traffic
13280 *
13281 * Return: 0 on success and non zero value on failure
13282 */
13283
13284int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13285 bool is_tos_active)
13286{
13287 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013288 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013289 uint32_t max_off_chan_time = 0;
13290 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013291 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013292 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013293
13294 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13295 ret = wlan_hdd_validate_context(hdd_ctx);
13296
13297 if (ret < 0) {
13298 hdd_err("failed to set limit off chan params");
13299 return ret;
13300 }
13301
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013302 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13303
13304 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013305 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013306 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013307 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013308
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013309 if (adapter->active_ac) {
13310 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013311 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013312 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13313 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13314 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013315 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013316 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013317 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13318 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13319 PM_LATENCY);
13320 } else {
13321 /*ignore this command if only BE/BK is active */
13322 is_tos_active = false;
13323 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13324 hdd_ctx->config->conc_system_pref);
13325 }
13326 } else {
13327 /* No active tos */
13328 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13329 hdd_ctx->config->conc_system_pref);
13330 }
13331
Jeff Johnson1b780e42017-10-31 14:11:45 -070013332 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013333 is_tos_active, max_off_chan_time,
13334 hdd_ctx->config->nRestTimeConc, true);
13335 if (!QDF_IS_STATUS_SUCCESS(status)) {
13336 hdd_err("failed to set limit off chan params");
13337 ret = -EINVAL;
13338 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013339
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013340 return ret;
13341}
13342
13343/**
13344 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13345 * @adapter - HDD adapter
13346 *
13347 * Return: 0 on success and non zero value on failure
13348 */
13349int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13350{
13351 struct hdd_context *hdd_ctx;
13352 int ret;
13353 QDF_STATUS status;
13354 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13355
13356 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13357 ret = wlan_hdd_validate_context(hdd_ctx);
13358 if (ret < 0)
13359 return ret;
13360
13361 /* set the system preferece to default */
13362 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13363 hdd_ctx->config->conc_system_pref);
13364
13365 /* clear the bitmap */
13366 adapter->active_ac = 0;
13367
13368 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013369 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013370
Jeff Johnson1b780e42017-10-31 14:11:45 -070013371 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013372 false, 0, 0, false);
13373 if (!QDF_IS_STATUS_SUCCESS(status)) {
13374 hdd_err("failed to reset limit off chan params");
13375 ret = -EINVAL;
13376 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013377
13378 return ret;
13379}
13380
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013381/**
13382 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13383 * @drv_op: Enum indicating driver op
13384 *
13385 * Return: none
13386 */
13387void hdd_start_driver_ops_timer(int drv_op)
13388{
13389 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13390 switch (drv_op) {
13391 case eHDD_DRV_OP_PROBE:
13392 memcpy(drv_ops_string, "probe", sizeof("probe"));
13393 break;
13394 case eHDD_DRV_OP_REMOVE:
13395 memcpy(drv_ops_string, "remove", sizeof("remove"));
13396 break;
13397 case eHDD_DRV_OP_SHUTDOWN:
13398 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13399 break;
13400 case eHDD_DRV_OP_REINIT:
13401 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13402 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013403 case eHDD_DRV_OP_IFF_UP:
13404 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13405 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013406 }
13407
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013408 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013409 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13410 HDD_OPS_INACTIVITY_TIMEOUT);
13411}
13412
13413/**
13414 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13415 *
13416 * Return: none
13417 */
13418void hdd_stop_driver_ops_timer(void)
13419{
13420 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13421}
13422
13423/**
13424 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13425 * inactivity timer
13426 *
13427 * Return: None
13428 */
13429void hdd_drv_ops_inactivity_handler(void)
13430{
13431 hdd_err("%s: %d Sec timer expired while in .%s",
13432 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13433
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013434 if (hdd_drv_ops_task) {
13435 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13436 qdf_print_thread_trace(hdd_drv_ops_task);
13437 } else {
13438 hdd_err("hdd_drv_ops_task is null");
13439 }
13440
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013441 /* Driver shutdown is stuck, no recovery possible at this point */
13442 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13443 sizeof("shutdown")))
13444 QDF_BUG(0);
13445
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013446 if (cds_is_fw_down()) {
13447 hdd_err("FW is down");
13448 return;
13449 }
13450
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013451 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013452 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013453 else
13454 QDF_BUG(0);
13455}
13456
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013457void hdd_pld_ipa_uc_shutdown_pipes(void)
13458{
13459 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13460
13461 if (!hdd_ctx)
13462 return;
13463
13464 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13465}
13466
Yun Parkff6a16a2017-09-26 16:38:18 -070013467/**
13468 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13469 * @struct hdd_context *hdd_ctx
13470 * @struct hdd_adapter *padapter
13471 * @bool enble
13472 *
13473 * Return: none
13474 */
13475void hdd_set_rx_mode_rps(bool enable)
13476{
13477 struct cds_config_info *cds_cfg = cds_get_ini_config();
13478 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13479 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13480
13481 if (adapter && hdd_ctx &&
13482 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13483 if (enable && !cds_cfg->rps_enabled)
13484 hdd_send_rps_ind(adapter);
13485 else if (!enable && cds_cfg->rps_enabled)
13486 hdd_send_rps_disable_ind(adapter);
13487 }
13488}
13489
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013490/* Register the module init/exit functions */
13491module_init(hdd_module_init);
13492module_exit(hdd_module_exit);
13493
13494MODULE_LICENSE("Dual BSD/GPL");
13495MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13496MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13497
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013498module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13499 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013500
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013501module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13502 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13503
Ravi Joshia307f632017-07-17 23:41:41 -070013504module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13505 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013507module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13508 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13509
13510module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13511
13512module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13513
13514module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);