blob: 661b0f3174a9c2d9044cb31ce8adb68464266e94 [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;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428
Dustin Brown5e06bd32016-10-04 12:49:10 -07001429 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001430 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001431 return;
1432 }
1433
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434 /* Get the current MPDU length */
1435 status =
1436 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1437 &value);
1438
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301439 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001440 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 value = 0;
1442 }
1443
1444 /*
1445 * VHT max MPDU length:
1446 * override if user configured value is too high
1447 * that the target cannot support
1448 */
1449 if (value > cfg->vht_max_mpdu) {
1450 status = sme_cfg_set_int(hdd_ctx->hHal,
1451 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1452 cfg->vht_max_mpdu);
1453
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001454 if (status == QDF_STATUS_E_FAILURE)
1455 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456 }
1457
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001458 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1459 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1460
1461 if (pconfig->enable2x2)
1462 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1463
1464 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1465 QDF_STATUS_E_FAILURE) {
1466 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1467 }
1468
1469 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1470 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1471 if (pconfig->enable2x2)
1472 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1473
1474 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1475 QDF_STATUS_E_FAILURE) {
1476 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1477 }
1478
1479 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1480 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1481 if (pconfig->enable2x2)
1482 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1483
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001484 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001485 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1486
1487 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1488 QDF_STATUS_E_FAILURE) {
1489 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1490 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001491 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001492 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493 &value);
1494
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301495 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001496 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497 value = 0;
1498 }
1499
jiad4a7a33c2017-08-08 15:32:24 +08001500 /* Set HW RX LDPC capability */
1501 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1502 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001503 status = sme_cfg_set_int(hdd_ctx->hHal,
1504 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001505 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001506
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001507 if (status == QDF_STATUS_E_FAILURE)
1508 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001509 }
1510
1511 /* Get current GI 80 value */
1512 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1513 &value);
1514
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301515 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001516 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001517 value = 0;
1518 }
1519
1520 /* set the Guard interval 80MHz */
1521 if (value && !cfg->vht_short_gi_80) {
1522 status = sme_cfg_set_int(hdd_ctx->hHal,
1523 WNI_CFG_VHT_SHORT_GI_80MHZ,
1524 cfg->vht_short_gi_80);
1525
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001526 if (status == QDF_STATUS_E_FAILURE)
1527 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001528 }
1529
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530 /* Get VHT TX STBC cap */
1531 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1532
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301533 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001534 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001535 value = 0;
1536 }
1537
1538 /* VHT TX STBC cap */
1539 if (value && !cfg->vht_tx_stbc) {
1540 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1541 cfg->vht_tx_stbc);
1542
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001543 if (status == QDF_STATUS_E_FAILURE)
1544 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001545 }
1546
1547 /* Get VHT RX STBC cap */
1548 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1549
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301550 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001551 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552 value = 0;
1553 }
1554
1555 /* VHT RX STBC cap */
1556 if (value && !cfg->vht_rx_stbc) {
1557 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1558 cfg->vht_rx_stbc);
1559
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001560 if (status == QDF_STATUS_E_FAILURE)
1561 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001562 }
1563
1564 /* Get VHT SU Beamformer cap */
1565 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1566 &value);
1567
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301568 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001569 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001570 value = 0;
1571 }
1572
1573 /* set VHT SU Beamformer cap */
1574 if (value && !cfg->vht_su_bformer) {
1575 status = sme_cfg_set_int(hdd_ctx->hHal,
1576 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1577 cfg->vht_su_bformer);
1578
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001579 if (status == QDF_STATUS_E_FAILURE)
1580 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001581 }
1582
1583 /* check and update SU BEAMFORMEE capabality */
1584 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1585 pconfig->enableTxBF = cfg->vht_su_bformee;
1586
1587 status = sme_cfg_set_int(hdd_ctx->hHal,
1588 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1589 pconfig->enableTxBF);
1590
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001591 if (status == QDF_STATUS_E_FAILURE)
1592 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593
1594 /* Get VHT MU Beamformer cap */
1595 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1596 &value);
1597
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301598 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001599 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 value = 0;
1601 }
1602
1603 /* set VHT MU Beamformer cap */
1604 if (value && !cfg->vht_mu_bformer) {
1605 status = sme_cfg_set_int(hdd_ctx->hHal,
1606 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1607 cfg->vht_mu_bformer);
1608
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001609 if (status == QDF_STATUS_E_FAILURE)
1610 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 }
1612
1613 /* Get VHT MU Beamformee cap */
1614 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1615 &value);
1616
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301617 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001618 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619 value = 0;
1620 }
1621
1622 /* set VHT MU Beamformee cap */
1623 if (value && !cfg->vht_mu_bformee) {
1624 status = sme_cfg_set_int(hdd_ctx->hHal,
1625 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1626 cfg->vht_mu_bformee);
1627
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001628 if (status == QDF_STATUS_E_FAILURE)
1629 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001630 }
1631
1632 /* Get VHT MAX AMPDU Len exp */
1633 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1634 &value);
1635
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301636 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001637 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001638 value = 0;
1639 }
1640
1641 /*
1642 * VHT max AMPDU len exp:
1643 * override if user configured value is too high
1644 * that the target cannot support.
1645 * Even though Rome publish ampdu_len=7, it can
1646 * only support 4 because of some h/w bug.
1647 */
1648
1649 if (value > cfg->vht_max_ampdu_len_exp) {
1650 status = sme_cfg_set_int(hdd_ctx->hHal,
1651 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1652 cfg->vht_max_ampdu_len_exp);
1653
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001654 if (status == QDF_STATUS_E_FAILURE)
1655 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001656 }
1657
1658 /* Get VHT TXOP PS CAP */
1659 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1660
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301661 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001662 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 value = 0;
1664 }
1665
1666 /* set VHT TXOP PS cap */
1667 if (value && !cfg->vht_txop_ps) {
1668 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1669 cfg->vht_txop_ps);
1670
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001671 if (status == QDF_STATUS_E_FAILURE)
1672 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001673 }
1674
1675 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1676 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1677 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1678 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1679 else
1680 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1681
1682
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001683 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1684 status = sme_cfg_set_int(hdd_ctx->hHal,
1685 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1686 VHT_CAP_160_AND_80P80_SUPP);
1687 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001688 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001689 band_5g->vht_cap.cap |=
1690 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001691 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1692 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1693 status = sme_cfg_set_int(hdd_ctx->hHal,
1694 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1695 VHT_CAP_160_SUPP);
1696 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001697 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001698 band_5g->vht_cap.cap |=
1699 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001700 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1701 }
1702 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1703 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301704 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001705 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301706 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001707 &value);
1708 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301709 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001710 value = 0;
1711 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301712 /* set the Guard interval 160MHz */
1713 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001714 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301715 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1716 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001717
1718 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301719 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001720 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001721
1722 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1723 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1724
1725 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1726 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1727 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1728 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1729
1730 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1731 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1732
1733 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1734 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1735 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1736 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1737 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1738 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1739
1740 band_5g->vht_cap.cap |=
1741 (cfg->vht_max_ampdu_len_exp <<
1742 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1743
1744 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1745 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1746 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1747 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1748 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1749 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1750 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1751 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1752
1753 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1754 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1755
1756}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001758/**
1759 * hdd_generate_macaddr_auto() - Auto-generate mac address
1760 * @hdd_ctx: Pointer to the HDD context
1761 *
1762 * Auto-generate mac address using device serial number.
1763 * Keep the first 3 bytes of OUI as before and replace
1764 * the last 3 bytes with the lower 3 bytes of serial number.
1765 *
1766 * Return: 0 for success
1767 * Non zero failure code for errors
1768 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001769static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001770{
1771 unsigned int serialno = 0;
1772 struct qdf_mac_addr mac_addr = {
1773 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1774 };
1775
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001776 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001777 if (serialno == 0)
1778 return -EINVAL;
1779
1780 serialno &= 0x00ffffff;
1781
1782 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1783 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1784 mac_addr.bytes[5] = serialno & 0xff;
1785
1786 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1787 return 0;
1788}
1789
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301790/**
1791 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1792 * configuration to cfg_ini in HDD
1793 * @hdd_ctx: Pointer to hdd_ctx
1794 * @cfg: target configuration
1795 *
1796 * Return: None
1797 */
1798#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001799static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301800 struct wma_tgt_cfg *cfg)
1801{
1802 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1803}
1804#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001805static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301806 struct wma_tgt_cfg *cfg)
1807{
1808}
1809#endif
1810
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001811void hdd_update_tgt_cfg(void *context, void *param)
1812{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001813 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001814 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001815 struct wma_tgt_cfg *cfg = param;
1816 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001817 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301818 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001819 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301820
Dustin Brownbd68fe12017-11-21 15:28:52 -08001821 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1822 if (ret) {
1823 hdd_err("Failed to create pdev; errno:%d", ret);
1824 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001825 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001826 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001827 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001828 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1829 hdd_err("dispatcher pdev open failed");
1830 QDF_BUG(0);
1831 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301832 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001833
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001834 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301835
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301836 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1837 cds_get_context(QDF_MODULE_ID_SOC));
1838 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1839 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301840 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1841 hdd_softap_hard_start_xmit);
1842 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1843 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301844
Naveen Rawat64e477e2016-05-20 10:34:56 -07001845 if (cds_cfg) {
1846 if (hdd_ctx->config->enable_sub_20_channel_width !=
1847 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1848 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1849 cds_cfg->sub_20_channel_width =
1850 WLAN_SUB_20_CH_WIDTH_NONE;
1851 } else {
1852 cds_cfg->sub_20_channel_width =
1853 hdd_ctx->config->enable_sub_20_channel_width;
1854 }
1855 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856
1857 /* first store the INI band capability */
1858 temp_band_cap = hdd_ctx->config->nBandCapability;
1859
1860 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301861 hdd_ctx->is_fils_roaming_supported =
1862 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301864 hdd_ctx->config->is_11k_offload_supported =
1865 cfg->services.is_11k_offload_supported;
1866
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001867 /*
1868 * now overwrite the target band capability with INI
1869 * setting if INI setting is a subset
1870 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001871
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001872 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1873 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001874 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001875 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1876 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001878 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001879 }
1880
Amar Singhal58b45ef2017-08-01 13:43:54 -07001881 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1882
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301883 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001884 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1885 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1886 }
1887
1888 /* This can be extended to other configurations like ht, vht cap... */
1889
Anurag Chouhanc5548422016-02-24 18:33:27 +05301890 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001892 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001894 static struct qdf_mac_addr default_mac_addr = {
1895 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1896 };
1897 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1898 &default_mac_addr)) {
1899 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1900 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1901 MAC_ADDRESS_STR,
1902 MAC_ADDR_ARRAY(hdd_ctx->config->
1903 intfMacAddr[0].bytes));
1904 } else {
1905 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1906 MAC_ADDRESS_STR,
1907 MAC_ADDR_ARRAY(hdd_ctx->config->
1908 intfMacAddr[0].bytes));
1909 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001910 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001911 }
1912
1913 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001914 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001915
1916 hdd_ctx->max_intf_count = cfg->max_intf_count;
1917
Jeff Johnsonc875e242016-09-23 18:12:34 -07001918 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001919
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001920 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1921 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1922
1923 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001926 if (cfg->services.en_11ax) {
1927 hdd_info("11AX: 11ax is enabled - update HDD config");
1928 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1929 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001930
1931 hdd_update_vdev_nss(hdd_ctx);
1932
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301933 hdd_update_hw_dbs_capable(hdd_ctx);
1934
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001935 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001936 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001937 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001938 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001939
Nitesh Shahe50711f2017-04-26 16:30:45 +05301940 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1941 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1942 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001943 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001944 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001945
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001946 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1947 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301948 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301949 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301950
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301951 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001952 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1953 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301954 hdd_ctx->config->txBFCsnValue =
1955 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1956
Arif Hussainee10f902017-12-27 16:30:17 -08001957 status = sme_cfg_set_int(hdd_ctx->hHal,
1958 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1959 hdd_ctx->config->txBFCsnValue);
1960 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301961 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1962
1963
1964 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001965 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1966 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301967
1968 /*
1969 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1970 */
1971 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301972
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301973 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1974
Yue Macd359b72017-10-03 15:21:00 -07001975 /*
1976 * This needs to be done after HDD pdev is created and stored since
1977 * it will access the HDD pdev object lock.
1978 */
1979 hdd_runtime_suspend_context_init(hdd_ctx);
1980
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001981 /* Configure NAN datapath features */
1982 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001983 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08001984 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08001985 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
1986 cfg->obss_detection_offloaded);
1987 if (QDF_IS_STATUS_ERROR(status))
1988 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08001989
1990 status = sme_cfg_set_int(hdd_ctx->hHal,
1991 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
1992 cfg->obss_color_collision_offloaded);
1993 if (QDF_IS_STATUS_ERROR(status))
1994 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001995}
1996
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001997bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001998{
Jeff Johnson9d295242017-08-29 14:39:48 -07001999 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002000 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002001
Jiachao Wuf610d912018-01-23 17:47:32 +08002002 if (!hdd_ctx) {
2003 hdd_info("Couldn't get hdd_ctx");
2004 return true;
2005 }
2006
2007 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002008 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002009 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302010 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002011 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002012
Dustin Brown920397d2017-12-13 16:27:50 -08002013 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002014 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2015
2016 if ((QDF_SAP_MODE == adapter->device_mode ||
2017 QDF_P2P_GO_MODE == adapter->device_mode) &&
2018 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002019 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002020 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2021 true;
2022 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002023 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302024 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302026
2027 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029
2030/**
2031 * hdd_is_valid_mac_address() - validate MAC address
2032 * @pMacAddr: Pointer to the input MAC address
2033 *
2034 * This function validates whether the given MAC address is valid or not
2035 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2036 * where X is the hexa decimal digit character and separated by ':'
2037 * This algorithm works even if MAC address is not separated by ':'
2038 *
2039 * This code checks given input string mac contains exactly 12 hexadecimal
2040 * digits and a separator colon : appears in the input string only after
2041 * an even number of hex digits.
2042 *
2043 * Return: 1 for valid and 0 for invalid
2044 */
2045bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2046{
2047 int xdigit = 0;
2048 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002050 while (*pMacAddr) {
2051 if (isxdigit(*pMacAddr)) {
2052 xdigit++;
2053 } else if (':' == *pMacAddr) {
2054 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2055 break;
2056
2057 ++separator;
2058 } else {
2059 /* Invalid MAC found */
2060 return 0;
2061 }
2062 ++pMacAddr;
2063 }
2064 return xdigit == 12 && (separator == 5 || separator == 0);
2065}
2066
2067/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302068 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2069 * @dev: Handle to struct net_device to be updated.
2070 *
2071 * Return: None
2072 */
2073static void hdd_mon_mode_ether_setup(struct net_device *dev)
2074{
2075 dev->header_ops = NULL;
2076 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2077 dev->hard_header_len = ETH_HLEN;
2078 dev->mtu = ETH_DATA_LEN;
2079 dev->addr_len = ETH_ALEN;
2080 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2081 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2082 dev->priv_flags |= IFF_TX_SKB_SHARING;
2083
2084 memset(dev->broadcast, 0xFF, ETH_ALEN);
2085}
2086
2087/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002088 * __hdd__mon_open() - HDD Open function
2089 * @dev: Pointer to net_device structure
2090 *
2091 * This is called in response to ifconfig up
2092 *
2093 * Return: 0 for success; non-zero for failure
2094 */
2095static int __hdd_mon_open(struct net_device *dev)
2096{
2097 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002098 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2099 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002100
Dustin Brownfdf17c12018-03-14 12:55:34 -07002101 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002102
2103 ret = wlan_hdd_validate_context(hdd_ctx);
2104 if (ret)
2105 return ret;
2106
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302107 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002108
2109 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2110 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2111 if (ret) {
2112 hdd_err("Failed to start WLAN modules return");
2113 return ret;
2114 }
2115 hdd_err("hdd_wlan_start_modules() successful !");
2116
2117 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2118 ret = hdd_start_adapter(adapter);
2119 if (ret) {
2120 hdd_err("Failed to start adapter :%d",
2121 adapter->device_mode);
2122 return ret;
2123 }
2124 hdd_err("hdd_start_adapters() successful !");
2125 }
2126 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2127 }
2128
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002129 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002130
2131 if (!ret)
2132 ret = hdd_enable_monitor_mode(dev);
2133
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002134 return ret;
2135}
2136
2137/**
2138 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2139 * @dev: Pointer to net_device structure
2140 *
2141 * This is called in response to ifconfig up
2142 *
2143 * Return: 0 for success; non-zero for failure
2144 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002145static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002146{
2147 int ret;
2148
2149 cds_ssr_protect(__func__);
2150 ret = __hdd_mon_open(dev);
2151 cds_ssr_unprotect(__func__);
2152
2153 return ret;
2154}
2155
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002156static QDF_STATUS
2157wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2158{
2159 struct policy_mgr_dual_mac_config cfg = {0};
2160 QDF_STATUS status;
2161 uint32_t channel_select_logic_conc;
2162 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2163
2164 if (!hdd_ctx) {
2165 hdd_err("HDD context is NULL");
2166 return QDF_STATUS_E_FAILURE;
2167 }
2168
2169
2170 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2171 return QDF_STATUS_SUCCESS;
2172
2173 cfg.scan_config = 0;
2174 cfg.fw_mode_config = 0;
2175 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2176
2177 channel_select_logic_conc = hdd_ctx->config->
2178 channel_select_logic_conc;
2179
2180 if (hdd_ctx->config->dual_mac_feature_disable !=
2181 DISABLE_DBS_CXN_AND_SCAN) {
2182 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2183 hdd_ctx->hdd_psoc, &cfg.scan_config,
2184 &cfg.fw_mode_config,
2185 hdd_ctx->config->dual_mac_feature_disable,
2186 channel_select_logic_conc);
2187
2188 if (status != QDF_STATUS_SUCCESS) {
2189 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2190 status);
2191 return status;
2192 }
2193 }
2194
2195 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2196 cfg.scan_config, cfg.fw_mode_config);
2197
2198 status = sme_soc_set_dual_mac_config(cfg);
2199 if (status != QDF_STATUS_SUCCESS) {
2200 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2201 return status;
2202 }
2203
2204 return QDF_STATUS_SUCCESS;
2205}
2206
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002207/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302208 * hdd_start_adapter() - Wrapper function for device specific adapter
2209 * @adapter: pointer to HDD adapter
2210 *
2211 * This function is called to start the device specific adapter for
2212 * the mode passed in the adapter's device_mode.
2213 *
2214 * Return: 0 for success; non-zero for failure
2215 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002216int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302217{
2218
2219 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002220 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302221
Dustin Brownfdf17c12018-03-14 12:55:34 -07002222 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002223 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302224
2225 switch (device_mode) {
2226 case QDF_P2P_CLIENT_MODE:
2227 case QDF_P2P_DEVICE_MODE:
2228 case QDF_OCB_MODE:
2229 case QDF_STA_MODE:
2230 case QDF_MONITOR_MODE:
2231 ret = hdd_start_station_adapter(adapter);
2232 if (ret)
2233 goto err_start_adapter;
2234 break;
2235 case QDF_P2P_GO_MODE:
2236 case QDF_SAP_MODE:
2237 ret = hdd_start_ap_adapter(adapter);
2238 if (ret)
2239 goto err_start_adapter;
2240 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302241 case QDF_IBSS_MODE:
2242 /*
2243 * For IBSS interface is initialized as part of
2244 * hdd_init_station_mode()
2245 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002246 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302247 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002248 /* vdevs are dynamically managed by firmware in FTM */
2249 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302250 default:
2251 hdd_err("Invalid session type %d", device_mode);
2252 QDF_ASSERT(0);
2253 goto err_start_adapter;
2254 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002255
Arun Khandavallifae92942016-08-01 13:31:08 +05302256 if (hdd_set_fw_params(adapter))
2257 hdd_err("Failed to set the FW params for the adapter!");
2258
2259 /*
2260 * Action frame registered in one adapter which will
2261 * applicable to all interfaces
2262 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302263 ret = wlan_hdd_cfg80211_register_frames(adapter);
2264 if (ret < 0) {
2265 hdd_err("Failed to register frames - ret %d", ret);
2266 goto err_start_adapter;
2267 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002268 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302269
Dustin Browndb2a8be2017-12-20 11:49:56 -08002270exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002271 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002272
Arun Khandavallifae92942016-08-01 13:31:08 +05302273 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002274
Arun Khandavallifae92942016-08-01 13:31:08 +05302275err_start_adapter:
2276 return -EINVAL;
2277}
2278
2279/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302280 * hdd_enable_power_management() - API to Enable Power Management
2281 *
2282 * API invokes Bus Interface Layer power management functionality
2283 *
2284 * Return: None
2285 */
2286static void hdd_enable_power_management(void)
2287{
2288 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2289
2290 if (!hif_ctx) {
2291 hdd_err("Bus Interface Context is Invalid");
2292 return;
2293 }
2294
2295 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2296}
2297
2298/**
2299 * hdd_disable_power_management() - API to disable Power Management
2300 *
2301 * API disable Bus Interface Layer Power management functionality
2302 *
2303 * Return: None
2304 */
2305static void hdd_disable_power_management(void)
2306{
2307 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2308
2309 if (!hif_ctx) {
2310 hdd_err("Bus Interface Context is Invalid");
2311 return;
2312 }
2313
2314 hif_disable_power_management(hif_ctx);
2315}
2316
2317/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302318 * hdd_update_hw_sw_info() - API to update the HW/SW information
2319 *
2320 * API to update the HW and SW information in the driver
2321 *
2322 * Return: None
2323 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002324static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302325{
2326 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002327 size_t target_hw_name_len;
2328 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302329
2330 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2331 if (!hif_sc) {
2332 hdd_err("HIF context is NULL");
2333 return;
2334 }
2335
2336 /*
2337 * target hw version/revision would only be retrieved after firmware
2338 * download
2339 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002340 hif_get_hw_info(hif_sc,
2341 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302342 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002343 &target_hw_name);
2344
2345 if (hdd_ctx->target_hw_name)
2346 qdf_mem_free(hdd_ctx->target_hw_name);
2347
2348 target_hw_name_len = strlen(target_hw_name) + 1;
2349 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2350 if (hdd_ctx->target_hw_name)
2351 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2352 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302353
2354 /* Get the wlan hw/fw version */
2355 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302356}
2357
2358/**
gbian62edd7e2017-03-07 13:12:13 +08002359 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2360 * @hdd_ctx: Pointer to hdd context
2361 *
2362 * Return: none
2363 */
2364static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002365hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002366{
2367 uint8_t num_entries = 0;
2368 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2369 uint8_t *tx_sched_wrr_ac;
2370 int i;
2371 cds_context_type *cds_ctx;
2372
2373 if (NULL == hdd_ctx)
2374 return;
2375
2376 if (NULL == hdd_ctx->config) {
2377 /* Do nothing if hdd_ctx is invalid */
2378 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2379 return;
2380 }
2381
2382 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2383
2384 if (!cds_ctx) {
2385 hdd_err("Invalid CDS Context");
2386 return;
2387 }
2388
2389 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2390 switch (i) {
2391 case OL_TX_WMM_AC_BE:
2392 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2393 break;
2394 case OL_TX_WMM_AC_BK:
2395 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2396 break;
2397 case OL_TX_WMM_AC_VI:
2398 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2399 break;
2400 case OL_TX_WMM_AC_VO:
2401 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2402 break;
2403 default:
2404 tx_sched_wrr_ac = NULL;
2405 break;
2406 }
2407
2408 hdd_string_to_u8_array(tx_sched_wrr_ac,
2409 tx_sched_wrr_param,
2410 &num_entries,
2411 sizeof(tx_sched_wrr_param));
2412
2413 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2414 cds_ctx->ac_specs[i].wrr_skip_weight =
2415 tx_sched_wrr_param[0];
2416 cds_ctx->ac_specs[i].credit_threshold =
2417 tx_sched_wrr_param[1];
2418 cds_ctx->ac_specs[i].send_limit =
2419 tx_sched_wrr_param[2];
2420 cds_ctx->ac_specs[i].credit_reserve =
2421 tx_sched_wrr_param[3];
2422 cds_ctx->ac_specs[i].discard_weight =
2423 tx_sched_wrr_param[4];
2424 }
2425
2426 num_entries = 0;
2427 }
2428}
2429
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302430#ifdef IPA_OFFLOAD
2431/**
2432 * hdd_update_ipa_component_config() - update ipa config
2433 * @hdd_ctx: Pointer to hdd context
2434 *
2435 * Return: none
2436 */
2437static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2438{
2439 struct hdd_config *cfg = hdd_ctx->config;
2440 struct wlan_ipa_config ipa_cfg;
2441
2442 ipa_cfg.ipa_config = cfg->IpaConfig;
2443 ipa_cfg.desc_size = cfg->IpaDescSize;
2444 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2445 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2446 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2447 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2448 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2449 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2450 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2451
2452 ucfg_ipa_update_config(&ipa_cfg);
2453}
2454#else
2455static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2456{
2457}
2458#endif
2459
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002460#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002461static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2462 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2463{
Jeff Johnson9d295242017-08-29 14:39:48 -07002464 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002465 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002466
2467 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2468 if (!adapter) {
2469 hdd_err("Adapter is NULL");
2470 return PM_MAX_NUM_OF_MODE;
2471 }
2472
2473 return policy_mgr_convert_device_mode_to_qdf_type(
2474 adapter->device_mode);
2475}
2476
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002477static void hdd_register_policy_manager_callback(
2478 struct wlan_objmgr_psoc *psoc)
2479{
2480 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002481
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002482 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002483 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002484 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2485 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002486 hdd_cbacks.get_mode_for_non_connected_vdev =
2487 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302488 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002489
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002490 if (QDF_STATUS_SUCCESS !=
2491 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2492 hdd_err("HDD callback registration with policy manager failed");
2493 }
2494}
2495#else
2496static void hdd_register_policy_manager_callback(
2497 struct wlan_objmgr_psoc *psoc)
2498{
2499}
2500#endif
2501
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002502static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002503{
2504 struct nan_callbacks cb_obj = {0};
2505
2506 cb_obj.ndi_open = hdd_ndi_open;
2507 cb_obj.ndi_close = hdd_ndi_close;
2508 cb_obj.ndi_start = hdd_ndi_start;
2509 cb_obj.ndi_delete = hdd_ndi_delete;
2510 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2511 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2512
Naveen Rawat37f62c82017-03-26 22:24:43 -07002513 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2514 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002515 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002516
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002517 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2518}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002519
Dustin Brown26b3d042017-12-21 11:13:27 -08002520#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002521/**
2522 * hdd_check_for_leaks() - Perform runtime memory leak checks
2523 *
2524 * This API triggers runtime memory leak detection. This feature enforces the
2525 * policy that any memory allocated at runtime must also be released at runtime.
2526 *
2527 * Allocating memory at runtime and releasing it at unload is effectively a
2528 * memory leak for configurations which never unload (e.g. LONU, statically
2529 * compiled driver). Such memory leaks are NOT false positives, and must be
2530 * fixed.
2531 *
2532 * Return: None
2533 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002534static void hdd_check_for_leaks(void)
2535{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002536 /* DO NOT REMOVE these checks; for false positives, read above first */
2537
Dustin Brown677e0862017-10-10 16:30:09 -07002538 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002539 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002540 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002541}
2542
Dustin Brown26b3d042017-12-21 11:13:27 -08002543#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2544#else
2545static inline void hdd_check_for_leaks(void) {}
2546
2547#define hdd_debug_domain_set(domain)
2548#endif /* CONFIG_LEAK_DETECTION */
2549
gbian62edd7e2017-03-07 13:12:13 +08002550/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002551 * hdd_update_country_code - Update country code
2552 * @hdd_ctx: HDD context
2553 *
2554 * Update country code based on module parameter country_code
2555 *
2556 * Return: 0 on success and errno on failure
2557 */
2558static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2559{
2560 if (!country_code)
2561 return 0;
2562
2563 return hdd_reg_set_country(hdd_ctx, country_code);
2564}
2565
2566/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302567 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2568 * @hdd_ctx: HDD context
2569 * @adapter: HDD adapter
2570 * @reinit: flag to indicate from SSR or normal path
2571 *
2572 * This function maintains the driver state machine it will be invoked from
2573 * startup, reinit and change interface. Depending on the driver state shall
2574 * perform the opening of the modules.
2575 *
2576 * Return: 0 for success; non-zero for failure
2577 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002578int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2579 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302580 bool reinit)
2581{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002582 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302583 qdf_device_t qdf_dev;
2584 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302585 bool unint = false;
2586 void *hif_ctx;
2587
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002588 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302589
2590 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2591 if (!qdf_dev) {
2592 hdd_err("QDF Device Context is Invalid return");
2593 return -EINVAL;
2594 }
2595
Dustin Brown6f427922017-09-19 12:19:00 -07002596 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302597
Dustin Brown1fe30a82017-10-03 16:13:36 -07002598 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302599 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2600 mutex_unlock(&hdd_ctx->iface_change_lock);
2601 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002602 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302603 return 0;
2604 }
2605
Dustin Brown1fe30a82017-10-03 16:13:36 -07002606 hdd_ctx->start_modules_in_progress = true;
2607
Arun Khandavallifae92942016-08-01 13:31:08 +05302608 switch (hdd_ctx->driver_status) {
2609 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002610 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302611 unint = true;
2612 /* Fall through dont add break here */
2613 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002614 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2615
Dustin Brown26b3d042017-12-21 11:13:27 -08002616 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002617
Arun Khandavallifae92942016-08-01 13:31:08 +05302618 if (!reinit && !unint) {
2619 ret = pld_power_on(qdf_dev->dev);
2620 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002621 hdd_err("Failed to Powerup the device; errno: %d",
2622 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302623 goto release_lock;
2624 }
2625 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002626
2627 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2628 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302629 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2630 qdf_dev->bus_type,
2631 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2632 HIF_ENABLE_TYPE_PROBE);
2633 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002634 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302635 goto power_down;
2636 }
2637
2638 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302639 if (!hif_ctx) {
2640 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002641 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302642 goto power_down;
2643 }
2644
Arun Khandavallifae92942016-08-01 13:31:08 +05302645 status = ol_cds_init(qdf_dev, hif_ctx);
2646 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002647 hdd_err("No Memory to Create BMI Context; status: %d",
2648 status);
2649 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302650 goto hif_close;
2651 }
2652
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302653 hdd_update_ipa_component_config(hdd_ctx);
2654
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002655 ret = hdd_update_config(hdd_ctx);
2656 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002657 hdd_err("Failed to update configuration; errno: %d",
2658 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002659 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002660 }
2661
gbian62edd7e2017-03-07 13:12:13 +08002662 hdd_update_cds_ac_specs_params(hdd_ctx);
2663
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302664 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002665 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002666 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002667 ret = qdf_status_to_os_return(status);
2668 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302669 }
2670
Mukul Sharma9d797a02017-01-05 20:26:03 +05302671 /* initalize components configurations after psoc open */
2672 ret = hdd_update_components_config(hdd_ctx);
2673 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002674 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302675 ret);
2676 goto close;
2677 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002678 status = cds_dp_open(hdd_ctx->hdd_psoc);
2679 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002680 hdd_err("Failed to Open cds post open; status: %d",
2681 status);
2682 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002683 goto close;
2684 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302685
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002686 /*
2687 * NAN compoenet requires certian operations like, open adapter,
2688 * close adapter, etc. to be initiated by HDD, for those
2689 * register HDD callbacks with UMAC's NAN componenet.
2690 */
2691 hdd_nan_register_callbacks(hdd_ctx);
2692
Arun Khandavallifae92942016-08-01 13:31:08 +05302693 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2694
Jeff Johnson3a280122017-09-13 07:42:00 -07002695 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302696 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002697 hdd_err("Failed to pre-enable CDS; status: %d", status);
2698 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002699 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302700 }
2701
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002702 hdd_register_policy_manager_callback(
2703 hdd_ctx->hdd_psoc);
2704
Amar Singhal0928b192017-12-01 10:50:54 -08002705 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2706
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302707 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302708 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002709 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302710
Arun Khandavallifae92942016-08-01 13:31:08 +05302711 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002712 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302713 break;
2714 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302715
Arun Khandavallifae92942016-08-01 13:31:08 +05302716 /* Fall through dont add break here */
2717 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002718 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2719
Arun Khandavallifae92942016-08-01 13:31:08 +05302720 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002721 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002722 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002723 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302724 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302725 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2726 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002727 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302728 break;
2729 }
Dustin Browndca39692017-11-09 15:30:25 -08002730
2731 ret = hdd_configure_cds(hdd_ctx, adapter);
2732 if (ret) {
2733 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002734 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302735 }
Dustin Browndca39692017-11-09 15:30:25 -08002736
Komal Seelamf2136bb2016-09-28 18:30:44 +05302737 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002738
Arun Khandavallifae92942016-08-01 13:31:08 +05302739 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002740 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302741 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002742
Arun Khandavallifae92942016-08-01 13:31:08 +05302743 default:
2744 hdd_err("WLAN start invoked in wrong state! :%d\n",
2745 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002746 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302747 goto release_lock;
2748 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002749
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302750 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002751 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2752 ret = hdd_update_country_code(hdd_ctx);
2753 if (ret)
2754 hdd_err("Failed to update command line country code!");
2755 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302756 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002757
Dustin Browne74003f2018-03-14 12:51:58 -07002758 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002759
Arun Khandavallifae92942016-08-01 13:31:08 +05302760 return 0;
2761
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002762post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002763 cds_post_disable();
Amar Singhal410675c2018-01-10 12:14:21 -08002764 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Dustin Brownbd68fe12017-11-21 15:28:52 -08002765 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002766
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002767cds_txrx_free:
2768 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002769
Arun Khandavallifae92942016-08-01 13:31:08 +05302770close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002771 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002772 hdd_info("Wlan transition aborted (now CLOSED)");
2773
Jeff Johnsone4b14592017-09-13 14:23:33 -07002774 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302775
Dustin Brown28b17892017-10-10 13:29:38 -07002776deinit_config:
2777 cds_deinit_ini_config();
2778
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002779cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302780 ol_cds_free();
2781
2782hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002783 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2784 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302785power_down:
2786 if (!reinit && !unint)
2787 pld_power_off(qdf_dev->dev);
2788release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302789 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302790 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002791
2792 /* many adapter resources are not freed by design in SSR case */
2793 if (!reinit)
2794 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002795 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002796
Dustin Browne74003f2018-03-14 12:51:58 -07002797 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002798
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002799 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302800}
2801
Naveen Rawat910726a2017-03-06 11:42:51 -08002802#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002803static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002804{
2805 int ret = os_if_wifi_pos_register_nl();
2806
2807 if (ret)
2808 hdd_err("os_if_wifi_pos_register_nl failed");
2809
2810 return ret;
2811}
2812
2813static int hdd_deactivate_wifi_pos(void)
2814{
2815 int ret = os_if_wifi_pos_deregister_nl();
2816
2817 if (ret)
2818 hdd_err("os_if_wifi_pos_deregister_nl failed");
2819
2820 return ret;
2821}
2822
2823/**
2824 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2825 * @hdd_ctx: hdd context
2826 *
2827 * Return: status of operation
2828 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002829static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002830{
2831 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2832 struct hdd_config *cfg = hdd_ctx->config;
2833
2834 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2835 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2836 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2837 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2838 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2839 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2840 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2841 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2842}
2843#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002844static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002845{
2846 return oem_activate_service(hdd_ctx);
2847}
2848
2849static int hdd_deactivate_wifi_pos(void)
2850{
2851 return 0;
2852}
2853
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002854static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002855{
2856}
2857#endif
2858
Arun Khandavallifae92942016-08-01 13:31:08 +05302859/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002860 * __hdd_open() - HDD Open function
2861 * @dev: Pointer to net_device structure
2862 *
2863 * This is called in response to ifconfig up
2864 *
2865 * Return: 0 for success; non-zero for failure
2866 */
2867static int __hdd_open(struct net_device *dev)
2868{
Jeff Johnson9d295242017-08-29 14:39:48 -07002869 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002870 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002871 int ret;
2872
Dustin Brownfdf17c12018-03-14 12:55:34 -07002873 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302874 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002875 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002876
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302877 /* Nothing to be done if device is unloading */
2878 if (cds_is_driver_unloading()) {
2879 hdd_err("Driver is unloading can not open the hdd");
2880 return -EBUSY;
2881 }
2882
Dustin Brown01847752017-10-25 13:56:27 -07002883 if (cds_is_driver_recovering()) {
2884 hdd_err("WLAN is currently recovering; Please try again.");
2885 return -EBUSY;
2886 }
2887
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302888 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2889 hdd_err("con_mode_handler is in progress; Please try again.");
2890 return -EBUSY;
2891 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302892
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302893 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302894 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2895
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302896 /*
2897 * This scenario can be hit in cases where in the wlan driver after
2898 * registering the netdevices and there is a failure in driver
2899 * initialization. So return error gracefully because the netdevices
2900 * will be de-registered as part of the load failure.
2901 */
2902
2903 if (!cds_is_driver_loaded()) {
2904 hdd_err("Failed to start the wlan driver!!");
2905 ret = -EIO;
2906 goto err_hdd_hdd_init_deinit_lock;
2907 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302908
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002909
Arun Khandavallifae92942016-08-01 13:31:08 +05302910 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2911 if (ret) {
2912 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302913 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302914 }
2915
2916
2917 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2918 ret = hdd_start_adapter(adapter);
2919 if (ret) {
2920 hdd_err("Failed to start adapter :%d",
2921 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302922 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302923 }
2924 }
2925
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2927 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002928 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002929 /* Enable TX queues only when we are connected */
2930 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302931 WLAN_START_ALL_NETIF_QUEUE,
2932 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002933 }
2934
Naveen Rawat286def52016-09-23 15:38:02 -07002935 /* Enable carrier and transmit queues for NDI */
2936 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002937 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002938 wlan_hdd_netif_queue_control(adapter,
2939 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2940 WLAN_CONTROL_PATH);
2941 }
2942
Naveen Rawat910726a2017-03-06 11:42:51 -08002943 hdd_populate_wifi_pos_cfg(hdd_ctx);
2944
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302945err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302946 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302947 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002948 return ret;
2949}
2950
Arun Khandavallifae92942016-08-01 13:31:08 +05302951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002952/**
2953 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2954 * @dev: Pointer to net_device structure
2955 *
2956 * This is called in response to ifconfig up
2957 *
2958 * Return: 0 for success; non-zero for failure
2959 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002960static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002961{
2962 int ret;
2963
2964 cds_ssr_protect(__func__);
2965 ret = __hdd_open(dev);
2966 cds_ssr_unprotect(__func__);
2967
2968 return ret;
2969}
2970
2971/**
2972 * __hdd_stop() - HDD stop function
2973 * @dev: Pointer to net_device structure
2974 *
2975 * This is called in response to ifconfig down
2976 *
2977 * Return: 0 for success; non-zero for failure
2978 */
2979static int __hdd_stop(struct net_device *dev)
2980{
Jeff Johnson9d295242017-08-29 14:39:48 -07002981 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002982 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002983 int ret;
2984
Dustin Brownfdf17c12018-03-14 12:55:34 -07002985 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002986
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302987 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002988 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002989
2990 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302991 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993
2994 /* Nothing to be done if the interface is not opened */
2995 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002996 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002997 return -ENODEV;
2998 }
2999
3000 /* Make sure the interface is marked as closed */
3001 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303002
3003 hdd_debug("Disabling Auto Power save timer");
3004 sme_ps_disable_auto_ps_timer(
3005 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07003006 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303007
3008 /*
3009 * Disable TX on the interface, after this hard_start_xmit() will not
3010 * be called on that interface
3011 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003012 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003013 hdd_device_mode_to_string(adapter->device_mode),
3014 adapter->device_mode);
3015
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303016 wlan_hdd_netif_queue_control(adapter,
3017 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3018 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003019
3020 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003021 * NAN data interface is different in some sense. The traffic on NDI is
3022 * bursty in nature and depends on the need to transfer. The service
3023 * layer may down the interface after the usage and up again when
3024 * required. In some sense, the NDI is expected to be available
3025 * (like SAP) iface until NDI delete request is issued by the service
3026 * layer. Skip BSS termination and adapter deletion for NAN Data
3027 * interface (NDI).
3028 */
3029 if (WLAN_HDD_IS_NDI(adapter))
3030 return 0;
3031
3032 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003033 * The interface is marked as down for outside world (aka kernel)
3034 * But the driver is pretty much alive inside. The driver needs to
3035 * tear down the existing connection on the netdev (session)
3036 * cleanup the data pipes and wait until the control plane is stabilized
3037 * for this interface. The call also needs to wait until the above
3038 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003039 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003040 * That is intentional to be able to scan if it is a STA/P2P interface
3041 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003042 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003043
3044 /* DeInit the adapter. This ensures datapath cleanup as well */
3045 hdd_deinit_adapter(hdd_ctx, adapter, true);
3046
Arun Khandavallifae92942016-08-01 13:31:08 +05303047
3048 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303049 * Upon wifi turn off, DUT has to flush the scan results so if
3050 * this is the last cli iface, flush the scan database.
3051 */
3052 if (!hdd_is_cli_iface_up(hdd_ctx))
3053 sme_scan_flush_result(hdd_ctx->hHal);
3054
3055 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303056 * Find if any iface is up. If any iface is up then can't put device to
3057 * sleep/power save mode
3058 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303059 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003060 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003061 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3062 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303063 hdd_prevent_suspend_timeout(
3064 hdd_ctx->config->iface_change_wait_time,
3065 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303066 }
3067
Dustin Browne74003f2018-03-14 12:51:58 -07003068 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003069 return 0;
3070}
3071
3072/**
3073 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3074 * @dev: pointer to net_device structure
3075 *
3076 * This is called in response to ifconfig down
3077 *
3078 * Return: 0 for success and error number for failure
3079 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003080static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003081{
3082 int ret;
3083
3084 cds_ssr_protect(__func__);
3085 ret = __hdd_stop(dev);
3086 cds_ssr_unprotect(__func__);
3087
3088 return ret;
3089}
3090
3091/**
3092 * __hdd_uninit() - HDD uninit function
3093 * @dev: Pointer to net_device structure
3094 *
3095 * This is called during the netdev unregister to uninitialize all data
3096 * associated with the device
3097 *
3098 * Return: None
3099 */
3100static void __hdd_uninit(struct net_device *dev)
3101{
Jeff Johnson9d295242017-08-29 14:39:48 -07003102 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003103 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003104
Dustin Brownfdf17c12018-03-14 12:55:34 -07003105 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106
3107 do {
3108 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003109 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110 break;
3111 }
3112
Jeff Johnson399c6272017-08-30 10:51:00 -07003113 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3114 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003115 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003116 break;
3117 }
3118
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003119 if (dev != adapter->dev)
3120 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121
Jeff Johnson399c6272017-08-30 10:51:00 -07003122 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123
3124 /* after uninit our adapter structure will no longer be valid */
3125 adapter->dev = NULL;
3126 adapter->magic = 0;
3127 } while (0);
3128
Dustin Browne74003f2018-03-14 12:51:58 -07003129 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003130}
3131
3132/**
3133 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3134 * @dev: pointer to net_device structure
3135 *
3136 * This is called during the netdev unregister to uninitialize all data
3137 * associated with the device
3138 *
3139 * Return: none
3140 */
3141static void hdd_uninit(struct net_device *dev)
3142{
3143 cds_ssr_protect(__func__);
3144 __hdd_uninit(dev);
3145 cds_ssr_unprotect(__func__);
3146}
3147
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003148static int hdd_open_cesium_nl_sock(void)
3149{
3150#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3151 struct netlink_kernel_cfg cfg = {
3152 .groups = WLAN_NLINK_MCAST_GRP_ID,
3153 .input = NULL
3154 };
3155#endif
3156 int ret = 0;
3157
3158#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3159 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3160#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3161 THIS_MODULE,
3162#endif
3163 &cfg);
3164#else
3165 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3166 WLAN_NLINK_MCAST_GRP_ID,
3167 NULL, NULL, THIS_MODULE);
3168#endif
3169
3170 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003171 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003172 ret = -ECONNREFUSED;
3173 }
3174
3175 return ret;
3176}
3177
3178static void hdd_close_cesium_nl_sock(void)
3179{
3180 if (NULL != cesium_nl_srv_sock) {
3181 netlink_kernel_release(cesium_nl_srv_sock);
3182 cesium_nl_srv_sock = NULL;
3183 }
3184}
3185
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186/**
3187 * __hdd_set_mac_address() - set the user specified mac address
3188 * @dev: Pointer to the net device.
3189 * @addr: Pointer to the sockaddr.
3190 *
3191 * This function sets the user specified mac address using
3192 * the command ifconfig wlanX hw ether <mac adress>.
3193 *
3194 * Return: 0 for success, non zero for failure
3195 */
3196static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3197{
Jeff Johnson9d295242017-08-29 14:39:48 -07003198 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003199 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303201 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303203 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204
Dustin Brownfdf17c12018-03-14 12:55:34 -07003205 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303207 if (netif_running(dev)) {
3208 hdd_err("On iface up, set mac address change isn't supported");
3209 return -EBUSY;
3210 }
3211
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3213 ret = wlan_hdd_validate_context(hdd_ctx);
3214 if (0 != ret)
3215 return ret;
3216
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303217 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
3218
3219 if (qdf_is_macaddr_zero(&mac_addr)) {
3220 hdd_err("MAC is all zero");
3221 return -EINVAL;
3222 }
3223
3224 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3225 hdd_err("MAC is Broadcast");
3226 return -EINVAL;
3227 }
3228
3229 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3230 hdd_err("MAC is Multicast");
3231 return -EINVAL;
3232 }
3233
Jeff Johnson1e851a12017-10-28 14:36:12 -07003234 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003235 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3236
Dustin Browne74003f2018-03-14 12:51:58 -07003237 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303238 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003239}
3240
3241/**
3242 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3243 * function from SSR
3244 * @dev: pointer to net_device structure
3245 * @addr: Pointer to the sockaddr
3246 *
3247 * This function sets the user specified mac address using
3248 * the command ifconfig wlanX hw ether <mac adress>.
3249 *
3250 * Return: 0 for success.
3251 */
3252static int hdd_set_mac_address(struct net_device *dev, void *addr)
3253{
3254 int ret;
3255
3256 cds_ssr_protect(__func__);
3257 ret = __hdd_set_mac_address(dev, addr);
3258 cds_ssr_unprotect(__func__);
3259
3260 return ret;
3261}
3262
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003263uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264{
3265 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003266
Anurag Chouhan6d760662016-02-20 16:05:43 +05303267 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3269 break;
3270 }
3271
Anurag Chouhan6d760662016-02-20 16:05:43 +05303272 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273 return NULL;
3274
3275 hdd_ctx->config->intfAddrMask |= (1 << i);
3276 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3277}
3278
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003279void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3280 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281{
3282 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003283
Anurag Chouhan6d760662016-02-20 16:05:43 +05303284 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003285 if (!memcmp(releaseAddr,
3286 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3287 6)) {
3288 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3289 break;
3290 }
3291 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003292}
3293
3294#ifdef WLAN_FEATURE_PACKET_FILTERING
3295/**
3296 * __hdd_set_multicast_list() - set the multicast address list
3297 * @dev: Pointer to the WLAN device.
3298 * @skb: Pointer to OS packet (sk_buff).
3299 *
3300 * This funciton sets the multicast address list.
3301 *
3302 * Return: None
3303 */
3304static void __hdd_set_multicast_list(struct net_device *dev)
3305{
Jeff Johnson9d295242017-08-29 14:39:48 -07003306 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307 int i = 0, status;
3308 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003309 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303310 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3311 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3312 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003313
Dustin Brownfdf17c12018-03-14 12:55:34 -07003314 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303315 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303316 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303317
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003318 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303319 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303320 goto out;
3321
Dustin Brownc788acb2017-08-01 17:43:51 -07003322 status = hdd_validate_adapter(adapter);
3323 if (status)
3324 goto out;
3325
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303326 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3327 hdd_err("%s: Driver module is closed", __func__);
3328 return;
3329 }
3330
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303331 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3332 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003333 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303334 goto out;
3335 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303337 /* Delete already configured multicast address list */
3338 if (adapter->mc_addr_list.mc_cnt > 0) {
3339 hdd_info("clear previously configured MC address list");
3340 hdd_disable_and_flush_mc_addr_list(adapter,
3341 pmo_mc_list_change_notify);
3342 }
3343
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003345 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303346 hdd_disable_and_flush_mc_addr_list(adapter,
3347 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348 } else {
3349 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303350 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003351 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303352 pmo_ucfg_max_mc_addr_supported(psoc));
3353 hdd_disable_and_flush_mc_addr_list(adapter,
3354 pmo_mc_list_change_notify);
3355 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003357 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003358 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303359 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360 if (i == mc_count)
3361 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303362 memset(&(mc_list_request->mc_addr[i].bytes),
3363 0, ETH_ALEN);
3364 memcpy(&(mc_list_request->mc_addr[i].bytes),
3365 ha->addr, ETH_ALEN);
3366 hdd_info("mlist[%d] = %pM", i,
3367 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368 i++;
3369 }
3370 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303371
3372 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003373 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303374 mc_list_request->count = mc_count;
3375 status = hdd_cache_mc_addr_list(mc_list_request);
3376 if (status == 0) {
3377 hdd_enable_mc_addr_filtering(adapter,
3378 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003379 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303380 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003381 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303382out:
3383 if (mc_list_request)
3384 qdf_mem_free(mc_list_request);
Dustin Browne74003f2018-03-14 12:51:58 -07003385 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003386}
3387
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303388
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003389/**
3390 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3391 * @dev: pointer to net_device
3392 *
3393 * Return: none
3394 */
3395static void hdd_set_multicast_list(struct net_device *dev)
3396{
3397 cds_ssr_protect(__func__);
3398 __hdd_set_multicast_list(dev);
3399 cds_ssr_unprotect(__func__);
3400}
3401#endif
3402
3403/**
3404 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3405 * @dev: Pointer to the WLAN device.
3406 * @skb: Pointer to OS packet (sk_buff).
3407 *
3408 * This function is registered with the Linux OS for network
3409 * core to decide which queue to use first.
3410 *
3411 * Return: ac, Queue Index/access category corresponding to UP in IP header
3412 */
3413static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3414#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3415 , void *accel_priv
3416#endif
3417#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3418 , select_queue_fallback_t fallback
3419#endif
3420)
3421{
3422 return hdd_wmm_select_queue(dev, skb);
3423}
3424
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003425static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003426 .ndo_open = hdd_open,
3427 .ndo_stop = hdd_stop,
3428 .ndo_uninit = hdd_uninit,
3429 .ndo_start_xmit = hdd_hard_start_xmit,
3430 .ndo_tx_timeout = hdd_tx_timeout,
3431 .ndo_get_stats = hdd_get_stats,
3432 .ndo_do_ioctl = hdd_ioctl,
3433 .ndo_set_mac_address = hdd_set_mac_address,
3434 .ndo_select_queue = hdd_select_queue,
3435#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437#endif
3438};
3439
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003440/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003441static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003442 .ndo_open = hdd_mon_open,
3443 .ndo_stop = hdd_stop,
3444 .ndo_get_stats = hdd_get_stats,
3445};
3446
3447/**
3448 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003449 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003450 * Return: None
3451 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003452void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003454 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003455 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003456 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003457 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003458}
3459
3460/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003461 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3462 * @hdd_ctx: global hdd context
3463 * @macAddr: mac address to assign to the interface
3464 * @name: User-visible name of the interface
3465 *
3466 * hdd adapter pointer would point to the netdev->priv space, this function
3467 * would retrive the pointer, and setup the hdd adapter configuration.
3468 *
3469 * Return: the pointer to hdd adapter, otherwise NULL
3470 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003471static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003473 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474 const char *name)
3475{
Jeff Johnson5505db82017-11-02 21:19:23 -07003476 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003477 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003478 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303479 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003480 /*
3481 * cfg80211 initialization and registration....
3482 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003483 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003484#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3485 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003486#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003487 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3488 hdd_mon_mode_ether_setup : ether_setup),
3489 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003490
Jeff Johnson5505db82017-11-02 21:19:23 -07003491 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492
3493 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003494 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003495
Jeff Johnson9d295242017-08-29 14:39:48 -07003496 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003497 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303498 qdf_mem_set(sta_ctx->conn_info.staId,
3499 sizeof(sta_ctx->conn_info.staId),
3500 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003501 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003502 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003503 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003504 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003505
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303506 qdf_status = qdf_event_create(
3507 &adapter->qdf_session_open_event);
3508 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3509 hdd_err("Session open QDF event init failed!");
3510 free_netdev(adapter->dev);
3511 return NULL;
3512 }
3513
3514 qdf_status = qdf_event_create(
3515 &adapter->qdf_session_close_event);
3516 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3517 hdd_err("Session close QDF event init failed!");
3518 free_netdev(adapter->dev);
3519 return NULL;
3520 }
3521
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303523 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003524 init_completion(&adapter->linkup_event_var);
3525 init_completion(&adapter->cancel_rem_on_chan_var);
3526 init_completion(&adapter->rem_on_chan_ready_event);
3527 init_completion(&adapter->sta_authorized_event);
3528 init_completion(&adapter->offchannel_tx_event);
3529 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003530 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303531 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003532
3533 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003534 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303535 adapter->disconnection_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003537 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538
Jeff Johnson5505db82017-11-02 21:19:23 -07003539 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003541 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003543 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003544
3545 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003546 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003547 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003548 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003549
Jeff Johnson5505db82017-11-02 21:19:23 -07003550 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003551
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552 hdd_set_station_ops(adapter->dev);
3553
Jeff Johnson5505db82017-11-02 21:19:23 -07003554 hdd_dev_setup_destructor(dev);
3555 dev->ieee80211_ptr = &adapter->wdev;
3556 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003558 adapter->wdev.netdev = dev;
3559 /* set dev's parent to underlying device */
3560 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003561 hdd_wmm_init(adapter);
3562 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303563 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003564 }
3565
3566 return adapter;
3567}
3568
Jeff Johnson9d295242017-08-29 14:39:48 -07003569static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003570{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003571 struct net_device *dev = adapter->dev;
3572 int ret;
3573
Dustin Brown491d54b2018-03-14 12:39:11 -07003574 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003575
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003576 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003577 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3578
3579 ret = dev_alloc_name(dev, dev->name);
3580 if (ret < 0) {
3581 hdd_err(
3582 "unable to get dev name: %s, err = 0x%x",
3583 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303584 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585 }
3586 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003587
3588 ret = register_netdevice(dev);
3589 if (ret) {
3590 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3591 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303592 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003593 }
3594 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003595 ret = register_netdev(dev);
3596 if (ret) {
3597 hdd_err("register_netdev(%s) failed, 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 }
3602 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3603
Dustin Browne74003f2018-03-14 12:51:58 -07003604 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003605
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303606 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003607}
3608
Krunal Sonib51eec72017-11-20 21:53:01 -08003609QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610{
Krunal Sonib51eec72017-11-20 21:53:01 -08003611 struct hdd_adapter *adapter;
3612 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003613
Krunal Sonib51eec72017-11-20 21:53:01 -08003614 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3615 if (!hdd_ctx) {
3616 hdd_err("Invalid HDD_CTX");
3617 return QDF_STATUS_E_FAILURE;
3618 }
3619
3620 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3621 if (NULL == adapter) {
3622 hdd_err("NULL adapter");
3623 return QDF_STATUS_E_INVAL;
3624 }
3625 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303626 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003627 hdd_debug("session %d opened", adapter->session_id);
3628
3629 return QDF_STATUS_SUCCESS;
3630}
3631
3632QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3633{
3634 struct hdd_adapter *adapter;
3635 struct hdd_context *hdd_ctx;
3636
3637 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3638 if (!hdd_ctx) {
3639 hdd_err("Invalid HDD_CTX");
3640 return QDF_STATUS_E_FAILURE;
3641 }
3642
3643 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003645 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303646 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003647 }
3648
3649 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003650 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303651 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652 }
3653
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003654 /*
3655 * For NAN Data interface, the close session results in the final
3656 * indication to the userspace
3657 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003658 if (adapter->device_mode == QDF_NDI_MODE)
3659 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3662
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003663 /*
3664 * We can be blocked while waiting for scheduled work to be
3665 * flushed, and the adapter structure can potentially be freed, in
3666 * which case the magic will have been reset. So make sure the
3667 * magic is still good, and hence the adapter structure is still
3668 * valid, before signaling completion
3669 */
3670 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303671 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003672
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303673 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674}
3675
Jeff Johnson9d295242017-08-29 14:39:48 -07003676int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677{
Dustin Brownd28772b2017-03-17 14:16:07 -07003678 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679
Dustin Brownd28772b2017-03-17 14:16:07 -07003680 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003681 if (QDF_IS_STATUS_ERROR(status))
3682 return qdf_status_to_os_return(status);
3683
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003684 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003685 if (QDF_IS_STATUS_ERROR(status))
3686 return qdf_status_to_os_return(status);
3687
3688 if (wma_capability_enhanced_mcast_filter())
3689 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3690 else
3691 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003692
3693 return qdf_status_to_os_return(status);
3694}
3695
Jeff Johnson9d295242017-08-29 14:39:48 -07003696int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003697{
3698 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003699 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003700 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003701 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003702
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003703 vdev_id = adapter->session_id;
3704 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003705
3706 /* vdev created sanity check */
3707 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003708 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003709 return -EINVAL;
3710 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003711 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003712
Dustin Brownd28772b2017-03-17 14:16:07 -07003713 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303714 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003715 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003716 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003717 if (QDF_IS_STATUS_ERROR(status)) {
3718 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003719 errno = qdf_status_to_os_return(status);
3720 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003721 }
3722
3723 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303724 status = qdf_wait_for_event_completion(
3725 &adapter->qdf_session_close_event,
3726 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3727 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003728 if (adapter->device_mode == QDF_NDI_MODE)
3729 hdd_ndp_session_end_handler(adapter);
3730 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303731 adapter->session_id = HDD_SESSION_ID_INVALID;
3732 if (QDF_STATUS_E_TIMEOUT != status) {
3733 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003734 errno = -ETIMEDOUT;
3735 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303736 } else if (adapter->qdf_session_close_event.force_set) {
3737 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003738 errno = -EINVAL;
3739 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303740 } else {
3741 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003742 errno = -EINVAL;
3743 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303744 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003745 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003746
Yue Maf9782842017-05-08 12:49:49 -07003747release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003748 /*
3749 * In SSR or driver unloading case, directly exit may cause objects
3750 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003751 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003752 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003753 return errno;
3754
Sandeep Puligillaef415362017-08-30 16:37:13 -07003755 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003756 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003757 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003758 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003759 return errno;
3760 }
3761
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003762 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003763
3764 return 0;
3765}
3766
Krunal Sonib51eec72017-11-20 21:53:01 -08003767static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3768 struct sme_session_params *session_param,
3769 csr_roam_completeCallback callback,
3770 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003771{
Dustin Brownd28772b2017-03-17 14:16:07 -07003772 uint32_t type;
3773 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003774 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003775
3776 /* determine vdev (sub)type */
3777 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303778 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003779 hdd_err("failed to get vdev type: %d", status);
3780 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003781 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003782 session_param->sme_session_id = adapter->session_id;
3783 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3784 session_param->type_of_persona = type;
3785 session_param->subtype_of_persona = sub_type;
3786 session_param->session_open_cb = hdd_sme_open_session_callback;
3787 session_param->session_close_cb = hdd_sme_close_session_callback;
3788 session_param->callback = callback;
3789 session_param->callback_ctx = callback_ctx;
3790
3791 return 0;
3792}
3793
3794int hdd_vdev_create(struct hdd_adapter *adapter,
3795 csr_roam_completeCallback callback, void *ctx)
3796{
3797 QDF_STATUS status;
3798 int errno;
3799 struct hdd_context *hdd_ctx;
3800 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003801
3802 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003803
3804 /* do vdev create via objmgr */
3805 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003806 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003807 if (errno) {
3808 hdd_err("failed to create objmgr vdev: %d", errno);
3809 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003810 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003811
3812 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303813 status = qdf_event_reset(&adapter->qdf_session_open_event);
3814 if (QDF_STATUS_SUCCESS != status) {
3815 hdd_err("failed to reinit session open event");
3816 return -EINVAL;
3817 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003818 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3819 callback, ctx);
3820 if (errno) {
3821 hdd_err("failed to populating SME params");
3822 goto objmgr_vdev_destroy_procedure;
3823 }
3824
3825 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003826 if (QDF_IS_STATUS_ERROR(status)) {
3827 hdd_err("failed to open sme session: %d", status);
3828 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003829 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003830 }
3831
3832 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303833 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3834 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3835 if (QDF_STATUS_SUCCESS != status) {
3836 if (adapter->qdf_session_open_event.force_set) {
3837 /*
3838 * SSR/PDR has caused shutdown, which has forcefully
3839 * set the event. Return without the closing session.
3840 */
3841 adapter->session_id = HDD_SESSION_ID_INVALID;
3842 hdd_err("Session open event forcefully set");
3843 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303844 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003845
3846 if (QDF_STATUS_E_TIMEOUT == status)
3847 hdd_err("Session failed to open within timeout period");
3848 else
3849 hdd_err("Failed to wait for session open event(status-%d)",
3850 status);
3851 errno = -ETIMEDOUT;
3852 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3853 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003854 }
3855
3856 /* firmware ready for component communication, raise vdev_ready event */
3857 errno = hdd_vdev_ready(adapter);
3858 if (errno) {
3859 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003860 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003861 }
3862
Jeff Johnson1b780e42017-10-31 14:11:45 -07003863 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003864
3865 return 0;
3866
3867 /*
3868 * Due to legacy constraints, we need to destroy in the same order as
3869 * create. So, split error handling into 2 cases to accommodate.
3870 */
3871
Krunal Soni4a020c72017-10-30 20:58:40 -07003872objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003873 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003874
3875 return errno;
3876
Krunal Soni4a020c72017-10-30 20:58:40 -07003877hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003878 QDF_BUG(!hdd_vdev_destroy(adapter));
3879
3880 return errno;
3881}
3882
Jeff Johnson9d295242017-08-29 14:39:48 -07003883QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003884{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003885 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003886 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003887 QDF_STATUS status;
3888 int ret_val;
3889
Dustin Brownd28772b2017-03-17 14:16:07 -07003890 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3891 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3892 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003893 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003894
Jeff Johnson7f2c5912018-03-23 11:42:28 -07003895 hdd_roam_profile_init(adapter);
3896 hdd_register_wext(adapter->dev);
3897
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003898 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003899
Jeff Johnsond377dce2017-10-04 10:32:42 -07003900 qdf_mem_set(sta_ctx->conn_info.staId,
3901 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303902
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003903 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003904 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303905 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003907 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003908 hdd_ctx->config->OperatingChannel;
3909
3910 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003911 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003912
3913 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303914 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003915 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916 status, status);
3917 goto error_init_txrx;
3918 }
3919
3920 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3921
3922 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303923 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003924 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925 status, status);
3926 goto error_wmm_init;
3927 }
3928
3929 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3930
Jeff Johnson1b780e42017-10-31 14:11:45 -07003931 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932 WMI_PDEV_PARAM_BURST_ENABLE,
3933 hdd_ctx->config->enableSifsBurst,
3934 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003935 if (ret_val)
3936 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303938 /*
3939 * In case of USB tethering, LRO is disabled. If SSR happened
3940 * during that time, then as part of SSR init, do not enable
3941 * the LRO again. Keep the LRO state same as before SSR.
3942 */
3943 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003944 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303945
3946 /* rcpi info initialization */
3947 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3948
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303949 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951error_wmm_init:
3952 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3953 hdd_deinit_tx_rx(adapter);
3954error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003955 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003956 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 return status;
3959}
3960
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303961/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003962 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303963 * @hdd_ctx: global hdd context
3964 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003965 * @rtnl_held: Used to indicate whether or not the caller is holding
3966 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303967 *
3968 * This function De-initializes the STA/P2P/OCB adapter.
3969 *
3970 * Return: None.
3971 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003972static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003973 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003974 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303975{
Dustin Brownfdf17c12018-03-14 12:55:34 -07003976 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303977
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303978 if (adapter->dev) {
3979 if (rtnl_held)
3980 adapter->dev->wireless_handlers = NULL;
3981 else {
3982 rtnl_lock();
3983 adapter->dev->wireless_handlers = NULL;
3984 rtnl_unlock();
3985 }
3986 }
3987
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303988 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3989 hdd_deinit_tx_rx(adapter);
3990 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3991 }
3992
3993 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3994 hdd_wmm_adapter_close(adapter);
3995 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3996 }
3997
Krunal Sonib51eec72017-11-20 21:53:01 -08003998
Dustin Browne74003f2018-03-14 12:51:58 -07003999 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304000}
4001
Krunal Sonib51eec72017-11-20 21:53:01 -08004002void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4003 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 bool rtnl_held)
4005{
Dustin Brown491d54b2018-03-14 12:39:11 -07004006 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004009 case QDF_STA_MODE:
4010 case QDF_P2P_CLIENT_MODE:
4011 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004012 case QDF_IBSS_MODE:
4013 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004014 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004015 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016 break;
4017 }
4018
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004019 case QDF_SAP_MODE:
4020 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004022 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 break;
4024 }
4025
4026 default:
4027 break;
4028 }
4029
Dustin Browne74003f2018-03-14 12:51:58 -07004030 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004031}
4032
Jeff Johnson9d295242017-08-29 14:39:48 -07004033static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004034 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035{
Jeff Johnson5505db82017-11-02 21:19:23 -07004036 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037
4038 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004039 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004040 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004041 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042 return;
4043 }
4044
Alok Kumarb64650c2018-03-23 17:05:11 +05304045 hdd_nud_deinit_tracking(adapter);
4046 qdf_mutex_destroy(&adapter->disconnection_status_lock);
4047
Rajeev Kumardca5f812016-02-04 17:28:06 -08004048 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 /*
4051 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4052 * the driver is almost closed and cannot handle either control
4053 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004054 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4055 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056 * is not right. Setting this flag helps hdd_stop() to recognize that
4057 * the interface is closed and restricts any operations on that
4058 */
4059 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4060
4061 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004062 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004063 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004064 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004065 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066 /*
4067 * Note that the adapter is no longer valid at this point
4068 * since the memory has been reclaimed
4069 */
4070 }
4071}
4072
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004073static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004074 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004075{
Jeff Johnson9d295242017-08-29 14:39:48 -07004076 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004077
Dustin Brown920397d2017-12-13 16:27:50 -08004078 hdd_for_each_adapter(hdd_ctx, adapter) {
4079 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4080 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304081 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004082 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004083 }
Dustin Brown920397d2017-12-13 16:27:50 -08004084
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304085 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004087
Arun Khandavalli2358d522016-05-16 18:05:37 +05304088#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4089/**
4090 * hdd_set_fw_log_params() - Set log parameters to FW
4091 * @hdd_ctx: HDD Context
4092 * @adapter: HDD Adapter
4093 *
4094 * This function set the FW Debug log level based on the INI.
4095 *
4096 * Return: None
4097 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004098static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004099 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304100{
4101 uint8_t count = 0, numentries = 0,
4102 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4103 uint32_t value = 0;
4104 int ret;
4105
Arun Khandavallifae92942016-08-01 13:31:08 +05304106 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4107 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004108 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304109 return;
4110 }
4111
Arun Khandavallifae92942016-08-01 13:31:08 +05304112 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304113 hdd_ctx->fw_log_settings.dl_type =
4114 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004115 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304116 WMI_DBGLOG_TYPE,
4117 hdd_ctx->config->enableFwLogType,
4118 DBG_CMD);
4119 if (ret != 0)
4120 hdd_err("Failed to enable FW log type ret %d",
4121 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304122
4123 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304124 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004125 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304126 WMI_DBGLOG_LOG_LEVEL,
4127 hdd_ctx->config->enableFwLogLevel,
4128 DBG_CMD);
4129 if (ret != 0)
4130 hdd_err("Failed to enable FW log level ret %d",
4131 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304132
4133 hdd_string_to_u8_array(
4134 hdd_ctx->config->enableFwModuleLogLevel,
4135 moduleloglevel,
4136 &numentries,
4137 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4138
4139 while (count < numentries) {
4140 /*
4141 * FW module log level input string looks like
4142 * below:
4143 * gFwDebugModuleLoglevel=<FW Module ID>,
4144 * <Log Level>,...
4145 * For example:
4146 * gFwDebugModuleLoglevel=
4147 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4148 * Above input string means :
4149 * For FW module ID 1 enable log level 0
4150 * For FW module ID 2 enable log level 1
4151 * For FW module ID 3 enable log level 2
4152 * For FW module ID 4 enable log level 3
4153 * For FW module ID 5 enable log level 4
4154 * For FW module ID 6 enable log level 5
4155 * For FW module ID 7 enable log level 6
4156 */
4157
Nishank Aggarwale239d962017-03-03 12:26:02 +05304158 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4159 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4160 hdd_err("Module id %d and dbglog level %d input length is more than max",
4161 moduleloglevel[count],
4162 moduleloglevel[count + 1]);
4163 return;
4164 }
4165
4166 value = moduleloglevel[count] << 16;
4167 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004168 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304169 WMI_DBGLOG_MOD_LOG_LEVEL,
4170 value, DBG_CMD);
4171 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304172 hdd_err("Failed to enable FW module log level %d ret %d",
4173 value, ret);
4174
4175 count += 2;
4176 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304177
Arun Khandavalli2358d522016-05-16 18:05:37 +05304178}
4179#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004180static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004181 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304182{
4183}
4184
4185#endif
4186
4187/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004188 * hdd_configure_chain_mask() - programs chain mask to firmware
4189 * @adapter: HDD adapter
4190 *
4191 * Return: 0 on success or errno on failure
4192 */
4193static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4194{
4195 int ret_val;
4196 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4197
4198 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4199 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4200 hdd_ctx->config->txchainmask1x1,
4201 hdd_ctx->config->rxchainmask1x1);
4202 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4203 hdd_ctx->config->dual_mac_feature_disable,
4204 hdd_ctx->config->tx_chain_mask_2g,
4205 hdd_ctx->config->rx_chain_mask_2g);
4206 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4207 hdd_ctx->config->tx_chain_mask_5g,
4208 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004209 hdd_debug("enable_bt_chain_separation %d",
4210 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004211
Liangwei Dong22810e82018-03-15 03:42:12 -04004212 if (hdd_ctx->config->enable2x2 &&
4213 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004214 hdd_info("2x2 enabled. skip chain mask programming");
4215 return 0;
4216 }
4217
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004218 if (hdd_ctx->config->dual_mac_feature_disable !=
4219 DISABLE_DBS_CXN_AND_SCAN) {
4220 hdd_info("DBS enabled(%d). skip chain mask programming",
4221 hdd_ctx->config->dual_mac_feature_disable);
4222 return 0;
4223 }
4224
Naveen Rawatdacb5032018-02-08 15:23:24 -08004225 if (hdd_ctx->lte_coex_ant_share) {
4226 hdd_info("lte ant sharing enabled. skip chainmask programming");
4227 return 0;
4228 }
4229
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004230 if (hdd_ctx->config->txchainmask1x1) {
4231 ret_val = sme_cli_set_command(adapter->session_id,
4232 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4233 hdd_ctx->config->txchainmask1x1,
4234 PDEV_CMD);
4235 if (ret_val)
4236 goto error;
4237 }
4238
4239 if (hdd_ctx->config->rxchainmask1x1) {
4240 ret_val = sme_cli_set_command(adapter->session_id,
4241 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4242 hdd_ctx->config->rxchainmask1x1,
4243 PDEV_CMD);
4244 if (ret_val)
4245 goto error;
4246 }
4247
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004248 if (hdd_ctx->config->txchainmask1x1 ||
4249 hdd_ctx->config->rxchainmask1x1) {
4250 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4251 return 0;
4252 }
4253
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004254 if (hdd_ctx->config->tx_chain_mask_2g) {
4255 ret_val = sme_cli_set_command(adapter->session_id,
4256 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4257 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4258 if (0 != ret_val)
4259 goto error;
4260 }
4261
4262 if (hdd_ctx->config->rx_chain_mask_2g) {
4263 ret_val = sme_cli_set_command(adapter->session_id,
4264 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4265 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4266 if (0 != ret_val)
4267 goto error;
4268 }
4269
4270 if (hdd_ctx->config->tx_chain_mask_5g) {
4271 ret_val = sme_cli_set_command(adapter->session_id,
4272 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4273 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4274 if (0 != ret_val)
4275 goto error;
4276 }
4277
4278 if (hdd_ctx->config->rx_chain_mask_5g) {
4279 ret_val = sme_cli_set_command(adapter->session_id,
4280 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4281 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4282 if (0 != ret_val)
4283 goto error;
4284 }
4285
4286 return 0;
4287
4288error:
4289 hdd_err("WMI PDEV set param failed %d", ret_val);
4290 return -EINVAL;
4291}
4292
4293/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304294 * hdd_set_fw_params() - Set parameters to firmware
4295 * @adapter: HDD adapter
4296 *
4297 * This function Sets various parameters to fw once the
4298 * adapter is started.
4299 *
4300 * Return: 0 on success or errno on failure
4301 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004302int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304303{
4304 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004305 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304306
Dustin Brownfdf17c12018-03-14 12:55:34 -07004307 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304308
4309 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4310 if (!hdd_ctx)
4311 return -EINVAL;
4312
Dustin Brown732ab9c2017-06-15 13:24:09 -07004313 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4314 hdd_debug("FTM Mode is active; nothing to do");
4315 return 0;
4316 }
4317
Jeff Johnson1b780e42017-10-31 14:11:45 -07004318 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304319 WMI_PDEV_PARAM_DTIM_SYNTH,
4320 hdd_ctx->config->enable_lprx, PDEV_CMD);
4321 if (ret) {
4322 hdd_err("Failed to set LPRx");
4323 goto error;
4324 }
4325
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304326
4327 ret = sme_cli_set_command(
4328 adapter->session_id,
4329 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4330 hdd_ctx->config->enable_dtim_selection_diversity,
4331 PDEV_CMD);
4332 if (ret) {
4333 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4334 goto error;
4335 }
4336
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304337 ret = sme_cli_set_command(
4338 adapter->session_id,
4339 WMI_PDEV_PARAM_TX_SCH_DELAY,
4340 hdd_ctx->config->enable_tx_sch_delay,
4341 PDEV_CMD);
4342 if (ret) {
4343 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4344 goto error;
4345 }
4346
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304347 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004348 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304349 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4350 hdd_ctx->config->upper_brssi_thresh);
4351
Jeff Johnson1b780e42017-10-31 14:11:45 -07004352 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304353 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4354 hdd_ctx->config->lower_brssi_thresh);
4355
Jeff Johnson1b780e42017-10-31 14:11:45 -07004356 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304357 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4358 hdd_ctx->config->enable_dtim_1chrx);
4359 }
4360
Dustin Brown732ab9c2017-06-15 13:24:09 -07004361 if (hdd_ctx->config->enable2x2) {
4362 hdd_debug("configuring 2x2 mode fw params");
4363
Jeff Johnson1b780e42017-10-31 14:11:45 -07004364 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004365 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4366 hdd_ctx->config->enable_cck_tx_fir_override,
4367 PDEV_CMD);
4368 if (ret) {
4369 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4370 ret);
4371 goto error;
4372 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004373
4374 if (hdd_configure_chain_mask(adapter))
4375 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004376 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304377#define HDD_DTIM_1CHAIN_RX_ID 0x5
4378#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004379 hdd_debug("configuring 1x1 mode fw params");
4380
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004381 /*
4382 * Disable DTIM 1 chain Rx when in 1x1,
4383 * we are passing two value
4384 * as param_id << 29 | param_value.
4385 * Below param_value = 0(disable)
4386 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004387 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004388 WMI_STA_SMPS_PARAM_CMDID,
4389 HDD_DTIM_1CHAIN_RX_ID <<
4390 HDD_SMPS_PARAM_VALUE_S,
4391 VDEV_CMD);
4392 if (ret) {
4393 hdd_err("DTIM 1 chain set failed %d", ret);
4394 goto error;
4395 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304396
Arun Khandavalli2358d522016-05-16 18:05:37 +05304397#undef HDD_DTIM_1CHAIN_RX_ID
4398#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004399
4400 if (hdd_configure_chain_mask(adapter))
4401 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004402 }
4403
Jeff Johnson1b780e42017-10-31 14:11:45 -07004404 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004405 WMI_PDEV_PARAM_HYST_EN,
4406 hdd_ctx->config->enableMemDeepSleep,
4407 PDEV_CMD);
4408 if (ret) {
4409 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4410 goto error;
4411 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304412
Jeff Johnson1b780e42017-10-31 14:11:45 -07004413 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004414 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4415 hdd_ctx->config->rts_profile,
4416 VDEV_CMD);
4417 if (ret) {
4418 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4419 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304420 }
4421
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004422 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4423
Jeff Johnson1b780e42017-10-31 14:11:45 -07004424 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004425 GEN_VDEV_PARAM_AMSDU,
4426 hdd_ctx->config->max_amsdu_num,
4427 GEN_CMD);
4428 if (ret != 0) {
4429 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4430 goto error;
4431 }
4432
Arun Khandavalli2358d522016-05-16 18:05:37 +05304433 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004434 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004435
Arun Khandavalli2358d522016-05-16 18:05:37 +05304436 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304437
Arun Khandavalli2358d522016-05-16 18:05:37 +05304438error:
4439 return -EINVAL;
4440}
4441
Ryan Hsu07495ea2016-01-21 15:25:39 -08004442/**
4443 * hdd_open_adapter() - open and setup the hdd adatper
4444 * @hdd_ctx: global hdd context
4445 * @session_type: type of the interface to be created
4446 * @iface_name: User-visible name of the interface
4447 * @macAddr: MAC address to assign to the interface
4448 * @name_assign_type: the name of assign type of the netdev
4449 * @rtnl_held: the rtnl lock hold flag
4450 *
4451 * This function open and setup the hdd adpater according to the device
4452 * type request, assign the name, the mac address assigned, and then prepared
4453 * the hdd related parameters, queue, lock and ready to start.
4454 *
4455 * Return: the pointer of hdd adapter, otherwise NULL.
4456 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004457struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004459 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004460 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004461{
Jeff Johnson9d295242017-08-29 14:39:48 -07004462 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304463 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464
4465 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4466 /*
4467 * Max limit reached on the number of vdevs configured by the
4468 * host. Return error
4469 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304470 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4471 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004472 return NULL;
4473 }
4474
4475 if (macAddr == NULL) {
4476 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304477 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004478 return NULL;
4479 }
4480 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304481 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304482 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4483 " already exists",
4484 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004485 return NULL;
4486 }
4487
4488 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004489 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004490 /* Reset locally administered bit if the device mode is STA */
4491 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304492 hdd_info("locally administered bit reset in sta mode: "
4493 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004494 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004495 case QDF_P2P_CLIENT_MODE:
4496 case QDF_P2P_DEVICE_MODE:
4497 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004498 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304499 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004500 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4501 name_assign_type,
4502 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004503
4504 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304505 hdd_err("failed to allocate adapter for session %d",
4506 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507 return NULL;
4508 }
4509
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004510 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004512 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004513 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304514 else if (QDF_MONITOR_MODE == session_type)
4515 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004516 else
4517 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4518
4519 adapter->device_mode = session_type;
4520
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004521
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004522 /*
4523 * Workqueue which gets scheduled in IPv4 notification
4524 * callback
4525 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004526 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528
4529#ifdef WLAN_NS_OFFLOAD
4530 /*
4531 * Workqueue which gets scheduled in IPv6
4532 * notification callback.
4533 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004534 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004535 hdd_ipv6_notifier_work_queue);
4536#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004538 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004539 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004540
4541 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004542 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004543 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304544 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4545 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304546
Ravi Joshi1a292562017-05-18 16:28:54 -07004547 /* Initialize NAN Data Interface */
4548 if (QDF_NDI_MODE == session_type) {
4549 status = hdd_init_nan_data_mode(adapter);
4550 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004551 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004552 }
4553
Alok Kumarb64650c2018-03-23 17:05:11 +05304554 hdd_nud_init_tracking(adapter);
4555
4556 qdf_mutex_create(&adapter->disconnection_status_lock);
4557
Ravi Joshi1a292562017-05-18 16:28:54 -07004558 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004560 case QDF_P2P_GO_MODE:
4561 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004562 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4563 name_assign_type,
4564 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004565 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004566 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304567 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568 return NULL;
4569 }
4570
4571 adapter->wdev.iftype =
4572 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004573 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574 NL80211_IFTYPE_P2P_GO;
4575 adapter->device_mode = session_type;
4576
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004577 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004578 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004579 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004580
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004581 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004582 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304583 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4584 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304585
4586 /*
4587 * Workqueue which gets scheduled in IPv4 notification
4588 * callback
4589 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004590 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304591 hdd_ipv4_notifier_work_queue);
4592
4593#ifdef WLAN_NS_OFFLOAD
4594 /*
4595 * Workqueue which gets scheduled in IPv6
4596 * notification callback.
4597 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004598 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304599 hdd_ipv6_notifier_work_queue);
4600#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004601 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304602 case QDF_FTM_MODE:
4603 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4604 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004605 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304606 if (NULL == adapter) {
4607 hdd_err("Failed to allocate adapter for FTM mode");
4608 return NULL;
4609 }
4610 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4611 adapter->device_mode = session_type;
4612 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004613 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004614 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004615
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304616 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004617 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304618 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304619 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4620 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304621 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004622 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004623 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304624 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625 return NULL;
4626 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004627
hqueaa33ee2017-05-04 17:56:35 +08004628 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4629
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304630 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004631 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004632 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004633 }
4634
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304635 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004636 if (NULL != adapter) {
4637 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4638 adapter = NULL;
4639 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004640
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004641 return NULL;
4642 }
4643
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304644 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004645 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4646 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004647
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004648 /* Adapter successfully added. Increment the vdev count */
4649 hdd_ctx->current_intf_count++;
4650
Jeff Johnson5880d792016-08-15 13:32:30 -07004651 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004652 hdd_ctx->current_intf_count);
4653
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004654 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655 }
4656
Rajeev Kumardca5f812016-02-04 17:28:06 -08004657 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004658 hdd_err("Interface %s wow debug_fs init failed",
4659 netdev_name(adapter->dev));
4660
4661 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4662 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004663
4664 return adapter;
4665
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004666err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004667 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304668 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004669
4670 return NULL;
4671}
4672
Nirav Shaheb017be2018-02-15 11:20:58 +05304673#ifdef MSM_PLATFORM
4674static inline
4675void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4676{
4677 cancel_work_sync(&hdd_ctx->bus_bw_work);
4678}
4679#else
4680static inline
4681void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4682{
4683}
4684#endif
4685
Jeff Johnson9d295242017-08-29 14:39:48 -07004686QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004687 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004688{
Dustin Brown920397d2017-12-13 16:27:50 -08004689 /*
4690 * Here we are stopping global bus_bw timer & work per adapter.
4691 *
4692 * The reason is to fix one race condition between
4693 * bus bandwidth work and cleaning up an adapter.
4694 * Under some conditions, it is possible for the bus bandwidth
4695 * work to access a particularly destroyed adapter, leading to
4696 * use-after-free.
4697 */
4698 hdd_debug("wait for bus bw work to flush");
4699 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4700 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004701
Dustin Brown920397d2017-12-13 16:27:50 -08004702 /* cleanup adapter */
4703 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4704 adapter->device_mode);
4705 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4706 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004707
Dustin Brown920397d2017-12-13 16:27:50 -08004708 /* conditionally restart the bw timer */
4709 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004710
Dustin Brown920397d2017-12-13 16:27:50 -08004711 /* Adapter removed. Decrement vdev count */
4712 if (hdd_ctx->current_intf_count != 0)
4713 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004714
Dustin Brown920397d2017-12-13 16:27:50 -08004715 /* Fw will take care incase of concurrency */
4716 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004717}
4718
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004719/**
4720 * hdd_close_all_adapters - Close all open adapters
4721 * @hdd_ctx: Hdd context
4722 * rtnl_held: True if RTNL lock held
4723 *
4724 * Close all open adapters.
4725 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304726 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004727 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004728QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729{
Dustin Brown920397d2017-12-13 16:27:50 -08004730 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304731 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004732
Dustin Brown491d54b2018-03-14 12:39:11 -07004733 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004734
4735 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004736 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4737 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304738 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004739 adapter->mac_addr.bytes);
4740 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4741
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304742 /* Adapter removed. Decrement vdev count */
4743 if (hdd_ctx->current_intf_count != 0)
4744 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004745 }
Dustin Brown920397d2017-12-13 16:27:50 -08004746 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004747
Dustin Browne74003f2018-03-14 12:51:58 -07004748 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004749
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304750 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004751}
4752
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004753void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004754{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304755 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004756 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004757
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004758 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004759 case QDF_STA_MODE:
4760 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004761 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004762 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004763 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004764 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004765 break;
4766 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004767 case QDF_SAP_MODE:
4768 case QDF_P2P_GO_MODE:
4769 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004770 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004771 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004772 break;
4773 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004774 case QDF_FTM_MODE:
4775 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004776 default:
4777 /*
4778 * wlan_hdd_reset_prob_rspies should not have been called
4779 * for these kind of devices
4780 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004781 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004782 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004783 return;
4784 }
4785
Anurag Chouhanc5548422016-02-24 18:33:27 +05304786 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004787 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004788 updateIE.ieBufferlength = 0;
4789 updateIE.pAdditionIEBuffer = NULL;
4790 updateIE.append = true;
4791 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004792 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304794 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004795 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004796 }
4797}
4798
Dustin Browndb2a8be2017-12-20 11:49:56 -08004799QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4800 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004801{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304802 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07004803 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004804 union iwreq_data wrqu;
4805 tSirUpdateIE updateIE;
4806 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304807 tsap_Config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808
Dustin Brown491d54b2018-03-14 12:39:11 -07004809 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004810
Alok Kumarb64650c2018-03-23 17:05:11 +05304811 hdd_nud_ignore_tracking(adapter, true);
4812 hdd_nud_reset_tracking(adapter);
4813
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004814 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304815 wlan_hdd_netif_queue_control(adapter,
4816 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4817 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004818 /*
4819 * if this is the last active connection check & stop the
4820 * opportunistic timer first
4821 */
4822 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4823 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4824 policy_mgr_convert_device_mode_to_qdf_type(
4825 adapter->device_mode), NULL) == 1)) ||
4826 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4827 policy_mgr_check_and_stop_opportunistic_timer(
4828 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004829 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004830 case QDF_STA_MODE:
4831 case QDF_P2P_CLIENT_MODE:
4832 case QDF_IBSS_MODE:
4833 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004834 case QDF_NDI_MODE:
4835 if ((QDF_NDI_MODE == adapter->device_mode) ||
4836 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004837 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4838 hdd_is_connecting(
4839 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004840 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07004841 roam_profile = hdd_roam_profile(adapter);
4842 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004843 if (QDF_NDI_MODE == adapter->device_mode)
4844 qdf_ret_status = sme_roam_disconnect(
4845 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004846 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004847 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07004848 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004849 eCSR_BSS_TYPE_START_IBSS)
4850 qdf_ret_status = sme_roam_disconnect(
4851 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004852 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004853 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004854 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004855 qdf_ret_status =
4856 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004857 hdd_debug("Send disconnected event to userspace");
4858 wlan_hdd_cfg80211_indicate_disconnect(
4859 adapter->dev, true,
4860 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08004861 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004862 qdf_ret_status = sme_roam_disconnect(
4863 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004864 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004865 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004866 /* success implies disconnect command got
4867 * queued up successfully
4868 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004869 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4870 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871 rc = wait_for_completion_timeout(
4872 &adapter->disconnect_comp_var,
4873 msecs_to_jiffies
4874 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004875 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004876 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004877 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004878 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4879 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004880 memset(&wrqu, '\0', sizeof(wrqu));
4881 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4882 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4883 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4884 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304885 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004886 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004887
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304888 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304889 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004890
4891#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004892 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893#endif
4894
4895 hdd_deregister_tx_flow_control(adapter);
4896
4897#ifdef WLAN_NS_OFFLOAD
4898#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004899 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900#endif
4901#endif
4902
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304903 if (adapter->device_mode == QDF_STA_MODE)
4904 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4905 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004906
4907 if (wlan_hdd_try_disconnect(adapter)) {
4908 hdd_err("Error: Can't disconnect adapter");
4909 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004910 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004911
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304912 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004913 break;
4914
Rajeev Kumar3b906202018-02-01 10:55:14 -08004915 case QDF_MONITOR_MODE:
4916 wlan_hdd_scan_abort(adapter);
4917 hdd_deregister_tx_flow_control(adapter);
4918 hdd_vdev_destroy(adapter);
4919 break;
4920
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004921 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004922 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304923 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304924 sap_config = &adapter->session.ap.sap_config;
4925 if (sap_config)
4926 wlansap_reset_sap_config_add_ie(sap_config,
4927 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05304928 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004929 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004930
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004931 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004932 if (QDF_SAP_MODE == adapter->device_mode) {
4933 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4934 cds_flush_delayed_work(
4935 &adapter->acs_pending_work);
4936 clear_bit(ACS_PENDING, &adapter->event_flags);
4937 }
4938 }
Krunal Soni22208392017-09-29 18:10:34 -07004939 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004940
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004941 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004942 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004943 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004944 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4945
4946 hdd_deregister_tx_flow_control(adapter);
4947
Kapil Guptac1224bf2017-06-22 21:22:40 +05304948 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004949 mutex_lock(&hdd_ctx->sap_lock);
4950 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304951 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304952 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004953
4954 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004955 status = wlansap_stop_bss(
4956 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004957
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304958 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004959 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004960 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304961 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304962 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304963 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304964 qdf_wait_for_event_completion(
4965 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004966 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004967
Anurag Chouhance0dc992016-02-16 18:18:03 +05304968 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004969 hdd_err("failure waiting for wlansap_stop_bss %d",
4970 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004971 }
4972 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004973 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004974 }
4975 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004976 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4977 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004978 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07004979 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05304980 adapter->device_mode,
4981 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004982
Anurag Chouhanc5548422016-02-24 18:33:27 +05304983 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004984 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004985 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004986 updateIE.ieBufferlength = 0;
4987 updateIE.pAdditionIEBuffer = NULL;
4988 updateIE.append = false;
4989 updateIE.notify = false;
4990 /* Probe bcn reset */
4991 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4992 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304993 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004994 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995 }
4996 /* Assoc resp reset */
4997 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4998 &updateIE,
4999 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305000 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005001 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002 }
5003 /* Reset WNI_CFG_PROBE_RSP Flags */
5004 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07005006 qdf_mem_free(adapter->session.ap.beacon);
5007 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305008 /*
5009 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5010 */
5011 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5012 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5013
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305014#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005015 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305016#endif
5017
5018#ifdef WLAN_NS_OFFLOAD
5019#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005020 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305021#endif
5022#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005023
5024 hdd_vdev_destroy(adapter);
5025
Krunal Sonib51eec72017-11-20 21:53:01 -08005026 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005027 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005028 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005029 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005030 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005031 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005032 hdd_deregister_tx_flow_control(adapter);
5033 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005034 break;
5035 default:
5036 break;
5037 }
5038
Dustin Brown04348372017-12-14 16:13:39 -08005039 if (adapter->scan_info.default_scan_ies) {
5040 qdf_mem_free(adapter->scan_info.default_scan_ies);
5041 adapter->scan_info.default_scan_ies = NULL;
5042 }
5043
Dustin Browne74003f2018-03-14 12:51:58 -07005044 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005045
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305046 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005047}
5048
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305049/**
5050 * hdd_deinit_all_adapters - deinit all adapters
5051 * @hdd_ctx: HDD context
5052 * @rtnl_held: True if RTNL lock held
5053 *
5054 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005055void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305056{
Jeff Johnson9d295242017-08-29 14:39:48 -07005057 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305058
Dustin Brown491d54b2018-03-14 12:39:11 -07005059 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305060
Dustin Brown920397d2017-12-13 16:27:50 -08005061 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305062 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305063
Dustin Browne74003f2018-03-14 12:51:58 -07005064 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305065}
5066
Dustin Browndb2a8be2017-12-20 11:49:56 -08005067QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068{
Jeff Johnson9d295242017-08-29 14:39:48 -07005069 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005070
Dustin Brown491d54b2018-03-14 12:39:11 -07005071 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005072
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305073 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5074
Dustin Brown920397d2017-12-13 16:27:50 -08005075 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005076 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005077
Dustin Browne74003f2018-03-14 12:51:58 -07005078 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305080 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081}
5082
Paul Zhang84fa9382017-11-10 21:18:21 +08005083static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5084 struct hdd_adapter *adapter)
5085{
5086 switch (adapter->device_mode) {
5087 case QDF_STA_MODE:
5088 case QDF_P2P_CLIENT_MODE:
5089 case QDF_IBSS_MODE:
5090 case QDF_P2P_DEVICE_MODE:
5091 case QDF_NDI_MODE:
5092 wlan_hdd_scan_abort(adapter);
5093 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5094 if (adapter->device_mode == QDF_STA_MODE)
5095 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5096 adapter->dev);
5097 break;
5098 case QDF_P2P_GO_MODE:
5099 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5100 break;
5101 case QDF_SAP_MODE:
5102 wlan_hdd_undo_acs(adapter);
5103 break;
5104 default:
5105 break;
5106 }
5107}
5108
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005109QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005110{
Jeff Johnson9d295242017-08-29 14:39:48 -07005111 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005112 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005113 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005114 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115
Dustin Brown491d54b2018-03-14 12:39:11 -07005116 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005117
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305118 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5119
Dustin Brown920397d2017-12-13 16:27:50 -08005120 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005121 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5122 hdd_device_mode_to_string(adapter->device_mode),
5123 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305124
5125 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005126 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305127 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005128 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005129 adapter->session.station.hdd_reassoc_scenario = false;
5130 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305131
Arun Khandavallicc544b32017-01-30 19:52:16 +05305132 if (hdd_ctx->config->sap_internal_restart &&
5133 adapter->device_mode == QDF_SAP_MODE) {
5134 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305135 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305136 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005137 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005138 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005139 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005140 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5141 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305142 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305143 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005144 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005145 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005146
Paul Zhang84fa9382017-11-10 21:18:21 +08005147 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005148
5149 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005150 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005151 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005152 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305153 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005154 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5155 hdd_wmm_adapter_close(adapter);
5156 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5157 }
5158
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305159 if (adapter->device_mode == QDF_STA_MODE)
5160 hdd_clear_fils_connection_info(adapter);
5161
Wu Gao3545e642017-07-14 19:24:41 +08005162 if (adapter->device_mode == QDF_SAP_MODE) {
5163 /*
5164 * If adapter is SAP, set session ID to invalid
5165 * since SAP session will be cleanup during SSR.
5166 */
Wu Gao36717432016-11-21 15:09:48 +08005167 wlansap_set_invalid_session(
5168 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5169
Wu Gao3545e642017-07-14 19:24:41 +08005170 wlansap_cleanup_cac_timer(
5171 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5172 }
5173
Yue Ma42654682018-01-11 16:55:24 -08005174 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005175 if (adapter->device_mode == QDF_STA_MODE ||
5176 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005177 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005178 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005179 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005180
5181 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5182 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005183 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5184 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5185 if (adapter->sta_info[sta_id].in_use) {
5186 hdd_debug("[SSR] deregister STA with ID %d",
5187 sta_id);
5188 hdd_softap_deregister_sta(adapter,
5189 sta_id);
5190 adapter->sta_info[sta_id].in_use = 0;
5191 }
5192 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005193 }
5194
Alok Kumarb64650c2018-03-23 17:05:11 +05305195 hdd_nud_reset_tracking(adapter);
5196 hdd_nud_ignore_tracking(adapter, true);
5197 hdd_set_disconnect_status(adapter, false);
5198
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005199 hdd_softap_deinit_tx_rx(adapter);
5200
Yue Maf9782842017-05-08 12:49:49 -07005201 /* Destroy vdev which will be recreated during reinit. */
5202 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203 }
5204
Dustin Browne74003f2018-03-14 12:51:58 -07005205 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005206
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305207 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005208}
5209
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005210bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305211{
Dustin Brown920397d2017-12-13 16:27:50 -08005212 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305213 bool close_modules = true;
5214
Arun Khandavalliba479c42017-07-26 21:29:40 +05305215 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5216 hdd_info("FTM mode, don't close the module");
5217 return false;
5218 }
5219
Dustin Brown920397d2017-12-13 16:27:50 -08005220 hdd_for_each_adapter(hdd_ctx, adapter) {
5221 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5222 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005223 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305224 close_modules = false;
5225 break;
5226 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305227 }
5228
5229 return close_modules;
5230}
5231
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305232bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305233{
5234 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5235 return true;
5236 else
5237 return false;
5238}
5239
Anurag Chouhanc4092922016-09-08 15:56:11 +05305240#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005241 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305242struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5243 struct ieee80211_channel *channel,
5244 const u8 *bssid, const u8 *ssid,
5245 size_t ssid_len)
5246{
5247 return cfg80211_get_bss(wiphy, channel, bssid,
5248 ssid, ssid_len,
5249 WLAN_CAPABILITY_ESS,
5250 WLAN_CAPABILITY_ESS);
5251}
5252#else
5253struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5254 struct ieee80211_channel *channel,
5255 const u8 *bssid, const u8 *ssid,
5256 size_t ssid_len)
5257{
5258 return cfg80211_get_bss(wiphy, channel, bssid,
5259 ssid, ssid_len,
5260 IEEE80211_BSS_TYPE_ESS,
5261 IEEE80211_PRIVACY_ANY);
5262}
5263#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305264
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305265#if defined CFG80211_CONNECT_BSS || \
5266 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305267#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305268 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305269/**
5270 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5271 * @timeout_reason: reason for connect timeout
5272 *
5273 * This function is used to convert host timeout
5274 * reason enum to kernel specific enum.
5275 *
5276 * Return: nl timeout enum
5277 */
5278static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5279 tSirResultCodes timeout_reason)
5280{
5281 switch (timeout_reason) {
5282 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5283 return NL80211_TIMEOUT_SCAN;
5284 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5285 return NL80211_TIMEOUT_AUTH;
5286 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5287 return NL80211_TIMEOUT_ASSOC;
5288 default:
5289 return NL80211_TIMEOUT_UNSPECIFIED;
5290 }
5291}
5292
5293/**
5294 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5295 * @dev: network device
5296 * @bssid: bssid to which we want to associate
5297 * @timeout_reason: reason for connect timeout
5298 *
5299 * This API is used to send connection timeout reason to supplicant
5300 *
5301 * Return: void
5302 */
5303static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5304 const u8 *bssid,
5305 tSirResultCodes timeout_reason)
5306{
5307 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005308
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305309 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5310
5311 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5312 nl_timeout_reason);
5313}
5314
5315/**
5316 * __hdd_connect_bss() - API to send connection status to supplicant
5317 * @dev: network device
5318 * @bssid: bssid to which we want to associate
5319 * @req_ie: Request Information Element
5320 * @req_ie_len: len of the req IE
5321 * @resp_ie: Response IE
5322 * @resp_ie_len: len of ht response IE
5323 * @status: status
5324 * @gfp: Kernel Flag
5325 * @timeout_reason: reason for connect timeout
5326 *
5327 * Return: void
5328 */
5329static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5330 struct cfg80211_bss *bss, const u8 *req_ie,
5331 size_t req_ie_len, const u8 *resp_ie,
5332 size_t resp_ie_len, int status, gfp_t gfp,
5333 tSirResultCodes timeout_reason)
5334{
5335 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005336
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305337 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5338
5339 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5340 resp_ie, resp_ie_len, status, gfp,
5341 nl_timeout_reason);
5342}
5343#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305344#if defined CFG80211_CONNECT_TIMEOUT || \
5345 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305346static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5347 const u8 *bssid,
5348 tSirResultCodes timeout_reason)
5349{
5350 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5351}
5352#endif
5353
5354static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5355 struct cfg80211_bss *bss, const u8 *req_ie,
5356 size_t req_ie_len, const u8 *resp_ie,
5357 size_t resp_ie_len, int status, gfp_t gfp,
5358 tSirResultCodes timeout_reason)
5359{
5360 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5361 resp_ie, resp_ie_len, status, gfp);
5362}
5363#endif
5364
Abhishek Singha84d3952016-09-13 13:45:05 +05305365/**
5366 * hdd_connect_bss() - API to send connection status to supplicant
5367 * @dev: network device
5368 * @bssid: bssid to which we want to associate
5369 * @req_ie: Request Information Element
5370 * @req_ie_len: len of the req IE
5371 * @resp_ie: Response IE
5372 * @resp_ie_len: len of ht response IE
5373 * @status: status
5374 * @gfp: Kernel Flag
5375 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305376 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305377 *
5378 * The API is a wrapper to send connection status to supplicant
5379 *
5380 * Return: Void
5381 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305382#if defined CFG80211_CONNECT_TIMEOUT || \
5383 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305384static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5385 struct cfg80211_bss *bss, const u8 *req_ie,
5386 size_t req_ie_len, const u8 *resp_ie,
5387 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305388 bool connect_timeout,
5389 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305390{
5391 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305392 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305393 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305394 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5395 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305396}
5397#else
5398static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5399 struct cfg80211_bss *bss, const u8 *req_ie,
5400 size_t req_ie_len, const u8 *resp_ie,
5401 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305402 bool connect_timeout,
5403 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305404{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305405 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5406 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305407}
5408#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305409
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305410#if defined(WLAN_FEATURE_FILS_SK)
5411#if defined(CFG80211_CONNECT_DONE) || \
5412 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5413#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5414 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305415/**
5416 * hdd_populate_fils_params() - Populate FILS keys to connect response
5417 * @fils_params: connect response to supplicant
5418 * @fils_kek: FILS kek
5419 * @fils_kek_len: FILS kek length
5420 * @pmk: FILS PMK
5421 * @pmk_len: FILS PMK length
5422 * @pmkid: PMKID
5423 * @fils_seq_num: FILS Seq number
5424 *
5425 * Return: None
5426 */
5427static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5428 *fils_params, const uint8_t *fils_kek,
5429 size_t fils_kek_len, const uint8_t *pmk,
5430 size_t pmk_len, const uint8_t *pmkid,
5431 uint16_t fils_seq_num)
5432{
5433 /* Increament seq number to be used for next FILS */
5434 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5435 fils_params->update_erp_next_seq_num = true;
5436 fils_params->fils_kek = fils_kek;
5437 fils_params->fils_kek_len = fils_kek_len;
5438 fils_params->pmk = pmk;
5439 fils_params->pmk_len = pmk_len;
5440 fils_params->pmkid = pmkid;
5441}
5442#else
5443static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5444 *fils_params, const uint8_t
5445 *fils_kek, size_t fils_kek_len,
5446 const uint8_t *pmk, size_t pmk_len,
5447 const uint8_t *pmkid,
5448 uint16_t fils_seq_num)
5449{ }
5450#endif
5451
Jeff Johnson172237b2017-11-07 15:32:59 -08005452void hdd_update_hlp_info(struct net_device *dev,
5453 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305454{
5455 struct sk_buff *skb;
5456 uint16_t skb_len;
5457 struct llc_snap_hdr_t *llc_hdr;
5458 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305459 uint8_t *hlp_data;
5460 uint16_t hlp_data_len;
5461 struct fils_join_rsp_params *roam_fils_params
5462 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305463 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5464
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305465 if (!roam_fils_params) {
5466 hdd_err("FILS Roam Param NULL");
5467 return;
5468 }
5469
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005470 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305471 hdd_err("FILS HLP Data NULL, len %d",
5472 roam_fils_params->hlp_data_len);
5473 return;
5474 }
5475
5476 hlp_data = roam_fils_params->hlp_data;
5477 hlp_data_len = roam_fils_params->hlp_data_len;
5478
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305479 /* Calculate skb length */
5480 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5481 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5482 if (skb == NULL) {
5483 hdd_err("HLP packet nbuf alloc fails");
5484 return;
5485 }
5486
5487 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5488 QDF_MAC_ADDR_SIZE);
5489 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5490 QDF_MAC_ADDR_SIZE);
5491
5492 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5493 if (IS_SNAP(llc_hdr)) {
5494 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5495 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5496 }
5497
5498 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5499
5500 /*
5501 * This HLP packet is formed from HLP info encapsulated
5502 * in assoc response frame which is AEAD encrypted.
5503 * Hence, this checksum validation can be set unnecessary.
5504 * i.e. network layer need not worry about checksum.
5505 */
5506 skb->ip_summed = CHECKSUM_UNNECESSARY;
5507
5508 status = hdd_rx_packet_cbk(padapter, skb);
5509 if (QDF_IS_STATUS_ERROR(status)) {
5510 hdd_err("Sending HLP packet fails");
5511 return;
5512 }
5513 hdd_debug("send HLP packet to netif successfully");
5514}
5515
5516/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305517 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5518 * @dev: network device
5519 * @bssid: bssid to which we want to associate
5520 * @bss: cfg80211 bss info
5521 * @roam_info: information about connected bss
5522 * @req_ie: Request Information Element
5523 * @req_ie_len: len of the req IE
5524 * @resp_ie: Response IE
5525 * @resp_ie_len: len of ht response IE
5526 * @status: status
5527 * @gfp: allocation flags
5528 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5529 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305530 *
5531 * This API is used as wrapper to send FILS key/sequence number
5532 * params etc. to supplicant in case of FILS connection
5533 *
5534 * Return: None
5535 */
5536static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005537 struct cfg80211_bss *bss,
5538 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305539 const u8 *req_ie, size_t req_ie_len,
5540 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005541 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305542 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305543{
5544 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305545 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5546 struct fils_join_rsp_params *roam_fils_params =
5547 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005548
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305549 qdf_mem_zero(&fils_params, sizeof(fils_params));
5550
5551 if (!roam_fils_params) {
5552 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5553 } else {
5554 fils_params.status = status;
5555 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005556 fils_params.timeout_reason =
5557 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305558 fils_params.req_ie = req_ie;
5559 fils_params.req_ie_len = req_ie_len;
5560 fils_params.resp_ie = resp_ie;
5561 fils_params.resp_ie_len = resp_ie_len;
5562 fils_params.bss = bss;
5563 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5564 roam_fils_params->kek_len,
5565 roam_fils_params->fils_pmk,
5566 roam_fils_params->fils_pmk_len,
5567 roam_fils_params->fils_pmkid,
5568 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305569 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305570 }
5571 hdd_debug("FILS indicate connect status %d seq no %d",
5572 fils_params.status,
5573 fils_params.fils_erp_next_seq_num);
5574
5575 cfg80211_connect_done(dev, &fils_params, gfp);
5576
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305577 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305578 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305579
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305580 /* Clear all the FILS key info */
5581 if (roam_fils_params && roam_fils_params->fils_pmk)
5582 qdf_mem_free(roam_fils_params->fils_pmk);
5583 if (roam_fils_params)
5584 qdf_mem_free(roam_fils_params);
5585 roam_info->fils_join_rsp = NULL;
5586}
5587#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005588static inline void
5589hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005590 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005591 const u8 *req_ie, size_t req_ie_len,
5592 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5593 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305594 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305595{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305596#endif
5597#endif
5598
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305599#if defined(WLAN_FEATURE_FILS_SK) && \
5600 (defined(CFG80211_CONNECT_DONE) || \
5601 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305602/**
5603 * hdd_fils_update_connect_results() - API to send fils connection status to
5604 * supplicant.
5605 * @dev: network device
5606 * @bssid: bssid to which we want to associate
5607 * @bss: cfg80211 bss info
5608 * @roam_info: information about connected bss
5609 * @req_ie: Request Information Element
5610 * @req_ie_len: len of the req IE
5611 * @resp_ie: Response IE
5612 * @resp_ie_len: len of ht response IE
5613 * @status: status
5614 * @gfp: allocation flags
5615 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5616 * @timeout_reason: reason for connect timeout
5617 *
5618 * The API is a wrapper to send connection status to supplicant
5619 *
5620 * Return: 0 if success else failure
5621 */
5622static int hdd_fils_update_connect_results(struct net_device *dev,
5623 const u8 *bssid,
5624 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005625 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305626 size_t req_ie_len, const u8 *resp_ie,
5627 size_t resp_ie_len, u16 status, gfp_t gfp,
5628 bool connect_timeout,
5629 tSirResultCodes timeout_reason)
5630{
Dustin Brown491d54b2018-03-14 12:39:11 -07005631 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305632 if (!roam_info || !roam_info->is_fils_connection)
5633 return -EINVAL;
5634
5635 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5636 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305637 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305638 return 0;
5639}
5640#else
5641static inline int hdd_fils_update_connect_results(struct net_device *dev,
5642 const u8 *bssid,
5643 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005644 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305645 size_t req_ie_len, const u8 *resp_ie,
5646 size_t resp_ie_len, u16 status, gfp_t gfp,
5647 bool connect_timeout,
5648 tSirResultCodes timeout_reason)
5649{
5650 return -EINVAL;
5651}
5652#endif
5653
Anurag Chouhanc4092922016-09-08 15:56:11 +05305654/**
5655 * hdd_connect_result() - API to send connection status to supplicant
5656 * @dev: network device
5657 * @bssid: bssid to which we want to associate
5658 * @roam_info: information about connected bss
5659 * @req_ie: Request Information Element
5660 * @req_ie_len: len of the req IE
5661 * @resp_ie: Response IE
5662 * @resp_ie_len: len of ht response IE
5663 * @status: status
5664 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305665 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305666 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305667 *
5668 * The API is a wrapper to send connection status to supplicant
5669 * and allow runtime suspend
5670 *
5671 * Return: Void
5672 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305673void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005674 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305675 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305676 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305677 bool connect_timeout,
5678 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305679{
Jeff Johnson9d295242017-08-29 14:39:48 -07005680 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305681 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005682 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305683
5684 if (WLAN_STATUS_SUCCESS == status) {
5685 struct ieee80211_channel *chan;
5686 int freq;
5687 int chan_no = roam_info->pBssDesc->channelId;
5688
5689 if (chan_no <= 14)
5690 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005691 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305692 else
5693 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005694 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305695
5696 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5697 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5698 roam_info->u.pConnectedProfile->SSID.ssId,
5699 roam_info->u.pConnectedProfile->SSID.length);
5700 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305701
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305702 if (hdd_fils_update_connect_results(dev, bssid, bss,
5703 roam_info, req_ie, req_ie_len, resp_ie,
5704 resp_ie_len, status, gfp, connect_timeout,
5705 timeout_reason) != 0) {
5706 hdd_connect_bss(dev, bssid, bss, req_ie,
5707 req_ie_len, resp_ie, resp_ie_len,
5708 status, gfp, connect_timeout, timeout_reason);
5709 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305710
Jingxiang Geb49aa302018-01-17 20:54:15 +08005711 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005712 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305713}
5714#else
5715void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005716 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305717 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305718 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305719 bool connect_timeout,
5720 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305721{
Jeff Johnson9d295242017-08-29 14:39:48 -07005722 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005723 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305724
Anurag Chouhanc4092922016-09-08 15:56:11 +05305725 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5726 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005727
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#endif
5732
5733
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005734QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005735{
Jeff Johnson9d295242017-08-29 14:39:48 -07005736 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005737#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005738 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005739#endif
5740 eConnectionState connState;
5741
Dustin Brown491d54b2018-03-14 12:39:11 -07005742 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005743
Dustin Brown920397d2017-12-13 16:27:50 -08005744 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305745 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005746 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305747
Yue Ma42654682018-01-11 16:55:24 -08005748 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5749 hdd_device_mode_to_string(adapter->device_mode),
5750 adapter->device_mode);
5751
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005752 hdd_wmm_init(adapter);
5753
5754 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005755 case QDF_STA_MODE:
5756 case QDF_P2P_CLIENT_MODE:
5757 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005758
5759 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5760 ->conn_info.connState;
5761
Krunal Sonib51eec72017-11-20 21:53:01 -08005762 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005763 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005764 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005765
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005766 /* Indicate disconnect event to supplicant
5767 * if associated previously
5768 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005769 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005770 eConnectionState_IbssConnected == connState ||
5771 eConnectionState_NotConnected == connState ||
5772 eConnectionState_IbssDisconnected == connState ||
5773 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005774 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005775
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005776 memset(&wrqu, '\0', sizeof(wrqu));
5777 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5778 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5779 wireless_send_event(adapter->dev, SIOCGIWAP,
5780 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005781 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005782 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005783
5784 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305785 wlan_hdd_cfg80211_indicate_disconnect(
5786 adapter->dev, false,
5787 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005788 } else if (eConnectionState_Connecting == connState) {
5789 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005790 * Indicate connect failure to supplicant if we
5791 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005792 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305793 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305794 NULL, 0, NULL, 0,
5795 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005796 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005797 }
5798
5799 hdd_register_tx_flow_control(adapter,
5800 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005801 hdd_tx_resume_cb,
5802 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005803
Alok Kumarb64650c2018-03-23 17:05:11 +05305804 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805 break;
5806
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005807 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005808 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005809 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305810
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005811 break;
5812
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005813 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005814#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005815 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005816 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5817#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005818 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005819 /* event supplicant to restart */
5820 cfg80211_del_sta(adapter->dev,
5821 (const u8 *)&bcastMac.bytes[0],
5822 GFP_KERNEL);
5823#endif
5824 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305825 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005826 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305827 hdd_set_mon_rx_cb(adapter->dev);
5828 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5829 adapter->mon_bandwidth);
5830 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005831 default:
5832 break;
5833 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005834 /*
5835 * Action frame registered in one adapter which will
5836 * applicable to all interfaces
5837 */
5838 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005839 }
5840
Dustin Browne74003f2018-03-14 12:51:58 -07005841 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005842
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305843 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005844}
5845
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005846QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005847 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005848{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305849 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005850 qdf_list_node_t *node;
5851
5852 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005853
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005854 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005855 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005856 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005857
5858 if (QDF_IS_STATUS_ERROR(status))
5859 return status;
5860
5861 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5862
5863 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005864}
5865
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005866QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005867 struct hdd_adapter *current_adapter,
5868 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005869{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305870 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005871 qdf_list_node_t *node;
5872
5873 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005874
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005875 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005876 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005877 &current_adapter->node,
5878 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005879 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005880
5881 if (QDF_IS_STATUS_ERROR(status))
5882 return status;
5883
5884 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5885
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005886 return status;
5887}
5888
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005889QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005890 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005891{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305892 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005893
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005894 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005895 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898 return status;
5899}
5900
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005901QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005902 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005903{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305904 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005905 qdf_list_node_t *node;
5906
5907 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005908
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005909 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005910 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005911 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005912
5913 if (QDF_IS_STATUS_ERROR(status))
5914 return status;
5915
5916 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5917
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005918 return status;
5919}
5920
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005921QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005922 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005923{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305924 QDF_STATUS status;
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_insert_back(&hdd_ctx->hdd_adapters, &adapter->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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005930 return status;
5931}
5932
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005933QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005934 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005935{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305936 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005937
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005938 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005939 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005940 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005941
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005942 return status;
5943}
5944
Jeff Johnson9d295242017-08-29 14:39:48 -07005945struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005946 tSirMacAddr macAddr)
5947{
Jeff Johnson9d295242017-08-29 14:39:48 -07005948 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005949
Dustin Brown920397d2017-12-13 16:27:50 -08005950 hdd_for_each_adapter(hdd_ctx, adapter) {
5951 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5952 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005953 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954 }
5955
5956 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005957}
5958
Jeff Johnson9d295242017-08-29 14:39:48 -07005959struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005960 uint32_t vdev_id)
5961{
Jeff Johnson9d295242017-08-29 14:39:48 -07005962 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005963
Dustin Brown920397d2017-12-13 16:27:50 -08005964 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005965 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005966 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005967 }
5968
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005969 return NULL;
5970}
5971
Abhishek Singh7996eb72015-12-30 17:24:02 +05305972/**
5973 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5974 * the sessionid
5975 * @hdd_ctx: hdd context.
5976 * @sme_session_id: sme session is for the adapter to get.
5977 *
5978 * This function is used to get the adapter with provided session id
5979 *
5980 * Return: adapter pointer if found
5981 *
5982 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005983struct hdd_adapter *
5984hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5985 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305986{
Jeff Johnson9d295242017-08-29 14:39:48 -07005987 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305988
Dustin Brown920397d2017-12-13 16:27:50 -08005989 hdd_for_each_adapter(hdd_ctx, adapter) {
5990 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305991 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305992 }
Dustin Brown920397d2017-12-13 16:27:50 -08005993
Abhishek Singh7996eb72015-12-30 17:24:02 +05305994 return NULL;
5995}
5996
Jeff Johnson9d295242017-08-29 14:39:48 -07005997struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005998 const char *iface_name)
5999{
Jeff Johnson9d295242017-08-29 14:39:48 -07006000 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006001
Dustin Brown920397d2017-12-13 16:27:50 -08006002 hdd_for_each_adapter(hdd_ctx, adapter) {
6003 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006004 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006005 }
Dustin Brown920397d2017-12-13 16:27:50 -08006006
Naveen Rawat4edb6822017-04-12 10:09:17 -07006007 return NULL;
6008}
6009
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006010/**
6011 * hdd_get_adapter() - to get adapter matching the mode
6012 * @hdd_ctx: hdd context
6013 * @mode: adapter mode
6014 *
6015 * This routine will return the pointer to adapter matching
6016 * with the passed mode.
6017 *
6018 * Return: pointer to adapter or null
6019 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006020struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006021 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006022{
Jeff Johnson9d295242017-08-29 14:39:48 -07006023 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006024
Dustin Brown920397d2017-12-13 16:27:50 -08006025 hdd_for_each_adapter(hdd_ctx, adapter) {
6026 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006027 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006028 }
6029
6030 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006031}
6032
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306033enum tQDF_ADAPTER_MODE hdd_get_device_mode(uint32_t session_id)
6034{
6035 struct hdd_context *hdd_ctx;
6036 struct hdd_adapter *adapter;
6037
6038 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6039 if (!hdd_ctx) {
6040 hdd_err("Invalid HDD context");
6041 return QDF_MAX_NO_OF_MODE;
6042 }
6043
6044 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6045 if (!adapter) {
6046 hdd_err("Invalid HDD adapter");
6047 return QDF_MAX_NO_OF_MODE;
6048 }
6049
6050 return adapter->device_mode;
6051}
6052
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006053/**
6054 * hdd_get_operating_channel() - return operating channel of the device mode
6055 * @hdd_ctx: Pointer to the HDD context.
6056 * @mode: Device mode for which operating channel is required.
6057 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006058 * QDF_STA_MODE,
6059 * QDF_P2P_CLIENT_MODE,
6060 * QDF_SAP_MODE,
6061 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062 *
6063 * This API returns the operating channel of the requested device mode
6064 *
6065 * Return: channel number. "0" id the requested device is not found OR it is
6066 * not connected.
6067 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006068uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006069 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006070{
Jeff Johnson9d295242017-08-29 14:39:48 -07006071 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006072 uint8_t operatingChannel = 0;
6073
Dustin Brown920397d2017-12-13 16:27:50 -08006074 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075 if (mode == adapter->device_mode) {
6076 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006077 case QDF_STA_MODE:
6078 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006079 if (hdd_conn_is_connected
6080 (WLAN_HDD_GET_STATION_CTX_PTR
6081 (adapter))) {
6082 operatingChannel =
6083 (WLAN_HDD_GET_STATION_CTX_PTR
6084 (adapter))->conn_info.
6085 operationChannel;
6086 }
6087 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006088 case QDF_SAP_MODE:
6089 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006090 /* softap connection info */
6091 if (test_bit
6092 (SOFTAP_BSS_STARTED,
6093 &adapter->event_flags))
6094 operatingChannel =
6095 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006096 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006097 break;
6098 default:
6099 break;
6100 }
6101
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006102 /* Found the device of interest. break the loop */
6103 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006104 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006105 }
Dustin Brown920397d2017-12-13 16:27:50 -08006106
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006107 return operatingChannel;
6108}
6109
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006110static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006111 hdd_ctx)
6112{
Jeff Johnson9d295242017-08-29 14:39:48 -07006113 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006114
Dustin Brown491d54b2018-03-14 12:39:11 -07006115 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006116
Dustin Brown920397d2017-12-13 16:27:50 -08006117 hdd_for_each_adapter(hdd_ctx, adapter) {
6118 if (adapter->device_mode == QDF_STA_MODE ||
6119 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6120 adapter->device_mode == QDF_IBSS_MODE ||
6121 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6122 adapter->device_mode == QDF_SAP_MODE ||
6123 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006124 wlan_hdd_cfg80211_deregister_frames(adapter);
6125 hdd_unregister_wext(adapter->dev);
6126 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006127 }
6128
Dustin Browne74003f2018-03-14 12:51:58 -07006129 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006130
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306131 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006132}
6133
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006134QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006135{
Jeff Johnson9d295242017-08-29 14:39:48 -07006136 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006137
Dustin Brown491d54b2018-03-14 12:39:11 -07006138 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006139
Dustin Brown920397d2017-12-13 16:27:50 -08006140 hdd_for_each_adapter(hdd_ctx, adapter) {
6141 if (adapter->device_mode == QDF_STA_MODE ||
6142 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6143 adapter->device_mode == QDF_IBSS_MODE ||
6144 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6145 adapter->device_mode == QDF_SAP_MODE ||
6146 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006147 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006148 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306149 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006150 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006151 }
6152
Dustin Browne74003f2018-03-14 12:51:58 -07006153 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006154
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306155 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006156}
6157
Dustin Brownf27bce82016-11-03 12:52:27 -07006158/**
6159 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6160 * adapters
6161 * @hdd_ctx: The HDD context containing the adapters to operate on
6162 *
6163 * return: QDF_STATUS_SUCCESS
6164 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006165static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006166{
Jeff Johnson9d295242017-08-29 14:39:48 -07006167 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006168 int err;
6169
Dustin Brown491d54b2018-03-14 12:39:11 -07006170 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006171
Dustin Brown920397d2017-12-13 16:27:50 -08006172 hdd_for_each_adapter(hdd_ctx, adapter) {
6173 if (adapter->device_mode == QDF_STA_MODE ||
6174 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6175 adapter->device_mode == QDF_IBSS_MODE ||
6176 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6177 adapter->device_mode == QDF_SAP_MODE ||
6178 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006179 err = wlan_hdd_sched_scan_stop(adapter->dev);
6180 if (err)
6181 hdd_err("Unable to stop scheduled scan");
6182 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006183 }
6184
Dustin Browne74003f2018-03-14 12:51:58 -07006185 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006186
6187 return QDF_STATUS_SUCCESS;
6188}
6189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006190#ifdef WLAN_NS_OFFLOAD
6191/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006192 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006193 * @hdd_ctx: Pointer to hdd context
6194 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006195 * Unregister for IPv6 address change notifications.
6196 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006197 * Return: None
6198 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006199static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006200{
6201 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202}
6203
6204/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006205 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006206 * @hdd_ctx: Pointer to hdd context
6207 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006208 * Register for IPv6 address change notifications.
6209 *
6210 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006212static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006213{
6214 int ret;
6215
6216 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6217 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006218 if (ret) {
6219 hdd_err("Failed to register IPv6 notifier: %d", ret);
6220 goto out;
6221 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006222
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006223 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006224out:
6225 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006226}
6227#else
6228/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006229 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006230 * @hdd_ctx: Pointer to hdd context
6231 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006232 * Unregister for IPv6 address change notifications.
6233 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234 * Return: None
6235 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006236static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006237{
6238}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006239
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006241 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006242 * @hdd_ctx: Pointer to hdd context
6243 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006244 * Register for IPv6 address change notifications.
6245 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246 * Return: None
6247 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006248static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006249{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006250 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251}
6252#endif
6253
Alok Kumarb64650c2018-03-23 17:05:11 +05306254void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6255{
6256 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6257 adapter->disconnection_in_progress = status;
6258 qdf_mutex_release(&adapter->disconnection_status_lock);
6259 hdd_debug("setting disconnection status: %d", status);
6260}
6261
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006262/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006263 * hdd_register_notifiers - Register netdev notifiers.
6264 * @hdd_ctx: HDD context
6265 *
6266 * Register netdev notifiers like IPv4 and IPv6.
6267 *
6268 * Return: 0 on success and errno on failure
6269 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006270static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006271{
6272 int ret;
6273
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006274 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6275 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306276 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006277
6278 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6279 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6280 if (ret) {
6281 hdd_err("Failed to register IPv4 notifier: %d", ret);
6282 goto unregister_ip6_notifier;
6283 }
6284
Alok Kumarb64650c2018-03-23 17:05:11 +05306285 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6286 if (ret) {
6287 hdd_err("Failed to register netevent notifier: %d",
6288 ret);
6289 goto unregister_inetaddr_notifier;
6290 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006291 return 0;
6292
Alok Kumarb64650c2018-03-23 17:05:11 +05306293unregister_inetaddr_notifier:
6294 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006295unregister_ip6_notifier:
6296 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006297out:
6298 return ret;
6299
6300}
6301
6302/**
6303 * hdd_unregister_notifiers - Unregister netdev notifiers.
6304 * @hdd_ctx: HDD context
6305 *
6306 * Unregister netdev notifiers like IPv4 and IPv6.
6307 *
6308 * Return: None.
6309 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006310void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006311{
Alok Kumarb64650c2018-03-23 17:05:11 +05306312 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006313 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6314
6315 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006316}
6317
6318/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006319 * hdd_exit_netlink_services - Exit netlink services
6320 * @hdd_ctx: HDD context
6321 *
6322 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6323 * nl service.
6324 *
6325 * Return: None.
6326 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006327static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006328{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006329 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006330 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006331 ptt_sock_deactivate_svc();
6332
6333 nl_srv_exit();
6334}
6335
6336/**
6337 * hdd_init_netlink_services- Init netlink services
6338 * @hdd_ctx: HDD context
6339 *
6340 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6341 * nl service.
6342 *
6343 * Return: 0 on success and errno on failure.
6344 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006345static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006346{
6347 int ret;
6348
Ryan Hsuceddceb2016-04-28 10:20:14 -07006349 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006350 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006351 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006352 goto out;
6353 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006354 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006355
Naveen Rawat910726a2017-03-06 11:42:51 -08006356 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006357 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006358 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006359 goto err_nl_srv;
6360 }
6361
6362 ret = ptt_sock_activate_svc();
6363 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006364 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006365 goto err_nl_srv;
6366 }
6367
6368 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006369 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006370 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006371
6372 ret = cnss_diag_activate_service();
6373 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006374 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006375 goto err_close_cesium;
6376 }
6377
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006378 ret = spectral_scan_activate_service();
6379 if (ret) {
6380 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6381 goto err_close_cesium;
6382 }
6383
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006384 return 0;
6385
6386err_close_cesium:
6387 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006388 ptt_sock_deactivate_svc();
6389err_nl_srv:
6390 nl_srv_exit();
6391out:
6392 return ret;
6393}
6394
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006395/**
6396 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6397 * @hdd_ctx: HDD context.
6398 *
6399 * Destroy RX wakelock.
6400 *
6401 * Return: None.
6402 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006403static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006404{
6405 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6406}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006407
6408/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006409 * hdd_rx_wake_lock_create() - Create RX wakelock
6410 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006411 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006412 * Create RX wakelock.
6413 *
6414 * Return: None.
6415 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006416static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006417{
6418 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6419}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006420
6421/**
Houston Hoffman160db392016-10-10 17:37:51 -07006422 * hdd_context_deinit() - Deinitialize HDD context
6423 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006424 *
Houston Hoffman160db392016-10-10 17:37:51 -07006425 * Deinitialize HDD context along with all the feature specific contexts but
6426 * do not free hdd context itself. Caller of this API is supposed to free
6427 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006428 *
Houston Hoffman160db392016-10-10 17:37:51 -07006429 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006430 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006431static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006432{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306433 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6434
Houston Hoffman160db392016-10-10 17:37:51 -07006435 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006436
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006437 hdd_sap_context_destroy(hdd_ctx);
6438
6439 hdd_rx_wake_lock_destroy(hdd_ctx);
6440
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006441 hdd_scan_context_destroy(hdd_ctx);
6442
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006443 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006444
Houston Hoffman160db392016-10-10 17:37:51 -07006445 return 0;
6446}
6447
6448/**
6449 * hdd_context_destroy() - Destroy HDD context
6450 * @hdd_ctx: HDD context to be destroyed.
6451 *
6452 * Free config and HDD context as well as destroy all the resources.
6453 *
6454 * Return: None
6455 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006456static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006457{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006458 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306459
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306460 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6461
Houston Hoffman160db392016-10-10 17:37:51 -07006462 hdd_context_deinit(hdd_ctx);
6463
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306464 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006465 hdd_ctx->config = NULL;
6466
6467 wiphy_free(hdd_ctx->wiphy);
6468}
6469
6470/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306471 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6472 *
6473 * This function is used to destroy bug report lock
6474 *
6475 * Return: None
6476 */
6477static void wlan_destroy_bug_report_lock(void)
6478{
6479 p_cds_contextType p_cds_context;
6480
6481 p_cds_context = cds_get_global_context();
6482 if (!p_cds_context) {
6483 hdd_err("cds context is NULL");
6484 return;
6485 }
6486
6487 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6488}
6489
6490/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006491 * hdd_wlan_exit() - HDD WLAN exit function
6492 * @hdd_ctx: Pointer to the HDD Context
6493 *
6494 * This is the driver exit point (invoked during rmmod)
6495 *
6496 * Return: None
6497 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006498static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006499{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006500 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306501 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006502
Dustin Brown491d54b2018-03-14 12:39:11 -07006503 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006504
Dustin Brown6f427922017-09-19 12:19:00 -07006505 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306506
6507 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006508
Prashanth Bhattaab004382016-10-11 16:08:11 -07006509 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006510
6511#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306512 if (QDF_TIMER_STATE_RUNNING ==
6513 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6514 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006515 }
6516
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306517 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306518 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006519 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006520 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006521 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6522 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6523 hdd_ctx->last_acs_channel_list = NULL;
6524 hdd_ctx->num_of_channels = 0;
6525 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006526#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006527
Arun Khandavallifae92942016-08-01 13:31:08 +05306528 mutex_lock(&hdd_ctx->iface_change_lock);
6529 driver_status = hdd_ctx->driver_status;
6530 mutex_unlock(&hdd_ctx->iface_change_lock);
6531
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006532 /*
6533 * Powersave Offload Case
6534 * Disable Idle Power Save Mode
6535 */
6536 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006537 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306538 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006539
Arun Khandavallifae92942016-08-01 13:31:08 +05306540 if (driver_status != DRIVER_MODULES_CLOSED) {
6541 hdd_unregister_wext_all_adapters(hdd_ctx);
6542 /*
6543 * Cancel any outstanding scan requests. We are about to close
6544 * all of our adapters, but an adapter structure is what SME
6545 * passes back to our callback function. Hence if there
6546 * are any outstanding scan requests then there is a
6547 * race condition between when the adapter is closed and
6548 * when the callback is invoked. We try to resolve that
6549 * race condition here by canceling any outstanding scans
6550 * before we close the adapters.
6551 * Note that the scans may be cancelled in an asynchronous
6552 * manner, so ideally there needs to be some kind of
6553 * synchronization. Rather than introduce a new
6554 * synchronization here, we will utilize the fact that we are
6555 * about to Request Full Power, and since that is synchronized,
6556 * the expectation is that by the time Request Full Power has
6557 * completed, all scans will be cancelled
6558 */
6559 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006560 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006561 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006562 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006563 }
6564
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306565 unregister_netdevice_notifier(&hdd_netdev_notifier);
6566
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006567 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306568
Dustin Brown021cecd2017-12-11 13:56:43 -08006569 hdd_driver_memdump_deinit();
6570
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306571 qdf_nbuf_deinit_replenish_timer();
6572
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306573 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6574 hdd_info("Release wakelock for monitor mode!");
6575 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6576 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6577 }
6578
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306579 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6580 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6581 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6582
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006583 /*
6584 * Close CDS
6585 * This frees pMac(HAL) context. There should not be any call
6586 * that requires pMac access after this.
6587 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006588
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006589 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006590
Dustin Brownd005ad82018-01-19 10:32:13 -08006591 hdd_close_all_adapters(hdd_ctx, false);
6592
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306593 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306594 /*
6595 * If there is re_init failure wiphy would have already de-registered
6596 * check the wiphy status before un-registering again
6597 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306598 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306599 wiphy_unregister(wiphy);
6600 wlan_hdd_cfg80211_deinit(wiphy);
6601 hdd_lpass_notify_stop(hdd_ctx);
6602 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006603
Arun Khandavallifae92942016-08-01 13:31:08 +05306604 hdd_exit_netlink_services(hdd_ctx);
6605 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306606#ifdef FEATURE_WLAN_CH_AVOID
6607 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6608#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306609
Abhishek Singhe9068f12017-03-31 14:14:52 +05306610 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6611 if (driver_status)
6612 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006613
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006614 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006615}
6616
6617void __hdd_wlan_exit(void)
6618{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006619 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006620
Dustin Brown491d54b2018-03-14 12:39:11 -07006621 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006622
Anurag Chouhan6d760662016-02-20 16:05:43 +05306623 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006624 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006625 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07006626 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006627 return;
6628 }
6629
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006630 /* Do all the cleanup before deregistering the driver */
6631 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006632
Dustin Browne74003f2018-03-14 12:51:58 -07006633 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006634}
6635
6636#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006637/**
6638 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006639 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006640 *
6641 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6642 * Then new ACS request will do a fresh scan without reusing the cached
6643 * scan information.
6644 *
6645 * Return: void
6646 */
Tang Yingying523322d2017-01-17 23:28:43 +08006647static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006649 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006651 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006652 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006653 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6654 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6655 hdd_ctx->last_acs_channel_list = NULL;
6656 hdd_ctx->num_of_channels = 0;
6657 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006658
6659 if (!hdd_ctx->hHal)
6660 return;
6661 sme_scan_flush_result(hdd_ctx->hHal);
6662}
6663#endif
6664
6665#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006666int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6667 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006668{
6669 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306670 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006671 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006672
6673 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6674
6675 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306676 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306678
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679 if (!hdd_ctx->hHal)
6680 return -EINVAL;
6681
Jeff Johnsone7672e72017-10-21 15:10:04 -07006682 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006683 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306684 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006685 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006686 return -EINVAL;
6687 }
6688
6689 return 0;
6690}
6691#endif
6692
6693/**
6694 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6695 * @state: state
6696 *
6697 * This function notifies FW with modem power status
6698 *
6699 * Return: 0 if successful, error number otherwise
6700 */
6701int hdd_wlan_notify_modem_power_state(int state)
6702{
6703 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306704 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006705 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006706
Anurag Chouhan6d760662016-02-20 16:05:43 +05306707 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006708 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306709 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006710 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306711
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006712 if (!hdd_ctx->hHal)
6713 return -EINVAL;
6714
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306715 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6716 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006717 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006718 state);
6719 return -EINVAL;
6720 }
6721 return 0;
6722}
6723
6724/**
6725 *
6726 * hdd_post_cds_enable_config() - HDD post cds start config helper
6727 * @adapter - Pointer to the HDD
6728 *
6729 * Return: None
6730 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006731QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006732{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306733 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006734
6735 /*
6736 * Send ready indication to the HDD. This will kick off the MAC
6737 * into a 'running' state and should kick off an initial scan.
6738 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306739 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6740 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006741 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6742 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306743 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006744 }
6745
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306746 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006747}
6748
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05306749struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
6750{
6751 struct hdd_adapter *adapter;
6752
6753 hdd_for_each_adapter(hdd_ctx, adapter) {
6754 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
6755 return adapter;
6756 }
6757
6758 return NULL;
6759}
6760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006761/* wake lock APIs for HDD */
6762void hdd_prevent_suspend(uint32_t reason)
6763{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306764 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006765}
6766
6767void hdd_allow_suspend(uint32_t reason)
6768{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306769 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770}
6771
6772void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6773{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306774 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6775 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006776}
6777
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006779QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006780{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006781
Amar Singhal6f8592b2017-04-26 14:31:58 -07006782 return sme_init_chan_list(hdd_ctx->hHal,
6783 hdd_ctx->reg.alpha2,
6784 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006785}
6786
6787/**
6788 * hdd_is_5g_supported() - check if hardware supports 5GHz
6789 * @hdd_ctx: Pointer to the hdd context
6790 *
6791 * HDD function to know if hardware supports 5GHz
6792 *
6793 * Return: true if hardware supports 5GHz
6794 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006795bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006796{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006797 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006798 return true;
6799
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006800 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006801 return true;
6802 else
6803 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006804}
6805
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006806static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807{
6808 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006809 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006810
6811 wiphy = hdd_ctx->wiphy;
6812
6813 /*
6814 * The channel information in
6815 * wiphy needs to be initialized before wiphy registration
6816 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006817 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6818 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006819 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006820 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006821 }
6822
6823#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6824 wiphy->wowlan = &wowlan_support_reg_init;
6825#else
6826 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6827 WIPHY_WOWLAN_MAGIC_PKT |
6828 WIPHY_WOWLAN_DISCONNECT |
6829 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6830 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6831 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6832 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6833 WIPHY_WOWLAN_RFKILL_RELEASE;
6834
6835 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6836 WOW_MAX_FILTERS_PER_LIST);
6837 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6838 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6839#endif
6840
6841 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006842 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306843 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006844 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306845 return ret_val;
6846 }
6847
Amar Singhal2d812012018-02-03 15:06:47 +08006848 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006849
Amar Singhale4f28ee2015-10-21 14:36:56 -07006850 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006851}
6852
Mohit Khannaca4173b2017-09-12 21:52:19 -07006853#ifdef MSM_PLATFORM
6854/**
6855 * hdd_display_periodic_stats() - Function to display periodic stats
6856 * @hdd_ctx - handle to hdd context
6857 * @bool data_in_interval - true, if data detected in bw time interval
6858 *
6859 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6860 * Stats show up in wlan driver logs.
6861 *
6862 * Returns: None
6863 */
6864static inline
6865void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6866 bool data_in_interval)
6867{
6868 static u32 counter;
6869 static bool data_in_time_period;
6870 ol_txrx_pdev_handle pdev;
6871
6872 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6873 return;
6874
6875 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6876 if (!pdev) {
6877 hdd_err("pdev is NULL");
6878 return;
6879 }
6880
6881 counter++;
6882 if (data_in_interval)
6883 data_in_time_period = data_in_interval;
6884
6885 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6886 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6887 if (data_in_time_period) {
6888 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6889 CDP_TXRX_PATH_STATS,
6890 QDF_STATS_VERBOSITY_LEVEL_LOW);
6891 wlan_hdd_display_netif_queue_history
6892 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6893 qdf_dp_trace_dump_stats();
6894 }
6895 counter = 0;
6896 data_in_time_period = false;
6897 }
6898}
6899
Ravi Joshie2331e82015-07-01 18:18:54 -07006900/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006901 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006902 * @hdd_ctx - handle to hdd context
6903 * @tx_packets - transmit packet count
6904 * @rx_packets - receive packet count
6905 *
6906 * The function controls the bus bandwidth and dynamic control of
6907 * tcp delayed ack configuration
6908 *
6909 * Returns: None
6910 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006911
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006912static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006913 const uint64_t tx_packets,
6914 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006915{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006916 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006917 uint64_t temp_rx = 0;
6918 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006919 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006920 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006921 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006922 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006923 uint16_t index = 0;
6924 bool vote_level_change = false;
6925 bool rx_level_change = false;
6926 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006927
Mohit Khannaca4173b2017-09-12 21:52:19 -07006928 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006929 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006930 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006931 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006932 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006933 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006934 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006935 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006936
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006937 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006938 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6939 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006940 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006941 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006942 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306943 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306944 if (hdd_ctx->hbw_requested) {
6945 pld_remove_pm_qos(hdd_ctx->parent_dev);
6946 hdd_ctx->hbw_requested = false;
6947 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306948 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006949 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006950 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306951 if (!hdd_ctx->hbw_requested) {
6952 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6953 hdd_ctx->hbw_requested = true;
6954 }
6955
Nirav Shah3bbfa512016-05-12 16:43:49 +05306956 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006957 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006958 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006959 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006960 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006961
Mohit Khannaf8f96822017-05-17 17:11:59 -07006962 qdf_dp_trace_throttle_live_mode(
6963 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6964
Mohit Khannae71e2262015-11-10 09:37:24 -08006965 /* fine-tuning parameters for RX Flows */
6966 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6967
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006968 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006969
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306970 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6971 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6972 else
6973 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6974
Ravi Joshifed83572016-10-07 16:20:37 -07006975 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6976 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6977 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6978 next_rx_level = WLAN_SVC_TP_HIGH;
6979 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006980 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006981 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006982 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006983 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006984
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006985 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006986 struct wlan_rx_tp_data rx_tp_data = {0};
6987
Ravi Joshie2331e82015-07-01 18:18:54 -07006988 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989 next_rx_level, temp_rx);
6990 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006991 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006992 /* Send throughput indication only if it is enabled.
6993 * Disabling tcp_del_ack will revert the tcp stack behavior
6994 * to default delayed ack. Note that this will disable the
6995 * dynamic delayed ack mechanism across the system
6996 */
6997 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006998 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6999
Mohit Khanna6272fb682017-04-13 09:34:36 -07007000 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7001 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7002
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007003 rx_tp_data.level = next_rx_level;
7004 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7005 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7006 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007 }
7008
Mohit Khannae71e2262015-11-10 09:37:24 -08007009 /* fine-tuning parameters for TX Flows */
7010 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7011 hdd_ctx->prev_tx = tx_packets;
7012 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7013 next_tx_level = WLAN_SVC_TP_HIGH;
7014 else
7015 next_tx_level = WLAN_SVC_TP_LOW;
7016
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007017 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7018 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007019 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7020 next_tx_level, temp_tx);
7021 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007022 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307023 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7024 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007025 &next_tx_level,
7026 sizeof(next_tx_level));
7027 }
7028
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007029 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007030 if (vote_level_change || tx_level_change || rx_level_change) {
7031 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7032 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7033 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7034 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7035 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7036 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7037 hdd_ctx->hdd_txrx_hist_idx++;
7038 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7039 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007040
7041 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007042}
7043
7044#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307045static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007046{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007047 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307048 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07007049 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307050 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307051 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7052 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007053 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307054 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007055 bool connected = false;
7056 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7057
Prashanth Bhattaab004382016-10-11 16:08:11 -07007058 if (wlan_hdd_validate_context(hdd_ctx))
7059 return;
7060
Jeff Johnson214671b2017-10-30 19:45:23 -07007061 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007062 goto restart_timer;
7063
Dustin Brown920397d2017-12-13 16:27:50 -08007064 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307065 /*
7066 * Validate magic so we don't end up accessing
7067 * an invalid adapter.
7068 */
7069 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7070 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007071
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007072 if ((adapter->device_mode == QDF_STA_MODE ||
7073 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007074 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7075 != eConnectionState_Associated) {
7076
7077 continue;
7078 }
7079
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007080 if ((adapter->device_mode == QDF_SAP_MODE ||
7081 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007082 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007083
7084 continue;
7085 }
7086
7087 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7088 adapter->prev_tx_packets);
7089 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7090 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307091
7092 if (adapter->device_mode == QDF_SAP_MODE ||
7093 adapter->device_mode == QDF_P2P_GO_MODE ||
7094 adapter->device_mode == QDF_IBSS_MODE) {
7095
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007096 ret = cdp_get_intra_bss_fwd_pkts_count(
7097 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007098 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307099 &fwd_tx_packets, &fwd_rx_packets);
7100 if (ret == A_OK) {
7101 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7102 fwd_tx_packets,
7103 adapter->prev_fwd_tx_packets);
7104 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7105 fwd_tx_packets,
7106 adapter->prev_fwd_rx_packets);
7107 }
7108 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007109
7110 total_rx += adapter->stats.rx_packets;
7111 total_tx += adapter->stats.tx_packets;
7112
7113 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7114 adapter->prev_tx_packets = adapter->stats.tx_packets;
7115 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307116 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7117 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007118 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7119 connected = true;
7120 }
7121
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307122 /* add intra bss forwarded tx and rx packets */
7123 tx_packets += fwd_tx_packets_diff;
7124 rx_packets += fwd_rx_packets_diff;
7125
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05307126 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7127 &ipa_rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007128 tx_packets += (uint64_t)ipa_tx_packets;
7129 rx_packets += (uint64_t)ipa_rx_packets;
7130
7131 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007132 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007133 return;
7134 }
7135
Yuanyuan Liu13738502016-04-06 17:41:37 -07007136 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007137
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +05307138 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05307139 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007140
Jingxiang Gec64e1932017-08-22 14:38:59 +08007141restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007142 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007143 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007144 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307145 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007146 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007147 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007148}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007149
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307150/**
7151 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7152 * @arg: Argument of timer function
7153 *
7154 * Schedule a workqueue in this function where all the processing is done.
7155 *
7156 * Return: None.
7157 */
7158static void __hdd_bus_bw_cbk(void *arg)
7159{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007160 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307161
7162 if (wlan_hdd_validate_context(hdd_ctx))
7163 return;
7164
7165 schedule_work(&hdd_ctx->bus_bw_work);
7166}
7167
7168/**
7169 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7170 * @arg: Argument of timer function
7171 *
7172 * Return: None.
7173 */
7174static void hdd_bus_bw_cbk(void *arg)
7175{
7176 cds_ssr_protect(__func__);
7177 __hdd_bus_bw_cbk(arg);
7178 cds_ssr_unprotect(__func__);
7179}
7180
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007181int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007182{
7183 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307184 INIT_WORK(&hdd_ctx->bus_bw_work,
7185 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007186 hdd_ctx->bus_bw_timer_running = false;
7187 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307188 qdf_timer_init(NULL,
7189 &hdd_ctx->bus_bw_timer,
7190 hdd_bus_bw_cbk, (void *)hdd_ctx,
7191 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007192
7193 return 0;
7194}
7195
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007196void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007197{
Dustin Brownfce08d12017-01-17 16:29:38 -08007198 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007199 hdd_reset_tcp_delack(hdd_ctx);
7200
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007201 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307202 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307203 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007204 hdd_ctx->bus_bw_timer_running = false;
7205 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007206}
Lin Baic5c06882017-09-21 13:58:43 +08007207
7208void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7209{
7210 if (hdd_ctx)
7211 cancel_work_sync(&hdd_ctx->bus_bw_work);
7212}
jiadcdaf9bd2017-10-26 12:20:21 +08007213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007214#endif
7215
7216/**
Nirav Shahed34b212016-04-25 10:59:16 +05307217 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7218 * @hdd_ctx: hdd context
7219 *
7220 * Return: 0 for success or error code
7221 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007222static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307223{
7224 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7225 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7226 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007227 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307228 return -ENOMEM;
7229 }
7230 return 0;
7231}
7232
7233/**
7234 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7235 * @hdd_ctx: hdd context
7236 *
7237 * Return: none
7238 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007239void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307240{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307241 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7242 return;
7243
7244 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7245 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307246}
7247
Nirav Shahda008342016-05-17 18:50:40 +05307248static uint8_t *convert_level_to_string(uint32_t level)
7249{
7250 switch (level) {
7251 /* initialize the wlan sub system */
7252 case WLAN_SVC_TP_NONE:
7253 return "NONE";
7254 case WLAN_SVC_TP_LOW:
7255 return "LOW";
7256 case WLAN_SVC_TP_MEDIUM:
7257 return "MED";
7258 case WLAN_SVC_TP_HIGH:
7259 return "HIGH";
7260 default:
7261 return "INVAL";
7262 }
7263}
7264
Nirav Shahed34b212016-04-25 10:59:16 +05307265
7266/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007267 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7268 * @hdd_ctx: hdd context
7269 *
7270 * Return: none
7271 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007272void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007273{
7274 int i;
7275
7276#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007277 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307278 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007279 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007280 hdd_ctx->config->busBandwidthHighThreshold,
7281 hdd_ctx->config->busBandwidthMediumThreshold,
7282 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007283 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307284 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007285 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007286 hdd_ctx->config->tcpDelackThresholdHigh,
7287 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007288 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307289 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007290#endif
7291
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007292 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307293 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7294
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007295 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007296
7297 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007298 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007299 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007300 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7301 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7302 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7303 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7304 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007305 hdd_ctx->hdd_txrx_hist[i].
7306 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007307 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007308 hdd_ctx->hdd_txrx_hist[i].
7309 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007310 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007311 hdd_ctx->hdd_txrx_hist[i].
7312 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007313 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007314}
7315
7316/**
7317 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7318 * @hdd_ctx: hdd context
7319 *
7320 * Return: none
7321 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007322void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007323{
7324 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307325 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7326 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007327}
7328
Mohit Khannaca4173b2017-09-12 21:52:19 -07007329/* length of the netif queue log needed per adapter */
7330#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7331
7332/**
7333 *
7334 * hdd_display_netif_queue_history_compact() - display compact netifq history
7335 * @hdd_ctx: hdd context
7336 *
7337 * Return: none
7338 */
7339static void
7340hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7341{
7342 int adapter_num = 0;
7343 int i;
7344 int bytes_written;
7345 u32 tbytes;
7346 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007347 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007348 char *comb_log_str;
7349 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007350 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007351
jiadbdefb252018-01-03 14:27:06 +08007352 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7353 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7354 if (!comb_log_str) {
7355 hdd_err("failed to alloc comb_log_str");
7356 return;
7357 }
7358
Mohit Khannaca4173b2017-09-12 21:52:19 -07007359 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007360
Dustin Brown920397d2017-12-13 16:27:50 -08007361 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007362 curr_time = qdf_system_ticks();
7363 total = curr_time - adapter->start_time;
7364 delta = curr_time - adapter->last_time;
7365
7366 if (adapter->pause_map) {
7367 pause = adapter->total_pause_time + delta;
7368 unpause = adapter->total_unpause_time;
7369 } else {
7370 unpause = adapter->total_unpause_time + delta;
7371 pause = adapter->total_pause_time;
7372 }
7373
7374 tbytes = 0;
7375 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7376 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7377 if (adapter->queue_oper_stats[i].pause_count == 0)
7378 continue;
7379 tbytes +=
7380 snprintf(
7381 &temp_str[tbytes],
7382 (tbytes >= sizeof(temp_str) ?
7383 0 : sizeof(temp_str) - tbytes),
7384 "%d(%d,%d) ",
7385 i,
7386 adapter->queue_oper_stats[i].
7387 pause_count,
7388 adapter->queue_oper_stats[i].
7389 unpause_count);
7390 }
7391 if (tbytes >= sizeof(temp_str))
7392 hdd_warn("log truncated");
7393
7394 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007395 bytes_written >= comb_log_str_size ? 0 :
7396 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007397 "[%d %d] (%d) %u/%ums %s|",
7398 adapter->session_id, adapter->device_mode,
7399 adapter->pause_map,
7400 qdf_system_ticks_to_msecs(pause),
7401 qdf_system_ticks_to_msecs(total),
7402 temp_str);
7403
Mohit Khannaca4173b2017-09-12 21:52:19 -07007404 adapter_num++;
7405 }
7406
7407 /* using QDF_TRACE to avoid printing function name */
7408 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7409 "STATS |%s", comb_log_str);
7410
jiadbdefb252018-01-03 14:27:06 +08007411 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007412 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007413
7414 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007415}
7416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007417/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007418 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007419 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007420 *
7421 * Return: none
7422 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007423void
7424wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7425 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007426{
7427
Jeff Johnson9d295242017-08-29 14:39:48 -07007428 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007429 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307430 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007431
Mohit Khannaca4173b2017-09-12 21:52:19 -07007432 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7433 hdd_display_netif_queue_history_compact(hdd_ctx);
7434 return;
7435 }
7436
Dustin Brown920397d2017-12-13 16:27:50 -08007437 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007438 hdd_debug("Netif queue operation statistics:");
7439 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007440 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007441 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307442 curr_time = qdf_system_ticks();
7443 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307444 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307445 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307446 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307447 unpause = adapter->total_unpause_time;
7448 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307449 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307450 pause = adapter->total_pause_time;
7451 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007452 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307453 qdf_system_ticks_to_msecs(total),
7454 qdf_system_ticks_to_msecs(pause),
7455 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007456 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007457
Nirav Shahda008342016-05-17 18:50:40 +05307458 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7459 qdf_time_t pause_delta = 0;
7460
7461 if (adapter->pause_map & (1 << i))
7462 pause_delta = delta;
7463
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007464 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007465 hdd_debug("%s: %d: %d: %ums",
7466 hdd_reason_type_to_string(i),
7467 adapter->queue_oper_stats[i].pause_count,
7468 adapter->queue_oper_stats[i].unpause_count,
7469 qdf_system_ticks_to_msecs(
7470 adapter->queue_oper_stats[i].total_pause_time +
7471 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007472 }
7473
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007474 hdd_debug("Netif queue operation history:");
7475 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307476 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7477
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007478 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007479
7480 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007481 /* using hdd_log to avoid printing function name */
7482 if (adapter->queue_oper_history[i].time == 0)
7483 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007484 hdd_debug("%d: %u: %s: %s: %x",
7485 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007486 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007487 hdd_action_type_to_string(
7488 adapter->queue_oper_history[i].netif_action),
7489 hdd_reason_type_to_string(
7490 adapter->queue_oper_history[i].netif_reason),
7491 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007492 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007493 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007494}
7495
7496/**
7497 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7498 * @hdd_ctx: hdd context
7499 *
7500 * Return: none
7501 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007502void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007503{
Jeff Johnson9d295242017-08-29 14:39:48 -07007504 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007505
Dustin Brown920397d2017-12-13 16:27:50 -08007506 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307507 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007508 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307509 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007510 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307511 adapter->history_index = 0;
7512 adapter->start_time = adapter->last_time = qdf_system_ticks();
7513 adapter->total_pause_time = 0;
7514 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007515 }
7516}
7517
7518/**
7519 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7520 * @halHandle: Hal handle
7521 * @pContext: Pointer to the context
7522 * @sessionId: Session ID
7523 * @scanId: Scan ID
7524 * @status: Status
7525 *
7526 * This is the callback to be executed when 11d scan is completed to flush out
7527 * the scan results
7528 *
7529 * 11d scan is done during driver load and is a passive scan on all
7530 * channels supported by the device, 11d scans may find some APs on
7531 * frequencies which are forbidden to be used in the regulatory domain
7532 * the device is operating in. If these APs are notified to the supplicant
7533 * it may try to connect to these APs, thus flush out all the scan results
7534 * which are present in SME after 11d scan is done.
7535 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307536 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007537 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307538static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007539 uint8_t sessionId, uint32_t scanId,
7540 eCsrScanStatus status)
7541{
Dustin Brown491d54b2018-03-14 12:39:11 -07007542 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007543
7544 sme_scan_flush_result(halHandle);
7545
Dustin Browne74003f2018-03-14 12:51:58 -07007546 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007547
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307548 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007549}
7550
7551#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7552/**
7553 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7554 * @hdd_ctx: hdd global context
7555 *
7556 * Return: none
7557 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007558static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007559{
7560 uint8_t i;
7561
7562 mutex_init(&hdd_ctx->op_ctx.op_lock);
7563 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7564 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7565 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7566 }
7567}
7568#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007569static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007570{
7571}
7572#endif
7573
Yingying Tang95409972016-10-20 15:16:15 +08007574#ifdef WLAN_FEATURE_WOW_PULSE
7575/**
7576 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007577 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007578 * @enable: enable or disable this behaviour
7579 *
7580 * Return: int
7581 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007582static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007583{
7584 struct hdd_config *pcfg_ini = phddctx->config;
7585 struct wow_pulse_mode wow_pulse_set_info;
7586 QDF_STATUS status;
7587
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007588 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007589
7590 if (false == phddctx->config->wow_pulse_support)
7591 return 0;
7592
7593 /* prepare the request to send to SME */
7594 if (enable == true) {
7595 wow_pulse_set_info.wow_pulse_enable = true;
7596 wow_pulse_set_info.wow_pulse_pin =
7597 pcfg_ini->wow_pulse_pin;
7598 wow_pulse_set_info.wow_pulse_interval_low =
7599 pcfg_ini->wow_pulse_interval_low;
7600 wow_pulse_set_info.wow_pulse_interval_high =
7601 pcfg_ini->wow_pulse_interval_high;
7602 } else {
7603 wow_pulse_set_info.wow_pulse_enable = false;
7604 wow_pulse_set_info.wow_pulse_pin = 0;
7605 wow_pulse_set_info.wow_pulse_interval_low = 0;
7606 wow_pulse_set_info.wow_pulse_interval_high = 0;
7607 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007608 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007609 wow_pulse_set_info.wow_pulse_enable,
7610 wow_pulse_set_info.wow_pulse_pin,
7611 wow_pulse_set_info.wow_pulse_interval_low,
7612 wow_pulse_set_info.wow_pulse_interval_high);
7613
7614 status = sme_set_wow_pulse(&wow_pulse_set_info);
7615 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007616 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007617 return -EIO;
7618 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007619 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007620 return 0;
7621}
7622#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007623static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007624{
7625 return 0;
7626}
7627#endif
7628
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007629#ifdef WLAN_FEATURE_FASTPATH
7630/**
7631 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7632 * @hdd_cfg: hdd config
7633 * @context: lower layer context
7634 *
7635 * Return: none
7636 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307637void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007638 void *context)
7639{
7640 if (hdd_cfg->fastpath_enable)
7641 hif_enable_fastpath(context);
7642}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007643#endif
7644
Yuanyuan Liu13738502016-04-06 17:41:37 -07007645#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007646/**
7647 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007648 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007649 * @level: thermal level
7650 *
7651 * Change IPA data path to SW path when the thermal throttle level greater
7652 * than 0, and restore the original data path when throttle level is 0
7653 *
7654 * Return: none
7655 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007656static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007657{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007658 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007660 /* Change IPA to SW path when throttle level greater than 0 */
7661 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307662 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007663 else
7664 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307665 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007666}
7667
7668/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307669 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7670 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307671 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007672 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307673 * Get a safe channel to restart SAP. PCL already takes into account the
7674 * unsafe channels. So, the PCL is validated with the ACS range to provide
7675 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007676 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307677 * Return: Channel number to restart SAP in case of success. In case of any
7678 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007679 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307680static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007681 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007682{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307683 struct sir_pcl_list pcl;
7684 QDF_STATUS status;
7685 uint32_t i, j;
7686 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007687 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307688 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007689 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007690
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307691 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7692 if (!hdd_ctx) {
7693 hdd_err("invalid HDD context");
7694 return INVALID_CHANNEL_ID;
7695 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007696
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307697 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7698 if (!hal_handle) {
7699 hdd_err("invalid HAL handle");
7700 return INVALID_CHANNEL_ID;
7701 }
7702
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007703 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7704 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007705 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7706 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307707 if (QDF_IS_STATUS_ERROR(status)) {
7708 hdd_err("Get PCL failed");
7709 return INVALID_CHANNEL_ID;
7710 }
7711
Frank Liudc2cefb2017-06-21 15:38:18 +08007712 /*
7713 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7714 * channel is unsafe channel, the pcl may be empty, instead of return,
7715 * try to choose a safe channel from acs range.
7716 */
7717 if (!pcl.pcl_len)
7718 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307719
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007720 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007721 adapter->session.ap.sap_config.acs_cfg.start_ch,
7722 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307723
7724 /* PCL already takes unsafe channel into account */
7725 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007726 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307727 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007728 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307729 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007730 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007731 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307732 return pcl.pcl_list[i];
7733 }
7734 }
7735
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007736 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307737
7738 /* Try for safe channel from all valid channel */
7739 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007740 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7741 &pcl.pcl_len);
7742 if (ret) {
7743 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307744 return INVALID_CHANNEL_ID;
7745 }
7746
7747 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007748 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307749 found = false;
7750 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007751 if (pcl.pcl_list[i] ==
7752 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007753 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307754 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007755 break;
7756 }
7757 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307758
7759 if (found)
7760 continue;
7761
7762 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007763 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307764 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007765 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007766 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307767 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007768 }
7769 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307770
7771 return INVALID_CHANNEL_ID;
7772}
Nirav Shaheb017be2018-02-15 11:20:58 +05307773#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307774
7775/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007776 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307777 * @adapter: AP adapter
7778 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007779 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307780 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007781 * Moves the SAP interface by invoking the function which
7782 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307783 *
7784 * Return: None
7785 */
Min Liu2fef5792018-01-19 17:59:42 +08007786void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7787 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307788{
Jeff Johnson87251032017-08-29 13:31:11 -07007789 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307790 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007791 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307792
7793 if (!adapter) {
7794 hdd_err("invalid adapter");
7795 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007796 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307797
7798 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7799
7800 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7801 if (!hal_handle) {
7802 hdd_err("invalid HAL handle");
7803 return;
7804 }
7805
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007806 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7807
Jeff Johnson91df29d2017-10-27 19:29:50 -07007808 hdd_ap_ctx->sap_config.channel = channel;
7809 hdd_ap_ctx->sap_config.ch_params.ch_width =
7810 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307811
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007812 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007813 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307814
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007815 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007816 hdd_ap_ctx->sap_config.channel,
7817 hdd_ap_ctx->sap_config.sec_ch,
7818 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307819
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007820 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007821 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007822 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007823}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307824
Jeff Johnson9d295242017-08-29 14:39:48 -07007825int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307826{
7827 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307828 int status;
7829 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307830
7831 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7832
7833 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007834 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307835 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007836 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307837 }
7838 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007839 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307840 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307841 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007842 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307843 WLAN_VENDOR_ACS_WAIT_TIME);
7844 if (qdf_status != QDF_STATUS_SUCCESS) {
7845 hdd_err("failed to start external acs timer");
7846 return -ENOSPC;
7847 }
7848 /* Update config to application */
7849 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07007850 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307851
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307852 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307853}
7854
Nirav Shaheb017be2018-02-15 11:20:58 +05307855#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307856/**
7857 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7858 * @hdd_ctx: hdd context pointer
7859 *
7860 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7861 * and if ACS is enabled, driver will ask userspace to restart the
7862 * sap. User space on LTE coex indication restart driver.
7863 *
7864 * Return - none
7865 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007866void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307867{
Dustin Brown920397d2017-12-13 16:27:50 -08007868 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307869 uint32_t i;
7870 bool found = false;
7871 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007872
Dustin Brown920397d2017-12-13 16:27:50 -08007873 hdd_for_each_adapter(hdd_ctxt, adapter) {
7874 if (!(adapter->device_mode == QDF_SAP_MODE &&
7875 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007876 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007877 adapter->device_mode,
7878 adapter->session.ap.sap_config.
7879 acs_cfg.acs_mode);
7880 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307881 }
7882
7883 found = false;
7884 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007885 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307886 hdd_ctxt->unsafe_channel_list[i]) {
7887 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007888 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007889 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307890 break;
7891 }
7892 }
7893
7894 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007895 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007896 adapter->session.ap.operating_channel);
7897 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307898 }
7899
Kapil Gupta8878ad92017-02-13 11:56:04 +05307900 if (hdd_ctxt->config->vendor_acs_support &&
7901 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007902 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307903 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007904 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307905 } else
7906 restart_chan =
7907 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007908 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307909 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007910 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307911 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007912 /*
7913 * SAP restart due to unsafe channel. While
7914 * restarting the SAP, make sure to clear
7915 * acs_channel, channel to reset to
7916 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307917 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007918 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307919 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007920 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307921 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007922 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307923 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7924 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007925 hdd_debug("driver to start sap: %d",
7926 hdd_ctxt->config->sap_internal_restart);
7927 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08007928 hdd_switch_sap_channel(adapter, restart_chan,
7929 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04007930 else
7931 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307932 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307933 }
7934}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007936/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007937 * hdd_init_channel_avoidance() - Initialize channel avoidance
7938 * @hdd_ctx: HDD global context
7939 *
7940 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007941 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007942 * down to the lower layers. Then subscribe to subsequent channel
7943 * avoidance events.
7944 *
7945 * Return: None
7946 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007947static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007948{
7949 uint16_t unsafe_channel_count;
7950 int index;
7951
Yuanyuan Liu13738502016-04-06 17:41:37 -07007952 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7953 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007954 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007955 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007956
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007957 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007958 hdd_ctx->unsafe_channel_count);
7959
Anurag Chouhan6d760662016-02-20 16:05:43 +05307960 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007961 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007962
7963 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007964 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007965 hdd_ctx->unsafe_channel_list[index]);
7966
7967 }
7968
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007969}
Dustin Brown676a2322017-08-15 13:16:13 -07007970
Jeff Johnson9d295242017-08-29 14:39:48 -07007971static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007972 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007973{
7974 uint8_t restart_chan;
7975
7976 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7977 if (!restart_chan) {
7978 hdd_alert("fail to restart SAP");
7979 return;
7980 }
7981
7982 /* SAP restart due to unsafe channel. While restarting
7983 * the SAP, make sure to clear acs_channel, channel to
7984 * reset to 0. Otherwise these settings will override
7985 * the ACS while restart.
7986 */
7987 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007988 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007989
7990 hdd_debug("sending coex indication");
7991
7992 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7993 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08007994 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07007995}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007996
7997int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7998 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7999{
8000 uint32_t size;
8001 uint16_t *unsafe_list;
8002 uint16_t chan_count;
8003
8004 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8005 return -EINVAL;
8006
8007 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8008 NUM_CHANNELS);
8009 if (chan_count) {
8010 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8011 unsafe_list = qdf_mem_malloc(size);
8012 if (!unsafe_list) {
8013 hdd_err("No memory for unsafe chan list size%d",
8014 size);
8015 return -ENOMEM;
8016 }
8017 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8018 } else {
8019 unsafe_list = NULL;
8020 }
8021
8022 *local_unsafe_list = unsafe_list;
8023 *local_unsafe_list_count = chan_count;
8024
8025 return 0;
8026}
8027
8028bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8029 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8030{
8031 int i, j;
8032
8033 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8034 return true;
8035 if (local_unsafe_list_count == 0)
8036 return false;
8037 for (i = 0; i < local_unsafe_list_count; i++) {
8038 for (j = 0; j < local_unsafe_list_count; j++)
8039 if (local_unsafe_list[i] ==
8040 hdd_ctx->unsafe_channel_list[j])
8041 break;
8042 if (j >= local_unsafe_list_count)
8043 break;
8044 }
8045 if (i >= local_unsafe_list_count) {
8046 hdd_info("unsafe chan list same");
8047 return false;
8048 }
8049
8050 return true;
8051}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008052#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008053static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008054{
8055}
Dustin Brown676a2322017-08-15 13:16:13 -07008056
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008057static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008058{
8059}
Dustin Brown676a2322017-08-15 13:16:13 -07008060
Jeff Johnson9d295242017-08-29 14:39:48 -07008061static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008062 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008063{
8064 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8065}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008066#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008067
8068/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008069 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8070 * user space
8071 * @frame_ind: Management frame data to be informed.
8072 *
8073 * This function is used to indicate management frame to
8074 * user space
8075 *
8076 * Return: None
8077 *
8078 */
8079void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8080{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008081 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008082 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008083 int i;
8084
Rajeev Kumard004abc2016-02-17 12:09:56 -08008085 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008086 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008087
8088 if (0 != wlan_hdd_validate_context(hdd_ctx))
8089 return;
8090
8091 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8092 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8093 adapter =
8094 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8095 if (adapter)
8096 break;
8097 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008098 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8099 hdd_for_each_adapter(hdd_ctx, adapter) {
8100 if ((NULL != adapter) &&
8101 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8102 __hdd_indicate_mgmt_frame(adapter,
8103 frame_ind->frame_len,
8104 frame_ind->frameBuf,
8105 frame_ind->frameType,
8106 frame_ind->rxChan,
8107 frame_ind->rxRssi);
8108 }
8109 }
8110 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008111 } else {
8112 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8113 frame_ind->sessionId);
8114 }
8115
8116 if ((NULL != adapter) &&
8117 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8118 __hdd_indicate_mgmt_frame(adapter,
8119 frame_ind->frame_len,
8120 frame_ind->frameBuf,
8121 frame_ind->frameType,
8122 frame_ind->rxChan,
8123 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008124}
8125
Kapil Gupta8878ad92017-02-13 11:56:04 +05308126void hdd_acs_response_timeout_handler(void *context)
8127{
8128 struct hdd_external_acs_timer_context *timer_context =
8129 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008130 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008131 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308132 uint8_t reason;
8133
Dustin Brown491d54b2018-03-14 12:39:11 -07008134 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308135 if (!timer_context) {
8136 hdd_err("invlaid timer context");
8137 return;
8138 }
8139 adapter = timer_context->adapter;
8140 reason = timer_context->reason;
8141
8142
8143 if ((!adapter) ||
8144 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8145 hdd_err("invalid adapter or adapter has invalid magic");
8146 return;
8147 }
8148 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8149 if (wlan_hdd_validate_context(hdd_ctx))
8150 return;
8151
8152 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8153 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8154 else
8155 return;
8156
8157 hdd_err("ACS timeout happened for %s reason %d",
8158 adapter->dev->name, reason);
8159 switch (reason) {
8160 /* SAP init case */
8161 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8162 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8163 false);
8164 wlan_hdd_cfg80211_start_acs(adapter);
8165 break;
8166 /* DFS detected on current channel */
8167 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8168 wlan_sap_update_next_channel(
8169 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8170 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008171 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308172 break;
8173 /* LTE coex event on current channel */
8174 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8175 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8176 break;
8177 default:
8178 hdd_info("invalid reason for timer invoke");
8179
8180 }
8181}
8182
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008183/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008184 * hdd_override_ini_config - Override INI config
8185 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008186 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008187 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008188 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008189 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008190 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008191static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008192{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008193
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008194 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8195 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008196 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008197 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008198 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008199 if (0 == enable_11d || 1 == enable_11d) {
8200 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008201 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008202 }
Leo Chang11545d62016-10-17 14:53:50 -07008203
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308204 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008205 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008206 hdd_debug("IpaConfig override to %d",
8207 hdd_ctx->config->IpaConfig);
8208 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308209
8210 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8211 !hdd_ctx->config->enable_bcast_probe_rsp) {
8212 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8213 hdd_ctx->config->rssi_assoc_reject_enabled,
8214 hdd_ctx->config->enable_bcast_probe_rsp);
8215 hdd_ctx->config->oce_sta_enabled = 0;
8216 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008217}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008218
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008219/**
8220 * hdd_set_trace_level_for_each - Set trace level for each INI config
8221 * @hdd_ctx - HDD context
8222 *
8223 * Set trace level for each module based on INI config.
8224 *
8225 * Return: None
8226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008227static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008228{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308229 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8230 hdd_ctx->config->qdf_trace_enable_wdi);
8231 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8232 hdd_ctx->config->qdf_trace_enable_hdd);
8233 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8234 hdd_ctx->config->qdf_trace_enable_sme);
8235 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8236 hdd_ctx->config->qdf_trace_enable_pe);
8237 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8238 hdd_ctx->config->qdf_trace_enable_wma);
8239 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8240 hdd_ctx->config->qdf_trace_enable_sys);
8241 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8242 hdd_ctx->config->qdf_trace_enable_qdf);
8243 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8244 hdd_ctx->config->qdf_trace_enable_sap);
8245 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8246 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8247 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8248 hdd_ctx->config->qdf_trace_enable_bmi);
8249 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8250 hdd_ctx->config->qdf_trace_enable_cfg);
8251 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8252 hdd_ctx->config->qdf_trace_enable_epping);
8253 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8254 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8255 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008256 hdd_ctx->config->qdf_trace_enable_txrx);
8257 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8258 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308259 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8260 hdd_ctx->config->qdf_trace_enable_htc);
8261 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8262 hdd_ctx->config->qdf_trace_enable_hif);
8263 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8264 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8265 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8266 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008267 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8268 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008269 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8270 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008271 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8272 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008273 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8274 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008275
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008276 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008277}
8278
8279/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008280 * hdd_context_init() - Initialize HDD context
8281 * @hdd_ctx: HDD context.
8282 *
8283 * Initialize HDD context along with all the feature specific contexts.
8284 *
8285 * return: 0 on success and errno on failure.
8286 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008287static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008288{
8289 int ret;
8290
8291 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8292 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8293
8294 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308295 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008296
8297 init_completion(&hdd_ctx->mc_sus_event_var);
8298 init_completion(&hdd_ctx->ready_to_suspend);
8299
8300 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308301 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008302 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308303
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008304 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008305
8306 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8307
8308 ret = hdd_scan_context_init(hdd_ctx);
8309 if (ret)
8310 goto list_destroy;
8311
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008312 hdd_rx_wake_lock_create(hdd_ctx);
8313
8314 ret = hdd_sap_context_init(hdd_ctx);
8315 if (ret)
8316 goto scan_destroy;
8317
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008318 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8319
8320 hdd_init_offloaded_packets_ctx(hdd_ctx);
8321
8322 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8323 hdd_ctx->config);
8324 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008325 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008326
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308327 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8328 "monitor_mode_wakelock");
8329
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008330 return 0;
8331
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008332sap_destroy:
8333 hdd_sap_context_destroy(hdd_ctx);
8334
8335scan_destroy:
8336 hdd_scan_context_destroy(hdd_ctx);
8337 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008338list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008339 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008340
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008341 return ret;
8342}
8343
8344/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308345 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8346 * @hdd_ctx: pointer to hdd context
8347 *
8348 * Return: status of initialization
8349 * 0 - success
8350 * negative value - failure
8351 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008352static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308353{
8354 int ret;
8355
8356 if (!hdd_ctx->config->probe_req_ie_whitelist)
8357 return 0;
8358
8359 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8360 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8361 hdd_ctx->config->probe_req_ie_whitelist = false;
8362 return -EINVAL;
8363 }
8364
8365 /* parse ini string probe req oui */
8366 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8367 if (ret) {
8368 hdd_err("parsing error: disable ie whitelisting");
8369 hdd_ctx->config->probe_req_ie_whitelist = false;
8370 }
8371
8372 return ret;
8373}
8374
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308375/**
8376 * hdd_iface_change_callback() - Function invoked when stop modules expires
8377 * @priv: pointer to hdd context
8378 *
8379 * This function is invoked when the timer waiting for the interface change
8380 * expires, it shall cut-down the power to wlan and stop all the modules.
8381 *
8382 * Return: void
8383 */
8384static void hdd_iface_change_callback(void *priv)
8385{
8386 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8387 int ret;
8388 int status = wlan_hdd_validate_context(hdd_ctx);
8389
8390 if (status)
8391 return;
8392
Dustin Brown491d54b2018-03-14 12:39:11 -07008393 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308394 hdd_debug("Interface change timer expired close the modules!");
8395 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8396 if (ret)
8397 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008398 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308399}
8400
Nirav Shaheb017be2018-02-15 11:20:58 +05308401#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8402static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8403{
8404 wlan_logging_set_log_to_console(hdd_ctx->config->
8405 wlan_logging_to_console);
8406 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8407}
8408#else
8409static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8410{ }
8411#endif
8412
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308413/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008414 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308415 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008416 *
8417 * Allocate and initialize HDD context. HDD context is allocated as part of
8418 * wiphy allocation and then context is initialized.
8419 *
8420 * Return: HDD context on success and ERR_PTR on failure
8421 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008422static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008423{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308424 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008425 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008426 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008427
Dustin Brown491d54b2018-03-14 12:39:11 -07008428 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008429
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008430 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008431 if (hdd_ctx == NULL) {
8432 ret = -ENOMEM;
8433 goto err_out;
8434 }
8435
Dustin Brown6f427922017-09-19 12:19:00 -07008436 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8437 hdd_iface_change_callback,
8438 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308439
8440 mutex_init(&hdd_ctx->iface_change_lock);
8441
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008442 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308443 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008444
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308445 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008446 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008447 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008448 ret = -ENOMEM;
8449 goto err_free_hdd_context;
8450 }
8451
8452 /* Read and parse the qcom_cfg.ini file */
8453 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308454 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308455 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008456 WLAN_INI_FILE);
8457 ret = -EINVAL;
8458 goto err_free_config;
8459 }
8460
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308461 ie_whitelist_attrs_init(hdd_ctx);
8462
Dustin Brown7f939932017-05-18 15:02:17 -07008463 hdd_debug("setting timer multiplier: %u",
8464 hdd_ctx->config->timer_multiplier);
8465 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8466
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008467
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308468 if (hdd_ctx->config->fhostNSOffload)
8469 hdd_ctx->ns_offload_enable = true;
8470
Abhishek Singh5ea86532016-04-27 14:10:53 +05308471 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8472
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008473 hdd_override_ini_config(hdd_ctx);
8474
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008475 ret = hdd_context_init(hdd_ctx);
8476
8477 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008478 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008479
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008480 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308481 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008482
Anurag Chouhan6d760662016-02-20 16:05:43 +05308483 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008484 goto skip_multicast_logging;
8485
8486 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8487
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008488 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8489 if (ret)
8490 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308491
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008492 ret = hdd_init_netlink_services(hdd_ctx);
8493 if (ret)
8494 goto err_deinit_txrx_histogram;
8495
Nirav Shaheb017be2018-02-15 11:20:58 +05308496 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308497
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008498skip_multicast_logging:
8499 hdd_set_trace_level_for_each(hdd_ctx);
8500
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008501 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8502
Dustin Browne74003f2018-03-14 12:51:58 -07008503 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008504
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008505 return hdd_ctx;
8506
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008507err_deinit_txrx_histogram:
8508 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8509
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008510err_deinit_hdd_context:
8511 hdd_context_deinit(hdd_ctx);
8512
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008513err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308514 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008515
8516err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308517 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008518 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008519
8520err_out:
8521 return ERR_PTR(ret);
8522}
8523
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008524#ifdef WLAN_OPEN_P2P_INTERFACE
8525/**
8526 * hdd_open_p2p_interface - Open P2P interface
8527 * @hdd_ctx: HDD context
8528 * @rtnl_held: True if RTNL lock held
8529 *
8530 * Open P2P interface during probe. This function called to open the P2P
8531 * interface at probe along with STA interface.
8532 *
8533 * Return: 0 on success and errno on failure
8534 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008535static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008536{
Jeff Johnson9d295242017-08-29 14:39:48 -07008537 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008538 uint8_t *p2p_dev_addr;
8539
8540 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8541 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008542 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008543 hdd_ctx->config->intfMacAddr[0].bytes,
8544 sizeof(tSirMacAddr));
8545
8546 /*
8547 * Generate the P2P Device Address. This consists of
8548 * the device's primary MAC address with the locally
8549 * administered bit set.
8550 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008551 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008552 } else {
8553 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8554 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008555 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008556 return -ENOSPC;
8557 }
8558
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008559 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8560 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008561 }
8562
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008563 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008564 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008565 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008566
8567 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008568 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008569 return -ENOSPC;
8570 }
8571
8572 return 0;
8573}
8574#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008575static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008576 bool rtnl_held)
8577{
8578 return 0;
8579}
8580#endif
8581
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008582static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008583{
Jeff Johnson9d295242017-08-29 14:39:48 -07008584 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008585 int ret = 0;
8586
8587 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8588 wlan_hdd_get_intf_addr(hdd_ctx),
8589 NET_NAME_UNKNOWN, rtnl_held);
8590 if (adapter == NULL) {
8591 hdd_err("Failed to open 802.11p interface");
8592 ret = -ENOSPC;
8593 }
8594
8595 return ret;
8596}
8597
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008598/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308599 * hdd_start_station_adapter()- Start the Station Adapter
8600 * @adapter: HDD adapter
8601 *
8602 * This function initializes the adapter for the station mode.
8603 *
8604 * Return: 0 on success or errno on failure.
8605 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008606int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308607{
8608 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008609 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308610
Dustin Brownfdf17c12018-03-14 12:55:34 -07008611 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008612 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8613 hdd_err("session is already opened, %d",
8614 adapter->session_id);
8615 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8616 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308617
Krunal Sonib51eec72017-11-20 21:53:01 -08008618 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8619 if (ret) {
8620 hdd_err("failed to create vdev: %d", ret);
8621 return ret;
8622 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308623 status = hdd_init_station_mode(adapter);
8624
8625 if (QDF_STATUS_SUCCESS != status) {
8626 hdd_err("Error Initializing station mode: %d", status);
8627 return qdf_status_to_os_return(status);
8628 }
8629
Arun Khandavallifae92942016-08-01 13:31:08 +05308630 hdd_register_tx_flow_control(adapter,
8631 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008632 hdd_tx_resume_cb,
8633 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308634
Dustin Browne74003f2018-03-14 12:51:58 -07008635 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308636 return 0;
8637}
8638
8639/**
8640 * hdd_start_ap_adapter()- Start AP Adapter
8641 * @adapter: HDD adapter
8642 *
8643 * This function initializes the adapter for the AP mode.
8644 *
8645 * Return: 0 on success errno on failure.
8646 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008647int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308648{
8649 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008650 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008651 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008652 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308653
Dustin Brown491d54b2018-03-14 12:39:11 -07008654 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308655
Krunal Sonib51eec72017-11-20 21:53:01 -08008656 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8657 hdd_err("session is already opened, %d",
8658 adapter->session_id);
8659 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8660 }
8661 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008662 * In SSR case no need to create new sap context.
8663 * Otherwise create sap context first and then create
8664 * vdev as while creating the vdev, driver needs to
8665 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008666 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008667 if (adapter->session.ap.sap_context) {
8668 is_ssr = true;
8669 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008670 hdd_err("sap creation failed");
8671 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8672 }
8673
8674 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8675 adapter->session.ap.sap_context);
8676 if (ret) {
8677 hdd_err("failed to create vdev, status:%d", ret);
8678 hdd_sap_destroy_ctx(adapter);
8679 return ret;
8680 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008681
8682 if (adapter->device_mode == QDF_SAP_MODE)
8683 sme_cli_set_command(adapter->session_id,
8684 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8685 (bool)(hdd_ctx->config->fine_time_meas_cap &
8686 WMI_FW_AP_RTT_RESPR),
8687 VDEV_CMD);
8688
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008689 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308690
8691 if (QDF_STATUS_SUCCESS != status) {
8692 hdd_err("Error Initializing the AP mode: %d", status);
8693 return qdf_status_to_os_return(status);
8694 }
8695
Arun Khandavallifae92942016-08-01 13:31:08 +05308696 hdd_register_tx_flow_control(adapter,
8697 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008698 hdd_softap_tx_resume_cb,
8699 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308700
Dustin Browne74003f2018-03-14 12:51:58 -07008701 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308702 return 0;
8703}
8704
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308705static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8706 bool rtnl_held)
8707{
8708 struct hdd_adapter *adapter;
8709
8710 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8711 hdd_ctx->config->enableConcurrentSTA,
8712 wlan_hdd_get_intf_addr(hdd_ctx),
8713 NET_NAME_UNKNOWN, rtnl_held);
8714
8715 if (!adapter)
8716 return -ENOSPC;
8717
8718 return 0;
8719}
8720
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308721/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008722 * hdd_open_interfaces - Open all required interfaces
8723 * hdd_ctx: HDD context
8724 * rtnl_held: True if RTNL lock is held
8725 *
8726 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8727 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008728 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008729 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008730static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008731{
Jeff Johnson9d295242017-08-29 14:39:48 -07008732 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008733 int ret;
8734
Ravi Joshia307f632017-07-17 23:41:41 -07008735 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008736 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8737 con_mode == QDF_GLOBAL_FTM_MODE) {
8738 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8739 QDF_MONITOR_MODE : QDF_FTM_MODE;
8740
8741 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8742 wlan_hdd_get_intf_addr(hdd_ctx),
8743 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008744 if (!adapter) {
8745 hdd_err("open adapter failed");
8746 return -ENOSPC;
8747 }
Lin Bai1c678482017-12-18 18:29:11 +08008748
Ravi Joshia307f632017-07-17 23:41:41 -07008749 return 0;
8750 }
8751
Jeff Johnson957bc272017-02-02 08:54:48 -08008752 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308753 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008754 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008755
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008756 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008757 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008758 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008759
8760 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008761 return -ENOSPC;
8762
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308763 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8764 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8765 if (ret)
8766 hdd_err("Cannot create concurrent STA interface");
8767 }
8768
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008769 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8770 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008771 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008772
8773 /* Open 802.11p Interface */
8774 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008775 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8776 if (ret)
8777 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008778 }
8779
Jeff Johnson957bc272017-02-02 08:54:48 -08008780 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008781
Jeff Johnson957bc272017-02-02 08:54:48 -08008782err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008783 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008784 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008785}
8786
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008787
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308788#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8789/**
8790 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8791 * @cds_cfg: CDS Configuration
8792 * @hdd_ctx: Pointer to hdd context
8793 *
8794 * Return: none
8795 */
8796static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8797 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008798 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308799{
8800 cds_cfg->tx_flow_stop_queue_th =
8801 hdd_ctx->config->TxFlowStopQueueThreshold;
8802 cds_cfg->tx_flow_start_queue_offset =
8803 hdd_ctx->config->TxFlowStartQueueOffset;
8804}
8805#else
8806static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8807 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008808 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308809{
8810}
8811#endif
8812
8813#ifdef FEATURE_WLAN_RA_FILTERING
8814/**
8815 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8816 * @cds_cfg: CDS Configuration
8817 * @hdd_ctx: Pointer to hdd context
8818 *
8819 * Return: none
8820 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308821static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008822 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308823{
8824 cds_cfg->ra_ratelimit_interval =
8825 hdd_ctx->config->RArateLimitInterval;
8826 cds_cfg->is_ra_ratelimit_enabled =
8827 hdd_ctx->config->IsRArateLimitEnabled;
8828}
8829#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308830static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008831 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308832{
8833}
8834#endif
8835
8836/**
8837 * hdd_update_cds_config() - API to update cds configuration parameters
8838 * @hdd_ctx: HDD Context
8839 *
8840 * Return: 0 for Success, errno on failure
8841 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008842static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308843{
8844 struct cds_config_info *cds_cfg;
8845
8846 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8847 if (!cds_cfg) {
8848 hdd_err("failed to allocate cds config");
8849 return -ENOMEM;
8850 }
8851
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008852 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008853 if (!hdd_ctx->config->nMaxPsPoll ||
8854 !hdd_ctx->config->enablePowersaveOffload) {
8855 cds_cfg->powersave_offload_enabled =
8856 hdd_ctx->config->enablePowersaveOffload;
8857 } else {
8858 if ((hdd_ctx->config->enablePowersaveOffload ==
8859 PS_QPOWER_NODEEPSLEEP) ||
8860 (hdd_ctx->config->enablePowersaveOffload ==
8861 PS_LEGACY_NODEEPSLEEP))
8862 cds_cfg->powersave_offload_enabled =
8863 PS_LEGACY_NODEEPSLEEP;
8864 else
8865 cds_cfg->powersave_offload_enabled =
8866 PS_LEGACY_DEEPSLEEP;
8867 hdd_info("Qpower disabled in cds config, %d",
8868 cds_cfg->powersave_offload_enabled);
8869 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308870 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8871 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8872 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8873 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308874
8875 /*
8876 * Copy the DFS Phyerr Filtering Offload status.
8877 * This parameter reflects the value of the
8878 * dfs_phyerr_filter_offload flag as set in the ini.
8879 */
8880 cds_cfg->dfs_phyerr_filter_offload =
8881 hdd_ctx->config->fDfsPhyerrFilterOffload;
8882 if (hdd_ctx->config->ssdp)
8883 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8884
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308885 cds_cfg->force_target_assert_enabled =
8886 hdd_ctx->config->crash_inject_enabled;
8887
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308888 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8889 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8890
8891 cds_cfg->ap_maxoffload_reorderbuffs =
8892 hdd_ctx->config->apMaxOffloadReorderBuffs;
8893
8894 cds_cfg->ap_disable_intrabss_fwd =
8895 hdd_ctx->config->apDisableIntraBssFwd;
8896
8897 cds_cfg->dfs_pri_multiplier =
8898 hdd_ctx->config->dfsRadarPriMultiplier;
8899 cds_cfg->reorder_offload =
8900 hdd_ctx->config->reorderOffloadSupport;
8901
8902 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05308903 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07008904 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8905 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008906 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008907 hdd_ctx->config->IpaUcTxBufCount);
8908 hdd_ctx->config->IpaUcTxBufCount =
8909 rounddown_pow_of_two(
8910 hdd_ctx->config->IpaUcTxBufCount);
8911 if (!hdd_ctx->config->IpaUcTxBufCount) {
8912 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308913 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008914 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008915 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008916 hdd_ctx->config->IpaUcTxBufCount);
8917 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308918 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8919 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008920 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8921 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008922 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008923 hdd_ctx->config->IpaUcRxIndRingCount);
8924 hdd_ctx->config->IpaUcRxIndRingCount =
8925 rounddown_pow_of_two(
8926 hdd_ctx->config->IpaUcRxIndRingCount);
8927 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8928 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308929 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008930 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008931 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008932 hdd_ctx->config->IpaUcRxIndRingCount);
8933 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308934 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008935 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308936 cds_cfg->uc_tx_partition_base =
8937 hdd_ctx->config->IpaUcTxPartitionBase;
8938 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8939
8940 cds_cfg->ip_tcp_udp_checksum_offload =
8941 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008942 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308943 cds_cfg->ce_classify_enabled =
8944 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008945 cds_cfg->bpf_packet_filter_enable =
8946 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308947 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8948 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8949 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008950 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008951 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008952 cds_cfg->max_msdus_per_rxinorderind =
8953 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008954 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008955 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308956 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8957 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308958 cds_cfg->auto_power_save_fail_mode =
8959 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308960
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308961 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008962 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08008963 cds_cfg->delay_before_vdev_stop =
8964 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308965
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308966 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8967 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8968 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008969 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308970 cds_init_ini_config(cds_cfg);
8971 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308972
8973exit:
8974 qdf_mem_free(cds_cfg);
8975 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308976}
8977
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008978/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008979 * hdd_update_user_config() - API to update user configuration
8980 * parameters to obj mgr which are used by multiple components
8981 * @hdd_ctx: HDD Context
8982 *
8983 * Return: 0 for Success, errno on failure
8984 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008985static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008986{
8987 struct wlan_objmgr_psoc_user_config *user_config;
8988
8989 user_config = qdf_mem_malloc(sizeof(*user_config));
8990 if (user_config == NULL) {
8991 hdd_alert("Failed to alloc memory for user_config!");
8992 return -ENOMEM;
8993 }
8994
8995 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8996 user_config->dual_mac_feature_disable =
8997 hdd_ctx->config->dual_mac_feature_disable;
8998 user_config->indoor_channel_support =
8999 hdd_ctx->config->indoor_channel_support;
9000 user_config->is_11d_support_enabled =
9001 hdd_ctx->config->Is11dSupportEnabled;
9002 user_config->is_11h_support_enabled =
9003 hdd_ctx->config->Is11hSupportEnabled;
9004 user_config->optimize_chan_avoid_event =
9005 hdd_ctx->config->goptimize_chan_avoid_event;
9006 user_config->skip_dfs_chnl_in_p2p_search =
9007 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009008 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009009 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9010
9011 qdf_mem_free(user_config);
9012 return 0;
9013}
9014
9015/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009016 * hdd_init_thermal_info - Initialize thermal level
9017 * @hdd_ctx: HDD context
9018 *
9019 * Initialize thermal level at SME layer and set the thermal level callback
9020 * which would be called when a configured thermal threshold is hit.
9021 *
9022 * Return: 0 on success and errno on failure
9023 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009024static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009025{
9026 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309027 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009028
9029 thermal_param.smeThermalMgmtEnabled =
9030 hdd_ctx->config->thermalMitigationEnable;
9031 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9032
Poddar, Siddarth83905022016-04-16 17:56:08 -07009033 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9034 hdd_ctx->config->throttle_dutycycle_level0;
9035 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9036 hdd_ctx->config->throttle_dutycycle_level1;
9037 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9038 hdd_ctx->config->throttle_dutycycle_level2;
9039 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9040 hdd_ctx->config->throttle_dutycycle_level3;
9041
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009042 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9043 hdd_ctx->config->thermalTempMinLevel0;
9044 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9045 hdd_ctx->config->thermalTempMaxLevel0;
9046 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9047 hdd_ctx->config->thermalTempMinLevel1;
9048 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9049 hdd_ctx->config->thermalTempMaxLevel1;
9050 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9051 hdd_ctx->config->thermalTempMinLevel2;
9052 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9053 hdd_ctx->config->thermalTempMaxLevel2;
9054 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9055 hdd_ctx->config->thermalTempMinLevel3;
9056 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9057 hdd_ctx->config->thermalTempMaxLevel3;
9058
9059 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9060
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309061 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309062 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009063
9064 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9065 hdd_set_thermal_level_cb);
9066
9067 return 0;
9068
9069}
9070
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009071#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9072/**
9073 * hdd_hold_rtnl_lock - Hold RTNL lock
9074 *
9075 * Hold RTNL lock
9076 *
9077 * Return: True if held and false otherwise
9078 */
9079static inline bool hdd_hold_rtnl_lock(void)
9080{
9081 rtnl_lock();
9082 return true;
9083}
9084
9085/**
9086 * hdd_release_rtnl_lock - Release RTNL lock
9087 *
9088 * Release RTNL lock
9089 *
9090 * Return: None
9091 */
9092static inline void hdd_release_rtnl_lock(void)
9093{
9094 rtnl_unlock();
9095}
9096#else
9097static inline bool hdd_hold_rtnl_lock(void) { return false; }
9098static inline void hdd_release_rtnl_lock(void) { }
9099#endif
9100
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009101#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009102
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309103/* MAX iwpriv command support */
9104#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309105#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309106#define MAX_PKTLOG_SIZE 16
9107
9108/**
9109 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9110 * @hdd_ctx: hdd context
9111 * @set_value2: pktlog buffer size value
9112 *
9113 *
9114 * Return: 0 for success or error.
9115 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009116static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309117{
9118 struct sir_wifi_start_log start_log = { 0 };
9119 QDF_STATUS status;
9120
9121 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9122 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9123 start_log.ini_triggered = cds_is_packet_log_enabled();
9124 start_log.user_triggered = 1;
9125 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309126 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309127
9128 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9129 if (!QDF_IS_STATUS_SUCCESS(status)) {
9130 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009131 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309132 return -EINVAL;
9133 }
9134
9135 return 0;
9136}
9137
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009138/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309139 * hdd_pktlog_clear_buff() - clear pktlog buffer
9140 * @hdd_ctx: hdd context
9141 *
9142 * Return: 0 for success or error.
9143 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009144static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309145{
9146 struct sir_wifi_start_log start_log;
9147 QDF_STATUS status;
9148
9149 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9150 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9151 start_log.ini_triggered = cds_is_packet_log_enabled();
9152 start_log.user_triggered = 1;
9153 start_log.size = 0;
9154 start_log.is_pktlog_buff_clear = true;
9155
9156 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9157 if (!QDF_IS_STATUS_SUCCESS(status)) {
9158 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009159 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309160 return -EINVAL;
9161 }
9162
9163 return 0;
9164}
9165
9166
9167/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009168 * hdd_process_pktlog_command() - process pktlog command
9169 * @hdd_ctx: hdd context
9170 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309171 * @set_value2: pktlog buffer size value
9172 *
9173 * This function process pktlog command.
9174 * set_value2 only matters when set_value is 3 (set buff size)
9175 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009176 *
9177 * Return: 0 for success or error.
9178 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009179int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309180 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009181{
9182 int ret;
9183 bool enable;
9184 uint8_t user_triggered = 0;
9185
9186 ret = wlan_hdd_validate_context(hdd_ctx);
9187 if (0 != ret)
9188 return ret;
9189
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009190 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009191
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309192 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009193 hdd_err("invalid pktlog value %d", set_value);
9194 return -EINVAL;
9195 }
9196
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309197 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9198 if (set_value2 <= 0) {
9199 hdd_err("invalid pktlog size %d", set_value2);
9200 return -EINVAL;
9201 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9202 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9203 return -EINVAL;
9204 }
9205 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309206 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9207 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309208 }
9209
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009210 /*
9211 * set_value = 0 then disable packetlog
9212 * set_value = 1 enable packetlog forcefully
9213 * set_vlaue = 2 then disable packetlog if disabled through ini or
9214 * enable packetlog with AUTO type.
9215 */
9216 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9217 true : false;
9218
9219 if (1 == set_value) {
9220 enable = true;
9221 user_triggered = 1;
9222 }
9223
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309224 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009225}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009226
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009227/**
9228 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9229 * @hdd_ctx: HDD context
9230 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309231 * @user_triggered: triggered through iwpriv
9232 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009233 *
9234 * Return: 0 on success; error number otherwise
9235 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009236int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309237 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009238{
9239 struct sir_wifi_start_log start_log;
9240 QDF_STATUS status;
9241
9242 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9243 start_log.verbose_level =
9244 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009245 start_log.ini_triggered = cds_is_packet_log_enabled();
9246 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309247 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309248 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309249 /*
9250 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9251 * commands. Host uses this flag to decide whether to send pktlog
9252 * disable command to fw without sending pktlog enable command
9253 * previously. For eg, If vendor sends pktlog disable command without
9254 * sending pktlog enable command, then host discards the packet
9255 * but for iwpriv command, host will send it to fw.
9256 */
9257 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009258 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9259 if (!QDF_IS_STATUS_SUCCESS(status)) {
9260 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009261 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009262 return -EINVAL;
9263 }
9264
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309265 if (enable == true)
9266 hdd_ctx->is_pktlog_enabled = 1;
9267 else
9268 hdd_ctx->is_pktlog_enabled = 0;
9269
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009270 return 0;
9271}
9272#endif /* REMOVE_PKT_LOG */
9273
Komal Seelam92fff912016-03-24 11:51:41 +05309274/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009275 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9276 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309277 * @dev: Device Pointer
9278 * @num: Number of Valid Mac address
9279 *
9280 * Return: Pointer to MAC address buffer
9281 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009282static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9283 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309284{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009285 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309286}
Komal Seelam92fff912016-03-24 11:51:41 +05309287
9288/**
9289 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9290 * @hdd_ctx: HDD Context
9291 * @num: Number of random mac addresses needed
9292 *
9293 * Generate random addresses using bit manipulation on the base mac address
9294 *
9295 * Return: None
9296 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009297void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309298{
9299 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9300 uint32_t iter;
9301 struct hdd_config *ini = hdd_ctx->config;
9302 uint8_t *buf = NULL;
9303 uint8_t macaddr_b3, tmp_br3;
9304 uint8_t *src = ini->intfMacAddr[0].bytes;
9305
9306 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9307 buf = ini->intfMacAddr[iter].bytes;
9308 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9309 macaddr_b3 = buf[3];
9310 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9311 INTF_MACADDR_MASK;
9312 macaddr_b3 += tmp_br3;
9313 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9314 buf[0] |= 0x02;
9315 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009316 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309317 }
9318}
9319
9320/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009321 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309322 * @hdd_ctx: HDD Context
9323 *
9324 * API to get mac addresses from platform driver and update the driver
9325 * structures and configure FW with the base mac address.
9326 * Return: int
9327 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009328static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309329{
9330 uint32_t no_of_mac_addr, iter;
9331 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9332 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9333 uint8_t *addr, *buf;
9334 struct device *dev = hdd_ctx->parent_dev;
9335 struct hdd_config *ini = hdd_ctx->config;
9336 tSirMacAddr mac_addr;
9337 QDF_STATUS status;
9338
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009339 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309340
9341 if (no_of_mac_addr == 0 || !addr) {
9342 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9343 return -EINVAL;
9344 }
9345
9346 if (no_of_mac_addr > max_mac_addr)
9347 no_of_mac_addr = max_mac_addr;
9348
9349 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9350
9351 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9352 buf = ini->intfMacAddr[iter].bytes;
9353 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009354 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309355 }
9356
9357 status = sme_set_custom_mac_addr(mac_addr);
9358
9359 if (!QDF_IS_STATUS_SUCCESS(status))
9360 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009361
Komal Seelam92fff912016-03-24 11:51:41 +05309362 if (no_of_mac_addr < max_mac_addr)
9363 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9364 no_of_mac_addr);
9365 return 0;
9366}
9367
9368/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009369 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9370 * @hdd_ctx: HDD Context
9371 *
9372 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9373 * will generate its own MAC and update it to FW.
9374 *
9375 * Return: 0 for success
9376 * Non-zero error code for failure
9377 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009378static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009379{
9380 tSirMacAddr customMacAddr;
9381 QDF_STATUS status;
9382
9383 qdf_mem_copy(&customMacAddr,
9384 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9385 sizeof(tSirMacAddr));
9386 status = sme_set_custom_mac_addr(customMacAddr);
9387 if (!QDF_IS_STATUS_SUCCESS(status))
9388 return -EAGAIN;
9389 return 0;
9390}
9391
9392/**
Komal Seelam92fff912016-03-24 11:51:41 +05309393 * hdd_initialize_mac_address() - API to get wlan mac addresses
9394 * @hdd_ctx: HDD Context
9395 *
9396 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9397 * is provisioned with mac addresses, driver uses it, else it will use
9398 * wlan_mac.bin to update HW MAC addresses.
9399 *
9400 * Return: None
9401 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009402static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309403{
9404 QDF_STATUS status;
9405 int ret;
9406
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009407 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309408 if (ret == 0)
9409 return;
9410
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009411 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9412 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309413
9414 status = hdd_update_mac_config(hdd_ctx);
9415
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009416 if (QDF_IS_STATUS_SUCCESS(status))
9417 return;
9418
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009419 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9420 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009421
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009422 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009423 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009424 if (ret != 0) {
9425 hdd_err("MAC address out-of-sync, ret:%d", ret);
9426 QDF_ASSERT(ret);
9427 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009428 }
Komal Seelam92fff912016-03-24 11:51:41 +05309429}
9430
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009431static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009432{
9433 int vdev_id = 0;
9434 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9435 int value = hdd_ctx->config->smart_chainmask_enabled;
9436 int vpdev = PDEV_CMD;
9437 int ret;
9438
Naveen Rawat247a8682017-06-05 15:00:31 -07009439 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009440 if (ret)
9441 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9442
9443 return ret;
9444}
9445
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009446static int hdd_set_alternative_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_ALTERNATIVE_CHAINMASK_SCHEME;
9450 int value = hdd_ctx->config->alternative_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_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9457 ret);
9458
9459 return ret;
9460}
9461
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009462static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009463{
9464 int vdev_id = 0;
9465 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9466 int value = hdd_ctx->config->ani_enabled;
9467 int vpdev = PDEV_CMD;
9468 int ret;
9469
Naveen Rawat247a8682017-06-05 15:00:31 -07009470 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009471 if (ret)
9472 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9473
9474 return ret;
9475}
9476
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009477/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009478 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9479 * @hdd_ctx: HDD context
9480 *
9481 * Pre configurations to be done at lower layer before calling cds enable.
9482 *
9483 * Return: 0 on success and errno on failure.
9484 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009485static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009486{
9487 int ret;
9488 QDF_STATUS status;
9489 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009490 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009491
Leo Changfdb45c32016-10-28 11:09:23 -07009492 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009493 /*
9494 * Set 802.11p config
9495 * TODO-OCB: This has been temporarily added here to ensure this
9496 * parameter is set in CSR when we init the channel list. This should
9497 * be removed once the 5.9 GHz channels are added to the regulatory
9498 * domain.
9499 */
9500 hdd_set_dot11p_config(hdd_ctx);
9501
9502 /*
9503 * Note that the cds_pre_enable() sequence triggers the cfg download.
9504 * The cfg download must occur before we update the SME config
9505 * since the SME config operation must access the cfg database
9506 */
9507 status = hdd_set_sme_config(hdd_ctx);
9508
9509 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009510 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009511 ret = qdf_status_to_os_return(status);
9512 goto out;
9513 }
9514
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009515 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9516 if (QDF_STATUS_SUCCESS != status) {
9517 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9518 ret = qdf_status_to_os_return(status);
9519 goto out;
9520 }
9521
Naveen Rawat247a8682017-06-05 15:00:31 -07009522 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009523 hdd_ctx->config->tx_chain_mask_1ss,
9524 PDEV_CMD);
9525 if (0 != ret) {
9526 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9527 goto out;
9528 }
9529
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009530 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9531 if (ret)
9532 goto out;
9533
9534 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9535 if (ret)
9536 goto out;
9537
Jeff Johnson12a744b2017-04-04 08:19:37 -07009538 ret = hdd_set_ani_enabled(hdd_ctx);
9539 if (ret)
9540 goto out;
9541
Naveen Rawat247a8682017-06-05 15:00:31 -07009542 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009543 hdd_ctx->config->arp_ac_category,
9544 PDEV_CMD);
9545 if (0 != ret) {
9546 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9547 hdd_ctx->config->arp_ac_category, ret);
9548 goto out;
9549 }
9550
Prashanth Bhatta07998752016-04-28 12:35:33 -07009551 status = hdd_set_sme_chan_list(hdd_ctx);
9552 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009553 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009554 ret = qdf_status_to_os_return(status);
9555 goto out;
9556 }
9557
9558 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009559 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009560 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009561 ret = -EINVAL;
9562 goto out;
9563 }
9564
Prashanth Bhatta07998752016-04-28 12:35:33 -07009565 /*
9566 * Set the MAC Address Currently this is used by HAL to add self sta.
9567 * Remove this once self sta is added as part of session open.
9568 */
9569 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9570 hdd_ctx->config->intfMacAddr[0].bytes,
9571 sizeof(hdd_ctx->config->intfMacAddr[0]));
9572
9573 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9574 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9575 hal_status, hal_status);
9576 ret = -EINVAL;
9577 goto out;
9578 }
9579
9580 hdd_init_channel_avoidance(hdd_ctx);
9581
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309582 /* update enable sap mandatory chan list */
9583 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9584 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009585out:
9586 return ret;
9587}
9588
9589/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009590 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9591 * @context_ptr - hdd context pointer
9592 * @event_ptr - event structure pointer
9593 *
9594 * This is the p2p listen offload stop event handler, it sends vendor
9595 * event back to supplicant to notify the stop reason.
9596 *
9597 * Return: None
9598 */
9599static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9600 void *event_ptr)
9601{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009602 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009603 struct sir_p2p_lo_event *evt = event_ptr;
9604 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009605 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009606
Dustin Brown491d54b2018-03-14 12:39:11 -07009607 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009608
9609 if (hdd_ctx == NULL) {
9610 hdd_err("Invalid HDD context pointer");
9611 return;
9612 }
9613
Peng Xu5c682812017-08-06 07:39:13 -07009614 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9615 if (!adapter) {
9616 hdd_err("Cannot find adapter by vdev_id = %d",
9617 evt->vdev_id);
9618 return;
9619 }
9620
Peng Xu8fdaa492016-06-22 10:20:47 -07009621 vendor_event =
9622 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009623 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009624 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9625 GFP_KERNEL);
9626
9627 if (!vendor_event) {
9628 hdd_err("cfg80211_vendor_event_alloc failed");
9629 return;
9630 }
9631
9632 if (nla_put_u32(vendor_event,
9633 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9634 evt->reason_code)) {
9635 hdd_err("nla put failed");
9636 kfree_skb(vendor_event);
9637 return;
9638 }
9639
9640 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009641 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9642 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009643}
9644
9645/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309646 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9647 * @hdd_ctx: HDD context
9648 *
9649 * This function sends the adaptive dwell time config configuration to the
9650 * firmware via WMA
9651 *
9652 * Return: 0 - success, < 0 - failure
9653 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009654static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309655{
9656 QDF_STATUS status;
9657 struct adaptive_dwelltime_params dwelltime_params;
9658
9659 dwelltime_params.is_enabled =
9660 hdd_ctx->config->adaptive_dwell_mode_enabled;
9661 dwelltime_params.dwelltime_mode =
9662 hdd_ctx->config->global_adapt_dwelltime_mode;
9663 dwelltime_params.lpf_weight =
9664 hdd_ctx->config->adapt_dwell_lpf_weight;
9665 dwelltime_params.passive_mon_intval =
9666 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9667 dwelltime_params.wifi_act_threshold =
9668 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9669
9670 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9671 &dwelltime_params);
9672
9673 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9674 if (!QDF_IS_STATUS_SUCCESS(status)) {
9675 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9676 return -EAGAIN;
9677 }
9678 return 0;
9679}
9680
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009681int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309682{
9683 QDF_STATUS status;
9684 struct wmi_dbs_scan_sel_params dbs_scan_params;
9685 uint32_t i = 0;
9686 uint8_t count = 0, numentries = 0;
9687 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9688 * CDS_DBS_SCAN_CLIENTS_MAX];
9689
9690 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +05309691 if ((hdd_ctx->config->dual_mac_feature_disable ==
9692 DISABLE_DBS_CXN_AND_SCAN) ||
9693 (hdd_ctx->config->dual_mac_feature_disable ==
9694 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309695 return -EINVAL;
9696
9697 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9698 dbs_scan_config, &numentries,
9699 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9700 * CDS_DBS_SCAN_CLIENTS_MAX));
9701
9702 hdd_info("numentries %hu", numentries);
9703 if (!numentries) {
9704 hdd_info("Donot send scan_selection_config");
9705 return 0;
9706 }
9707
9708 /* hdd_set_fw_log_params */
9709 dbs_scan_params.num_clients = 0;
9710 while (count < (numentries - 2)) {
9711 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9712 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9713 dbs_scan_params.num_non_dbs_scans[i] =
9714 dbs_scan_config[count + 2];
9715 dbs_scan_params.num_clients++;
9716 hdd_debug("module:%d NDS:%d NNDS:%d",
9717 dbs_scan_params.module_id[i],
9718 dbs_scan_params.num_dbs_scans[i],
9719 dbs_scan_params.num_non_dbs_scans[i]);
9720 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9721 i++;
9722 }
9723
9724 dbs_scan_params.pdev_id = 0;
9725
9726 hdd_debug("clients:%d pdev:%d",
9727 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9728
9729 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9730 &dbs_scan_params);
9731 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9732 if (!QDF_IS_STATUS_SUCCESS(status)) {
9733 hdd_err("Failed to send DBS Scan selection configuration!");
9734 return -EAGAIN;
9735 }
9736 return 0;
9737}
9738
Arun Khandavallid4349a92016-07-25 11:10:43 +05309739#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9740/**
9741 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9742 * @hdd_ctx: HDD context
9743 *
9744 * Set auto shutdown callback to get indications from firmware to indicate
9745 * userspace to shutdown WLAN after a configured amount of inactivity.
9746 *
9747 * Return: 0 on success and errno on failure.
9748 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009749static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309750{
9751 QDF_STATUS status;
9752
9753 if (!hdd_ctx->config->WlanAutoShutdown)
9754 return 0;
9755
9756 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9757 wlan_hdd_auto_shutdown_cb);
9758 if (status != QDF_STATUS_SUCCESS)
9759 hdd_err("Auto shutdown feature could not be enabled: %d",
9760 status);
9761
9762 return qdf_status_to_os_return(status);
9763}
9764#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009765static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309766{
9767 return 0;
9768}
9769#endif
9770
9771/**
9772 * hdd_features_init() - Init features
9773 * @hdd_ctx: HDD context
9774 * @adapter: Primary adapter context
9775 *
9776 * Initialize features and their feature context after WLAN firmware is up.
9777 *
9778 * Return: 0 on success and errno on failure.
9779 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009780static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309781{
9782 tSirTxPowerLimit hddtxlimit;
9783 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309784 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309785 int ret;
9786
Dustin Brown491d54b2018-03-14 12:39:11 -07009787 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309788
Arun Khandavallid4349a92016-07-25 11:10:43 +05309789 /* FW capabilities received, Set the Dot11 mode */
9790 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009791 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9792 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309793
Arun Khandavallid4349a92016-07-25 11:10:43 +05309794
9795 if (hdd_ctx->config->fIsImpsEnabled)
9796 hdd_set_idle_ps_config(hdd_ctx, true);
9797 else
9798 hdd_set_idle_ps_config(hdd_ctx, false);
9799
Poddar, Siddarth37033032017-10-11 15:47:40 +05309800 /* Send Enable/Disable data stall detection cmd to FW */
9801 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9802 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9803
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309804 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009805 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309806
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309807 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9808 hdd_warn("Error in setting Voltage Corner mode config to FW");
9809
Arun Khandavallid4349a92016-07-25 11:10:43 +05309810 if (hdd_lro_init(hdd_ctx))
9811 hdd_err("Unable to initialize LRO in fw");
9812
9813 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9814 hdd_err("Unable to send adaptive dwelltime setting to FW");
9815
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309816 if (hdd_dbs_scan_selection_init(hdd_ctx))
9817 hdd_err("Unable to send DBS scan selection setting to FW");
9818
Arun Khandavallid4349a92016-07-25 11:10:43 +05309819 ret = hdd_init_thermal_info(hdd_ctx);
9820 if (ret) {
9821 hdd_err("Error while initializing thermal information");
9822 goto deregister_frames;
9823 }
9824
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309825 /**
9826 * In case of SSR/PDR, if pktlog was enabled manually before
9827 * SSR/PDR, Then enabled it again automatically after Wlan
9828 * device up.
9829 */
9830 if (cds_is_driver_recovering()) {
9831 if (hdd_ctx->is_pktlog_enabled)
9832 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +08009833 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309834
Arun Khandavallid4349a92016-07-25 11:10:43 +05309835 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9836 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9837 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9838 if (!QDF_IS_STATUS_SUCCESS(status))
9839 hdd_err("Error setting txlimit in sme: %d", status);
9840
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009841 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309842
Arun Khandavallid4349a92016-07-25 11:10:43 +05309843 ret = hdd_register_cb(hdd_ctx);
9844 if (ret) {
9845 hdd_err("Failed to register HDD callbacks!");
9846 goto deregister_frames;
9847 }
9848
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309849 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9850 status = sme_enable_disable_chanavoidind_event(
9851 hdd_ctx->hHal, 0);
9852 if (!QDF_IS_STATUS_SUCCESS(status)) {
9853 hdd_err("Failed to disable Chan Avoidance Indication");
9854 goto deregister_cb;
9855 }
9856 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309857
Manjeet Singha9cae432017-02-28 11:58:22 +05309858 if (hdd_ctx->config->enable_5g_band_pref) {
9859 band_pref_params.rssi_boost_threshold_5g =
9860 hdd_ctx->config->rssi_boost_threshold_5g;
9861 band_pref_params.rssi_boost_factor_5g =
9862 hdd_ctx->config->rssi_boost_factor_5g;
9863 band_pref_params.max_rssi_boost_5g =
9864 hdd_ctx->config->max_rssi_boost_5g;
9865 band_pref_params.rssi_penalize_threshold_5g =
9866 hdd_ctx->config->rssi_penalize_threshold_5g;
9867 band_pref_params.rssi_penalize_factor_5g =
9868 hdd_ctx->config->rssi_penalize_factor_5g;
9869 band_pref_params.max_rssi_penalize_5g =
9870 hdd_ctx->config->max_rssi_penalize_5g;
9871 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9872 }
9873
Arun Khandavallid4349a92016-07-25 11:10:43 +05309874 /* register P2P Listen Offload event callback */
9875 if (wma_is_p2p_lo_capable())
9876 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9877 wlan_hdd_p2p_lo_event_callback);
9878
9879 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9880
9881 if (ret)
9882 goto deregister_cb;
9883
Dustin Brown11638b72018-01-25 17:37:25 +05309884 wlan_hdd_init_chan_info(hdd_ctx);
9885
Dustin Browne74003f2018-03-14 12:51:58 -07009886 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309887 return 0;
9888
9889deregister_cb:
9890 hdd_deregister_cb(hdd_ctx);
9891deregister_frames:
9892 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309893 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309894}
9895
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009896/**
9897 * hdd_features_deinit() - Deinit features
9898 * @hdd_ctx: HDD context
9899 *
9900 * De-Initialize features and their feature context.
9901 *
9902 * Return: none.
9903 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009904static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009905{
Dustin Brown11638b72018-01-25 17:37:25 +05309906 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009907 wlan_hdd_tsf_deinit(hdd_ctx);
9908}
9909
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309910/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009911 * hdd_register_bcn_cb() - register scan beacon callback
9912 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309913 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009914 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309915 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009916static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309917{
9918 QDF_STATUS status;
9919
9920 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9921 wlan_cfg80211_inform_bss_frame,
9922 SCAN_CB_TYPE_INFORM_BCN);
9923 if (!QDF_IS_STATUS_SUCCESS(status)) {
9924 hdd_err("failed with status code %08d [x%08x]",
9925 status, status);
9926 return status;
9927 }
9928
9929 return QDF_STATUS_SUCCESS;
9930}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309931
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309932/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309933 * hdd_configure_cds() - Configure cds modules
9934 * @hdd_ctx: HDD context
9935 * @adapter: Primary adapter context
9936 *
9937 * Enable Cds modules after WLAN firmware is up.
9938 *
9939 * Return: 0 on success and errno on failure.
9940 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009941int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309942{
9943 int ret;
9944 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309945 int set_value;
9946 uint32_t num_abg_tx_chains = 0;
9947 uint32_t num_11b_tx_chains = 0;
9948 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009949 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309950
9951 if (hdd_ctx->config->sifs_burst_duration) {
9952 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9953 hdd_ctx->config->sifs_burst_duration;
9954
9955 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9956 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9957 set_value, PDEV_CMD);
9958 }
9959
9960 if (hdd_ctx->config->is_force_1x1)
9961 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9962 1, PDEV_CMD);
9963 /* set chip power save failure detected callback */
9964 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9965 hdd_chip_pwr_save_fail_detected_cb);
9966
9967 if (hdd_ctx->config->max_mpdus_inampdu) {
9968 set_value = hdd_ctx->config->max_mpdus_inampdu;
9969 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9970 set_value, PDEV_CMD);
9971 }
9972
9973 if (hdd_ctx->config->enable_rts_sifsbursting) {
9974 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9975 sme_cli_set_command(0,
9976 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9977 set_value, PDEV_CMD);
9978 }
9979
9980 if (hdd_ctx->config->sap_get_peer_info) {
9981 set_value = hdd_ctx->config->sap_get_peer_info;
9982 sme_cli_set_command(0,
9983 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9984 set_value, PDEV_CMD);
9985 }
9986
9987 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9988 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9989 if (!hdd_ctx->config->enable2x2) {
9990 if (num_11b_tx_chains > 1)
9991 num_11b_tx_chains = 1;
9992 if (num_11ag_tx_chains > 1)
9993 num_11ag_tx_chains = 1;
9994 }
9995 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9996 num_11b_tx_chains);
9997 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9998 num_11ag_tx_chains);
9999 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10000 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010001
10002 ret = hdd_pre_enable_configure(hdd_ctx);
10003 if (ret) {
10004 hdd_err("Failed to pre-configure cds");
10005 goto out;
10006 }
10007
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010008 /* Always get latest IPA resources allocated from cds_open and configure
10009 * IPA module before configuring them to FW. Sequence required as crash
10010 * observed otherwise.
10011 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010012 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10013 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010014 hdd_err("Failed to setup pipes");
10015 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010016 }
10017
Arun Khandavallifae92942016-08-01 13:31:08 +053010018 /*
10019 * Start CDS which starts up the SME/MAC/HAL modules and everything
10020 * else
10021 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010022 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010023
10024 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010025 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010026 goto out;
10027 }
10028
10029 status = hdd_post_cds_enable_config(hdd_ctx);
10030 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010031 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010032 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010033 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010034 status = hdd_register_bcn_cb(hdd_ctx);
10035 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010036 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010037 goto cds_disable;
10038 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010039
10040 ret = hdd_features_init(hdd_ctx, adapter);
10041 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010042 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010043
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010044 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010045 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010046 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010047 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10048 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010049 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010050 goto cds_disable;
10051 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010052 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10053 wlan_hdd_send_mode_change_event);
10054 if (!QDF_IS_STATUS_SUCCESS(status)) {
10055 hdd_debug("Failed to register mode change cb with Policy Manager");
10056 goto cds_disable;
10057 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010058
Jeff Johnson8bb61112018-03-31 13:33:54 -070010059 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010060 hdd_debug("enhance green ap is not enabled");
10061
Nachiket Kukadedd302662017-07-13 17:31:44 +053010062 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10063 hdd_debug("Failed to set wow pulse");
10064
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010065 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10066 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010067 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10068 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10069
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010070
10071 if (hdd_ctx->config->enable_phy_reg_retention)
10072 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10073 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10074
Arun Khandavallifae92942016-08-01 13:31:08 +053010075 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010076
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010077cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010078 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010079
Arun Khandavallifae92942016-08-01 13:31:08 +053010080out:
10081 return -EINVAL;
10082}
10083
10084/**
10085 * hdd_deconfigure_cds() -De-Configure cds
10086 * @hdd_ctx: HDD context
10087 *
10088 * Deconfigure Cds modules before WLAN firmware is down.
10089 *
10090 * Return: 0 on success and errno on failure.
10091 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010092static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010093{
10094 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010095 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010096
Dustin Brown491d54b2018-03-14 12:39:11 -070010097 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010098
10099 /* De-init features */
10100 hdd_features_deinit(hdd_ctx);
10101
Arun Khandavallifae92942016-08-01 13:31:08 +053010102 /* De-register the SME callbacks */
10103 hdd_deregister_cb(hdd_ctx);
10104
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010105 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10106 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10107 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10108 }
10109
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010110 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010111 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10112 hdd_err("Failed to Disable the CDS Modules! :%d",
10113 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010114 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010115 }
10116
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010117 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010118 hdd_err("Failed to disconnect pipes");
10119 ret = -EINVAL;
10120 }
10121
Dustin Browne74003f2018-03-14 12:51:58 -070010122 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010123 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010124}
10125
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010126#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10127static void hdd_deregister_policy_manager_callback(
10128 struct wlan_objmgr_psoc *psoc)
10129{
10130 if (QDF_STATUS_SUCCESS !=
10131 policy_mgr_deregister_hdd_cb(psoc)) {
10132 hdd_err("HDD callback deregister with policy manager failed");
10133 }
10134}
10135#else
10136static void hdd_deregister_policy_manager_callback(
10137 struct wlan_objmgr_psoc *psoc)
10138{
10139}
10140#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010141
10142/**
10143 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10144 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010145 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010146 *
10147 * This function maintains the driver state machine it will be invoked from
10148 * exit, shutdown and con_mode change handler. Depending on the driver state
10149 * shall perform the stopping/closing of the modules.
10150 *
10151 * Return: 0 for success; non-zero for failure
10152 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010153int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010154{
10155 void *hif_ctx;
10156 qdf_device_t qdf_ctx;
10157 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010158 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010159 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010160 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10161 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010162 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010163 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010164
Dustin Brown491d54b2018-03-14 12:39:11 -070010165 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010166 hdd_alert("stop WLAN module: entering driver status=%d",
10167 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010168
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010169 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10170
Arun Khandavallifae92942016-08-01 13:31:08 +053010171 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10172 if (!qdf_ctx) {
10173 hdd_err("QDF device context NULL");
10174 return -EINVAL;
10175 }
10176
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010177 mutex_lock(&hdd_ctx->iface_change_lock);
10178 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010179 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010180
Dustin Brown70111822017-03-30 15:31:40 -070010181 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010182 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010183 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010184 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010185
10186 cds_print_external_threads();
10187
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010188 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010189 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010190 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10191 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010192 hdd_prevent_suspend_timeout(
10193 hdd_ctx->config->iface_change_wait_time,
10194 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010195 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010196 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010197 return 0;
10198 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010199 }
10200
Arun Khandavallifae92942016-08-01 13:31:08 +053010201 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10202
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010203 /* free user wowl patterns */
10204 hdd_free_user_wowl_ptrns();
10205
Arun Khandavallifae92942016-08-01 13:31:08 +053010206 switch (hdd_ctx->driver_status) {
10207 case DRIVER_MODULES_UNINITIALIZED:
10208 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010209 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010210 case DRIVER_MODULES_CLOSED:
10211 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010212 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010213 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010214 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10215
Komal Seelamf2136bb2016-09-28 18:30:44 +053010216 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010217 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010218 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010219 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010220 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010221 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010222 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010223
Arun Khandavallifae92942016-08-01 13:31:08 +053010224 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010225 hdd_info("Wlan transitioned (now OPENED)");
10226
10227 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010228 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010229 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010230 break;
10231 default:
10232 hdd_err("Trying to stop wlan in a wrong state: %d",
10233 hdd_ctx->driver_status);
10234 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010235 ret = -EINVAL;
10236 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010237 }
10238
Amar Singhal18081642018-01-26 16:04:13 -080010239 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010240 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010241
Rajeev Kumarbe021242017-02-16 16:12:23 -080010242 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010243 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10244 hdd_err("Failed to process post CDS disable Modules! :%d",
10245 qdf_status);
10246 ret = -EINVAL;
10247 QDF_ASSERT(0);
10248 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010249
psimhadeea0a12017-12-18 14:50:02 -080010250 hdd_runtime_suspend_context_deinit(hdd_ctx);
10251
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010252 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10253 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10254 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10255 ret = -EINVAL;
10256 QDF_ASSERT(0);
10257 }
10258
Jeff Johnsone4b14592017-09-13 14:23:33 -070010259 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010260 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010261 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010262 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010263 QDF_ASSERT(0);
10264 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010265
Amar Singhal410675c2018-01-10 12:14:21 -080010266 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010267 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10268 if (ret) {
10269 hdd_err("Failed to destroy pdev; errno:%d", ret);
10270 QDF_ASSERT(0);
10271 }
10272
10273 /*
10274 * Reset total mac phy during module stop such that during
10275 * next module start same psoc is used to populate new service
10276 * ready data
10277 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010278 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10279 if (tgt_hdl)
10280 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10281
Liangwei Dong50a64a72018-01-11 01:17:00 -050010282
Arun Khandavallifae92942016-08-01 13:31:08 +053010283 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10284 if (!hif_ctx) {
10285 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010286 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010287 }
10288
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010289 if (hdd_ctx->target_hw_name) {
10290 qdf_mem_free(hdd_ctx->target_hw_name);
10291 hdd_ctx->target_hw_name = NULL;
10292 }
10293
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010294 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010295
10296 ol_cds_free();
10297
Dustin Brown70111822017-03-30 15:31:40 -070010298 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010299 ret = pld_power_off(qdf_ctx->dev);
10300 if (ret)
10301 hdd_err("CNSS power down failed put device into Low power mode:%d",
10302 ret);
10303 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010304
Dustin Brown4bc0a622017-12-06 15:56:50 -080010305 /* many adapter resources are not freed by design in SSR case */
10306 if (!is_recovery_stop)
10307 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010308 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010309
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010310 /* Once the firmware sequence is completed reset this flag */
10311 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010312 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010313 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010314
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010315done:
10316 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010317 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010318 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010319 hdd_alert("stop WLAN module: exit driver status=%d",
10320 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010321
Dustin Browne74003f2018-03-14 12:51:58 -070010322 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010323
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010324 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010325}
10326
Arun Khandavallifae92942016-08-01 13:31:08 +053010327
10328/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010329 * hdd_state_info_dump() - prints state information of hdd layer
10330 * @buf: buffer pointer
10331 * @size: size of buffer to be filled
10332 *
10333 * This function is used to dump state information of hdd layer
10334 *
10335 * Return: None
10336 */
10337static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10338{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010339 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010340 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010341 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010342 uint16_t len = 0;
10343 char *buf = *buf_ptr;
10344
10345 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10346 if (!hdd_ctx) {
10347 hdd_err("Failed to get hdd context ");
10348 return;
10349 }
10350
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010351 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010352
10353 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010354 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010355 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010356 "\n is_scheduler_suspended %d",
10357 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010358
Dustin Brown920397d2017-12-13 16:27:50 -080010359 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010360 if (adapter->dev)
10361 len += scnprintf(buf + len, *size - len,
10362 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010363 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010364 "\n device_mode: %d", adapter->device_mode);
10365 switch (adapter->device_mode) {
10366 case QDF_STA_MODE:
10367 case QDF_P2P_CLIENT_MODE:
10368 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10369 len += scnprintf(buf + len, *size - len,
10370 "\n connState: %d",
10371 hdd_sta_ctx->conn_info.connState);
10372 break;
10373
10374 default:
10375 break;
10376 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010377 }
10378
10379 *size -= len;
10380 *buf_ptr += len;
10381}
10382
10383/**
10384 * hdd_register_debug_callback() - registration function for hdd layer
10385 * to print hdd state information
10386 *
10387 * Return: None
10388 */
10389static void hdd_register_debug_callback(void)
10390{
10391 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10392}
10393
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010394/*
10395 * wlan_init_bug_report_lock() - Initialize bug report lock
10396 *
10397 * This function is used to create bug report lock
10398 *
10399 * Return: None
10400 */
10401static void wlan_init_bug_report_lock(void)
10402{
10403 p_cds_contextType p_cds_context;
10404
10405 p_cds_context = cds_get_global_context();
10406 if (!p_cds_context) {
10407 hdd_err("cds context is NULL");
10408 return;
10409 }
10410
10411 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10412}
10413
Mohit Khannaf8f96822017-05-17 17:11:59 -070010414void hdd_dp_trace_init(struct hdd_config *config)
10415{
10416
10417 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10418 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10419 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10420 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10421 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10422 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10423 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010424 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010425
10426 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10427 &num_entries, sizeof(config_params));
10428
10429 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010430 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010431 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010432 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010433 else if (bw_compute_interval > 1000) {
10434 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10435 thresh_time_limit = 1;
10436 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010437 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10438
10439 switch (num_entries) {
10440 case 4:
10441 proto_bitmap = config_params[3];
10442 case 3:
10443 verbosity = config_params[2];
10444 case 2:
10445 thresh = config_params[1];
10446 case 1:
10447 live_mode = config_params[0];
10448 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010449 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010450 live_mode, thresh, thresh_time_limit,
10451 verbosity, proto_bitmap);
10452 };
10453
10454 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10455 verbosity, proto_bitmap);
10456
10457}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010458/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010459 * hdd_wlan_startup() - HDD init function
10460 * @dev: Pointer to the underlying device
10461 *
10462 * This is the driver startup code executed once a WLAN device has been detected
10463 *
10464 * Return: 0 for success, < 0 for failure
10465 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010466int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010467{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010468 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010469 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010470 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010471 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010472
Dustin Brown491d54b2018-03-14 12:39:11 -070010473 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010474
Arun Khandavallifae92942016-08-01 13:31:08 +053010475 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010476
10477 if (IS_ERR(hdd_ctx))
10478 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010479
Abhishek Singhe9068f12017-03-31 14:14:52 +053010480 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10481 DEFAULT_PSOC_ID);
10482 if (ret) {
10483 hdd_err("Psoc creation fails!");
10484 QDF_BUG(0);
10485 goto err_hdd_free_context;
10486 }
10487
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010488 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010489#ifdef FEATURE_WLAN_CH_AVOID
10490 mutex_init(&hdd_ctx->avoid_freq_lock);
10491#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010492
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010493 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010494 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010495
Dustin Brown021cecd2017-12-11 13:56:43 -080010496 hdd_driver_memdump_init();
10497
Jeff Johnson957bc272017-02-02 08:54:48 -080010498 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010499 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010500 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010501 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010502 }
10503
Yingying Tang80e15f32016-09-27 18:23:01 +080010504 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010505
Anurag Chouhan6d760662016-02-20 16:05:43 +053010506 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010507
10508 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010509 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010510 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010511 }
10512
Prashanth Bhatta07998752016-04-28 12:35:33 -070010513 ret = hdd_wiphy_init(hdd_ctx);
10514 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010515 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010516 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010517 }
10518
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010519 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010520 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010521
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010522 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010523
Paul Zhangfb02f452017-12-22 11:58:43 +080010524 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10525 if (ret) {
10526 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010527 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080010528 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010529
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010530 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010531
Jeff Johnson957bc272017-02-02 08:54:48 -080010532 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10533 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010534 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010535 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010536 }
10537
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010538 hdd_release_rtnl_lock();
10539 rtnl_held = false;
10540
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010541 wlan_hdd_update_11n_mode(hdd_ctx->config);
10542
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010543#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010544 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010545 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010546 hdd_skip_acs_scan_timer_handler,
10547 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010548 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010549 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010550 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010551#endif
10552
Prashanth Bhattaab004382016-10-11 16:08:11 -070010553 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010554
Jeff Johnson9afc5012016-09-23 13:56:27 -070010555 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010556
Nirav Shahbd36b062016-07-18 11:12:59 +053010557 if (hdd_ctx->rps)
10558 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010559
Paul Zhangfb02f452017-12-22 11:58:43 +080010560 ret = hdd_register_notifiers(hdd_ctx);
10561 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010562 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010563
Paul Zhangfb02f452017-12-22 11:58:43 +080010564 status = wlansap_global_init();
10565 if (QDF_IS_STATUS_ERROR(status)) {
10566 hdd_unregister_notifiers(hdd_ctx);
10567 goto err_close_adapters;
10568 }
10569
Arun Khandavallifae92942016-08-01 13:31:08 +053010570 if (hdd_ctx->config->fIsImpsEnabled)
10571 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010572 else
10573 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010574
Mukul Sharma07bd8752017-10-10 16:58:14 +053010575 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010576 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10577 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010578 hdd_prevent_suspend_timeout(
10579 hdd_ctx->config->iface_change_wait_time,
10580 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10581 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010582
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010583 goto success;
10584
Jeff Johnson957bc272017-02-02 08:54:48 -080010585err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010586 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010587
Jeff Johnson46bde382017-02-01 15:31:16 -080010588err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010589 if (rtnl_held)
10590 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010591
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010592 unregister_netdevice_notifier(&hdd_netdev_notifier);
10593
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010594err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010595 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010596
Arun Khandavallifae92942016-08-01 13:31:08 +053010597err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010598 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010599
Dustin Brown021cecd2017-12-11 13:56:43 -080010600err_memdump_deinit:
10601 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010602
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010603 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010604 hdd_exit_netlink_services(hdd_ctx);
10605
Dustin Brown20912462017-06-07 13:48:25 -070010606 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10607
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010608err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010609 if (cds_is_fw_down())
10610 hdd_err("Not setting the complete event as fw is down");
10611 else
10612 hdd_start_complete(ret);
10613
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010614 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010615 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010616 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010617
10618success:
Dustin Browne74003f2018-03-14 12:51:58 -070010619 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010620 return 0;
10621}
10622
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010623/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010624 * hdd_wlan_update_target_info() - update target type info
10625 * @hdd_ctx: HDD context
10626 * @context: hif context
10627 *
10628 * Update target info received from firmware in hdd context
10629 * Return:None
10630 */
10631
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010632void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010633{
10634 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10635
10636 if (!tgt_info) {
10637 hdd_err("Target info is Null");
10638 return;
10639 }
10640
10641 hdd_ctx->target_type = tgt_info->target_type;
10642}
10643
10644/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010645 * hdd_get_nud_stats_cb() - callback api to update the stats
10646 * received from the firmware
10647 * @data: pointer to adapter.
10648 * @rsp: pointer to data received from FW.
10649 *
10650 * This is called when wlan driver received response event for
10651 * get arp stats to firmware.
10652 *
10653 * Return: None
10654 */
10655static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10656{
10657 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10658 struct hdd_nud_stats_context *context;
10659 int status;
10660 struct hdd_adapter *adapter = NULL;
10661
Dustin Brown491d54b2018-03-14 12:39:11 -070010662 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010663
10664 if (!rsp) {
10665 hdd_err("data is null");
10666 return;
10667 }
10668
10669 status = wlan_hdd_validate_context(hdd_ctx);
10670 if (0 != status)
10671 return;
10672
10673 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10674 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10675 hdd_err("Invalid adapter or adapter has invalid magic");
10676 return;
10677 }
10678
Dustin Brown5e89ef82018-03-14 11:50:23 -070010679 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10680 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10681 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10682 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10683 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10684 rsp->out_of_order_arp_rsp_drop_cnt);
10685 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
10686 hdd_info("rsp->connect_status :%x", rsp->connect_status);
10687 hdd_info("rsp->ba_session_establishment_status :%x",
10688 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010689
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010690 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010691 adapter->dad |= rsp->dad_detected;
10692 adapter->con_status = rsp->connect_status;
10693
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053010694 /* Flag true indicates connectivity check stats present. */
10695 if (rsp->connect_stats_present) {
10696 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
10697 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
10698 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
10699 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
10700 rsp->icmpv4_rsp_recvd;
10701 }
10702
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010703 spin_lock(&hdd_context_lock);
10704 context = &hdd_ctx->nud_stats_context;
10705 complete(&context->response_event);
10706 spin_unlock(&hdd_context_lock);
10707
Dustin Browne74003f2018-03-14 12:51:58 -070010708 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010709}
10710
10711/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010712 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010713 * @hdd_ctx: HDD context
10714 *
10715 * Register the HDD callbacks to CDS/SME.
10716 *
10717 * Return: 0 for success or Error code for failure
10718 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010719int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010720{
10721 QDF_STATUS status;
10722 int ret = 0;
10723
Dustin Brown491d54b2018-03-14 12:39:11 -070010724 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010725
10726 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10727
10728 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10729 hdd_send_oem_data_rsp_msg);
10730
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010731 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10732 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010733 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10734 sme_nan_register_callback(hdd_ctx->hHal,
10735 wlan_hdd_cfg80211_nan_callback);
10736 sme_stats_ext_register_callback(hdd_ctx->hHal,
10737 wlan_hdd_cfg80211_stats_ext_callback);
10738
10739 sme_ext_scan_register_callback(hdd_ctx->hHal,
10740 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010741 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10742 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010743
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010744 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10745 hdd_rssi_threshold_breached);
10746
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010747 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10748
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010749 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10750 wlan_hdd_cfg80211_link_layer_stats_callback);
10751
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010752 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10753
Zhang Qianca38fb12016-12-23 11:10:48 +080010754 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10755 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10756
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010757 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10758 hdd_lost_link_info_cb);
10759 /* print error and not block the startup process */
10760 if (!QDF_IS_STATUS_SUCCESS(status))
10761 hdd_err("set lost link info callback failed");
10762
Poddar, Siddarth34872782017-08-10 14:08:51 +053010763 ret = hdd_register_data_stall_detect_cb();
10764 if (ret) {
10765 hdd_err("Register data stall detect detect callback failed.");
10766 return ret;
10767 }
10768
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010769 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10770
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010771 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010772 hdd_set_connection_in_progress,
10773 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010774
10775 status = sme_congestion_register_callback(hdd_ctx->hHal,
10776 hdd_update_cca_info_cb);
10777 if (!QDF_IS_STATUS_SUCCESS(status))
10778 hdd_err("set congestion callback failed");
10779
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010780 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10781 hdd_bt_activity_cb);
10782 if (!QDF_IS_STATUS_SUCCESS(status))
10783 hdd_err("set bt activity info callback failed");
10784
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010785 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10786 hdd_tx_queue_cb);
10787 if (!QDF_IS_STATUS_SUCCESS(status))
10788 hdd_err("Register tx queue callback failed");
10789
Dustin Browne74003f2018-03-14 12:51:58 -070010790 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010791
10792 return ret;
10793}
10794
10795/**
10796 * hdd_deregister_cb() - De-Register HDD callbacks.
10797 * @hdd_ctx: HDD context
10798 *
10799 * De-Register the HDD callbacks to CDS/SME.
10800 *
10801 * Return: void
10802 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010803void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010804{
10805 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010806 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010807
Dustin Brown491d54b2018-03-14 12:39:11 -070010808 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010809
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010810 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010811 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10812 if (!QDF_IS_STATUS_SUCCESS(status))
10813 hdd_err("De-register of dcc stats callback failed: %d",
10814 status);
10815
10816 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010817 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10818
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010819 sme_stats_ext_register_callback(hdd_ctx->hHal,
10820 wlan_hdd_cfg80211_stats_ext_callback);
10821
10822 sme_nan_deregister_callback(hdd_ctx->hHal);
10823 status = sme_reset_tsfcb(hdd_ctx->hHal);
10824 if (!QDF_IS_STATUS_SUCCESS(status))
10825 hdd_err("Failed to de-register tsfcb the callback:%d",
10826 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010827
Poddar, Siddarth34872782017-08-10 14:08:51 +053010828 ret = hdd_deregister_data_stall_detect_cb();
10829 if (ret)
10830 hdd_err("Failed to de-register data stall detect event callback");
10831
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010832 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10833 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10834
Dustin Browne74003f2018-03-14 12:51:58 -070010835 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010836}
10837
10838/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010839 * hdd_softap_sta_deauth() - handle deauth req from HDD
10840 * @adapter: Pointer to the HDD
10841 * @enable: bool value
10842 *
10843 * This to take counter measure to handle deauth req from HDD
10844 *
10845 * Return: None
10846 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010847QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010848 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010849{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010850 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010851
Dustin Brown491d54b2018-03-14 12:39:11 -070010852 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010853
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010854 /* Ignore request to deauth bcmc station */
10855 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010856 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010857
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010858 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010859 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10860 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010861
Dustin Browne74003f2018-03-14 12:51:58 -070010862 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010863 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010864}
10865
10866/**
10867 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10868 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010869 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010870 *
10871 * This to take counter measure to handle deauth req from HDD
10872 *
10873 * Return: None
10874 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010875void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010876 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010877{
Dustin Brown491d54b2018-03-14 12:39:11 -070010878 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010879
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010880 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010881 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010882 return;
10883
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010884 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010885 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010886}
10887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010888/**
10889 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10890 * @hdd_ctx: HDD Context
10891 *
10892 * API to find if there is any STA or P2P-Client is connected
10893 *
10894 * Return: true if connected; false otherwise
10895 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010896QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010897{
10898 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10899}
10900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010901/**
10902 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10903 * @adapter: HDD adapter pointer
10904 *
10905 * This function loop through each adapter and disable roaming on each STA
10906 * device mode except the input adapter.
10907 *
10908 * Note: On the input adapter roaming is not enabled yet hence no need to
10909 * disable.
10910 *
10911 * Return: None
10912 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010913void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010914{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010915 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010916 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010917
10918 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010919 hdd_ctx->config->isRoamOffloadScanEnabled &&
10920 QDF_STA_MODE == adapter->device_mode &&
10921 policy_mgr_is_sta_active_connection_exists(
10922 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010923 hdd_debug("Connect received on STA session Id(%d)",
10924 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010925 /*
10926 * Loop through adapter and disable roaming for each STA device
10927 * mode except the input adapter.
10928 */
Dustin Brown920397d2017-12-13 16:27:50 -080010929 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010930 if (QDF_STA_MODE == adapterIdx->device_mode &&
10931 adapter->session_id != adapterIdx->session_id) {
10932 hdd_debug("Disable Roaming on session Id(%d)",
10933 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010934 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10935 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010936 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010937 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010938 }
10939 }
10940}
10941
10942/**
10943 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10944 * @adapter: HDD adapter pointer
10945 *
10946 * This function loop through each adapter and enable roaming on each STA
10947 * device mode except the input adapter.
10948 * Note: On the input adapter no need to enable roaming because link got
10949 * disconnected on this.
10950 *
10951 * Return: None
10952 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010953void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010954{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010955 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010956 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010957
10958 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010959 hdd_ctx->config->isRoamOffloadScanEnabled &&
10960 QDF_STA_MODE == adapter->device_mode &&
10961 policy_mgr_is_sta_active_connection_exists(
10962 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010963 hdd_debug("Disconnect received on STA session Id(%d)",
10964 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010965 /*
10966 * Loop through adapter and enable roaming for each STA device
10967 * mode except the input adapter.
10968 */
Dustin Brown920397d2017-12-13 16:27:50 -080010969 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010970 if (QDF_STA_MODE == adapterIdx->device_mode &&
10971 adapter->session_id != adapterIdx->session_id) {
10972 hdd_debug("Enabling Roaming on session Id(%d)",
10973 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010974 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10975 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010976 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010977 REASON_CONNECT);
10978 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010979 }
10980 }
10981}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010982
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010983/**
10984 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10985 * @skb: sk buffer pointer
10986 *
10987 * Sends the bcast message to SVC multicast group with generic nl socket
10988 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10989 *
10990 * Return: None
10991 */
10992static void nl_srv_bcast_svc(struct sk_buff *skb)
10993{
10994#ifdef CNSS_GENL
10995 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10996#else
10997 nl_srv_bcast(skb);
10998#endif
10999}
11000
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011001void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011002{
11003 struct sk_buff *skb;
11004 struct nlmsghdr *nlh;
11005 tAniMsgHdr *ani_hdr;
11006 void *nl_data = NULL;
11007 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011008 struct radio_index_tlv *radio_info;
11009 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011010
11011 if (in_interrupt() || irqs_disabled() || in_atomic())
11012 flags = GFP_ATOMIC;
11013
11014 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11015
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011016 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011017 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011018
11019 nlh = (struct nlmsghdr *)skb->data;
11020 nlh->nlmsg_pid = 0; /* from kernel */
11021 nlh->nlmsg_flags = 0;
11022 nlh->nlmsg_seq = 0;
11023 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11024
11025 ani_hdr = NLMSG_DATA(nlh);
11026 ani_hdr->type = type;
11027
11028 switch (type) {
11029 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011030 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011031 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011032 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011033 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011034 ani_hdr->length = 0;
11035 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011036 break;
11037 case WLAN_SVC_WLAN_STATUS_IND:
11038 case WLAN_SVC_WLAN_VERSION_IND:
11039 case WLAN_SVC_DFS_CAC_START_IND:
11040 case WLAN_SVC_DFS_CAC_END_IND:
11041 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11042 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11043 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011044 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011045 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011046 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011047 ani_hdr->length = len;
11048 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11049 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11050 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011051 break;
11052
11053 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011054 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011055 type);
11056 kfree_skb(skb);
11057 return;
11058 }
11059
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011060 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011061 * Add radio index at the end of the svc event in TLV format
11062 * to maintain the backward compatibility with userspace
11063 * applications.
11064 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011065
11066 tlv_len = 0;
11067
11068 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11069 < WLAN_NL_MAX_PAYLOAD) {
11070 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11071 sizeof(*ani_hdr) + len);
11072 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11073 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11074 radio_info->radio = radio;
11075 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011076 hdd_debug("Added radio index tlv - radio index %d",
11077 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011078 }
11079
11080 nlh->nlmsg_len += tlv_len;
11081 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11082
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011083 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011084}
11085
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011086#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11087void wlan_hdd_auto_shutdown_cb(void)
11088{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011089 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011090
11091 if (!hdd_ctx)
11092 return;
11093
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011094 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011095 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11096 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011097}
11098
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011099void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011100{
Jeff Johnson9d295242017-08-29 14:39:48 -070011101 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011102 bool ap_connected = false, sta_connected = false;
11103 tHalHandle hal_handle;
11104
11105 hal_handle = hdd_ctx->hHal;
11106 if (hal_handle == NULL)
11107 return;
11108
11109 if (hdd_ctx->config->WlanAutoShutdown == 0)
11110 return;
11111
11112 if (enable == false) {
11113 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011114 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011115 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011116 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011117 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011118 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011119 return;
11120 }
11121
11122 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011123 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11124 hdd_for_each_adapter(hdd_ctx, adapter) {
11125 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011126 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11127 conn_info.connState ==
11128 eConnectionState_Associated) {
11129 sta_connected = true;
11130 break;
11131 }
11132 }
Dustin Brown920397d2017-12-13 16:27:50 -080011133
11134 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011135 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011136 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011137 ap_connected = true;
11138 break;
11139 }
11140 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011141 }
11142 }
11143
11144 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011145 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011146 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011147 }
Jeff Johnson68755312017-02-10 11:46:55 -080011148
11149 if (sme_set_auto_shutdown_timer(hal_handle,
11150 hdd_ctx->config->WlanAutoShutdown)
11151 != QDF_STATUS_SUCCESS)
11152 hdd_err("Failed to start wlan auto shutdown timer");
11153 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011154 hdd_info("Auto Shutdown timer for %d seconds enabled",
11155 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011156}
11157#endif
11158
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011159struct hdd_adapter *
11160hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11161 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011162{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011163 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011164 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011165
11166 con_sap_adapter = NULL;
11167
Dustin Brown920397d2017-12-13 16:27:50 -080011168 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011169 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11170 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011171 adapter != this_sap_adapter) {
11172 if (check_start_bss) {
11173 if (test_bit(SOFTAP_BSS_STARTED,
11174 &adapter->event_flags)) {
11175 con_sap_adapter = adapter;
11176 break;
11177 }
11178 } else {
11179 con_sap_adapter = adapter;
11180 break;
11181 }
11182 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011183 }
11184
11185 return con_sap_adapter;
11186}
11187
11188#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011189static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011190{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011191 return adapter->device_mode == QDF_STA_MODE ||
11192 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011193}
11194
Jeff Johnson9d295242017-08-29 14:39:48 -070011195static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011196{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011197 return adapter->device_mode == QDF_SAP_MODE ||
11198 adapter->device_mode == QDF_P2P_GO_MODE;
11199}
11200
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011201static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011202{
Dustin Brown920397d2017-12-13 16:27:50 -080011203 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011204
Dustin Brown920397d2017-12-13 16:27:50 -080011205 hdd_for_each_adapter(hdd_ctx, adapter) {
11206 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011207 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11208 conn_info.connState == eConnectionState_Associated) {
11209 return true;
11210 }
11211
Dustin Brown920397d2017-12-13 16:27:50 -080011212 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011213 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011214 return true;
11215 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011216 }
11217
11218 return false;
11219}
11220
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011221static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011222{
11223 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011224
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011225 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011226 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011227 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011228
Dustin Brown5ec6b552017-03-31 12:11:40 -070011229 return is_running;
11230}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011231
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011232static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011233{
11234 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11235 hdd_ctx->bus_bw_timer_running = true;
11236 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11237 hdd_ctx->config->busBandwidthComputeInterval);
11238 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11239}
11240
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011241void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011242{
Dustin Brown491d54b2018-03-14 12:39:11 -070011243 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011244
11245 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11246 hdd_debug("Bandwidth compute timer already started");
11247 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011248 }
11249
Dustin Brown5ec6b552017-03-31 12:11:40 -070011250 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11251
Dustin Browne74003f2018-03-14 12:51:58 -070011252 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011253}
11254
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011255void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011256{
Dustin Brown491d54b2018-03-14 12:39:11 -070011257 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011258
11259 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11260 hdd_debug("Bandwidth compute timer already started");
11261 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011262 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011263
11264 if (hdd_any_adapter_is_assoc(hdd_ctx))
11265 __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 -070011270static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011271{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011272 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011273
11274 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11275 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11276 hdd_ctx->bus_bw_timer_running = false;
11277 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11278
11279 hdd_reset_tcp_delack(hdd_ctx);
11280}
11281
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011282void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011283{
Dustin Brown491d54b2018-03-14 12:39:11 -070011284 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011285
11286 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11287 hdd_debug("Bandwidth compute timer already stopped");
11288 return;
11289 }
11290
11291 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11292
Dustin Browne74003f2018-03-14 12:51:58 -070011293 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011294}
11295
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011296void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011297{
Dustin Brown491d54b2018-03-14 12:39:11 -070011298 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011299
11300 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11301 hdd_debug("Bandwidth compute timer already stopped");
11302 return;
11303 }
11304
11305 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11306 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11307
Dustin Browne74003f2018-03-14 12:51:58 -070011308 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011309}
11310#endif
11311
11312/**
11313 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11314 * and sta's operating channel.
11315 * @sta_adapter: Describe the first argument to foobar.
11316 * @ap_adapter: Describe the second argument to foobar.
11317 * @roam_profile: Roam profile of AP to which STA wants to connect.
11318 * @concurrent_chnl_same: If both SAP and STA channels are same then
11319 * set this flag to true else false.
11320 *
11321 * This function checks the sap's operating channel and sta's operating channel.
11322 * if both are same then it will return false else it will restart the sap in
11323 * sta's channel and return true.
11324 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011325 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011326 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011327QDF_STATUS
11328wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11329 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011330 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011331 tScanResultHandle *scan_cache,
11332 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011333{
Jeff Johnson87251032017-08-29 13:31:11 -070011334 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011335 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011336 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011337 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011338 *concurrent_chnl_same = true;
11339
11340 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11341 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011342 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011343 scan_cache,
11344 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011345 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011346 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011347 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011348 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011349 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011350 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011351 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011352 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011353 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011354 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011355 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011356 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011357 }
11358 }
11359 } else {
11360 /*
11361 * Lets handle worst case scenario here, Scan cache lookup is
11362 * failed so we have to stop the SAP to avoid any channel
11363 * discrepancy between SAP's channel and STA's channel.
11364 * Return the status as failure so caller function could know
11365 * that scan look up is failed.
11366 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011367 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011368 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011369 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011370 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011371}
11372
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011373/**
11374 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11375 * @ap_adapter: SAP adapter
11376 *
11377 * This function will process the stopping of sap adapter.
11378 *
11379 * Return: None
11380 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011381void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011382{
Jeff Johnson87251032017-08-29 13:31:11 -070011383 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011384 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011385 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011386 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011387
11388 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011389 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011390 return;
11391 }
11392
11393 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11394 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011395 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011396 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011397
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011398 mutex_lock(&hdd_ctx->sap_lock);
11399 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011400 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011401 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011402 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011403 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011404 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011405 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011406 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011407 qdf_stop_bss_event,
11408 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011409 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011410 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011411 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011412 return;
11413 }
11414 }
11415 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011416 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11417 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011418 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011419 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011420 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011421 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011422 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011423 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011424 }
11425 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011426}
11427
11428/**
11429 * wlan_hdd_start_sap() - this function starts bss of SAP.
11430 * @ap_adapter: SAP adapter
11431 *
11432 * This function will process the starting of sap adapter.
11433 *
11434 * Return: None
11435 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011436void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011437{
Jeff Johnson87251032017-08-29 13:31:11 -070011438 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011439 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011440 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011441 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011442 tsap_Config_t *sap_config;
11443
11444 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011445 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011446 return;
11447 }
11448
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011449 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011450 hdd_err("SoftAp role has not been enabled");
11451 return;
11452 }
11453
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011454 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11455 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11456 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011457 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011458
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011459 mutex_lock(&hdd_ctx->sap_lock);
11460 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11461 goto end;
11462
11463 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011464 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011465 goto end;
11466 }
11467
Wei Song2f76f642016-11-18 16:32:53 +080011468 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011469 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011470 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011471 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011472 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011473 goto end;
11474
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011475 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011476 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011477 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011478 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011479 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011480 goto end;
11481 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011482 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011483 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011484 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011485 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011486 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11487 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011488 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011489 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011490 true);
11491 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011492 mutex_unlock(&hdd_ctx->sap_lock);
11493
11494 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011495end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011496 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011497 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011498 /* SAP context and beacon cleanup will happen during driver unload
11499 * in hdd_stop_adapter
11500 */
11501 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11502
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011503}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011504
11505/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011506 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11507 * mac scan config
11508 * @status: Status of set antenna mode
11509 *
11510 * Callback on setting the dual mac configuration
11511 *
11512 * Return: None
11513 */
11514void wlan_hdd_soc_set_antenna_mode_cb(
11515 enum set_antenna_mode_status status)
11516{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011517 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011518
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011519 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011520
11521 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11522 if (0 != wlan_hdd_validate_context(hdd_ctx))
11523 return;
11524
11525 /* Signal the completion of set dual mac config */
11526 complete(&hdd_ctx->set_antenna_mode_cmpl);
11527}
11528
11529/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011530 * hdd_get_fw_version() - Get FW version
11531 * @hdd_ctx: pointer to HDD context.
11532 * @major_spid: FW version - major spid.
11533 * @minor_spid: FW version - minor spid
11534 * @ssid: FW version - ssid
11535 * @crmid: FW version - crmid
11536 *
11537 * This function is called to get the firmware build version stored
11538 * as part of the HDD context
11539 *
11540 * Return: None
11541 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011542void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011543 uint32_t *major_spid, uint32_t *minor_spid,
11544 uint32_t *siid, uint32_t *crmid)
11545{
11546 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11547 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11548 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11549 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11550}
11551
11552#ifdef QCA_CONFIG_SMP
11553/**
11554 * wlan_hdd_get_cpu() - get cpu_index
11555 *
11556 * Return: cpu_index
11557 */
11558int wlan_hdd_get_cpu(void)
11559{
11560 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011561
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011562 put_cpu();
11563 return cpu_index;
11564}
11565#endif
11566
11567/**
11568 * hdd_get_fwpath() - get framework path
11569 *
11570 * This function is used to get the string written by
11571 * userspace to start the wlan driver
11572 *
11573 * Return: string
11574 */
11575const char *hdd_get_fwpath(void)
11576{
11577 return fwpath.string;
11578}
11579
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011580static int hdd_qdf_print_init(void)
11581{
11582 int qdf_print_idx;
11583 QDF_STATUS status;
11584
11585 status = qdf_print_setup();
11586 if (status != QDF_STATUS_SUCCESS) {
11587 pr_err("qdf_print_setup failed\n");
11588 return -EINVAL;
11589 }
11590
11591 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11592
11593 if (qdf_print_idx < 0) {
11594 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11595 qdf_print_idx);
11596 return -EINVAL;
11597 }
11598
11599 qdf_set_pidx(qdf_print_idx);
11600
11601 return 0;
11602}
11603
11604static void hdd_qdf_print_deinit(void)
11605{
11606 int qdf_print_idx;
11607
11608 qdf_print_idx = qdf_get_pidx();
11609 qdf_print_ctrl_cleanup(qdf_print_idx);
11610}
11611
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011612/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011613 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011614 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011615 * This function initilizes CDS global context with the help of cds_init. This
11616 * has to be the first function called after probe to get a valid global
11617 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011618 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011619 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011620 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011621int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011622{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011623 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011624 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011625
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011626 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011627 if (QDF_IS_STATUS_ERROR(status)) {
11628 hdd_err("Failed to allocate CDS context");
11629 ret = -ENOMEM;
11630 goto err_out;
11631 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011632
11633 wlan_init_bug_report_lock();
11634
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011635#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11636 wlan_logging_sock_init_svc();
11637#endif
11638
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011639 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11640 (void *)hdd_drv_ops_inactivity_handler, NULL,
11641 QDF_TIMER_TYPE_SW);
11642
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011643 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011644 hdd_qdf_print_init();
11645
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011646 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011647
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011648err_out:
11649 return ret;
11650}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011651
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011652/**
11653 * hdd_deinit() - Deinitialize Driver
11654 *
11655 * This function frees CDS global context with the help of cds_deinit. This
11656 * has to be the last function call in remove callback to free the global
11657 * context.
11658 */
11659void hdd_deinit(void)
11660{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011661 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011662
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011663 wlan_destroy_bug_report_lock();
11664 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011665
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011666 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011667#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11668 wlan_logging_sock_deinit_svc();
11669#endif
11670}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011671
Yue Ma6e7b1a02017-04-03 14:17:46 -070011672#ifdef QCA_WIFI_NAPIER_EMULATION
11673#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11674#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011675#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011676#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011677
Sachin Ahujadddd2632017-03-07 19:07:24 +053011678static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11679 struct file *file)
11680{
11681 return 0;
11682}
11683
11684static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11685 const char __user *user_buf,
11686 size_t count,
11687 loff_t *f_pos)
11688{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011689 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011690 static const char wlan_off_str[] = "OFF";
11691 static const char wlan_on_str[] = "ON";
11692 int ret;
11693 unsigned long rc;
11694
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011695 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011696 pr_err("Failed to read buffer\n");
11697 return -EINVAL;
11698 }
11699
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011700 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011701 pr_debug("Wifi turning off from UI\n");
11702 goto exit;
11703 }
11704
Sachin Ahuja16904db2017-12-13 19:56:57 +053011705 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
11706 pr_info("Wifi Turning On from UI\n");
11707 }
11708
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011709 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011710 pr_err("Invalid value received from framework");
11711 goto exit;
11712 }
11713
11714 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011715 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011716 rc = wait_for_completion_timeout(&wlan_start_comp,
11717 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11718 if (!rc) {
11719 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11720 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053011721 return ret;
11722 }
11723
11724 hdd_start_complete(0);
11725 }
11726
11727exit:
11728 return count;
11729}
11730
11731
11732const struct file_operations wlan_hdd_state_fops = {
11733 .owner = THIS_MODULE,
11734 .open = wlan_hdd_state_ctrl_param_open,
11735 .write = wlan_hdd_state_ctrl_param_write,
11736};
11737
11738static int wlan_hdd_state_ctrl_param_create(void)
11739{
11740 unsigned int wlan_hdd_state_major = 0;
11741 int ret;
11742 struct device *dev;
11743
11744 device = MKDEV(wlan_hdd_state_major, 0);
11745
11746 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11747 if (ret) {
11748 pr_err("Failed to register qcwlanstate");
11749 goto dev_alloc_err;
11750 }
11751 wlan_hdd_state_major = MAJOR(device);
11752
11753 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11754 if (IS_ERR(class)) {
11755 pr_err("wlan_hdd_state class_create error");
11756 goto class_err;
11757 }
11758
11759 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11760 if (IS_ERR(dev)) {
11761 pr_err("wlan_hdd_statedevice_create error");
11762 goto err_class_destroy;
11763 }
11764
11765 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11766 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11767 if (ret) {
11768 pr_err("Failed to add cdev error");
11769 goto cdev_add_err;
11770 }
11771
11772 pr_info("wlan_hdd_state %s major(%d) initialized",
11773 WLAN_MODULE_NAME, wlan_hdd_state_major);
11774
11775 return 0;
11776
11777cdev_add_err:
11778 device_destroy(class, device);
11779err_class_destroy:
11780 class_destroy(class);
11781class_err:
11782 unregister_chrdev_region(device, dev_num);
11783dev_alloc_err:
11784 return -ENODEV;
11785}
11786
11787static void wlan_hdd_state_ctrl_param_destroy(void)
11788{
11789 cdev_del(&wlan_hdd_state_cdev);
11790 device_destroy(class, device);
11791 class_destroy(class);
11792 unregister_chrdev_region(device, dev_num);
11793
11794 pr_info("Device node unregistered");
11795}
11796
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011797/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011798 * component_init - API to init cld component's
11799 *
11800 * Return: None
11801 */
11802static void component_init(void)
11803{
11804 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011805 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011806 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011807 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011808}
11809
11810/**
11811 * component_deinit - API to deinit cld component's
11812 *
11813 * Return: None
11814 */
11815static void component_deinit(void)
11816{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011817 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011818 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011819 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011820 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011821}
11822
11823void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11824{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011825 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011826 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011827}
11828
11829void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11830{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011831 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011832 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011833}
11834
11835/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011836 * __hdd_module_init - Module init helper
11837 *
11838 * Module init helper function used by both module and static driver.
11839 *
11840 * Return: 0 for success, errno on failure
11841 */
11842static int __hdd_module_init(void)
11843{
11844 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011845
Dustin Brown96cd9632017-11-13 12:45:04 -080011846 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011847 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011848 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080011849 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011850
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011851 pld_init();
11852
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011853 ret = hdd_init();
11854 if (ret) {
11855 pr_err("hdd_init failed %x\n", ret);
11856 goto err_hdd_init;
11857 }
11858
Rajeev Kumar97767a02016-11-30 11:20:40 -080011859 dispatcher_init();
11860
Mukul Sharmad75a6672017-06-22 15:40:53 +053011861 /* Ensure to call post objmgr init */
11862 component_init();
11863
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011864 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011865
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011866 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011867
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011868 ret = wlan_hdd_register_driver();
11869 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011870 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11871 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011872 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011873 }
11874
Sachin Ahuja16904db2017-12-13 19:56:57 +053011875 ret = wlan_hdd_state_ctrl_param_create();
11876 if (ret) {
11877 pr_err("wlan_hdd_state_create:%x\n", ret);
11878 goto out;
11879 }
11880
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011881 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011882
11883 return 0;
11884out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011885 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011886 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011887 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011888 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011889
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011890err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011891 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011892 return ret;
11893}
11894
11895/**
11896 * __hdd_module_exit - Module exit helper
11897 *
11898 * Module exit helper function used by both module and static driver.
11899 */
11900static void __hdd_module_exit(void)
11901{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011902
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011903 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11904 QWLAN_VERSIONSTR);
11905
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011906 hdd_wait_for_recovery_completion();
11907
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011908 wlan_hdd_unregister_driver();
11909
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011910 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011911
Mukul Sharmad75a6672017-06-22 15:40:53 +053011912 /* Ensure to call prior to objmgr deinit */
11913 component_deinit();
11914
Rajeev Kumar97767a02016-11-30 11:20:40 -080011915 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011916
11917 hdd_sysfs_destroy_version_interface();
11918
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011919 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011920 pld_deinit();
11921
Sachin Ahujadddd2632017-03-07 19:07:24 +053011922 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011923}
11924
Arun Khandavallifae92942016-08-01 13:31:08 +053011925#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011926/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011927 * wlan_boot_cb() - Wlan boot callback
11928 * @kobj: object whose directory we're creating the link in.
11929 * @attr: attribute the user is interacting with
11930 * @buff: the buffer containing the user data
11931 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011932 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011933 * This callback is invoked when the fs is ready to start the
11934 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011935 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011936 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011937 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011938static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011939 struct kobj_attribute *attr,
11940 const char *buf,
11941 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011942{
Arun Khandavallifae92942016-08-01 13:31:08 +053011943
Arun Khandavallifae92942016-08-01 13:31:08 +053011944 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011945 pr_err("%s: wlan driver already initialized\n", __func__);
11946 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011947 }
11948
Arun Khandavallifae92942016-08-01 13:31:08 +053011949 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011950 pr_err("%s: wlan driver initialization failed\n", __func__);
11951 return -EIO;
11952 }
11953
11954 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011955
11956 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011957}
Arun Khandavallifae92942016-08-01 13:31:08 +053011958
11959/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011960 * hdd_sysfs_cleanup() - cleanup sysfs
11961 *
11962 * Return: None
11963 *
11964 */
11965static void hdd_sysfs_cleanup(void)
11966{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011967 /* remove from group */
11968 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11969 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11970 wlan_loader->attr_group);
11971
11972 /* unlink the object from parent */
11973 kobject_del(wlan_loader->boot_wlan_obj);
11974
11975 /* free the object */
11976 kobject_put(wlan_loader->boot_wlan_obj);
11977
11978 kfree(wlan_loader->attr_group);
11979 kfree(wlan_loader);
11980
11981 wlan_loader = NULL;
11982}
11983
11984/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011985 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11986 * ready
11987 *
11988 * This is creates the syfs entry boot_wlan. Which shall be invoked
11989 * when the filesystem is ready.
11990 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011991 * QDF API cannot be used here since this function is called even before
11992 * initializing WLAN driver.
11993 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011994 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011995 */
11996static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011997{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011998 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011999
12000 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012001 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012002 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012003
12004 wlan_loader->boot_wlan_obj = NULL;
12005 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12006 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012007 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012008 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012009
12010 wlan_loader->loaded_state = 0;
12011 wlan_loader->attr_group->attrs = attrs;
12012
12013 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12014 kernel_kobj);
12015 if (!wlan_loader->boot_wlan_obj) {
12016 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012017 goto error_return;
12018 }
12019
12020 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12021 wlan_loader->attr_group);
12022 if (ret) {
12023 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12024 goto error_return;
12025 }
12026
12027 return 0;
12028
12029error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012030 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012031
12032 return ret;
12033}
12034
12035/**
12036 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12037 *
12038 * Return: 0 on success or errno on failure
12039 */
12040static int wlan_deinit_sysfs(void)
12041{
Arun Khandavallifae92942016-08-01 13:31:08 +053012042 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012043 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012044 return -EINVAL;
12045 }
12046
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012047 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012048 return 0;
12049}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012050
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012051#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012052
12053#ifdef MODULE
12054/**
12055 * __hdd_module_init - Module init helper
12056 *
12057 * Module init helper function used by both module and static driver.
12058 *
12059 * Return: 0 for success, errno on failure
12060 */
12061static int hdd_module_init(void)
12062{
Arun Khandavallifae92942016-08-01 13:31:08 +053012063 if (__hdd_module_init()) {
12064 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012065 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012066 }
12067
Dustin Brownab482ac2017-06-09 17:00:44 -070012068 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012069}
12070#else
12071static int __init hdd_module_init(void)
12072{
12073 int ret = -EINVAL;
12074
12075 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012076 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012077 pr_err("Failed to create sysfs entry for loading wlan");
12078
12079 return ret;
12080}
12081#endif
12082
12083
12084#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012085/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012086 * hdd_module_exit() - Exit function
12087 *
12088 * This is the driver exit point (invoked when module is unloaded using rmmod)
12089 *
12090 * Return: None
12091 */
12092static void __exit hdd_module_exit(void)
12093{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012094 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012095}
Arun Khandavallifae92942016-08-01 13:31:08 +053012096#else
12097static void __exit hdd_module_exit(void)
12098{
12099 __hdd_module_exit();
12100 wlan_deinit_sysfs();
12101}
12102#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012103
Srinivas Girigowda841da292018-02-21 16:33:00 -080012104static int fwpath_changed_handler(const char *kmessage,
12105 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012106{
12107 return param_set_copystring(kmessage, kp);
12108}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012109
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012110/**
12111 * is_con_mode_valid() check con mode is valid or not
12112 * @mode: global con mode
12113 *
12114 * Return: TRUE on success FALSE on failure
12115 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012116static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012117{
12118 switch (mode) {
12119 case QDF_GLOBAL_MONITOR_MODE:
12120 case QDF_GLOBAL_FTM_MODE:
12121 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012122 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012123 return true;
12124 default:
12125 return false;
12126 }
12127}
12128
12129/**
12130 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12131 * @mode: global con mode
12132 *
12133 * Return: adapter mode
12134 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012135static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012136 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012137{
12138
12139 switch (mode) {
12140 case QDF_GLOBAL_MISSION_MODE:
12141 return QDF_STA_MODE;
12142 case QDF_GLOBAL_MONITOR_MODE:
12143 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012144 case QDF_GLOBAL_EPPING_MODE:
12145 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012146 case QDF_GLOBAL_FTM_MODE:
12147 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012148 case QDF_GLOBAL_QVIT_MODE:
12149 return QDF_QVIT_MODE;
12150 default:
12151 return QDF_MAX_NO_OF_MODE;
12152 }
12153}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012154
Dustin Brown27cd9942017-09-27 16:11:44 -070012155static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012156 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012157{
12158 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12159 return;
12160
12161 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012162 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012163 hdd_info("Release wakelock for monitor mode!");
12164 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12165 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12166 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012167 case QDF_GLOBAL_FTM_MODE:
12168 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012169 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012170 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012171
Dustin Brown27cd9942017-09-27 16:11:44 -070012172 break;
12173 default:
12174 break;
12175 }
12176}
12177
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012178static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012179 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012180{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012181 int driver_status;
12182
12183 driver_status = hdd_ctx->driver_status;
12184
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012185 switch (curr_mode) {
12186 case QDF_GLOBAL_MISSION_MODE:
12187 case QDF_GLOBAL_MONITOR_MODE:
12188 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012189 hdd_deinit_all_adapters(hdd_ctx, false);
12190 hdd_close_all_adapters(hdd_ctx, false);
12191 break;
12192 case QDF_GLOBAL_EPPING_MODE:
12193 epping_disable();
12194 epping_close();
12195 break;
12196 default:
12197 return;
12198 }
12199}
12200
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012201static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012202 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012203{
Jeff Johnson9d295242017-08-29 14:39:48 -070012204 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012205 int ret = 0;
12206 bool rtnl_held;
12207 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12208 QDF_STATUS status;
12209
12210 if (!qdf_dev) {
12211 hdd_err("qdf device context is Null return!");
12212 return -EINVAL;
12213 }
12214
12215 rtnl_held = hdd_hold_rtnl_lock();
12216 switch (mode) {
12217 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012218 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12219 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012220 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012221 break;
12222 case QDF_GLOBAL_FTM_MODE:
12223 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12224 wlan_hdd_get_intf_addr(hdd_ctx),
12225 NET_NAME_UNKNOWN, rtnl_held);
12226 if (adapter == NULL)
12227 ret = -EINVAL;
12228 break;
12229 case QDF_GLOBAL_MONITOR_MODE:
12230 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12231 wlan_hdd_get_intf_addr(hdd_ctx),
12232 NET_NAME_UNKNOWN, rtnl_held);
12233 if (adapter == NULL)
12234 ret = -EINVAL;
12235 break;
12236 case QDF_GLOBAL_EPPING_MODE:
12237 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012238 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012239 hdd_err("Failed to open in eeping mode: %d", status);
12240 ret = -EINVAL;
12241 break;
12242 }
12243 ret = epping_enable(qdf_dev->dev);
12244 if (ret) {
12245 hdd_err("Failed to enable in epping mode : %d", ret);
12246 epping_close();
12247 }
12248 break;
12249 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012250 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012251 ret = -ENOTSUPP;
12252 break;
12253 }
12254 hdd_release_rtnl_lock();
12255 rtnl_held = false;
12256 return ret;
12257}
12258
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012259/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012260 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012261 * @kmessage: con mode name on which driver to be bring up
12262 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012263 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012264 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012265 * This function is invoked when user updates con mode using sys entry,
12266 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012267 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012268 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012269 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012270static int __con_mode_handler(const char *kmessage,
12271 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012272 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012273{
12274 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012275 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012276 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012277 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012278 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012279
Dustin Brownab6029b2017-05-24 13:04:19 -070012280 hdd_info("con_mode handler: %s", kmessage);
12281
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012282 ret = wlan_hdd_validate_context(hdd_ctx);
12283 if (ret)
12284 return ret;
12285
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012286 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012287 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012288
Dustin Brown20024e32018-01-03 12:34:58 -080012289 ret = kstrtoint(kmessage, 0, &new_con_mode);
12290 if (ret) {
12291 hdd_err("Failed to parse con_mode '%s'", kmessage);
12292 goto reset_flags;
12293 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012294 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012295
Dustin Brown20024e32018-01-03 12:34:58 -080012296 if (!is_con_mode_valid(new_con_mode)) {
12297 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012298 ret = -EINVAL;
12299 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012300 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012301
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012302 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012303 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012304 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012305 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012306 ret = 0;
12307 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012308 }
12309
Dustin Brown27cd9942017-09-27 16:11:44 -070012310 /* ensure adapters are stopped */
12311 hdd_stop_present_mode(hdd_ctx, curr_mode);
12312
Frank Liu6666f832018-01-04 10:06:05 +080012313 /* Cleanup present mode before switching to new mode */
12314 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12315
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012316 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012317 if (ret) {
12318 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012319 goto reset_flags;
12320 }
12321
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012322
Dustin Brown20024e32018-01-03 12:34:58 -080012323 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012324
Frank Liu6666f832018-01-04 10:06:05 +080012325 /*
12326 * Set ACTIVE domain before adapters created, otherwise check domain
12327 * match will fail when cleanup adapters.
12328 */
12329 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012330 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012331 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012332 if (ret) {
12333 hdd_err("Failed to register for new mode");
12334 goto reset_flags;
12335 }
12336
Dustin Brown20024e32018-01-03 12:34:58 -080012337 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012338 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12339 hdd_err("invalid adapter");
12340 ret = -EINVAL;
12341 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012342 }
12343
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012344 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012345 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012346 hdd_err("Failed to get adapter:%d", adapter_mode);
12347 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012348 }
12349
12350 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12351 if (ret) {
12352 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012353 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012354 }
12355
Dustin Brown20024e32018-01-03 12:34:58 -080012356 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012357 if (hdd_start_adapter(adapter)) {
12358 hdd_err("Failed to start %s adapter", kmessage);
12359 ret = -EINVAL;
12360 goto reset_flags;
12361 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012362
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012363 hdd_info("Acquire wakelock for monitor mode!");
12364 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12365 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12366 }
12367
Dustin Brown20024e32018-01-03 12:34:58 -080012368 /* con_mode is a global module parameter */
12369 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012370 hdd_info("Mode successfully changed to %s", kmessage);
12371 ret = 0;
12372
12373reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012374 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012375 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012376 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012377 return ret;
12378}
12379
12380
Srinivas Girigowda841da292018-02-21 16:33:00 -080012381static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012382{
12383 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012384 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012385
12386 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12387 ret = wlan_hdd_validate_context(hdd_ctx);
12388 if (ret)
12389 return ret;
12390
12391 cds_ssr_protect(__func__);
12392 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12393 cds_ssr_unprotect(__func__);
12394
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012395 return ret;
12396}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012397
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012398static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012399 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012400{
12401 int ret;
12402
12403 ret = param_set_int(kmessage, kp);
12404
12405 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12406 pr_err("Only FTM mode supported!");
12407 return -ENOTSUPP;
12408 }
12409
12410 hdd_set_conparam(con_mode_ftm);
12411 con_mode = con_mode_ftm;
12412
12413 return ret;
12414}
12415
Ravi Joshia307f632017-07-17 23:41:41 -070012416static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012417 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012418{
12419 int ret;
12420
12421 ret = param_set_int(kmessage, kp);
12422
12423 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12424 pr_err("Only Monitor mode supported!");
12425 return -ENOTSUPP;
12426 }
12427
12428 hdd_set_conparam(con_mode_monitor);
12429 con_mode = con_mode_monitor;
12430
12431 return ret;
12432}
12433
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012434/**
12435 * hdd_get_conparam() - driver exit point
12436 *
12437 * This is the driver exit point (invoked when module is unloaded using rmmod)
12438 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012439 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012440 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012441enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012442{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012443 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012444}
12445
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012446void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012447{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012448 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012449}
12450
Komal Seelamc11bb222016-01-27 18:57:10 +053012451/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012452 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12453 * @hdd_ctx: HDD context
12454 *
12455 * Cleans up the pre cac interface, if it exists
12456 *
12457 * Return: None
12458 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012459void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012460{
12461 uint8_t session_id;
12462 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012463 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012464
12465 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12466 if (QDF_IS_STATUS_ERROR(status)) {
12467 hdd_err("failed to get pre cac vdev id");
12468 return;
12469 }
12470
12471 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12472 if (!precac_adapter) {
12473 hdd_err("invalid pre cac adapater");
12474 return;
12475 }
12476
12477 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12478 wlan_hdd_sap_pre_cac_failure,
12479 (void *)precac_adapter);
12480 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12481
12482}
12483
12484/**
Komal Seelamec702b02016-02-24 18:42:16 +053012485 * hdd_update_ol_config - API to update ol configuration parameters
12486 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012487 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012488 * Return: void
12489 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012490static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012491{
Komal Seelamec702b02016-02-24 18:42:16 +053012492 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012493 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012494
Komal Seelamec702b02016-02-24 18:42:16 +053012495 if (!ol_ctx)
12496 return;
12497
12498 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12499 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12500 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12501 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012502 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012503
12504 ol_init_ini_config(ol_ctx, &cfg);
12505}
12506
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012507#ifdef FEATURE_RUNTIME_PM
12508/**
12509 * hdd_populate_runtime_cfg() - populate runtime configuration
12510 * @hdd_ctx: hdd context
12511 * @cfg: pointer to the configuration memory being populated
12512 *
12513 * Return: void
12514 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012515static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012516 struct hif_config_info *cfg)
12517{
12518 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12519 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12520}
12521#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012522static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012523 struct hif_config_info *cfg)
12524{
12525}
12526#endif
12527
Komal Seelamec702b02016-02-24 18:42:16 +053012528/**
12529 * hdd_update_hif_config - API to update HIF configuration parameters
12530 * @hdd_ctx: HDD Context
12531 *
12532 * Return: void
12533 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012534static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012535{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012536 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012537 struct hif_config_info cfg;
12538
12539 if (!scn)
12540 return;
12541
12542 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012543 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012544 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012545
12546 if (hdd_ctx->config->prevent_link_down)
12547 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012548}
12549
12550/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012551 * hdd_update_dp_config() - Propagate config parameters to Lithium
12552 * datapath
12553 * @hdd_ctx: HDD Context
12554 *
12555 * Return: 0 for success/errno for failure
12556 */
12557static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12558{
12559 struct cdp_config_params params;
12560 QDF_STATUS status;
12561
12562 params.tso_enable = hdd_ctx->config->tso_enable;
12563 params.lro_enable = hdd_ctx->config->lro_enable;
12564#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12565 params.tx_flow_stop_queue_threshold =
12566 hdd_ctx->config->TxFlowStopQueueThreshold;
12567 params.tx_flow_start_queue_offset =
12568 hdd_ctx->config->TxFlowStartQueueOffset;
12569#endif
12570 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12571 params.napi_enable = hdd_ctx->napi_enable;
12572 params.tcp_udp_checksumoffload =
12573 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12574
12575 status = cdp_update_config_parameters(
12576 cds_get_context(QDF_MODULE_ID_SOC),
12577 &params);
12578 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012579 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012580 return status;
12581 }
12582
12583 return 0;
12584}
12585
12586/**
Komal Seelamec702b02016-02-24 18:42:16 +053012587 * hdd_update_config() - Initialize driver per module ini parameters
12588 * @hdd_ctx: HDD Context
12589 *
12590 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012591 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012592 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012593int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012594{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012595 int ret;
12596
Komal Seelamec702b02016-02-24 18:42:16 +053012597 hdd_update_ol_config(hdd_ctx);
12598 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012599 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12600 ret = hdd_update_cds_config_ftm(hdd_ctx);
12601 else
12602 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012603 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012604
12605 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012606}
12607
Mukul Sharma9d797a02017-01-05 20:26:03 +053012608#ifdef FEATURE_WLAN_RA_FILTERING
12609/**
12610 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12611 * @psoc_cfg: pmo psoc Configuration
12612 * @hdd_ctx: Pointer to hdd context
12613 *
12614 * Return: none
12615 */
12616static inline void hdd_ra_populate_pmo_config(
12617 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012618 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012619{
12620 psoc_cfg->ra_ratelimit_interval =
12621 hdd_ctx->config->RArateLimitInterval;
12622 psoc_cfg->ra_ratelimit_enable =
12623 hdd_ctx->config->IsRArateLimitEnabled;
12624}
12625#else
12626static inline void hdd_ra_populate_pmo_config(
12627 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012628 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012629{
12630}
12631#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012632
Mukul Sharma9d797a02017-01-05 20:26:03 +053012633/**
12634 * hdd_update_pmo_config - API to update pmo configuration parameters
12635 * @hdd_ctx: HDD context
12636 *
12637 * Return: void
12638 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012639static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012640{
Mukul Sharma9d797a02017-01-05 20:26:03 +053012641 struct pmo_psoc_cfg psoc_cfg;
12642 QDF_STATUS status;
12643
12644 /*
12645 * Value of hdd_ctx->wowEnable can be,
12646 * 0 - Disable both magic pattern match and pattern byte match.
12647 * 1 - Enable magic pattern match on all interfaces.
12648 * 2 - Enable pattern byte match on all interfaces.
12649 * 3 - Enable both magic patter and pattern byte match on
12650 * all interfaces.
12651 */
12652 psoc_cfg.magic_ptrn_enable =
12653 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12654 psoc_cfg.ptrn_match_enable_all_vdev =
12655 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080012656 psoc_cfg.ptrn_id_per_vdev =
12657 wma_is_service_enabled(wmi_service_unified_wow_capability);
12658 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012659 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012660 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080012661 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012662 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080012663 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012664 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12665 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080012666 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012667 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012668 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053012669 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12670 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12671 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080012672 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012673 psoc_cfg.auto_power_save_fail_mode =
12674 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012675
12676 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012677 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12678 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012679
Dustin Brownb9987af2018-03-01 17:15:11 -080012680 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
12681 if (QDF_IS_STATUS_ERROR(status))
12682 hdd_err("failed pmo psoc configuration; status:%d", status);
12683
12684 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012685}
12686
Abhishek Singhb20db962017-03-03 21:28:46 +053012687#ifdef FEATURE_WLAN_SCAN_PNO
12688static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12689 struct hdd_config *cfg)
12690{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012691 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12692
Abhishek Singhb20db962017-03-03 21:28:46 +053012693 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12694 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12695 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12696 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12697 pno_cfg->channel_prediction_full_scan =
12698 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012699 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12700 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12701 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12702 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012703}
12704#else
12705static inline void
12706hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012707 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012708{
Abhishek Singhb20db962017-03-03 21:28:46 +053012709}
12710#endif
12711
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012712void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12713 struct hdd_config *cfg)
12714{
12715 uint8_t i = 0;
12716
12717 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12718 if (!ie_whitelist->white_list)
12719 return;
12720
12721 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12722 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12723 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12724 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12725 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12726 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12727 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12728 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12729
12730 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12731 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12732 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12733}
12734
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012735uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12736{
12737 uint8_t i, score;
12738
12739 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12740 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12741 if (score > MAX_INDEX_SCORE)
12742 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12743 MAX_INDEX_SCORE, i);
12744 }
12745
12746 return per_index_score;
12747}
12748
12749/**
12750 * hdd_update_score_config - API to update candidate scoring related params
12751 * configuration parameters
12752 * @score_config: score config to update
12753 * @cfg: config params
12754 *
12755 * Return: 0 if success else err
12756 */
12757static void hdd_update_score_config(
12758 struct scoring_config *score_config, struct hdd_config *cfg)
12759{
12760 int total_weight;
12761
12762 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12763 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12764 score_config->weight_cfg.vht_caps_weightage =
12765 cfg->vht_caps_weightage;
12766 score_config->weight_cfg.he_caps_weightage =
12767 cfg->he_caps_weightage;
12768 score_config->weight_cfg.chan_width_weightage =
12769 cfg->chan_width_weightage;
12770 score_config->weight_cfg.chan_band_weightage =
12771 cfg->chan_band_weightage;
12772 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12773 score_config->weight_cfg.beamforming_cap_weightage =
12774 cfg->beamforming_cap_weightage;
12775 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12776 score_config->weight_cfg.channel_congestion_weightage =
12777 cfg->channel_congestion_weightage;
12778 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12779
12780 total_weight = score_config->weight_cfg.rssi_weightage +
12781 score_config->weight_cfg.ht_caps_weightage +
12782 score_config->weight_cfg.vht_caps_weightage +
12783 score_config->weight_cfg.he_caps_weightage +
12784 score_config->weight_cfg.chan_width_weightage +
12785 score_config->weight_cfg.chan_band_weightage +
12786 score_config->weight_cfg.nss_weightage +
12787 score_config->weight_cfg.beamforming_cap_weightage +
12788 score_config->weight_cfg.pcl_weightage +
12789 score_config->weight_cfg.channel_congestion_weightage +
12790 score_config->weight_cfg.oce_wan_weightage;
12791
12792 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12793 hdd_err("total weight is greater than %d fallback to default values",
12794 BEST_CANDIDATE_MAX_WEIGHT);
12795
12796 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12797 score_config->weight_cfg.ht_caps_weightage =
12798 HT_CAPABILITY_WEIGHTAGE;
12799 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12800 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12801 score_config->weight_cfg.chan_width_weightage =
12802 CHAN_WIDTH_WEIGHTAGE;
12803 score_config->weight_cfg.chan_band_weightage =
12804 CHAN_BAND_WEIGHTAGE;
12805 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12806 score_config->weight_cfg.beamforming_cap_weightage =
12807 BEAMFORMING_CAP_WEIGHTAGE;
12808 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12809 score_config->weight_cfg.channel_congestion_weightage =
12810 CHANNEL_CONGESTION_WEIGHTAGE;
12811 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12812 }
12813
12814 score_config->bandwidth_weight_per_index =
12815 hdd_limit_max_per_index_score(
12816 cfg->bandwidth_weight_per_index);
12817 score_config->nss_weight_per_index =
12818 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12819 score_config->band_weight_per_index =
12820 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12821
12822 score_config->rssi_score.best_rssi_threshold =
12823 cfg->best_rssi_threshold;
12824 score_config->rssi_score.good_rssi_threshold =
12825 cfg->good_rssi_threshold;
12826 score_config->rssi_score.bad_rssi_threshold =
12827 cfg->bad_rssi_threshold;
12828 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12829 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12830 score_config->rssi_score.good_rssi_bucket_size =
12831 cfg->good_rssi_bucket_size;
12832 score_config->rssi_score.bad_rssi_bucket_size =
12833 cfg->bad_rssi_bucket_size;
12834 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12835 cfg->rssi_pref_5g_rssi_thresh;
12836
12837 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12838 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12839 hdd_limit_max_per_index_score(
12840 cfg->esp_qbss_score_slots3_to_0);
12841 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12842 hdd_limit_max_per_index_score(
12843 cfg->esp_qbss_score_slots7_to_4);
12844 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12845 hdd_limit_max_per_index_score(
12846 cfg->esp_qbss_score_slots11_to_8);
12847 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12848 hdd_limit_max_per_index_score(
12849 cfg->esp_qbss_score_slots15_to_12);
12850
12851 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12852 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12853 hdd_limit_max_per_index_score(
12854 cfg->oce_wan_score_slots3_to_0);
12855 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12856 hdd_limit_max_per_index_score(
12857 cfg->oce_wan_score_slots7_to_4);
12858 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12859 hdd_limit_max_per_index_score(
12860 cfg->oce_wan_score_slots11_to_8);
12861 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12862 hdd_limit_max_per_index_score(
12863 cfg->oce_wan_score_slots15_to_12);
12864
12865
12866 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12867 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12868 score_config->nss = cfg->enable2x2 ? 2 : 1;
12869
12870 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12871 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12872 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12873 score_config->he_cap = 1;
12874
12875 if (score_config->he_cap ||
12876 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12877 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12878 score_config->vht_cap = 1;
12879
12880 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12881 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12882 score_config->ht_cap = 1;
12883
12884 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12885 score_config->vht_24G_cap = 1;
12886
12887 if (cfg->enableTxBF)
12888 score_config->beamformee_cap = 1;
12889
12890}
12891
Abhishek Singh257a9482017-03-06 16:52:39 +053012892/**
bings81fe50a2017-11-27 14:33:26 +080012893 * hdd_update_dfs_config() - API to update dfs configuration parameters.
12894 * @hdd_ctx: HDD context
12895 *
12896 * Return: 0 if success else err
12897 */
12898static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
12899{
12900 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12901 struct hdd_config *cfg = hdd_ctx->config;
12902 struct dfs_user_config dfs_cfg;
12903 QDF_STATUS status;
12904
12905 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
12906 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
12907 if (QDF_IS_STATUS_ERROR(status)) {
12908 hdd_err("failed dfs psoc configuration");
12909 return -EINVAL;
12910 }
12911
12912 return 0;
12913}
12914
12915/**
Abhishek Singh257a9482017-03-06 16:52:39 +053012916 * hdd_update_scan_config - API to update scan configuration parameters
12917 * @hdd_ctx: HDD context
12918 *
12919 * Return: 0 if success else err
12920 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012921static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012922{
12923 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12924 struct scan_user_cfg scan_cfg;
12925 struct hdd_config *cfg = hdd_ctx->config;
12926 QDF_STATUS status;
12927
12928 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12929 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12930 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12931 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12932 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12933 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12934 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012935 /* convert to ms */
12936 scan_cfg.scan_cache_aging_time =
12937 cfg->scanAgingTimeout * 1000;
12938 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12939 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12940 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12941 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012942 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012943 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012944 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12945 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012946 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012947 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053012948 scan_cfg.sta_miracast_mcc_rest_time =
12949 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053012950
Abhishek Singhb20db962017-03-03 21:28:46 +053012951 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012952 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012953 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012954
Abhishek Singh257a9482017-03-06 16:52:39 +053012955 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12956 if (status != QDF_STATUS_SUCCESS) {
12957 hdd_err("failed pmo psoc configuration");
12958 return -EINVAL;
12959 }
12960
12961 return 0;
12962}
Abhishek Singh257a9482017-03-06 16:52:39 +053012963
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012964int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012965{
12966 int ret;
12967
12968 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012969 if (ret)
12970 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012971
Abhishek Singh257a9482017-03-06 16:52:39 +053012972 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012973 if (ret)
12974 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012975
Frank Liud4b2fa02017-03-29 11:46:48 +080012976 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012977 if (ret)
12978 return ret;
12979
12980 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080012981 if (ret)
12982 return ret;
12983
12984 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012985
12986 return ret;
12987}
12988
Agrawal Ashish65634612016-08-18 13:24:32 +053012989/**
12990 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12991 * @mode : cfg80211 DFS mode
12992 *
12993 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12994 */
12995enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12996{
12997 switch (mode) {
12998 case DFS_MODE_ENABLE:
12999 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013000 case DFS_MODE_DISABLE:
13001 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013002 case DFS_MODE_DEPRIORITIZE:
13003 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013004 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013005 hdd_debug("ACS dfs mode is NONE");
13006 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013007 }
13008}
13009
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013010/**
13011 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13012 * @hddctx: pointer to hdd context
13013 * @set_value: enable/disable
13014 *
13015 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13016 * Host(even though it is duplicate). When Host send vendor command
13017 * disable,FW doesn't perform any action. Whenever any change in
13018 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13019 *
13020 * return - 0 on success, appropriate error values on failure.
13021 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013022int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013023{
13024 QDF_STATUS status;
13025
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013026 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013027 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013028
13029 if (!hddctx->config->goptimize_chan_avoid_event) {
13030 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13031 return -EINVAL;
13032 }
13033
13034 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13035 if (!QDF_IS_STATUS_SUCCESS(status)) {
13036 hdd_err("Failed to send chan avoid command to SME");
13037 return -EINVAL;
13038 }
13039 return 0;
13040}
Agrawal Ashish65634612016-08-18 13:24:32 +053013041
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013042/**
13043 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13044 * @value: value to set
13045 *
13046 * This function will set the passed value to roaming in progress flag.
13047 *
13048 * Return: None
13049 */
13050void hdd_set_roaming_in_progress(bool value)
13051{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013052 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013053
13054 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13055 if (!hdd_ctx) {
13056 hdd_err("HDD context is NULL");
13057 return;
13058 }
13059
13060 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013061 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013062}
13063
13064/**
13065 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013066 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013067 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013068 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013069 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013070bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013071{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013072 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013073 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013074
13075 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13076 if (!hdd_ctx) {
13077 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013078 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013079 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013080 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13081 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013082 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13083 hdd_ctx->roaming_in_progress);
13084
13085 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013086}
13087
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013088/**
13089 * hdd_is_connection_in_progress() - check if connection is in
13090 * progress
13091 * @session_id: session id
13092 * @reason: scan reject reason
13093 *
13094 * Go through each adapter and check if Connection is in progress
13095 *
13096 * Return: true if connection is in progress else false
13097 */
13098bool hdd_is_connection_in_progress(uint8_t *session_id,
13099 enum scan_reject_states *reason)
13100{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013101 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013102 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013103 uint8_t sta_id = 0;
13104 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013105 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013106
13107 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13108 if (!hdd_ctx) {
13109 hdd_err("HDD context is NULL");
13110 return false;
13111 }
13112
Dustin Brown920397d2017-12-13 16:27:50 -080013113 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013114 hdd_info("Adapter with device mode %s(%d) exists",
13115 hdd_device_mode_to_string(adapter->device_mode),
13116 adapter->device_mode);
13117 if (((QDF_STA_MODE == adapter->device_mode)
13118 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13119 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13120 && (eConnectionState_Connecting ==
13121 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13122 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013123 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013124 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013125 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013126 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013127 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013128 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013129 }
13130 return true;
13131 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013132 /*
13133 * sme_neighbor_middle_of_roaming is for LFR2
13134 * hdd_is_roaming_in_progress is for LFR3
13135 */
13136 if (((QDF_STA_MODE == adapter->device_mode) &&
13137 sme_neighbor_middle_of_roaming(
13138 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013139 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013140 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013141 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013142 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013143 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013144 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013145 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013146 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013147 }
13148 return true;
13149 }
13150 if ((QDF_STA_MODE == adapter->device_mode) ||
13151 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13152 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13153 hdd_sta_ctx =
13154 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13155 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013156 hdd_sta_ctx->conn_info.connState)
13157 && sme_is_sta_key_exchange_in_progress(
13158 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013159 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013160 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013161 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013162 " is in middle of WPS/EAPOL exchange.",
13163 MAC_ADDR_ARRAY(sta_mac));
13164 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013165 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013166 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013167 }
13168 return true;
13169 }
13170 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13171 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13172 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13173 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013174 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013175 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013176 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013177 continue;
13178
13179 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013180 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013181 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013182 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013183 " of SAP/GO is in middle of WPS/EAPOL exchange",
13184 MAC_ADDR_ARRAY(sta_mac));
13185 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013186 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013187 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013188 }
13189 return true;
13190 }
13191 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013192 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013193 return true;
13194 }
13195 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013196 }
Dustin Brown920397d2017-12-13 16:27:50 -080013197
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013198 return false;
13199}
13200
13201/**
13202 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013203 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013204 *
13205 * Return: None
13206 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013207void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013208{
Jeff Johnson87251032017-08-29 13:31:11 -070013209 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013210 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013211 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013212 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013213 tsap_Config_t *sap_config;
13214 void *sap_ctx;
13215
13216 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013217 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013218 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013219
13220 mutex_lock(&hdd_ctx->sap_lock);
13221 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13222 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013223 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13224 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13225 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13226 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013227 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013228 qdf_stop_bss_event,
13229 SME_CMD_TIMEOUT_VALUE);
13230
13231 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013232 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013233 goto end;
13234 }
13235 }
13236 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013237 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013238 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013239 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013240 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013241 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013242
13243 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013244 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013245 wlansap_reset_sap_config_add_ie(sap_config,
13246 eUPDATE_IE_ALL);
13247 goto end;
13248 }
13249
13250 qdf_event_reset(&hostapd_state->qdf_event);
13251 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13252 sap_config,
13253 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013254 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013255 wlansap_reset_sap_config_add_ie(sap_config,
13256 eUPDATE_IE_ALL);
13257 goto end;
13258 }
13259
Jeff Johnson6867ec32017-09-29 20:30:20 -070013260 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013261 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013262 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013263 SME_CMD_TIMEOUT_VALUE);
13264 wlansap_reset_sap_config_add_ie(sap_config,
13265 eUPDATE_IE_ALL);
13266 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013267 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013268 goto end;
13269 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013270 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013271 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013272 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013273 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13274 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013275 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013276 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013277 ap_adapter->device_mode,
13278 true);
13279 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013280 }
13281end:
13282 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013283}
13284
13285/**
13286 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13287 * with non dfs acs
13288 *
13289 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13290 *
13291 * Return: None
13292 */
13293void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13294{
Jeff Johnson9d295242017-08-29 14:39:48 -070013295 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013296 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013297 cds_context_type *cds_ctx;
13298
13299 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13300 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013301 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013302 return;
13303 }
13304
13305 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13306 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013307 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013308 return;
13309 }
13310
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013311 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13312 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013313 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013314 return;
13315 }
13316
13317 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013318 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13319 &ap_adapter->event_flags) &&
13320 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013321 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013322
Jeff Johnson6867ec32017-09-29 20:30:20 -070013323 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013324 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013325 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013326 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013327 acs_cfg.acs_mode = true;
13328
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013329 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013330 }
13331}
13332
13333/**
13334 * hdd_set_connection_in_progress() - to set the connection in
13335 * progress flag
13336 * @value: value to set
13337 *
13338 * This function will set the passed value to connection in progress flag.
13339 * If value is previously being set to true then no need to set it again.
13340 *
13341 * Return: true if value is being set correctly and false otherwise.
13342 */
13343bool hdd_set_connection_in_progress(bool value)
13344{
13345 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013346 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013347
13348 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13349 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013350 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013351 return false;
13352 }
13353
13354 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13355 /*
13356 * if the value is set to true previously and if someone is
13357 * trying to make it true again then it could be some race
13358 * condition being triggered. Avoid this situation by returning
13359 * false
13360 */
13361 if (hdd_ctx->connection_in_progress && value)
13362 status = false;
13363 else
13364 hdd_ctx->connection_in_progress = value;
13365 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13366 return status;
13367}
13368
Jeff Johnson9d295242017-08-29 14:39:48 -070013369int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013370{
13371 if (!adapter) {
13372 hdd_err("Invalid adapter");
13373 return -EINVAL;
13374 }
13375 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013376 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013377 WMA_VDEV_MCC_SET_TIME_QUOTA,
13378 set_value, VDEV_CMD);
13379 return 0;
13380
13381}
13382
Jeff Johnson9d295242017-08-29 14:39:48 -070013383int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013384{
13385 if (!adapter) {
13386 hdd_err("Invalid adapter");
13387 return -EINVAL;
13388 }
13389
13390 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013391 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013392 WMA_VDEV_MCC_SET_TIME_LATENCY,
13393 set_value, VDEV_CMD);
13394 return 0;
13395}
13396
Jeff Johnson9d295242017-08-29 14:39:48 -070013397struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013398 *psoc, uint8_t vdev_id)
13399{
Jeff Johnson9d295242017-08-29 14:39:48 -070013400 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013401 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013402
13403 /*
13404 * Currently PSOC is not being used. But this logic will
13405 * change once we have the converged implementation of
13406 * HDD context per PSOC in place. This would break if
13407 * multiple vdev objects reuse the vdev id.
13408 */
13409 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13410 if (!adapter)
13411 hdd_err("Get adapter by vdev id failed");
13412
13413 return adapter;
13414}
13415
Jeff Johnson9d295242017-08-29 14:39:48 -070013416int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013417 int8_t *rssi, int8_t *snr)
13418{
13419 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013420 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013421
Jeff Johnson025618c2018-03-18 14:41:00 -070013422 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013423 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013424 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013425 if (QDF_STATUS_SUCCESS != status) {
13426 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13427 return -EINVAL;
13428 }
13429
13430 return 0;
13431}
13432
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013433/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013434 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13435 * @adapter - HDD adapter
13436 * @tos - type of service
13437 * @status - status of the traffic
13438 *
13439 * Return: 0 on success and non zero value on failure
13440 */
13441
13442int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13443 bool is_tos_active)
13444{
13445 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013446 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013447 uint32_t max_off_chan_time = 0;
13448 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013449 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013450 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013451
13452 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13453 ret = wlan_hdd_validate_context(hdd_ctx);
13454
13455 if (ret < 0) {
13456 hdd_err("failed to set limit off chan params");
13457 return ret;
13458 }
13459
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013460 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13461
13462 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013463 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013464 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013465 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013466
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013467 if (adapter->active_ac) {
13468 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013469 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013470 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13471 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13472 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013473 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013474 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013475 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13476 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13477 PM_LATENCY);
13478 } else {
13479 /*ignore this command if only BE/BK is active */
13480 is_tos_active = false;
13481 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13482 hdd_ctx->config->conc_system_pref);
13483 }
13484 } else {
13485 /* No active tos */
13486 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13487 hdd_ctx->config->conc_system_pref);
13488 }
13489
Jeff Johnson1b780e42017-10-31 14:11:45 -070013490 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013491 is_tos_active, max_off_chan_time,
13492 hdd_ctx->config->nRestTimeConc, true);
13493 if (!QDF_IS_STATUS_SUCCESS(status)) {
13494 hdd_err("failed to set limit off chan params");
13495 ret = -EINVAL;
13496 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013497
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013498 return ret;
13499}
13500
13501/**
13502 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13503 * @adapter - HDD adapter
13504 *
13505 * Return: 0 on success and non zero value on failure
13506 */
13507int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13508{
13509 struct hdd_context *hdd_ctx;
13510 int ret;
13511 QDF_STATUS status;
13512 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13513
13514 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13515 ret = wlan_hdd_validate_context(hdd_ctx);
13516 if (ret < 0)
13517 return ret;
13518
13519 /* set the system preferece to default */
13520 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13521 hdd_ctx->config->conc_system_pref);
13522
13523 /* clear the bitmap */
13524 adapter->active_ac = 0;
13525
13526 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013527 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013528
Jeff Johnson1b780e42017-10-31 14:11:45 -070013529 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013530 false, 0, 0, false);
13531 if (!QDF_IS_STATUS_SUCCESS(status)) {
13532 hdd_err("failed to reset limit off chan params");
13533 ret = -EINVAL;
13534 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013535
13536 return ret;
13537}
13538
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013539/**
13540 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13541 * @drv_op: Enum indicating driver op
13542 *
13543 * Return: none
13544 */
13545void hdd_start_driver_ops_timer(int drv_op)
13546{
13547 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13548 switch (drv_op) {
13549 case eHDD_DRV_OP_PROBE:
13550 memcpy(drv_ops_string, "probe", sizeof("probe"));
13551 break;
13552 case eHDD_DRV_OP_REMOVE:
13553 memcpy(drv_ops_string, "remove", sizeof("remove"));
13554 break;
13555 case eHDD_DRV_OP_SHUTDOWN:
13556 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13557 break;
13558 case eHDD_DRV_OP_REINIT:
13559 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13560 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013561 case eHDD_DRV_OP_IFF_UP:
13562 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13563 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013564 }
13565
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013566 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013567 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13568 HDD_OPS_INACTIVITY_TIMEOUT);
13569}
13570
13571/**
13572 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13573 *
13574 * Return: none
13575 */
13576void hdd_stop_driver_ops_timer(void)
13577{
13578 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13579}
13580
13581/**
13582 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13583 * inactivity timer
13584 *
13585 * Return: None
13586 */
13587void hdd_drv_ops_inactivity_handler(void)
13588{
13589 hdd_err("%s: %d Sec timer expired while in .%s",
13590 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13591
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013592 if (hdd_drv_ops_task) {
13593 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13594 qdf_print_thread_trace(hdd_drv_ops_task);
13595 } else {
13596 hdd_err("hdd_drv_ops_task is null");
13597 }
13598
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013599 /* Driver shutdown is stuck, no recovery possible at this point */
13600 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13601 sizeof("shutdown")))
13602 QDF_BUG(0);
13603
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013604 if (cds_is_fw_down()) {
13605 hdd_err("FW is down");
13606 return;
13607 }
13608
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013609 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013610 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013611 else
13612 QDF_BUG(0);
13613}
13614
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013615void hdd_pld_ipa_uc_shutdown_pipes(void)
13616{
13617 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13618
13619 if (!hdd_ctx)
13620 return;
13621
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053013622 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013623}
13624
Yun Parkff6a16a2017-09-26 16:38:18 -070013625/**
13626 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13627 * @struct hdd_context *hdd_ctx
13628 * @struct hdd_adapter *padapter
13629 * @bool enble
13630 *
13631 * Return: none
13632 */
13633void hdd_set_rx_mode_rps(bool enable)
13634{
13635 struct cds_config_info *cds_cfg = cds_get_ini_config();
13636 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13637 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13638
13639 if (adapter && hdd_ctx &&
13640 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13641 if (enable && !cds_cfg->rps_enabled)
13642 hdd_send_rps_ind(adapter);
13643 else if (!enable && cds_cfg->rps_enabled)
13644 hdd_send_rps_disable_ind(adapter);
13645 }
13646}
13647
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053013648bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
13649{
13650 struct hdd_adapter *adapter = NULL;
13651
13652 hdd_for_each_adapter(hdd_ctx, adapter) {
13653 if ((adapter->device_mode == QDF_STA_MODE ||
13654 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
13655 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
13656 &adapter->event_flags)){
13657 return true;
13658 }
13659 }
13660
13661 return false;
13662}
13663
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013664/* Register the module init/exit functions */
13665module_init(hdd_module_init);
13666module_exit(hdd_module_exit);
13667
13668MODULE_LICENSE("Dual BSD/GPL");
13669MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13670MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13671
Srinivas Girigowda841da292018-02-21 16:33:00 -080013672static const struct kernel_param_ops con_mode_ops = {
13673 .set = con_mode_handler,
13674 .get = param_get_int,
13675};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013676
Srinivas Girigowda841da292018-02-21 16:33:00 -080013677static const struct kernel_param_ops con_mode_ftm_ops = {
13678 .set = con_mode_handler_ftm,
13679 .get = param_get_int,
13680};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013681
Srinivas Girigowda841da292018-02-21 16:33:00 -080013682static const struct kernel_param_ops con_mode_monitor_ops = {
13683 .set = con_mode_handler_monitor,
13684 .get = param_get_int,
13685};
Ravi Joshia307f632017-07-17 23:41:41 -070013686
Srinivas Girigowda841da292018-02-21 16:33:00 -080013687static const struct kernel_param_ops fwpath_ops = {
13688 .set = fwpath_changed_handler,
13689 .get = param_get_string,
13690};
13691
13692module_param_cb(con_mode, &con_mode_ops, &con_mode,
13693 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13694
13695module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
13696 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13697
13698module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
13699 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13700
13701module_param_cb(fwpath, &fwpath_ops, &fwpath,
13702 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013703
13704module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13705
13706module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13707
13708module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);