blob: 78ac8e2c82a62314269397e5a06b01c8c6907fa0 [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"
Dustin Brown26b3d042017-12-21 11:13:27 -080058#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080059#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080060#endif
Dustin Brownd4241942018-02-26 12:51:37 -080061#include "qdf_str.h"
62#include "qdf_trace.h"
63#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070064#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080065#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070066#include <cdp_txrx_stats.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080067
68#include <net/addrconf.h>
69#include <linux/wireless.h>
70#include <net/cfg80211.h>
71#include <linux/inetdevice.h>
72#include <net/addrconf.h>
73#include "wlan_hdd_cfg80211.h"
74#include "wlan_hdd_ext_scan.h"
75#include "wlan_hdd_p2p.h"
76#include <linux/rtnetlink.h>
77#include "sap_api.h"
78#include <linux/semaphore.h>
79#include <linux/ctype.h>
80#include <linux/compat.h>
81#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080082#include <soc/qcom/subsystem_restart.h>
83#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080084#include <wlan_hdd_hostapd.h>
85#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070086#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#include "cfg_api.h"
88#include "qwlan_version.h"
89#include "wma_types.h"
90#include "wlan_hdd_tdls.h"
91#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053092#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070094#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070095#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080096#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097#include "wlan_hdd_nan.h"
98#include "wlan_hdd_debugfs.h"
99#include "wlan_hdd_driver_ops.h"
100#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530101#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800102
103#include <wlan_hdd_ipa.h>
104#include "hif.h"
105#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800106#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700107#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530108#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700109#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700110#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530111#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700112#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530113#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800114#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800115#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530116#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800117#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800118#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530119#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530120#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800121#include "os_if_wifi_pos.h"
122#include "wifi_pos_api.h"
123#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800124#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700125#include "os_if_nan.h"
126#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700127#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800128#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700129#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530130#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530131#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700132#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800133#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530134#include "wlan_disa_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530135#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530136#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530137#include "wlan_hdd_nud_tracking.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530138
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530139#ifdef CNSS_GENL
140#include <net/cnss_nl.h>
141#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800142#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800143#include "wlan_ocb_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530144
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800145#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800146#ifdef MODULE
147#define WLAN_MODULE_NAME module_name(THIS_MODULE)
148#else
149#define WLAN_MODULE_NAME "wlan"
150#endif
151
152#ifdef TIMER_MANAGER
153#define TIMER_MANAGER_STR " +TIMER_MANAGER"
154#else
155#define TIMER_MANAGER_STR ""
156#endif
157
158#ifdef MEMORY_DEBUG
159#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
160#else
161#define MEMORY_DEBUG_STR ""
162#endif
163
Dustin Brownc1034df2018-02-07 14:51:32 -0800164#ifdef PANIC_ON_BUG
165#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
166#else
167#define PANIC_ON_BUG_STR ""
168#endif
169
Sachin Ahujadddd2632017-03-07 19:07:24 +0530170int wlan_start_ret_val;
171static DECLARE_COMPLETION(wlan_start_comp);
172static unsigned int dev_num = 1;
173static struct cdev wlan_hdd_state_cdev;
174static struct class *class;
175static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530176#ifndef MODULE
177static struct gwlan_loader *wlan_loader;
178static ssize_t wlan_boot_cb(struct kobject *kobj,
179 struct kobj_attribute *attr,
180 const char *buf, size_t count);
181struct gwlan_loader {
182 bool loaded_state;
183 struct kobject *boot_wlan_obj;
184 struct attribute_group *attr_group;
185};
186
187static struct kobj_attribute wlan_boot_attribute =
188 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
189
190static struct attribute *attrs[] = {
191 &wlan_boot_attribute.attr,
192 NULL,
193};
194
195#define MODULE_INITIALIZED 1
196#endif
197
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530198#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
199#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800200#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530201
202static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800203static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530204static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800206/* the Android framework expects this param even though we don't use it */
207#define BUF_LEN 20
208static char fwpath_buffer[BUF_LEN];
209static struct kparam_string fwpath = {
210 .string = fwpath_buffer,
211 .maxlen = BUF_LEN,
212};
213
214static char *country_code;
215static int enable_11d = -1;
216static int enable_dfs_chan_scan = -1;
217
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800218/*
219 * spinlock for synchronizing asynchronous request/response
220 * (full description of use in wlan_hdd_main.h)
221 */
222DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530223DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800224
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800225#define WLAN_NLINK_CESIUM 30
226
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530227static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800228
229#define WOW_MAX_FILTER_LISTS 1
230#define WOW_MAX_FILTERS_PER_LIST 4
231#define WOW_MIN_PATTERN_SIZE 6
232#define WOW_MAX_PATTERN_SIZE 64
233
234#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
235static const struct wiphy_wowlan_support wowlan_support_reg_init = {
236 .flags = WIPHY_WOWLAN_ANY |
237 WIPHY_WOWLAN_MAGIC_PKT |
238 WIPHY_WOWLAN_DISCONNECT |
239 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
240 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
241 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
242 WIPHY_WOWLAN_4WAY_HANDSHAKE |
243 WIPHY_WOWLAN_RFKILL_RELEASE,
244 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
245 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
246 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
247};
248#endif
249
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700250static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
251 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
263 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
264 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
265 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
266 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
267 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700285 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700286 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700287 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530288 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800289 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530290 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700291};
292
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530293int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
294 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
295 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
296 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
297 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
298};
299
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800300/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530301struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800302
303struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800304#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700305static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800306#endif
307
Sachin Ahujadddd2632017-03-07 19:07:24 +0530308void hdd_start_complete(int ret)
309{
310 wlan_start_ret_val = ret;
311
312 complete(&wlan_start_comp);
313}
314
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800315/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530316 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700317 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530318 *
319 * Return: none
320 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700321static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530322{
Jeff Johnson9d295242017-08-29 14:39:48 -0700323 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530324
Dustin Brown920397d2017-12-13 16:27:50 -0800325 hdd_for_each_adapter(hdd_ctx, adapter)
326 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530327}
328
329/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800330 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
331 * @vdev_id: vdev_id
332 * @action: action type
333 * @reason: reason type
334 *
335 * Return: none
336 */
337void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
338 enum netif_action_type action, enum netif_reason_type reason)
339{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700340 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700341 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800342
343 if (!hdd_ctx) {
344 hdd_err("hdd ctx is NULL");
345 return;
346 }
347 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
348
349 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800350}
351
352/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700353 * Store WLAN driver version and timestamp info in global variables such that
354 * crash debugger can extract them from driver debug symbol and crashdump for
355 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800356 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800357#ifdef BUILD_TAG
358uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
359#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800360uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700361#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800362
363/**
364 * hdd_device_mode_to_string() - return string conversion of device mode
365 * @device_mode: device mode
366 *
367 * This utility function helps log string conversion of device mode.
368 *
369 * Return: string conversion of device mode, if match found;
370 * "Unknown" otherwise.
371 */
372const char *hdd_device_mode_to_string(uint8_t device_mode)
373{
374 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800375 CASE_RETURN_STRING(QDF_STA_MODE);
376 CASE_RETURN_STRING(QDF_SAP_MODE);
377 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
378 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
379 CASE_RETURN_STRING(QDF_FTM_MODE);
380 CASE_RETURN_STRING(QDF_IBSS_MODE);
381 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
382 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700383 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800384 default:
385 return "Unknown";
386 }
387}
388
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530389/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500390 * hdd_get_valid_chan() - return current chan list from regulatory.
391 * @hdd_ctx: HDD context
392 * @chan_list: buf hold returned chan list
393 * @chan_num: input buf size and output returned chan num
394 *
395 * This function helps get current available chan list from regulatory
396 * module. It excludes the "disabled" and "invalid" channels.
397 *
398 * Return: 0 for success.
399 */
400static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
401 uint8_t *chan_list,
402 uint32_t *chan_num)
403{
404 int i = 0, j = 0;
405 struct regulatory_channel *cur_chan_list;
406 struct wlan_objmgr_pdev *pdev;
407
408 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
409 return -EINVAL;
410
411 pdev = hdd_ctx->hdd_pdev;
412 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
413 sizeof(struct regulatory_channel));
414 if (!cur_chan_list)
415 return -ENOMEM;
416
417 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
418 QDF_STATUS_SUCCESS) {
419 qdf_mem_free(cur_chan_list);
420 return -EINVAL;
421 }
422
423 for (i = 0; i < NUM_CHANNELS; i++) {
424 uint32_t ch = cur_chan_list[i].chan_num;
425 enum channel_state state = wlan_reg_get_channel_state(pdev,
426 ch);
427
428 if (state != CHANNEL_STATE_DISABLE &&
429 state != CHANNEL_STATE_INVALID &&
430 j < *chan_num) {
431 chan_list[j] = (uint8_t)ch;
432 j++;
433 }
434 }
435 *chan_num = j;
436 qdf_mem_free(cur_chan_list);
437 return 0;
438}
439
440/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530441 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
442 * @adapter: HDD adapter
443 * @chan_number: Channel number
444 * @chan_bw: Bandwidth
445 *
446 * Checks if the given bandwidth is valid for the given channel number.
447 *
448 * Return: 0 for success, non-zero for failure
449 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700450int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530451 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800452 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530453{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500454 uint8_t chan[NUM_CHANNELS];
455 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530456 bool found = false;
457 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500458 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530459
460 hal = WLAN_HDD_GET_HAL_CTX(adapter);
461 if (!hal) {
462 hdd_err("Invalid HAL context");
463 return -EINVAL;
464 }
465
Liangwei Dong17bf2662018-01-05 02:02:05 -0500466 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
467 &len);
468 if (ret) {
469 hdd_err("error %d in getting valid channel list", ret);
470 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530471 }
472
473 for (i = 0; i < len; i++) {
474 if (chan[i] == chan_number) {
475 found = true;
476 break;
477 }
478 }
479
480 if (found == false) {
481 hdd_err("Channel not in driver's valid channel list");
482 return -EOPNOTSUPP;
483 }
484
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700485 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
486 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530487 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
488 return -EINVAL;
489 }
490
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700491 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530492 if (chan_bw == CH_WIDTH_80MHZ) {
493 hdd_err("BW80 not possible in 2.4GHz band");
494 return -EINVAL;
495 }
496 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
497 (chan_bw != CH_WIDTH_MAX)) {
498 hdd_err("Only BW20 possible on channel 14");
499 return -EINVAL;
500 }
501 }
502
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700503 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530504 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
505 (chan_bw != CH_WIDTH_MAX)) {
506 hdd_err("Only BW20 possible on channel 165");
507 return -EINVAL;
508 }
509 }
510
511 return 0;
512}
513
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530514/**
515 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
516 *
517 * Block the unloading of the driver (or) interface up until the
518 * cds recovery is completed
519 *
520 * Return: true for recovery completion else false
521 */
522static bool hdd_wait_for_recovery_completion(void)
523{
524 int retry = 0;
525
526 /* Wait for recovery to complete */
527 while (cds_is_driver_recovering()) {
528 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
529 hdd_err("Recovery in progress; wait here!!!");
530 msleep(1000);
531 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
532 hdd_err("SSR never completed, error");
533 /*
534 * Trigger the bug_on in the internal builds, in the
535 * customer builds self-recovery will be enabled
536 * in those cases just return error.
537 */
538 if (cds_is_self_recovery_enabled())
539 return false;
540 QDF_BUG(0);
541 }
542 }
543
544 hdd_info("Recovery completed successfully!");
545 return true;
546}
547
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548static int __hdd_netdev_notifier_call(struct notifier_block *nb,
549 unsigned long state, void *data)
550{
551#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
552 struct netdev_notifier_info *dev_notif_info = data;
553 struct net_device *dev = dev_notif_info->dev;
554#else
555 struct net_device *dev = data;
556#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700557 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700558 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800559
Dustin Brownfdf17c12018-03-14 12:55:34 -0700560 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800561
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 /* Make sure that this callback corresponds to our device. */
563 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
564 return NOTIFY_DONE;
565
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530566 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800567 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700568 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800569 return NOTIFY_DONE;
570 }
571
572 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700573 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800574 return NOTIFY_DONE;
575 }
576
577 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
578 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800579 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530580 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800581 return NOTIFY_DONE;
582 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800583
584 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
585 hdd_err("%s: Driver module is closed", __func__);
586 return NOTIFY_DONE;
587 }
588
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530589 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800590 return NOTIFY_DONE;
591
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800592 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800593 dev->name, state);
594
595 switch (state) {
596 case NETDEV_REGISTER:
597 break;
598
599 case NETDEV_UNREGISTER:
600 break;
601
602 case NETDEV_UP:
603 sme_ch_avoid_update_req(hdd_ctx->hHal);
604 break;
605
606 case NETDEV_DOWN:
607 break;
608
609 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700610 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800611 complete(&adapter->linkup_event_var);
612 break;
613
614 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700615 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
616 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530617 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700618 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800619 } else {
hqueaa33ee2017-05-04 17:56:35 +0800620 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800621 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800622 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530623 /*
624 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
625 * of return status of hdd_stop call, kernel resets the IFF_UP
626 * flag after which driver does not send the cfg80211_scan_done.
627 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
628 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530629 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800630 break;
631
632 default:
633 break;
634 }
635
636 return NOTIFY_DONE;
637}
638
639/**
640 * hdd_netdev_notifier_call() - netdev notifier callback function
641 * @nb: pointer to notifier block
642 * @state: state
643 * @ndev: ndev pointer
644 *
645 * Return: 0 on success, error number otherwise.
646 */
647static int hdd_netdev_notifier_call(struct notifier_block *nb,
648 unsigned long state,
649 void *ndev)
650{
651 int ret;
652
653 cds_ssr_protect(__func__);
654 ret = __hdd_netdev_notifier_call(nb, state, ndev);
655 cds_ssr_unprotect(__func__);
656
657 return ret;
658}
659
660struct notifier_block hdd_netdev_notifier = {
661 .notifier_call = hdd_netdev_notifier_call,
662};
663
664/* variable to hold the insmod parameters */
665static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800666
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530667static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700668int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530669
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800670/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800672
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530673/**
674 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
675 * @ch_width: NL channel width
676 *
677 * Converts the NL channel width to the driver's internal representation
678 *
679 * Return: Converted channel width. In case of non matching NL channel width,
680 * CH_WIDTH_MAX will be returned.
681 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800682enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530683{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800684 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700685
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800686 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530687 switch (ch_width) {
688 case NL80211_CHAN_WIDTH_20_NOHT:
689 case NL80211_CHAN_WIDTH_20:
690 return CH_WIDTH_20MHZ;
691 case NL80211_CHAN_WIDTH_40:
692 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530693 case NL80211_CHAN_WIDTH_80:
694 return CH_WIDTH_80MHZ;
695 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800696 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
697 return CH_WIDTH_80P80MHZ;
698 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
699 return CH_WIDTH_160MHZ;
700 else
701 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530702 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800703 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
704 return CH_WIDTH_160MHZ;
705 else
706 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530707 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800708 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530709 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800710 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530711 default:
712 hdd_err("Invalid channel width %d, setting to default",
713 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800714 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530715 }
716}
717
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530718/* wlan_hdd_find_opclass() - Find operating class for a channel
719 * @hal: handler to HAL
720 * @channel: channel id
721 * @bw_offset: bandwidth offset
722 *
723 * Function invokes sme api to find the operating class
724 *
725 * Return: operating class
726 */
727uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
728 uint8_t bw_offset)
729{
730 uint8_t opclass = 0;
731
732 sme_get_opclass(hal, channel, bw_offset, &opclass);
733 return opclass;
734}
735
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530737 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530738 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 * @bitmask: Bitmask of log levels to be enabled
740 *
741 * Called immediately after the cfg.ini is read in order to configure
742 * the desired trace levels.
743 *
744 * Return: None
745 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530746int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530748 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530749 int qdf_print_idx = -1;
750 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800751 /*
752 * if the bitmask is the default value, then a bitmask was not
753 * specified in cfg.ini, so leave the logging level alone (it
754 * will remain at the "compiled in" default value)
755 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700756 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530757 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530759 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800760
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530761 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530762 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530763 QDF_TRACE_LEVEL_NONE, 0);
764
765 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530766 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530768 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769 while (0 != bitmask) {
770 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530771 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530772 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530773 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530774 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700776
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800777 level++;
778 bitmask >>= 1;
779 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530780 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800781}
782
783/**
Chris Guo1751acf2017-07-03 14:09:01 +0800784 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
785 * @hdd_ctx: HDD context pointer
786 *
787 * Return: 0 if the context is valid. Error code otherwise
788 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700789int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800790{
791 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
792 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
793 return -ENODEV;
794 }
795
796 if (cds_is_driver_recovering()) {
797 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
798 (void *)_RET_IP_, cds_get_driver_state());
799 return -EAGAIN;
800 }
801
802 if (hdd_ctx->start_modules_in_progress ||
803 hdd_ctx->stop_modules_in_progress) {
804 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
805 (void *)_RET_IP_);
806 return -EAGAIN;
807 }
808
809 return 0;
810}
811
812
813/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814 * wlan_hdd_validate_context() - check the HDD context
815 * @hdd_ctx: HDD context pointer
816 *
817 * Return: 0 if the context is valid. Error code otherwise
818 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700819int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530822 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 return -ENODEV;
824 }
825
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800826 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800827 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530828 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829 return -EAGAIN;
830 }
831
Yue Ma9f275d92017-09-14 16:58:41 -0700832 if (cds_is_load_or_unload_in_progress()) {
833 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
834 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700836 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530837
838 if (hdd_ctx->start_modules_in_progress ||
839 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800840 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530841 (void *)_RET_IP_);
842 return -EAGAIN;
843 }
844
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530845 if (cds_is_driver_in_bad_state()) {
846 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
847 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530848 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530849 }
850
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530851 if (cds_is_fw_down()) {
852 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
853 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530854 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530855 }
856
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 return 0;
858}
859
Jeff Johnson9d295242017-08-29 14:39:48 -0700860int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700861{
862 if (!adapter) {
863 hdd_err("adapter is null");
864 return -EINVAL;
865 }
866
867 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
868 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
869 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
870 return -EINVAL;
871 }
872
873 if (!adapter->dev) {
874 hdd_err("adapter net_device is null");
875 return -EINVAL;
876 }
877
878 if (!(adapter->dev->flags & IFF_UP)) {
879 hdd_info("adapter net_device is not up");
880 return -EAGAIN;
881 }
882
Jeff Johnson1b780e42017-10-31 14:11:45 -0700883 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700884 hdd_info("adapter session is not open");
885 return -EAGAIN;
886 }
887
Jeff Johnson1b780e42017-10-31 14:11:45 -0700888 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
889 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700890 return -EINVAL;
891 }
892
893 return 0;
894}
895
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530897 * wlan_hdd_validate_modules_state() - Check modules status
898 * @hdd_ctx: HDD context pointer
899 *
900 * Check's the driver module's state and returns true if the
901 * modules are enabled returns false if modules are closed.
902 *
903 * Return: True if modules are enabled or false.
904 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700905bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530906{
907 mutex_lock(&hdd_ctx->iface_change_lock);
908 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
909 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700910 hdd_info("Modules not enabled, Present status: %d",
911 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530912 return false;
913 }
914 mutex_unlock(&hdd_ctx->iface_change_lock);
915 return true;
916}
917
918/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800919 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700920 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 *
922 * This function sets the IBSS power save config parameters to WMA
923 * which will send it to firmware if FW supports IBSS power save
924 * before vdev start.
925 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530926 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927 * on failure.
928 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700929QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800930{
931 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700932 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933
934 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700935 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530936 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937 }
938
Jeff Johnson1b780e42017-10-31 14:11:45 -0700939 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800940 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
941 hdd_ctx->config->ibssATIMWinSize,
942 VDEV_CMD);
943 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700944 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", 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_POWER_SAVE_ALLOWED,
950 hdd_ctx->config->isIbssPowerSaveAllowed,
951 VDEV_CMD);
952 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700953 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
954 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530955 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 }
957
Jeff Johnson1b780e42017-10-31 14:11:45 -0700958 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
960 hdd_ctx->config->
961 isIbssPowerCollapseAllowed, VDEV_CMD);
962 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700963 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
964 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530965 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800966 }
967
Jeff Johnson1b780e42017-10-31 14:11:45 -0700968 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
970 hdd_ctx->config->isIbssAwakeOnTxRx,
971 VDEV_CMD);
972 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700973 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530974 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800975 }
976
Jeff Johnson1b780e42017-10-31 14:11:45 -0700977 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800978 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
979 hdd_ctx->config->ibssInactivityCount,
980 VDEV_CMD);
981 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700982 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530983 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 }
985
Jeff Johnson1b780e42017-10-31 14:11:45 -0700986 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
988 hdd_ctx->config->ibssTxSpEndInactivityTime,
989 VDEV_CMD);
990 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700991 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
992 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530993 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994 }
995
Jeff Johnson1b780e42017-10-31 14:11:45 -0700996 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
998 hdd_ctx->config->ibssPsWarmupTime,
999 VDEV_CMD);
1000 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001001 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
1002 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301003 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001004 }
1005
Jeff Johnson1b780e42017-10-31 14:11:45 -07001006 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001007 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1008 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1009 VDEV_CMD);
1010 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001011 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1012 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301013 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001014 }
1015
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301016 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017}
1018
Yue Macd359b72017-10-03 15:21:00 -07001019#ifdef FEATURE_RUNTIME_PM
1020/**
1021 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1022 * @hdd_ctx: HDD context
1023 *
1024 * Return: None
1025 */
1026static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1027{
1028 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1029
Yue Macd359b72017-10-03 15:21:00 -07001030 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001031 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001032
1033 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1034}
1035
1036/**
1037 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1038 * @hdd_ctx: HDD Context
1039 *
1040 * Return: None
1041 */
1042static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1043{
1044 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1045
Yue Macd359b72017-10-03 15:21:00 -07001046 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001047 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001048
1049 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1050}
1051
Yue Macd359b72017-10-03 15:21:00 -07001052#else /* FEATURE_RUNTIME_PM */
1053static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1054static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001055#endif /* FEATURE_RUNTIME_PM */
1056
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057#define INTF_MACADDR_MASK 0x7
1058
1059/**
1060 * hdd_update_macaddr() - update mac address
1061 * @config: hdd configuration
1062 * @hw_macaddr: mac address
1063 *
1064 * Mac address for multiple virtual interface is found as following
1065 * i) The mac address of the first interface is just the actual hw mac address.
1066 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1067 * define the mac address for the remaining interfaces and locally
1068 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1069 * supported virtual interfaces, right now this is 0x07 (meaning 8
1070 * interface).
1071 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1072 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1073 *
1074 * Return: None
1075 */
1076void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301077 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001078{
1079 int8_t i;
1080 uint8_t macaddr_b3, tmp_br3;
1081
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301082 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301083 QDF_MAC_ADDR_SIZE);
1084 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301085 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301086 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001087 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1088 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1089 INTF_MACADDR_MASK;
1090 macaddr_b3 += tmp_br3;
1091
1092 /* XOR-ing bit-24 of the mac address. This will give enough
1093 * mac address range before collision
1094 */
1095 macaddr_b3 ^= (1 << 7);
1096
1097 /* Set locally administered bit */
1098 config->intfMacAddr[i].bytes[0] |= 0x02;
1099 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001100 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001101 MAC_ADDRESS_STR, i,
1102 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1103 }
1104}
1105
Kabilan Kannan44a58372017-12-06 18:16:11 -08001106static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1107{
1108 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1109 struct tdls_start_params tdls_cfg;
1110 struct tdls_user_config *config = &tdls_cfg.config;
1111 struct hdd_config *cfg = hdd_ctx->config;
1112 QDF_STATUS status;
1113
1114 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1115 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1116 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1117 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1118 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1119 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1120 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1121 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1122 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1123 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1124 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1125 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1126 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1127 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1128 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1129 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1130 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1131 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1132 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1133 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1134 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1135 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1136 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1137 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1138 (cfg->fEnableTDLSImplicitTrigger ?
1139 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1140 (cfg->fTDLSExternalControl ?
1141 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1142 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1143 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1144
1145 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1146 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1147 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1148 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1149 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1150 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1151 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1152 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001153 tdls_cfg.tdls_peer_context = hdd_ctx;
1154 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1155 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001156 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1157 tdls_cfg.tdls_wmm_cb_data = psoc;
1158 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1159 tdls_cfg.tdls_rx_cb_data = psoc;
1160 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1161
1162 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1163 if (status != QDF_STATUS_SUCCESS) {
1164 hdd_err("failed pmo psoc configuration");
1165 return -EINVAL;
1166 }
1167
1168 hdd_ctx->tdls_umac_comp_active = true;
1169 /* enable napier specific tdls data path */
1170 hdd_ctx->tdls_nap_active = true;
1171
1172 return 0;
1173}
1174
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001175static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001176 struct wma_tgt_services *cfg)
1177{
1178 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001179
1180 /* Set up UAPSD */
1181 config->apUapsdEnabled &= cfg->uapsd;
1182
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001183 /* 11AX mode support */
1184 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1185 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1186 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001188 /* 11AC mode support */
1189 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1190 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1191 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192
1193 /* ARP offload: override user setting if invalid */
1194 config->fhostArpOffload &= cfg->arp_offload;
1195
1196#ifdef FEATURE_WLAN_SCAN_PNO
1197 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001198 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 if (cfg->pno_offload)
1200 config->PnoOffload = true;
1201#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202#ifdef FEATURE_WLAN_TDLS
1203 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301204 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1205 cfg->en_tdls_offchan;
1206 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1207 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001208 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001209 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001210 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001211 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001213#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1214 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1215#endif
Will Huang496b36c2017-07-11 16:38:50 +08001216 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001217 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001218 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001219 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001220
1221}
1222
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001223/**
1224 * hdd_update_vdev_nss() - sets the vdev nss
1225 * @hdd_ctx: HDD context
1226 *
1227 * Sets the Nss per vdev type based on INI
1228 *
1229 * Return: None
1230 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001231static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001232{
1233 struct hdd_config *cfg_ini = hdd_ctx->config;
1234 uint8_t max_supp_nss = 1;
1235
Naveen Rawat10b1c152017-01-18 11:16:06 -08001236 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001237 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001238 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1239 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1240 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001241
1242 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001243 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001244
1245 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001246 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001247}
1248
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301249/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301250 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1251 * @hdd_ctx: HDD context
1252 *
1253 * Updates wiphy vhtcap fields
1254 *
1255 * Return: None
1256 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001257static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301258{
1259 struct ieee80211_supported_band *band_5g =
1260 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1261 uint32_t val;
1262
1263 if (!band_5g) {
1264 hdd_debug("5GHz band disabled, skipping capability population");
1265 return;
1266 }
1267
1268 val = hdd_ctx->config->txBFCsnValue;
1269 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1270
1271 val = NUM_OF_SOUNDING_DIMENSIONS;
1272 band_5g->vht_cap.cap |=
1273 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1274
1275 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1276 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1277}
1278
1279/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301280 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1281 * @hdd_ctx: HDD context
1282 *
1283 * Sets the DBS capability as per INI and firmware capability
1284 *
1285 * Return: None
1286 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001287static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301288{
1289 struct hdd_config *cfg_ini = hdd_ctx->config;
1290 uint8_t hw_dbs_capable = 0;
1291
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001292 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1293 ((cfg_ini->dual_mac_feature_disable ==
1294 ENABLE_DBS_CXN_AND_SCAN) ||
1295 (cfg_ini->dual_mac_feature_disable ==
1296 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301297 hw_dbs_capable = 1;
1298
1299 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1300}
1301
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001302static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001303 struct wma_tgt_ht_cap *cfg)
1304{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301305 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001306 uint32_t value, val32;
1307 uint16_t val16;
1308 struct hdd_config *pconfig = hdd_ctx->config;
1309 tSirMacHTCapabilityInfo *phtCapInfo;
1310 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1311 uint8_t enable_tx_stbc;
1312
1313 /* check and update RX STBC */
1314 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1315 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1316
1317 /* get the MPDU density */
1318 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1319
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301320 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001321 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001322 value = 0;
1323 }
1324
1325 /*
1326 * MPDU density:
1327 * override user's setting if value is larger
1328 * than the one supported by target
1329 */
1330 if (value > cfg->mpdu_density) {
1331 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1332 cfg->mpdu_density);
1333
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301334 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001335 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001336 }
1337
1338 /* get the HT capability info */
1339 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301340 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001341 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342 return;
1343 }
1344 val16 = (uint16_t) val32;
1345 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1346
1347 /* Set the LDPC capability */
1348 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1349
1350 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1351 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1352
1353 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1354 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1355
1356 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1357 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1358
1359 enable_tx_stbc = pconfig->enableTxSTBC;
1360
1361 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1362 pconfig->enable2x2 = 1;
1363 } else {
1364 pconfig->enable2x2 = 0;
1365 enable_tx_stbc = 0;
1366
1367 /* 1x1 */
1368 /* Update Rx Highest Long GI data Rate */
1369 if (sme_cfg_set_int(hdd_ctx->hHal,
1370 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001371 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301372 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001373 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 }
1375
1376 /* Update Tx Highest Long GI data Rate */
1377 if (sme_cfg_set_int
1378 (hdd_ctx->hHal,
1379 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001380 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301381 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001382 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383 }
1384 }
1385 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1386 enable_tx_stbc = 0;
1387 phtCapInfo->txSTBC = enable_tx_stbc;
1388
1389 val32 = val16;
1390 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301391 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001392 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1394 value = SIZE_OF_SUPPORTED_MCS_SET;
1395 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301396 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001397 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001398
1399 if (pconfig->enable2x2) {
1400 for (value = 0; value < cfg->num_rf_chains; value++)
1401 mcs_set[value] =
1402 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1403
1404 status =
1405 sme_cfg_set_str(hdd_ctx->hHal,
1406 WNI_CFG_SUPPORTED_MCS_SET,
1407 mcs_set,
1408 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301409 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001410 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001411 }
1412 }
1413#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1414}
1415
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001416static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001417 struct wma_tgt_vht_cap *cfg)
1418{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301419 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420 uint32_t value = 0;
1421 struct hdd_config *pconfig = hdd_ctx->config;
1422 struct wiphy *wiphy = hdd_ctx->wiphy;
1423 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001424 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001425 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001426 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001427 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001428 struct wma_caps_per_phy caps_per_phy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001429
Dustin Brown5e06bd32016-10-04 12:49:10 -07001430 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001431 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001432 return;
1433 }
1434
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001435 /* Get the current MPDU length */
1436 status =
1437 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1438 &value);
1439
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301440 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001441 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 value = 0;
1443 }
1444
1445 /*
1446 * VHT max MPDU length:
1447 * override if user configured value is too high
1448 * that the target cannot support
1449 */
1450 if (value > cfg->vht_max_mpdu) {
1451 status = sme_cfg_set_int(hdd_ctx->hHal,
1452 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1453 cfg->vht_max_mpdu);
1454
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001455 if (status == QDF_STATUS_E_FAILURE)
1456 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001457 }
1458
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001459 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1460 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1461
1462 if (pconfig->enable2x2)
1463 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1464
1465 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1466 QDF_STATUS_E_FAILURE) {
1467 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1468 }
1469
1470 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1471 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1472 if (pconfig->enable2x2)
1473 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1474
1475 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1476 QDF_STATUS_E_FAILURE) {
1477 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1478 }
1479
1480 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1481 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1482 if (pconfig->enable2x2)
1483 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1484
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001485 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001486 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1487
1488 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1489 QDF_STATUS_E_FAILURE) {
1490 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1491 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001492 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001493 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001494 &value);
1495
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301496 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001497 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001498 value = 0;
1499 }
1500
jiad4a7a33c2017-08-08 15:32:24 +08001501 /* Set HW RX LDPC capability */
1502 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1503 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001504 status = sme_cfg_set_int(hdd_ctx->hHal,
1505 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001506 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001508 if (status == QDF_STATUS_E_FAILURE)
1509 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001510 }
1511
1512 /* Get current GI 80 value */
1513 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1514 &value);
1515
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301516 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001517 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001518 value = 0;
1519 }
1520
1521 /* set the Guard interval 80MHz */
1522 if (value && !cfg->vht_short_gi_80) {
1523 status = sme_cfg_set_int(hdd_ctx->hHal,
1524 WNI_CFG_VHT_SHORT_GI_80MHZ,
1525 cfg->vht_short_gi_80);
1526
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001527 if (status == QDF_STATUS_E_FAILURE)
1528 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529 }
1530
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001531 /* Get VHT TX STBC cap */
1532 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1533
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301534 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001535 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001536 value = 0;
1537 }
1538
1539 /* VHT TX STBC cap */
1540 if (value && !cfg->vht_tx_stbc) {
1541 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1542 cfg->vht_tx_stbc);
1543
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001544 if (status == QDF_STATUS_E_FAILURE)
1545 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001546 }
1547
1548 /* Get VHT RX STBC cap */
1549 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1550
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301551 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001552 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553 value = 0;
1554 }
1555
1556 /* VHT RX STBC cap */
1557 if (value && !cfg->vht_rx_stbc) {
1558 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1559 cfg->vht_rx_stbc);
1560
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001561 if (status == QDF_STATUS_E_FAILURE)
1562 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001563 }
1564
1565 /* Get VHT SU Beamformer cap */
1566 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1567 &value);
1568
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301569 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001570 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001571 value = 0;
1572 }
1573
1574 /* set VHT SU Beamformer cap */
1575 if (value && !cfg->vht_su_bformer) {
1576 status = sme_cfg_set_int(hdd_ctx->hHal,
1577 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1578 cfg->vht_su_bformer);
1579
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001580 if (status == QDF_STATUS_E_FAILURE)
1581 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001582 }
1583
1584 /* check and update SU BEAMFORMEE capabality */
1585 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1586 pconfig->enableTxBF = cfg->vht_su_bformee;
1587
1588 status = sme_cfg_set_int(hdd_ctx->hHal,
1589 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1590 pconfig->enableTxBF);
1591
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001592 if (status == QDF_STATUS_E_FAILURE)
1593 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594
1595 /* Get VHT MU Beamformer cap */
1596 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1597 &value);
1598
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301599 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001600 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001601 value = 0;
1602 }
1603
1604 /* set VHT MU Beamformer cap */
1605 if (value && !cfg->vht_mu_bformer) {
1606 status = sme_cfg_set_int(hdd_ctx->hHal,
1607 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1608 cfg->vht_mu_bformer);
1609
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001610 if (status == QDF_STATUS_E_FAILURE)
1611 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 }
1613
1614 /* Get VHT MU Beamformee cap */
1615 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1616 &value);
1617
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301618 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001619 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 value = 0;
1621 }
1622
1623 /* set VHT MU Beamformee cap */
1624 if (value && !cfg->vht_mu_bformee) {
1625 status = sme_cfg_set_int(hdd_ctx->hHal,
1626 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1627 cfg->vht_mu_bformee);
1628
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001629 if (status == QDF_STATUS_E_FAILURE)
1630 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 }
1632
1633 /* Get VHT MAX AMPDU Len exp */
1634 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1635 &value);
1636
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301637 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001638 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639 value = 0;
1640 }
1641
1642 /*
1643 * VHT max AMPDU len exp:
1644 * override if user configured value is too high
1645 * that the target cannot support.
1646 * Even though Rome publish ampdu_len=7, it can
1647 * only support 4 because of some h/w bug.
1648 */
1649
1650 if (value > cfg->vht_max_ampdu_len_exp) {
1651 status = sme_cfg_set_int(hdd_ctx->hHal,
1652 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1653 cfg->vht_max_ampdu_len_exp);
1654
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001655 if (status == QDF_STATUS_E_FAILURE)
1656 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657 }
1658
1659 /* Get VHT TXOP PS CAP */
1660 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1661
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301662 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001663 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664 value = 0;
1665 }
1666
1667 /* set VHT TXOP PS cap */
1668 if (value && !cfg->vht_txop_ps) {
1669 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1670 cfg->vht_txop_ps);
1671
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001672 if (status == QDF_STATUS_E_FAILURE)
1673 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674 }
1675
1676 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1677 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1678 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1679 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1680 else
1681 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1682
1683
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001684 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1685 status = sme_cfg_set_int(hdd_ctx->hHal,
1686 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1687 VHT_CAP_160_AND_80P80_SUPP);
1688 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001689 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001690 band_5g->vht_cap.cap |=
1691 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001692 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1693 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1694 status = sme_cfg_set_int(hdd_ctx->hHal,
1695 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1696 VHT_CAP_160_SUPP);
1697 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001698 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001699 band_5g->vht_cap.cap |=
1700 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001701 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1702 }
1703 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1704 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301705 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001706 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301707 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001708 &value);
1709 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301710 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001711 value = 0;
1712 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301713 /* set the Guard interval 160MHz */
1714 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001715 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301716 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1717 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001718
1719 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301720 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001721 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001722
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001723 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001725 hdd_debug("VHT RxLDPC capability is set");
1726 } else {
1727 /*
1728 * Get the RX LDPC capability for the NON DBS
1729 * hardware mode for 5G band
1730 */
1731 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1732 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1733 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1734 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1735 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1736 hdd_debug("VHT RX LDPC capability is set");
1737 }
1738 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001739
1740 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1741 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1742 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1743 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1744
1745 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1746 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1747
1748 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1749 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1750 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1751 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1752 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1753 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1754
1755 band_5g->vht_cap.cap |=
1756 (cfg->vht_max_ampdu_len_exp <<
1757 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1758
1759 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1760 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1761 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1762 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1763 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1764 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1765 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1766 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1767
1768 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1769 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1770
1771}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001772
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001773/**
1774 * hdd_generate_macaddr_auto() - Auto-generate mac address
1775 * @hdd_ctx: Pointer to the HDD context
1776 *
1777 * Auto-generate mac address using device serial number.
1778 * Keep the first 3 bytes of OUI as before and replace
1779 * the last 3 bytes with the lower 3 bytes of serial number.
1780 *
1781 * Return: 0 for success
1782 * Non zero failure code for errors
1783 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001784static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001785{
1786 unsigned int serialno = 0;
1787 struct qdf_mac_addr mac_addr = {
1788 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1789 };
1790
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001791 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001792 if (serialno == 0)
1793 return -EINVAL;
1794
1795 serialno &= 0x00ffffff;
1796
1797 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1798 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1799 mac_addr.bytes[5] = serialno & 0xff;
1800
1801 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1802 return 0;
1803}
1804
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301805/**
1806 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1807 * configuration to cfg_ini in HDD
1808 * @hdd_ctx: Pointer to hdd_ctx
1809 * @cfg: target configuration
1810 *
1811 * Return: None
1812 */
1813#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001814static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301815 struct wma_tgt_cfg *cfg)
1816{
1817 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1818}
1819#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001820static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301821 struct wma_tgt_cfg *cfg)
1822{
1823}
1824#endif
1825
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001826void hdd_update_tgt_cfg(void *context, void *param)
1827{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001828 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001829 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001830 struct wma_tgt_cfg *cfg = param;
1831 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001832 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301833 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001834 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301835
Dustin Brownbd68fe12017-11-21 15:28:52 -08001836 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1837 if (ret) {
1838 hdd_err("Failed to create pdev; errno:%d", ret);
1839 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001840 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001841 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001842 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001843 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1844 hdd_err("dispatcher pdev open failed");
1845 QDF_BUG(0);
1846 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301847 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001848
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001849 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301850
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301851 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1852 cds_get_context(QDF_MODULE_ID_SOC));
1853 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1854 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301855 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1856 hdd_softap_hard_start_xmit);
1857 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1858 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301859
Naveen Rawat64e477e2016-05-20 10:34:56 -07001860 if (cds_cfg) {
1861 if (hdd_ctx->config->enable_sub_20_channel_width !=
1862 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1863 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1864 cds_cfg->sub_20_channel_width =
1865 WLAN_SUB_20_CH_WIDTH_NONE;
1866 } else {
1867 cds_cfg->sub_20_channel_width =
1868 hdd_ctx->config->enable_sub_20_channel_width;
1869 }
1870 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001871
1872 /* first store the INI band capability */
1873 temp_band_cap = hdd_ctx->config->nBandCapability;
1874
1875 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301876 hdd_ctx->is_fils_roaming_supported =
1877 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301879 hdd_ctx->config->is_11k_offload_supported =
1880 cfg->services.is_11k_offload_supported;
1881
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001882 /*
1883 * now overwrite the target band capability with INI
1884 * setting if INI setting is a subset
1885 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001886
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001887 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1888 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001889 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001890 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1891 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001892 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001893 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001894 }
1895
Amar Singhal58b45ef2017-08-01 13:43:54 -07001896 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1897
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301898 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001899 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1900 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1901 }
1902
1903 /* This can be extended to other configurations like ht, vht cap... */
1904
Anurag Chouhanc5548422016-02-24 18:33:27 +05301905 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001906 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001907 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001908 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001909 static struct qdf_mac_addr default_mac_addr = {
1910 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1911 };
1912 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1913 &default_mac_addr)) {
1914 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1915 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1916 MAC_ADDRESS_STR,
1917 MAC_ADDR_ARRAY(hdd_ctx->config->
1918 intfMacAddr[0].bytes));
1919 } else {
1920 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1921 MAC_ADDRESS_STR,
1922 MAC_ADDR_ARRAY(hdd_ctx->config->
1923 intfMacAddr[0].bytes));
1924 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001925 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001926 }
1927
1928 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001929 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930
1931 hdd_ctx->max_intf_count = cfg->max_intf_count;
1932
Jeff Johnsonc875e242016-09-23 18:12:34 -07001933 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1936 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1937
1938 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1939
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001940 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001941 if (cfg->services.en_11ax) {
1942 hdd_info("11AX: 11ax is enabled - update HDD config");
1943 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1944 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001945
1946 hdd_update_vdev_nss(hdd_ctx);
1947
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301948 hdd_update_hw_dbs_capable(hdd_ctx);
1949
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001950 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001951 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001952 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001953 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001954
Nitesh Shahe50711f2017-04-26 16:30:45 +05301955 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1956 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1957 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001958 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001959 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001960
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001961 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1962 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301963 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301964 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301965
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301966 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001967 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1968 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301969 hdd_ctx->config->txBFCsnValue =
1970 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1971
Arif Hussainee10f902017-12-27 16:30:17 -08001972 status = sme_cfg_set_int(hdd_ctx->hHal,
1973 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1974 hdd_ctx->config->txBFCsnValue);
1975 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301976 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1977
1978
1979 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001980 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1981 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301982
1983 /*
1984 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1985 */
1986 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301987
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301988 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1989
Yue Macd359b72017-10-03 15:21:00 -07001990 /*
1991 * This needs to be done after HDD pdev is created and stored since
1992 * it will access the HDD pdev object lock.
1993 */
1994 hdd_runtime_suspend_context_init(hdd_ctx);
1995
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001996 /* Configure NAN datapath features */
1997 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001998 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08001999 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002000 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2001 cfg->obss_detection_offloaded);
2002 if (QDF_IS_STATUS_ERROR(status))
2003 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002004
2005 status = sme_cfg_set_int(hdd_ctx->hHal,
2006 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2007 cfg->obss_color_collision_offloaded);
2008 if (QDF_IS_STATUS_ERROR(status))
2009 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002010}
2011
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002012bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002013{
Jeff Johnson9d295242017-08-29 14:39:48 -07002014 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002015 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002016
Jiachao Wuf610d912018-01-23 17:47:32 +08002017 if (!hdd_ctx) {
2018 hdd_info("Couldn't get hdd_ctx");
2019 return true;
2020 }
2021
2022 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002023 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002024 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302025 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002026 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002027
Dustin Brown920397d2017-12-13 16:27:50 -08002028 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002029 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2030
2031 if ((QDF_SAP_MODE == adapter->device_mode ||
2032 QDF_P2P_GO_MODE == adapter->device_mode) &&
2033 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002034 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002035 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2036 true;
2037 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002038 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302039 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002040 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302041
2042 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002043}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044
2045/**
2046 * hdd_is_valid_mac_address() - validate MAC address
2047 * @pMacAddr: Pointer to the input MAC address
2048 *
2049 * This function validates whether the given MAC address is valid or not
2050 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2051 * where X is the hexa decimal digit character and separated by ':'
2052 * This algorithm works even if MAC address is not separated by ':'
2053 *
2054 * This code checks given input string mac contains exactly 12 hexadecimal
2055 * digits and a separator colon : appears in the input string only after
2056 * an even number of hex digits.
2057 *
2058 * Return: 1 for valid and 0 for invalid
2059 */
2060bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2061{
2062 int xdigit = 0;
2063 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 while (*pMacAddr) {
2066 if (isxdigit(*pMacAddr)) {
2067 xdigit++;
2068 } else if (':' == *pMacAddr) {
2069 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2070 break;
2071
2072 ++separator;
2073 } else {
2074 /* Invalid MAC found */
2075 return 0;
2076 }
2077 ++pMacAddr;
2078 }
2079 return xdigit == 12 && (separator == 5 || separator == 0);
2080}
2081
2082/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302083 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2084 * @dev: Handle to struct net_device to be updated.
2085 *
2086 * Return: None
2087 */
2088static void hdd_mon_mode_ether_setup(struct net_device *dev)
2089{
2090 dev->header_ops = NULL;
2091 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2092 dev->hard_header_len = ETH_HLEN;
2093 dev->mtu = ETH_DATA_LEN;
2094 dev->addr_len = ETH_ALEN;
2095 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2096 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2097 dev->priv_flags |= IFF_TX_SKB_SHARING;
2098
2099 memset(dev->broadcast, 0xFF, ETH_ALEN);
2100}
2101
2102/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002103 * __hdd__mon_open() - HDD Open function
2104 * @dev: Pointer to net_device structure
2105 *
2106 * This is called in response to ifconfig up
2107 *
2108 * Return: 0 for success; non-zero for failure
2109 */
2110static int __hdd_mon_open(struct net_device *dev)
2111{
2112 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002113 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2114 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002115
Dustin Brownfdf17c12018-03-14 12:55:34 -07002116 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002117
2118 ret = wlan_hdd_validate_context(hdd_ctx);
2119 if (ret)
2120 return ret;
2121
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302122 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002123
2124 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2125 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2126 if (ret) {
2127 hdd_err("Failed to start WLAN modules return");
2128 return ret;
2129 }
2130 hdd_err("hdd_wlan_start_modules() successful !");
2131
2132 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2133 ret = hdd_start_adapter(adapter);
2134 if (ret) {
2135 hdd_err("Failed to start adapter :%d",
2136 adapter->device_mode);
2137 return ret;
2138 }
2139 hdd_err("hdd_start_adapters() successful !");
2140 }
2141 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2142 }
2143
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002144 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002145
2146 if (!ret)
2147 ret = hdd_enable_monitor_mode(dev);
2148
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002149 return ret;
2150}
2151
2152/**
2153 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2154 * @dev: Pointer to net_device structure
2155 *
2156 * This is called in response to ifconfig up
2157 *
2158 * Return: 0 for success; non-zero for failure
2159 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002160static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002161{
2162 int ret;
2163
2164 cds_ssr_protect(__func__);
2165 ret = __hdd_mon_open(dev);
2166 cds_ssr_unprotect(__func__);
2167
2168 return ret;
2169}
2170
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002171static QDF_STATUS
2172wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2173{
2174 struct policy_mgr_dual_mac_config cfg = {0};
2175 QDF_STATUS status;
2176 uint32_t channel_select_logic_conc;
2177 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2178
2179 if (!hdd_ctx) {
2180 hdd_err("HDD context is NULL");
2181 return QDF_STATUS_E_FAILURE;
2182 }
2183
2184
2185 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2186 return QDF_STATUS_SUCCESS;
2187
2188 cfg.scan_config = 0;
2189 cfg.fw_mode_config = 0;
2190 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2191
2192 channel_select_logic_conc = hdd_ctx->config->
2193 channel_select_logic_conc;
2194
2195 if (hdd_ctx->config->dual_mac_feature_disable !=
2196 DISABLE_DBS_CXN_AND_SCAN) {
2197 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2198 hdd_ctx->hdd_psoc, &cfg.scan_config,
2199 &cfg.fw_mode_config,
2200 hdd_ctx->config->dual_mac_feature_disable,
2201 channel_select_logic_conc);
2202
2203 if (status != QDF_STATUS_SUCCESS) {
2204 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2205 status);
2206 return status;
2207 }
2208 }
2209
2210 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2211 cfg.scan_config, cfg.fw_mode_config);
2212
2213 status = sme_soc_set_dual_mac_config(cfg);
2214 if (status != QDF_STATUS_SUCCESS) {
2215 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2216 return status;
2217 }
2218
2219 return QDF_STATUS_SUCCESS;
2220}
2221
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002222/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302223 * hdd_start_adapter() - Wrapper function for device specific adapter
2224 * @adapter: pointer to HDD adapter
2225 *
2226 * This function is called to start the device specific adapter for
2227 * the mode passed in the adapter's device_mode.
2228 *
2229 * Return: 0 for success; non-zero for failure
2230 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002231int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302232{
2233
2234 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002235 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302236
Dustin Brownfdf17c12018-03-14 12:55:34 -07002237 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002238 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302239
2240 switch (device_mode) {
2241 case QDF_P2P_CLIENT_MODE:
2242 case QDF_P2P_DEVICE_MODE:
2243 case QDF_OCB_MODE:
2244 case QDF_STA_MODE:
2245 case QDF_MONITOR_MODE:
2246 ret = hdd_start_station_adapter(adapter);
2247 if (ret)
2248 goto err_start_adapter;
2249 break;
2250 case QDF_P2P_GO_MODE:
2251 case QDF_SAP_MODE:
2252 ret = hdd_start_ap_adapter(adapter);
2253 if (ret)
2254 goto err_start_adapter;
2255 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302256 case QDF_IBSS_MODE:
2257 /*
2258 * For IBSS interface is initialized as part of
2259 * hdd_init_station_mode()
2260 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002261 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302262 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002263 /* vdevs are dynamically managed by firmware in FTM */
2264 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302265 default:
2266 hdd_err("Invalid session type %d", device_mode);
2267 QDF_ASSERT(0);
2268 goto err_start_adapter;
2269 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002270
Arun Khandavallifae92942016-08-01 13:31:08 +05302271 if (hdd_set_fw_params(adapter))
2272 hdd_err("Failed to set the FW params for the adapter!");
2273
2274 /*
2275 * Action frame registered in one adapter which will
2276 * applicable to all interfaces
2277 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302278 ret = wlan_hdd_cfg80211_register_frames(adapter);
2279 if (ret < 0) {
2280 hdd_err("Failed to register frames - ret %d", ret);
2281 goto err_start_adapter;
2282 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002283 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302284
Dustin Browndb2a8be2017-12-20 11:49:56 -08002285exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002286 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002287
Arun Khandavallifae92942016-08-01 13:31:08 +05302288 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002289
Arun Khandavallifae92942016-08-01 13:31:08 +05302290err_start_adapter:
2291 return -EINVAL;
2292}
2293
2294/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302295 * hdd_enable_power_management() - API to Enable Power Management
2296 *
2297 * API invokes Bus Interface Layer power management functionality
2298 *
2299 * Return: None
2300 */
2301static void hdd_enable_power_management(void)
2302{
2303 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2304
2305 if (!hif_ctx) {
2306 hdd_err("Bus Interface Context is Invalid");
2307 return;
2308 }
2309
2310 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2311}
2312
2313/**
2314 * hdd_disable_power_management() - API to disable Power Management
2315 *
2316 * API disable Bus Interface Layer Power management functionality
2317 *
2318 * Return: None
2319 */
2320static void hdd_disable_power_management(void)
2321{
2322 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2323
2324 if (!hif_ctx) {
2325 hdd_err("Bus Interface Context is Invalid");
2326 return;
2327 }
2328
2329 hif_disable_power_management(hif_ctx);
2330}
2331
2332/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302333 * hdd_update_hw_sw_info() - API to update the HW/SW information
2334 *
2335 * API to update the HW and SW information in the driver
2336 *
2337 * Return: None
2338 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002339static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302340{
2341 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002342 size_t target_hw_name_len;
2343 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302344
2345 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2346 if (!hif_sc) {
2347 hdd_err("HIF context is NULL");
2348 return;
2349 }
2350
2351 /*
2352 * target hw version/revision would only be retrieved after firmware
2353 * download
2354 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002355 hif_get_hw_info(hif_sc,
2356 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302357 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002358 &target_hw_name);
2359
2360 if (hdd_ctx->target_hw_name)
2361 qdf_mem_free(hdd_ctx->target_hw_name);
2362
2363 target_hw_name_len = strlen(target_hw_name) + 1;
2364 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2365 if (hdd_ctx->target_hw_name)
2366 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2367 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302368
2369 /* Get the wlan hw/fw version */
2370 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302371}
2372
2373/**
gbian62edd7e2017-03-07 13:12:13 +08002374 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2375 * @hdd_ctx: Pointer to hdd context
2376 *
2377 * Return: none
2378 */
2379static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002380hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002381{
2382 uint8_t num_entries = 0;
2383 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2384 uint8_t *tx_sched_wrr_ac;
2385 int i;
2386 cds_context_type *cds_ctx;
2387
2388 if (NULL == hdd_ctx)
2389 return;
2390
2391 if (NULL == hdd_ctx->config) {
2392 /* Do nothing if hdd_ctx is invalid */
2393 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2394 return;
2395 }
2396
2397 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2398
2399 if (!cds_ctx) {
2400 hdd_err("Invalid CDS Context");
2401 return;
2402 }
2403
2404 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2405 switch (i) {
2406 case OL_TX_WMM_AC_BE:
2407 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2408 break;
2409 case OL_TX_WMM_AC_BK:
2410 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2411 break;
2412 case OL_TX_WMM_AC_VI:
2413 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2414 break;
2415 case OL_TX_WMM_AC_VO:
2416 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2417 break;
2418 default:
2419 tx_sched_wrr_ac = NULL;
2420 break;
2421 }
2422
2423 hdd_string_to_u8_array(tx_sched_wrr_ac,
2424 tx_sched_wrr_param,
2425 &num_entries,
2426 sizeof(tx_sched_wrr_param));
2427
2428 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2429 cds_ctx->ac_specs[i].wrr_skip_weight =
2430 tx_sched_wrr_param[0];
2431 cds_ctx->ac_specs[i].credit_threshold =
2432 tx_sched_wrr_param[1];
2433 cds_ctx->ac_specs[i].send_limit =
2434 tx_sched_wrr_param[2];
2435 cds_ctx->ac_specs[i].credit_reserve =
2436 tx_sched_wrr_param[3];
2437 cds_ctx->ac_specs[i].discard_weight =
2438 tx_sched_wrr_param[4];
2439 }
2440
2441 num_entries = 0;
2442 }
2443}
2444
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302445#ifdef IPA_OFFLOAD
2446/**
2447 * hdd_update_ipa_component_config() - update ipa config
2448 * @hdd_ctx: Pointer to hdd context
2449 *
2450 * Return: none
2451 */
2452static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2453{
2454 struct hdd_config *cfg = hdd_ctx->config;
2455 struct wlan_ipa_config ipa_cfg;
2456
2457 ipa_cfg.ipa_config = cfg->IpaConfig;
2458 ipa_cfg.desc_size = cfg->IpaDescSize;
2459 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2460 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2461 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2462 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2463 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2464 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2465 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2466
2467 ucfg_ipa_update_config(&ipa_cfg);
2468}
2469#else
2470static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2471{
2472}
2473#endif
2474
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002475#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002476static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2477 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2478{
Jeff Johnson9d295242017-08-29 14:39:48 -07002479 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002480 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002481
2482 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2483 if (!adapter) {
2484 hdd_err("Adapter is NULL");
2485 return PM_MAX_NUM_OF_MODE;
2486 }
2487
2488 return policy_mgr_convert_device_mode_to_qdf_type(
2489 adapter->device_mode);
2490}
2491
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002492static void hdd_register_policy_manager_callback(
2493 struct wlan_objmgr_psoc *psoc)
2494{
2495 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002496
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002497 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002498 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002499 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2500 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002501 hdd_cbacks.get_mode_for_non_connected_vdev =
2502 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302503 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002504
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002505 if (QDF_STATUS_SUCCESS !=
2506 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2507 hdd_err("HDD callback registration with policy manager failed");
2508 }
2509}
2510#else
2511static void hdd_register_policy_manager_callback(
2512 struct wlan_objmgr_psoc *psoc)
2513{
2514}
2515#endif
2516
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002517static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002518{
2519 struct nan_callbacks cb_obj = {0};
2520
2521 cb_obj.ndi_open = hdd_ndi_open;
2522 cb_obj.ndi_close = hdd_ndi_close;
2523 cb_obj.ndi_start = hdd_ndi_start;
2524 cb_obj.ndi_delete = hdd_ndi_delete;
2525 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2526 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2527
Naveen Rawat37f62c82017-03-26 22:24:43 -07002528 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2529 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002530 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002531
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002532 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2533}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002534
Dustin Brown26b3d042017-12-21 11:13:27 -08002535#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002536/**
2537 * hdd_check_for_leaks() - Perform runtime memory leak checks
2538 *
2539 * This API triggers runtime memory leak detection. This feature enforces the
2540 * policy that any memory allocated at runtime must also be released at runtime.
2541 *
2542 * Allocating memory at runtime and releasing it at unload is effectively a
2543 * memory leak for configurations which never unload (e.g. LONU, statically
2544 * compiled driver). Such memory leaks are NOT false positives, and must be
2545 * fixed.
2546 *
2547 * Return: None
2548 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002549static void hdd_check_for_leaks(void)
2550{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002551 /* DO NOT REMOVE these checks; for false positives, read above first */
2552
Dustin Brown677e0862017-10-10 16:30:09 -07002553 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002554 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002555 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002556}
2557
Dustin Brown26b3d042017-12-21 11:13:27 -08002558#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2559#else
2560static inline void hdd_check_for_leaks(void) {}
2561
2562#define hdd_debug_domain_set(domain)
2563#endif /* CONFIG_LEAK_DETECTION */
2564
gbian62edd7e2017-03-07 13:12:13 +08002565/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002566 * hdd_update_country_code - Update country code
2567 * @hdd_ctx: HDD context
2568 *
2569 * Update country code based on module parameter country_code
2570 *
2571 * Return: 0 on success and errno on failure
2572 */
2573static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2574{
2575 if (!country_code)
2576 return 0;
2577
2578 return hdd_reg_set_country(hdd_ctx, country_code);
2579}
2580
2581/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302582 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2583 * @hdd_ctx: HDD context
2584 * @adapter: HDD adapter
2585 * @reinit: flag to indicate from SSR or normal path
2586 *
2587 * This function maintains the driver state machine it will be invoked from
2588 * startup, reinit and change interface. Depending on the driver state shall
2589 * perform the opening of the modules.
2590 *
2591 * Return: 0 for success; non-zero for failure
2592 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002593int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2594 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302595 bool reinit)
2596{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002597 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302598 qdf_device_t qdf_dev;
2599 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302600 bool unint = false;
2601 void *hif_ctx;
2602
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002603 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302604
2605 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2606 if (!qdf_dev) {
2607 hdd_err("QDF Device Context is Invalid return");
2608 return -EINVAL;
2609 }
2610
Dustin Brown6f427922017-09-19 12:19:00 -07002611 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302612
Dustin Brown1fe30a82017-10-03 16:13:36 -07002613 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302614 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2615 mutex_unlock(&hdd_ctx->iface_change_lock);
2616 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002617 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302618 return 0;
2619 }
2620
Dustin Brown1fe30a82017-10-03 16:13:36 -07002621 hdd_ctx->start_modules_in_progress = true;
2622
Arun Khandavallifae92942016-08-01 13:31:08 +05302623 switch (hdd_ctx->driver_status) {
2624 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002625 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302626 unint = true;
2627 /* Fall through dont add break here */
2628 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002629 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2630
Dustin Brown26b3d042017-12-21 11:13:27 -08002631 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002632
Arun Khandavallifae92942016-08-01 13:31:08 +05302633 if (!reinit && !unint) {
2634 ret = pld_power_on(qdf_dev->dev);
2635 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002636 hdd_err("Failed to Powerup the device; errno: %d",
2637 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302638 goto release_lock;
2639 }
2640 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002641
2642 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2643 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302644 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2645 qdf_dev->bus_type,
2646 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2647 HIF_ENABLE_TYPE_PROBE);
2648 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002649 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302650 goto power_down;
2651 }
2652
2653 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302654 if (!hif_ctx) {
2655 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002656 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302657 goto power_down;
2658 }
2659
Arun Khandavallifae92942016-08-01 13:31:08 +05302660 status = ol_cds_init(qdf_dev, hif_ctx);
2661 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002662 hdd_err("No Memory to Create BMI Context; status: %d",
2663 status);
2664 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302665 goto hif_close;
2666 }
2667
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302668 hdd_update_ipa_component_config(hdd_ctx);
2669
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002670 ret = hdd_update_config(hdd_ctx);
2671 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002672 hdd_err("Failed to update configuration; errno: %d",
2673 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002674 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002675 }
2676
gbian62edd7e2017-03-07 13:12:13 +08002677 hdd_update_cds_ac_specs_params(hdd_ctx);
2678
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302679 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002680 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002681 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002682 ret = qdf_status_to_os_return(status);
2683 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302684 }
2685
Mukul Sharma9d797a02017-01-05 20:26:03 +05302686 /* initalize components configurations after psoc open */
2687 ret = hdd_update_components_config(hdd_ctx);
2688 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002689 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302690 ret);
2691 goto close;
2692 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002693 status = cds_dp_open(hdd_ctx->hdd_psoc);
2694 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002695 hdd_err("Failed to Open cds post open; status: %d",
2696 status);
2697 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002698 goto close;
2699 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302700
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002701 /*
2702 * NAN compoenet requires certian operations like, open adapter,
2703 * close adapter, etc. to be initiated by HDD, for those
2704 * register HDD callbacks with UMAC's NAN componenet.
2705 */
2706 hdd_nan_register_callbacks(hdd_ctx);
2707
Arun Khandavallifae92942016-08-01 13:31:08 +05302708 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2709
Jeff Johnson3a280122017-09-13 07:42:00 -07002710 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302711 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002712 hdd_err("Failed to pre-enable CDS; status: %d", status);
2713 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002714 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302715 }
2716
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002717 hdd_register_policy_manager_callback(
2718 hdd_ctx->hdd_psoc);
2719
Amar Singhal0928b192017-12-01 10:50:54 -08002720 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2721
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302722 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302723 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002724 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302725
Arun Khandavallifae92942016-08-01 13:31:08 +05302726 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002727 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302728 break;
2729 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302730
Arun Khandavallifae92942016-08-01 13:31:08 +05302731 /* Fall through dont add break here */
2732 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002733 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2734
Arun Khandavallifae92942016-08-01 13:31:08 +05302735 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002736 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002737 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002738 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302739 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302740 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2741 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002742 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302743 break;
2744 }
Dustin Browndca39692017-11-09 15:30:25 -08002745
2746 ret = hdd_configure_cds(hdd_ctx, adapter);
2747 if (ret) {
2748 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002749 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302750 }
Dustin Browndca39692017-11-09 15:30:25 -08002751
Komal Seelamf2136bb2016-09-28 18:30:44 +05302752 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002753
Arun Khandavallifae92942016-08-01 13:31:08 +05302754 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002755 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302756 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002757
Arun Khandavallifae92942016-08-01 13:31:08 +05302758 default:
2759 hdd_err("WLAN start invoked in wrong state! :%d\n",
2760 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002761 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302762 goto release_lock;
2763 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002764
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302765 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002766 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2767 ret = hdd_update_country_code(hdd_ctx);
2768 if (ret)
2769 hdd_err("Failed to update command line country code!");
2770 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302771 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002772
Dustin Browne74003f2018-03-14 12:51:58 -07002773 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002774
Arun Khandavallifae92942016-08-01 13:31:08 +05302775 return 0;
2776
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002777post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002778 cds_post_disable();
Amar Singhal410675c2018-01-10 12:14:21 -08002779 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Dustin Brownbd68fe12017-11-21 15:28:52 -08002780 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002781
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002782cds_txrx_free:
2783 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002784
Arun Khandavallifae92942016-08-01 13:31:08 +05302785close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002786 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002787 hdd_info("Wlan transition aborted (now CLOSED)");
2788
Jeff Johnsone4b14592017-09-13 14:23:33 -07002789 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302790
Dustin Brown28b17892017-10-10 13:29:38 -07002791deinit_config:
2792 cds_deinit_ini_config();
2793
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002794cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302795 ol_cds_free();
2796
2797hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002798 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2799 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302800power_down:
2801 if (!reinit && !unint)
2802 pld_power_off(qdf_dev->dev);
2803release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302804 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302805 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002806
2807 /* many adapter resources are not freed by design in SSR case */
2808 if (!reinit)
2809 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002810 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002811
Dustin Browne74003f2018-03-14 12:51:58 -07002812 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002813
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002814 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302815}
2816
Naveen Rawat910726a2017-03-06 11:42:51 -08002817#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002818static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002819{
2820 int ret = os_if_wifi_pos_register_nl();
2821
2822 if (ret)
2823 hdd_err("os_if_wifi_pos_register_nl failed");
2824
2825 return ret;
2826}
2827
2828static int hdd_deactivate_wifi_pos(void)
2829{
2830 int ret = os_if_wifi_pos_deregister_nl();
2831
2832 if (ret)
2833 hdd_err("os_if_wifi_pos_deregister_nl failed");
2834
2835 return ret;
2836}
2837
2838/**
2839 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2840 * @hdd_ctx: hdd context
2841 *
2842 * Return: status of operation
2843 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002844static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002845{
2846 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2847 struct hdd_config *cfg = hdd_ctx->config;
2848
2849 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2850 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2851 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2852 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2853 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2854 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2855 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2856 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2857}
2858#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002859static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002860{
2861 return oem_activate_service(hdd_ctx);
2862}
2863
2864static int hdd_deactivate_wifi_pos(void)
2865{
2866 return 0;
2867}
2868
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002869static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002870{
2871}
2872#endif
2873
Arun Khandavallifae92942016-08-01 13:31:08 +05302874/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002875 * __hdd_open() - HDD Open function
2876 * @dev: Pointer to net_device structure
2877 *
2878 * This is called in response to ifconfig up
2879 *
2880 * Return: 0 for success; non-zero for failure
2881 */
2882static int __hdd_open(struct net_device *dev)
2883{
Jeff Johnson9d295242017-08-29 14:39:48 -07002884 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002885 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002886 int ret;
2887
Dustin Brownfdf17c12018-03-14 12:55:34 -07002888 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302889 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002890 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002891
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302892 /* Nothing to be done if device is unloading */
2893 if (cds_is_driver_unloading()) {
2894 hdd_err("Driver is unloading can not open the hdd");
2895 return -EBUSY;
2896 }
2897
Dustin Brown01847752017-10-25 13:56:27 -07002898 if (cds_is_driver_recovering()) {
2899 hdd_err("WLAN is currently recovering; Please try again.");
2900 return -EBUSY;
2901 }
2902
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302903 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2904 hdd_err("con_mode_handler is in progress; Please try again.");
2905 return -EBUSY;
2906 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302907
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302908 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302909 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2910
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302911 /*
2912 * This scenario can be hit in cases where in the wlan driver after
2913 * registering the netdevices and there is a failure in driver
2914 * initialization. So return error gracefully because the netdevices
2915 * will be de-registered as part of the load failure.
2916 */
2917
2918 if (!cds_is_driver_loaded()) {
2919 hdd_err("Failed to start the wlan driver!!");
2920 ret = -EIO;
2921 goto err_hdd_hdd_init_deinit_lock;
2922 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302923
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002924
Arun Khandavallifae92942016-08-01 13:31:08 +05302925 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2926 if (ret) {
2927 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302928 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302929 }
2930
2931
2932 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2933 ret = hdd_start_adapter(adapter);
2934 if (ret) {
2935 hdd_err("Failed to start adapter :%d",
2936 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302937 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302938 }
2939 }
2940
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002941 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2942 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002943 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002944 /* Enable TX queues only when we are connected */
2945 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302946 WLAN_START_ALL_NETIF_QUEUE,
2947 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002948 }
2949
Naveen Rawat286def52016-09-23 15:38:02 -07002950 /* Enable carrier and transmit queues for NDI */
2951 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002952 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002953 wlan_hdd_netif_queue_control(adapter,
2954 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2955 WLAN_CONTROL_PATH);
2956 }
2957
Naveen Rawat910726a2017-03-06 11:42:51 -08002958 hdd_populate_wifi_pos_cfg(hdd_ctx);
2959
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302960err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302961 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302962 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002963 return ret;
2964}
2965
Arun Khandavallifae92942016-08-01 13:31:08 +05302966
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002967/**
2968 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2969 * @dev: Pointer to net_device structure
2970 *
2971 * This is called in response to ifconfig up
2972 *
2973 * Return: 0 for success; non-zero for failure
2974 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002975static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002976{
2977 int ret;
2978
2979 cds_ssr_protect(__func__);
2980 ret = __hdd_open(dev);
2981 cds_ssr_unprotect(__func__);
2982
2983 return ret;
2984}
2985
2986/**
2987 * __hdd_stop() - HDD stop function
2988 * @dev: Pointer to net_device structure
2989 *
2990 * This is called in response to ifconfig down
2991 *
2992 * Return: 0 for success; non-zero for failure
2993 */
2994static int __hdd_stop(struct net_device *dev)
2995{
Jeff Johnson9d295242017-08-29 14:39:48 -07002996 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002997 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002998 int ret;
2999
Dustin Brownfdf17c12018-03-14 12:55:34 -07003000 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003001
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303002 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003003 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004
3005 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303006 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003007 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003008
3009 /* Nothing to be done if the interface is not opened */
3010 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003011 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003012 return -ENODEV;
3013 }
3014
3015 /* Make sure the interface is marked as closed */
3016 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303017
3018 hdd_debug("Disabling Auto Power save timer");
3019 sme_ps_disable_auto_ps_timer(
3020 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07003021 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303022
3023 /*
3024 * Disable TX on the interface, after this hard_start_xmit() will not
3025 * be called on that interface
3026 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003027 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003028 hdd_device_mode_to_string(adapter->device_mode),
3029 adapter->device_mode);
3030
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303031 wlan_hdd_netif_queue_control(adapter,
3032 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3033 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003034
3035 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003036 * NAN data interface is different in some sense. The traffic on NDI is
3037 * bursty in nature and depends on the need to transfer. The service
3038 * layer may down the interface after the usage and up again when
3039 * required. In some sense, the NDI is expected to be available
3040 * (like SAP) iface until NDI delete request is issued by the service
3041 * layer. Skip BSS termination and adapter deletion for NAN Data
3042 * interface (NDI).
3043 */
3044 if (WLAN_HDD_IS_NDI(adapter))
3045 return 0;
3046
3047 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003048 * The interface is marked as down for outside world (aka kernel)
3049 * But the driver is pretty much alive inside. The driver needs to
3050 * tear down the existing connection on the netdev (session)
3051 * cleanup the data pipes and wait until the control plane is stabilized
3052 * for this interface. The call also needs to wait until the above
3053 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003054 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003055 * That is intentional to be able to scan if it is a STA/P2P interface
3056 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003057 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003058
3059 /* DeInit the adapter. This ensures datapath cleanup as well */
3060 hdd_deinit_adapter(hdd_ctx, adapter, true);
3061
Arun Khandavallifae92942016-08-01 13:31:08 +05303062
3063 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303064 * Upon wifi turn off, DUT has to flush the scan results so if
3065 * this is the last cli iface, flush the scan database.
3066 */
3067 if (!hdd_is_cli_iface_up(hdd_ctx))
3068 sme_scan_flush_result(hdd_ctx->hHal);
3069
3070 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303071 * Find if any iface is up. If any iface is up then can't put device to
3072 * sleep/power save mode
3073 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303074 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003075 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003076 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3077 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303078 hdd_prevent_suspend_timeout(
3079 hdd_ctx->config->iface_change_wait_time,
3080 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303081 }
3082
Dustin Browne74003f2018-03-14 12:51:58 -07003083 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003084 return 0;
3085}
3086
3087/**
3088 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3089 * @dev: pointer to net_device structure
3090 *
3091 * This is called in response to ifconfig down
3092 *
3093 * Return: 0 for success and error number for failure
3094 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003095static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003096{
3097 int ret;
3098
3099 cds_ssr_protect(__func__);
3100 ret = __hdd_stop(dev);
3101 cds_ssr_unprotect(__func__);
3102
3103 return ret;
3104}
3105
3106/**
3107 * __hdd_uninit() - HDD uninit function
3108 * @dev: Pointer to net_device structure
3109 *
3110 * This is called during the netdev unregister to uninitialize all data
3111 * associated with the device
3112 *
3113 * Return: None
3114 */
3115static void __hdd_uninit(struct net_device *dev)
3116{
Jeff Johnson9d295242017-08-29 14:39:48 -07003117 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003118 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003119
Dustin Brownfdf17c12018-03-14 12:55:34 -07003120 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121
3122 do {
3123 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003124 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003125 break;
3126 }
3127
Jeff Johnson399c6272017-08-30 10:51:00 -07003128 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3129 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003130 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003131 break;
3132 }
3133
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003134 if (dev != adapter->dev)
3135 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003136
Jeff Johnson399c6272017-08-30 10:51:00 -07003137 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138
3139 /* after uninit our adapter structure will no longer be valid */
3140 adapter->dev = NULL;
3141 adapter->magic = 0;
3142 } while (0);
3143
Dustin Browne74003f2018-03-14 12:51:58 -07003144 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003145}
3146
3147/**
3148 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3149 * @dev: pointer to net_device structure
3150 *
3151 * This is called during the netdev unregister to uninitialize all data
3152 * associated with the device
3153 *
3154 * Return: none
3155 */
3156static void hdd_uninit(struct net_device *dev)
3157{
3158 cds_ssr_protect(__func__);
3159 __hdd_uninit(dev);
3160 cds_ssr_unprotect(__func__);
3161}
3162
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003163static int hdd_open_cesium_nl_sock(void)
3164{
3165#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3166 struct netlink_kernel_cfg cfg = {
3167 .groups = WLAN_NLINK_MCAST_GRP_ID,
3168 .input = NULL
3169 };
3170#endif
3171 int ret = 0;
3172
3173#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3174 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3175#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3176 THIS_MODULE,
3177#endif
3178 &cfg);
3179#else
3180 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3181 WLAN_NLINK_MCAST_GRP_ID,
3182 NULL, NULL, THIS_MODULE);
3183#endif
3184
3185 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003186 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003187 ret = -ECONNREFUSED;
3188 }
3189
3190 return ret;
3191}
3192
3193static void hdd_close_cesium_nl_sock(void)
3194{
3195 if (NULL != cesium_nl_srv_sock) {
3196 netlink_kernel_release(cesium_nl_srv_sock);
3197 cesium_nl_srv_sock = NULL;
3198 }
3199}
3200
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003201/**
3202 * __hdd_set_mac_address() - set the user specified mac address
3203 * @dev: Pointer to the net device.
3204 * @addr: Pointer to the sockaddr.
3205 *
3206 * This function sets the user specified mac address using
3207 * the command ifconfig wlanX hw ether <mac adress>.
3208 *
3209 * Return: 0 for success, non zero for failure
3210 */
3211static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3212{
Jeff Johnson9d295242017-08-29 14:39:48 -07003213 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003214 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303216 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303218 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003219
Dustin Brownfdf17c12018-03-14 12:55:34 -07003220 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003221
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303222 if (netif_running(dev)) {
3223 hdd_err("On iface up, set mac address change isn't supported");
3224 return -EBUSY;
3225 }
3226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003227 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3228 ret = wlan_hdd_validate_context(hdd_ctx);
3229 if (0 != ret)
3230 return ret;
3231
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303232 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
3233
3234 if (qdf_is_macaddr_zero(&mac_addr)) {
3235 hdd_err("MAC is all zero");
3236 return -EINVAL;
3237 }
3238
3239 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3240 hdd_err("MAC is Broadcast");
3241 return -EINVAL;
3242 }
3243
3244 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3245 hdd_err("MAC is Multicast");
3246 return -EINVAL;
3247 }
3248
Jeff Johnson1e851a12017-10-28 14:36:12 -07003249 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3251
Dustin Browne74003f2018-03-14 12:51:58 -07003252 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303253 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003254}
3255
3256/**
3257 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3258 * function from SSR
3259 * @dev: pointer to net_device structure
3260 * @addr: Pointer to the sockaddr
3261 *
3262 * This function sets the user specified mac address using
3263 * the command ifconfig wlanX hw ether <mac adress>.
3264 *
3265 * Return: 0 for success.
3266 */
3267static int hdd_set_mac_address(struct net_device *dev, void *addr)
3268{
3269 int ret;
3270
3271 cds_ssr_protect(__func__);
3272 ret = __hdd_set_mac_address(dev, addr);
3273 cds_ssr_unprotect(__func__);
3274
3275 return ret;
3276}
3277
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003278uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003279{
3280 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003281
Anurag Chouhan6d760662016-02-20 16:05:43 +05303282 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3284 break;
3285 }
3286
Anurag Chouhan6d760662016-02-20 16:05:43 +05303287 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288 return NULL;
3289
3290 hdd_ctx->config->intfAddrMask |= (1 << i);
3291 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3292}
3293
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003294void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3295 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003296{
3297 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003298
Anurag Chouhan6d760662016-02-20 16:05:43 +05303299 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003300 if (!memcmp(releaseAddr,
3301 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3302 6)) {
3303 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3304 break;
3305 }
3306 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307}
3308
3309#ifdef WLAN_FEATURE_PACKET_FILTERING
3310/**
3311 * __hdd_set_multicast_list() - set the multicast address list
3312 * @dev: Pointer to the WLAN device.
3313 * @skb: Pointer to OS packet (sk_buff).
3314 *
3315 * This funciton sets the multicast address list.
3316 *
3317 * Return: None
3318 */
3319static void __hdd_set_multicast_list(struct net_device *dev)
3320{
Jeff Johnson9d295242017-08-29 14:39:48 -07003321 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003322 int i = 0, status;
3323 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003324 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303325 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3326 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3327 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003328
Dustin Brownfdf17c12018-03-14 12:55:34 -07003329 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303330 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303331 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303332
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003333 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303334 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303335 goto out;
3336
Dustin Brownc788acb2017-08-01 17:43:51 -07003337 status = hdd_validate_adapter(adapter);
3338 if (status)
3339 goto out;
3340
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303341 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3342 hdd_err("%s: Driver module is closed", __func__);
3343 return;
3344 }
3345
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303346 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3347 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003348 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303349 goto out;
3350 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003351
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303352 /* Delete already configured multicast address list */
3353 if (adapter->mc_addr_list.mc_cnt > 0) {
3354 hdd_info("clear previously configured MC address list");
3355 hdd_disable_and_flush_mc_addr_list(adapter,
3356 pmo_mc_list_change_notify);
3357 }
3358
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003360 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303361 hdd_disable_and_flush_mc_addr_list(adapter,
3362 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363 } else {
3364 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303365 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003366 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303367 pmo_ucfg_max_mc_addr_supported(psoc));
3368 hdd_disable_and_flush_mc_addr_list(adapter,
3369 pmo_mc_list_change_notify);
3370 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003372 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003373 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303374 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375 if (i == mc_count)
3376 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303377 memset(&(mc_list_request->mc_addr[i].bytes),
3378 0, ETH_ALEN);
3379 memcpy(&(mc_list_request->mc_addr[i].bytes),
3380 ha->addr, ETH_ALEN);
3381 hdd_info("mlist[%d] = %pM", i,
3382 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003383 i++;
3384 }
3385 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303386
3387 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003388 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303389 mc_list_request->count = mc_count;
3390 status = hdd_cache_mc_addr_list(mc_list_request);
3391 if (status == 0) {
3392 hdd_enable_mc_addr_filtering(adapter,
3393 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003394 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303395 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303397out:
3398 if (mc_list_request)
3399 qdf_mem_free(mc_list_request);
Dustin Browne74003f2018-03-14 12:51:58 -07003400 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003401}
3402
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303403
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404/**
3405 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3406 * @dev: pointer to net_device
3407 *
3408 * Return: none
3409 */
3410static void hdd_set_multicast_list(struct net_device *dev)
3411{
3412 cds_ssr_protect(__func__);
3413 __hdd_set_multicast_list(dev);
3414 cds_ssr_unprotect(__func__);
3415}
3416#endif
3417
3418/**
3419 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3420 * @dev: Pointer to the WLAN device.
3421 * @skb: Pointer to OS packet (sk_buff).
3422 *
3423 * This function is registered with the Linux OS for network
3424 * core to decide which queue to use first.
3425 *
3426 * Return: ac, Queue Index/access category corresponding to UP in IP header
3427 */
3428static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3429#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3430 , void *accel_priv
3431#endif
3432#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3433 , select_queue_fallback_t fallback
3434#endif
3435)
3436{
3437 return hdd_wmm_select_queue(dev, skb);
3438}
3439
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003440static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441 .ndo_open = hdd_open,
3442 .ndo_stop = hdd_stop,
3443 .ndo_uninit = hdd_uninit,
3444 .ndo_start_xmit = hdd_hard_start_xmit,
3445 .ndo_tx_timeout = hdd_tx_timeout,
3446 .ndo_get_stats = hdd_get_stats,
3447 .ndo_do_ioctl = hdd_ioctl,
3448 .ndo_set_mac_address = hdd_set_mac_address,
3449 .ndo_select_queue = hdd_select_queue,
3450#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003451 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452#endif
3453};
3454
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003455/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003456static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003457 .ndo_open = hdd_mon_open,
3458 .ndo_stop = hdd_stop,
3459 .ndo_get_stats = hdd_get_stats,
3460};
3461
3462/**
3463 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003464 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003465 * Return: None
3466 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003467void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003469 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003470 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003471 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003472 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003473}
3474
3475/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003476 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3477 * @hdd_ctx: global hdd context
3478 * @macAddr: mac address to assign to the interface
3479 * @name: User-visible name of the interface
3480 *
3481 * hdd adapter pointer would point to the netdev->priv space, this function
3482 * would retrive the pointer, and setup the hdd adapter configuration.
3483 *
3484 * Return: the pointer to hdd adapter, otherwise NULL
3485 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003486static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003488 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489 const char *name)
3490{
Jeff Johnson5505db82017-11-02 21:19:23 -07003491 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003492 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003493 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303494 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003495 /*
3496 * cfg80211 initialization and registration....
3497 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003498 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003499#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3500 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003502 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3503 hdd_mon_mode_ether_setup : ether_setup),
3504 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003505
Jeff Johnson5505db82017-11-02 21:19:23 -07003506 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507
3508 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003509 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003510
Jeff Johnson9d295242017-08-29 14:39:48 -07003511 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003512 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303513 qdf_mem_set(sta_ctx->conn_info.staId,
3514 sizeof(sta_ctx->conn_info.staId),
3515 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003516 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003517 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003519 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303521 qdf_status = qdf_event_create(
3522 &adapter->qdf_session_open_event);
3523 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3524 hdd_err("Session open QDF event init failed!");
3525 free_netdev(adapter->dev);
3526 return NULL;
3527 }
3528
3529 qdf_status = qdf_event_create(
3530 &adapter->qdf_session_close_event);
3531 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3532 hdd_err("Session close QDF event init failed!");
3533 free_netdev(adapter->dev);
3534 return NULL;
3535 }
3536
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003537 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303538 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003539 init_completion(&adapter->linkup_event_var);
3540 init_completion(&adapter->cancel_rem_on_chan_var);
3541 init_completion(&adapter->rem_on_chan_ready_event);
3542 init_completion(&adapter->sta_authorized_event);
3543 init_completion(&adapter->offchannel_tx_event);
3544 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003545 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303546 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003547
3548 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003549 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303550 adapter->disconnection_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003551 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003552 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553
Jeff Johnson5505db82017-11-02 21:19:23 -07003554 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003555 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003556 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003558 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559
3560 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003561 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003563 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003564
Jeff Johnson5505db82017-11-02 21:19:23 -07003565 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003566
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003567 hdd_set_station_ops(adapter->dev);
3568
Jeff Johnson5505db82017-11-02 21:19:23 -07003569 hdd_dev_setup_destructor(dev);
3570 dev->ieee80211_ptr = &adapter->wdev;
3571 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003572 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003573 adapter->wdev.netdev = dev;
3574 /* set dev's parent to underlying device */
3575 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576 hdd_wmm_init(adapter);
3577 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303578 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003579 }
3580
3581 return adapter;
3582}
3583
Jeff Johnson9d295242017-08-29 14:39:48 -07003584static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003586 struct net_device *dev = adapter->dev;
3587 int ret;
3588
Dustin Brown491d54b2018-03-14 12:39:11 -07003589 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003591 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003592 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3593
3594 ret = dev_alloc_name(dev, dev->name);
3595 if (ret < 0) {
3596 hdd_err(
3597 "unable to get dev name: %s, err = 0x%x",
3598 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303599 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 }
3601 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003602
3603 ret = register_netdevice(dev);
3604 if (ret) {
3605 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3606 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303607 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608 }
3609 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003610 ret = register_netdev(dev);
3611 if (ret) {
3612 hdd_err("register_netdev(%s) failed, err = 0x%x",
3613 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303614 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003615 }
3616 }
3617 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3618
Dustin Browne74003f2018-03-14 12:51:58 -07003619 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003620
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303621 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003622}
3623
Krunal Sonib51eec72017-11-20 21:53:01 -08003624QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625{
Krunal Sonib51eec72017-11-20 21:53:01 -08003626 struct hdd_adapter *adapter;
3627 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628
Krunal Sonib51eec72017-11-20 21:53:01 -08003629 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3630 if (!hdd_ctx) {
3631 hdd_err("Invalid HDD_CTX");
3632 return QDF_STATUS_E_FAILURE;
3633 }
3634
3635 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3636 if (NULL == adapter) {
3637 hdd_err("NULL adapter");
3638 return QDF_STATUS_E_INVAL;
3639 }
3640 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303641 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003642 hdd_debug("session %d opened", adapter->session_id);
3643
3644 return QDF_STATUS_SUCCESS;
3645}
3646
3647QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3648{
3649 struct hdd_adapter *adapter;
3650 struct hdd_context *hdd_ctx;
3651
3652 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3653 if (!hdd_ctx) {
3654 hdd_err("Invalid HDD_CTX");
3655 return QDF_STATUS_E_FAILURE;
3656 }
3657
3658 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003660 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303661 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003662 }
3663
3664 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003665 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303666 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 }
3668
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003669 /*
3670 * For NAN Data interface, the close session results in the final
3671 * indication to the userspace
3672 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003673 if (adapter->device_mode == QDF_NDI_MODE)
3674 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003675
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3677
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003678 /*
3679 * We can be blocked while waiting for scheduled work to be
3680 * flushed, and the adapter structure can potentially be freed, in
3681 * which case the magic will have been reset. So make sure the
3682 * magic is still good, and hence the adapter structure is still
3683 * valid, before signaling completion
3684 */
3685 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303686 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003687
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303688 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689}
3690
Jeff Johnson9d295242017-08-29 14:39:48 -07003691int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692{
Dustin Brownd28772b2017-03-17 14:16:07 -07003693 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694
Dustin Brownd28772b2017-03-17 14:16:07 -07003695 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003696 if (QDF_IS_STATUS_ERROR(status))
3697 return qdf_status_to_os_return(status);
3698
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003699 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003700 if (QDF_IS_STATUS_ERROR(status))
3701 return qdf_status_to_os_return(status);
3702
3703 if (wma_capability_enhanced_mcast_filter())
3704 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3705 else
3706 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003707
3708 return qdf_status_to_os_return(status);
3709}
3710
Jeff Johnson9d295242017-08-29 14:39:48 -07003711int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003712{
3713 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003714 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003715 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003716 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003717
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003718 vdev_id = adapter->session_id;
3719 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003720
3721 /* vdev created sanity check */
3722 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003723 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003724 return -EINVAL;
3725 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003726 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003727
Dustin Brownd28772b2017-03-17 14:16:07 -07003728 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303729 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003730 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003731 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003732 if (QDF_IS_STATUS_ERROR(status)) {
3733 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003734 errno = qdf_status_to_os_return(status);
3735 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003736 }
3737
3738 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303739 status = qdf_wait_for_event_completion(
3740 &adapter->qdf_session_close_event,
3741 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3742 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003743 if (adapter->device_mode == QDF_NDI_MODE)
3744 hdd_ndp_session_end_handler(adapter);
3745 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303746 adapter->session_id = HDD_SESSION_ID_INVALID;
3747 if (QDF_STATUS_E_TIMEOUT != status) {
3748 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003749 errno = -ETIMEDOUT;
3750 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303751 } else if (adapter->qdf_session_close_event.force_set) {
3752 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003753 errno = -EINVAL;
3754 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303755 } else {
3756 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003757 errno = -EINVAL;
3758 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303759 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003760 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003761
Yue Maf9782842017-05-08 12:49:49 -07003762release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003763 /*
3764 * In SSR or driver unloading case, directly exit may cause objects
3765 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003766 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003767 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003768 return errno;
3769
Sandeep Puligillaef415362017-08-30 16:37:13 -07003770 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003771 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003772 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003773 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003774 return errno;
3775 }
3776
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003777 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003778
3779 return 0;
3780}
3781
Krunal Sonib51eec72017-11-20 21:53:01 -08003782static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3783 struct sme_session_params *session_param,
3784 csr_roam_completeCallback callback,
3785 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003786{
Dustin Brownd28772b2017-03-17 14:16:07 -07003787 uint32_t type;
3788 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003789 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003790
3791 /* determine vdev (sub)type */
3792 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303793 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003794 hdd_err("failed to get vdev type: %d", status);
3795 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003796 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003797 session_param->sme_session_id = adapter->session_id;
3798 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3799 session_param->type_of_persona = type;
3800 session_param->subtype_of_persona = sub_type;
3801 session_param->session_open_cb = hdd_sme_open_session_callback;
3802 session_param->session_close_cb = hdd_sme_close_session_callback;
3803 session_param->callback = callback;
3804 session_param->callback_ctx = callback_ctx;
3805
3806 return 0;
3807}
3808
3809int hdd_vdev_create(struct hdd_adapter *adapter,
3810 csr_roam_completeCallback callback, void *ctx)
3811{
3812 QDF_STATUS status;
3813 int errno;
3814 struct hdd_context *hdd_ctx;
3815 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003816
3817 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003818
3819 /* do vdev create via objmgr */
3820 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003821 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003822 if (errno) {
3823 hdd_err("failed to create objmgr vdev: %d", errno);
3824 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003825 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003826
3827 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303828 status = qdf_event_reset(&adapter->qdf_session_open_event);
3829 if (QDF_STATUS_SUCCESS != status) {
3830 hdd_err("failed to reinit session open event");
3831 return -EINVAL;
3832 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003833 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3834 callback, ctx);
3835 if (errno) {
3836 hdd_err("failed to populating SME params");
3837 goto objmgr_vdev_destroy_procedure;
3838 }
3839
3840 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003841 if (QDF_IS_STATUS_ERROR(status)) {
3842 hdd_err("failed to open sme session: %d", status);
3843 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003844 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003845 }
3846
3847 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303848 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3849 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3850 if (QDF_STATUS_SUCCESS != status) {
3851 if (adapter->qdf_session_open_event.force_set) {
3852 /*
3853 * SSR/PDR has caused shutdown, which has forcefully
3854 * set the event. Return without the closing session.
3855 */
3856 adapter->session_id = HDD_SESSION_ID_INVALID;
3857 hdd_err("Session open event forcefully set");
3858 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303859 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003860
3861 if (QDF_STATUS_E_TIMEOUT == status)
3862 hdd_err("Session failed to open within timeout period");
3863 else
3864 hdd_err("Failed to wait for session open event(status-%d)",
3865 status);
3866 errno = -ETIMEDOUT;
3867 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3868 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003869 }
3870
3871 /* firmware ready for component communication, raise vdev_ready event */
3872 errno = hdd_vdev_ready(adapter);
3873 if (errno) {
3874 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003875 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003876 }
3877
Jeff Johnson1b780e42017-10-31 14:11:45 -07003878 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003879
3880 return 0;
3881
3882 /*
3883 * Due to legacy constraints, we need to destroy in the same order as
3884 * create. So, split error handling into 2 cases to accommodate.
3885 */
3886
Krunal Soni4a020c72017-10-30 20:58:40 -07003887objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003888 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003889
3890 return errno;
3891
Krunal Soni4a020c72017-10-30 20:58:40 -07003892hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003893 QDF_BUG(!hdd_vdev_destroy(adapter));
3894
3895 return errno;
3896}
3897
Jeff Johnson9d295242017-08-29 14:39:48 -07003898QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003899{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003900 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003901 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003902 QDF_STATUS status;
3903 int ret_val;
3904
Dustin Brownd28772b2017-03-17 14:16:07 -07003905 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3906 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3907 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003908 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003909
Jeff Johnson7f2c5912018-03-23 11:42:28 -07003910 hdd_roam_profile_init(adapter);
3911 hdd_register_wext(adapter->dev);
3912
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003913 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914
Jeff Johnsond377dce2017-10-04 10:32:42 -07003915 qdf_mem_set(sta_ctx->conn_info.staId,
3916 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303917
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003918 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003919 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303920 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003921 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003922 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923 hdd_ctx->config->OperatingChannel;
3924
3925 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003926 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927
3928 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303929 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003930 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 status, status);
3932 goto error_init_txrx;
3933 }
3934
3935 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3936
3937 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303938 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003939 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940 status, status);
3941 goto error_wmm_init;
3942 }
3943
3944 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3945
Jeff Johnson1b780e42017-10-31 14:11:45 -07003946 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947 WMI_PDEV_PARAM_BURST_ENABLE,
3948 hdd_ctx->config->enableSifsBurst,
3949 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003950 if (ret_val)
3951 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003952
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303953 /*
3954 * In case of USB tethering, LRO is disabled. If SSR happened
3955 * during that time, then as part of SSR init, do not enable
3956 * the LRO again. Keep the LRO state same as before SSR.
3957 */
3958 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003959 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303960
3961 /* rcpi info initialization */
3962 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3963
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303964 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003965
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966error_wmm_init:
3967 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3968 hdd_deinit_tx_rx(adapter);
3969error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003970 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003971 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003973 return status;
3974}
3975
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303976/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003977 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303978 * @hdd_ctx: global hdd context
3979 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003980 * @rtnl_held: Used to indicate whether or not the caller is holding
3981 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303982 *
3983 * This function De-initializes the STA/P2P/OCB adapter.
3984 *
3985 * Return: None.
3986 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003987static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003988 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003989 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303990{
Dustin Brownfdf17c12018-03-14 12:55:34 -07003991 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303992
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303993 if (adapter->dev) {
3994 if (rtnl_held)
3995 adapter->dev->wireless_handlers = NULL;
3996 else {
3997 rtnl_lock();
3998 adapter->dev->wireless_handlers = NULL;
3999 rtnl_unlock();
4000 }
4001 }
4002
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304003 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4004 hdd_deinit_tx_rx(adapter);
4005 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4006 }
4007
4008 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4009 hdd_wmm_adapter_close(adapter);
4010 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4011 }
4012
Krunal Sonib51eec72017-11-20 21:53:01 -08004013
Dustin Browne74003f2018-03-14 12:51:58 -07004014 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304015}
4016
Krunal Sonib51eec72017-11-20 21:53:01 -08004017void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4018 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 bool rtnl_held)
4020{
Dustin Brown491d54b2018-03-14 12:39:11 -07004021 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304022
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004024 case QDF_STA_MODE:
4025 case QDF_P2P_CLIENT_MODE:
4026 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004027 case QDF_IBSS_MODE:
4028 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004030 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004031 break;
4032 }
4033
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004034 case QDF_SAP_MODE:
4035 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004036 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004037 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038 break;
4039 }
4040
4041 default:
4042 break;
4043 }
4044
Dustin Browne74003f2018-03-14 12:51:58 -07004045 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004046}
4047
Jeff Johnson9d295242017-08-29 14:39:48 -07004048static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004049 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050{
Jeff Johnson5505db82017-11-02 21:19:23 -07004051 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052
4053 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004054 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004055 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004056 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004057 return;
4058 }
4059
Alok Kumarb64650c2018-03-23 17:05:11 +05304060 hdd_nud_deinit_tracking(adapter);
4061 qdf_mutex_destroy(&adapter->disconnection_status_lock);
4062
Rajeev Kumardca5f812016-02-04 17:28:06 -08004063 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065 /*
4066 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4067 * the driver is almost closed and cannot handle either control
4068 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004069 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4070 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071 * is not right. Setting this flag helps hdd_stop() to recognize that
4072 * the interface is closed and restricts any operations on that
4073 */
4074 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4075
4076 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004077 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004078 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004079 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004080 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004081 /*
4082 * Note that the adapter is no longer valid at this point
4083 * since the memory has been reclaimed
4084 */
4085 }
4086}
4087
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004088static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004089 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090{
Jeff Johnson9d295242017-08-29 14:39:48 -07004091 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004092
Dustin Brown920397d2017-12-13 16:27:50 -08004093 hdd_for_each_adapter(hdd_ctx, adapter) {
4094 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4095 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304096 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098 }
Dustin Brown920397d2017-12-13 16:27:50 -08004099
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304100 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004101}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004102
Arun Khandavalli2358d522016-05-16 18:05:37 +05304103#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4104/**
4105 * hdd_set_fw_log_params() - Set log parameters to FW
4106 * @hdd_ctx: HDD Context
4107 * @adapter: HDD Adapter
4108 *
4109 * This function set the FW Debug log level based on the INI.
4110 *
4111 * Return: None
4112 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004113static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004114 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304115{
4116 uint8_t count = 0, numentries = 0,
4117 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4118 uint32_t value = 0;
4119 int ret;
4120
Arun Khandavallifae92942016-08-01 13:31:08 +05304121 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4122 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004123 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304124 return;
4125 }
4126
Arun Khandavallifae92942016-08-01 13:31:08 +05304127 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304128 hdd_ctx->fw_log_settings.dl_type =
4129 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004130 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304131 WMI_DBGLOG_TYPE,
4132 hdd_ctx->config->enableFwLogType,
4133 DBG_CMD);
4134 if (ret != 0)
4135 hdd_err("Failed to enable FW log type ret %d",
4136 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304137
4138 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304139 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004140 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304141 WMI_DBGLOG_LOG_LEVEL,
4142 hdd_ctx->config->enableFwLogLevel,
4143 DBG_CMD);
4144 if (ret != 0)
4145 hdd_err("Failed to enable FW log level ret %d",
4146 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304147
4148 hdd_string_to_u8_array(
4149 hdd_ctx->config->enableFwModuleLogLevel,
4150 moduleloglevel,
4151 &numentries,
4152 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4153
4154 while (count < numentries) {
4155 /*
4156 * FW module log level input string looks like
4157 * below:
4158 * gFwDebugModuleLoglevel=<FW Module ID>,
4159 * <Log Level>,...
4160 * For example:
4161 * gFwDebugModuleLoglevel=
4162 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4163 * Above input string means :
4164 * For FW module ID 1 enable log level 0
4165 * For FW module ID 2 enable log level 1
4166 * For FW module ID 3 enable log level 2
4167 * For FW module ID 4 enable log level 3
4168 * For FW module ID 5 enable log level 4
4169 * For FW module ID 6 enable log level 5
4170 * For FW module ID 7 enable log level 6
4171 */
4172
Nishank Aggarwale239d962017-03-03 12:26:02 +05304173 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4174 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4175 hdd_err("Module id %d and dbglog level %d input length is more than max",
4176 moduleloglevel[count],
4177 moduleloglevel[count + 1]);
4178 return;
4179 }
4180
4181 value = moduleloglevel[count] << 16;
4182 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004183 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304184 WMI_DBGLOG_MOD_LOG_LEVEL,
4185 value, DBG_CMD);
4186 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304187 hdd_err("Failed to enable FW module log level %d ret %d",
4188 value, ret);
4189
4190 count += 2;
4191 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304192
Arun Khandavalli2358d522016-05-16 18:05:37 +05304193}
4194#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004195static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004196 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304197{
4198}
4199
4200#endif
4201
4202/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004203 * hdd_configure_chain_mask() - programs chain mask to firmware
4204 * @adapter: HDD adapter
4205 *
4206 * Return: 0 on success or errno on failure
4207 */
4208static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4209{
4210 int ret_val;
4211 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4212
4213 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4214 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4215 hdd_ctx->config->txchainmask1x1,
4216 hdd_ctx->config->rxchainmask1x1);
4217 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4218 hdd_ctx->config->dual_mac_feature_disable,
4219 hdd_ctx->config->tx_chain_mask_2g,
4220 hdd_ctx->config->rx_chain_mask_2g);
4221 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4222 hdd_ctx->config->tx_chain_mask_5g,
4223 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004224 hdd_debug("enable_bt_chain_separation %d",
4225 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004226
Liangwei Dong22810e82018-03-15 03:42:12 -04004227 if (hdd_ctx->config->enable2x2 &&
4228 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004229 hdd_info("2x2 enabled. skip chain mask programming");
4230 return 0;
4231 }
4232
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004233 if (hdd_ctx->config->dual_mac_feature_disable !=
4234 DISABLE_DBS_CXN_AND_SCAN) {
4235 hdd_info("DBS enabled(%d). skip chain mask programming",
4236 hdd_ctx->config->dual_mac_feature_disable);
4237 return 0;
4238 }
4239
Naveen Rawatdacb5032018-02-08 15:23:24 -08004240 if (hdd_ctx->lte_coex_ant_share) {
4241 hdd_info("lte ant sharing enabled. skip chainmask programming");
4242 return 0;
4243 }
4244
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004245 if (hdd_ctx->config->txchainmask1x1) {
4246 ret_val = sme_cli_set_command(adapter->session_id,
4247 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4248 hdd_ctx->config->txchainmask1x1,
4249 PDEV_CMD);
4250 if (ret_val)
4251 goto error;
4252 }
4253
4254 if (hdd_ctx->config->rxchainmask1x1) {
4255 ret_val = sme_cli_set_command(adapter->session_id,
4256 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4257 hdd_ctx->config->rxchainmask1x1,
4258 PDEV_CMD);
4259 if (ret_val)
4260 goto error;
4261 }
4262
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004263 if (hdd_ctx->config->txchainmask1x1 ||
4264 hdd_ctx->config->rxchainmask1x1) {
4265 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4266 return 0;
4267 }
4268
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004269 if (hdd_ctx->config->tx_chain_mask_2g) {
4270 ret_val = sme_cli_set_command(adapter->session_id,
4271 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4272 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4273 if (0 != ret_val)
4274 goto error;
4275 }
4276
4277 if (hdd_ctx->config->rx_chain_mask_2g) {
4278 ret_val = sme_cli_set_command(adapter->session_id,
4279 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4280 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4281 if (0 != ret_val)
4282 goto error;
4283 }
4284
4285 if (hdd_ctx->config->tx_chain_mask_5g) {
4286 ret_val = sme_cli_set_command(adapter->session_id,
4287 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4288 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4289 if (0 != ret_val)
4290 goto error;
4291 }
4292
4293 if (hdd_ctx->config->rx_chain_mask_5g) {
4294 ret_val = sme_cli_set_command(adapter->session_id,
4295 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4296 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4297 if (0 != ret_val)
4298 goto error;
4299 }
4300
4301 return 0;
4302
4303error:
4304 hdd_err("WMI PDEV set param failed %d", ret_val);
4305 return -EINVAL;
4306}
4307
4308/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304309 * hdd_set_fw_params() - Set parameters to firmware
4310 * @adapter: HDD adapter
4311 *
4312 * This function Sets various parameters to fw once the
4313 * adapter is started.
4314 *
4315 * Return: 0 on success or errno on failure
4316 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004317int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304318{
4319 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004320 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304321
Dustin Brownfdf17c12018-03-14 12:55:34 -07004322 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304323
4324 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4325 if (!hdd_ctx)
4326 return -EINVAL;
4327
Dustin Brown732ab9c2017-06-15 13:24:09 -07004328 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4329 hdd_debug("FTM Mode is active; nothing to do");
4330 return 0;
4331 }
4332
Jeff Johnson1b780e42017-10-31 14:11:45 -07004333 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304334 WMI_PDEV_PARAM_DTIM_SYNTH,
4335 hdd_ctx->config->enable_lprx, PDEV_CMD);
4336 if (ret) {
4337 hdd_err("Failed to set LPRx");
4338 goto error;
4339 }
4340
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304341
4342 ret = sme_cli_set_command(
4343 adapter->session_id,
4344 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4345 hdd_ctx->config->enable_dtim_selection_diversity,
4346 PDEV_CMD);
4347 if (ret) {
4348 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4349 goto error;
4350 }
4351
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304352 ret = sme_cli_set_command(
4353 adapter->session_id,
4354 WMI_PDEV_PARAM_TX_SCH_DELAY,
4355 hdd_ctx->config->enable_tx_sch_delay,
4356 PDEV_CMD);
4357 if (ret) {
4358 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4359 goto error;
4360 }
4361
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304362 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004363 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304364 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4365 hdd_ctx->config->upper_brssi_thresh);
4366
Jeff Johnson1b780e42017-10-31 14:11:45 -07004367 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304368 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4369 hdd_ctx->config->lower_brssi_thresh);
4370
Jeff Johnson1b780e42017-10-31 14:11:45 -07004371 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304372 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4373 hdd_ctx->config->enable_dtim_1chrx);
4374 }
4375
Dustin Brown732ab9c2017-06-15 13:24:09 -07004376 if (hdd_ctx->config->enable2x2) {
4377 hdd_debug("configuring 2x2 mode fw params");
4378
Jeff Johnson1b780e42017-10-31 14:11:45 -07004379 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004380 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4381 hdd_ctx->config->enable_cck_tx_fir_override,
4382 PDEV_CMD);
4383 if (ret) {
4384 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4385 ret);
4386 goto error;
4387 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004388
4389 if (hdd_configure_chain_mask(adapter))
4390 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004391 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304392#define HDD_DTIM_1CHAIN_RX_ID 0x5
4393#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004394 hdd_debug("configuring 1x1 mode fw params");
4395
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004396 /*
4397 * Disable DTIM 1 chain Rx when in 1x1,
4398 * we are passing two value
4399 * as param_id << 29 | param_value.
4400 * Below param_value = 0(disable)
4401 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004402 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004403 WMI_STA_SMPS_PARAM_CMDID,
4404 HDD_DTIM_1CHAIN_RX_ID <<
4405 HDD_SMPS_PARAM_VALUE_S,
4406 VDEV_CMD);
4407 if (ret) {
4408 hdd_err("DTIM 1 chain set failed %d", ret);
4409 goto error;
4410 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304411
Arun Khandavalli2358d522016-05-16 18:05:37 +05304412#undef HDD_DTIM_1CHAIN_RX_ID
4413#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004414
4415 if (hdd_configure_chain_mask(adapter))
4416 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004417 }
4418
Jeff Johnson1b780e42017-10-31 14:11:45 -07004419 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004420 WMI_PDEV_PARAM_HYST_EN,
4421 hdd_ctx->config->enableMemDeepSleep,
4422 PDEV_CMD);
4423 if (ret) {
4424 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4425 goto error;
4426 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304427
Jeff Johnson1b780e42017-10-31 14:11:45 -07004428 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004429 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4430 hdd_ctx->config->rts_profile,
4431 VDEV_CMD);
4432 if (ret) {
4433 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4434 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304435 }
4436
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004437 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4438
Jeff Johnson1b780e42017-10-31 14:11:45 -07004439 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004440 GEN_VDEV_PARAM_AMSDU,
4441 hdd_ctx->config->max_amsdu_num,
4442 GEN_CMD);
4443 if (ret != 0) {
4444 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4445 goto error;
4446 }
4447
Arun Khandavalli2358d522016-05-16 18:05:37 +05304448 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004449 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004450
Arun Khandavalli2358d522016-05-16 18:05:37 +05304451 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304452
Arun Khandavalli2358d522016-05-16 18:05:37 +05304453error:
4454 return -EINVAL;
4455}
4456
Ryan Hsu07495ea2016-01-21 15:25:39 -08004457/**
4458 * hdd_open_adapter() - open and setup the hdd adatper
4459 * @hdd_ctx: global hdd context
4460 * @session_type: type of the interface to be created
4461 * @iface_name: User-visible name of the interface
4462 * @macAddr: MAC address to assign to the interface
4463 * @name_assign_type: the name of assign type of the netdev
4464 * @rtnl_held: the rtnl lock hold flag
4465 *
4466 * This function open and setup the hdd adpater according to the device
4467 * type request, assign the name, the mac address assigned, and then prepared
4468 * the hdd related parameters, queue, lock and ready to start.
4469 *
4470 * Return: the pointer of hdd adapter, otherwise NULL.
4471 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004472struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004473 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004474 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004475 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004476{
Jeff Johnson9d295242017-08-29 14:39:48 -07004477 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304478 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004479
4480 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4481 /*
4482 * Max limit reached on the number of vdevs configured by the
4483 * host. Return error
4484 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304485 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4486 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004487 return NULL;
4488 }
4489
4490 if (macAddr == NULL) {
4491 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304492 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004493 return NULL;
4494 }
4495 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304496 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304497 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4498 " already exists",
4499 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 return NULL;
4501 }
4502
4503 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004504 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004505 /* Reset locally administered bit if the device mode is STA */
4506 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304507 hdd_info("locally administered bit reset in sta mode: "
4508 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004509 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004510 case QDF_P2P_CLIENT_MODE:
4511 case QDF_P2P_DEVICE_MODE:
4512 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004513 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304514 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004515 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4516 name_assign_type,
4517 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518
4519 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304520 hdd_err("failed to allocate adapter for session %d",
4521 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004522 return NULL;
4523 }
4524
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004525 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004526 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004527 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304529 else if (QDF_MONITOR_MODE == session_type)
4530 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004531 else
4532 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4533
4534 adapter->device_mode = session_type;
4535
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004536
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537 /*
4538 * Workqueue which gets scheduled in IPv4 notification
4539 * callback
4540 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004541 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004542 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004543
4544#ifdef WLAN_NS_OFFLOAD
4545 /*
4546 * Workqueue which gets scheduled in IPv6
4547 * notification callback.
4548 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004549 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550 hdd_ipv6_notifier_work_queue);
4551#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004552 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004553 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004554 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004555
4556 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004557 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004558 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304559 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4560 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304561
Ravi Joshi1a292562017-05-18 16:28:54 -07004562 /* Initialize NAN Data Interface */
4563 if (QDF_NDI_MODE == session_type) {
4564 status = hdd_init_nan_data_mode(adapter);
4565 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004566 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004567 }
4568
Alok Kumarb64650c2018-03-23 17:05:11 +05304569 hdd_nud_init_tracking(adapter);
4570
4571 qdf_mutex_create(&adapter->disconnection_status_lock);
4572
Ravi Joshi1a292562017-05-18 16:28:54 -07004573 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004575 case QDF_P2P_GO_MODE:
4576 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004577 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4578 name_assign_type,
4579 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004580 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004581 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304582 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004583 return NULL;
4584 }
4585
4586 adapter->wdev.iftype =
4587 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004588 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004589 NL80211_IFTYPE_P2P_GO;
4590 adapter->device_mode = session_type;
4591
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004592 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004593 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004594 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004595
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004596 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004597 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304598 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4599 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304600
4601 /*
4602 * Workqueue which gets scheduled in IPv4 notification
4603 * callback
4604 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004605 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304606 hdd_ipv4_notifier_work_queue);
4607
4608#ifdef WLAN_NS_OFFLOAD
4609 /*
4610 * Workqueue which gets scheduled in IPv6
4611 * notification callback.
4612 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004613 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304614 hdd_ipv6_notifier_work_queue);
4615#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004616 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304617 case QDF_FTM_MODE:
4618 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4619 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004620 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304621 if (NULL == adapter) {
4622 hdd_err("Failed to allocate adapter for FTM mode");
4623 return NULL;
4624 }
4625 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4626 adapter->device_mode = session_type;
4627 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004628 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004629 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004630
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304631 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004632 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304633 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304634 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4635 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304636 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004637 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004638 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304639 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004640 return NULL;
4641 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004642
hqueaa33ee2017-05-04 17:56:35 +08004643 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4644
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304645 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004646 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004647 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004648 }
4649
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304650 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651 if (NULL != adapter) {
4652 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4653 adapter = NULL;
4654 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004655
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004656 return NULL;
4657 }
4658
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304659 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004660 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4661 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004663 /* Adapter successfully added. Increment the vdev count */
4664 hdd_ctx->current_intf_count++;
4665
Jeff Johnson5880d792016-08-15 13:32:30 -07004666 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667 hdd_ctx->current_intf_count);
4668
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004669 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004670 }
4671
Rajeev Kumardca5f812016-02-04 17:28:06 -08004672 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004673 hdd_err("Interface %s wow debug_fs init failed",
4674 netdev_name(adapter->dev));
4675
4676 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4677 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004678
4679 return adapter;
4680
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004681err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004682 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304683 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004684
4685 return NULL;
4686}
4687
Nirav Shaheb017be2018-02-15 11:20:58 +05304688#ifdef MSM_PLATFORM
4689static inline
4690void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4691{
4692 cancel_work_sync(&hdd_ctx->bus_bw_work);
4693}
4694#else
4695static inline
4696void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4697{
4698}
4699#endif
4700
Jeff Johnson9d295242017-08-29 14:39:48 -07004701QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004702 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004703{
Dustin Brown920397d2017-12-13 16:27:50 -08004704 /*
4705 * Here we are stopping global bus_bw timer & work per adapter.
4706 *
4707 * The reason is to fix one race condition between
4708 * bus bandwidth work and cleaning up an adapter.
4709 * Under some conditions, it is possible for the bus bandwidth
4710 * work to access a particularly destroyed adapter, leading to
4711 * use-after-free.
4712 */
4713 hdd_debug("wait for bus bw work to flush");
4714 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4715 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004716
Dustin Brown920397d2017-12-13 16:27:50 -08004717 /* cleanup adapter */
4718 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4719 adapter->device_mode);
4720 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4721 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004722
Dustin Brown920397d2017-12-13 16:27:50 -08004723 /* conditionally restart the bw timer */
4724 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004725
Dustin Brown920397d2017-12-13 16:27:50 -08004726 /* Adapter removed. Decrement vdev count */
4727 if (hdd_ctx->current_intf_count != 0)
4728 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004729
Dustin Brown920397d2017-12-13 16:27:50 -08004730 /* Fw will take care incase of concurrency */
4731 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004732}
4733
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004734/**
4735 * hdd_close_all_adapters - Close all open adapters
4736 * @hdd_ctx: Hdd context
4737 * rtnl_held: True if RTNL lock held
4738 *
4739 * Close all open adapters.
4740 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304741 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004742 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004743QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744{
Dustin Brown920397d2017-12-13 16:27:50 -08004745 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304746 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004747
Dustin Brown491d54b2018-03-14 12:39:11 -07004748 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004749
4750 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004751 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4752 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304753 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004754 adapter->mac_addr.bytes);
4755 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4756
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304757 /* Adapter removed. Decrement vdev count */
4758 if (hdd_ctx->current_intf_count != 0)
4759 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004760 }
Dustin Brown920397d2017-12-13 16:27:50 -08004761 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004762
Dustin Browne74003f2018-03-14 12:51:58 -07004763 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004764
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304765 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766}
4767
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004768void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304770 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004771 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004772
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004773 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004774 case QDF_STA_MODE:
4775 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004776 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004777 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004778 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004779 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004780 break;
4781 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004782 case QDF_SAP_MODE:
4783 case QDF_P2P_GO_MODE:
4784 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004785 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004786 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004787 break;
4788 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004789 case QDF_FTM_MODE:
4790 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791 default:
4792 /*
4793 * wlan_hdd_reset_prob_rspies should not have been called
4794 * for these kind of devices
4795 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004796 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004797 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004798 return;
4799 }
4800
Anurag Chouhanc5548422016-02-24 18:33:27 +05304801 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004802 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004803 updateIE.ieBufferlength = 0;
4804 updateIE.pAdditionIEBuffer = NULL;
4805 updateIE.append = true;
4806 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004807 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304809 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004810 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004811 }
4812}
4813
Dustin Browndb2a8be2017-12-20 11:49:56 -08004814QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4815 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004816{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304817 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07004818 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004819 union iwreq_data wrqu;
4820 tSirUpdateIE updateIE;
4821 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304822 tsap_Config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004823
Dustin Brown491d54b2018-03-14 12:39:11 -07004824 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004825
Alok Kumarb64650c2018-03-23 17:05:11 +05304826 hdd_nud_ignore_tracking(adapter, true);
4827 hdd_nud_reset_tracking(adapter);
4828
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004829 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304830 wlan_hdd_netif_queue_control(adapter,
4831 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4832 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004833 /*
4834 * if this is the last active connection check & stop the
4835 * opportunistic timer first
4836 */
4837 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4838 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4839 policy_mgr_convert_device_mode_to_qdf_type(
4840 adapter->device_mode), NULL) == 1)) ||
4841 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4842 policy_mgr_check_and_stop_opportunistic_timer(
4843 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004844 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004845 case QDF_STA_MODE:
4846 case QDF_P2P_CLIENT_MODE:
4847 case QDF_IBSS_MODE:
4848 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004849 case QDF_NDI_MODE:
4850 if ((QDF_NDI_MODE == adapter->device_mode) ||
4851 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004852 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4853 hdd_is_connecting(
4854 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004855 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07004856 roam_profile = hdd_roam_profile(adapter);
4857 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004858 if (QDF_NDI_MODE == adapter->device_mode)
4859 qdf_ret_status = sme_roam_disconnect(
4860 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004861 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004862 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07004863 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004864 eCSR_BSS_TYPE_START_IBSS)
4865 qdf_ret_status = sme_roam_disconnect(
4866 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004867 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004868 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004869 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004870 qdf_ret_status =
4871 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004872 hdd_debug("Send disconnected event to userspace");
4873 wlan_hdd_cfg80211_indicate_disconnect(
4874 adapter->dev, true,
4875 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08004876 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004877 qdf_ret_status = sme_roam_disconnect(
4878 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004879 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004880 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004881 /* success implies disconnect command got
4882 * queued up successfully
4883 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004884 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4885 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004886 rc = wait_for_completion_timeout(
4887 &adapter->disconnect_comp_var,
4888 msecs_to_jiffies
4889 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004890 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004891 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004892 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004893 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4894 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004895 memset(&wrqu, '\0', sizeof(wrqu));
4896 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4897 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4898 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4899 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304900 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004901 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004902
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304903 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304904 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004905
4906#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004907 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004908#endif
4909
4910 hdd_deregister_tx_flow_control(adapter);
4911
4912#ifdef WLAN_NS_OFFLOAD
4913#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004914 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004915#endif
4916#endif
4917
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304918 if (adapter->device_mode == QDF_STA_MODE)
4919 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4920 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004921
4922 if (wlan_hdd_try_disconnect(adapter)) {
4923 hdd_err("Error: Can't disconnect adapter");
4924 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004925 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004926
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304927 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004928 break;
4929
Rajeev Kumar3b906202018-02-01 10:55:14 -08004930 case QDF_MONITOR_MODE:
4931 wlan_hdd_scan_abort(adapter);
4932 hdd_deregister_tx_flow_control(adapter);
4933 hdd_vdev_destroy(adapter);
4934 break;
4935
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004936 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004937 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304938 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304939 sap_config = &adapter->session.ap.sap_config;
4940 if (sap_config)
4941 wlansap_reset_sap_config_add_ie(sap_config,
4942 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05304943 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004944 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004945
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004946 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004947 if (QDF_SAP_MODE == adapter->device_mode) {
4948 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4949 cds_flush_delayed_work(
4950 &adapter->acs_pending_work);
4951 clear_bit(ACS_PENDING, &adapter->event_flags);
4952 }
4953 }
Krunal Soni22208392017-09-29 18:10:34 -07004954 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004955
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004956 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05304957 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004958 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004959 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004960 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4961
4962 hdd_deregister_tx_flow_control(adapter);
4963
Kapil Guptac1224bf2017-06-22 21:22:40 +05304964 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004965 mutex_lock(&hdd_ctx->sap_lock);
4966 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304967 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304968 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004969
4970 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004971 status = wlansap_stop_bss(
4972 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004973
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304974 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004975 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004976 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304977 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304978 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304979 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304980 qdf_wait_for_event_completion(
4981 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004982 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004983
Anurag Chouhance0dc992016-02-16 18:18:03 +05304984 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004985 hdd_err("failure waiting for wlansap_stop_bss %d",
4986 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004987 }
4988 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004989 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004990 }
4991 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004992 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4993 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004994 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07004995 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05304996 adapter->device_mode,
4997 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998
Anurag Chouhanc5548422016-02-24 18:33:27 +05304999 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005000 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005001 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002 updateIE.ieBufferlength = 0;
5003 updateIE.pAdditionIEBuffer = NULL;
5004 updateIE.append = false;
5005 updateIE.notify = false;
5006 /* Probe bcn reset */
5007 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5008 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305009 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005010 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005011 }
5012 /* Assoc resp reset */
5013 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5014 &updateIE,
5015 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305016 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005017 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005018 }
5019 /* Reset WNI_CFG_PROBE_RSP Flags */
5020 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005021 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07005022 qdf_mem_free(adapter->session.ap.beacon);
5023 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305024 /*
5025 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5026 */
5027 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5028 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5029
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305030#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005031 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305032#endif
5033
5034#ifdef WLAN_NS_OFFLOAD
5035#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005036 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305037#endif
5038#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005039
5040 hdd_vdev_destroy(adapter);
5041
Krunal Sonib51eec72017-11-20 21:53:01 -08005042 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005043 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005044 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005045 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005046 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005047 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005048 hdd_deregister_tx_flow_control(adapter);
5049 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050 break;
5051 default:
5052 break;
5053 }
5054
Dustin Brown04348372017-12-14 16:13:39 -08005055 if (adapter->scan_info.default_scan_ies) {
5056 qdf_mem_free(adapter->scan_info.default_scan_ies);
5057 adapter->scan_info.default_scan_ies = NULL;
5058 }
5059
Dustin Browne74003f2018-03-14 12:51:58 -07005060 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005061
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305062 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005063}
5064
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305065/**
5066 * hdd_deinit_all_adapters - deinit all adapters
5067 * @hdd_ctx: HDD context
5068 * @rtnl_held: True if RTNL lock held
5069 *
5070 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005071void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305072{
Jeff Johnson9d295242017-08-29 14:39:48 -07005073 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305074
Dustin Brown491d54b2018-03-14 12:39:11 -07005075 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305076
Dustin Brown920397d2017-12-13 16:27:50 -08005077 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305078 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305079
Dustin Browne74003f2018-03-14 12:51:58 -07005080 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305081}
5082
Dustin Browndb2a8be2017-12-20 11:49:56 -08005083QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084{
Jeff Johnson9d295242017-08-29 14:39:48 -07005085 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005086
Dustin Brown491d54b2018-03-14 12:39:11 -07005087 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005088
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305089 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5090
Dustin Brown920397d2017-12-13 16:27:50 -08005091 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005092 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093
Dustin Browne74003f2018-03-14 12:51:58 -07005094 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005095
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305096 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005097}
5098
Paul Zhang84fa9382017-11-10 21:18:21 +08005099static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5100 struct hdd_adapter *adapter)
5101{
5102 switch (adapter->device_mode) {
5103 case QDF_STA_MODE:
5104 case QDF_P2P_CLIENT_MODE:
5105 case QDF_IBSS_MODE:
5106 case QDF_P2P_DEVICE_MODE:
5107 case QDF_NDI_MODE:
5108 wlan_hdd_scan_abort(adapter);
5109 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5110 if (adapter->device_mode == QDF_STA_MODE)
5111 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5112 adapter->dev);
5113 break;
5114 case QDF_P2P_GO_MODE:
5115 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5116 break;
5117 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305118 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005119 wlan_hdd_undo_acs(adapter);
5120 break;
5121 default:
5122 break;
5123 }
5124}
5125
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005126QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005127{
Jeff Johnson9d295242017-08-29 14:39:48 -07005128 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005129 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005130 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005131 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132
Dustin Brown491d54b2018-03-14 12:39:11 -07005133 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005134
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305135 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5136
Dustin Brown920397d2017-12-13 16:27:50 -08005137 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005138 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5139 hdd_device_mode_to_string(adapter->device_mode),
5140 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305141
5142 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005143 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305144 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005145 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005146 adapter->session.station.hdd_reassoc_scenario = false;
5147 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305148
Arun Khandavallicc544b32017-01-30 19:52:16 +05305149 if (hdd_ctx->config->sap_internal_restart &&
5150 adapter->device_mode == QDF_SAP_MODE) {
5151 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305152 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305153 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005154 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005155 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005156 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005157 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5158 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305159 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305160 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005161 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005162 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163
Paul Zhang84fa9382017-11-10 21:18:21 +08005164 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005165
5166 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005167 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005168 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005169 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305170 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005171 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5172 hdd_wmm_adapter_close(adapter);
5173 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5174 }
5175
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305176 if (adapter->device_mode == QDF_STA_MODE)
5177 hdd_clear_fils_connection_info(adapter);
5178
Wu Gao3545e642017-07-14 19:24:41 +08005179 if (adapter->device_mode == QDF_SAP_MODE) {
5180 /*
5181 * If adapter is SAP, set session ID to invalid
5182 * since SAP session will be cleanup during SSR.
5183 */
Wu Gao36717432016-11-21 15:09:48 +08005184 wlansap_set_invalid_session(
5185 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5186
Wu Gao3545e642017-07-14 19:24:41 +08005187 wlansap_cleanup_cac_timer(
5188 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5189 }
5190
Yue Ma42654682018-01-11 16:55:24 -08005191 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005192 if (adapter->device_mode == QDF_STA_MODE ||
5193 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005194 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005195 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005196 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005197
5198 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5199 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005200 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5201 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5202 if (adapter->sta_info[sta_id].in_use) {
5203 hdd_debug("[SSR] deregister STA with ID %d",
5204 sta_id);
5205 hdd_softap_deregister_sta(adapter,
5206 sta_id);
5207 adapter->sta_info[sta_id].in_use = 0;
5208 }
5209 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005210 }
5211
Alok Kumarb64650c2018-03-23 17:05:11 +05305212 hdd_nud_reset_tracking(adapter);
5213 hdd_nud_ignore_tracking(adapter, true);
5214 hdd_set_disconnect_status(adapter, false);
5215
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005216 hdd_softap_deinit_tx_rx(adapter);
5217
Yue Maf9782842017-05-08 12:49:49 -07005218 /* Destroy vdev which will be recreated during reinit. */
5219 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005220 }
5221
Dustin Browne74003f2018-03-14 12:51:58 -07005222 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305224 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225}
5226
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005227bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305228{
Dustin Brown920397d2017-12-13 16:27:50 -08005229 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305230 bool close_modules = true;
5231
Arun Khandavalliba479c42017-07-26 21:29:40 +05305232 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5233 hdd_info("FTM mode, don't close the module");
5234 return false;
5235 }
5236
Dustin Brown920397d2017-12-13 16:27:50 -08005237 hdd_for_each_adapter(hdd_ctx, adapter) {
5238 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5239 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005240 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305241 close_modules = false;
5242 break;
5243 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305244 }
5245
5246 return close_modules;
5247}
5248
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305249bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305250{
5251 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5252 return true;
5253 else
5254 return false;
5255}
5256
Anurag Chouhanc4092922016-09-08 15:56:11 +05305257#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005258 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305259struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5260 struct ieee80211_channel *channel,
5261 const u8 *bssid, const u8 *ssid,
5262 size_t ssid_len)
5263{
5264 return cfg80211_get_bss(wiphy, channel, bssid,
5265 ssid, ssid_len,
5266 WLAN_CAPABILITY_ESS,
5267 WLAN_CAPABILITY_ESS);
5268}
5269#else
5270struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5271 struct ieee80211_channel *channel,
5272 const u8 *bssid, const u8 *ssid,
5273 size_t ssid_len)
5274{
5275 return cfg80211_get_bss(wiphy, channel, bssid,
5276 ssid, ssid_len,
5277 IEEE80211_BSS_TYPE_ESS,
5278 IEEE80211_PRIVACY_ANY);
5279}
5280#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305281
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305282#if defined CFG80211_CONNECT_BSS || \
5283 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305284#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305285 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305286/**
5287 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5288 * @timeout_reason: reason for connect timeout
5289 *
5290 * This function is used to convert host timeout
5291 * reason enum to kernel specific enum.
5292 *
5293 * Return: nl timeout enum
5294 */
5295static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5296 tSirResultCodes timeout_reason)
5297{
5298 switch (timeout_reason) {
5299 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5300 return NL80211_TIMEOUT_SCAN;
5301 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5302 return NL80211_TIMEOUT_AUTH;
5303 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5304 return NL80211_TIMEOUT_ASSOC;
5305 default:
5306 return NL80211_TIMEOUT_UNSPECIFIED;
5307 }
5308}
5309
5310/**
5311 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5312 * @dev: network device
5313 * @bssid: bssid to which we want to associate
5314 * @timeout_reason: reason for connect timeout
5315 *
5316 * This API is used to send connection timeout reason to supplicant
5317 *
5318 * Return: void
5319 */
5320static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5321 const u8 *bssid,
5322 tSirResultCodes timeout_reason)
5323{
5324 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005325
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305326 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5327
5328 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5329 nl_timeout_reason);
5330}
5331
5332/**
5333 * __hdd_connect_bss() - API to send connection status to supplicant
5334 * @dev: network device
5335 * @bssid: bssid to which we want to associate
5336 * @req_ie: Request Information Element
5337 * @req_ie_len: len of the req IE
5338 * @resp_ie: Response IE
5339 * @resp_ie_len: len of ht response IE
5340 * @status: status
5341 * @gfp: Kernel Flag
5342 * @timeout_reason: reason for connect timeout
5343 *
5344 * Return: void
5345 */
5346static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5347 struct cfg80211_bss *bss, const u8 *req_ie,
5348 size_t req_ie_len, const u8 *resp_ie,
5349 size_t resp_ie_len, int status, gfp_t gfp,
5350 tSirResultCodes timeout_reason)
5351{
5352 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005353
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305354 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5355
5356 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5357 resp_ie, resp_ie_len, status, gfp,
5358 nl_timeout_reason);
5359}
5360#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305361#if defined CFG80211_CONNECT_TIMEOUT || \
5362 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305363static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5364 const u8 *bssid,
5365 tSirResultCodes timeout_reason)
5366{
5367 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5368}
5369#endif
5370
5371static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5372 struct cfg80211_bss *bss, const u8 *req_ie,
5373 size_t req_ie_len, const u8 *resp_ie,
5374 size_t resp_ie_len, int status, gfp_t gfp,
5375 tSirResultCodes timeout_reason)
5376{
5377 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5378 resp_ie, resp_ie_len, status, gfp);
5379}
5380#endif
5381
Abhishek Singha84d3952016-09-13 13:45:05 +05305382/**
5383 * hdd_connect_bss() - API to send connection status to supplicant
5384 * @dev: network device
5385 * @bssid: bssid to which we want to associate
5386 * @req_ie: Request Information Element
5387 * @req_ie_len: len of the req IE
5388 * @resp_ie: Response IE
5389 * @resp_ie_len: len of ht response IE
5390 * @status: status
5391 * @gfp: Kernel Flag
5392 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305393 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305394 *
5395 * The API is a wrapper to send connection status to supplicant
5396 *
5397 * Return: Void
5398 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305399#if defined CFG80211_CONNECT_TIMEOUT || \
5400 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305401static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5402 struct cfg80211_bss *bss, const u8 *req_ie,
5403 size_t req_ie_len, const u8 *resp_ie,
5404 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305405 bool connect_timeout,
5406 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305407{
5408 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305409 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305410 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305411 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5412 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305413}
5414#else
5415static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5416 struct cfg80211_bss *bss, const u8 *req_ie,
5417 size_t req_ie_len, const u8 *resp_ie,
5418 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305419 bool connect_timeout,
5420 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305421{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305422 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5423 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305424}
5425#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305426
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305427#if defined(WLAN_FEATURE_FILS_SK)
5428#if defined(CFG80211_CONNECT_DONE) || \
5429 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5430#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5431 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305432/**
5433 * hdd_populate_fils_params() - Populate FILS keys to connect response
5434 * @fils_params: connect response to supplicant
5435 * @fils_kek: FILS kek
5436 * @fils_kek_len: FILS kek length
5437 * @pmk: FILS PMK
5438 * @pmk_len: FILS PMK length
5439 * @pmkid: PMKID
5440 * @fils_seq_num: FILS Seq number
5441 *
5442 * Return: None
5443 */
5444static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5445 *fils_params, const uint8_t *fils_kek,
5446 size_t fils_kek_len, const uint8_t *pmk,
5447 size_t pmk_len, const uint8_t *pmkid,
5448 uint16_t fils_seq_num)
5449{
5450 /* Increament seq number to be used for next FILS */
5451 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5452 fils_params->update_erp_next_seq_num = true;
5453 fils_params->fils_kek = fils_kek;
5454 fils_params->fils_kek_len = fils_kek_len;
5455 fils_params->pmk = pmk;
5456 fils_params->pmk_len = pmk_len;
5457 fils_params->pmkid = pmkid;
5458}
5459#else
5460static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5461 *fils_params, const uint8_t
5462 *fils_kek, size_t fils_kek_len,
5463 const uint8_t *pmk, size_t pmk_len,
5464 const uint8_t *pmkid,
5465 uint16_t fils_seq_num)
5466{ }
5467#endif
5468
Jeff Johnson172237b2017-11-07 15:32:59 -08005469void hdd_update_hlp_info(struct net_device *dev,
5470 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305471{
5472 struct sk_buff *skb;
5473 uint16_t skb_len;
5474 struct llc_snap_hdr_t *llc_hdr;
5475 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305476 uint8_t *hlp_data;
5477 uint16_t hlp_data_len;
5478 struct fils_join_rsp_params *roam_fils_params
5479 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305480 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5481
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305482 if (!roam_fils_params) {
5483 hdd_err("FILS Roam Param NULL");
5484 return;
5485 }
5486
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005487 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305488 hdd_err("FILS HLP Data NULL, len %d",
5489 roam_fils_params->hlp_data_len);
5490 return;
5491 }
5492
5493 hlp_data = roam_fils_params->hlp_data;
5494 hlp_data_len = roam_fils_params->hlp_data_len;
5495
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305496 /* Calculate skb length */
5497 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5498 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5499 if (skb == NULL) {
5500 hdd_err("HLP packet nbuf alloc fails");
5501 return;
5502 }
5503
5504 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5505 QDF_MAC_ADDR_SIZE);
5506 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5507 QDF_MAC_ADDR_SIZE);
5508
5509 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5510 if (IS_SNAP(llc_hdr)) {
5511 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5512 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5513 }
5514
5515 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5516
5517 /*
5518 * This HLP packet is formed from HLP info encapsulated
5519 * in assoc response frame which is AEAD encrypted.
5520 * Hence, this checksum validation can be set unnecessary.
5521 * i.e. network layer need not worry about checksum.
5522 */
5523 skb->ip_summed = CHECKSUM_UNNECESSARY;
5524
5525 status = hdd_rx_packet_cbk(padapter, skb);
5526 if (QDF_IS_STATUS_ERROR(status)) {
5527 hdd_err("Sending HLP packet fails");
5528 return;
5529 }
5530 hdd_debug("send HLP packet to netif successfully");
5531}
5532
5533/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305534 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5535 * @dev: network device
5536 * @bssid: bssid to which we want to associate
5537 * @bss: cfg80211 bss info
5538 * @roam_info: information about connected bss
5539 * @req_ie: Request Information Element
5540 * @req_ie_len: len of the req IE
5541 * @resp_ie: Response IE
5542 * @resp_ie_len: len of ht response IE
5543 * @status: status
5544 * @gfp: allocation flags
5545 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5546 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305547 *
5548 * This API is used as wrapper to send FILS key/sequence number
5549 * params etc. to supplicant in case of FILS connection
5550 *
5551 * Return: None
5552 */
5553static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005554 struct cfg80211_bss *bss,
5555 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305556 const u8 *req_ie, size_t req_ie_len,
5557 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005558 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305559 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305560{
5561 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305562 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5563 struct fils_join_rsp_params *roam_fils_params =
5564 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005565
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305566 qdf_mem_zero(&fils_params, sizeof(fils_params));
5567
5568 if (!roam_fils_params) {
5569 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5570 } else {
5571 fils_params.status = status;
5572 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005573 fils_params.timeout_reason =
5574 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305575 fils_params.req_ie = req_ie;
5576 fils_params.req_ie_len = req_ie_len;
5577 fils_params.resp_ie = resp_ie;
5578 fils_params.resp_ie_len = resp_ie_len;
5579 fils_params.bss = bss;
5580 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5581 roam_fils_params->kek_len,
5582 roam_fils_params->fils_pmk,
5583 roam_fils_params->fils_pmk_len,
5584 roam_fils_params->fils_pmkid,
5585 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305586 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305587 }
5588 hdd_debug("FILS indicate connect status %d seq no %d",
5589 fils_params.status,
5590 fils_params.fils_erp_next_seq_num);
5591
5592 cfg80211_connect_done(dev, &fils_params, gfp);
5593
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305594 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305595 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305596
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305597 /* Clear all the FILS key info */
5598 if (roam_fils_params && roam_fils_params->fils_pmk)
5599 qdf_mem_free(roam_fils_params->fils_pmk);
5600 if (roam_fils_params)
5601 qdf_mem_free(roam_fils_params);
5602 roam_info->fils_join_rsp = NULL;
5603}
5604#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005605static inline void
5606hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005607 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005608 const u8 *req_ie, size_t req_ie_len,
5609 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5610 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305611 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305612{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305613#endif
5614#endif
5615
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305616#if defined(WLAN_FEATURE_FILS_SK) && \
5617 (defined(CFG80211_CONNECT_DONE) || \
5618 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305619/**
5620 * hdd_fils_update_connect_results() - API to send fils connection status to
5621 * supplicant.
5622 * @dev: network device
5623 * @bssid: bssid to which we want to associate
5624 * @bss: cfg80211 bss info
5625 * @roam_info: information about connected bss
5626 * @req_ie: Request Information Element
5627 * @req_ie_len: len of the req IE
5628 * @resp_ie: Response IE
5629 * @resp_ie_len: len of ht response IE
5630 * @status: status
5631 * @gfp: allocation flags
5632 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5633 * @timeout_reason: reason for connect timeout
5634 *
5635 * The API is a wrapper to send connection status to supplicant
5636 *
5637 * Return: 0 if success else failure
5638 */
5639static int hdd_fils_update_connect_results(struct net_device *dev,
5640 const u8 *bssid,
5641 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005642 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305643 size_t req_ie_len, const u8 *resp_ie,
5644 size_t resp_ie_len, u16 status, gfp_t gfp,
5645 bool connect_timeout,
5646 tSirResultCodes timeout_reason)
5647{
Dustin Brown491d54b2018-03-14 12:39:11 -07005648 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305649 if (!roam_info || !roam_info->is_fils_connection)
5650 return -EINVAL;
5651
5652 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5653 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305654 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305655 return 0;
5656}
5657#else
5658static inline int hdd_fils_update_connect_results(struct net_device *dev,
5659 const u8 *bssid,
5660 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005661 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305662 size_t req_ie_len, const u8 *resp_ie,
5663 size_t resp_ie_len, u16 status, gfp_t gfp,
5664 bool connect_timeout,
5665 tSirResultCodes timeout_reason)
5666{
5667 return -EINVAL;
5668}
5669#endif
5670
Anurag Chouhanc4092922016-09-08 15:56:11 +05305671/**
5672 * hdd_connect_result() - API to send connection status to supplicant
5673 * @dev: network device
5674 * @bssid: bssid to which we want to associate
5675 * @roam_info: information about connected bss
5676 * @req_ie: Request Information Element
5677 * @req_ie_len: len of the req IE
5678 * @resp_ie: Response IE
5679 * @resp_ie_len: len of ht response IE
5680 * @status: status
5681 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305682 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305683 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305684 *
5685 * The API is a wrapper to send connection status to supplicant
5686 * and allow runtime suspend
5687 *
5688 * Return: Void
5689 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305690void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005691 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305692 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305693 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305694 bool connect_timeout,
5695 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305696{
Jeff Johnson9d295242017-08-29 14:39:48 -07005697 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305698 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005699 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305700
5701 if (WLAN_STATUS_SUCCESS == status) {
5702 struct ieee80211_channel *chan;
5703 int freq;
5704 int chan_no = roam_info->pBssDesc->channelId;
5705
5706 if (chan_no <= 14)
5707 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005708 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305709 else
5710 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005711 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305712
5713 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5714 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5715 roam_info->u.pConnectedProfile->SSID.ssId,
5716 roam_info->u.pConnectedProfile->SSID.length);
5717 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305718
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305719 if (hdd_fils_update_connect_results(dev, bssid, bss,
5720 roam_info, req_ie, req_ie_len, resp_ie,
5721 resp_ie_len, status, gfp, connect_timeout,
5722 timeout_reason) != 0) {
5723 hdd_connect_bss(dev, bssid, bss, req_ie,
5724 req_ie_len, resp_ie, resp_ie_len,
5725 status, gfp, connect_timeout, timeout_reason);
5726 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305727
Jingxiang Geb49aa302018-01-17 20:54:15 +08005728 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005729 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305730}
5731#else
5732void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005733 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305734 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305735 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305736 bool connect_timeout,
5737 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305738{
Jeff Johnson9d295242017-08-29 14:39:48 -07005739 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005740 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305741
Anurag Chouhanc4092922016-09-08 15:56:11 +05305742 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5743 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005744
Jingxiang Geb49aa302018-01-17 20:54:15 +08005745 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005746 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305747}
5748#endif
5749
5750
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005751QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005752{
Jeff Johnson9d295242017-08-29 14:39:48 -07005753 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005754#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005755 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005756#endif
5757 eConnectionState connState;
5758
Dustin Brown491d54b2018-03-14 12:39:11 -07005759 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005760
Dustin Brown920397d2017-12-13 16:27:50 -08005761 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305762 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005763 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305764
Yue Ma42654682018-01-11 16:55:24 -08005765 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5766 hdd_device_mode_to_string(adapter->device_mode),
5767 adapter->device_mode);
5768
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005769 hdd_wmm_init(adapter);
5770
5771 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005772 case QDF_STA_MODE:
5773 case QDF_P2P_CLIENT_MODE:
5774 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005775
5776 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5777 ->conn_info.connState;
5778
Krunal Sonib51eec72017-11-20 21:53:01 -08005779 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005780 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005781 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005782
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005783 /* Indicate disconnect event to supplicant
5784 * if associated previously
5785 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005786 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005787 eConnectionState_IbssConnected == connState ||
5788 eConnectionState_NotConnected == connState ||
5789 eConnectionState_IbssDisconnected == connState ||
5790 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005791 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005792
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005793 memset(&wrqu, '\0', sizeof(wrqu));
5794 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5795 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5796 wireless_send_event(adapter->dev, SIOCGIWAP,
5797 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005798 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005799 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005800
5801 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305802 wlan_hdd_cfg80211_indicate_disconnect(
5803 adapter->dev, false,
5804 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805 } else if (eConnectionState_Connecting == connState) {
5806 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005807 * Indicate connect failure to supplicant if we
5808 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005809 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305810 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305811 NULL, 0, NULL, 0,
5812 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005813 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005814 }
5815
5816 hdd_register_tx_flow_control(adapter,
5817 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005818 hdd_tx_resume_cb,
5819 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005820
Alok Kumarb64650c2018-03-23 17:05:11 +05305821 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005822 break;
5823
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005824 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005825 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005826 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305827
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005828 break;
5829
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005830 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005831#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005832 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005833 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5834#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005835 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005836 /* event supplicant to restart */
5837 cfg80211_del_sta(adapter->dev,
5838 (const u8 *)&bcastMac.bytes[0],
5839 GFP_KERNEL);
5840#endif
5841 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305842 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005843 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305844 hdd_set_mon_rx_cb(adapter->dev);
5845 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5846 adapter->mon_bandwidth);
5847 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005848 default:
5849 break;
5850 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005851 /*
5852 * Action frame registered in one adapter which will
5853 * applicable to all interfaces
5854 */
5855 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005856 }
5857
Dustin Browne74003f2018-03-14 12:51:58 -07005858 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005859
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305860 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005861}
5862
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005863QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005864 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005865{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305866 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005867 qdf_list_node_t *node;
5868
5869 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005870
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005871 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005872 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005873 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005874
5875 if (QDF_IS_STATUS_ERROR(status))
5876 return status;
5877
5878 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5879
5880 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005881}
5882
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005883QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005884 struct hdd_adapter *current_adapter,
5885 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005886{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305887 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005888 qdf_list_node_t *node;
5889
5890 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005891
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005892 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005893 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005894 &current_adapter->node,
5895 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005896 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005897
5898 if (QDF_IS_STATUS_ERROR(status))
5899 return status;
5900
5901 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5902
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005903 return status;
5904}
5905
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005906QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005907 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005908{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305909 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005910
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005911 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005912 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005913 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005914
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005915 return status;
5916}
5917
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005918QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005919 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005920{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305921 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005922 qdf_list_node_t *node;
5923
5924 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005925
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005926 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005927 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005928 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005929
5930 if (QDF_IS_STATUS_ERROR(status))
5931 return status;
5932
5933 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005935 return status;
5936}
5937
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005938QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005939 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005940{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305941 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005942
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005943 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005944 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005945 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005947 return status;
5948}
5949
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005950QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005951 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005952{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305953 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005954
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005955 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005956 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005957 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005958
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005959 return status;
5960}
5961
Jeff Johnson9d295242017-08-29 14:39:48 -07005962struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005963 tSirMacAddr macAddr)
5964{
Jeff Johnson9d295242017-08-29 14:39:48 -07005965 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005966
Dustin Brown920397d2017-12-13 16:27:50 -08005967 hdd_for_each_adapter(hdd_ctx, adapter) {
5968 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5969 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005970 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005971 }
5972
5973 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005974}
5975
Jeff Johnson9d295242017-08-29 14:39:48 -07005976struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005977 uint32_t vdev_id)
5978{
Jeff Johnson9d295242017-08-29 14:39:48 -07005979 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980
Dustin Brown920397d2017-12-13 16:27:50 -08005981 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005982 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005983 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005984 }
5985
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005986 return NULL;
5987}
5988
Abhishek Singh7996eb72015-12-30 17:24:02 +05305989/**
5990 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5991 * the sessionid
5992 * @hdd_ctx: hdd context.
5993 * @sme_session_id: sme session is for the adapter to get.
5994 *
5995 * This function is used to get the adapter with provided session id
5996 *
5997 * Return: adapter pointer if found
5998 *
5999 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006000struct hdd_adapter *
6001hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6002 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306003{
Jeff Johnson9d295242017-08-29 14:39:48 -07006004 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306005
Dustin Brown920397d2017-12-13 16:27:50 -08006006 hdd_for_each_adapter(hdd_ctx, adapter) {
6007 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306008 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306009 }
Dustin Brown920397d2017-12-13 16:27:50 -08006010
Abhishek Singh7996eb72015-12-30 17:24:02 +05306011 return NULL;
6012}
6013
Jeff Johnson9d295242017-08-29 14:39:48 -07006014struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006015 const char *iface_name)
6016{
Jeff Johnson9d295242017-08-29 14:39:48 -07006017 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006018
Dustin Brown920397d2017-12-13 16:27:50 -08006019 hdd_for_each_adapter(hdd_ctx, adapter) {
6020 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006021 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006022 }
Dustin Brown920397d2017-12-13 16:27:50 -08006023
Naveen Rawat4edb6822017-04-12 10:09:17 -07006024 return NULL;
6025}
6026
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006027/**
6028 * hdd_get_adapter() - to get adapter matching the mode
6029 * @hdd_ctx: hdd context
6030 * @mode: adapter mode
6031 *
6032 * This routine will return the pointer to adapter matching
6033 * with the passed mode.
6034 *
6035 * Return: pointer to adapter or null
6036 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006037struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006038 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006039{
Jeff Johnson9d295242017-08-29 14:39:48 -07006040 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006041
Dustin Brown920397d2017-12-13 16:27:50 -08006042 hdd_for_each_adapter(hdd_ctx, adapter) {
6043 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006045 }
6046
6047 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006048}
6049
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306050enum tQDF_ADAPTER_MODE hdd_get_device_mode(uint32_t session_id)
6051{
6052 struct hdd_context *hdd_ctx;
6053 struct hdd_adapter *adapter;
6054
6055 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6056 if (!hdd_ctx) {
6057 hdd_err("Invalid HDD context");
6058 return QDF_MAX_NO_OF_MODE;
6059 }
6060
6061 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6062 if (!adapter) {
6063 hdd_err("Invalid HDD adapter");
6064 return QDF_MAX_NO_OF_MODE;
6065 }
6066
6067 return adapter->device_mode;
6068}
6069
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006070/**
6071 * hdd_get_operating_channel() - return operating channel of the device mode
6072 * @hdd_ctx: Pointer to the HDD context.
6073 * @mode: Device mode for which operating channel is required.
6074 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006075 * QDF_STA_MODE,
6076 * QDF_P2P_CLIENT_MODE,
6077 * QDF_SAP_MODE,
6078 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006079 *
6080 * This API returns the operating channel of the requested device mode
6081 *
6082 * Return: channel number. "0" id the requested device is not found OR it is
6083 * not connected.
6084 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006085uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006086 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006087{
Jeff Johnson9d295242017-08-29 14:39:48 -07006088 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006089 uint8_t operatingChannel = 0;
6090
Dustin Brown920397d2017-12-13 16:27:50 -08006091 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006092 if (mode == adapter->device_mode) {
6093 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006094 case QDF_STA_MODE:
6095 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006096 if (hdd_conn_is_connected
6097 (WLAN_HDD_GET_STATION_CTX_PTR
6098 (adapter))) {
6099 operatingChannel =
6100 (WLAN_HDD_GET_STATION_CTX_PTR
6101 (adapter))->conn_info.
6102 operationChannel;
6103 }
6104 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006105 case QDF_SAP_MODE:
6106 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006107 /* softap connection info */
6108 if (test_bit
6109 (SOFTAP_BSS_STARTED,
6110 &adapter->event_flags))
6111 operatingChannel =
6112 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006113 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006114 break;
6115 default:
6116 break;
6117 }
6118
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006119 /* Found the device of interest. break the loop */
6120 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006121 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006122 }
Dustin Brown920397d2017-12-13 16:27:50 -08006123
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006124 return operatingChannel;
6125}
6126
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006127static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006128 hdd_ctx)
6129{
Jeff Johnson9d295242017-08-29 14:39:48 -07006130 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006131
Dustin Brown491d54b2018-03-14 12:39:11 -07006132 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006133
Dustin Brown920397d2017-12-13 16:27:50 -08006134 hdd_for_each_adapter(hdd_ctx, adapter) {
6135 if (adapter->device_mode == QDF_STA_MODE ||
6136 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6137 adapter->device_mode == QDF_IBSS_MODE ||
6138 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6139 adapter->device_mode == QDF_SAP_MODE ||
6140 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006141 wlan_hdd_cfg80211_deregister_frames(adapter);
6142 hdd_unregister_wext(adapter->dev);
6143 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006144 }
6145
Dustin Browne74003f2018-03-14 12:51:58 -07006146 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006147
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306148 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006149}
6150
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006151QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006152{
Jeff Johnson9d295242017-08-29 14:39:48 -07006153 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006154
Dustin Brown491d54b2018-03-14 12:39:11 -07006155 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006156
Dustin Brown920397d2017-12-13 16:27:50 -08006157 hdd_for_each_adapter(hdd_ctx, adapter) {
6158 if (adapter->device_mode == QDF_STA_MODE ||
6159 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6160 adapter->device_mode == QDF_IBSS_MODE ||
6161 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6162 adapter->device_mode == QDF_SAP_MODE ||
6163 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006164 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006165 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306166 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006167 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168 }
6169
Dustin Browne74003f2018-03-14 12:51:58 -07006170 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006171
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306172 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173}
6174
Dustin Brownf27bce82016-11-03 12:52:27 -07006175/**
6176 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6177 * adapters
6178 * @hdd_ctx: The HDD context containing the adapters to operate on
6179 *
6180 * return: QDF_STATUS_SUCCESS
6181 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006182static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006183{
Jeff Johnson9d295242017-08-29 14:39:48 -07006184 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006185 int err;
6186
Dustin Brown491d54b2018-03-14 12:39:11 -07006187 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006188
Dustin Brown920397d2017-12-13 16:27:50 -08006189 hdd_for_each_adapter(hdd_ctx, adapter) {
6190 if (adapter->device_mode == QDF_STA_MODE ||
6191 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6192 adapter->device_mode == QDF_IBSS_MODE ||
6193 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6194 adapter->device_mode == QDF_SAP_MODE ||
6195 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006196 err = wlan_hdd_sched_scan_stop(adapter->dev);
6197 if (err)
6198 hdd_err("Unable to stop scheduled scan");
6199 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006200 }
6201
Dustin Browne74003f2018-03-14 12:51:58 -07006202 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006203
6204 return QDF_STATUS_SUCCESS;
6205}
6206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006207#ifdef WLAN_NS_OFFLOAD
6208/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006209 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006210 * @hdd_ctx: Pointer to hdd context
6211 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006212 * Unregister for IPv6 address change notifications.
6213 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006214 * Return: None
6215 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006216static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006217{
6218 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006219}
6220
6221/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006222 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006223 * @hdd_ctx: Pointer to hdd context
6224 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006225 * Register for IPv6 address change notifications.
6226 *
6227 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006228 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006229static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006230{
6231 int ret;
6232
6233 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6234 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006235 if (ret) {
6236 hdd_err("Failed to register IPv6 notifier: %d", ret);
6237 goto out;
6238 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006239
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006240 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006241out:
6242 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006243}
6244#else
6245/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006246 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247 * @hdd_ctx: Pointer to hdd context
6248 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006249 * Unregister for IPv6 address change notifications.
6250 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251 * Return: None
6252 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006253static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254{
6255}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006256
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006257/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006258 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006259 * @hdd_ctx: Pointer to hdd context
6260 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006261 * Register for IPv6 address change notifications.
6262 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006263 * Return: None
6264 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006265static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006266{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006267 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006268}
6269#endif
6270
Alok Kumarb64650c2018-03-23 17:05:11 +05306271void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6272{
6273 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6274 adapter->disconnection_in_progress = status;
6275 qdf_mutex_release(&adapter->disconnection_status_lock);
6276 hdd_debug("setting disconnection status: %d", status);
6277}
6278
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006280 * hdd_register_notifiers - Register netdev notifiers.
6281 * @hdd_ctx: HDD context
6282 *
6283 * Register netdev notifiers like IPv4 and IPv6.
6284 *
6285 * Return: 0 on success and errno on failure
6286 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006287static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006288{
6289 int ret;
6290
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006291 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6292 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306293 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006294
6295 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6296 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6297 if (ret) {
6298 hdd_err("Failed to register IPv4 notifier: %d", ret);
6299 goto unregister_ip6_notifier;
6300 }
6301
Alok Kumarb64650c2018-03-23 17:05:11 +05306302 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6303 if (ret) {
6304 hdd_err("Failed to register netevent notifier: %d",
6305 ret);
6306 goto unregister_inetaddr_notifier;
6307 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006308 return 0;
6309
Alok Kumarb64650c2018-03-23 17:05:11 +05306310unregister_inetaddr_notifier:
6311 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006312unregister_ip6_notifier:
6313 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006314out:
6315 return ret;
6316
6317}
6318
6319/**
6320 * hdd_unregister_notifiers - Unregister netdev notifiers.
6321 * @hdd_ctx: HDD context
6322 *
6323 * Unregister netdev notifiers like IPv4 and IPv6.
6324 *
6325 * Return: None.
6326 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006327void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006328{
Alok Kumarb64650c2018-03-23 17:05:11 +05306329 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006330 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6331
6332 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006333}
6334
6335/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006336 * hdd_exit_netlink_services - Exit netlink services
6337 * @hdd_ctx: HDD context
6338 *
6339 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6340 * nl service.
6341 *
6342 * Return: None.
6343 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006344static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006345{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006346 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006347 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006348 ptt_sock_deactivate_svc();
6349
6350 nl_srv_exit();
6351}
6352
6353/**
6354 * hdd_init_netlink_services- Init netlink services
6355 * @hdd_ctx: HDD context
6356 *
6357 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6358 * nl service.
6359 *
6360 * Return: 0 on success and errno on failure.
6361 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006362static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006363{
6364 int ret;
6365
Ryan Hsuceddceb2016-04-28 10:20:14 -07006366 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006367 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006368 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006369 goto out;
6370 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006371 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006372
Naveen Rawat910726a2017-03-06 11:42:51 -08006373 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006374 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006375 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006376 goto err_nl_srv;
6377 }
6378
6379 ret = ptt_sock_activate_svc();
6380 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006381 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006382 goto err_nl_srv;
6383 }
6384
6385 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006386 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006387 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006388
6389 ret = cnss_diag_activate_service();
6390 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006391 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006392 goto err_close_cesium;
6393 }
6394
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006395 ret = spectral_scan_activate_service();
6396 if (ret) {
6397 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6398 goto err_close_cesium;
6399 }
6400
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006401 return 0;
6402
6403err_close_cesium:
6404 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006405 ptt_sock_deactivate_svc();
6406err_nl_srv:
6407 nl_srv_exit();
6408out:
6409 return ret;
6410}
6411
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006412/**
6413 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6414 * @hdd_ctx: HDD context.
6415 *
6416 * Destroy RX wakelock.
6417 *
6418 * Return: None.
6419 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006420static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006421{
6422 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6423}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006424
6425/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006426 * hdd_rx_wake_lock_create() - Create RX wakelock
6427 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006428 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006429 * Create RX wakelock.
6430 *
6431 * Return: None.
6432 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006433static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006434{
6435 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6436}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006437
6438/**
Houston Hoffman160db392016-10-10 17:37:51 -07006439 * hdd_context_deinit() - Deinitialize HDD context
6440 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006441 *
Houston Hoffman160db392016-10-10 17:37:51 -07006442 * Deinitialize HDD context along with all the feature specific contexts but
6443 * do not free hdd context itself. Caller of this API is supposed to free
6444 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006445 *
Houston Hoffman160db392016-10-10 17:37:51 -07006446 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006447 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006448static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006449{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306450 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6451
Houston Hoffman160db392016-10-10 17:37:51 -07006452 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006453
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006454 hdd_sap_context_destroy(hdd_ctx);
6455
6456 hdd_rx_wake_lock_destroy(hdd_ctx);
6457
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006458 hdd_scan_context_destroy(hdd_ctx);
6459
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006460 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006461
Houston Hoffman160db392016-10-10 17:37:51 -07006462 return 0;
6463}
6464
6465/**
6466 * hdd_context_destroy() - Destroy HDD context
6467 * @hdd_ctx: HDD context to be destroyed.
6468 *
6469 * Free config and HDD context as well as destroy all the resources.
6470 *
6471 * Return: None
6472 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006473static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006474{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006475 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306476
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306477 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6478
Houston Hoffman160db392016-10-10 17:37:51 -07006479 hdd_context_deinit(hdd_ctx);
6480
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306481 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006482 hdd_ctx->config = NULL;
6483
6484 wiphy_free(hdd_ctx->wiphy);
6485}
6486
6487/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306488 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6489 *
6490 * This function is used to destroy bug report lock
6491 *
6492 * Return: None
6493 */
6494static void wlan_destroy_bug_report_lock(void)
6495{
6496 p_cds_contextType p_cds_context;
6497
6498 p_cds_context = cds_get_global_context();
6499 if (!p_cds_context) {
6500 hdd_err("cds context is NULL");
6501 return;
6502 }
6503
6504 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6505}
6506
6507/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006508 * hdd_wlan_exit() - HDD WLAN exit function
6509 * @hdd_ctx: Pointer to the HDD Context
6510 *
6511 * This is the driver exit point (invoked during rmmod)
6512 *
6513 * Return: None
6514 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006515static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006516{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006517 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306518 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006519
Dustin Brown491d54b2018-03-14 12:39:11 -07006520 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006521
Arun Khandavallifae92942016-08-01 13:31:08 +05306522 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006523
Prashanth Bhattaab004382016-10-11 16:08:11 -07006524 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006525
6526#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306527 if (QDF_TIMER_STATE_RUNNING ==
6528 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6529 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006530 }
6531
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306532 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306533 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006534 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006535 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006536 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6537 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6538 hdd_ctx->last_acs_channel_list = NULL;
6539 hdd_ctx->num_of_channels = 0;
6540 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006541#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006542
Arun Khandavallifae92942016-08-01 13:31:08 +05306543 mutex_lock(&hdd_ctx->iface_change_lock);
6544 driver_status = hdd_ctx->driver_status;
6545 mutex_unlock(&hdd_ctx->iface_change_lock);
6546
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006547 /*
6548 * Powersave Offload Case
6549 * Disable Idle Power Save Mode
6550 */
6551 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006552 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306553 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006554
Arun Khandavallifae92942016-08-01 13:31:08 +05306555 if (driver_status != DRIVER_MODULES_CLOSED) {
6556 hdd_unregister_wext_all_adapters(hdd_ctx);
6557 /*
6558 * Cancel any outstanding scan requests. We are about to close
6559 * all of our adapters, but an adapter structure is what SME
6560 * passes back to our callback function. Hence if there
6561 * are any outstanding scan requests then there is a
6562 * race condition between when the adapter is closed and
6563 * when the callback is invoked. We try to resolve that
6564 * race condition here by canceling any outstanding scans
6565 * before we close the adapters.
6566 * Note that the scans may be cancelled in an asynchronous
6567 * manner, so ideally there needs to be some kind of
6568 * synchronization. Rather than introduce a new
6569 * synchronization here, we will utilize the fact that we are
6570 * about to Request Full Power, and since that is synchronized,
6571 * the expectation is that by the time Request Full Power has
6572 * completed, all scans will be cancelled
6573 */
6574 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006575 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006576 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006577 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006578 }
6579
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306580 unregister_netdevice_notifier(&hdd_netdev_notifier);
6581
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006582 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306583
Dustin Brown021cecd2017-12-11 13:56:43 -08006584 hdd_driver_memdump_deinit();
6585
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306586 qdf_nbuf_deinit_replenish_timer();
6587
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306588 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6589 hdd_info("Release wakelock for monitor mode!");
6590 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6591 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6592 }
6593
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306594 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6595 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6596 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006598 /*
6599 * Close CDS
6600 * This frees pMac(HAL) context. There should not be any call
6601 * that requires pMac access after this.
6602 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006603
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006604 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006605
Dustin Brownd005ad82018-01-19 10:32:13 -08006606 hdd_close_all_adapters(hdd_ctx, false);
6607
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306608 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306609 /*
6610 * If there is re_init failure wiphy would have already de-registered
6611 * check the wiphy status before un-registering again
6612 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306613 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306614 wiphy_unregister(wiphy);
6615 wlan_hdd_cfg80211_deinit(wiphy);
6616 hdd_lpass_notify_stop(hdd_ctx);
6617 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006618
Arun Khandavallifae92942016-08-01 13:31:08 +05306619 hdd_exit_netlink_services(hdd_ctx);
6620 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306621#ifdef FEATURE_WLAN_CH_AVOID
6622 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6623#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306624
Abhishek Singhe9068f12017-03-31 14:14:52 +05306625 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6626 if (driver_status)
6627 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006628
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006629 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006630}
6631
6632void __hdd_wlan_exit(void)
6633{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006634 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006635
Dustin Brown491d54b2018-03-14 12:39:11 -07006636 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006637
Anurag Chouhan6d760662016-02-20 16:05:43 +05306638 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006639 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006640 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07006641 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006642 return;
6643 }
6644
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006645 /* Do all the cleanup before deregistering the driver */
6646 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006647
Dustin Browne74003f2018-03-14 12:51:58 -07006648 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006649}
6650
6651#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006652/**
6653 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006654 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006655 *
6656 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6657 * Then new ACS request will do a fresh scan without reusing the cached
6658 * scan information.
6659 *
6660 * Return: void
6661 */
Tang Yingying523322d2017-01-17 23:28:43 +08006662static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006663{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006664 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006665
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006666 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006667 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006668 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6669 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6670 hdd_ctx->last_acs_channel_list = NULL;
6671 hdd_ctx->num_of_channels = 0;
6672 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006673
6674 if (!hdd_ctx->hHal)
6675 return;
6676 sme_scan_flush_result(hdd_ctx->hHal);
6677}
6678#endif
6679
6680#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006681int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6682 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006683{
6684 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306685 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006686 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006687
6688 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6689
6690 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306691 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306693
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006694 if (!hdd_ctx->hHal)
6695 return -EINVAL;
6696
Jeff Johnsone7672e72017-10-21 15:10:04 -07006697 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006698 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306699 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006700 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006701 return -EINVAL;
6702 }
6703
6704 return 0;
6705}
6706#endif
6707
6708/**
6709 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6710 * @state: state
6711 *
6712 * This function notifies FW with modem power status
6713 *
6714 * Return: 0 if successful, error number otherwise
6715 */
6716int hdd_wlan_notify_modem_power_state(int state)
6717{
6718 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306719 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006720 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006721
Anurag Chouhan6d760662016-02-20 16:05:43 +05306722 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006723 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306724 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006725 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306726
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006727 if (!hdd_ctx->hHal)
6728 return -EINVAL;
6729
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306730 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6731 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006732 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006733 state);
6734 return -EINVAL;
6735 }
6736 return 0;
6737}
6738
6739/**
6740 *
6741 * hdd_post_cds_enable_config() - HDD post cds start config helper
6742 * @adapter - Pointer to the HDD
6743 *
6744 * Return: None
6745 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006746QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006747{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306748 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006749
6750 /*
6751 * Send ready indication to the HDD. This will kick off the MAC
6752 * into a 'running' state and should kick off an initial scan.
6753 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306754 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6755 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006756 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6757 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306758 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006759 }
6760
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306761 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006762}
6763
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05306764struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
6765{
6766 struct hdd_adapter *adapter;
6767
6768 hdd_for_each_adapter(hdd_ctx, adapter) {
6769 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
6770 return adapter;
6771 }
6772
6773 return NULL;
6774}
6775
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006776/* wake lock APIs for HDD */
6777void hdd_prevent_suspend(uint32_t reason)
6778{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306779 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006780}
6781
6782void hdd_allow_suspend(uint32_t reason)
6783{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306784 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006785}
6786
6787void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6788{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306789 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6790 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006791}
6792
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006793/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006794QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006795{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006796
Amar Singhal6f8592b2017-04-26 14:31:58 -07006797 return sme_init_chan_list(hdd_ctx->hHal,
6798 hdd_ctx->reg.alpha2,
6799 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800}
6801
6802/**
6803 * hdd_is_5g_supported() - check if hardware supports 5GHz
6804 * @hdd_ctx: Pointer to the hdd context
6805 *
6806 * HDD function to know if hardware supports 5GHz
6807 *
6808 * Return: true if hardware supports 5GHz
6809 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006810bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006811{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006812 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006813 return true;
6814
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006815 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006816 return true;
6817 else
6818 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006819}
6820
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006821static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006822{
6823 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006824 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006825
6826 wiphy = hdd_ctx->wiphy;
6827
6828 /*
6829 * The channel information in
6830 * wiphy needs to be initialized before wiphy registration
6831 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006832 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6833 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006834 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006835 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006836 }
6837
6838#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6839 wiphy->wowlan = &wowlan_support_reg_init;
6840#else
6841 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6842 WIPHY_WOWLAN_MAGIC_PKT |
6843 WIPHY_WOWLAN_DISCONNECT |
6844 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6845 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6846 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6847 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6848 WIPHY_WOWLAN_RFKILL_RELEASE;
6849
6850 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6851 WOW_MAX_FILTERS_PER_LIST);
6852 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6853 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6854#endif
6855
6856 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006857 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306858 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006859 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306860 return ret_val;
6861 }
6862
Amar Singhal2d812012018-02-03 15:06:47 +08006863 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864
Amar Singhale4f28ee2015-10-21 14:36:56 -07006865 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006866}
6867
Mohit Khannaca4173b2017-09-12 21:52:19 -07006868#ifdef MSM_PLATFORM
6869/**
6870 * hdd_display_periodic_stats() - Function to display periodic stats
6871 * @hdd_ctx - handle to hdd context
6872 * @bool data_in_interval - true, if data detected in bw time interval
6873 *
6874 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6875 * Stats show up in wlan driver logs.
6876 *
6877 * Returns: None
6878 */
6879static inline
6880void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6881 bool data_in_interval)
6882{
6883 static u32 counter;
6884 static bool data_in_time_period;
6885 ol_txrx_pdev_handle pdev;
6886
6887 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6888 return;
6889
6890 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6891 if (!pdev) {
6892 hdd_err("pdev is NULL");
6893 return;
6894 }
6895
6896 counter++;
6897 if (data_in_interval)
6898 data_in_time_period = data_in_interval;
6899
6900 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6901 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6902 if (data_in_time_period) {
6903 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6904 CDP_TXRX_PATH_STATS,
6905 QDF_STATS_VERBOSITY_LEVEL_LOW);
6906 wlan_hdd_display_netif_queue_history
6907 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6908 qdf_dp_trace_dump_stats();
6909 }
6910 counter = 0;
6911 data_in_time_period = false;
6912 }
6913}
6914
Ravi Joshie2331e82015-07-01 18:18:54 -07006915/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006916 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006917 * @hdd_ctx - handle to hdd context
6918 * @tx_packets - transmit packet count
6919 * @rx_packets - receive packet count
6920 *
6921 * The function controls the bus bandwidth and dynamic control of
6922 * tcp delayed ack configuration
6923 *
6924 * Returns: None
6925 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006926
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006927static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006928 const uint64_t tx_packets,
6929 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006930{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006931 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006932 uint64_t temp_rx = 0;
6933 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006934 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006935 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006936 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006937 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006938 uint16_t index = 0;
6939 bool vote_level_change = false;
6940 bool rx_level_change = false;
6941 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006942
Mohit Khannaca4173b2017-09-12 21:52:19 -07006943 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006944 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006945 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006946 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006947 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006948 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006949 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006950 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006952 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006953 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6954 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006955 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006956 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006957 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306958 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306959 if (hdd_ctx->hbw_requested) {
6960 pld_remove_pm_qos(hdd_ctx->parent_dev);
6961 hdd_ctx->hbw_requested = false;
6962 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306963 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006964 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006965 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306966 if (!hdd_ctx->hbw_requested) {
6967 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6968 hdd_ctx->hbw_requested = true;
6969 }
6970
Nirav Shah3bbfa512016-05-12 16:43:49 +05306971 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006972 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006973 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006974 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006975 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006976
Mohit Khannaf8f96822017-05-17 17:11:59 -07006977 qdf_dp_trace_throttle_live_mode(
6978 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6979
Mohit Khannae71e2262015-11-10 09:37:24 -08006980 /* fine-tuning parameters for RX Flows */
6981 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6982
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006983 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006984
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306985 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6986 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6987 else
6988 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6989
Ravi Joshifed83572016-10-07 16:20:37 -07006990 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6991 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6992 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6993 next_rx_level = WLAN_SVC_TP_HIGH;
6994 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006995 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006996 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006997 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006998 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006999
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007000 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007001 struct wlan_rx_tp_data rx_tp_data = {0};
7002
Ravi Joshie2331e82015-07-01 18:18:54 -07007003 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007004 next_rx_level, temp_rx);
7005 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007006 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007007 /* Send throughput indication only if it is enabled.
7008 * Disabling tcp_del_ack will revert the tcp stack behavior
7009 * to default delayed ack. Note that this will disable the
7010 * dynamic delayed ack mechanism across the system
7011 */
7012 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007013 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7014
Mohit Khanna6272fb682017-04-13 09:34:36 -07007015 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7016 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7017
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007018 rx_tp_data.level = next_rx_level;
7019 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7020 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7021 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007022 }
7023
Mohit Khannae71e2262015-11-10 09:37:24 -08007024 /* fine-tuning parameters for TX Flows */
7025 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7026 hdd_ctx->prev_tx = tx_packets;
7027 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7028 next_tx_level = WLAN_SVC_TP_HIGH;
7029 else
7030 next_tx_level = WLAN_SVC_TP_LOW;
7031
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007032 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7033 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007034 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7035 next_tx_level, temp_tx);
7036 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007037 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307038 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7039 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007040 &next_tx_level,
7041 sizeof(next_tx_level));
7042 }
7043
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007044 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007045 if (vote_level_change || tx_level_change || rx_level_change) {
7046 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7047 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7048 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7049 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7050 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7051 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7052 hdd_ctx->hdd_txrx_hist_idx++;
7053 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7054 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007055
7056 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007057}
7058
7059#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307060static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007061{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007062 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307063 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07007064 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307065 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307066 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7067 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007068 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307069 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007070 bool connected = false;
7071 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7072
Prashanth Bhattaab004382016-10-11 16:08:11 -07007073 if (wlan_hdd_validate_context(hdd_ctx))
7074 return;
7075
Jeff Johnson214671b2017-10-30 19:45:23 -07007076 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007077 goto restart_timer;
7078
Dustin Brown920397d2017-12-13 16:27:50 -08007079 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307080 /*
7081 * Validate magic so we don't end up accessing
7082 * an invalid adapter.
7083 */
7084 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7085 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007086
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007087 if ((adapter->device_mode == QDF_STA_MODE ||
7088 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007089 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7090 != eConnectionState_Associated) {
7091
7092 continue;
7093 }
7094
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007095 if ((adapter->device_mode == QDF_SAP_MODE ||
7096 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007097 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007098
7099 continue;
7100 }
7101
7102 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7103 adapter->prev_tx_packets);
7104 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7105 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307106
7107 if (adapter->device_mode == QDF_SAP_MODE ||
7108 adapter->device_mode == QDF_P2P_GO_MODE ||
7109 adapter->device_mode == QDF_IBSS_MODE) {
7110
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007111 ret = cdp_get_intra_bss_fwd_pkts_count(
7112 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007113 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307114 &fwd_tx_packets, &fwd_rx_packets);
7115 if (ret == A_OK) {
7116 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7117 fwd_tx_packets,
7118 adapter->prev_fwd_tx_packets);
7119 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7120 fwd_tx_packets,
7121 adapter->prev_fwd_rx_packets);
7122 }
7123 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007124
7125 total_rx += adapter->stats.rx_packets;
7126 total_tx += adapter->stats.tx_packets;
7127
7128 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7129 adapter->prev_tx_packets = adapter->stats.tx_packets;
7130 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307131 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7132 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007133 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7134 connected = true;
7135 }
7136
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307137 /* add intra bss forwarded tx and rx packets */
7138 tx_packets += fwd_tx_packets_diff;
7139 rx_packets += fwd_rx_packets_diff;
7140
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05307141 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7142 &ipa_rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007143 tx_packets += (uint64_t)ipa_tx_packets;
7144 rx_packets += (uint64_t)ipa_rx_packets;
7145
7146 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007147 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007148 return;
7149 }
7150
Yuanyuan Liu13738502016-04-06 17:41:37 -07007151 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007152
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +05307153 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05307154 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007155
Jingxiang Gec64e1932017-08-22 14:38:59 +08007156restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007157 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007158 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007159 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307160 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007161 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007162 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007163}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007164
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307165/**
7166 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7167 * @arg: Argument of timer function
7168 *
7169 * Schedule a workqueue in this function where all the processing is done.
7170 *
7171 * Return: None.
7172 */
7173static void __hdd_bus_bw_cbk(void *arg)
7174{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007175 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307176
7177 if (wlan_hdd_validate_context(hdd_ctx))
7178 return;
7179
7180 schedule_work(&hdd_ctx->bus_bw_work);
7181}
7182
7183/**
7184 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7185 * @arg: Argument of timer function
7186 *
7187 * Return: None.
7188 */
7189static void hdd_bus_bw_cbk(void *arg)
7190{
7191 cds_ssr_protect(__func__);
7192 __hdd_bus_bw_cbk(arg);
7193 cds_ssr_unprotect(__func__);
7194}
7195
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007196int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007197{
7198 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307199 INIT_WORK(&hdd_ctx->bus_bw_work,
7200 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007201 hdd_ctx->bus_bw_timer_running = false;
7202 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307203 qdf_timer_init(NULL,
7204 &hdd_ctx->bus_bw_timer,
7205 hdd_bus_bw_cbk, (void *)hdd_ctx,
7206 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007207
7208 return 0;
7209}
7210
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007211void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007212{
Dustin Brownfce08d12017-01-17 16:29:38 -08007213 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007214 hdd_reset_tcp_delack(hdd_ctx);
7215
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007216 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307217 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307218 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007219 hdd_ctx->bus_bw_timer_running = false;
7220 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007221}
Lin Baic5c06882017-09-21 13:58:43 +08007222
7223void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7224{
7225 if (hdd_ctx)
7226 cancel_work_sync(&hdd_ctx->bus_bw_work);
7227}
jiadcdaf9bd2017-10-26 12:20:21 +08007228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007229#endif
7230
7231/**
Nirav Shahed34b212016-04-25 10:59:16 +05307232 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7233 * @hdd_ctx: hdd context
7234 *
7235 * Return: 0 for success or error code
7236 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007237static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307238{
7239 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7240 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7241 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007242 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307243 return -ENOMEM;
7244 }
7245 return 0;
7246}
7247
7248/**
7249 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7250 * @hdd_ctx: hdd context
7251 *
7252 * Return: none
7253 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007254void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307255{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307256 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7257 return;
7258
7259 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7260 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307261}
7262
Nirav Shahda008342016-05-17 18:50:40 +05307263static uint8_t *convert_level_to_string(uint32_t level)
7264{
7265 switch (level) {
7266 /* initialize the wlan sub system */
7267 case WLAN_SVC_TP_NONE:
7268 return "NONE";
7269 case WLAN_SVC_TP_LOW:
7270 return "LOW";
7271 case WLAN_SVC_TP_MEDIUM:
7272 return "MED";
7273 case WLAN_SVC_TP_HIGH:
7274 return "HIGH";
7275 default:
7276 return "INVAL";
7277 }
7278}
7279
Nirav Shahed34b212016-04-25 10:59:16 +05307280
7281/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007282 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7283 * @hdd_ctx: hdd context
7284 *
7285 * Return: none
7286 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007287void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007288{
7289 int i;
7290
7291#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007292 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307293 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007294 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007295 hdd_ctx->config->busBandwidthHighThreshold,
7296 hdd_ctx->config->busBandwidthMediumThreshold,
7297 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007298 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307299 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007300 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007301 hdd_ctx->config->tcpDelackThresholdHigh,
7302 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007303 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307304 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007305#endif
7306
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007307 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307308 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7309
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007310 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007311
7312 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007313 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007314 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007315 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7316 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7317 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7318 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7319 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007320 hdd_ctx->hdd_txrx_hist[i].
7321 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007322 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007323 hdd_ctx->hdd_txrx_hist[i].
7324 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007325 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007326 hdd_ctx->hdd_txrx_hist[i].
7327 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007328 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007329}
7330
7331/**
7332 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7333 * @hdd_ctx: hdd context
7334 *
7335 * Return: none
7336 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007337void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007338{
7339 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307340 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7341 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342}
7343
Mohit Khannaca4173b2017-09-12 21:52:19 -07007344/* length of the netif queue log needed per adapter */
7345#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7346
7347/**
7348 *
7349 * hdd_display_netif_queue_history_compact() - display compact netifq history
7350 * @hdd_ctx: hdd context
7351 *
7352 * Return: none
7353 */
7354static void
7355hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7356{
7357 int adapter_num = 0;
7358 int i;
7359 int bytes_written;
7360 u32 tbytes;
7361 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007362 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007363 char *comb_log_str;
7364 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007365 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007366
jiadbdefb252018-01-03 14:27:06 +08007367 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7368 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7369 if (!comb_log_str) {
7370 hdd_err("failed to alloc comb_log_str");
7371 return;
7372 }
7373
Mohit Khannaca4173b2017-09-12 21:52:19 -07007374 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007375
Dustin Brown920397d2017-12-13 16:27:50 -08007376 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007377 curr_time = qdf_system_ticks();
7378 total = curr_time - adapter->start_time;
7379 delta = curr_time - adapter->last_time;
7380
7381 if (adapter->pause_map) {
7382 pause = adapter->total_pause_time + delta;
7383 unpause = adapter->total_unpause_time;
7384 } else {
7385 unpause = adapter->total_unpause_time + delta;
7386 pause = adapter->total_pause_time;
7387 }
7388
7389 tbytes = 0;
7390 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7391 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7392 if (adapter->queue_oper_stats[i].pause_count == 0)
7393 continue;
7394 tbytes +=
7395 snprintf(
7396 &temp_str[tbytes],
7397 (tbytes >= sizeof(temp_str) ?
7398 0 : sizeof(temp_str) - tbytes),
7399 "%d(%d,%d) ",
7400 i,
7401 adapter->queue_oper_stats[i].
7402 pause_count,
7403 adapter->queue_oper_stats[i].
7404 unpause_count);
7405 }
7406 if (tbytes >= sizeof(temp_str))
7407 hdd_warn("log truncated");
7408
7409 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007410 bytes_written >= comb_log_str_size ? 0 :
7411 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007412 "[%d %d] (%d) %u/%ums %s|",
7413 adapter->session_id, adapter->device_mode,
7414 adapter->pause_map,
7415 qdf_system_ticks_to_msecs(pause),
7416 qdf_system_ticks_to_msecs(total),
7417 temp_str);
7418
Mohit Khannaca4173b2017-09-12 21:52:19 -07007419 adapter_num++;
7420 }
7421
7422 /* using QDF_TRACE to avoid printing function name */
7423 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7424 "STATS |%s", comb_log_str);
7425
jiadbdefb252018-01-03 14:27:06 +08007426 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007427 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007428
7429 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007430}
7431
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007432/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007433 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007434 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435 *
7436 * Return: none
7437 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007438void
7439wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7440 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007441{
7442
Jeff Johnson9d295242017-08-29 14:39:48 -07007443 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007444 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307445 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007446
Mohit Khannaca4173b2017-09-12 21:52:19 -07007447 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7448 hdd_display_netif_queue_history_compact(hdd_ctx);
7449 return;
7450 }
7451
Dustin Brown920397d2017-12-13 16:27:50 -08007452 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007453 hdd_debug("Netif queue operation statistics:");
7454 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007455 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007456 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307457 curr_time = qdf_system_ticks();
7458 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307459 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307460 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307461 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307462 unpause = adapter->total_unpause_time;
7463 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307464 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307465 pause = adapter->total_pause_time;
7466 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007467 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307468 qdf_system_ticks_to_msecs(total),
7469 qdf_system_ticks_to_msecs(pause),
7470 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007471 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007472
Nirav Shahda008342016-05-17 18:50:40 +05307473 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7474 qdf_time_t pause_delta = 0;
7475
7476 if (adapter->pause_map & (1 << i))
7477 pause_delta = delta;
7478
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007479 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007480 hdd_debug("%s: %d: %d: %ums",
7481 hdd_reason_type_to_string(i),
7482 adapter->queue_oper_stats[i].pause_count,
7483 adapter->queue_oper_stats[i].unpause_count,
7484 qdf_system_ticks_to_msecs(
7485 adapter->queue_oper_stats[i].total_pause_time +
7486 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007487 }
7488
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007489 hdd_debug("Netif queue operation history:");
7490 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307491 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7492
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007493 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007494
7495 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007496 /* using hdd_log to avoid printing function name */
7497 if (adapter->queue_oper_history[i].time == 0)
7498 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007499 hdd_debug("%d: %u: %s: %s: %x",
7500 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007501 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007502 hdd_action_type_to_string(
7503 adapter->queue_oper_history[i].netif_action),
7504 hdd_reason_type_to_string(
7505 adapter->queue_oper_history[i].netif_reason),
7506 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007507 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007508 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007509}
7510
7511/**
7512 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7513 * @hdd_ctx: hdd context
7514 *
7515 * Return: none
7516 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007517void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007518{
Jeff Johnson9d295242017-08-29 14:39:48 -07007519 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007520
Dustin Brown920397d2017-12-13 16:27:50 -08007521 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307522 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007523 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307524 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007525 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307526 adapter->history_index = 0;
7527 adapter->start_time = adapter->last_time = qdf_system_ticks();
7528 adapter->total_pause_time = 0;
7529 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007530 }
7531}
7532
7533/**
7534 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7535 * @halHandle: Hal handle
7536 * @pContext: Pointer to the context
7537 * @sessionId: Session ID
7538 * @scanId: Scan ID
7539 * @status: Status
7540 *
7541 * This is the callback to be executed when 11d scan is completed to flush out
7542 * the scan results
7543 *
7544 * 11d scan is done during driver load and is a passive scan on all
7545 * channels supported by the device, 11d scans may find some APs on
7546 * frequencies which are forbidden to be used in the regulatory domain
7547 * the device is operating in. If these APs are notified to the supplicant
7548 * it may try to connect to these APs, thus flush out all the scan results
7549 * which are present in SME after 11d scan is done.
7550 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307551 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007552 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307553static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007554 uint8_t sessionId, uint32_t scanId,
7555 eCsrScanStatus status)
7556{
Dustin Brown491d54b2018-03-14 12:39:11 -07007557 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007558
7559 sme_scan_flush_result(halHandle);
7560
Dustin Browne74003f2018-03-14 12:51:58 -07007561 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007562
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307563 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007564}
7565
7566#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7567/**
7568 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7569 * @hdd_ctx: hdd global context
7570 *
7571 * Return: none
7572 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007573static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007574{
7575 uint8_t i;
7576
7577 mutex_init(&hdd_ctx->op_ctx.op_lock);
7578 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7579 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7580 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7581 }
7582}
7583#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007584static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007585{
7586}
7587#endif
7588
Yingying Tang95409972016-10-20 15:16:15 +08007589#ifdef WLAN_FEATURE_WOW_PULSE
7590/**
7591 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007592 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007593 * @enable: enable or disable this behaviour
7594 *
7595 * Return: int
7596 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007597static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007598{
7599 struct hdd_config *pcfg_ini = phddctx->config;
7600 struct wow_pulse_mode wow_pulse_set_info;
7601 QDF_STATUS status;
7602
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007603 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007604
7605 if (false == phddctx->config->wow_pulse_support)
7606 return 0;
7607
7608 /* prepare the request to send to SME */
7609 if (enable == true) {
7610 wow_pulse_set_info.wow_pulse_enable = true;
7611 wow_pulse_set_info.wow_pulse_pin =
7612 pcfg_ini->wow_pulse_pin;
7613 wow_pulse_set_info.wow_pulse_interval_low =
7614 pcfg_ini->wow_pulse_interval_low;
7615 wow_pulse_set_info.wow_pulse_interval_high =
7616 pcfg_ini->wow_pulse_interval_high;
7617 } else {
7618 wow_pulse_set_info.wow_pulse_enable = false;
7619 wow_pulse_set_info.wow_pulse_pin = 0;
7620 wow_pulse_set_info.wow_pulse_interval_low = 0;
7621 wow_pulse_set_info.wow_pulse_interval_high = 0;
7622 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007623 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007624 wow_pulse_set_info.wow_pulse_enable,
7625 wow_pulse_set_info.wow_pulse_pin,
7626 wow_pulse_set_info.wow_pulse_interval_low,
7627 wow_pulse_set_info.wow_pulse_interval_high);
7628
7629 status = sme_set_wow_pulse(&wow_pulse_set_info);
7630 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007631 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007632 return -EIO;
7633 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007634 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007635 return 0;
7636}
7637#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007638static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007639{
7640 return 0;
7641}
7642#endif
7643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007644#ifdef WLAN_FEATURE_FASTPATH
7645/**
7646 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7647 * @hdd_cfg: hdd config
7648 * @context: lower layer context
7649 *
7650 * Return: none
7651 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307652void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007653 void *context)
7654{
7655 if (hdd_cfg->fastpath_enable)
7656 hif_enable_fastpath(context);
7657}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007658#endif
7659
Yuanyuan Liu13738502016-04-06 17:41:37 -07007660#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007661/**
7662 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007663 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007664 * @level: thermal level
7665 *
7666 * Change IPA data path to SW path when the thermal throttle level greater
7667 * than 0, and restore the original data path when throttle level is 0
7668 *
7669 * Return: none
7670 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007671static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007672{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007673 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007674
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007675 /* Change IPA to SW path when throttle level greater than 0 */
7676 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307677 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007678 else
7679 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307680 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007681}
7682
7683/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307684 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7685 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307686 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007687 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307688 * Get a safe channel to restart SAP. PCL already takes into account the
7689 * unsafe channels. So, the PCL is validated with the ACS range to provide
7690 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007691 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307692 * Return: Channel number to restart SAP in case of success. In case of any
7693 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007694 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307695static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007696 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007697{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307698 struct sir_pcl_list pcl;
7699 QDF_STATUS status;
7700 uint32_t i, j;
7701 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007702 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307703 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007704 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007705
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307706 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7707 if (!hdd_ctx) {
7708 hdd_err("invalid HDD context");
7709 return INVALID_CHANNEL_ID;
7710 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007711
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307712 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7713 if (!hal_handle) {
7714 hdd_err("invalid HAL handle");
7715 return INVALID_CHANNEL_ID;
7716 }
7717
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007718 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7719 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007720 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7721 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307722 if (QDF_IS_STATUS_ERROR(status)) {
7723 hdd_err("Get PCL failed");
7724 return INVALID_CHANNEL_ID;
7725 }
7726
Frank Liudc2cefb2017-06-21 15:38:18 +08007727 /*
7728 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7729 * channel is unsafe channel, the pcl may be empty, instead of return,
7730 * try to choose a safe channel from acs range.
7731 */
7732 if (!pcl.pcl_len)
7733 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307734
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007735 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007736 adapter->session.ap.sap_config.acs_cfg.start_ch,
7737 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307738
7739 /* PCL already takes unsafe channel into account */
7740 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007741 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307742 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007743 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307744 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007745 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007746 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307747 return pcl.pcl_list[i];
7748 }
7749 }
7750
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007751 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307752
7753 /* Try for safe channel from all valid channel */
7754 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007755 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7756 &pcl.pcl_len);
7757 if (ret) {
7758 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307759 return INVALID_CHANNEL_ID;
7760 }
7761
7762 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007763 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307764 found = false;
7765 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007766 if (pcl.pcl_list[i] ==
7767 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007768 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307769 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007770 break;
7771 }
7772 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307773
7774 if (found)
7775 continue;
7776
7777 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007778 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307779 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007780 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007781 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307782 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007783 }
7784 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307785
7786 return INVALID_CHANNEL_ID;
7787}
Nirav Shaheb017be2018-02-15 11:20:58 +05307788#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307789
7790/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007791 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307792 * @adapter: AP adapter
7793 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007794 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307795 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007796 * Moves the SAP interface by invoking the function which
7797 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307798 *
7799 * Return: None
7800 */
Min Liu2fef5792018-01-19 17:59:42 +08007801void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7802 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307803{
Jeff Johnson87251032017-08-29 13:31:11 -07007804 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307805 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007806 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307807
7808 if (!adapter) {
7809 hdd_err("invalid adapter");
7810 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007811 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307812
7813 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7814
7815 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7816 if (!hal_handle) {
7817 hdd_err("invalid HAL handle");
7818 return;
7819 }
7820
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007821 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7822
Jeff Johnson91df29d2017-10-27 19:29:50 -07007823 hdd_ap_ctx->sap_config.channel = channel;
7824 hdd_ap_ctx->sap_config.ch_params.ch_width =
7825 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307826
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007827 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007828 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307829
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007830 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007831 hdd_ap_ctx->sap_config.channel,
7832 hdd_ap_ctx->sap_config.sec_ch,
7833 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307834
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007835 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007836 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007837 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007838}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307839
Jeff Johnson9d295242017-08-29 14:39:48 -07007840int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307841{
7842 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307843 int status;
7844 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307845
7846 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7847
7848 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007849 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307850 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007851 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307852 }
7853 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007854 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307855 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307856 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007857 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307858 WLAN_VENDOR_ACS_WAIT_TIME);
7859 if (qdf_status != QDF_STATUS_SUCCESS) {
7860 hdd_err("failed to start external acs timer");
7861 return -ENOSPC;
7862 }
7863 /* Update config to application */
7864 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07007865 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307866
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307867 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307868}
7869
Nirav Shaheb017be2018-02-15 11:20:58 +05307870#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307871/**
7872 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7873 * @hdd_ctx: hdd context pointer
7874 *
7875 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7876 * and if ACS is enabled, driver will ask userspace to restart the
7877 * sap. User space on LTE coex indication restart driver.
7878 *
7879 * Return - none
7880 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007881void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307882{
Dustin Brown920397d2017-12-13 16:27:50 -08007883 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307884 uint32_t i;
7885 bool found = false;
7886 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007887
Dustin Brown920397d2017-12-13 16:27:50 -08007888 hdd_for_each_adapter(hdd_ctxt, adapter) {
7889 if (!(adapter->device_mode == QDF_SAP_MODE &&
7890 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007891 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007892 adapter->device_mode,
7893 adapter->session.ap.sap_config.
7894 acs_cfg.acs_mode);
7895 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307896 }
7897
7898 found = false;
7899 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007900 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307901 hdd_ctxt->unsafe_channel_list[i]) {
7902 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007903 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007904 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307905 break;
7906 }
7907 }
7908
7909 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007910 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007911 adapter->session.ap.operating_channel);
7912 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307913 }
7914
Kapil Gupta8878ad92017-02-13 11:56:04 +05307915 if (hdd_ctxt->config->vendor_acs_support &&
7916 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007917 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307918 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007919 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307920 } else
7921 restart_chan =
7922 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007923 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307924 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007925 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307926 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007927 /*
7928 * SAP restart due to unsafe channel. While
7929 * restarting the SAP, make sure to clear
7930 * acs_channel, channel to reset to
7931 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307932 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007933 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307934 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007935 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307936 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007937 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307938 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7939 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007940 hdd_debug("driver to start sap: %d",
7941 hdd_ctxt->config->sap_internal_restart);
7942 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08007943 hdd_switch_sap_channel(adapter, restart_chan,
7944 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04007945 else
7946 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307947 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307948 }
7949}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307950
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007951/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007952 * hdd_init_channel_avoidance() - Initialize channel avoidance
7953 * @hdd_ctx: HDD global context
7954 *
7955 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007956 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007957 * down to the lower layers. Then subscribe to subsequent channel
7958 * avoidance events.
7959 *
7960 * Return: None
7961 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007962static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007963{
7964 uint16_t unsafe_channel_count;
7965 int index;
7966
Yuanyuan Liu13738502016-04-06 17:41:37 -07007967 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7968 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007969 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007970 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007971
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007972 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007973 hdd_ctx->unsafe_channel_count);
7974
Anurag Chouhan6d760662016-02-20 16:05:43 +05307975 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007976 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007977
7978 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007979 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007980 hdd_ctx->unsafe_channel_list[index]);
7981
7982 }
7983
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007984}
Dustin Brown676a2322017-08-15 13:16:13 -07007985
Jeff Johnson9d295242017-08-29 14:39:48 -07007986static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007987 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007988{
7989 uint8_t restart_chan;
7990
7991 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7992 if (!restart_chan) {
7993 hdd_alert("fail to restart SAP");
7994 return;
7995 }
7996
7997 /* SAP restart due to unsafe channel. While restarting
7998 * the SAP, make sure to clear acs_channel, channel to
7999 * reset to 0. Otherwise these settings will override
8000 * the ACS while restart.
8001 */
8002 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008003 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008004
8005 hdd_debug("sending coex indication");
8006
8007 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8008 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008009 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008010}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008011
8012int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8013 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8014{
8015 uint32_t size;
8016 uint16_t *unsafe_list;
8017 uint16_t chan_count;
8018
8019 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8020 return -EINVAL;
8021
8022 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8023 NUM_CHANNELS);
8024 if (chan_count) {
8025 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8026 unsafe_list = qdf_mem_malloc(size);
8027 if (!unsafe_list) {
8028 hdd_err("No memory for unsafe chan list size%d",
8029 size);
8030 return -ENOMEM;
8031 }
8032 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8033 } else {
8034 unsafe_list = NULL;
8035 }
8036
8037 *local_unsafe_list = unsafe_list;
8038 *local_unsafe_list_count = chan_count;
8039
8040 return 0;
8041}
8042
8043bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8044 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8045{
8046 int i, j;
8047
8048 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8049 return true;
8050 if (local_unsafe_list_count == 0)
8051 return false;
8052 for (i = 0; i < local_unsafe_list_count; i++) {
8053 for (j = 0; j < local_unsafe_list_count; j++)
8054 if (local_unsafe_list[i] ==
8055 hdd_ctx->unsafe_channel_list[j])
8056 break;
8057 if (j >= local_unsafe_list_count)
8058 break;
8059 }
8060 if (i >= local_unsafe_list_count) {
8061 hdd_info("unsafe chan list same");
8062 return false;
8063 }
8064
8065 return true;
8066}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008067#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008068static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008069{
8070}
Dustin Brown676a2322017-08-15 13:16:13 -07008071
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008072static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008073{
8074}
Dustin Brown676a2322017-08-15 13:16:13 -07008075
Jeff Johnson9d295242017-08-29 14:39:48 -07008076static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008077 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008078{
8079 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8080}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008081#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008082
8083/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008084 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8085 * user space
8086 * @frame_ind: Management frame data to be informed.
8087 *
8088 * This function is used to indicate management frame to
8089 * user space
8090 *
8091 * Return: None
8092 *
8093 */
8094void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8095{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008096 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008097 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008098 int i;
8099
Rajeev Kumard004abc2016-02-17 12:09:56 -08008100 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008101 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008102
8103 if (0 != wlan_hdd_validate_context(hdd_ctx))
8104 return;
8105
8106 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8107 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8108 adapter =
8109 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8110 if (adapter)
8111 break;
8112 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008113 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8114 hdd_for_each_adapter(hdd_ctx, adapter) {
8115 if ((NULL != adapter) &&
8116 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8117 __hdd_indicate_mgmt_frame(adapter,
8118 frame_ind->frame_len,
8119 frame_ind->frameBuf,
8120 frame_ind->frameType,
8121 frame_ind->rxChan,
8122 frame_ind->rxRssi);
8123 }
8124 }
8125 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008126 } else {
8127 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8128 frame_ind->sessionId);
8129 }
8130
8131 if ((NULL != adapter) &&
8132 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8133 __hdd_indicate_mgmt_frame(adapter,
8134 frame_ind->frame_len,
8135 frame_ind->frameBuf,
8136 frame_ind->frameType,
8137 frame_ind->rxChan,
8138 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008139}
8140
Kapil Gupta8878ad92017-02-13 11:56:04 +05308141void hdd_acs_response_timeout_handler(void *context)
8142{
8143 struct hdd_external_acs_timer_context *timer_context =
8144 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008145 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008146 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308147 uint8_t reason;
8148
Dustin Brown491d54b2018-03-14 12:39:11 -07008149 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308150 if (!timer_context) {
8151 hdd_err("invlaid timer context");
8152 return;
8153 }
8154 adapter = timer_context->adapter;
8155 reason = timer_context->reason;
8156
8157
8158 if ((!adapter) ||
8159 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8160 hdd_err("invalid adapter or adapter has invalid magic");
8161 return;
8162 }
8163 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8164 if (wlan_hdd_validate_context(hdd_ctx))
8165 return;
8166
8167 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8168 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8169 else
8170 return;
8171
8172 hdd_err("ACS timeout happened for %s reason %d",
8173 adapter->dev->name, reason);
8174 switch (reason) {
8175 /* SAP init case */
8176 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8177 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8178 false);
8179 wlan_hdd_cfg80211_start_acs(adapter);
8180 break;
8181 /* DFS detected on current channel */
8182 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8183 wlan_sap_update_next_channel(
8184 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8185 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008186 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308187 break;
8188 /* LTE coex event on current channel */
8189 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8190 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8191 break;
8192 default:
8193 hdd_info("invalid reason for timer invoke");
8194
8195 }
8196}
8197
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008198/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008199 * hdd_override_ini_config - Override INI config
8200 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008201 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008202 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008203 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008204 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008205 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008206static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008207{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008208
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008209 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8210 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008211 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008212 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008213 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008214 if (0 == enable_11d || 1 == enable_11d) {
8215 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008216 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008217 }
Leo Chang11545d62016-10-17 14:53:50 -07008218
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308219 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008220 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008221 hdd_debug("IpaConfig override to %d",
8222 hdd_ctx->config->IpaConfig);
8223 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308224
8225 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8226 !hdd_ctx->config->enable_bcast_probe_rsp) {
8227 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8228 hdd_ctx->config->rssi_assoc_reject_enabled,
8229 hdd_ctx->config->enable_bcast_probe_rsp);
8230 hdd_ctx->config->oce_sta_enabled = 0;
8231 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008232}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008233
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008234/**
8235 * hdd_set_trace_level_for_each - Set trace level for each INI config
8236 * @hdd_ctx - HDD context
8237 *
8238 * Set trace level for each module based on INI config.
8239 *
8240 * Return: None
8241 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008242static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008243{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308244 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8245 hdd_ctx->config->qdf_trace_enable_wdi);
8246 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8247 hdd_ctx->config->qdf_trace_enable_hdd);
8248 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8249 hdd_ctx->config->qdf_trace_enable_sme);
8250 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8251 hdd_ctx->config->qdf_trace_enable_pe);
8252 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8253 hdd_ctx->config->qdf_trace_enable_wma);
8254 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8255 hdd_ctx->config->qdf_trace_enable_sys);
8256 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8257 hdd_ctx->config->qdf_trace_enable_qdf);
8258 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8259 hdd_ctx->config->qdf_trace_enable_sap);
8260 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8261 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8262 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8263 hdd_ctx->config->qdf_trace_enable_bmi);
8264 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8265 hdd_ctx->config->qdf_trace_enable_cfg);
8266 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8267 hdd_ctx->config->qdf_trace_enable_epping);
8268 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8269 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8270 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008271 hdd_ctx->config->qdf_trace_enable_txrx);
8272 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8273 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308274 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8275 hdd_ctx->config->qdf_trace_enable_htc);
8276 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8277 hdd_ctx->config->qdf_trace_enable_hif);
8278 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8279 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8280 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8281 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008282 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8283 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008284 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8285 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008286 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8287 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008288 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8289 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008290
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008291 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008292}
8293
8294/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008295 * hdd_context_init() - Initialize HDD context
8296 * @hdd_ctx: HDD context.
8297 *
8298 * Initialize HDD context along with all the feature specific contexts.
8299 *
8300 * return: 0 on success and errno on failure.
8301 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008302static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008303{
8304 int ret;
8305
8306 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8307 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8308
8309 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308310 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008311
8312 init_completion(&hdd_ctx->mc_sus_event_var);
8313 init_completion(&hdd_ctx->ready_to_suspend);
8314
8315 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308316 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008317 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308318
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008319 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008320
8321 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8322
8323 ret = hdd_scan_context_init(hdd_ctx);
8324 if (ret)
8325 goto list_destroy;
8326
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008327 hdd_rx_wake_lock_create(hdd_ctx);
8328
8329 ret = hdd_sap_context_init(hdd_ctx);
8330 if (ret)
8331 goto scan_destroy;
8332
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008333 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8334
8335 hdd_init_offloaded_packets_ctx(hdd_ctx);
8336
8337 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8338 hdd_ctx->config);
8339 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008340 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008341
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308342 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8343 "monitor_mode_wakelock");
8344
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008345 return 0;
8346
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008347sap_destroy:
8348 hdd_sap_context_destroy(hdd_ctx);
8349
8350scan_destroy:
8351 hdd_scan_context_destroy(hdd_ctx);
8352 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008353list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008354 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008355
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008356 return ret;
8357}
8358
8359/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308360 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8361 * @hdd_ctx: pointer to hdd context
8362 *
8363 * Return: status of initialization
8364 * 0 - success
8365 * negative value - failure
8366 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008367static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308368{
8369 int ret;
8370
8371 if (!hdd_ctx->config->probe_req_ie_whitelist)
8372 return 0;
8373
8374 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8375 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8376 hdd_ctx->config->probe_req_ie_whitelist = false;
8377 return -EINVAL;
8378 }
8379
8380 /* parse ini string probe req oui */
8381 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8382 if (ret) {
8383 hdd_err("parsing error: disable ie whitelisting");
8384 hdd_ctx->config->probe_req_ie_whitelist = false;
8385 }
8386
8387 return ret;
8388}
8389
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308390/**
8391 * hdd_iface_change_callback() - Function invoked when stop modules expires
8392 * @priv: pointer to hdd context
8393 *
8394 * This function is invoked when the timer waiting for the interface change
8395 * expires, it shall cut-down the power to wlan and stop all the modules.
8396 *
8397 * Return: void
8398 */
8399static void hdd_iface_change_callback(void *priv)
8400{
8401 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8402 int ret;
8403 int status = wlan_hdd_validate_context(hdd_ctx);
8404
8405 if (status)
8406 return;
8407
Dustin Brown491d54b2018-03-14 12:39:11 -07008408 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308409 hdd_debug("Interface change timer expired close the modules!");
8410 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8411 if (ret)
8412 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008413 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308414}
8415
Nirav Shaheb017be2018-02-15 11:20:58 +05308416#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8417static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8418{
8419 wlan_logging_set_log_to_console(hdd_ctx->config->
8420 wlan_logging_to_console);
8421 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8422}
8423#else
8424static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8425{ }
8426#endif
8427
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308428/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008429 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308430 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008431 *
8432 * Allocate and initialize HDD context. HDD context is allocated as part of
8433 * wiphy allocation and then context is initialized.
8434 *
8435 * Return: HDD context on success and ERR_PTR on failure
8436 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008437static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008438{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308439 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008440 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008441 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008442
Dustin Brown491d54b2018-03-14 12:39:11 -07008443 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008444
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008445 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008446 if (hdd_ctx == NULL) {
8447 ret = -ENOMEM;
8448 goto err_out;
8449 }
8450
Dustin Brown6f427922017-09-19 12:19:00 -07008451 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8452 hdd_iface_change_callback,
8453 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308454
8455 mutex_init(&hdd_ctx->iface_change_lock);
8456
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008457 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308458 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008459
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308460 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008461 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008462 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008463 ret = -ENOMEM;
8464 goto err_free_hdd_context;
8465 }
8466
8467 /* Read and parse the qcom_cfg.ini file */
8468 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308469 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308470 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008471 WLAN_INI_FILE);
8472 ret = -EINVAL;
8473 goto err_free_config;
8474 }
8475
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308476 ie_whitelist_attrs_init(hdd_ctx);
8477
Dustin Brown7f939932017-05-18 15:02:17 -07008478 hdd_debug("setting timer multiplier: %u",
8479 hdd_ctx->config->timer_multiplier);
8480 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8481
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008482
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308483 if (hdd_ctx->config->fhostNSOffload)
8484 hdd_ctx->ns_offload_enable = true;
8485
Abhishek Singh5ea86532016-04-27 14:10:53 +05308486 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8487
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008488 hdd_override_ini_config(hdd_ctx);
8489
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008490 ret = hdd_context_init(hdd_ctx);
8491
8492 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008493 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008494
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008495 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308496 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008497
Anurag Chouhan6d760662016-02-20 16:05:43 +05308498 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008499 goto skip_multicast_logging;
8500
8501 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8502
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008503 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8504 if (ret)
8505 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308506
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008507 ret = hdd_init_netlink_services(hdd_ctx);
8508 if (ret)
8509 goto err_deinit_txrx_histogram;
8510
Nirav Shaheb017be2018-02-15 11:20:58 +05308511 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308512
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008513skip_multicast_logging:
8514 hdd_set_trace_level_for_each(hdd_ctx);
8515
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008516 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8517
Dustin Browne74003f2018-03-14 12:51:58 -07008518 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008519
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008520 return hdd_ctx;
8521
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008522err_deinit_txrx_histogram:
8523 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8524
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008525err_deinit_hdd_context:
8526 hdd_context_deinit(hdd_ctx);
8527
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008528err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308529 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008530
8531err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308532 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008533 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008534
8535err_out:
8536 return ERR_PTR(ret);
8537}
8538
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008539#ifdef WLAN_OPEN_P2P_INTERFACE
8540/**
8541 * hdd_open_p2p_interface - Open P2P interface
8542 * @hdd_ctx: HDD context
8543 * @rtnl_held: True if RTNL lock held
8544 *
8545 * Open P2P interface during probe. This function called to open the P2P
8546 * interface at probe along with STA interface.
8547 *
8548 * Return: 0 on success and errno on failure
8549 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008550static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008551{
Jeff Johnson9d295242017-08-29 14:39:48 -07008552 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008553 uint8_t *p2p_dev_addr;
8554
8555 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8556 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008557 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008558 hdd_ctx->config->intfMacAddr[0].bytes,
8559 sizeof(tSirMacAddr));
8560
8561 /*
8562 * Generate the P2P Device Address. This consists of
8563 * the device's primary MAC address with the locally
8564 * administered bit set.
8565 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008566 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008567 } else {
8568 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8569 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008570 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008571 return -ENOSPC;
8572 }
8573
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008574 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8575 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008576 }
8577
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008578 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008579 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008580 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008581
8582 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008583 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008584 return -ENOSPC;
8585 }
8586
8587 return 0;
8588}
8589#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008590static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008591 bool rtnl_held)
8592{
8593 return 0;
8594}
8595#endif
8596
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008597static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008598{
Jeff Johnson9d295242017-08-29 14:39:48 -07008599 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008600 int ret = 0;
8601
8602 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8603 wlan_hdd_get_intf_addr(hdd_ctx),
8604 NET_NAME_UNKNOWN, rtnl_held);
8605 if (adapter == NULL) {
8606 hdd_err("Failed to open 802.11p interface");
8607 ret = -ENOSPC;
8608 }
8609
8610 return ret;
8611}
8612
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008613/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308614 * hdd_start_station_adapter()- Start the Station Adapter
8615 * @adapter: HDD adapter
8616 *
8617 * This function initializes the adapter for the station mode.
8618 *
8619 * Return: 0 on success or errno on failure.
8620 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008621int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308622{
8623 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008624 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308625
Dustin Brownfdf17c12018-03-14 12:55:34 -07008626 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008627 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8628 hdd_err("session is already opened, %d",
8629 adapter->session_id);
8630 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8631 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308632
Krunal Sonib51eec72017-11-20 21:53:01 -08008633 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8634 if (ret) {
8635 hdd_err("failed to create vdev: %d", ret);
8636 return ret;
8637 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308638 status = hdd_init_station_mode(adapter);
8639
8640 if (QDF_STATUS_SUCCESS != status) {
8641 hdd_err("Error Initializing station mode: %d", status);
8642 return qdf_status_to_os_return(status);
8643 }
8644
Arun Khandavallifae92942016-08-01 13:31:08 +05308645 hdd_register_tx_flow_control(adapter,
8646 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008647 hdd_tx_resume_cb,
8648 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308649
Dustin Browne74003f2018-03-14 12:51:58 -07008650 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308651 return 0;
8652}
8653
8654/**
8655 * hdd_start_ap_adapter()- Start AP Adapter
8656 * @adapter: HDD adapter
8657 *
8658 * This function initializes the adapter for the AP mode.
8659 *
8660 * Return: 0 on success errno on failure.
8661 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008662int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308663{
8664 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008665 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008666 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008667 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308668
Dustin Brown491d54b2018-03-14 12:39:11 -07008669 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308670
Krunal Sonib51eec72017-11-20 21:53:01 -08008671 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8672 hdd_err("session is already opened, %d",
8673 adapter->session_id);
8674 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8675 }
8676 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008677 * In SSR case no need to create new sap context.
8678 * Otherwise create sap context first and then create
8679 * vdev as while creating the vdev, driver needs to
8680 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008681 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008682 if (adapter->session.ap.sap_context) {
8683 is_ssr = true;
8684 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008685 hdd_err("sap creation failed");
8686 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8687 }
8688
8689 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8690 adapter->session.ap.sap_context);
8691 if (ret) {
8692 hdd_err("failed to create vdev, status:%d", ret);
8693 hdd_sap_destroy_ctx(adapter);
8694 return ret;
8695 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008696
8697 if (adapter->device_mode == QDF_SAP_MODE)
8698 sme_cli_set_command(adapter->session_id,
8699 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8700 (bool)(hdd_ctx->config->fine_time_meas_cap &
8701 WMI_FW_AP_RTT_RESPR),
8702 VDEV_CMD);
8703
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008704 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308705
8706 if (QDF_STATUS_SUCCESS != status) {
8707 hdd_err("Error Initializing the AP mode: %d", status);
8708 return qdf_status_to_os_return(status);
8709 }
8710
Arun Khandavallifae92942016-08-01 13:31:08 +05308711 hdd_register_tx_flow_control(adapter,
8712 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008713 hdd_softap_tx_resume_cb,
8714 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308715
Dustin Browne74003f2018-03-14 12:51:58 -07008716 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308717 return 0;
8718}
8719
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308720static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8721 bool rtnl_held)
8722{
8723 struct hdd_adapter *adapter;
8724
8725 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8726 hdd_ctx->config->enableConcurrentSTA,
8727 wlan_hdd_get_intf_addr(hdd_ctx),
8728 NET_NAME_UNKNOWN, rtnl_held);
8729
8730 if (!adapter)
8731 return -ENOSPC;
8732
8733 return 0;
8734}
8735
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308736/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008737 * hdd_open_interfaces - Open all required interfaces
8738 * hdd_ctx: HDD context
8739 * rtnl_held: True if RTNL lock is held
8740 *
8741 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8742 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008743 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008744 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008745static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008746{
Jeff Johnson9d295242017-08-29 14:39:48 -07008747 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008748 int ret;
8749
Ravi Joshia307f632017-07-17 23:41:41 -07008750 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008751 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8752 con_mode == QDF_GLOBAL_FTM_MODE) {
8753 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8754 QDF_MONITOR_MODE : QDF_FTM_MODE;
8755
8756 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8757 wlan_hdd_get_intf_addr(hdd_ctx),
8758 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008759 if (!adapter) {
8760 hdd_err("open adapter failed");
8761 return -ENOSPC;
8762 }
Lin Bai1c678482017-12-18 18:29:11 +08008763
Ravi Joshia307f632017-07-17 23:41:41 -07008764 return 0;
8765 }
8766
Jeff Johnson957bc272017-02-02 08:54:48 -08008767 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308768 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008769 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008770
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008771 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008772 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008773 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008774
8775 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008776 return -ENOSPC;
8777
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308778 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8779 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8780 if (ret)
8781 hdd_err("Cannot create concurrent STA interface");
8782 }
8783
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008784 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8785 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008786 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008787
8788 /* Open 802.11p Interface */
8789 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008790 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8791 if (ret)
8792 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008793 }
8794
Jeff Johnson957bc272017-02-02 08:54:48 -08008795 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008796
Jeff Johnson957bc272017-02-02 08:54:48 -08008797err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008798 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008799 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008800}
8801
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008802
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308803#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8804/**
8805 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8806 * @cds_cfg: CDS Configuration
8807 * @hdd_ctx: Pointer to hdd context
8808 *
8809 * Return: none
8810 */
8811static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8812 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008813 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308814{
8815 cds_cfg->tx_flow_stop_queue_th =
8816 hdd_ctx->config->TxFlowStopQueueThreshold;
8817 cds_cfg->tx_flow_start_queue_offset =
8818 hdd_ctx->config->TxFlowStartQueueOffset;
8819}
8820#else
8821static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8822 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008823 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308824{
8825}
8826#endif
8827
8828#ifdef FEATURE_WLAN_RA_FILTERING
8829/**
8830 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8831 * @cds_cfg: CDS Configuration
8832 * @hdd_ctx: Pointer to hdd context
8833 *
8834 * Return: none
8835 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308836static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008837 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308838{
8839 cds_cfg->ra_ratelimit_interval =
8840 hdd_ctx->config->RArateLimitInterval;
8841 cds_cfg->is_ra_ratelimit_enabled =
8842 hdd_ctx->config->IsRArateLimitEnabled;
8843}
8844#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308845static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008846 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308847{
8848}
8849#endif
8850
8851/**
8852 * hdd_update_cds_config() - API to update cds configuration parameters
8853 * @hdd_ctx: HDD Context
8854 *
8855 * Return: 0 for Success, errno on failure
8856 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008857static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308858{
8859 struct cds_config_info *cds_cfg;
8860
8861 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8862 if (!cds_cfg) {
8863 hdd_err("failed to allocate cds config");
8864 return -ENOMEM;
8865 }
8866
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008867 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008868 if (!hdd_ctx->config->nMaxPsPoll ||
8869 !hdd_ctx->config->enablePowersaveOffload) {
8870 cds_cfg->powersave_offload_enabled =
8871 hdd_ctx->config->enablePowersaveOffload;
8872 } else {
8873 if ((hdd_ctx->config->enablePowersaveOffload ==
8874 PS_QPOWER_NODEEPSLEEP) ||
8875 (hdd_ctx->config->enablePowersaveOffload ==
8876 PS_LEGACY_NODEEPSLEEP))
8877 cds_cfg->powersave_offload_enabled =
8878 PS_LEGACY_NODEEPSLEEP;
8879 else
8880 cds_cfg->powersave_offload_enabled =
8881 PS_LEGACY_DEEPSLEEP;
8882 hdd_info("Qpower disabled in cds config, %d",
8883 cds_cfg->powersave_offload_enabled);
8884 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308885 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8886 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8887 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8888 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308889
8890 /*
8891 * Copy the DFS Phyerr Filtering Offload status.
8892 * This parameter reflects the value of the
8893 * dfs_phyerr_filter_offload flag as set in the ini.
8894 */
8895 cds_cfg->dfs_phyerr_filter_offload =
8896 hdd_ctx->config->fDfsPhyerrFilterOffload;
8897 if (hdd_ctx->config->ssdp)
8898 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8899
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308900 cds_cfg->force_target_assert_enabled =
8901 hdd_ctx->config->crash_inject_enabled;
8902
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308903 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8904 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8905
8906 cds_cfg->ap_maxoffload_reorderbuffs =
8907 hdd_ctx->config->apMaxOffloadReorderBuffs;
8908
8909 cds_cfg->ap_disable_intrabss_fwd =
8910 hdd_ctx->config->apDisableIntraBssFwd;
8911
8912 cds_cfg->dfs_pri_multiplier =
8913 hdd_ctx->config->dfsRadarPriMultiplier;
8914 cds_cfg->reorder_offload =
8915 hdd_ctx->config->reorderOffloadSupport;
8916
8917 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05308918 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07008919 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8920 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008921 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008922 hdd_ctx->config->IpaUcTxBufCount);
8923 hdd_ctx->config->IpaUcTxBufCount =
8924 rounddown_pow_of_two(
8925 hdd_ctx->config->IpaUcTxBufCount);
8926 if (!hdd_ctx->config->IpaUcTxBufCount) {
8927 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308928 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008929 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008930 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008931 hdd_ctx->config->IpaUcTxBufCount);
8932 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308933 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8934 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008935 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8936 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008937 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008938 hdd_ctx->config->IpaUcRxIndRingCount);
8939 hdd_ctx->config->IpaUcRxIndRingCount =
8940 rounddown_pow_of_two(
8941 hdd_ctx->config->IpaUcRxIndRingCount);
8942 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8943 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308944 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008945 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008946 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008947 hdd_ctx->config->IpaUcRxIndRingCount);
8948 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308949 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008950 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308951 cds_cfg->uc_tx_partition_base =
8952 hdd_ctx->config->IpaUcTxPartitionBase;
8953 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8954
8955 cds_cfg->ip_tcp_udp_checksum_offload =
8956 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008957 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308958 cds_cfg->ce_classify_enabled =
8959 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008960 cds_cfg->bpf_packet_filter_enable =
8961 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308962 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8963 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8964 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008965 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008966 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008967 cds_cfg->max_msdus_per_rxinorderind =
8968 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008969 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008970 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308971 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8972 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308973 cds_cfg->auto_power_save_fail_mode =
8974 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308975
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308976 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008977 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08008978 cds_cfg->delay_before_vdev_stop =
8979 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308980
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308981 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8982 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8983 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008984 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308985 cds_init_ini_config(cds_cfg);
8986 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308987
8988exit:
8989 qdf_mem_free(cds_cfg);
8990 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308991}
8992
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008993/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008994 * hdd_update_user_config() - API to update user configuration
8995 * parameters to obj mgr which are used by multiple components
8996 * @hdd_ctx: HDD Context
8997 *
8998 * Return: 0 for Success, errno on failure
8999 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009000static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009001{
9002 struct wlan_objmgr_psoc_user_config *user_config;
9003
9004 user_config = qdf_mem_malloc(sizeof(*user_config));
9005 if (user_config == NULL) {
9006 hdd_alert("Failed to alloc memory for user_config!");
9007 return -ENOMEM;
9008 }
9009
9010 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9011 user_config->dual_mac_feature_disable =
9012 hdd_ctx->config->dual_mac_feature_disable;
9013 user_config->indoor_channel_support =
9014 hdd_ctx->config->indoor_channel_support;
9015 user_config->is_11d_support_enabled =
9016 hdd_ctx->config->Is11dSupportEnabled;
9017 user_config->is_11h_support_enabled =
9018 hdd_ctx->config->Is11hSupportEnabled;
9019 user_config->optimize_chan_avoid_event =
9020 hdd_ctx->config->goptimize_chan_avoid_event;
9021 user_config->skip_dfs_chnl_in_p2p_search =
9022 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009023 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009024 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9025
9026 qdf_mem_free(user_config);
9027 return 0;
9028}
9029
9030/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009031 * hdd_init_thermal_info - Initialize thermal level
9032 * @hdd_ctx: HDD context
9033 *
9034 * Initialize thermal level at SME layer and set the thermal level callback
9035 * which would be called when a configured thermal threshold is hit.
9036 *
9037 * Return: 0 on success and errno on failure
9038 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009039static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009040{
9041 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309042 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009043
9044 thermal_param.smeThermalMgmtEnabled =
9045 hdd_ctx->config->thermalMitigationEnable;
9046 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9047
Poddar, Siddarth83905022016-04-16 17:56:08 -07009048 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9049 hdd_ctx->config->throttle_dutycycle_level0;
9050 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9051 hdd_ctx->config->throttle_dutycycle_level1;
9052 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9053 hdd_ctx->config->throttle_dutycycle_level2;
9054 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9055 hdd_ctx->config->throttle_dutycycle_level3;
9056
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009057 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9058 hdd_ctx->config->thermalTempMinLevel0;
9059 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9060 hdd_ctx->config->thermalTempMaxLevel0;
9061 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9062 hdd_ctx->config->thermalTempMinLevel1;
9063 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9064 hdd_ctx->config->thermalTempMaxLevel1;
9065 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9066 hdd_ctx->config->thermalTempMinLevel2;
9067 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9068 hdd_ctx->config->thermalTempMaxLevel2;
9069 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9070 hdd_ctx->config->thermalTempMinLevel3;
9071 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9072 hdd_ctx->config->thermalTempMaxLevel3;
9073
9074 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9075
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309076 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309077 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009078
9079 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9080 hdd_set_thermal_level_cb);
9081
9082 return 0;
9083
9084}
9085
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009086#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9087/**
9088 * hdd_hold_rtnl_lock - Hold RTNL lock
9089 *
9090 * Hold RTNL lock
9091 *
9092 * Return: True if held and false otherwise
9093 */
9094static inline bool hdd_hold_rtnl_lock(void)
9095{
9096 rtnl_lock();
9097 return true;
9098}
9099
9100/**
9101 * hdd_release_rtnl_lock - Release RTNL lock
9102 *
9103 * Release RTNL lock
9104 *
9105 * Return: None
9106 */
9107static inline void hdd_release_rtnl_lock(void)
9108{
9109 rtnl_unlock();
9110}
9111#else
9112static inline bool hdd_hold_rtnl_lock(void) { return false; }
9113static inline void hdd_release_rtnl_lock(void) { }
9114#endif
9115
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009116#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009117
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309118/* MAX iwpriv command support */
9119#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309120#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309121#define MAX_PKTLOG_SIZE 16
9122
9123/**
9124 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9125 * @hdd_ctx: hdd context
9126 * @set_value2: pktlog buffer size value
9127 *
9128 *
9129 * Return: 0 for success or error.
9130 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009131static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309132{
9133 struct sir_wifi_start_log start_log = { 0 };
9134 QDF_STATUS status;
9135
9136 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9137 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9138 start_log.ini_triggered = cds_is_packet_log_enabled();
9139 start_log.user_triggered = 1;
9140 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309141 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309142
9143 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9144 if (!QDF_IS_STATUS_SUCCESS(status)) {
9145 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009146 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309147 return -EINVAL;
9148 }
9149
9150 return 0;
9151}
9152
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009153/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309154 * hdd_pktlog_clear_buff() - clear pktlog buffer
9155 * @hdd_ctx: hdd context
9156 *
9157 * Return: 0 for success or error.
9158 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009159static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309160{
9161 struct sir_wifi_start_log start_log;
9162 QDF_STATUS status;
9163
9164 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9165 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9166 start_log.ini_triggered = cds_is_packet_log_enabled();
9167 start_log.user_triggered = 1;
9168 start_log.size = 0;
9169 start_log.is_pktlog_buff_clear = true;
9170
9171 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9172 if (!QDF_IS_STATUS_SUCCESS(status)) {
9173 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009174 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309175 return -EINVAL;
9176 }
9177
9178 return 0;
9179}
9180
9181
9182/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009183 * hdd_process_pktlog_command() - process pktlog command
9184 * @hdd_ctx: hdd context
9185 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309186 * @set_value2: pktlog buffer size value
9187 *
9188 * This function process pktlog command.
9189 * set_value2 only matters when set_value is 3 (set buff size)
9190 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009191 *
9192 * Return: 0 for success or error.
9193 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009194int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309195 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009196{
9197 int ret;
9198 bool enable;
9199 uint8_t user_triggered = 0;
9200
9201 ret = wlan_hdd_validate_context(hdd_ctx);
9202 if (0 != ret)
9203 return ret;
9204
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009205 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009206
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309207 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009208 hdd_err("invalid pktlog value %d", set_value);
9209 return -EINVAL;
9210 }
9211
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309212 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9213 if (set_value2 <= 0) {
9214 hdd_err("invalid pktlog size %d", set_value2);
9215 return -EINVAL;
9216 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9217 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9218 return -EINVAL;
9219 }
9220 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309221 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9222 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309223 }
9224
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009225 /*
9226 * set_value = 0 then disable packetlog
9227 * set_value = 1 enable packetlog forcefully
9228 * set_vlaue = 2 then disable packetlog if disabled through ini or
9229 * enable packetlog with AUTO type.
9230 */
9231 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9232 true : false;
9233
9234 if (1 == set_value) {
9235 enable = true;
9236 user_triggered = 1;
9237 }
9238
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309239 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009240}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009241
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009242/**
9243 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9244 * @hdd_ctx: HDD context
9245 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309246 * @user_triggered: triggered through iwpriv
9247 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009248 *
9249 * Return: 0 on success; error number otherwise
9250 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009251int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309252 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009253{
9254 struct sir_wifi_start_log start_log;
9255 QDF_STATUS status;
9256
9257 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9258 start_log.verbose_level =
9259 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009260 start_log.ini_triggered = cds_is_packet_log_enabled();
9261 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309262 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309263 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309264 /*
9265 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9266 * commands. Host uses this flag to decide whether to send pktlog
9267 * disable command to fw without sending pktlog enable command
9268 * previously. For eg, If vendor sends pktlog disable command without
9269 * sending pktlog enable command, then host discards the packet
9270 * but for iwpriv command, host will send it to fw.
9271 */
9272 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009273 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9274 if (!QDF_IS_STATUS_SUCCESS(status)) {
9275 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009276 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009277 return -EINVAL;
9278 }
9279
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309280 if (enable == true)
9281 hdd_ctx->is_pktlog_enabled = 1;
9282 else
9283 hdd_ctx->is_pktlog_enabled = 0;
9284
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009285 return 0;
9286}
9287#endif /* REMOVE_PKT_LOG */
9288
Komal Seelam92fff912016-03-24 11:51:41 +05309289/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009290 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9291 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309292 * @dev: Device Pointer
9293 * @num: Number of Valid Mac address
9294 *
9295 * Return: Pointer to MAC address buffer
9296 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009297static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9298 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309299{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009300 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309301}
Komal Seelam92fff912016-03-24 11:51:41 +05309302
9303/**
9304 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9305 * @hdd_ctx: HDD Context
9306 * @num: Number of random mac addresses needed
9307 *
9308 * Generate random addresses using bit manipulation on the base mac address
9309 *
9310 * Return: None
9311 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009312void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309313{
9314 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9315 uint32_t iter;
9316 struct hdd_config *ini = hdd_ctx->config;
9317 uint8_t *buf = NULL;
9318 uint8_t macaddr_b3, tmp_br3;
9319 uint8_t *src = ini->intfMacAddr[0].bytes;
9320
9321 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9322 buf = ini->intfMacAddr[iter].bytes;
9323 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9324 macaddr_b3 = buf[3];
9325 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9326 INTF_MACADDR_MASK;
9327 macaddr_b3 += tmp_br3;
9328 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9329 buf[0] |= 0x02;
9330 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009331 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309332 }
9333}
9334
9335/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009336 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309337 * @hdd_ctx: HDD Context
9338 *
9339 * API to get mac addresses from platform driver and update the driver
9340 * structures and configure FW with the base mac address.
9341 * Return: int
9342 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009343static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309344{
9345 uint32_t no_of_mac_addr, iter;
9346 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9347 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9348 uint8_t *addr, *buf;
9349 struct device *dev = hdd_ctx->parent_dev;
9350 struct hdd_config *ini = hdd_ctx->config;
9351 tSirMacAddr mac_addr;
9352 QDF_STATUS status;
9353
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009354 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309355
9356 if (no_of_mac_addr == 0 || !addr) {
9357 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9358 return -EINVAL;
9359 }
9360
9361 if (no_of_mac_addr > max_mac_addr)
9362 no_of_mac_addr = max_mac_addr;
9363
9364 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9365
9366 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9367 buf = ini->intfMacAddr[iter].bytes;
9368 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009369 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309370 }
9371
9372 status = sme_set_custom_mac_addr(mac_addr);
9373
9374 if (!QDF_IS_STATUS_SUCCESS(status))
9375 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009376
Komal Seelam92fff912016-03-24 11:51:41 +05309377 if (no_of_mac_addr < max_mac_addr)
9378 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9379 no_of_mac_addr);
9380 return 0;
9381}
9382
9383/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009384 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9385 * @hdd_ctx: HDD Context
9386 *
9387 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9388 * will generate its own MAC and update it to FW.
9389 *
9390 * Return: 0 for success
9391 * Non-zero error code for failure
9392 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009393static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009394{
9395 tSirMacAddr customMacAddr;
9396 QDF_STATUS status;
9397
9398 qdf_mem_copy(&customMacAddr,
9399 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9400 sizeof(tSirMacAddr));
9401 status = sme_set_custom_mac_addr(customMacAddr);
9402 if (!QDF_IS_STATUS_SUCCESS(status))
9403 return -EAGAIN;
9404 return 0;
9405}
9406
9407/**
Komal Seelam92fff912016-03-24 11:51:41 +05309408 * hdd_initialize_mac_address() - API to get wlan mac addresses
9409 * @hdd_ctx: HDD Context
9410 *
9411 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9412 * is provisioned with mac addresses, driver uses it, else it will use
9413 * wlan_mac.bin to update HW MAC addresses.
9414 *
9415 * Return: None
9416 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009417static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309418{
9419 QDF_STATUS status;
9420 int ret;
9421
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009422 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309423 if (ret == 0)
9424 return;
9425
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009426 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9427 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309428
9429 status = hdd_update_mac_config(hdd_ctx);
9430
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009431 if (QDF_IS_STATUS_SUCCESS(status))
9432 return;
9433
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009434 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9435 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009436
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009437 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009438 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009439 if (ret != 0) {
9440 hdd_err("MAC address out-of-sync, ret:%d", ret);
9441 QDF_ASSERT(ret);
9442 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009443 }
Komal Seelam92fff912016-03-24 11:51:41 +05309444}
9445
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009446static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009447{
9448 int vdev_id = 0;
9449 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9450 int value = hdd_ctx->config->smart_chainmask_enabled;
9451 int vpdev = PDEV_CMD;
9452 int ret;
9453
Naveen Rawat247a8682017-06-05 15:00:31 -07009454 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009455 if (ret)
9456 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9457
9458 return ret;
9459}
9460
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009461static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009462{
9463 int vdev_id = 0;
9464 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9465 int value = hdd_ctx->config->alternative_chainmask_enabled;
9466 int vpdev = PDEV_CMD;
9467 int ret;
9468
Naveen Rawat247a8682017-06-05 15:00:31 -07009469 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009470 if (ret)
9471 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9472 ret);
9473
9474 return ret;
9475}
9476
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009477static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009478{
9479 int vdev_id = 0;
9480 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9481 int value = hdd_ctx->config->ani_enabled;
9482 int vpdev = PDEV_CMD;
9483 int ret;
9484
Naveen Rawat247a8682017-06-05 15:00:31 -07009485 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009486 if (ret)
9487 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9488
9489 return ret;
9490}
9491
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009492/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009493 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9494 * @hdd_ctx: HDD context
9495 *
9496 * Pre configurations to be done at lower layer before calling cds enable.
9497 *
9498 * Return: 0 on success and errno on failure.
9499 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009500static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009501{
9502 int ret;
9503 QDF_STATUS status;
9504 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009505 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009506
Leo Changfdb45c32016-10-28 11:09:23 -07009507 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009508 /*
9509 * Set 802.11p config
9510 * TODO-OCB: This has been temporarily added here to ensure this
9511 * parameter is set in CSR when we init the channel list. This should
9512 * be removed once the 5.9 GHz channels are added to the regulatory
9513 * domain.
9514 */
9515 hdd_set_dot11p_config(hdd_ctx);
9516
9517 /*
9518 * Note that the cds_pre_enable() sequence triggers the cfg download.
9519 * The cfg download must occur before we update the SME config
9520 * since the SME config operation must access the cfg database
9521 */
9522 status = hdd_set_sme_config(hdd_ctx);
9523
9524 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009525 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009526 ret = qdf_status_to_os_return(status);
9527 goto out;
9528 }
9529
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009530 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9531 if (QDF_STATUS_SUCCESS != status) {
9532 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9533 ret = qdf_status_to_os_return(status);
9534 goto out;
9535 }
9536
Naveen Rawat247a8682017-06-05 15:00:31 -07009537 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009538 hdd_ctx->config->tx_chain_mask_1ss,
9539 PDEV_CMD);
9540 if (0 != ret) {
9541 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9542 goto out;
9543 }
9544
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009545 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9546 if (ret)
9547 goto out;
9548
9549 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9550 if (ret)
9551 goto out;
9552
Jeff Johnson12a744b2017-04-04 08:19:37 -07009553 ret = hdd_set_ani_enabled(hdd_ctx);
9554 if (ret)
9555 goto out;
9556
Naveen Rawat247a8682017-06-05 15:00:31 -07009557 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009558 hdd_ctx->config->arp_ac_category,
9559 PDEV_CMD);
9560 if (0 != ret) {
9561 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9562 hdd_ctx->config->arp_ac_category, ret);
9563 goto out;
9564 }
9565
Prashanth Bhatta07998752016-04-28 12:35:33 -07009566 status = hdd_set_sme_chan_list(hdd_ctx);
9567 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009568 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009569 ret = qdf_status_to_os_return(status);
9570 goto out;
9571 }
9572
9573 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009574 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009575 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009576 ret = -EINVAL;
9577 goto out;
9578 }
9579
Prashanth Bhatta07998752016-04-28 12:35:33 -07009580 /*
9581 * Set the MAC Address Currently this is used by HAL to add self sta.
9582 * Remove this once self sta is added as part of session open.
9583 */
9584 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9585 hdd_ctx->config->intfMacAddr[0].bytes,
9586 sizeof(hdd_ctx->config->intfMacAddr[0]));
9587
9588 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9589 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9590 hal_status, hal_status);
9591 ret = -EINVAL;
9592 goto out;
9593 }
9594
9595 hdd_init_channel_avoidance(hdd_ctx);
9596
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309597 /* update enable sap mandatory chan list */
9598 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9599 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009600out:
9601 return ret;
9602}
9603
9604/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009605 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9606 * @context_ptr - hdd context pointer
9607 * @event_ptr - event structure pointer
9608 *
9609 * This is the p2p listen offload stop event handler, it sends vendor
9610 * event back to supplicant to notify the stop reason.
9611 *
9612 * Return: None
9613 */
9614static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9615 void *event_ptr)
9616{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009617 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009618 struct sir_p2p_lo_event *evt = event_ptr;
9619 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009620 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009621
Dustin Brown491d54b2018-03-14 12:39:11 -07009622 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009623
9624 if (hdd_ctx == NULL) {
9625 hdd_err("Invalid HDD context pointer");
9626 return;
9627 }
9628
Peng Xu5c682812017-08-06 07:39:13 -07009629 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9630 if (!adapter) {
9631 hdd_err("Cannot find adapter by vdev_id = %d",
9632 evt->vdev_id);
9633 return;
9634 }
9635
Peng Xu8fdaa492016-06-22 10:20:47 -07009636 vendor_event =
9637 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009638 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009639 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9640 GFP_KERNEL);
9641
9642 if (!vendor_event) {
9643 hdd_err("cfg80211_vendor_event_alloc failed");
9644 return;
9645 }
9646
9647 if (nla_put_u32(vendor_event,
9648 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9649 evt->reason_code)) {
9650 hdd_err("nla put failed");
9651 kfree_skb(vendor_event);
9652 return;
9653 }
9654
9655 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009656 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9657 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009658}
9659
9660/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309661 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9662 * @hdd_ctx: HDD context
9663 *
9664 * This function sends the adaptive dwell time config configuration to the
9665 * firmware via WMA
9666 *
9667 * Return: 0 - success, < 0 - failure
9668 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009669static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309670{
9671 QDF_STATUS status;
9672 struct adaptive_dwelltime_params dwelltime_params;
9673
9674 dwelltime_params.is_enabled =
9675 hdd_ctx->config->adaptive_dwell_mode_enabled;
9676 dwelltime_params.dwelltime_mode =
9677 hdd_ctx->config->global_adapt_dwelltime_mode;
9678 dwelltime_params.lpf_weight =
9679 hdd_ctx->config->adapt_dwell_lpf_weight;
9680 dwelltime_params.passive_mon_intval =
9681 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9682 dwelltime_params.wifi_act_threshold =
9683 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9684
9685 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9686 &dwelltime_params);
9687
9688 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9689 if (!QDF_IS_STATUS_SUCCESS(status)) {
9690 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9691 return -EAGAIN;
9692 }
9693 return 0;
9694}
9695
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009696int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309697{
9698 QDF_STATUS status;
9699 struct wmi_dbs_scan_sel_params dbs_scan_params;
9700 uint32_t i = 0;
9701 uint8_t count = 0, numentries = 0;
9702 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9703 * CDS_DBS_SCAN_CLIENTS_MAX];
9704
9705 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +05309706 if ((hdd_ctx->config->dual_mac_feature_disable ==
9707 DISABLE_DBS_CXN_AND_SCAN) ||
9708 (hdd_ctx->config->dual_mac_feature_disable ==
9709 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309710 return -EINVAL;
9711
9712 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9713 dbs_scan_config, &numentries,
9714 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9715 * CDS_DBS_SCAN_CLIENTS_MAX));
9716
9717 hdd_info("numentries %hu", numentries);
9718 if (!numentries) {
9719 hdd_info("Donot send scan_selection_config");
9720 return 0;
9721 }
9722
9723 /* hdd_set_fw_log_params */
9724 dbs_scan_params.num_clients = 0;
9725 while (count < (numentries - 2)) {
9726 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9727 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9728 dbs_scan_params.num_non_dbs_scans[i] =
9729 dbs_scan_config[count + 2];
9730 dbs_scan_params.num_clients++;
9731 hdd_debug("module:%d NDS:%d NNDS:%d",
9732 dbs_scan_params.module_id[i],
9733 dbs_scan_params.num_dbs_scans[i],
9734 dbs_scan_params.num_non_dbs_scans[i]);
9735 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9736 i++;
9737 }
9738
9739 dbs_scan_params.pdev_id = 0;
9740
9741 hdd_debug("clients:%d pdev:%d",
9742 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9743
9744 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9745 &dbs_scan_params);
9746 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9747 if (!QDF_IS_STATUS_SUCCESS(status)) {
9748 hdd_err("Failed to send DBS Scan selection configuration!");
9749 return -EAGAIN;
9750 }
9751 return 0;
9752}
9753
Arun Khandavallid4349a92016-07-25 11:10:43 +05309754#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9755/**
9756 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9757 * @hdd_ctx: HDD context
9758 *
9759 * Set auto shutdown callback to get indications from firmware to indicate
9760 * userspace to shutdown WLAN after a configured amount of inactivity.
9761 *
9762 * Return: 0 on success and errno on failure.
9763 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009764static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309765{
9766 QDF_STATUS status;
9767
9768 if (!hdd_ctx->config->WlanAutoShutdown)
9769 return 0;
9770
9771 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9772 wlan_hdd_auto_shutdown_cb);
9773 if (status != QDF_STATUS_SUCCESS)
9774 hdd_err("Auto shutdown feature could not be enabled: %d",
9775 status);
9776
9777 return qdf_status_to_os_return(status);
9778}
9779#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009780static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309781{
9782 return 0;
9783}
9784#endif
9785
9786/**
9787 * hdd_features_init() - Init features
9788 * @hdd_ctx: HDD context
9789 * @adapter: Primary adapter context
9790 *
9791 * Initialize features and their feature context after WLAN firmware is up.
9792 *
9793 * Return: 0 on success and errno on failure.
9794 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009795static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309796{
9797 tSirTxPowerLimit hddtxlimit;
9798 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309799 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309800 int ret;
9801
Dustin Brown491d54b2018-03-14 12:39:11 -07009802 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309803
Arun Khandavallid4349a92016-07-25 11:10:43 +05309804 /* FW capabilities received, Set the Dot11 mode */
9805 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009806 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9807 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309808
Arun Khandavallid4349a92016-07-25 11:10:43 +05309809
9810 if (hdd_ctx->config->fIsImpsEnabled)
9811 hdd_set_idle_ps_config(hdd_ctx, true);
9812 else
9813 hdd_set_idle_ps_config(hdd_ctx, false);
9814
Poddar, Siddarth37033032017-10-11 15:47:40 +05309815 /* Send Enable/Disable data stall detection cmd to FW */
9816 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9817 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9818
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309819 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009820 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309821
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309822 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9823 hdd_warn("Error in setting Voltage Corner mode config to FW");
9824
Arun Khandavallid4349a92016-07-25 11:10:43 +05309825 if (hdd_lro_init(hdd_ctx))
9826 hdd_err("Unable to initialize LRO in fw");
9827
9828 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9829 hdd_err("Unable to send adaptive dwelltime setting to FW");
9830
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309831 if (hdd_dbs_scan_selection_init(hdd_ctx))
9832 hdd_err("Unable to send DBS scan selection setting to FW");
9833
Arun Khandavallid4349a92016-07-25 11:10:43 +05309834 ret = hdd_init_thermal_info(hdd_ctx);
9835 if (ret) {
9836 hdd_err("Error while initializing thermal information");
9837 goto deregister_frames;
9838 }
9839
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309840 /**
9841 * In case of SSR/PDR, if pktlog was enabled manually before
9842 * SSR/PDR, Then enabled it again automatically after Wlan
9843 * device up.
9844 */
9845 if (cds_is_driver_recovering()) {
9846 if (hdd_ctx->is_pktlog_enabled)
9847 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +08009848 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309849
Arun Khandavallid4349a92016-07-25 11:10:43 +05309850 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9851 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9852 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9853 if (!QDF_IS_STATUS_SUCCESS(status))
9854 hdd_err("Error setting txlimit in sme: %d", status);
9855
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009856 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309857
Arun Khandavallid4349a92016-07-25 11:10:43 +05309858 ret = hdd_register_cb(hdd_ctx);
9859 if (ret) {
9860 hdd_err("Failed to register HDD callbacks!");
9861 goto deregister_frames;
9862 }
9863
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309864 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9865 status = sme_enable_disable_chanavoidind_event(
9866 hdd_ctx->hHal, 0);
9867 if (!QDF_IS_STATUS_SUCCESS(status)) {
9868 hdd_err("Failed to disable Chan Avoidance Indication");
9869 goto deregister_cb;
9870 }
9871 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309872
Manjeet Singha9cae432017-02-28 11:58:22 +05309873 if (hdd_ctx->config->enable_5g_band_pref) {
9874 band_pref_params.rssi_boost_threshold_5g =
9875 hdd_ctx->config->rssi_boost_threshold_5g;
9876 band_pref_params.rssi_boost_factor_5g =
9877 hdd_ctx->config->rssi_boost_factor_5g;
9878 band_pref_params.max_rssi_boost_5g =
9879 hdd_ctx->config->max_rssi_boost_5g;
9880 band_pref_params.rssi_penalize_threshold_5g =
9881 hdd_ctx->config->rssi_penalize_threshold_5g;
9882 band_pref_params.rssi_penalize_factor_5g =
9883 hdd_ctx->config->rssi_penalize_factor_5g;
9884 band_pref_params.max_rssi_penalize_5g =
9885 hdd_ctx->config->max_rssi_penalize_5g;
9886 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9887 }
9888
Arun Khandavallid4349a92016-07-25 11:10:43 +05309889 /* register P2P Listen Offload event callback */
9890 if (wma_is_p2p_lo_capable())
9891 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9892 wlan_hdd_p2p_lo_event_callback);
9893
9894 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9895
9896 if (ret)
9897 goto deregister_cb;
9898
Dustin Brown11638b72018-01-25 17:37:25 +05309899 wlan_hdd_init_chan_info(hdd_ctx);
9900
Dustin Browne74003f2018-03-14 12:51:58 -07009901 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309902 return 0;
9903
9904deregister_cb:
9905 hdd_deregister_cb(hdd_ctx);
9906deregister_frames:
9907 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309908 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309909}
9910
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009911/**
9912 * hdd_features_deinit() - Deinit features
9913 * @hdd_ctx: HDD context
9914 *
9915 * De-Initialize features and their feature context.
9916 *
9917 * Return: none.
9918 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009919static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009920{
Dustin Brown11638b72018-01-25 17:37:25 +05309921 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009922 wlan_hdd_tsf_deinit(hdd_ctx);
9923}
9924
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309925/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009926 * hdd_register_bcn_cb() - register scan beacon callback
9927 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309928 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009929 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309930 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009931static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309932{
9933 QDF_STATUS status;
9934
9935 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9936 wlan_cfg80211_inform_bss_frame,
9937 SCAN_CB_TYPE_INFORM_BCN);
9938 if (!QDF_IS_STATUS_SUCCESS(status)) {
9939 hdd_err("failed with status code %08d [x%08x]",
9940 status, status);
9941 return status;
9942 }
9943
9944 return QDF_STATUS_SUCCESS;
9945}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309946
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309947/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309948 * hdd_configure_cds() - Configure cds modules
9949 * @hdd_ctx: HDD context
9950 * @adapter: Primary adapter context
9951 *
9952 * Enable Cds modules after WLAN firmware is up.
9953 *
9954 * Return: 0 on success and errno on failure.
9955 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009956int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309957{
9958 int ret;
9959 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309960 int set_value;
9961 uint32_t num_abg_tx_chains = 0;
9962 uint32_t num_11b_tx_chains = 0;
9963 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009964 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309965
9966 if (hdd_ctx->config->sifs_burst_duration) {
9967 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9968 hdd_ctx->config->sifs_burst_duration;
9969
9970 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9971 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9972 set_value, PDEV_CMD);
9973 }
9974
9975 if (hdd_ctx->config->is_force_1x1)
9976 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9977 1, PDEV_CMD);
9978 /* set chip power save failure detected callback */
9979 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9980 hdd_chip_pwr_save_fail_detected_cb);
9981
9982 if (hdd_ctx->config->max_mpdus_inampdu) {
9983 set_value = hdd_ctx->config->max_mpdus_inampdu;
9984 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9985 set_value, PDEV_CMD);
9986 }
9987
9988 if (hdd_ctx->config->enable_rts_sifsbursting) {
9989 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9990 sme_cli_set_command(0,
9991 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9992 set_value, PDEV_CMD);
9993 }
9994
9995 if (hdd_ctx->config->sap_get_peer_info) {
9996 set_value = hdd_ctx->config->sap_get_peer_info;
9997 sme_cli_set_command(0,
9998 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9999 set_value, PDEV_CMD);
10000 }
10001
10002 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10003 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10004 if (!hdd_ctx->config->enable2x2) {
10005 if (num_11b_tx_chains > 1)
10006 num_11b_tx_chains = 1;
10007 if (num_11ag_tx_chains > 1)
10008 num_11ag_tx_chains = 1;
10009 }
10010 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10011 num_11b_tx_chains);
10012 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10013 num_11ag_tx_chains);
10014 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10015 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010016
10017 ret = hdd_pre_enable_configure(hdd_ctx);
10018 if (ret) {
10019 hdd_err("Failed to pre-configure cds");
10020 goto out;
10021 }
10022
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010023 /* Always get latest IPA resources allocated from cds_open and configure
10024 * IPA module before configuring them to FW. Sequence required as crash
10025 * observed otherwise.
10026 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010027 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10028 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010029 hdd_err("Failed to setup pipes");
10030 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010031 }
10032
Arun Khandavallifae92942016-08-01 13:31:08 +053010033 /*
10034 * Start CDS which starts up the SME/MAC/HAL modules and everything
10035 * else
10036 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010037 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010038
10039 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010040 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010041 goto out;
10042 }
10043
10044 status = hdd_post_cds_enable_config(hdd_ctx);
10045 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010046 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010047 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010048 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010049 status = hdd_register_bcn_cb(hdd_ctx);
10050 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010051 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010052 goto cds_disable;
10053 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010054
10055 ret = hdd_features_init(hdd_ctx, adapter);
10056 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010057 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010058
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010059 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010060 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010061 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010062 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10063 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010064 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010065 goto cds_disable;
10066 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010067 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10068 wlan_hdd_send_mode_change_event);
10069 if (!QDF_IS_STATUS_SUCCESS(status)) {
10070 hdd_debug("Failed to register mode change cb with Policy Manager");
10071 goto cds_disable;
10072 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010073
Jeff Johnson8bb61112018-03-31 13:33:54 -070010074 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010075 hdd_debug("enhance green ap is not enabled");
10076
Nachiket Kukadedd302662017-07-13 17:31:44 +053010077 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10078 hdd_debug("Failed to set wow pulse");
10079
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010080 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10081 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010082 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10083 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10084
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010085
10086 if (hdd_ctx->config->enable_phy_reg_retention)
10087 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10088 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10089
Arun Khandavallifae92942016-08-01 13:31:08 +053010090 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010091
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010092cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010093 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010094
Arun Khandavallifae92942016-08-01 13:31:08 +053010095out:
10096 return -EINVAL;
10097}
10098
10099/**
10100 * hdd_deconfigure_cds() -De-Configure cds
10101 * @hdd_ctx: HDD context
10102 *
10103 * Deconfigure Cds modules before WLAN firmware is down.
10104 *
10105 * Return: 0 on success and errno on failure.
10106 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010107static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010108{
10109 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010110 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010111
Dustin Brown491d54b2018-03-14 12:39:11 -070010112 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010113
10114 /* De-init features */
10115 hdd_features_deinit(hdd_ctx);
10116
Arun Khandavallifae92942016-08-01 13:31:08 +053010117 /* De-register the SME callbacks */
10118 hdd_deregister_cb(hdd_ctx);
10119
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010120 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10121 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10122 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10123 }
10124
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010125 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010126 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10127 hdd_err("Failed to Disable the CDS Modules! :%d",
10128 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010129 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010130 }
10131
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010132 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010133 hdd_err("Failed to disconnect pipes");
10134 ret = -EINVAL;
10135 }
10136
Dustin Browne74003f2018-03-14 12:51:58 -070010137 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010138 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010139}
10140
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010141#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10142static void hdd_deregister_policy_manager_callback(
10143 struct wlan_objmgr_psoc *psoc)
10144{
10145 if (QDF_STATUS_SUCCESS !=
10146 policy_mgr_deregister_hdd_cb(psoc)) {
10147 hdd_err("HDD callback deregister with policy manager failed");
10148 }
10149}
10150#else
10151static void hdd_deregister_policy_manager_callback(
10152 struct wlan_objmgr_psoc *psoc)
10153{
10154}
10155#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010156
10157/**
10158 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10159 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010160 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010161 *
10162 * This function maintains the driver state machine it will be invoked from
10163 * exit, shutdown and con_mode change handler. Depending on the driver state
10164 * shall perform the stopping/closing of the modules.
10165 *
10166 * Return: 0 for success; non-zero for failure
10167 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010168int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010169{
10170 void *hif_ctx;
10171 qdf_device_t qdf_ctx;
10172 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010173 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010174 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010175 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10176 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010177 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010178 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010179
Dustin Brown491d54b2018-03-14 12:39:11 -070010180 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010181 hdd_alert("stop WLAN module: entering driver status=%d",
10182 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010183
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010184 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10185
Arun Khandavallifae92942016-08-01 13:31:08 +053010186 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10187 if (!qdf_ctx) {
10188 hdd_err("QDF device context NULL");
10189 return -EINVAL;
10190 }
10191
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010192 mutex_lock(&hdd_ctx->iface_change_lock);
10193 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010194 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010195
Dustin Brown70111822017-03-30 15:31:40 -070010196 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010197 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010198 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010199 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010200
10201 cds_print_external_threads();
10202
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010203 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010204 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010205 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10206 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010207 hdd_prevent_suspend_timeout(
10208 hdd_ctx->config->iface_change_wait_time,
10209 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010210 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010211 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010212 return 0;
10213 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010214 }
10215
Arun Khandavallifae92942016-08-01 13:31:08 +053010216 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10217
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010218 /* free user wowl patterns */
10219 hdd_free_user_wowl_ptrns();
10220
Arun Khandavallifae92942016-08-01 13:31:08 +053010221 switch (hdd_ctx->driver_status) {
10222 case DRIVER_MODULES_UNINITIALIZED:
10223 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010224 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010225 case DRIVER_MODULES_CLOSED:
10226 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010227 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010228 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010229 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10230
Komal Seelamf2136bb2016-09-28 18:30:44 +053010231 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010232 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010233 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010234 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010235 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010236 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010237 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010238
Arun Khandavallifae92942016-08-01 13:31:08 +053010239 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010240 hdd_info("Wlan transitioned (now OPENED)");
10241
10242 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010243 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010244 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010245 break;
10246 default:
10247 hdd_err("Trying to stop wlan in a wrong state: %d",
10248 hdd_ctx->driver_status);
10249 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010250 ret = -EINVAL;
10251 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010252 }
10253
Amar Singhal18081642018-01-26 16:04:13 -080010254 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010255 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010256
Rajeev Kumarbe021242017-02-16 16:12:23 -080010257 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010258 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10259 hdd_err("Failed to process post CDS disable Modules! :%d",
10260 qdf_status);
10261 ret = -EINVAL;
10262 QDF_ASSERT(0);
10263 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010264
psimhadeea0a12017-12-18 14:50:02 -080010265 hdd_runtime_suspend_context_deinit(hdd_ctx);
10266
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010267 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10268 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10269 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10270 ret = -EINVAL;
10271 QDF_ASSERT(0);
10272 }
10273
Jeff Johnsone4b14592017-09-13 14:23:33 -070010274 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010275 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010276 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010277 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010278 QDF_ASSERT(0);
10279 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010280
Amar Singhal410675c2018-01-10 12:14:21 -080010281 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010282 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10283 if (ret) {
10284 hdd_err("Failed to destroy pdev; errno:%d", ret);
10285 QDF_ASSERT(0);
10286 }
10287
10288 /*
10289 * Reset total mac phy during module stop such that during
10290 * next module start same psoc is used to populate new service
10291 * ready data
10292 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010293 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10294 if (tgt_hdl)
10295 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10296
Liangwei Dong50a64a72018-01-11 01:17:00 -050010297
Arun Khandavallifae92942016-08-01 13:31:08 +053010298 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10299 if (!hif_ctx) {
10300 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010301 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010302 }
10303
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010304 if (hdd_ctx->target_hw_name) {
10305 qdf_mem_free(hdd_ctx->target_hw_name);
10306 hdd_ctx->target_hw_name = NULL;
10307 }
10308
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010309 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010310
10311 ol_cds_free();
10312
Dustin Brown70111822017-03-30 15:31:40 -070010313 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010314 ret = pld_power_off(qdf_ctx->dev);
10315 if (ret)
10316 hdd_err("CNSS power down failed put device into Low power mode:%d",
10317 ret);
10318 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010319
Dustin Brown4bc0a622017-12-06 15:56:50 -080010320 /* many adapter resources are not freed by design in SSR case */
10321 if (!is_recovery_stop)
10322 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010323 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010324
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010325 /* Once the firmware sequence is completed reset this flag */
10326 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010327 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010328 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010329
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010330done:
10331 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010332 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010333 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010334 hdd_alert("stop WLAN module: exit driver status=%d",
10335 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010336
Dustin Browne74003f2018-03-14 12:51:58 -070010337 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010338
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010339 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010340}
10341
Arun Khandavallifae92942016-08-01 13:31:08 +053010342
10343/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010344 * hdd_state_info_dump() - prints state information of hdd layer
10345 * @buf: buffer pointer
10346 * @size: size of buffer to be filled
10347 *
10348 * This function is used to dump state information of hdd layer
10349 *
10350 * Return: None
10351 */
10352static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10353{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010354 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010355 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010356 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010357 uint16_t len = 0;
10358 char *buf = *buf_ptr;
10359
10360 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10361 if (!hdd_ctx) {
10362 hdd_err("Failed to get hdd context ");
10363 return;
10364 }
10365
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010366 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010367
10368 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010369 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010370 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010371 "\n is_scheduler_suspended %d",
10372 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010373
Dustin Brown920397d2017-12-13 16:27:50 -080010374 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010375 if (adapter->dev)
10376 len += scnprintf(buf + len, *size - len,
10377 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010378 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010379 "\n device_mode: %d", adapter->device_mode);
10380 switch (adapter->device_mode) {
10381 case QDF_STA_MODE:
10382 case QDF_P2P_CLIENT_MODE:
10383 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10384 len += scnprintf(buf + len, *size - len,
10385 "\n connState: %d",
10386 hdd_sta_ctx->conn_info.connState);
10387 break;
10388
10389 default:
10390 break;
10391 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010392 }
10393
10394 *size -= len;
10395 *buf_ptr += len;
10396}
10397
10398/**
10399 * hdd_register_debug_callback() - registration function for hdd layer
10400 * to print hdd state information
10401 *
10402 * Return: None
10403 */
10404static void hdd_register_debug_callback(void)
10405{
10406 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10407}
10408
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010409/*
10410 * wlan_init_bug_report_lock() - Initialize bug report lock
10411 *
10412 * This function is used to create bug report lock
10413 *
10414 * Return: None
10415 */
10416static void wlan_init_bug_report_lock(void)
10417{
10418 p_cds_contextType p_cds_context;
10419
10420 p_cds_context = cds_get_global_context();
10421 if (!p_cds_context) {
10422 hdd_err("cds context is NULL");
10423 return;
10424 }
10425
10426 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10427}
10428
Mohit Khannaf8f96822017-05-17 17:11:59 -070010429void hdd_dp_trace_init(struct hdd_config *config)
10430{
10431
10432 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10433 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10434 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10435 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10436 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10437 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10438 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010439 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010440
10441 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10442 &num_entries, sizeof(config_params));
10443
10444 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010445 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010446 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010447 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010448 else if (bw_compute_interval > 1000) {
10449 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10450 thresh_time_limit = 1;
10451 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010452 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10453
10454 switch (num_entries) {
10455 case 4:
10456 proto_bitmap = config_params[3];
10457 case 3:
10458 verbosity = config_params[2];
10459 case 2:
10460 thresh = config_params[1];
10461 case 1:
10462 live_mode = config_params[0];
10463 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010464 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010465 live_mode, thresh, thresh_time_limit,
10466 verbosity, proto_bitmap);
10467 };
10468
10469 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10470 verbosity, proto_bitmap);
10471
10472}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010473/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010474 * hdd_wlan_startup() - HDD init function
10475 * @dev: Pointer to the underlying device
10476 *
10477 * This is the driver startup code executed once a WLAN device has been detected
10478 *
10479 * Return: 0 for success, < 0 for failure
10480 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010481int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010482{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010483 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010484 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010485 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010486 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010487
Dustin Brown491d54b2018-03-14 12:39:11 -070010488 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010489
Arun Khandavallifae92942016-08-01 13:31:08 +053010490 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010491
10492 if (IS_ERR(hdd_ctx))
10493 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010494
Abhishek Singhe9068f12017-03-31 14:14:52 +053010495 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10496 DEFAULT_PSOC_ID);
10497 if (ret) {
10498 hdd_err("Psoc creation fails!");
10499 QDF_BUG(0);
10500 goto err_hdd_free_context;
10501 }
10502
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010503 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010504#ifdef FEATURE_WLAN_CH_AVOID
10505 mutex_init(&hdd_ctx->avoid_freq_lock);
10506#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010507
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010508 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010509 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010510
Dustin Brown021cecd2017-12-11 13:56:43 -080010511 hdd_driver_memdump_init();
10512
Jeff Johnson957bc272017-02-02 08:54:48 -080010513 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010514 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010515 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010516 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010517 }
10518
Yingying Tang80e15f32016-09-27 18:23:01 +080010519 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010520
Anurag Chouhan6d760662016-02-20 16:05:43 +053010521 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010522
10523 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010524 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010525 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010526 }
10527
Prashanth Bhatta07998752016-04-28 12:35:33 -070010528 ret = hdd_wiphy_init(hdd_ctx);
10529 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010530 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010531 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010532 }
10533
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010534 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010535 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010536
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010537 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010538
Paul Zhangfb02f452017-12-22 11:58:43 +080010539 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10540 if (ret) {
10541 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010542 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080010543 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010544
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010545 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010546
Jeff Johnson957bc272017-02-02 08:54:48 -080010547 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10548 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010549 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010550 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010551 }
10552
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010553 hdd_release_rtnl_lock();
10554 rtnl_held = false;
10555
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010556 wlan_hdd_update_11n_mode(hdd_ctx->config);
10557
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010558#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010559 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010560 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010561 hdd_skip_acs_scan_timer_handler,
10562 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010563 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010564 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010565 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010566#endif
10567
Prashanth Bhattaab004382016-10-11 16:08:11 -070010568 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010569
Jeff Johnson9afc5012016-09-23 13:56:27 -070010570 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010571
Nirav Shahbd36b062016-07-18 11:12:59 +053010572 if (hdd_ctx->rps)
10573 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010574
Paul Zhangfb02f452017-12-22 11:58:43 +080010575 ret = hdd_register_notifiers(hdd_ctx);
10576 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010577 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010578
Paul Zhangfb02f452017-12-22 11:58:43 +080010579 status = wlansap_global_init();
10580 if (QDF_IS_STATUS_ERROR(status)) {
10581 hdd_unregister_notifiers(hdd_ctx);
10582 goto err_close_adapters;
10583 }
10584
Arun Khandavallifae92942016-08-01 13:31:08 +053010585 if (hdd_ctx->config->fIsImpsEnabled)
10586 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010587 else
10588 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010589
Mukul Sharma07bd8752017-10-10 16:58:14 +053010590 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010591 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10592 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010593 hdd_prevent_suspend_timeout(
10594 hdd_ctx->config->iface_change_wait_time,
10595 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10596 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010598 goto success;
10599
Jeff Johnson957bc272017-02-02 08:54:48 -080010600err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010601 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010602
Jeff Johnson46bde382017-02-01 15:31:16 -080010603err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010604 if (rtnl_held)
10605 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010606
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010607 unregister_netdevice_notifier(&hdd_netdev_notifier);
10608
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010609err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010610 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010611
Arun Khandavallifae92942016-08-01 13:31:08 +053010612err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010613 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010614
Dustin Brown021cecd2017-12-11 13:56:43 -080010615err_memdump_deinit:
10616 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010617
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010618 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010619 hdd_exit_netlink_services(hdd_ctx);
10620
Dustin Brown20912462017-06-07 13:48:25 -070010621 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10622
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010623err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010624 if (cds_is_fw_down())
10625 hdd_err("Not setting the complete event as fw is down");
10626 else
10627 hdd_start_complete(ret);
10628
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010629 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010630 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010631 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010632
10633success:
Dustin Browne74003f2018-03-14 12:51:58 -070010634 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010635 return 0;
10636}
10637
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010638/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010639 * hdd_wlan_update_target_info() - update target type info
10640 * @hdd_ctx: HDD context
10641 * @context: hif context
10642 *
10643 * Update target info received from firmware in hdd context
10644 * Return:None
10645 */
10646
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010647void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010648{
10649 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10650
10651 if (!tgt_info) {
10652 hdd_err("Target info is Null");
10653 return;
10654 }
10655
10656 hdd_ctx->target_type = tgt_info->target_type;
10657}
10658
10659/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010660 * hdd_get_nud_stats_cb() - callback api to update the stats
10661 * received from the firmware
10662 * @data: pointer to adapter.
10663 * @rsp: pointer to data received from FW.
10664 *
10665 * This is called when wlan driver received response event for
10666 * get arp stats to firmware.
10667 *
10668 * Return: None
10669 */
10670static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10671{
10672 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10673 struct hdd_nud_stats_context *context;
10674 int status;
10675 struct hdd_adapter *adapter = NULL;
10676
Dustin Brown491d54b2018-03-14 12:39:11 -070010677 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010678
10679 if (!rsp) {
10680 hdd_err("data is null");
10681 return;
10682 }
10683
10684 status = wlan_hdd_validate_context(hdd_ctx);
10685 if (0 != status)
10686 return;
10687
10688 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10689 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10690 hdd_err("Invalid adapter or adapter has invalid magic");
10691 return;
10692 }
10693
Dustin Brown5e89ef82018-03-14 11:50:23 -070010694 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10695 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10696 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10697 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10698 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10699 rsp->out_of_order_arp_rsp_drop_cnt);
10700 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
10701 hdd_info("rsp->connect_status :%x", rsp->connect_status);
10702 hdd_info("rsp->ba_session_establishment_status :%x",
10703 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010704
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010705 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010706 adapter->dad |= rsp->dad_detected;
10707 adapter->con_status = rsp->connect_status;
10708
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053010709 /* Flag true indicates connectivity check stats present. */
10710 if (rsp->connect_stats_present) {
10711 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
10712 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
10713 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
10714 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
10715 rsp->icmpv4_rsp_recvd;
10716 }
10717
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010718 spin_lock(&hdd_context_lock);
10719 context = &hdd_ctx->nud_stats_context;
10720 complete(&context->response_event);
10721 spin_unlock(&hdd_context_lock);
10722
Dustin Browne74003f2018-03-14 12:51:58 -070010723 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010724}
10725
10726/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010727 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010728 * @hdd_ctx: HDD context
10729 *
10730 * Register the HDD callbacks to CDS/SME.
10731 *
10732 * Return: 0 for success or Error code for failure
10733 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010734int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010735{
10736 QDF_STATUS status;
10737 int ret = 0;
10738
Dustin Brown491d54b2018-03-14 12:39:11 -070010739 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010740
10741 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10742
10743 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10744 hdd_send_oem_data_rsp_msg);
10745
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010746 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10747 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010748 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10749 sme_nan_register_callback(hdd_ctx->hHal,
10750 wlan_hdd_cfg80211_nan_callback);
10751 sme_stats_ext_register_callback(hdd_ctx->hHal,
10752 wlan_hdd_cfg80211_stats_ext_callback);
10753
10754 sme_ext_scan_register_callback(hdd_ctx->hHal,
10755 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010756 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10757 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010758
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010759 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10760 hdd_rssi_threshold_breached);
10761
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010762 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10763
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010764 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10765 wlan_hdd_cfg80211_link_layer_stats_callback);
10766
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010767 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10768
Zhang Qianca38fb12016-12-23 11:10:48 +080010769 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10770 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10771
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010772 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10773 hdd_lost_link_info_cb);
10774 /* print error and not block the startup process */
10775 if (!QDF_IS_STATUS_SUCCESS(status))
10776 hdd_err("set lost link info callback failed");
10777
Poddar, Siddarth34872782017-08-10 14:08:51 +053010778 ret = hdd_register_data_stall_detect_cb();
10779 if (ret) {
10780 hdd_err("Register data stall detect detect callback failed.");
10781 return ret;
10782 }
10783
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010784 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10785
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010786 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010787 hdd_set_connection_in_progress,
10788 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010789
10790 status = sme_congestion_register_callback(hdd_ctx->hHal,
10791 hdd_update_cca_info_cb);
10792 if (!QDF_IS_STATUS_SUCCESS(status))
10793 hdd_err("set congestion callback failed");
10794
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010795 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10796 hdd_bt_activity_cb);
10797 if (!QDF_IS_STATUS_SUCCESS(status))
10798 hdd_err("set bt activity info callback failed");
10799
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010800 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10801 hdd_tx_queue_cb);
10802 if (!QDF_IS_STATUS_SUCCESS(status))
10803 hdd_err("Register tx queue callback failed");
10804
Dustin Browne74003f2018-03-14 12:51:58 -070010805 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010806
10807 return ret;
10808}
10809
10810/**
10811 * hdd_deregister_cb() - De-Register HDD callbacks.
10812 * @hdd_ctx: HDD context
10813 *
10814 * De-Register the HDD callbacks to CDS/SME.
10815 *
10816 * Return: void
10817 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010818void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010819{
10820 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010821 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010822
Dustin Brown491d54b2018-03-14 12:39:11 -070010823 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010824
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010825 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010826 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10827 if (!QDF_IS_STATUS_SUCCESS(status))
10828 hdd_err("De-register of dcc stats callback failed: %d",
10829 status);
10830
10831 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010832 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10833
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010834 sme_stats_ext_register_callback(hdd_ctx->hHal,
10835 wlan_hdd_cfg80211_stats_ext_callback);
10836
10837 sme_nan_deregister_callback(hdd_ctx->hHal);
10838 status = sme_reset_tsfcb(hdd_ctx->hHal);
10839 if (!QDF_IS_STATUS_SUCCESS(status))
10840 hdd_err("Failed to de-register tsfcb the callback:%d",
10841 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010842
Poddar, Siddarth34872782017-08-10 14:08:51 +053010843 ret = hdd_deregister_data_stall_detect_cb();
10844 if (ret)
10845 hdd_err("Failed to de-register data stall detect event callback");
10846
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010847 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10848 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10849
Dustin Browne74003f2018-03-14 12:51:58 -070010850 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010851}
10852
10853/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010854 * hdd_softap_sta_deauth() - handle deauth req from HDD
10855 * @adapter: Pointer to the HDD
10856 * @enable: bool value
10857 *
10858 * This to take counter measure to handle deauth req from HDD
10859 *
10860 * Return: None
10861 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010862QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010863 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010864{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010865 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010866
Dustin Brown491d54b2018-03-14 12:39:11 -070010867 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010868
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010869 /* Ignore request to deauth bcmc station */
10870 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010871 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010872
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010873 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010874 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10875 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010876
Dustin Browne74003f2018-03-14 12:51:58 -070010877 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010878 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010879}
10880
10881/**
10882 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10883 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010884 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010885 *
10886 * This to take counter measure to handle deauth req from HDD
10887 *
10888 * Return: None
10889 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010890void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010891 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010892{
Dustin Brown491d54b2018-03-14 12:39:11 -070010893 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010894
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010895 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010896 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010897 return;
10898
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010899 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010900 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010901}
10902
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010903/**
10904 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10905 * @hdd_ctx: HDD Context
10906 *
10907 * API to find if there is any STA or P2P-Client is connected
10908 *
10909 * Return: true if connected; false otherwise
10910 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010911QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010912{
10913 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10914}
10915
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010916/**
10917 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10918 * @adapter: HDD adapter pointer
10919 *
10920 * This function loop through each adapter and disable roaming on each STA
10921 * device mode except the input adapter.
10922 *
10923 * Note: On the input adapter roaming is not enabled yet hence no need to
10924 * disable.
10925 *
10926 * Return: None
10927 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010928void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010929{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010930 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010931 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010932
10933 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010934 hdd_ctx->config->isRoamOffloadScanEnabled &&
10935 QDF_STA_MODE == adapter->device_mode &&
10936 policy_mgr_is_sta_active_connection_exists(
10937 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010938 hdd_debug("Connect received on STA session Id(%d)",
10939 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010940 /*
10941 * Loop through adapter and disable roaming for each STA device
10942 * mode except the input adapter.
10943 */
Dustin Brown920397d2017-12-13 16:27:50 -080010944 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010945 if (QDF_STA_MODE == adapterIdx->device_mode &&
10946 adapter->session_id != adapterIdx->session_id) {
10947 hdd_debug("Disable Roaming on session Id(%d)",
10948 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010949 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10950 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010951 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010952 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010953 }
10954 }
10955}
10956
10957/**
10958 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10959 * @adapter: HDD adapter pointer
10960 *
10961 * This function loop through each adapter and enable roaming on each STA
10962 * device mode except the input adapter.
10963 * Note: On the input adapter no need to enable roaming because link got
10964 * disconnected on this.
10965 *
10966 * Return: None
10967 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010968void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010969{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010970 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010971 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010972
10973 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010974 hdd_ctx->config->isRoamOffloadScanEnabled &&
10975 QDF_STA_MODE == adapter->device_mode &&
10976 policy_mgr_is_sta_active_connection_exists(
10977 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010978 hdd_debug("Disconnect received on STA session Id(%d)",
10979 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010980 /*
10981 * Loop through adapter and enable roaming for each STA device
10982 * mode except the input adapter.
10983 */
Dustin Brown920397d2017-12-13 16:27:50 -080010984 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010985 if (QDF_STA_MODE == adapterIdx->device_mode &&
10986 adapter->session_id != adapterIdx->session_id) {
10987 hdd_debug("Enabling Roaming on session Id(%d)",
10988 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010989 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10990 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010991 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010992 REASON_CONNECT);
10993 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010994 }
10995 }
10996}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010997
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010998/**
10999 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11000 * @skb: sk buffer pointer
11001 *
11002 * Sends the bcast message to SVC multicast group with generic nl socket
11003 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11004 *
11005 * Return: None
11006 */
11007static void nl_srv_bcast_svc(struct sk_buff *skb)
11008{
11009#ifdef CNSS_GENL
11010 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11011#else
11012 nl_srv_bcast(skb);
11013#endif
11014}
11015
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011016void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011017{
11018 struct sk_buff *skb;
11019 struct nlmsghdr *nlh;
11020 tAniMsgHdr *ani_hdr;
11021 void *nl_data = NULL;
11022 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011023 struct radio_index_tlv *radio_info;
11024 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011025
11026 if (in_interrupt() || irqs_disabled() || in_atomic())
11027 flags = GFP_ATOMIC;
11028
11029 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11030
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011031 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011032 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011033
11034 nlh = (struct nlmsghdr *)skb->data;
11035 nlh->nlmsg_pid = 0; /* from kernel */
11036 nlh->nlmsg_flags = 0;
11037 nlh->nlmsg_seq = 0;
11038 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11039
11040 ani_hdr = NLMSG_DATA(nlh);
11041 ani_hdr->type = type;
11042
11043 switch (type) {
11044 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011045 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011046 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011047 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011048 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011049 ani_hdr->length = 0;
11050 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011051 break;
11052 case WLAN_SVC_WLAN_STATUS_IND:
11053 case WLAN_SVC_WLAN_VERSION_IND:
11054 case WLAN_SVC_DFS_CAC_START_IND:
11055 case WLAN_SVC_DFS_CAC_END_IND:
11056 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11057 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11058 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011059 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011060 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011061 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011062 ani_hdr->length = len;
11063 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11064 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11065 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011066 break;
11067
11068 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011069 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011070 type);
11071 kfree_skb(skb);
11072 return;
11073 }
11074
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011075 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011076 * Add radio index at the end of the svc event in TLV format
11077 * to maintain the backward compatibility with userspace
11078 * applications.
11079 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011080
11081 tlv_len = 0;
11082
11083 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11084 < WLAN_NL_MAX_PAYLOAD) {
11085 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11086 sizeof(*ani_hdr) + len);
11087 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11088 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11089 radio_info->radio = radio;
11090 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011091 hdd_debug("Added radio index tlv - radio index %d",
11092 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011093 }
11094
11095 nlh->nlmsg_len += tlv_len;
11096 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11097
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011098 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011099}
11100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011101#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11102void wlan_hdd_auto_shutdown_cb(void)
11103{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011104 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011105
11106 if (!hdd_ctx)
11107 return;
11108
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011109 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011110 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11111 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011112}
11113
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011114void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011115{
Jeff Johnson9d295242017-08-29 14:39:48 -070011116 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011117 bool ap_connected = false, sta_connected = false;
11118 tHalHandle hal_handle;
11119
11120 hal_handle = hdd_ctx->hHal;
11121 if (hal_handle == NULL)
11122 return;
11123
11124 if (hdd_ctx->config->WlanAutoShutdown == 0)
11125 return;
11126
11127 if (enable == false) {
11128 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011129 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011130 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011131 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011132 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011133 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011134 return;
11135 }
11136
11137 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011138 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11139 hdd_for_each_adapter(hdd_ctx, adapter) {
11140 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011141 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11142 conn_info.connState ==
11143 eConnectionState_Associated) {
11144 sta_connected = true;
11145 break;
11146 }
11147 }
Dustin Brown920397d2017-12-13 16:27:50 -080011148
11149 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011150 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011151 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011152 ap_connected = true;
11153 break;
11154 }
11155 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011156 }
11157 }
11158
11159 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011160 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011161 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011162 }
Jeff Johnson68755312017-02-10 11:46:55 -080011163
11164 if (sme_set_auto_shutdown_timer(hal_handle,
11165 hdd_ctx->config->WlanAutoShutdown)
11166 != QDF_STATUS_SUCCESS)
11167 hdd_err("Failed to start wlan auto shutdown timer");
11168 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011169 hdd_info("Auto Shutdown timer for %d seconds enabled",
11170 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011171}
11172#endif
11173
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011174struct hdd_adapter *
11175hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11176 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011177{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011178 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011179 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011180
11181 con_sap_adapter = NULL;
11182
Dustin Brown920397d2017-12-13 16:27:50 -080011183 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011184 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11185 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011186 adapter != this_sap_adapter) {
11187 if (check_start_bss) {
11188 if (test_bit(SOFTAP_BSS_STARTED,
11189 &adapter->event_flags)) {
11190 con_sap_adapter = adapter;
11191 break;
11192 }
11193 } else {
11194 con_sap_adapter = adapter;
11195 break;
11196 }
11197 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011198 }
11199
11200 return con_sap_adapter;
11201}
11202
11203#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011204static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011205{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011206 return adapter->device_mode == QDF_STA_MODE ||
11207 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011208}
11209
Jeff Johnson9d295242017-08-29 14:39:48 -070011210static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011211{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011212 return adapter->device_mode == QDF_SAP_MODE ||
11213 adapter->device_mode == QDF_P2P_GO_MODE;
11214}
11215
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011216static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011217{
Dustin Brown920397d2017-12-13 16:27:50 -080011218 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011219
Dustin Brown920397d2017-12-13 16:27:50 -080011220 hdd_for_each_adapter(hdd_ctx, adapter) {
11221 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011222 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11223 conn_info.connState == eConnectionState_Associated) {
11224 return true;
11225 }
11226
Dustin Brown920397d2017-12-13 16:27:50 -080011227 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011228 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011229 return true;
11230 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011231 }
11232
11233 return false;
11234}
11235
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011236static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011237{
11238 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011239
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011240 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011241 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011242 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011243
Dustin Brown5ec6b552017-03-31 12:11:40 -070011244 return is_running;
11245}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011246
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011247static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011248{
11249 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11250 hdd_ctx->bus_bw_timer_running = true;
11251 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11252 hdd_ctx->config->busBandwidthComputeInterval);
11253 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11254}
11255
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011256void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011257{
Dustin Brown491d54b2018-03-14 12:39:11 -070011258 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011259
11260 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11261 hdd_debug("Bandwidth compute timer already started");
11262 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011263 }
11264
Dustin Brown5ec6b552017-03-31 12:11:40 -070011265 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11266
Dustin Browne74003f2018-03-14 12:51:58 -070011267 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011268}
11269
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011270void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011271{
Dustin Brown491d54b2018-03-14 12:39:11 -070011272 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011273
11274 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11275 hdd_debug("Bandwidth compute timer already started");
11276 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011277 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011278
11279 if (hdd_any_adapter_is_assoc(hdd_ctx))
11280 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11281
Dustin Browne74003f2018-03-14 12:51:58 -070011282 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011283}
11284
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011285static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011286{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011287 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011288
11289 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11290 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11291 hdd_ctx->bus_bw_timer_running = false;
11292 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11293
11294 hdd_reset_tcp_delack(hdd_ctx);
11295}
11296
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011297void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011298{
Dustin Brown491d54b2018-03-14 12:39:11 -070011299 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011300
11301 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11302 hdd_debug("Bandwidth compute timer already stopped");
11303 return;
11304 }
11305
11306 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11307
Dustin Browne74003f2018-03-14 12:51:58 -070011308 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011309}
11310
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011311void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011312{
Dustin Brown491d54b2018-03-14 12:39:11 -070011313 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011314
11315 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11316 hdd_debug("Bandwidth compute timer already stopped");
11317 return;
11318 }
11319
11320 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11321 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11322
Dustin Browne74003f2018-03-14 12:51:58 -070011323 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011324}
11325#endif
11326
11327/**
11328 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11329 * and sta's operating channel.
11330 * @sta_adapter: Describe the first argument to foobar.
11331 * @ap_adapter: Describe the second argument to foobar.
11332 * @roam_profile: Roam profile of AP to which STA wants to connect.
11333 * @concurrent_chnl_same: If both SAP and STA channels are same then
11334 * set this flag to true else false.
11335 *
11336 * This function checks the sap's operating channel and sta's operating channel.
11337 * if both are same then it will return false else it will restart the sap in
11338 * sta's channel and return true.
11339 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011340 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011341 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011342QDF_STATUS
11343wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11344 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011345 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011346 tScanResultHandle *scan_cache,
11347 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011348{
Jeff Johnson87251032017-08-29 13:31:11 -070011349 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011350 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011351 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011352 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011353 *concurrent_chnl_same = true;
11354
11355 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11356 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011357 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011358 scan_cache,
11359 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011360 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011361 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011362 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011363 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011364 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011365 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011366 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011367 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011368 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011369 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011370 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011371 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011372 }
11373 }
11374 } else {
11375 /*
11376 * Lets handle worst case scenario here, Scan cache lookup is
11377 * failed so we have to stop the SAP to avoid any channel
11378 * discrepancy between SAP's channel and STA's channel.
11379 * Return the status as failure so caller function could know
11380 * that scan look up is failed.
11381 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011382 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011383 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011384 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011385 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011386}
11387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011388/**
11389 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11390 * @ap_adapter: SAP adapter
11391 *
11392 * This function will process the stopping of sap adapter.
11393 *
11394 * Return: None
11395 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011396void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011397{
Jeff Johnson87251032017-08-29 13:31:11 -070011398 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011399 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011400 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011401 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011402
11403 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011404 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011405 return;
11406 }
11407
11408 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11409 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011410 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011411 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011412
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011413 mutex_lock(&hdd_ctx->sap_lock);
11414 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011415 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011416 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011417 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011418 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011419 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011420 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011421 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011422 qdf_stop_bss_event,
11423 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011424 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011425 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011426 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011427 return;
11428 }
11429 }
11430 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011431 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11432 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011433 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011434 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011435 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011436 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011437 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011438 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011439 }
11440 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011441}
11442
11443/**
11444 * wlan_hdd_start_sap() - this function starts bss of SAP.
11445 * @ap_adapter: SAP adapter
11446 *
11447 * This function will process the starting of sap adapter.
11448 *
11449 * Return: None
11450 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011451void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011452{
Jeff Johnson87251032017-08-29 13:31:11 -070011453 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011454 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011455 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011456 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011457 tsap_Config_t *sap_config;
11458
11459 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011460 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011461 return;
11462 }
11463
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011464 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011465 hdd_err("SoftAp role has not been enabled");
11466 return;
11467 }
11468
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011469 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11470 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11471 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011472 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011473
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011474 mutex_lock(&hdd_ctx->sap_lock);
11475 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11476 goto end;
11477
11478 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011479 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011480 goto end;
11481 }
11482
Wei Song2f76f642016-11-18 16:32:53 +080011483 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011484 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011485 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011486 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011487 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011488 goto end;
11489
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011490 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011491 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011492 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011493 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011494 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011495 goto end;
11496 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011497 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011498 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011499 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011500 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011501 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11502 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011503 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011504 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011505 true);
11506 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011507 mutex_unlock(&hdd_ctx->sap_lock);
11508
11509 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011510end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011511 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011512 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011513 /* SAP context and beacon cleanup will happen during driver unload
11514 * in hdd_stop_adapter
11515 */
11516 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11517
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011518}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011519
11520/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011521 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11522 * mac scan config
11523 * @status: Status of set antenna mode
11524 *
11525 * Callback on setting the dual mac configuration
11526 *
11527 * Return: None
11528 */
11529void wlan_hdd_soc_set_antenna_mode_cb(
11530 enum set_antenna_mode_status status)
11531{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011532 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011533
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011534 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011535
11536 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11537 if (0 != wlan_hdd_validate_context(hdd_ctx))
11538 return;
11539
11540 /* Signal the completion of set dual mac config */
11541 complete(&hdd_ctx->set_antenna_mode_cmpl);
11542}
11543
11544/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011545 * hdd_get_fw_version() - Get FW version
11546 * @hdd_ctx: pointer to HDD context.
11547 * @major_spid: FW version - major spid.
11548 * @minor_spid: FW version - minor spid
11549 * @ssid: FW version - ssid
11550 * @crmid: FW version - crmid
11551 *
11552 * This function is called to get the firmware build version stored
11553 * as part of the HDD context
11554 *
11555 * Return: None
11556 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011557void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011558 uint32_t *major_spid, uint32_t *minor_spid,
11559 uint32_t *siid, uint32_t *crmid)
11560{
11561 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11562 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11563 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11564 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11565}
11566
11567#ifdef QCA_CONFIG_SMP
11568/**
11569 * wlan_hdd_get_cpu() - get cpu_index
11570 *
11571 * Return: cpu_index
11572 */
11573int wlan_hdd_get_cpu(void)
11574{
11575 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011576
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011577 put_cpu();
11578 return cpu_index;
11579}
11580#endif
11581
11582/**
11583 * hdd_get_fwpath() - get framework path
11584 *
11585 * This function is used to get the string written by
11586 * userspace to start the wlan driver
11587 *
11588 * Return: string
11589 */
11590const char *hdd_get_fwpath(void)
11591{
11592 return fwpath.string;
11593}
11594
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011595static int hdd_qdf_print_init(void)
11596{
11597 int qdf_print_idx;
11598 QDF_STATUS status;
11599
11600 status = qdf_print_setup();
11601 if (status != QDF_STATUS_SUCCESS) {
11602 pr_err("qdf_print_setup failed\n");
11603 return -EINVAL;
11604 }
11605
11606 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11607
11608 if (qdf_print_idx < 0) {
11609 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11610 qdf_print_idx);
11611 return -EINVAL;
11612 }
11613
11614 qdf_set_pidx(qdf_print_idx);
11615
11616 return 0;
11617}
11618
11619static void hdd_qdf_print_deinit(void)
11620{
11621 int qdf_print_idx;
11622
11623 qdf_print_idx = qdf_get_pidx();
11624 qdf_print_ctrl_cleanup(qdf_print_idx);
11625}
11626
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011627/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011628 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011629 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011630 * This function initilizes CDS global context with the help of cds_init. This
11631 * has to be the first function called after probe to get a valid global
11632 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011633 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011634 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011635 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011636int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011637{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011638 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011639 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011640
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011641 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011642 if (QDF_IS_STATUS_ERROR(status)) {
11643 hdd_err("Failed to allocate CDS context");
11644 ret = -ENOMEM;
11645 goto err_out;
11646 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011647
11648 wlan_init_bug_report_lock();
11649
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011650#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11651 wlan_logging_sock_init_svc();
11652#endif
11653
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011654 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11655 (void *)hdd_drv_ops_inactivity_handler, NULL,
11656 QDF_TIMER_TYPE_SW);
11657
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011658 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011659 hdd_qdf_print_init();
11660
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011661 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011662
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011663err_out:
11664 return ret;
11665}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011666
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011667/**
11668 * hdd_deinit() - Deinitialize Driver
11669 *
11670 * This function frees CDS global context with the help of cds_deinit. This
11671 * has to be the last function call in remove callback to free the global
11672 * context.
11673 */
11674void hdd_deinit(void)
11675{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011676 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011677
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011678 wlan_destroy_bug_report_lock();
11679 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011680
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011681 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011682#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11683 wlan_logging_sock_deinit_svc();
11684#endif
11685}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011686
Yue Ma6e7b1a02017-04-03 14:17:46 -070011687#ifdef QCA_WIFI_NAPIER_EMULATION
11688#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11689#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011690#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011691#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011692
Sachin Ahujadddd2632017-03-07 19:07:24 +053011693static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11694 struct file *file)
11695{
11696 return 0;
11697}
11698
11699static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11700 const char __user *user_buf,
11701 size_t count,
11702 loff_t *f_pos)
11703{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011704 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011705 static const char wlan_off_str[] = "OFF";
11706 static const char wlan_on_str[] = "ON";
11707 int ret;
11708 unsigned long rc;
11709
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011710 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011711 pr_err("Failed to read buffer\n");
11712 return -EINVAL;
11713 }
11714
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011715 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011716 pr_debug("Wifi turning off from UI\n");
11717 goto exit;
11718 }
11719
Sachin Ahuja16904db2017-12-13 19:56:57 +053011720 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
11721 pr_info("Wifi Turning On from UI\n");
11722 }
11723
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011724 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011725 pr_err("Invalid value received from framework");
11726 goto exit;
11727 }
11728
11729 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011730 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011731 rc = wait_for_completion_timeout(&wlan_start_comp,
11732 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11733 if (!rc) {
11734 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11735 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053011736 return ret;
11737 }
11738
11739 hdd_start_complete(0);
11740 }
11741
11742exit:
11743 return count;
11744}
11745
11746
11747const struct file_operations wlan_hdd_state_fops = {
11748 .owner = THIS_MODULE,
11749 .open = wlan_hdd_state_ctrl_param_open,
11750 .write = wlan_hdd_state_ctrl_param_write,
11751};
11752
11753static int wlan_hdd_state_ctrl_param_create(void)
11754{
11755 unsigned int wlan_hdd_state_major = 0;
11756 int ret;
11757 struct device *dev;
11758
11759 device = MKDEV(wlan_hdd_state_major, 0);
11760
11761 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11762 if (ret) {
11763 pr_err("Failed to register qcwlanstate");
11764 goto dev_alloc_err;
11765 }
11766 wlan_hdd_state_major = MAJOR(device);
11767
11768 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11769 if (IS_ERR(class)) {
11770 pr_err("wlan_hdd_state class_create error");
11771 goto class_err;
11772 }
11773
11774 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11775 if (IS_ERR(dev)) {
11776 pr_err("wlan_hdd_statedevice_create error");
11777 goto err_class_destroy;
11778 }
11779
11780 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11781 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11782 if (ret) {
11783 pr_err("Failed to add cdev error");
11784 goto cdev_add_err;
11785 }
11786
11787 pr_info("wlan_hdd_state %s major(%d) initialized",
11788 WLAN_MODULE_NAME, wlan_hdd_state_major);
11789
11790 return 0;
11791
11792cdev_add_err:
11793 device_destroy(class, device);
11794err_class_destroy:
11795 class_destroy(class);
11796class_err:
11797 unregister_chrdev_region(device, dev_num);
11798dev_alloc_err:
11799 return -ENODEV;
11800}
11801
11802static void wlan_hdd_state_ctrl_param_destroy(void)
11803{
11804 cdev_del(&wlan_hdd_state_cdev);
11805 device_destroy(class, device);
11806 class_destroy(class);
11807 unregister_chrdev_region(device, dev_num);
11808
11809 pr_info("Device node unregistered");
11810}
11811
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011812/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011813 * component_init - API to init cld component's
11814 *
11815 * Return: None
11816 */
11817static void component_init(void)
11818{
11819 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011820 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011821 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011822 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011823}
11824
11825/**
11826 * component_deinit - API to deinit cld component's
11827 *
11828 * Return: None
11829 */
11830static void component_deinit(void)
11831{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011832 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011833 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011834 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011835 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011836}
11837
11838void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11839{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011840 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011841 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011842}
11843
11844void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11845{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011846 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011847 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011848}
11849
11850/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011851 * __hdd_module_init - Module init helper
11852 *
11853 * Module init helper function used by both module and static driver.
11854 *
11855 * Return: 0 for success, errno on failure
11856 */
11857static int __hdd_module_init(void)
11858{
11859 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011860
Dustin Brown96cd9632017-11-13 12:45:04 -080011861 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011862 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011863 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080011864 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011865
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011866 pld_init();
11867
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011868 ret = hdd_init();
11869 if (ret) {
11870 pr_err("hdd_init failed %x\n", ret);
11871 goto err_hdd_init;
11872 }
11873
Rajeev Kumar97767a02016-11-30 11:20:40 -080011874 dispatcher_init();
11875
Mukul Sharmad75a6672017-06-22 15:40:53 +053011876 /* Ensure to call post objmgr init */
11877 component_init();
11878
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011879 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011880
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011881 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011882
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011883 ret = wlan_hdd_register_driver();
11884 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011885 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11886 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011887 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011888 }
11889
Sachin Ahuja16904db2017-12-13 19:56:57 +053011890 ret = wlan_hdd_state_ctrl_param_create();
11891 if (ret) {
11892 pr_err("wlan_hdd_state_create:%x\n", ret);
11893 goto out;
11894 }
11895
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011896 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011897
11898 return 0;
11899out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011900 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011901 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011902 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011903 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011904
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011905err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011906 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011907 return ret;
11908}
11909
11910/**
11911 * __hdd_module_exit - Module exit helper
11912 *
11913 * Module exit helper function used by both module and static driver.
11914 */
11915static void __hdd_module_exit(void)
11916{
Will Huang36049722018-04-13 11:48:51 +080011917 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011918
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011919 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11920 QWLAN_VERSIONSTR);
11921
Will Huang36049722018-04-13 11:48:51 +080011922 if (!hdd_ctx) {
11923 hdd_err("hdd context is NULL return!!");
11924 return;
11925 }
11926
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011927 hdd_wait_for_recovery_completion();
11928
Will Huang36049722018-04-13 11:48:51 +080011929 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
11930
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011931 wlan_hdd_unregister_driver();
11932
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011933 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011934
Mukul Sharmad75a6672017-06-22 15:40:53 +053011935 /* Ensure to call prior to objmgr deinit */
11936 component_deinit();
11937
Rajeev Kumar97767a02016-11-30 11:20:40 -080011938 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011939
11940 hdd_sysfs_destroy_version_interface();
11941
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011942 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011943 pld_deinit();
11944
Sachin Ahujadddd2632017-03-07 19:07:24 +053011945 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011946}
11947
Arun Khandavallifae92942016-08-01 13:31:08 +053011948#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011949/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011950 * wlan_boot_cb() - Wlan boot callback
11951 * @kobj: object whose directory we're creating the link in.
11952 * @attr: attribute the user is interacting with
11953 * @buff: the buffer containing the user data
11954 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011955 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011956 * This callback is invoked when the fs is ready to start the
11957 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011958 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011959 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011960 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011961static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011962 struct kobj_attribute *attr,
11963 const char *buf,
11964 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011965{
Arun Khandavallifae92942016-08-01 13:31:08 +053011966
Arun Khandavallifae92942016-08-01 13:31:08 +053011967 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011968 pr_err("%s: wlan driver already initialized\n", __func__);
11969 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011970 }
11971
Arun Khandavallifae92942016-08-01 13:31:08 +053011972 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011973 pr_err("%s: wlan driver initialization failed\n", __func__);
11974 return -EIO;
11975 }
11976
11977 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011978
11979 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011980}
Arun Khandavallifae92942016-08-01 13:31:08 +053011981
11982/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011983 * hdd_sysfs_cleanup() - cleanup sysfs
11984 *
11985 * Return: None
11986 *
11987 */
11988static void hdd_sysfs_cleanup(void)
11989{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011990 /* remove from group */
11991 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11992 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11993 wlan_loader->attr_group);
11994
11995 /* unlink the object from parent */
11996 kobject_del(wlan_loader->boot_wlan_obj);
11997
11998 /* free the object */
11999 kobject_put(wlan_loader->boot_wlan_obj);
12000
12001 kfree(wlan_loader->attr_group);
12002 kfree(wlan_loader);
12003
12004 wlan_loader = NULL;
12005}
12006
12007/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012008 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12009 * ready
12010 *
12011 * This is creates the syfs entry boot_wlan. Which shall be invoked
12012 * when the filesystem is ready.
12013 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012014 * QDF API cannot be used here since this function is called even before
12015 * initializing WLAN driver.
12016 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012017 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012018 */
12019static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012020{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012021 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012022
12023 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012024 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012025 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012026
12027 wlan_loader->boot_wlan_obj = NULL;
12028 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12029 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012030 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012031 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012032
12033 wlan_loader->loaded_state = 0;
12034 wlan_loader->attr_group->attrs = attrs;
12035
12036 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12037 kernel_kobj);
12038 if (!wlan_loader->boot_wlan_obj) {
12039 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012040 goto error_return;
12041 }
12042
12043 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12044 wlan_loader->attr_group);
12045 if (ret) {
12046 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12047 goto error_return;
12048 }
12049
12050 return 0;
12051
12052error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012053 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012054
12055 return ret;
12056}
12057
12058/**
12059 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12060 *
12061 * Return: 0 on success or errno on failure
12062 */
12063static int wlan_deinit_sysfs(void)
12064{
Arun Khandavallifae92942016-08-01 13:31:08 +053012065 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012066 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012067 return -EINVAL;
12068 }
12069
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012070 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012071 return 0;
12072}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012073
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012074#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012075
12076#ifdef MODULE
12077/**
12078 * __hdd_module_init - Module init helper
12079 *
12080 * Module init helper function used by both module and static driver.
12081 *
12082 * Return: 0 for success, errno on failure
12083 */
12084static int hdd_module_init(void)
12085{
Arun Khandavallifae92942016-08-01 13:31:08 +053012086 if (__hdd_module_init()) {
12087 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012088 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012089 }
12090
Dustin Brownab482ac2017-06-09 17:00:44 -070012091 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012092}
12093#else
12094static int __init hdd_module_init(void)
12095{
12096 int ret = -EINVAL;
12097
12098 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012099 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012100 pr_err("Failed to create sysfs entry for loading wlan");
12101
12102 return ret;
12103}
12104#endif
12105
12106
12107#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012108/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012109 * hdd_module_exit() - Exit function
12110 *
12111 * This is the driver exit point (invoked when module is unloaded using rmmod)
12112 *
12113 * Return: None
12114 */
12115static void __exit hdd_module_exit(void)
12116{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012117 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012118}
Arun Khandavallifae92942016-08-01 13:31:08 +053012119#else
12120static void __exit hdd_module_exit(void)
12121{
12122 __hdd_module_exit();
12123 wlan_deinit_sysfs();
12124}
12125#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012126
Srinivas Girigowda841da292018-02-21 16:33:00 -080012127static int fwpath_changed_handler(const char *kmessage,
12128 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012129{
12130 return param_set_copystring(kmessage, kp);
12131}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012132
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012133/**
12134 * is_con_mode_valid() check con mode is valid or not
12135 * @mode: global con mode
12136 *
12137 * Return: TRUE on success FALSE on failure
12138 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012139static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012140{
12141 switch (mode) {
12142 case QDF_GLOBAL_MONITOR_MODE:
12143 case QDF_GLOBAL_FTM_MODE:
12144 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012145 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012146 return true;
12147 default:
12148 return false;
12149 }
12150}
12151
12152/**
12153 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12154 * @mode: global con mode
12155 *
12156 * Return: adapter mode
12157 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012158static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012159 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012160{
12161
12162 switch (mode) {
12163 case QDF_GLOBAL_MISSION_MODE:
12164 return QDF_STA_MODE;
12165 case QDF_GLOBAL_MONITOR_MODE:
12166 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012167 case QDF_GLOBAL_EPPING_MODE:
12168 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012169 case QDF_GLOBAL_FTM_MODE:
12170 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012171 case QDF_GLOBAL_QVIT_MODE:
12172 return QDF_QVIT_MODE;
12173 default:
12174 return QDF_MAX_NO_OF_MODE;
12175 }
12176}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012177
Dustin Brown27cd9942017-09-27 16:11:44 -070012178static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012179 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012180{
12181 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12182 return;
12183
12184 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012185 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012186 hdd_info("Release wakelock for monitor mode!");
12187 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12188 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12189 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012190 case QDF_GLOBAL_FTM_MODE:
12191 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012192 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012193 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012194
Dustin Brown27cd9942017-09-27 16:11:44 -070012195 break;
12196 default:
12197 break;
12198 }
12199}
12200
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012201static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012202 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012203{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012204 int driver_status;
12205
12206 driver_status = hdd_ctx->driver_status;
12207
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012208 switch (curr_mode) {
12209 case QDF_GLOBAL_MISSION_MODE:
12210 case QDF_GLOBAL_MONITOR_MODE:
12211 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012212 hdd_deinit_all_adapters(hdd_ctx, false);
12213 hdd_close_all_adapters(hdd_ctx, false);
12214 break;
12215 case QDF_GLOBAL_EPPING_MODE:
12216 epping_disable();
12217 epping_close();
12218 break;
12219 default:
12220 return;
12221 }
12222}
12223
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012224static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012225 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012226{
Jeff Johnson9d295242017-08-29 14:39:48 -070012227 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012228 int ret = 0;
12229 bool rtnl_held;
12230 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12231 QDF_STATUS status;
12232
12233 if (!qdf_dev) {
12234 hdd_err("qdf device context is Null return!");
12235 return -EINVAL;
12236 }
12237
12238 rtnl_held = hdd_hold_rtnl_lock();
12239 switch (mode) {
12240 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012241 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12242 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012243 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012244 break;
12245 case QDF_GLOBAL_FTM_MODE:
12246 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12247 wlan_hdd_get_intf_addr(hdd_ctx),
12248 NET_NAME_UNKNOWN, rtnl_held);
12249 if (adapter == NULL)
12250 ret = -EINVAL;
12251 break;
12252 case QDF_GLOBAL_MONITOR_MODE:
12253 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12254 wlan_hdd_get_intf_addr(hdd_ctx),
12255 NET_NAME_UNKNOWN, rtnl_held);
12256 if (adapter == NULL)
12257 ret = -EINVAL;
12258 break;
12259 case QDF_GLOBAL_EPPING_MODE:
12260 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012261 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012262 hdd_err("Failed to open in eeping mode: %d", status);
12263 ret = -EINVAL;
12264 break;
12265 }
12266 ret = epping_enable(qdf_dev->dev);
12267 if (ret) {
12268 hdd_err("Failed to enable in epping mode : %d", ret);
12269 epping_close();
12270 }
12271 break;
12272 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012273 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012274 ret = -ENOTSUPP;
12275 break;
12276 }
12277 hdd_release_rtnl_lock();
12278 rtnl_held = false;
12279 return ret;
12280}
12281
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012282/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012283 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012284 * @kmessage: con mode name on which driver to be bring up
12285 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012286 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012287 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012288 * This function is invoked when user updates con mode using sys entry,
12289 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012290 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012291 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012292 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012293static int __con_mode_handler(const char *kmessage,
12294 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012295 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012296{
12297 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012298 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012299 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012300 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012301 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012302
Dustin Brownab6029b2017-05-24 13:04:19 -070012303 hdd_info("con_mode handler: %s", kmessage);
12304
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012305 ret = wlan_hdd_validate_context(hdd_ctx);
12306 if (ret)
12307 return ret;
12308
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012309 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012310 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012311
Dustin Brown20024e32018-01-03 12:34:58 -080012312 ret = kstrtoint(kmessage, 0, &new_con_mode);
12313 if (ret) {
12314 hdd_err("Failed to parse con_mode '%s'", kmessage);
12315 goto reset_flags;
12316 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012317 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012318
Dustin Brown20024e32018-01-03 12:34:58 -080012319 if (!is_con_mode_valid(new_con_mode)) {
12320 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012321 ret = -EINVAL;
12322 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012323 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012324
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012325 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012326 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012327 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012328 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012329 ret = 0;
12330 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012331 }
12332
Dustin Brown27cd9942017-09-27 16:11:44 -070012333 /* ensure adapters are stopped */
12334 hdd_stop_present_mode(hdd_ctx, curr_mode);
12335
Frank Liu6666f832018-01-04 10:06:05 +080012336 /* Cleanup present mode before switching to new mode */
12337 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12338
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012339 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012340 if (ret) {
12341 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012342 goto reset_flags;
12343 }
12344
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012345
Dustin Brown20024e32018-01-03 12:34:58 -080012346 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012347
Frank Liu6666f832018-01-04 10:06:05 +080012348 /*
12349 * Set ACTIVE domain before adapters created, otherwise check domain
12350 * match will fail when cleanup adapters.
12351 */
12352 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012353 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012354 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012355 if (ret) {
12356 hdd_err("Failed to register for new mode");
12357 goto reset_flags;
12358 }
12359
Dustin Brown20024e32018-01-03 12:34:58 -080012360 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012361 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12362 hdd_err("invalid adapter");
12363 ret = -EINVAL;
12364 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012365 }
12366
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012367 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012368 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012369 hdd_err("Failed to get adapter:%d", adapter_mode);
12370 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012371 }
12372
12373 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12374 if (ret) {
12375 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012376 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012377 }
12378
Dustin Brown20024e32018-01-03 12:34:58 -080012379 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012380 if (hdd_start_adapter(adapter)) {
12381 hdd_err("Failed to start %s adapter", kmessage);
12382 ret = -EINVAL;
12383 goto reset_flags;
12384 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012385
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012386 hdd_info("Acquire wakelock for monitor mode!");
12387 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12388 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12389 }
12390
Dustin Brown20024e32018-01-03 12:34:58 -080012391 /* con_mode is a global module parameter */
12392 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012393 hdd_info("Mode successfully changed to %s", kmessage);
12394 ret = 0;
12395
12396reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012397 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012398 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012399 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012400 return ret;
12401}
12402
12403
Srinivas Girigowda841da292018-02-21 16:33:00 -080012404static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012405{
12406 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012407 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012408
12409 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12410 ret = wlan_hdd_validate_context(hdd_ctx);
12411 if (ret)
12412 return ret;
12413
12414 cds_ssr_protect(__func__);
12415 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12416 cds_ssr_unprotect(__func__);
12417
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012418 return ret;
12419}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012420
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012421static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012422 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012423{
12424 int ret;
12425
12426 ret = param_set_int(kmessage, kp);
12427
12428 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12429 pr_err("Only FTM mode supported!");
12430 return -ENOTSUPP;
12431 }
12432
12433 hdd_set_conparam(con_mode_ftm);
12434 con_mode = con_mode_ftm;
12435
12436 return ret;
12437}
12438
Ravi Joshia307f632017-07-17 23:41:41 -070012439static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012440 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012441{
12442 int ret;
12443
12444 ret = param_set_int(kmessage, kp);
12445
12446 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12447 pr_err("Only Monitor mode supported!");
12448 return -ENOTSUPP;
12449 }
12450
12451 hdd_set_conparam(con_mode_monitor);
12452 con_mode = con_mode_monitor;
12453
12454 return ret;
12455}
12456
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012457/**
12458 * hdd_get_conparam() - driver exit point
12459 *
12460 * This is the driver exit point (invoked when module is unloaded using rmmod)
12461 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012462 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012463 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012464enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012465{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012466 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012467}
12468
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012469void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012470{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012471 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012472}
12473
Komal Seelamc11bb222016-01-27 18:57:10 +053012474/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012475 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12476 * @hdd_ctx: HDD context
12477 *
12478 * Cleans up the pre cac interface, if it exists
12479 *
12480 * Return: None
12481 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012482void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012483{
12484 uint8_t session_id;
12485 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012486 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012487
12488 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12489 if (QDF_IS_STATUS_ERROR(status)) {
12490 hdd_err("failed to get pre cac vdev id");
12491 return;
12492 }
12493
12494 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12495 if (!precac_adapter) {
12496 hdd_err("invalid pre cac adapater");
12497 return;
12498 }
12499
12500 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12501 wlan_hdd_sap_pre_cac_failure,
12502 (void *)precac_adapter);
12503 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12504
12505}
12506
12507/**
Komal Seelamec702b02016-02-24 18:42:16 +053012508 * hdd_update_ol_config - API to update ol configuration parameters
12509 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012510 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012511 * Return: void
12512 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012513static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012514{
Komal Seelamec702b02016-02-24 18:42:16 +053012515 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012516 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012517
Komal Seelamec702b02016-02-24 18:42:16 +053012518 if (!ol_ctx)
12519 return;
12520
12521 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12522 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12523 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12524 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012525 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012526
12527 ol_init_ini_config(ol_ctx, &cfg);
12528}
12529
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012530#ifdef FEATURE_RUNTIME_PM
12531/**
12532 * hdd_populate_runtime_cfg() - populate runtime configuration
12533 * @hdd_ctx: hdd context
12534 * @cfg: pointer to the configuration memory being populated
12535 *
12536 * Return: void
12537 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012538static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012539 struct hif_config_info *cfg)
12540{
12541 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12542 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12543}
12544#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012545static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012546 struct hif_config_info *cfg)
12547{
12548}
12549#endif
12550
Komal Seelamec702b02016-02-24 18:42:16 +053012551/**
12552 * hdd_update_hif_config - API to update HIF configuration parameters
12553 * @hdd_ctx: HDD Context
12554 *
12555 * Return: void
12556 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012557static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012558{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012559 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012560 struct hif_config_info cfg;
12561
12562 if (!scn)
12563 return;
12564
12565 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012566 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012567 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012568
12569 if (hdd_ctx->config->prevent_link_down)
12570 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012571}
12572
12573/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012574 * hdd_update_dp_config() - Propagate config parameters to Lithium
12575 * datapath
12576 * @hdd_ctx: HDD Context
12577 *
12578 * Return: 0 for success/errno for failure
12579 */
12580static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12581{
12582 struct cdp_config_params params;
12583 QDF_STATUS status;
12584
12585 params.tso_enable = hdd_ctx->config->tso_enable;
12586 params.lro_enable = hdd_ctx->config->lro_enable;
12587#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12588 params.tx_flow_stop_queue_threshold =
12589 hdd_ctx->config->TxFlowStopQueueThreshold;
12590 params.tx_flow_start_queue_offset =
12591 hdd_ctx->config->TxFlowStartQueueOffset;
12592#endif
12593 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12594 params.napi_enable = hdd_ctx->napi_enable;
12595 params.tcp_udp_checksumoffload =
12596 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12597
12598 status = cdp_update_config_parameters(
12599 cds_get_context(QDF_MODULE_ID_SOC),
12600 &params);
12601 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012602 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012603 return status;
12604 }
12605
12606 return 0;
12607}
12608
12609/**
Komal Seelamec702b02016-02-24 18:42:16 +053012610 * hdd_update_config() - Initialize driver per module ini parameters
12611 * @hdd_ctx: HDD Context
12612 *
12613 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012614 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012615 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012616int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012617{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012618 int ret;
12619
Komal Seelamec702b02016-02-24 18:42:16 +053012620 hdd_update_ol_config(hdd_ctx);
12621 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012622 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12623 ret = hdd_update_cds_config_ftm(hdd_ctx);
12624 else
12625 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012626 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012627
12628 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012629}
12630
Mukul Sharma9d797a02017-01-05 20:26:03 +053012631#ifdef FEATURE_WLAN_RA_FILTERING
12632/**
12633 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12634 * @psoc_cfg: pmo psoc Configuration
12635 * @hdd_ctx: Pointer to hdd context
12636 *
12637 * Return: none
12638 */
12639static inline void hdd_ra_populate_pmo_config(
12640 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012641 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012642{
12643 psoc_cfg->ra_ratelimit_interval =
12644 hdd_ctx->config->RArateLimitInterval;
12645 psoc_cfg->ra_ratelimit_enable =
12646 hdd_ctx->config->IsRArateLimitEnabled;
12647}
12648#else
12649static inline void hdd_ra_populate_pmo_config(
12650 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012651 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012652{
12653}
12654#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012655
Mukul Sharma9d797a02017-01-05 20:26:03 +053012656/**
12657 * hdd_update_pmo_config - API to update pmo configuration parameters
12658 * @hdd_ctx: HDD context
12659 *
12660 * Return: void
12661 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012662static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012663{
Mukul Sharma9d797a02017-01-05 20:26:03 +053012664 struct pmo_psoc_cfg psoc_cfg;
12665 QDF_STATUS status;
12666
12667 /*
12668 * Value of hdd_ctx->wowEnable can be,
12669 * 0 - Disable both magic pattern match and pattern byte match.
12670 * 1 - Enable magic pattern match on all interfaces.
12671 * 2 - Enable pattern byte match on all interfaces.
12672 * 3 - Enable both magic patter and pattern byte match on
12673 * all interfaces.
12674 */
12675 psoc_cfg.magic_ptrn_enable =
12676 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12677 psoc_cfg.ptrn_match_enable_all_vdev =
12678 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080012679 psoc_cfg.ptrn_id_per_vdev =
12680 wma_is_service_enabled(wmi_service_unified_wow_capability);
12681 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012682 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012683 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080012684 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012685 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080012686 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012687 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12688 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080012689 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012690 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012691 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053012692 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12693 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12694 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080012695 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012696 psoc_cfg.auto_power_save_fail_mode =
12697 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012698
12699 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012700 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12701 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012702
Dustin Brownb9987af2018-03-01 17:15:11 -080012703 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
12704 if (QDF_IS_STATUS_ERROR(status))
12705 hdd_err("failed pmo psoc configuration; status:%d", status);
12706
12707 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012708}
12709
Abhishek Singhb20db962017-03-03 21:28:46 +053012710#ifdef FEATURE_WLAN_SCAN_PNO
12711static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12712 struct hdd_config *cfg)
12713{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012714 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12715
Abhishek Singhb20db962017-03-03 21:28:46 +053012716 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12717 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12718 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12719 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12720 pno_cfg->channel_prediction_full_scan =
12721 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012722 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12723 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12724 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12725 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012726}
12727#else
12728static inline void
12729hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012730 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012731{
Abhishek Singhb20db962017-03-03 21:28:46 +053012732}
12733#endif
12734
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012735void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12736 struct hdd_config *cfg)
12737{
12738 uint8_t i = 0;
12739
12740 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12741 if (!ie_whitelist->white_list)
12742 return;
12743
12744 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12745 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12746 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12747 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12748 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12749 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12750 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12751 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12752
12753 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12754 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12755 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12756}
12757
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012758uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12759{
12760 uint8_t i, score;
12761
12762 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12763 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12764 if (score > MAX_INDEX_SCORE)
12765 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12766 MAX_INDEX_SCORE, i);
12767 }
12768
12769 return per_index_score;
12770}
12771
12772/**
12773 * hdd_update_score_config - API to update candidate scoring related params
12774 * configuration parameters
12775 * @score_config: score config to update
12776 * @cfg: config params
12777 *
12778 * Return: 0 if success else err
12779 */
12780static void hdd_update_score_config(
12781 struct scoring_config *score_config, struct hdd_config *cfg)
12782{
12783 int total_weight;
12784
12785 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12786 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12787 score_config->weight_cfg.vht_caps_weightage =
12788 cfg->vht_caps_weightage;
12789 score_config->weight_cfg.he_caps_weightage =
12790 cfg->he_caps_weightage;
12791 score_config->weight_cfg.chan_width_weightage =
12792 cfg->chan_width_weightage;
12793 score_config->weight_cfg.chan_band_weightage =
12794 cfg->chan_band_weightage;
12795 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12796 score_config->weight_cfg.beamforming_cap_weightage =
12797 cfg->beamforming_cap_weightage;
12798 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12799 score_config->weight_cfg.channel_congestion_weightage =
12800 cfg->channel_congestion_weightage;
12801 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12802
12803 total_weight = score_config->weight_cfg.rssi_weightage +
12804 score_config->weight_cfg.ht_caps_weightage +
12805 score_config->weight_cfg.vht_caps_weightage +
12806 score_config->weight_cfg.he_caps_weightage +
12807 score_config->weight_cfg.chan_width_weightage +
12808 score_config->weight_cfg.chan_band_weightage +
12809 score_config->weight_cfg.nss_weightage +
12810 score_config->weight_cfg.beamforming_cap_weightage +
12811 score_config->weight_cfg.pcl_weightage +
12812 score_config->weight_cfg.channel_congestion_weightage +
12813 score_config->weight_cfg.oce_wan_weightage;
12814
12815 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12816 hdd_err("total weight is greater than %d fallback to default values",
12817 BEST_CANDIDATE_MAX_WEIGHT);
12818
12819 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12820 score_config->weight_cfg.ht_caps_weightage =
12821 HT_CAPABILITY_WEIGHTAGE;
12822 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12823 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12824 score_config->weight_cfg.chan_width_weightage =
12825 CHAN_WIDTH_WEIGHTAGE;
12826 score_config->weight_cfg.chan_band_weightage =
12827 CHAN_BAND_WEIGHTAGE;
12828 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12829 score_config->weight_cfg.beamforming_cap_weightage =
12830 BEAMFORMING_CAP_WEIGHTAGE;
12831 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12832 score_config->weight_cfg.channel_congestion_weightage =
12833 CHANNEL_CONGESTION_WEIGHTAGE;
12834 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12835 }
12836
12837 score_config->bandwidth_weight_per_index =
12838 hdd_limit_max_per_index_score(
12839 cfg->bandwidth_weight_per_index);
12840 score_config->nss_weight_per_index =
12841 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12842 score_config->band_weight_per_index =
12843 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12844
12845 score_config->rssi_score.best_rssi_threshold =
12846 cfg->best_rssi_threshold;
12847 score_config->rssi_score.good_rssi_threshold =
12848 cfg->good_rssi_threshold;
12849 score_config->rssi_score.bad_rssi_threshold =
12850 cfg->bad_rssi_threshold;
12851 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12852 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12853 score_config->rssi_score.good_rssi_bucket_size =
12854 cfg->good_rssi_bucket_size;
12855 score_config->rssi_score.bad_rssi_bucket_size =
12856 cfg->bad_rssi_bucket_size;
12857 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12858 cfg->rssi_pref_5g_rssi_thresh;
12859
12860 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12861 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12862 hdd_limit_max_per_index_score(
12863 cfg->esp_qbss_score_slots3_to_0);
12864 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12865 hdd_limit_max_per_index_score(
12866 cfg->esp_qbss_score_slots7_to_4);
12867 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12868 hdd_limit_max_per_index_score(
12869 cfg->esp_qbss_score_slots11_to_8);
12870 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12871 hdd_limit_max_per_index_score(
12872 cfg->esp_qbss_score_slots15_to_12);
12873
12874 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12875 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12876 hdd_limit_max_per_index_score(
12877 cfg->oce_wan_score_slots3_to_0);
12878 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12879 hdd_limit_max_per_index_score(
12880 cfg->oce_wan_score_slots7_to_4);
12881 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12882 hdd_limit_max_per_index_score(
12883 cfg->oce_wan_score_slots11_to_8);
12884 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12885 hdd_limit_max_per_index_score(
12886 cfg->oce_wan_score_slots15_to_12);
12887
12888
12889 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12890 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12891 score_config->nss = cfg->enable2x2 ? 2 : 1;
12892
12893 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12894 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12895 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12896 score_config->he_cap = 1;
12897
12898 if (score_config->he_cap ||
12899 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12900 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12901 score_config->vht_cap = 1;
12902
12903 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12904 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12905 score_config->ht_cap = 1;
12906
12907 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12908 score_config->vht_24G_cap = 1;
12909
12910 if (cfg->enableTxBF)
12911 score_config->beamformee_cap = 1;
12912
12913}
12914
Abhishek Singh257a9482017-03-06 16:52:39 +053012915/**
bings81fe50a2017-11-27 14:33:26 +080012916 * hdd_update_dfs_config() - API to update dfs configuration parameters.
12917 * @hdd_ctx: HDD context
12918 *
12919 * Return: 0 if success else err
12920 */
12921static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
12922{
12923 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12924 struct hdd_config *cfg = hdd_ctx->config;
12925 struct dfs_user_config dfs_cfg;
12926 QDF_STATUS status;
12927
12928 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
12929 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
12930 if (QDF_IS_STATUS_ERROR(status)) {
12931 hdd_err("failed dfs psoc configuration");
12932 return -EINVAL;
12933 }
12934
12935 return 0;
12936}
12937
12938/**
Abhishek Singh257a9482017-03-06 16:52:39 +053012939 * hdd_update_scan_config - API to update scan configuration parameters
12940 * @hdd_ctx: HDD context
12941 *
12942 * Return: 0 if success else err
12943 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012944static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012945{
12946 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12947 struct scan_user_cfg scan_cfg;
12948 struct hdd_config *cfg = hdd_ctx->config;
12949 QDF_STATUS status;
12950
12951 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12952 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12953 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12954 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12955 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12956 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12957 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012958 /* convert to ms */
12959 scan_cfg.scan_cache_aging_time =
12960 cfg->scanAgingTimeout * 1000;
12961 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12962 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12963 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12964 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012965 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012966 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012967 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12968 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012969 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012970 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053012971 scan_cfg.sta_miracast_mcc_rest_time =
12972 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053012973
Abhishek Singhb20db962017-03-03 21:28:46 +053012974 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012975 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012976 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012977
Abhishek Singh257a9482017-03-06 16:52:39 +053012978 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12979 if (status != QDF_STATUS_SUCCESS) {
12980 hdd_err("failed pmo psoc configuration");
12981 return -EINVAL;
12982 }
12983
12984 return 0;
12985}
Abhishek Singh257a9482017-03-06 16:52:39 +053012986
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012987int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012988{
12989 int ret;
12990
12991 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012992 if (ret)
12993 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012994
Abhishek Singh257a9482017-03-06 16:52:39 +053012995 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012996 if (ret)
12997 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012998
Frank Liud4b2fa02017-03-29 11:46:48 +080012999 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013000 if (ret)
13001 return ret;
13002
13003 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013004 if (ret)
13005 return ret;
13006
13007 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013008
13009 return ret;
13010}
13011
Agrawal Ashish65634612016-08-18 13:24:32 +053013012/**
13013 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13014 * @mode : cfg80211 DFS mode
13015 *
13016 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13017 */
13018enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13019{
13020 switch (mode) {
13021 case DFS_MODE_ENABLE:
13022 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013023 case DFS_MODE_DISABLE:
13024 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013025 case DFS_MODE_DEPRIORITIZE:
13026 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013027 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013028 hdd_debug("ACS dfs mode is NONE");
13029 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013030 }
13031}
13032
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013033/**
13034 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13035 * @hddctx: pointer to hdd context
13036 * @set_value: enable/disable
13037 *
13038 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13039 * Host(even though it is duplicate). When Host send vendor command
13040 * disable,FW doesn't perform any action. Whenever any change in
13041 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13042 *
13043 * return - 0 on success, appropriate error values on failure.
13044 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013045int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013046{
13047 QDF_STATUS status;
13048
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013049 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013050 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013051
13052 if (!hddctx->config->goptimize_chan_avoid_event) {
13053 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13054 return -EINVAL;
13055 }
13056
13057 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13058 if (!QDF_IS_STATUS_SUCCESS(status)) {
13059 hdd_err("Failed to send chan avoid command to SME");
13060 return -EINVAL;
13061 }
13062 return 0;
13063}
Agrawal Ashish65634612016-08-18 13:24:32 +053013064
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013065/**
13066 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13067 * @value: value to set
13068 *
13069 * This function will set the passed value to roaming in progress flag.
13070 *
13071 * Return: None
13072 */
13073void hdd_set_roaming_in_progress(bool value)
13074{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013075 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013076
13077 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13078 if (!hdd_ctx) {
13079 hdd_err("HDD context is NULL");
13080 return;
13081 }
13082
13083 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013084 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013085}
13086
13087/**
13088 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013089 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013090 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013091 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013092 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013093bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013094{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013095 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013096 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013097
13098 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13099 if (!hdd_ctx) {
13100 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013101 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013102 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013103 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13104 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013105 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13106 hdd_ctx->roaming_in_progress);
13107
13108 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013109}
13110
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013111/**
13112 * hdd_is_connection_in_progress() - check if connection is in
13113 * progress
13114 * @session_id: session id
13115 * @reason: scan reject reason
13116 *
13117 * Go through each adapter and check if Connection is in progress
13118 *
13119 * Return: true if connection is in progress else false
13120 */
13121bool hdd_is_connection_in_progress(uint8_t *session_id,
13122 enum scan_reject_states *reason)
13123{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013124 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013125 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013126 uint8_t sta_id = 0;
13127 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013128 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013129
13130 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13131 if (!hdd_ctx) {
13132 hdd_err("HDD context is NULL");
13133 return false;
13134 }
13135
Dustin Brown920397d2017-12-13 16:27:50 -080013136 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013137 hdd_info("Adapter with device mode %s(%d) exists",
13138 hdd_device_mode_to_string(adapter->device_mode),
13139 adapter->device_mode);
13140 if (((QDF_STA_MODE == adapter->device_mode)
13141 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13142 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13143 && (eConnectionState_Connecting ==
13144 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13145 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013146 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013147 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013148 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013149 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013150 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013151 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013152 }
13153 return true;
13154 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013155 /*
13156 * sme_neighbor_middle_of_roaming is for LFR2
13157 * hdd_is_roaming_in_progress is for LFR3
13158 */
13159 if (((QDF_STA_MODE == adapter->device_mode) &&
13160 sme_neighbor_middle_of_roaming(
13161 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013162 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013163 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013164 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013165 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013166 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013167 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013168 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013169 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013170 }
13171 return true;
13172 }
13173 if ((QDF_STA_MODE == adapter->device_mode) ||
13174 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13175 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13176 hdd_sta_ctx =
13177 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13178 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013179 hdd_sta_ctx->conn_info.connState)
13180 && sme_is_sta_key_exchange_in_progress(
13181 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013182 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013183 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013184 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013185 " is in middle of WPS/EAPOL exchange.",
13186 MAC_ADDR_ARRAY(sta_mac));
13187 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013188 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013189 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013190 }
13191 return true;
13192 }
13193 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13194 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13195 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13196 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013197 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013198 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013199 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013200 continue;
13201
13202 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013203 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013204 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013205 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013206 " of SAP/GO is in middle of WPS/EAPOL exchange",
13207 MAC_ADDR_ARRAY(sta_mac));
13208 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013209 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013210 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013211 }
13212 return true;
13213 }
13214 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013215 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013216 return true;
13217 }
13218 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013219 }
Dustin Brown920397d2017-12-13 16:27:50 -080013220
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013221 return false;
13222}
13223
13224/**
13225 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013226 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013227 *
13228 * Return: None
13229 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013230void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013231{
Jeff Johnson87251032017-08-29 13:31:11 -070013232 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013233 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013234 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013235 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013236 tsap_Config_t *sap_config;
13237 void *sap_ctx;
13238
13239 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013240 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013241 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013242
13243 mutex_lock(&hdd_ctx->sap_lock);
13244 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13245 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013246 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13247 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13248 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13249 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013250 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013251 qdf_stop_bss_event,
13252 SME_CMD_TIMEOUT_VALUE);
13253
13254 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013255 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013256 goto end;
13257 }
13258 }
13259 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013260 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013261 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013262 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013263 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013264 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013265
13266 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013267 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013268 wlansap_reset_sap_config_add_ie(sap_config,
13269 eUPDATE_IE_ALL);
13270 goto end;
13271 }
13272
13273 qdf_event_reset(&hostapd_state->qdf_event);
13274 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13275 sap_config,
13276 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013277 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013278 wlansap_reset_sap_config_add_ie(sap_config,
13279 eUPDATE_IE_ALL);
13280 goto end;
13281 }
13282
Jeff Johnson6867ec32017-09-29 20:30:20 -070013283 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013284 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013285 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013286 SME_CMD_TIMEOUT_VALUE);
13287 wlansap_reset_sap_config_add_ie(sap_config,
13288 eUPDATE_IE_ALL);
13289 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013290 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013291 goto end;
13292 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013293 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013294 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013295 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013296 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13297 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013298 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013299 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013300 ap_adapter->device_mode,
13301 true);
13302 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013303 }
13304end:
13305 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013306}
13307
13308/**
13309 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13310 * with non dfs acs
13311 *
13312 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13313 *
13314 * Return: None
13315 */
13316void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13317{
Jeff Johnson9d295242017-08-29 14:39:48 -070013318 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013319 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013320 cds_context_type *cds_ctx;
13321
13322 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13323 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013324 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013325 return;
13326 }
13327
13328 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13329 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013330 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013331 return;
13332 }
13333
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013334 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13335 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013336 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013337 return;
13338 }
13339
13340 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013341 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13342 &ap_adapter->event_flags) &&
13343 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013344 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013345
Jeff Johnson6867ec32017-09-29 20:30:20 -070013346 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013347 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013348 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013349 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013350 acs_cfg.acs_mode = true;
13351
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013352 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013353 }
13354}
13355
13356/**
13357 * hdd_set_connection_in_progress() - to set the connection in
13358 * progress flag
13359 * @value: value to set
13360 *
13361 * This function will set the passed value to connection in progress flag.
13362 * If value is previously being set to true then no need to set it again.
13363 *
13364 * Return: true if value is being set correctly and false otherwise.
13365 */
13366bool hdd_set_connection_in_progress(bool value)
13367{
13368 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013369 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013370
13371 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13372 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013373 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013374 return false;
13375 }
13376
13377 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13378 /*
13379 * if the value is set to true previously and if someone is
13380 * trying to make it true again then it could be some race
13381 * condition being triggered. Avoid this situation by returning
13382 * false
13383 */
13384 if (hdd_ctx->connection_in_progress && value)
13385 status = false;
13386 else
13387 hdd_ctx->connection_in_progress = value;
13388 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13389 return status;
13390}
13391
Jeff Johnson9d295242017-08-29 14:39:48 -070013392int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013393{
13394 if (!adapter) {
13395 hdd_err("Invalid adapter");
13396 return -EINVAL;
13397 }
13398 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013399 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013400 WMA_VDEV_MCC_SET_TIME_QUOTA,
13401 set_value, VDEV_CMD);
13402 return 0;
13403
13404}
13405
Jeff Johnson9d295242017-08-29 14:39:48 -070013406int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013407{
13408 if (!adapter) {
13409 hdd_err("Invalid adapter");
13410 return -EINVAL;
13411 }
13412
13413 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013414 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013415 WMA_VDEV_MCC_SET_TIME_LATENCY,
13416 set_value, VDEV_CMD);
13417 return 0;
13418}
13419
Jeff Johnson9d295242017-08-29 14:39:48 -070013420struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013421 *psoc, uint8_t vdev_id)
13422{
Jeff Johnson9d295242017-08-29 14:39:48 -070013423 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013424 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013425
13426 /*
13427 * Currently PSOC is not being used. But this logic will
13428 * change once we have the converged implementation of
13429 * HDD context per PSOC in place. This would break if
13430 * multiple vdev objects reuse the vdev id.
13431 */
13432 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13433 if (!adapter)
13434 hdd_err("Get adapter by vdev id failed");
13435
13436 return adapter;
13437}
13438
Jeff Johnson9d295242017-08-29 14:39:48 -070013439int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013440 int8_t *rssi, int8_t *snr)
13441{
13442 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013443 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013444
Jeff Johnson025618c2018-03-18 14:41:00 -070013445 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013446 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013447 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013448 if (QDF_STATUS_SUCCESS != status) {
13449 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13450 return -EINVAL;
13451 }
13452
13453 return 0;
13454}
13455
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013456/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013457 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13458 * @adapter - HDD adapter
13459 * @tos - type of service
13460 * @status - status of the traffic
13461 *
13462 * Return: 0 on success and non zero value on failure
13463 */
13464
13465int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13466 bool is_tos_active)
13467{
13468 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013469 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013470 uint32_t max_off_chan_time = 0;
13471 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013472 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013473 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013474
13475 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13476 ret = wlan_hdd_validate_context(hdd_ctx);
13477
13478 if (ret < 0) {
13479 hdd_err("failed to set limit off chan params");
13480 return ret;
13481 }
13482
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013483 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13484
13485 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013486 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013487 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013488 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013489
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013490 if (adapter->active_ac) {
13491 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013492 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013493 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13494 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13495 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013496 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013497 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013498 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13499 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13500 PM_LATENCY);
13501 } else {
13502 /*ignore this command if only BE/BK is active */
13503 is_tos_active = false;
13504 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13505 hdd_ctx->config->conc_system_pref);
13506 }
13507 } else {
13508 /* No active tos */
13509 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13510 hdd_ctx->config->conc_system_pref);
13511 }
13512
Jeff Johnson1b780e42017-10-31 14:11:45 -070013513 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013514 is_tos_active, max_off_chan_time,
13515 hdd_ctx->config->nRestTimeConc, true);
13516 if (!QDF_IS_STATUS_SUCCESS(status)) {
13517 hdd_err("failed to set limit off chan params");
13518 ret = -EINVAL;
13519 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013520
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013521 return ret;
13522}
13523
13524/**
13525 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13526 * @adapter - HDD adapter
13527 *
13528 * Return: 0 on success and non zero value on failure
13529 */
13530int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13531{
13532 struct hdd_context *hdd_ctx;
13533 int ret;
13534 QDF_STATUS status;
13535 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13536
13537 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13538 ret = wlan_hdd_validate_context(hdd_ctx);
13539 if (ret < 0)
13540 return ret;
13541
13542 /* set the system preferece to default */
13543 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13544 hdd_ctx->config->conc_system_pref);
13545
13546 /* clear the bitmap */
13547 adapter->active_ac = 0;
13548
13549 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013550 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013551
Jeff Johnson1b780e42017-10-31 14:11:45 -070013552 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013553 false, 0, 0, false);
13554 if (!QDF_IS_STATUS_SUCCESS(status)) {
13555 hdd_err("failed to reset limit off chan params");
13556 ret = -EINVAL;
13557 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013558
13559 return ret;
13560}
13561
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013562/**
13563 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13564 * @drv_op: Enum indicating driver op
13565 *
13566 * Return: none
13567 */
13568void hdd_start_driver_ops_timer(int drv_op)
13569{
13570 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13571 switch (drv_op) {
13572 case eHDD_DRV_OP_PROBE:
13573 memcpy(drv_ops_string, "probe", sizeof("probe"));
13574 break;
13575 case eHDD_DRV_OP_REMOVE:
13576 memcpy(drv_ops_string, "remove", sizeof("remove"));
13577 break;
13578 case eHDD_DRV_OP_SHUTDOWN:
13579 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13580 break;
13581 case eHDD_DRV_OP_REINIT:
13582 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13583 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013584 case eHDD_DRV_OP_IFF_UP:
13585 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13586 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013587 }
13588
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013589 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013590 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13591 HDD_OPS_INACTIVITY_TIMEOUT);
13592}
13593
13594/**
13595 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13596 *
13597 * Return: none
13598 */
13599void hdd_stop_driver_ops_timer(void)
13600{
13601 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13602}
13603
13604/**
13605 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13606 * inactivity timer
13607 *
13608 * Return: None
13609 */
13610void hdd_drv_ops_inactivity_handler(void)
13611{
13612 hdd_err("%s: %d Sec timer expired while in .%s",
13613 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13614
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013615 if (hdd_drv_ops_task) {
13616 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13617 qdf_print_thread_trace(hdd_drv_ops_task);
13618 } else {
13619 hdd_err("hdd_drv_ops_task is null");
13620 }
13621
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013622 /* Driver shutdown is stuck, no recovery possible at this point */
13623 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13624 sizeof("shutdown")))
13625 QDF_BUG(0);
13626
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013627 if (cds_is_fw_down()) {
13628 hdd_err("FW is down");
13629 return;
13630 }
13631
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013632 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013633 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013634 else
13635 QDF_BUG(0);
13636}
13637
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013638void hdd_pld_ipa_uc_shutdown_pipes(void)
13639{
13640 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13641
13642 if (!hdd_ctx)
13643 return;
13644
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053013645 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013646}
13647
Yun Parkff6a16a2017-09-26 16:38:18 -070013648/**
13649 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13650 * @struct hdd_context *hdd_ctx
13651 * @struct hdd_adapter *padapter
13652 * @bool enble
13653 *
13654 * Return: none
13655 */
13656void hdd_set_rx_mode_rps(bool enable)
13657{
13658 struct cds_config_info *cds_cfg = cds_get_ini_config();
13659 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13660 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13661
13662 if (adapter && hdd_ctx &&
13663 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13664 if (enable && !cds_cfg->rps_enabled)
13665 hdd_send_rps_ind(adapter);
13666 else if (!enable && cds_cfg->rps_enabled)
13667 hdd_send_rps_disable_ind(adapter);
13668 }
13669}
13670
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053013671bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
13672{
13673 struct hdd_adapter *adapter = NULL;
13674
13675 hdd_for_each_adapter(hdd_ctx, adapter) {
13676 if ((adapter->device_mode == QDF_STA_MODE ||
13677 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
13678 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
13679 &adapter->event_flags)){
13680 return true;
13681 }
13682 }
13683
13684 return false;
13685}
13686
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013687/* Register the module init/exit functions */
13688module_init(hdd_module_init);
13689module_exit(hdd_module_exit);
13690
13691MODULE_LICENSE("Dual BSD/GPL");
13692MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13693MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13694
Srinivas Girigowda841da292018-02-21 16:33:00 -080013695static const struct kernel_param_ops con_mode_ops = {
13696 .set = con_mode_handler,
13697 .get = param_get_int,
13698};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013699
Srinivas Girigowda841da292018-02-21 16:33:00 -080013700static const struct kernel_param_ops con_mode_ftm_ops = {
13701 .set = con_mode_handler_ftm,
13702 .get = param_get_int,
13703};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013704
Srinivas Girigowda841da292018-02-21 16:33:00 -080013705static const struct kernel_param_ops con_mode_monitor_ops = {
13706 .set = con_mode_handler_monitor,
13707 .get = param_get_int,
13708};
Ravi Joshia307f632017-07-17 23:41:41 -070013709
Srinivas Girigowda841da292018-02-21 16:33:00 -080013710static const struct kernel_param_ops fwpath_ops = {
13711 .set = fwpath_changed_handler,
13712 .get = param_get_string,
13713};
13714
13715module_param_cb(con_mode, &con_mode_ops, &con_mode,
13716 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13717
13718module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
13719 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13720
13721module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
13722 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13723
13724module_param_cb(fwpath, &fwpath_ops, &fwpath,
13725 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013726
13727module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13728
13729module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13730
13731module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);