blob: 556b1fd1490146dd7f73db116c2c9ee5cb0849e4 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Dustin Browndb2a8be2017-12-20 11:49:56 -08002 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_main.c
30 *
31 * WLAN Host Device Driver implementation
32 *
33 */
34
35/* Include Files */
36#include <wlan_hdd_includes.h>
37#include <cds_api.h>
38#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053039#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <linux/etherdevice.h>
41#include <linux/firmware.h>
42#include <wlan_hdd_tx_rx.h>
43#include <wni_api.h>
44#include <wlan_hdd_cfg.h>
45#include <wlan_ptt_sock_svc.h>
46#include <dbglog_host.h>
47#include <wlan_logging_sock_svc.h>
48#include <wlan_hdd_wowl.h>
49#include <wlan_hdd_misc.h>
50#include <wlan_hdd_wext.h>
51#include "wlan_hdd_trace.h"
52#include "wlan_hdd_ioctl.h"
53#include "wlan_hdd_ftm.h"
54#include "wlan_hdd_power.h"
55#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070056#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080057#include "wlan_hdd_request_manager.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053058#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053059#include "qdf_trace.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080060#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080061#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080062#endif
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070063#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080064#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070065#include <cdp_txrx_stats.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066
67#include <net/addrconf.h>
68#include <linux/wireless.h>
69#include <net/cfg80211.h>
70#include <linux/inetdevice.h>
71#include <net/addrconf.h>
72#include "wlan_hdd_cfg80211.h"
73#include "wlan_hdd_ext_scan.h"
74#include "wlan_hdd_p2p.h"
75#include <linux/rtnetlink.h>
76#include "sap_api.h"
77#include <linux/semaphore.h>
78#include <linux/ctype.h>
79#include <linux/compat.h>
80#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#include <soc/qcom/subsystem_restart.h>
82#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083#include <wlan_hdd_hostapd.h>
84#include <wlan_hdd_softap_tx_rx.h>
85#include "cfg_api.h"
86#include "qwlan_version.h"
87#include "wma_types.h"
88#include "wlan_hdd_tdls.h"
89#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053090#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070092#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070093#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080094#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095#include "wlan_hdd_nan.h"
96#include "wlan_hdd_debugfs.h"
97#include "wlan_hdd_driver_ops.h"
98#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053099#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800100
101#include <wlan_hdd_ipa.h>
102#include "hif.h"
103#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800104#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700105#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530106#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700107#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700108#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530109#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700110#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530111#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800112#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800113#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530114#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800115#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800116#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530117#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530118#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800119#include "os_if_wifi_pos.h"
120#include "wifi_pos_api.h"
121#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800122#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700123#include "os_if_nan.h"
124#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700125#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800126#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700127#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530128#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530129#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700130#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800131#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530132#include "wlan_disa_ucfg_api.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530133
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530134#ifdef CNSS_GENL
135#include <net/cnss_nl.h>
136#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800137#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800138#include "wlan_ocb_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530139
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530140#include <wlan_green_ap_ucfg_api.h>
141
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800142#ifdef MODULE
143#define WLAN_MODULE_NAME module_name(THIS_MODULE)
144#else
145#define WLAN_MODULE_NAME "wlan"
146#endif
147
148#ifdef TIMER_MANAGER
149#define TIMER_MANAGER_STR " +TIMER_MANAGER"
150#else
151#define TIMER_MANAGER_STR ""
152#endif
153
154#ifdef MEMORY_DEBUG
155#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
156#else
157#define MEMORY_DEBUG_STR ""
158#endif
159
Sachin Ahujadddd2632017-03-07 19:07:24 +0530160int wlan_start_ret_val;
161static DECLARE_COMPLETION(wlan_start_comp);
162static unsigned int dev_num = 1;
163static struct cdev wlan_hdd_state_cdev;
164static struct class *class;
165static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530166#ifndef MODULE
167static struct gwlan_loader *wlan_loader;
168static ssize_t wlan_boot_cb(struct kobject *kobj,
169 struct kobj_attribute *attr,
170 const char *buf, size_t count);
171struct gwlan_loader {
172 bool loaded_state;
173 struct kobject *boot_wlan_obj;
174 struct attribute_group *attr_group;
175};
176
177static struct kobj_attribute wlan_boot_attribute =
178 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
179
180static struct attribute *attrs[] = {
181 &wlan_boot_attribute.attr,
182 NULL,
183};
184
185#define MODULE_INITIALIZED 1
186#endif
187
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530188#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
189#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800190#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530191
192static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800193static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530194static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
195
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800196/* the Android framework expects this param even though we don't use it */
197#define BUF_LEN 20
198static char fwpath_buffer[BUF_LEN];
199static struct kparam_string fwpath = {
200 .string = fwpath_buffer,
201 .maxlen = BUF_LEN,
202};
203
204static char *country_code;
205static int enable_11d = -1;
206static int enable_dfs_chan_scan = -1;
207
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800208/*
209 * spinlock for synchronizing asynchronous request/response
210 * (full description of use in wlan_hdd_main.h)
211 */
212DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530213DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800214
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800215#define WLAN_NLINK_CESIUM 30
216
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530217static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800218
219#define WOW_MAX_FILTER_LISTS 1
220#define WOW_MAX_FILTERS_PER_LIST 4
221#define WOW_MIN_PATTERN_SIZE 6
222#define WOW_MAX_PATTERN_SIZE 64
223
224#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
225static const struct wiphy_wowlan_support wowlan_support_reg_init = {
226 .flags = WIPHY_WOWLAN_ANY |
227 WIPHY_WOWLAN_MAGIC_PKT |
228 WIPHY_WOWLAN_DISCONNECT |
229 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
230 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
231 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
232 WIPHY_WOWLAN_4WAY_HANDSHAKE |
233 WIPHY_WOWLAN_RFKILL_RELEASE,
234 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
235 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
236 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
237};
238#endif
239
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700240static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
241 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
243 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
244 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
253 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
254 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
255 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
256 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
257 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700275 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700276 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700277 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530278 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800279 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700280};
281
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530282int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
283 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
284 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
285 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
286 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
287};
288
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800289/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530290struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800291
292struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800293#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700294static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800295#endif
296
Sachin Ahujadddd2632017-03-07 19:07:24 +0530297void hdd_start_complete(int ret)
298{
299 wlan_start_ret_val = ret;
300
301 complete(&wlan_start_comp);
302}
303
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800304/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530305 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700306 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530307 *
308 * Return: none
309 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700310static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530311{
Jeff Johnson9d295242017-08-29 14:39:48 -0700312 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530313
Dustin Brown920397d2017-12-13 16:27:50 -0800314 hdd_for_each_adapter(hdd_ctx, adapter)
315 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530316}
317
318/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800319 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
320 * @vdev_id: vdev_id
321 * @action: action type
322 * @reason: reason type
323 *
324 * Return: none
325 */
326void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
327 enum netif_action_type action, enum netif_reason_type reason)
328{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700329 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700330 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800331
332 if (!hdd_ctx) {
333 hdd_err("hdd ctx is NULL");
334 return;
335 }
336 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
337
338 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800339}
340
341/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700342 * Store WLAN driver version and timestamp info in global variables such that
343 * crash debugger can extract them from driver debug symbol and crashdump for
344 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800345 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800346#ifdef BUILD_TAG
347uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
348#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800349uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700350#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800351
352/**
353 * hdd_device_mode_to_string() - return string conversion of device mode
354 * @device_mode: device mode
355 *
356 * This utility function helps log string conversion of device mode.
357 *
358 * Return: string conversion of device mode, if match found;
359 * "Unknown" otherwise.
360 */
361const char *hdd_device_mode_to_string(uint8_t device_mode)
362{
363 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800364 CASE_RETURN_STRING(QDF_STA_MODE);
365 CASE_RETURN_STRING(QDF_SAP_MODE);
366 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
367 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
368 CASE_RETURN_STRING(QDF_FTM_MODE);
369 CASE_RETURN_STRING(QDF_IBSS_MODE);
370 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
371 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700372 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800373 default:
374 return "Unknown";
375 }
376}
377
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530378/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500379 * hdd_get_valid_chan() - return current chan list from regulatory.
380 * @hdd_ctx: HDD context
381 * @chan_list: buf hold returned chan list
382 * @chan_num: input buf size and output returned chan num
383 *
384 * This function helps get current available chan list from regulatory
385 * module. It excludes the "disabled" and "invalid" channels.
386 *
387 * Return: 0 for success.
388 */
389static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
390 uint8_t *chan_list,
391 uint32_t *chan_num)
392{
393 int i = 0, j = 0;
394 struct regulatory_channel *cur_chan_list;
395 struct wlan_objmgr_pdev *pdev;
396
397 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
398 return -EINVAL;
399
400 pdev = hdd_ctx->hdd_pdev;
401 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
402 sizeof(struct regulatory_channel));
403 if (!cur_chan_list)
404 return -ENOMEM;
405
406 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
407 QDF_STATUS_SUCCESS) {
408 qdf_mem_free(cur_chan_list);
409 return -EINVAL;
410 }
411
412 for (i = 0; i < NUM_CHANNELS; i++) {
413 uint32_t ch = cur_chan_list[i].chan_num;
414 enum channel_state state = wlan_reg_get_channel_state(pdev,
415 ch);
416
417 if (state != CHANNEL_STATE_DISABLE &&
418 state != CHANNEL_STATE_INVALID &&
419 j < *chan_num) {
420 chan_list[j] = (uint8_t)ch;
421 j++;
422 }
423 }
424 *chan_num = j;
425 qdf_mem_free(cur_chan_list);
426 return 0;
427}
428
429/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530430 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
431 * @adapter: HDD adapter
432 * @chan_number: Channel number
433 * @chan_bw: Bandwidth
434 *
435 * Checks if the given bandwidth is valid for the given channel number.
436 *
437 * Return: 0 for success, non-zero for failure
438 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700439int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530440 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800441 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530442{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500443 uint8_t chan[NUM_CHANNELS];
444 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530445 bool found = false;
446 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500447 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530448
449 hal = WLAN_HDD_GET_HAL_CTX(adapter);
450 if (!hal) {
451 hdd_err("Invalid HAL context");
452 return -EINVAL;
453 }
454
Liangwei Dong17bf2662018-01-05 02:02:05 -0500455 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
456 &len);
457 if (ret) {
458 hdd_err("error %d in getting valid channel list", ret);
459 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530460 }
461
462 for (i = 0; i < len; i++) {
463 if (chan[i] == chan_number) {
464 found = true;
465 break;
466 }
467 }
468
469 if (found == false) {
470 hdd_err("Channel not in driver's valid channel list");
471 return -EOPNOTSUPP;
472 }
473
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700474 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
475 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530476 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
477 return -EINVAL;
478 }
479
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700480 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530481 if (chan_bw == CH_WIDTH_80MHZ) {
482 hdd_err("BW80 not possible in 2.4GHz band");
483 return -EINVAL;
484 }
485 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
486 (chan_bw != CH_WIDTH_MAX)) {
487 hdd_err("Only BW20 possible on channel 14");
488 return -EINVAL;
489 }
490 }
491
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700492 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530493 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
494 (chan_bw != CH_WIDTH_MAX)) {
495 hdd_err("Only BW20 possible on channel 165");
496 return -EINVAL;
497 }
498 }
499
500 return 0;
501}
502
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530503/**
504 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
505 *
506 * Block the unloading of the driver (or) interface up until the
507 * cds recovery is completed
508 *
509 * Return: true for recovery completion else false
510 */
511static bool hdd_wait_for_recovery_completion(void)
512{
513 int retry = 0;
514
515 /* Wait for recovery to complete */
516 while (cds_is_driver_recovering()) {
517 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
518 hdd_err("Recovery in progress; wait here!!!");
519 msleep(1000);
520 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
521 hdd_err("SSR never completed, error");
522 /*
523 * Trigger the bug_on in the internal builds, in the
524 * customer builds self-recovery will be enabled
525 * in those cases just return error.
526 */
527 if (cds_is_self_recovery_enabled())
528 return false;
529 QDF_BUG(0);
530 }
531 }
532
533 hdd_info("Recovery completed successfully!");
534 return true;
535}
536
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800537static int __hdd_netdev_notifier_call(struct notifier_block *nb,
538 unsigned long state, void *data)
539{
540#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
541 struct netdev_notifier_info *dev_notif_info = data;
542 struct net_device *dev = dev_notif_info->dev;
543#else
544 struct net_device *dev = data;
545#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700546 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700547 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800549 ENTER_DEV(dev);
550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800551 /* Make sure that this callback corresponds to our device. */
552 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
553 return NOTIFY_DONE;
554
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530555 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800556 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700557 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558 return NOTIFY_DONE;
559 }
560
561 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700562 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800563 return NOTIFY_DONE;
564 }
565
566 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
567 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800568 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530569 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800570 return NOTIFY_DONE;
571 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800572
573 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
574 hdd_err("%s: Driver module is closed", __func__);
575 return NOTIFY_DONE;
576 }
577
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530578 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800579 return NOTIFY_DONE;
580
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800581 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800582 dev->name, state);
583
584 switch (state) {
585 case NETDEV_REGISTER:
586 break;
587
588 case NETDEV_UNREGISTER:
589 break;
590
591 case NETDEV_UP:
592 sme_ch_avoid_update_req(hdd_ctx->hHal);
593 break;
594
595 case NETDEV_DOWN:
596 break;
597
598 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700599 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600 complete(&adapter->linkup_event_var);
601 break;
602
603 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700604 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
605 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530606 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700607 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800608 } else {
hqueaa33ee2017-05-04 17:56:35 +0800609 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800610 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800611 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530612 /*
613 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
614 * of return status of hdd_stop call, kernel resets the IFF_UP
615 * flag after which driver does not send the cfg80211_scan_done.
616 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
617 */
618 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800619 break;
620
621 default:
622 break;
623 }
624
625 return NOTIFY_DONE;
626}
627
628/**
629 * hdd_netdev_notifier_call() - netdev notifier callback function
630 * @nb: pointer to notifier block
631 * @state: state
632 * @ndev: ndev pointer
633 *
634 * Return: 0 on success, error number otherwise.
635 */
636static int hdd_netdev_notifier_call(struct notifier_block *nb,
637 unsigned long state,
638 void *ndev)
639{
640 int ret;
641
642 cds_ssr_protect(__func__);
643 ret = __hdd_netdev_notifier_call(nb, state, ndev);
644 cds_ssr_unprotect(__func__);
645
646 return ret;
647}
648
649struct notifier_block hdd_netdev_notifier = {
650 .notifier_call = hdd_netdev_notifier_call,
651};
652
653/* variable to hold the insmod parameters */
654static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800655
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530656static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700657int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530658
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800659/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800660static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800661
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530662/**
663 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
664 * @ch_width: NL channel width
665 *
666 * Converts the NL channel width to the driver's internal representation
667 *
668 * Return: Converted channel width. In case of non matching NL channel width,
669 * CH_WIDTH_MAX will be returned.
670 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800671enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530672{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800673 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700674
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800675 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530676 switch (ch_width) {
677 case NL80211_CHAN_WIDTH_20_NOHT:
678 case NL80211_CHAN_WIDTH_20:
679 return CH_WIDTH_20MHZ;
680 case NL80211_CHAN_WIDTH_40:
681 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530682 case NL80211_CHAN_WIDTH_80:
683 return CH_WIDTH_80MHZ;
684 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800685 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
686 return CH_WIDTH_80P80MHZ;
687 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
688 return CH_WIDTH_160MHZ;
689 else
690 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530691 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800692 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
693 return CH_WIDTH_160MHZ;
694 else
695 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530696 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800697 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530698 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800699 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530700 default:
701 hdd_err("Invalid channel width %d, setting to default",
702 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800703 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530704 }
705}
706
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530707/* wlan_hdd_find_opclass() - Find operating class for a channel
708 * @hal: handler to HAL
709 * @channel: channel id
710 * @bw_offset: bandwidth offset
711 *
712 * Function invokes sme api to find the operating class
713 *
714 * Return: operating class
715 */
716uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
717 uint8_t bw_offset)
718{
719 uint8_t opclass = 0;
720
721 sme_get_opclass(hal, channel, bw_offset, &opclass);
722 return opclass;
723}
724
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800725/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530726 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530727 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800728 * @bitmask: Bitmask of log levels to be enabled
729 *
730 * Called immediately after the cfg.ini is read in order to configure
731 * the desired trace levels.
732 *
733 * Return: None
734 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530735int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530737 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530738 int qdf_print_idx = -1;
739 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800740 /*
741 * if the bitmask is the default value, then a bitmask was not
742 * specified in cfg.ini, so leave the logging level alone (it
743 * will remain at the "compiled in" default value)
744 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700745 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530746 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530748 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800749
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530750 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530751 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530752 QDF_TRACE_LEVEL_NONE, 0);
753
754 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530755 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800756 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530757 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758 while (0 != bitmask) {
759 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530760 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530761 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530762 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530763 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700765
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800766 level++;
767 bitmask >>= 1;
768 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530769 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800770}
771
772/**
Chris Guo1751acf2017-07-03 14:09:01 +0800773 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
774 * @hdd_ctx: HDD context pointer
775 *
776 * Return: 0 if the context is valid. Error code otherwise
777 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700778int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800779{
780 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
781 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
782 return -ENODEV;
783 }
784
785 if (cds_is_driver_recovering()) {
786 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
787 (void *)_RET_IP_, cds_get_driver_state());
788 return -EAGAIN;
789 }
790
791 if (hdd_ctx->start_modules_in_progress ||
792 hdd_ctx->stop_modules_in_progress) {
793 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
794 (void *)_RET_IP_);
795 return -EAGAIN;
796 }
797
798 return 0;
799}
800
801
802/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803 * wlan_hdd_validate_context() - check the HDD context
804 * @hdd_ctx: HDD context pointer
805 *
806 * Return: 0 if the context is valid. Error code otherwise
807 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700808int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530811 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812 return -ENODEV;
813 }
814
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800815 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800816 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530817 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800818 return -EAGAIN;
819 }
820
Yue Ma9f275d92017-09-14 16:58:41 -0700821 if (cds_is_load_or_unload_in_progress()) {
822 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
823 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700825 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530826
827 if (hdd_ctx->start_modules_in_progress ||
828 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800829 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530830 (void *)_RET_IP_);
831 return -EAGAIN;
832 }
833
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530834 if (cds_is_driver_in_bad_state()) {
835 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
836 (void *)_RET_IP_, cds_get_driver_state());
837 return -ENODEV;
838 }
839
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840 return 0;
841}
842
Jeff Johnson9d295242017-08-29 14:39:48 -0700843int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700844{
845 if (!adapter) {
846 hdd_err("adapter is null");
847 return -EINVAL;
848 }
849
850 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
851 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
852 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
853 return -EINVAL;
854 }
855
856 if (!adapter->dev) {
857 hdd_err("adapter net_device is null");
858 return -EINVAL;
859 }
860
861 if (!(adapter->dev->flags & IFF_UP)) {
862 hdd_info("adapter net_device is not up");
863 return -EAGAIN;
864 }
865
Jeff Johnson1b780e42017-10-31 14:11:45 -0700866 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700867 hdd_info("adapter session is not open");
868 return -EAGAIN;
869 }
870
Jeff Johnson1b780e42017-10-31 14:11:45 -0700871 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
872 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700873 return -EINVAL;
874 }
875
876 return 0;
877}
878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530880 * wlan_hdd_validate_modules_state() - Check modules status
881 * @hdd_ctx: HDD context pointer
882 *
883 * Check's the driver module's state and returns true if the
884 * modules are enabled returns false if modules are closed.
885 *
886 * Return: True if modules are enabled or false.
887 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700888bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530889{
890 mutex_lock(&hdd_ctx->iface_change_lock);
891 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
892 mutex_unlock(&hdd_ctx->iface_change_lock);
893 hdd_notice("Modules not enabled, Present status: %d",
894 hdd_ctx->driver_status);
895 return false;
896 }
897 mutex_unlock(&hdd_ctx->iface_change_lock);
898 return true;
899}
900
901/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800902 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700903 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 *
905 * This function sets the IBSS power save config parameters to WMA
906 * which will send it to firmware if FW supports IBSS power save
907 * before vdev start.
908 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530909 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800910 * on failure.
911 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700912QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800913{
914 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700915 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800916
917 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700918 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530919 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 }
921
Jeff Johnson1b780e42017-10-31 14:11:45 -0700922 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
924 hdd_ctx->config->ibssATIMWinSize,
925 VDEV_CMD);
926 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700927 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530928 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800929 }
930
Jeff Johnson1b780e42017-10-31 14:11:45 -0700931 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800932 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
933 hdd_ctx->config->isIbssPowerSaveAllowed,
934 VDEV_CMD);
935 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700936 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
937 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530938 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800939 }
940
Jeff Johnson1b780e42017-10-31 14:11:45 -0700941 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800942 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
943 hdd_ctx->config->
944 isIbssPowerCollapseAllowed, VDEV_CMD);
945 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700946 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
947 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530948 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949 }
950
Jeff Johnson1b780e42017-10-31 14:11:45 -0700951 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800952 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
953 hdd_ctx->config->isIbssAwakeOnTxRx,
954 VDEV_CMD);
955 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700956 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530957 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 }
959
Jeff Johnson1b780e42017-10-31 14:11:45 -0700960 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
962 hdd_ctx->config->ibssInactivityCount,
963 VDEV_CMD);
964 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700965 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530966 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800967 }
968
Jeff Johnson1b780e42017-10-31 14:11:45 -0700969 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800970 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
971 hdd_ctx->config->ibssTxSpEndInactivityTime,
972 VDEV_CMD);
973 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700974 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
975 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530976 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 }
978
Jeff Johnson1b780e42017-10-31 14:11:45 -0700979 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800980 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
981 hdd_ctx->config->ibssPsWarmupTime,
982 VDEV_CMD);
983 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700984 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
985 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530986 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987 }
988
Jeff Johnson1b780e42017-10-31 14:11:45 -0700989 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800990 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
991 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
992 VDEV_CMD);
993 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700994 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
995 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530996 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997 }
998
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530999 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000}
1001
Yue Macd359b72017-10-03 15:21:00 -07001002#ifdef FEATURE_RUNTIME_PM
1003/**
1004 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1005 * @hdd_ctx: HDD context
1006 *
1007 * Return: None
1008 */
1009static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1010{
1011 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1012
Yue Macd359b72017-10-03 15:21:00 -07001013 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001014 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001015
1016 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1017}
1018
1019/**
1020 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1021 * @hdd_ctx: HDD Context
1022 *
1023 * Return: None
1024 */
1025static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1026{
1027 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1028
Yue Macd359b72017-10-03 15:21:00 -07001029 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001030 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001031
1032 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1033}
1034
Yue Macd359b72017-10-03 15:21:00 -07001035#else /* FEATURE_RUNTIME_PM */
1036static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1037static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001038#endif /* FEATURE_RUNTIME_PM */
1039
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040#define INTF_MACADDR_MASK 0x7
1041
1042/**
1043 * hdd_update_macaddr() - update mac address
1044 * @config: hdd configuration
1045 * @hw_macaddr: mac address
1046 *
1047 * Mac address for multiple virtual interface is found as following
1048 * i) The mac address of the first interface is just the actual hw mac address.
1049 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1050 * define the mac address for the remaining interfaces and locally
1051 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1052 * supported virtual interfaces, right now this is 0x07 (meaning 8
1053 * interface).
1054 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1055 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1056 *
1057 * Return: None
1058 */
1059void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301060 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061{
1062 int8_t i;
1063 uint8_t macaddr_b3, tmp_br3;
1064
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301065 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301066 QDF_MAC_ADDR_SIZE);
1067 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301068 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301069 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1071 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1072 INTF_MACADDR_MASK;
1073 macaddr_b3 += tmp_br3;
1074
1075 /* XOR-ing bit-24 of the mac address. This will give enough
1076 * mac address range before collision
1077 */
1078 macaddr_b3 ^= (1 << 7);
1079
1080 /* Set locally administered bit */
1081 config->intfMacAddr[i].bytes[0] |= 0x02;
1082 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001083 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001084 MAC_ADDRESS_STR, i,
1085 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1086 }
1087}
1088
Kabilan Kannan44a58372017-12-06 18:16:11 -08001089static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1090{
1091 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1092 struct tdls_start_params tdls_cfg;
1093 struct tdls_user_config *config = &tdls_cfg.config;
1094 struct hdd_config *cfg = hdd_ctx->config;
1095 QDF_STATUS status;
1096
1097 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1098 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1099 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1100 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1101 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1102 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1103 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1104 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1105 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1106 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1107 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1108 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1109 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1110 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1111 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1112 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1113 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1114 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1115 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1116 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1117 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1118 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1119 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1120 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1121 (cfg->fEnableTDLSImplicitTrigger ?
1122 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1123 (cfg->fTDLSExternalControl ?
1124 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1125 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1126 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1127
1128 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1129 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1130 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1131 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1132 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1133 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1134 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1135 tdls_cfg.tdls_evt_cb_data = psoc;
1136 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
1137 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
1138 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
1139 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1140 tdls_cfg.tdls_wmm_cb_data = psoc;
1141 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1142 tdls_cfg.tdls_rx_cb_data = psoc;
1143 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1144
1145 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1146 if (status != QDF_STATUS_SUCCESS) {
1147 hdd_err("failed pmo psoc configuration");
1148 return -EINVAL;
1149 }
1150
1151 hdd_ctx->tdls_umac_comp_active = true;
1152 /* enable napier specific tdls data path */
1153 hdd_ctx->tdls_nap_active = true;
1154
1155 return 0;
1156}
1157
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001158static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001159 struct wma_tgt_services *cfg)
1160{
1161 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001162
1163 /* Set up UAPSD */
1164 config->apUapsdEnabled &= cfg->uapsd;
1165
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001166 /* 11AX mode support */
1167 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1168 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1169 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1170
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001171 /* 11AC mode support */
1172 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1173 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1174 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001175
1176 /* ARP offload: override user setting if invalid */
1177 config->fhostArpOffload &= cfg->arp_offload;
1178
1179#ifdef FEATURE_WLAN_SCAN_PNO
1180 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001181 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001182 if (cfg->pno_offload)
1183 config->PnoOffload = true;
1184#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001185#ifdef FEATURE_WLAN_TDLS
1186 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301187 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1188 cfg->en_tdls_offchan;
1189 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1190 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001191 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001193 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001194 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001196#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1197 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1198#endif
Will Huang496b36c2017-07-11 16:38:50 +08001199 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001200 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001201 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001202 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001203
1204}
1205
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001206/**
1207 * hdd_update_vdev_nss() - sets the vdev nss
1208 * @hdd_ctx: HDD context
1209 *
1210 * Sets the Nss per vdev type based on INI
1211 *
1212 * Return: None
1213 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001214static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001215{
1216 struct hdd_config *cfg_ini = hdd_ctx->config;
1217 uint8_t max_supp_nss = 1;
1218
Naveen Rawat10b1c152017-01-18 11:16:06 -08001219 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001220 max_supp_nss = 2;
1221
1222 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001223 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001224
1225 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001226 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001227}
1228
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301229/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301230 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1231 * @hdd_ctx: HDD context
1232 *
1233 * Updates wiphy vhtcap fields
1234 *
1235 * Return: None
1236 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001237static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301238{
1239 struct ieee80211_supported_band *band_5g =
1240 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1241 uint32_t val;
1242
1243 if (!band_5g) {
1244 hdd_debug("5GHz band disabled, skipping capability population");
1245 return;
1246 }
1247
1248 val = hdd_ctx->config->txBFCsnValue;
1249 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1250
1251 val = NUM_OF_SOUNDING_DIMENSIONS;
1252 band_5g->vht_cap.cap |=
1253 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1254
1255 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1256 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1257}
1258
1259/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301260 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1261 * @hdd_ctx: HDD context
1262 *
1263 * Sets the DBS capability as per INI and firmware capability
1264 *
1265 * Return: None
1266 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001267static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301268{
1269 struct hdd_config *cfg_ini = hdd_ctx->config;
1270 uint8_t hw_dbs_capable = 0;
1271
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001272 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1273 ((cfg_ini->dual_mac_feature_disable ==
1274 ENABLE_DBS_CXN_AND_SCAN) ||
1275 (cfg_ini->dual_mac_feature_disable ==
1276 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301277 hw_dbs_capable = 1;
1278
1279 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1280}
1281
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001282static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001283 struct wma_tgt_ht_cap *cfg)
1284{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301285 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001286 uint32_t value, val32;
1287 uint16_t val16;
1288 struct hdd_config *pconfig = hdd_ctx->config;
1289 tSirMacHTCapabilityInfo *phtCapInfo;
1290 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1291 uint8_t enable_tx_stbc;
1292
1293 /* check and update RX STBC */
1294 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1295 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1296
1297 /* get the MPDU density */
1298 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1299
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301300 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001301 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001302 value = 0;
1303 }
1304
1305 /*
1306 * MPDU density:
1307 * override user's setting if value is larger
1308 * than the one supported by target
1309 */
1310 if (value > cfg->mpdu_density) {
1311 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1312 cfg->mpdu_density);
1313
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301314 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001315 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001316 }
1317
1318 /* get the HT capability info */
1319 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301320 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001321 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001322 return;
1323 }
1324 val16 = (uint16_t) val32;
1325 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1326
1327 /* Set the LDPC capability */
1328 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1329
1330 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1331 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1332
1333 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1334 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1335
1336 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1337 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1338
1339 enable_tx_stbc = pconfig->enableTxSTBC;
1340
1341 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1342 pconfig->enable2x2 = 1;
1343 } else {
1344 pconfig->enable2x2 = 0;
1345 enable_tx_stbc = 0;
1346
1347 /* 1x1 */
1348 /* Update Rx Highest Long GI data Rate */
1349 if (sme_cfg_set_int(hdd_ctx->hHal,
1350 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001351 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301352 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001353 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 }
1355
1356 /* Update Tx Highest Long GI data Rate */
1357 if (sme_cfg_set_int
1358 (hdd_ctx->hHal,
1359 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001360 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301361 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001362 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363 }
1364 }
1365 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1366 enable_tx_stbc = 0;
1367 phtCapInfo->txSTBC = enable_tx_stbc;
1368
1369 val32 = val16;
1370 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301371 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001372 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1374 value = SIZE_OF_SUPPORTED_MCS_SET;
1375 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301376 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001377 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001378
1379 if (pconfig->enable2x2) {
1380 for (value = 0; value < cfg->num_rf_chains; value++)
1381 mcs_set[value] =
1382 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1383
1384 status =
1385 sme_cfg_set_str(hdd_ctx->hHal,
1386 WNI_CFG_SUPPORTED_MCS_SET,
1387 mcs_set,
1388 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301389 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001390 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001391 }
1392 }
1393#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1394}
1395
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001396static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001397 struct wma_tgt_vht_cap *cfg)
1398{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301399 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001400 uint32_t value = 0;
1401 struct hdd_config *pconfig = hdd_ctx->config;
1402 struct wiphy *wiphy = hdd_ctx->wiphy;
1403 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001404 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001405 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001406 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001407 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001408
Dustin Brown5e06bd32016-10-04 12:49:10 -07001409 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001410 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001411 return;
1412 }
1413
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414 /* Get the current MPDU length */
1415 status =
1416 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1417 &value);
1418
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301419 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001420 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001421 value = 0;
1422 }
1423
1424 /*
1425 * VHT max MPDU length:
1426 * override if user configured value is too high
1427 * that the target cannot support
1428 */
1429 if (value > cfg->vht_max_mpdu) {
1430 status = sme_cfg_set_int(hdd_ctx->hHal,
1431 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1432 cfg->vht_max_mpdu);
1433
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001434 if (status == QDF_STATUS_E_FAILURE)
1435 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001436 }
1437
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001438 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1439 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1440
1441 if (pconfig->enable2x2)
1442 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1443
1444 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1445 QDF_STATUS_E_FAILURE) {
1446 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1447 }
1448
1449 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1450 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1451 if (pconfig->enable2x2)
1452 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1453
1454 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1455 QDF_STATUS_E_FAILURE) {
1456 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1457 }
1458
1459 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1460 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1461 if (pconfig->enable2x2)
1462 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1463
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001464 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001465 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1466
1467 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1468 QDF_STATUS_E_FAILURE) {
1469 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1470 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001471 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001472 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001473 &value);
1474
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301475 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001476 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001477 value = 0;
1478 }
1479
jiad4a7a33c2017-08-08 15:32:24 +08001480 /* Set HW RX LDPC capability */
1481 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1482 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 status = sme_cfg_set_int(hdd_ctx->hHal,
1484 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001485 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001486
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001487 if (status == QDF_STATUS_E_FAILURE)
1488 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001489 }
1490
1491 /* Get current GI 80 value */
1492 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1493 &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 SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497 value = 0;
1498 }
1499
1500 /* set the Guard interval 80MHz */
1501 if (value && !cfg->vht_short_gi_80) {
1502 status = sme_cfg_set_int(hdd_ctx->hHal,
1503 WNI_CFG_VHT_SHORT_GI_80MHZ,
1504 cfg->vht_short_gi_80);
1505
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001506 if (status == QDF_STATUS_E_FAILURE)
1507 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001508 }
1509
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001510 /* Get VHT TX STBC cap */
1511 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1512
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301513 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001514 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001515 value = 0;
1516 }
1517
1518 /* VHT TX STBC cap */
1519 if (value && !cfg->vht_tx_stbc) {
1520 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1521 cfg->vht_tx_stbc);
1522
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001523 if (status == QDF_STATUS_E_FAILURE)
1524 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001525 }
1526
1527 /* Get VHT RX STBC cap */
1528 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1529
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301530 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001531 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001532 value = 0;
1533 }
1534
1535 /* VHT RX STBC cap */
1536 if (value && !cfg->vht_rx_stbc) {
1537 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1538 cfg->vht_rx_stbc);
1539
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001540 if (status == QDF_STATUS_E_FAILURE)
1541 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 }
1543
1544 /* Get VHT SU Beamformer cap */
1545 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1546 &value);
1547
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301548 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001549 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550 value = 0;
1551 }
1552
1553 /* set VHT SU Beamformer cap */
1554 if (value && !cfg->vht_su_bformer) {
1555 status = sme_cfg_set_int(hdd_ctx->hHal,
1556 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1557 cfg->vht_su_bformer);
1558
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001559 if (status == QDF_STATUS_E_FAILURE)
1560 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001561 }
1562
1563 /* check and update SU BEAMFORMEE capabality */
1564 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1565 pconfig->enableTxBF = cfg->vht_su_bformee;
1566
1567 status = sme_cfg_set_int(hdd_ctx->hHal,
1568 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1569 pconfig->enableTxBF);
1570
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001571 if (status == QDF_STATUS_E_FAILURE)
1572 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001573
1574 /* Get VHT MU Beamformer cap */
1575 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1576 &value);
1577
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301578 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001579 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001580 value = 0;
1581 }
1582
1583 /* set VHT MU Beamformer cap */
1584 if (value && !cfg->vht_mu_bformer) {
1585 status = sme_cfg_set_int(hdd_ctx->hHal,
1586 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1587 cfg->vht_mu_bformer);
1588
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001589 if (status == QDF_STATUS_E_FAILURE)
1590 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001591 }
1592
1593 /* Get VHT MU Beamformee cap */
1594 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1595 &value);
1596
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301597 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001598 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599 value = 0;
1600 }
1601
1602 /* set VHT MU Beamformee cap */
1603 if (value && !cfg->vht_mu_bformee) {
1604 status = sme_cfg_set_int(hdd_ctx->hHal,
1605 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1606 cfg->vht_mu_bformee);
1607
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001608 if (status == QDF_STATUS_E_FAILURE)
1609 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 }
1611
1612 /* Get VHT MAX AMPDU Len exp */
1613 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1614 &value);
1615
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301616 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001617 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 value = 0;
1619 }
1620
1621 /*
1622 * VHT max AMPDU len exp:
1623 * override if user configured value is too high
1624 * that the target cannot support.
1625 * Even though Rome publish ampdu_len=7, it can
1626 * only support 4 because of some h/w bug.
1627 */
1628
1629 if (value > cfg->vht_max_ampdu_len_exp) {
1630 status = sme_cfg_set_int(hdd_ctx->hHal,
1631 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1632 cfg->vht_max_ampdu_len_exp);
1633
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001634 if (status == QDF_STATUS_E_FAILURE)
1635 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 }
1637
1638 /* Get VHT TXOP PS CAP */
1639 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1640
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301641 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001642 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643 value = 0;
1644 }
1645
1646 /* set VHT TXOP PS cap */
1647 if (value && !cfg->vht_txop_ps) {
1648 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1649 cfg->vht_txop_ps);
1650
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001651 if (status == QDF_STATUS_E_FAILURE)
1652 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001653 }
1654
1655 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1656 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1657 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1658 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1659 else
1660 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1661
1662
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001663 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1664 status = sme_cfg_set_int(hdd_ctx->hHal,
1665 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1666 VHT_CAP_160_AND_80P80_SUPP);
1667 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001668 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001669 band_5g->vht_cap.cap |=
1670 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001671 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1672 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1673 status = sme_cfg_set_int(hdd_ctx->hHal,
1674 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1675 VHT_CAP_160_SUPP);
1676 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001677 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001678 band_5g->vht_cap.cap |=
1679 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001680 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1681 }
1682 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1683 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301684 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001685 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301686 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001687 &value);
1688 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301689 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001690 value = 0;
1691 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301692 /* set the Guard interval 160MHz */
1693 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001694 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301695 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1696 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001697
1698 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301699 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001700 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701
1702 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1703 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1704
1705 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1706 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1707 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1708 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1709
1710 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1711 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1712
1713 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1714 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1715 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1716 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1717 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1718 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1719
1720 band_5g->vht_cap.cap |=
1721 (cfg->vht_max_ampdu_len_exp <<
1722 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1723
1724 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1725 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1726 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1727 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1728 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1729 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1730 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1731 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1732
1733 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1734 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1735
1736}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001737
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001738/**
1739 * hdd_generate_macaddr_auto() - Auto-generate mac address
1740 * @hdd_ctx: Pointer to the HDD context
1741 *
1742 * Auto-generate mac address using device serial number.
1743 * Keep the first 3 bytes of OUI as before and replace
1744 * the last 3 bytes with the lower 3 bytes of serial number.
1745 *
1746 * Return: 0 for success
1747 * Non zero failure code for errors
1748 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001749static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001750{
1751 unsigned int serialno = 0;
1752 struct qdf_mac_addr mac_addr = {
1753 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1754 };
1755
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001756 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001757 if (serialno == 0)
1758 return -EINVAL;
1759
1760 serialno &= 0x00ffffff;
1761
1762 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1763 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1764 mac_addr.bytes[5] = serialno & 0xff;
1765
1766 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1767 return 0;
1768}
1769
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301770/**
1771 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1772 * configuration to cfg_ini in HDD
1773 * @hdd_ctx: Pointer to hdd_ctx
1774 * @cfg: target configuration
1775 *
1776 * Return: None
1777 */
1778#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001779static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301780 struct wma_tgt_cfg *cfg)
1781{
1782 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1783}
1784#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001785static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301786 struct wma_tgt_cfg *cfg)
1787{
1788}
1789#endif
1790
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301791uint8_t hdd_check_green_ap_enable(struct hdd_context *hdd_ctx,
1792 bool *is_enabled)
1793{
1794 struct hdd_config *cfg;
1795 uint32_t concurrency_mode;
1796
1797 cfg = hdd_ctx->config;
1798 if (!cfg) {
1799 hdd_err("NULL hdd config");
1800 return -EINVAL;
1801 }
1802
1803 concurrency_mode = policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc);
1804
1805 if (cfg->enable2x2 && cfg->enableGreenAP) {
1806 if ((concurrency_mode & (1 << QDF_SAP_MODE)) &&
1807 !(concurrency_mode & (~(1 << QDF_SAP_MODE))))
1808 *is_enabled = true;
1809 }
1810 return 0;
1811}
1812
1813static int hdd_update_green_ap_config(struct hdd_context *hdd_ctx)
1814{
1815 struct green_ap_user_cfg green_ap_cfg;
1816 struct hdd_config *cfg = hdd_ctx->config;
1817 QDF_STATUS status;
1818
1819 green_ap_cfg.host_enable_egap = cfg->enable_egap;
1820 green_ap_cfg.egap_inactivity_time = cfg->egap_inact_time;
1821 green_ap_cfg.egap_wait_time = cfg->egap_wait_time;
1822 green_ap_cfg.egap_feature_flags = cfg->egap_feature_flag;
1823
1824 status = ucfg_green_ap_update_user_config(hdd_ctx->hdd_pdev,
1825 &green_ap_cfg);
1826 if (status != QDF_STATUS_SUCCESS) {
1827 hdd_err("failed to update green ap user configuration");
1828 return -EINVAL;
1829 }
1830
1831 return 0;
1832}
1833
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834void hdd_update_tgt_cfg(void *context, void *param)
1835{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001836 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001837 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001838 struct wma_tgt_cfg *cfg = param;
1839 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001840 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301841 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001842 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301843
Dustin Brownbd68fe12017-11-21 15:28:52 -08001844 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1845 if (ret) {
1846 hdd_err("Failed to create pdev; errno:%d", ret);
1847 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001848 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001849 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001850 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001851 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1852 hdd_err("dispatcher pdev open failed");
1853 QDF_BUG(0);
1854 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301855 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001856
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301857 ret = hdd_update_green_ap_config(hdd_ctx);
1858
Naveen Rawat64e477e2016-05-20 10:34:56 -07001859 if (cds_cfg) {
1860 if (hdd_ctx->config->enable_sub_20_channel_width !=
1861 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1862 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1863 cds_cfg->sub_20_channel_width =
1864 WLAN_SUB_20_CH_WIDTH_NONE;
1865 } else {
1866 cds_cfg->sub_20_channel_width =
1867 hdd_ctx->config->enable_sub_20_channel_width;
1868 }
1869 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001870
1871 /* first store the INI band capability */
1872 temp_band_cap = hdd_ctx->config->nBandCapability;
1873
1874 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301875 hdd_ctx->is_fils_roaming_supported =
1876 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301878 hdd_ctx->config->is_11k_offload_supported =
1879 cfg->services.is_11k_offload_supported;
1880
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001881 /*
1882 * now overwrite the target band capability with INI
1883 * setting if INI setting is a subset
1884 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001885
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001886 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1887 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001888 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001889 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1890 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001892 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893 }
1894
Amar Singhal58b45ef2017-08-01 13:43:54 -07001895 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1896
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301897 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001898 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1899 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1900 }
1901
1902 /* This can be extended to other configurations like ht, vht cap... */
1903
Anurag Chouhanc5548422016-02-24 18:33:27 +05301904 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001905 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001906 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001908 static struct qdf_mac_addr default_mac_addr = {
1909 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1910 };
1911 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1912 &default_mac_addr)) {
1913 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1914 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1915 MAC_ADDRESS_STR,
1916 MAC_ADDR_ARRAY(hdd_ctx->config->
1917 intfMacAddr[0].bytes));
1918 } else {
1919 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1920 MAC_ADDRESS_STR,
1921 MAC_ADDR_ARRAY(hdd_ctx->config->
1922 intfMacAddr[0].bytes));
1923 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001924 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925 }
1926
1927 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001928 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001929
1930 hdd_ctx->max_intf_count = cfg->max_intf_count;
1931
Jeff Johnsonc875e242016-09-23 18:12:34 -07001932 hdd_lpass_target_config(hdd_ctx, cfg);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301933 ucfg_green_ap_target_config(hdd_ctx->hdd_pdev, cfg->egap_support);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1936 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1937
1938 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1939
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001940 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001941 if (cfg->services.en_11ax) {
1942 hdd_info("11AX: 11ax is enabled - update HDD config");
1943 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1944 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001945
1946 hdd_update_vdev_nss(hdd_ctx);
1947
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301948 hdd_update_hw_dbs_capable(hdd_ctx);
1949
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001950 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001951 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001952 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001953 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001954
Nitesh Shahe50711f2017-04-26 16:30:45 +05301955 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1956 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1957 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001958 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001959 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001960
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001961 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1962 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301963 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301964 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301965
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301966 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001967 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1968 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301969 hdd_ctx->config->txBFCsnValue =
1970 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1971
Arif Hussainee10f902017-12-27 16:30:17 -08001972 status = sme_cfg_set_int(hdd_ctx->hHal,
1973 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1974 hdd_ctx->config->txBFCsnValue);
1975 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301976 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1977
1978
1979 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001980 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1981 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301982
1983 /*
1984 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1985 */
1986 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301987
Arun Khandavallid454d422016-08-17 12:47:05 +05301988 /*
1989 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1990 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1991 * configure the STA mode wow pattern.
1992 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301993 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301994 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301995
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301996 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1997
Yue Macd359b72017-10-03 15:21:00 -07001998 /*
1999 * This needs to be done after HDD pdev is created and stored since
2000 * it will access the HDD pdev object lock.
2001 */
2002 hdd_runtime_suspend_context_init(hdd_ctx);
2003
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002004 /* Configure NAN datapath features */
2005 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002006 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002007 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002008 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2009 cfg->obss_detection_offloaded);
2010 if (QDF_IS_STATUS_ERROR(status))
2011 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002012}
2013
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002014bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015{
Jeff Johnson9d295242017-08-29 14:39:48 -07002016 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002017 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002018
Jiachao Wuf610d912018-01-23 17:47:32 +08002019 if (!hdd_ctx) {
2020 hdd_info("Couldn't get hdd_ctx");
2021 return true;
2022 }
2023
2024 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002025 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002026 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302027 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002028 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029
Dustin Brown920397d2017-12-13 16:27:50 -08002030 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002031 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2032
2033 if ((QDF_SAP_MODE == adapter->device_mode ||
2034 QDF_P2P_GO_MODE == adapter->device_mode) &&
2035 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002036 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002037 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2038 true;
2039 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002040 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302041 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002042 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302043
2044 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002045}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046
2047/**
2048 * hdd_is_valid_mac_address() - validate MAC address
2049 * @pMacAddr: Pointer to the input MAC address
2050 *
2051 * This function validates whether the given MAC address is valid or not
2052 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2053 * where X is the hexa decimal digit character and separated by ':'
2054 * This algorithm works even if MAC address is not separated by ':'
2055 *
2056 * This code checks given input string mac contains exactly 12 hexadecimal
2057 * digits and a separator colon : appears in the input string only after
2058 * an even number of hex digits.
2059 *
2060 * Return: 1 for valid and 0 for invalid
2061 */
2062bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2063{
2064 int xdigit = 0;
2065 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002066
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002067 while (*pMacAddr) {
2068 if (isxdigit(*pMacAddr)) {
2069 xdigit++;
2070 } else if (':' == *pMacAddr) {
2071 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2072 break;
2073
2074 ++separator;
2075 } else {
2076 /* Invalid MAC found */
2077 return 0;
2078 }
2079 ++pMacAddr;
2080 }
2081 return xdigit == 12 && (separator == 5 || separator == 0);
2082}
2083
2084/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302085 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2086 * @dev: Handle to struct net_device to be updated.
2087 *
2088 * Return: None
2089 */
2090static void hdd_mon_mode_ether_setup(struct net_device *dev)
2091{
2092 dev->header_ops = NULL;
2093 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2094 dev->hard_header_len = ETH_HLEN;
2095 dev->mtu = ETH_DATA_LEN;
2096 dev->addr_len = ETH_ALEN;
2097 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2098 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2099 dev->priv_flags |= IFF_TX_SKB_SHARING;
2100
2101 memset(dev->broadcast, 0xFF, ETH_ALEN);
2102}
2103
2104/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002105 * __hdd__mon_open() - HDD Open function
2106 * @dev: Pointer to net_device structure
2107 *
2108 * This is called in response to ifconfig up
2109 *
2110 * Return: 0 for success; non-zero for failure
2111 */
2112static int __hdd_mon_open(struct net_device *dev)
2113{
2114 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002115 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2116 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002117
2118 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002119
2120 ret = wlan_hdd_validate_context(hdd_ctx);
2121 if (ret)
2122 return ret;
2123
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302124 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002125
2126 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2127 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2128 if (ret) {
2129 hdd_err("Failed to start WLAN modules return");
2130 return ret;
2131 }
2132 hdd_err("hdd_wlan_start_modules() successful !");
2133
2134 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2135 ret = hdd_start_adapter(adapter);
2136 if (ret) {
2137 hdd_err("Failed to start adapter :%d",
2138 adapter->device_mode);
2139 return ret;
2140 }
2141 hdd_err("hdd_start_adapters() successful !");
2142 }
2143 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2144 }
2145
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002146 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002147
2148 if (!ret)
2149 ret = hdd_enable_monitor_mode(dev);
2150
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002151 return ret;
2152}
2153
2154/**
2155 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2156 * @dev: Pointer to net_device structure
2157 *
2158 * This is called in response to ifconfig up
2159 *
2160 * Return: 0 for success; non-zero for failure
2161 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002162static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002163{
2164 int ret;
2165
2166 cds_ssr_protect(__func__);
2167 ret = __hdd_mon_open(dev);
2168 cds_ssr_unprotect(__func__);
2169
2170 return ret;
2171}
2172
2173/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302174 * hdd_start_adapter() - Wrapper function for device specific adapter
2175 * @adapter: pointer to HDD adapter
2176 *
2177 * This function is called to start the device specific adapter for
2178 * the mode passed in the adapter's device_mode.
2179 *
2180 * Return: 0 for success; non-zero for failure
2181 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002182int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302183{
2184
2185 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002186 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302187
2188 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002189 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302190
2191 switch (device_mode) {
2192 case QDF_P2P_CLIENT_MODE:
2193 case QDF_P2P_DEVICE_MODE:
2194 case QDF_OCB_MODE:
2195 case QDF_STA_MODE:
2196 case QDF_MONITOR_MODE:
2197 ret = hdd_start_station_adapter(adapter);
2198 if (ret)
2199 goto err_start_adapter;
2200 break;
2201 case QDF_P2P_GO_MODE:
2202 case QDF_SAP_MODE:
2203 ret = hdd_start_ap_adapter(adapter);
2204 if (ret)
2205 goto err_start_adapter;
2206 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302207 case QDF_IBSS_MODE:
2208 /*
2209 * For IBSS interface is initialized as part of
2210 * hdd_init_station_mode()
2211 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002212 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302213 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002214 /* vdevs are dynamically managed by firmware in FTM */
2215 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302216 default:
2217 hdd_err("Invalid session type %d", device_mode);
2218 QDF_ASSERT(0);
2219 goto err_start_adapter;
2220 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002221
Arun Khandavallifae92942016-08-01 13:31:08 +05302222 if (hdd_set_fw_params(adapter))
2223 hdd_err("Failed to set the FW params for the adapter!");
2224
2225 /*
2226 * Action frame registered in one adapter which will
2227 * applicable to all interfaces
2228 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302229 ret = wlan_hdd_cfg80211_register_frames(adapter);
2230 if (ret < 0) {
2231 hdd_err("Failed to register frames - ret %d", ret);
2232 goto err_start_adapter;
2233 }
2234
Dustin Browndb2a8be2017-12-20 11:49:56 -08002235exit_with_success:
Arun Khandavallifae92942016-08-01 13:31:08 +05302236 EXIT();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002237
Arun Khandavallifae92942016-08-01 13:31:08 +05302238 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002239
Arun Khandavallifae92942016-08-01 13:31:08 +05302240err_start_adapter:
2241 return -EINVAL;
2242}
2243
2244/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302245 * hdd_enable_power_management() - API to Enable Power Management
2246 *
2247 * API invokes Bus Interface Layer power management functionality
2248 *
2249 * Return: None
2250 */
2251static void hdd_enable_power_management(void)
2252{
2253 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2254
2255 if (!hif_ctx) {
2256 hdd_err("Bus Interface Context is Invalid");
2257 return;
2258 }
2259
2260 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2261}
2262
2263/**
2264 * hdd_disable_power_management() - API to disable Power Management
2265 *
2266 * API disable Bus Interface Layer Power management functionality
2267 *
2268 * Return: None
2269 */
2270static void hdd_disable_power_management(void)
2271{
2272 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2273
2274 if (!hif_ctx) {
2275 hdd_err("Bus Interface Context is Invalid");
2276 return;
2277 }
2278
2279 hif_disable_power_management(hif_ctx);
2280}
2281
2282/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302283 * hdd_update_hw_sw_info() - API to update the HW/SW information
2284 *
2285 * API to update the HW and SW information in the driver
2286 *
2287 * Return: None
2288 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002289static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302290{
2291 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002292 size_t target_hw_name_len;
2293 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302294
2295 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2296 if (!hif_sc) {
2297 hdd_err("HIF context is NULL");
2298 return;
2299 }
2300
2301 /*
2302 * target hw version/revision would only be retrieved after firmware
2303 * download
2304 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002305 hif_get_hw_info(hif_sc,
2306 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302307 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002308 &target_hw_name);
2309
2310 if (hdd_ctx->target_hw_name)
2311 qdf_mem_free(hdd_ctx->target_hw_name);
2312
2313 target_hw_name_len = strlen(target_hw_name) + 1;
2314 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2315 if (hdd_ctx->target_hw_name)
2316 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2317 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302318
2319 /* Get the wlan hw/fw version */
2320 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302321}
2322
2323/**
gbian62edd7e2017-03-07 13:12:13 +08002324 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2325 * @hdd_ctx: Pointer to hdd context
2326 *
2327 * Return: none
2328 */
2329static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002330hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002331{
2332 uint8_t num_entries = 0;
2333 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2334 uint8_t *tx_sched_wrr_ac;
2335 int i;
2336 cds_context_type *cds_ctx;
2337
2338 if (NULL == hdd_ctx)
2339 return;
2340
2341 if (NULL == hdd_ctx->config) {
2342 /* Do nothing if hdd_ctx is invalid */
2343 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2344 return;
2345 }
2346
2347 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2348
2349 if (!cds_ctx) {
2350 hdd_err("Invalid CDS Context");
2351 return;
2352 }
2353
2354 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2355 switch (i) {
2356 case OL_TX_WMM_AC_BE:
2357 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2358 break;
2359 case OL_TX_WMM_AC_BK:
2360 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2361 break;
2362 case OL_TX_WMM_AC_VI:
2363 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2364 break;
2365 case OL_TX_WMM_AC_VO:
2366 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2367 break;
2368 default:
2369 tx_sched_wrr_ac = NULL;
2370 break;
2371 }
2372
2373 hdd_string_to_u8_array(tx_sched_wrr_ac,
2374 tx_sched_wrr_param,
2375 &num_entries,
2376 sizeof(tx_sched_wrr_param));
2377
2378 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2379 cds_ctx->ac_specs[i].wrr_skip_weight =
2380 tx_sched_wrr_param[0];
2381 cds_ctx->ac_specs[i].credit_threshold =
2382 tx_sched_wrr_param[1];
2383 cds_ctx->ac_specs[i].send_limit =
2384 tx_sched_wrr_param[2];
2385 cds_ctx->ac_specs[i].credit_reserve =
2386 tx_sched_wrr_param[3];
2387 cds_ctx->ac_specs[i].discard_weight =
2388 tx_sched_wrr_param[4];
2389 }
2390
2391 num_entries = 0;
2392 }
2393}
2394
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002395#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002396static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2397 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2398{
Jeff Johnson9d295242017-08-29 14:39:48 -07002399 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002400 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002401
2402 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2403 if (!adapter) {
2404 hdd_err("Adapter is NULL");
2405 return PM_MAX_NUM_OF_MODE;
2406 }
2407
2408 return policy_mgr_convert_device_mode_to_qdf_type(
2409 adapter->device_mode);
2410}
2411
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002412static void hdd_register_policy_manager_callback(
2413 struct wlan_objmgr_psoc *psoc)
2414{
2415 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002416
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002417 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002418 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002419 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2420 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002421 hdd_cbacks.get_mode_for_non_connected_vdev =
2422 wlan_hdd_get_mode_for_non_connected_vdev;
2423
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002424 if (QDF_STATUS_SUCCESS !=
2425 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2426 hdd_err("HDD callback registration with policy manager failed");
2427 }
2428}
2429#else
2430static void hdd_register_policy_manager_callback(
2431 struct wlan_objmgr_psoc *psoc)
2432{
2433}
2434#endif
2435
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002436static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002437{
2438 struct nan_callbacks cb_obj = {0};
2439
2440 cb_obj.ndi_open = hdd_ndi_open;
2441 cb_obj.ndi_close = hdd_ndi_close;
2442 cb_obj.ndi_start = hdd_ndi_start;
2443 cb_obj.ndi_delete = hdd_ndi_delete;
2444 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2445 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2446
Naveen Rawat37f62c82017-03-26 22:24:43 -07002447 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2448 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002449 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002450
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002451 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2452}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002453
Dustin Brown26b3d042017-12-21 11:13:27 -08002454#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002455/**
2456 * hdd_check_for_leaks() - Perform runtime memory leak checks
2457 *
2458 * This API triggers runtime memory leak detection. This feature enforces the
2459 * policy that any memory allocated at runtime must also be released at runtime.
2460 *
2461 * Allocating memory at runtime and releasing it at unload is effectively a
2462 * memory leak for configurations which never unload (e.g. LONU, statically
2463 * compiled driver). Such memory leaks are NOT false positives, and must be
2464 * fixed.
2465 *
2466 * Return: None
2467 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002468static void hdd_check_for_leaks(void)
2469{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002470 /* DO NOT REMOVE these checks; for false positives, read above first */
2471
Dustin Brown677e0862017-10-10 16:30:09 -07002472 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002473 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002474 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002475}
2476
Dustin Brown26b3d042017-12-21 11:13:27 -08002477#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2478#else
2479static inline void hdd_check_for_leaks(void) {}
2480
2481#define hdd_debug_domain_set(domain)
2482#endif /* CONFIG_LEAK_DETECTION */
2483
gbian62edd7e2017-03-07 13:12:13 +08002484/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002485 * hdd_update_country_code - Update country code
2486 * @hdd_ctx: HDD context
2487 *
2488 * Update country code based on module parameter country_code
2489 *
2490 * Return: 0 on success and errno on failure
2491 */
2492static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2493{
2494 if (!country_code)
2495 return 0;
2496
2497 return hdd_reg_set_country(hdd_ctx, country_code);
2498}
2499
2500/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302501 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2502 * @hdd_ctx: HDD context
2503 * @adapter: HDD adapter
2504 * @reinit: flag to indicate from SSR or normal path
2505 *
2506 * This function maintains the driver state machine it will be invoked from
2507 * startup, reinit and change interface. Depending on the driver state shall
2508 * perform the opening of the modules.
2509 *
2510 * Return: 0 for success; non-zero for failure
2511 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002512int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2513 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302514 bool reinit)
2515{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002516 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302517 qdf_device_t qdf_dev;
2518 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302519 bool unint = false;
2520 void *hif_ctx;
2521
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002522 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302523
2524 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2525 if (!qdf_dev) {
2526 hdd_err("QDF Device Context is Invalid return");
2527 return -EINVAL;
2528 }
2529
Dustin Brown6f427922017-09-19 12:19:00 -07002530 hdd_set_idle_ps_config(hdd_ctx, false);
2531 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302532
Dustin Brown1fe30a82017-10-03 16:13:36 -07002533 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302534 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2535 mutex_unlock(&hdd_ctx->iface_change_lock);
2536 hdd_info("Driver modules already Enabled");
2537 EXIT();
2538 return 0;
2539 }
2540
Dustin Brown1fe30a82017-10-03 16:13:36 -07002541 hdd_ctx->start_modules_in_progress = true;
2542
Arun Khandavallifae92942016-08-01 13:31:08 +05302543 switch (hdd_ctx->driver_status) {
2544 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002545 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302546 unint = true;
2547 /* Fall through dont add break here */
2548 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002549 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2550
Dustin Brown26b3d042017-12-21 11:13:27 -08002551 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002552
Arun Khandavallifae92942016-08-01 13:31:08 +05302553 if (!reinit && !unint) {
2554 ret = pld_power_on(qdf_dev->dev);
2555 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002556 hdd_err("Failed to Powerup the device; errno: %d",
2557 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302558 goto release_lock;
2559 }
2560 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002561
2562 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2563 hdd_ctx->config->enable_fw_log);
2564
Arun Khandavallifae92942016-08-01 13:31:08 +05302565 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2566 qdf_dev->bus_type,
2567 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2568 HIF_ENABLE_TYPE_PROBE);
2569 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002570 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302571 goto power_down;
2572 }
2573
2574 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302575 if (!hif_ctx) {
2576 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002577 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302578 goto power_down;
2579 }
2580
Arun Khandavallifae92942016-08-01 13:31:08 +05302581 status = ol_cds_init(qdf_dev, hif_ctx);
2582 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002583 hdd_err("No Memory to Create BMI Context; status: %d",
2584 status);
2585 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302586 goto hif_close;
2587 }
2588
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002589 ret = hdd_update_config(hdd_ctx);
2590 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002591 hdd_err("Failed to update configuration; errno: %d",
2592 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002593 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002594 }
2595
gbian62edd7e2017-03-07 13:12:13 +08002596 hdd_update_cds_ac_specs_params(hdd_ctx);
2597
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302598 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002599 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002600 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002601 ret = qdf_status_to_os_return(status);
2602 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302603 }
2604
Mukul Sharma9d797a02017-01-05 20:26:03 +05302605 /* initalize components configurations after psoc open */
2606 ret = hdd_update_components_config(hdd_ctx);
2607 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002608 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302609 ret);
2610 goto close;
2611 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002612 status = cds_dp_open(hdd_ctx->hdd_psoc);
2613 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002614 hdd_err("Failed to Open cds post open; status: %d",
2615 status);
2616 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002617 goto close;
2618 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302619
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002620 /*
2621 * NAN compoenet requires certian operations like, open adapter,
2622 * close adapter, etc. to be initiated by HDD, for those
2623 * register HDD callbacks with UMAC's NAN componenet.
2624 */
2625 hdd_nan_register_callbacks(hdd_ctx);
2626
Arun Khandavallifae92942016-08-01 13:31:08 +05302627 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2628
Jeff Johnson3a280122017-09-13 07:42:00 -07002629 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302630 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002631 hdd_err("Failed to pre-enable CDS; status: %d", status);
2632 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002633 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302634 }
2635
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002636 hdd_register_policy_manager_callback(
2637 hdd_ctx->hdd_psoc);
2638
Amar Singhal0928b192017-12-01 10:50:54 -08002639 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2640
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302641 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302642 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002643 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302644
Arun Khandavallifae92942016-08-01 13:31:08 +05302645 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002646 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302647 break;
2648 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302649
2650 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002651 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2652 if (ret) {
2653 hdd_err("HDD IPA UC reinit failed; errno: %d",
2654 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002655 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002656 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302657 }
2658
Arun Khandavallifae92942016-08-01 13:31:08 +05302659 /* Fall through dont add break here */
2660 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002661 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2662
Arun Khandavallifae92942016-08-01 13:31:08 +05302663 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002664 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002665 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002666 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302667 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302668 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2669 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002670 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302671 break;
2672 }
Dustin Browndca39692017-11-09 15:30:25 -08002673
2674 ret = hdd_configure_cds(hdd_ctx, adapter);
2675 if (ret) {
2676 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002677 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302678 }
Dustin Browndca39692017-11-09 15:30:25 -08002679
Komal Seelamf2136bb2016-09-28 18:30:44 +05302680 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002681
Arun Khandavallifae92942016-08-01 13:31:08 +05302682 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002683 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302684 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002685
Arun Khandavallifae92942016-08-01 13:31:08 +05302686 default:
2687 hdd_err("WLAN start invoked in wrong state! :%d\n",
2688 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002689 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302690 goto release_lock;
2691 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002692
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302693 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002694 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2695 ret = hdd_update_country_code(hdd_ctx);
2696 if (ret)
2697 hdd_err("Failed to update command line country code!");
2698 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302699 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002700
Arun Khandavallifae92942016-08-01 13:31:08 +05302701 EXIT();
Dustin Brown550f6d22017-12-14 15:44:01 -08002702
Arun Khandavallifae92942016-08-01 13:31:08 +05302703 return 0;
2704
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002705post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002706 cds_post_disable();
Amar Singhal410675c2018-01-10 12:14:21 -08002707 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Dustin Brownbd68fe12017-11-21 15:28:52 -08002708 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002709
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002710cds_txrx_free:
2711 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002712
Arun Khandavallifae92942016-08-01 13:31:08 +05302713close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002714 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002715 hdd_info("Wlan transition aborted (now CLOSED)");
2716
Jeff Johnsone4b14592017-09-13 14:23:33 -07002717 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302718
Dustin Brown28b17892017-10-10 13:29:38 -07002719deinit_config:
2720 cds_deinit_ini_config();
2721
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002722cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302723 ol_cds_free();
2724
2725hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002726 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2727 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302728power_down:
2729 if (!reinit && !unint)
2730 pld_power_off(qdf_dev->dev);
2731release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302732 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302733 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002734
2735 /* many adapter resources are not freed by design in SSR case */
2736 if (!reinit)
2737 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002738 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002739
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302740 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002741
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002742 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302743}
2744
Naveen Rawat910726a2017-03-06 11:42:51 -08002745#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002746static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002747{
2748 int ret = os_if_wifi_pos_register_nl();
2749
2750 if (ret)
2751 hdd_err("os_if_wifi_pos_register_nl failed");
2752
2753 return ret;
2754}
2755
2756static int hdd_deactivate_wifi_pos(void)
2757{
2758 int ret = os_if_wifi_pos_deregister_nl();
2759
2760 if (ret)
2761 hdd_err("os_if_wifi_pos_deregister_nl failed");
2762
2763 return ret;
2764}
2765
2766/**
2767 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2768 * @hdd_ctx: hdd context
2769 *
2770 * Return: status of operation
2771 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002772static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002773{
2774 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2775 struct hdd_config *cfg = hdd_ctx->config;
2776
2777 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2778 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2779 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2780 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2781 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2782 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2783 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2784 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2785}
2786#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002787static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002788{
2789 return oem_activate_service(hdd_ctx);
2790}
2791
2792static int hdd_deactivate_wifi_pos(void)
2793{
2794 return 0;
2795}
2796
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002797static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002798{
2799}
2800#endif
2801
Arun Khandavallifae92942016-08-01 13:31:08 +05302802/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803 * __hdd_open() - HDD Open function
2804 * @dev: Pointer to net_device structure
2805 *
2806 * This is called in response to ifconfig up
2807 *
2808 * Return: 0 for success; non-zero for failure
2809 */
2810static int __hdd_open(struct net_device *dev)
2811{
Jeff Johnson9d295242017-08-29 14:39:48 -07002812 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002813 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814 int ret;
2815
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002816 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302817 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002818 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002819
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302820 /* Nothing to be done if device is unloading */
2821 if (cds_is_driver_unloading()) {
2822 hdd_err("Driver is unloading can not open the hdd");
2823 return -EBUSY;
2824 }
2825
Dustin Brown01847752017-10-25 13:56:27 -07002826 if (cds_is_driver_recovering()) {
2827 hdd_err("WLAN is currently recovering; Please try again.");
2828 return -EBUSY;
2829 }
2830
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302831 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2832 hdd_err("con_mode_handler is in progress; Please try again.");
2833 return -EBUSY;
2834 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302835
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302836 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302837 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2838
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302839 /*
2840 * This scenario can be hit in cases where in the wlan driver after
2841 * registering the netdevices and there is a failure in driver
2842 * initialization. So return error gracefully because the netdevices
2843 * will be de-registered as part of the load failure.
2844 */
2845
2846 if (!cds_is_driver_loaded()) {
2847 hdd_err("Failed to start the wlan driver!!");
2848 ret = -EIO;
2849 goto err_hdd_hdd_init_deinit_lock;
2850 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302851
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002852
Arun Khandavallifae92942016-08-01 13:31:08 +05302853 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2854 if (ret) {
2855 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302856 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302857 }
2858
2859
2860 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2861 ret = hdd_start_adapter(adapter);
2862 if (ret) {
2863 hdd_err("Failed to start adapter :%d",
2864 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302865 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302866 }
2867 }
2868
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2870 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002871 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002872 /* Enable TX queues only when we are connected */
2873 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302874 WLAN_START_ALL_NETIF_QUEUE,
2875 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002876 }
2877
Naveen Rawat286def52016-09-23 15:38:02 -07002878 /* Enable carrier and transmit queues for NDI */
2879 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002880 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002881 wlan_hdd_netif_queue_control(adapter,
2882 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2883 WLAN_CONTROL_PATH);
2884 }
2885
Naveen Rawat910726a2017-03-06 11:42:51 -08002886 hdd_populate_wifi_pos_cfg(hdd_ctx);
2887
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302888err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302889 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302890 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002891 return ret;
2892}
2893
Arun Khandavallifae92942016-08-01 13:31:08 +05302894
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002895/**
2896 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2897 * @dev: Pointer to net_device structure
2898 *
2899 * This is called in response to ifconfig up
2900 *
2901 * Return: 0 for success; non-zero for failure
2902 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002903static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002904{
2905 int ret;
2906
2907 cds_ssr_protect(__func__);
2908 ret = __hdd_open(dev);
2909 cds_ssr_unprotect(__func__);
2910
2911 return ret;
2912}
2913
2914/**
2915 * __hdd_stop() - HDD stop function
2916 * @dev: Pointer to net_device structure
2917 *
2918 * This is called in response to ifconfig down
2919 *
2920 * Return: 0 for success; non-zero for failure
2921 */
2922static int __hdd_stop(struct net_device *dev)
2923{
Jeff Johnson9d295242017-08-29 14:39:48 -07002924 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002925 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 int ret;
2927
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002928 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002929
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302930 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002931 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002932
2933 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302934 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002935 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002936
2937 /* Nothing to be done if the interface is not opened */
2938 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002939 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002940 return -ENODEV;
2941 }
2942
2943 /* Make sure the interface is marked as closed */
2944 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302945
2946 hdd_debug("Disabling Auto Power save timer");
2947 sme_ps_disable_auto_ps_timer(
2948 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002949 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302950
2951 /*
2952 * Disable TX on the interface, after this hard_start_xmit() will not
2953 * be called on that interface
2954 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002955 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2956 hdd_device_mode_to_string(adapter->device_mode),
2957 adapter->device_mode);
2958
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302959 wlan_hdd_netif_queue_control(adapter,
2960 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2961 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002962
2963 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002964 * NAN data interface is different in some sense. The traffic on NDI is
2965 * bursty in nature and depends on the need to transfer. The service
2966 * layer may down the interface after the usage and up again when
2967 * required. In some sense, the NDI is expected to be available
2968 * (like SAP) iface until NDI delete request is issued by the service
2969 * layer. Skip BSS termination and adapter deletion for NAN Data
2970 * interface (NDI).
2971 */
2972 if (WLAN_HDD_IS_NDI(adapter))
2973 return 0;
2974
2975 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002976 * The interface is marked as down for outside world (aka kernel)
2977 * But the driver is pretty much alive inside. The driver needs to
2978 * tear down the existing connection on the netdev (session)
2979 * cleanup the data pipes and wait until the control plane is stabilized
2980 * for this interface. The call also needs to wait until the above
2981 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002982 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002983 * That is intentional to be able to scan if it is a STA/P2P interface
2984 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002985 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002986
2987 /* DeInit the adapter. This ensures datapath cleanup as well */
2988 hdd_deinit_adapter(hdd_ctx, adapter, true);
2989
Arun Khandavallifae92942016-08-01 13:31:08 +05302990
2991 /*
2992 * Find if any iface is up. If any iface is up then can't put device to
2993 * sleep/power save mode
2994 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302995 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002996 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07002997 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
2998 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302999 hdd_prevent_suspend_timeout(
3000 hdd_ctx->config->iface_change_wait_time,
3001 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303002 }
3003
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004 EXIT();
3005 return 0;
3006}
3007
3008/**
3009 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3010 * @dev: pointer to net_device structure
3011 *
3012 * This is called in response to ifconfig down
3013 *
3014 * Return: 0 for success and error number for failure
3015 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003016static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003017{
3018 int ret;
3019
3020 cds_ssr_protect(__func__);
3021 ret = __hdd_stop(dev);
3022 cds_ssr_unprotect(__func__);
3023
3024 return ret;
3025}
3026
3027/**
3028 * __hdd_uninit() - HDD uninit function
3029 * @dev: Pointer to net_device structure
3030 *
3031 * This is called during the netdev unregister to uninitialize all data
3032 * associated with the device
3033 *
3034 * Return: None
3035 */
3036static void __hdd_uninit(struct net_device *dev)
3037{
Jeff Johnson9d295242017-08-29 14:39:48 -07003038 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003039 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003040
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003041 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003042
3043 do {
3044 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003045 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003046 break;
3047 }
3048
Jeff Johnson399c6272017-08-30 10:51:00 -07003049 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3050 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003051 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003052 break;
3053 }
3054
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003055 if (dev != adapter->dev)
3056 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003057
Jeff Johnson399c6272017-08-30 10:51:00 -07003058 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059
3060 /* after uninit our adapter structure will no longer be valid */
3061 adapter->dev = NULL;
3062 adapter->magic = 0;
3063 } while (0);
3064
3065 EXIT();
3066}
3067
3068/**
3069 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3070 * @dev: pointer to net_device structure
3071 *
3072 * This is called during the netdev unregister to uninitialize all data
3073 * associated with the device
3074 *
3075 * Return: none
3076 */
3077static void hdd_uninit(struct net_device *dev)
3078{
3079 cds_ssr_protect(__func__);
3080 __hdd_uninit(dev);
3081 cds_ssr_unprotect(__func__);
3082}
3083
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003084static int hdd_open_cesium_nl_sock(void)
3085{
3086#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3087 struct netlink_kernel_cfg cfg = {
3088 .groups = WLAN_NLINK_MCAST_GRP_ID,
3089 .input = NULL
3090 };
3091#endif
3092 int ret = 0;
3093
3094#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3095 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3096#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3097 THIS_MODULE,
3098#endif
3099 &cfg);
3100#else
3101 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3102 WLAN_NLINK_MCAST_GRP_ID,
3103 NULL, NULL, THIS_MODULE);
3104#endif
3105
3106 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003107 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003108 ret = -ECONNREFUSED;
3109 }
3110
3111 return ret;
3112}
3113
3114static void hdd_close_cesium_nl_sock(void)
3115{
3116 if (NULL != cesium_nl_srv_sock) {
3117 netlink_kernel_release(cesium_nl_srv_sock);
3118 cesium_nl_srv_sock = NULL;
3119 }
3120}
3121
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122/**
3123 * __hdd_set_mac_address() - set the user specified mac address
3124 * @dev: Pointer to the net device.
3125 * @addr: Pointer to the sockaddr.
3126 *
3127 * This function sets the user specified mac address using
3128 * the command ifconfig wlanX hw ether <mac adress>.
3129 *
3130 * Return: 0 for success, non zero for failure
3131 */
3132static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3133{
Jeff Johnson9d295242017-08-29 14:39:48 -07003134 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003135 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003136 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303137 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138 int ret;
3139
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003140 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141
3142 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3143 ret = wlan_hdd_validate_context(hdd_ctx);
3144 if (0 != ret)
3145 return ret;
3146
Jeff Johnson1e851a12017-10-28 14:36:12 -07003147 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3149
3150 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303151 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152}
3153
3154/**
3155 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3156 * function from SSR
3157 * @dev: pointer to net_device structure
3158 * @addr: Pointer to the sockaddr
3159 *
3160 * This function sets the user specified mac address using
3161 * the command ifconfig wlanX hw ether <mac adress>.
3162 *
3163 * Return: 0 for success.
3164 */
3165static int hdd_set_mac_address(struct net_device *dev, void *addr)
3166{
3167 int ret;
3168
3169 cds_ssr_protect(__func__);
3170 ret = __hdd_set_mac_address(dev, addr);
3171 cds_ssr_unprotect(__func__);
3172
3173 return ret;
3174}
3175
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003176uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177{
3178 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003179
Anurag Chouhan6d760662016-02-20 16:05:43 +05303180 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3182 break;
3183 }
3184
Anurag Chouhan6d760662016-02-20 16:05:43 +05303185 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186 return NULL;
3187
3188 hdd_ctx->config->intfAddrMask |= (1 << i);
3189 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3190}
3191
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003192void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3193 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194{
3195 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003196
Anurag Chouhan6d760662016-02-20 16:05:43 +05303197 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198 if (!memcmp(releaseAddr,
3199 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3200 6)) {
3201 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3202 break;
3203 }
3204 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205}
3206
3207#ifdef WLAN_FEATURE_PACKET_FILTERING
3208/**
3209 * __hdd_set_multicast_list() - set the multicast address list
3210 * @dev: Pointer to the WLAN device.
3211 * @skb: Pointer to OS packet (sk_buff).
3212 *
3213 * This funciton sets the multicast address list.
3214 *
3215 * Return: None
3216 */
3217static void __hdd_set_multicast_list(struct net_device *dev)
3218{
Jeff Johnson9d295242017-08-29 14:39:48 -07003219 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220 int i = 0, status;
3221 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003222 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303223 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3224 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3225 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003226
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003227 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303228 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303229 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303232 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303233 goto out;
3234
Dustin Brownc788acb2017-08-01 17:43:51 -07003235 status = hdd_validate_adapter(adapter);
3236 if (status)
3237 goto out;
3238
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303239 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3240 hdd_err("%s: Driver module is closed", __func__);
3241 return;
3242 }
3243
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303244 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3245 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003246 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303247 goto out;
3248 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303250 /* Delete already configured multicast address list */
3251 if (adapter->mc_addr_list.mc_cnt > 0) {
3252 hdd_info("clear previously configured MC address list");
3253 hdd_disable_and_flush_mc_addr_list(adapter,
3254 pmo_mc_list_change_notify);
3255 }
3256
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003257 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003258 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303259 hdd_disable_and_flush_mc_addr_list(adapter,
3260 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261 } else {
3262 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303263 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003264 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303265 pmo_ucfg_max_mc_addr_supported(psoc));
3266 hdd_disable_and_flush_mc_addr_list(adapter,
3267 pmo_mc_list_change_notify);
3268 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003271 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303272 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273 if (i == mc_count)
3274 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303275 memset(&(mc_list_request->mc_addr[i].bytes),
3276 0, ETH_ALEN);
3277 memcpy(&(mc_list_request->mc_addr[i].bytes),
3278 ha->addr, ETH_ALEN);
3279 hdd_info("mlist[%d] = %pM", i,
3280 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281 i++;
3282 }
3283 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303284
3285 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003286 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303287 mc_list_request->count = mc_count;
3288 status = hdd_cache_mc_addr_list(mc_list_request);
3289 if (status == 0) {
3290 hdd_enable_mc_addr_filtering(adapter,
3291 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003292 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303293 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003294 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303295out:
3296 if (mc_list_request)
3297 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303298 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299}
3300
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303301
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003302/**
3303 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3304 * @dev: pointer to net_device
3305 *
3306 * Return: none
3307 */
3308static void hdd_set_multicast_list(struct net_device *dev)
3309{
3310 cds_ssr_protect(__func__);
3311 __hdd_set_multicast_list(dev);
3312 cds_ssr_unprotect(__func__);
3313}
3314#endif
3315
3316/**
3317 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3318 * @dev: Pointer to the WLAN device.
3319 * @skb: Pointer to OS packet (sk_buff).
3320 *
3321 * This function is registered with the Linux OS for network
3322 * core to decide which queue to use first.
3323 *
3324 * Return: ac, Queue Index/access category corresponding to UP in IP header
3325 */
3326static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3327#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3328 , void *accel_priv
3329#endif
3330#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3331 , select_queue_fallback_t fallback
3332#endif
3333)
3334{
3335 return hdd_wmm_select_queue(dev, skb);
3336}
3337
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003338static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339 .ndo_open = hdd_open,
3340 .ndo_stop = hdd_stop,
3341 .ndo_uninit = hdd_uninit,
3342 .ndo_start_xmit = hdd_hard_start_xmit,
3343 .ndo_tx_timeout = hdd_tx_timeout,
3344 .ndo_get_stats = hdd_get_stats,
3345 .ndo_do_ioctl = hdd_ioctl,
3346 .ndo_set_mac_address = hdd_set_mac_address,
3347 .ndo_select_queue = hdd_select_queue,
3348#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003349 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003350#endif
3351};
3352
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003353/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003354static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003355 .ndo_open = hdd_mon_open,
3356 .ndo_stop = hdd_stop,
3357 .ndo_get_stats = hdd_get_stats,
3358};
3359
3360/**
3361 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003362 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003363 * Return: None
3364 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003365void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003367 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003368 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003369 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003370 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003371}
3372
3373/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003374 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3375 * @hdd_ctx: global hdd context
3376 * @macAddr: mac address to assign to the interface
3377 * @name: User-visible name of the interface
3378 *
3379 * hdd adapter pointer would point to the netdev->priv space, this function
3380 * would retrive the pointer, and setup the hdd adapter configuration.
3381 *
3382 * Return: the pointer to hdd adapter, otherwise NULL
3383 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003384static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003386 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003387 const char *name)
3388{
Jeff Johnson5505db82017-11-02 21:19:23 -07003389 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003390 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003391 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303392 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003393 /*
3394 * cfg80211 initialization and registration....
3395 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003396 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003397#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3398 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003399#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003400 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3401 hdd_mon_mode_ether_setup : ether_setup),
3402 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003403
Jeff Johnson5505db82017-11-02 21:19:23 -07003404 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405
3406 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003407 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408
Jeff Johnson9d295242017-08-29 14:39:48 -07003409 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003410 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303411 qdf_mem_set(sta_ctx->conn_info.staId,
3412 sizeof(sta_ctx->conn_info.staId),
3413 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003414 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003415 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003417 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003418
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303419 qdf_status = qdf_event_create(
3420 &adapter->qdf_session_open_event);
3421 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3422 hdd_err("Session open QDF event init failed!");
3423 free_netdev(adapter->dev);
3424 return NULL;
3425 }
3426
3427 qdf_status = qdf_event_create(
3428 &adapter->qdf_session_close_event);
3429 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3430 hdd_err("Session close QDF event init failed!");
3431 free_netdev(adapter->dev);
3432 return NULL;
3433 }
3434
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303436 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437 init_completion(&adapter->linkup_event_var);
3438 init_completion(&adapter->cancel_rem_on_chan_var);
3439 init_completion(&adapter->rem_on_chan_ready_event);
3440 init_completion(&adapter->sta_authorized_event);
3441 init_completion(&adapter->offchannel_tx_event);
3442 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003443 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303445 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003446
3447 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003448 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003450 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003451
Jeff Johnson5505db82017-11-02 21:19:23 -07003452 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003454 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003455 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003456 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003457
3458 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003459 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003461 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462
Jeff Johnson5505db82017-11-02 21:19:23 -07003463 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003464
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465 hdd_set_station_ops(adapter->dev);
3466
Jeff Johnson5505db82017-11-02 21:19:23 -07003467 hdd_dev_setup_destructor(dev);
3468 dev->ieee80211_ptr = &adapter->wdev;
3469 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003470 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003471 adapter->wdev.netdev = dev;
3472 /* set dev's parent to underlying device */
3473 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474 hdd_wmm_init(adapter);
3475 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303476 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 }
3478
3479 return adapter;
3480}
3481
Jeff Johnson9d295242017-08-29 14:39:48 -07003482static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003484 struct net_device *dev = adapter->dev;
3485 int ret;
3486
3487 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003489 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003490 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3491
3492 ret = dev_alloc_name(dev, dev->name);
3493 if (ret < 0) {
3494 hdd_err(
3495 "unable to get dev name: %s, err = 0x%x",
3496 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303497 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498 }
3499 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003500
3501 ret = register_netdevice(dev);
3502 if (ret) {
3503 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3504 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303505 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003506 }
3507 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003508 ret = register_netdev(dev);
3509 if (ret) {
3510 hdd_err("register_netdev(%s) failed, err = 0x%x",
3511 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303512 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003513 }
3514 }
3515 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3516
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003517 EXIT();
3518
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303519 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520}
3521
Krunal Sonib51eec72017-11-20 21:53:01 -08003522QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003523{
Krunal Sonib51eec72017-11-20 21:53:01 -08003524 struct hdd_adapter *adapter;
3525 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003526
Krunal Sonib51eec72017-11-20 21:53:01 -08003527 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3528 if (!hdd_ctx) {
3529 hdd_err("Invalid HDD_CTX");
3530 return QDF_STATUS_E_FAILURE;
3531 }
3532
3533 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3534 if (NULL == adapter) {
3535 hdd_err("NULL adapter");
3536 return QDF_STATUS_E_INVAL;
3537 }
3538 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303539 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003540 hdd_debug("session %d opened", adapter->session_id);
3541
3542 return QDF_STATUS_SUCCESS;
3543}
3544
3545QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3546{
3547 struct hdd_adapter *adapter;
3548 struct hdd_context *hdd_ctx;
3549
3550 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3551 if (!hdd_ctx) {
3552 hdd_err("Invalid HDD_CTX");
3553 return QDF_STATUS_E_FAILURE;
3554 }
3555
3556 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003558 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303559 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560 }
3561
3562 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003563 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303564 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003565 }
3566
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003567 /*
3568 * For NAN Data interface, the close session results in the final
3569 * indication to the userspace
3570 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003571 if (adapter->device_mode == QDF_NDI_MODE)
3572 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003573
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003574 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3575
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576 /*
3577 * We can be blocked while waiting for scheduled work to be
3578 * flushed, and the adapter structure can potentially be freed, in
3579 * which case the magic will have been reset. So make sure the
3580 * magic is still good, and hence the adapter structure is still
3581 * valid, before signaling completion
3582 */
3583 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303584 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303586 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587}
3588
Jeff Johnson9d295242017-08-29 14:39:48 -07003589int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590{
Dustin Brownd28772b2017-03-17 14:16:07 -07003591 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592
Dustin Brownd28772b2017-03-17 14:16:07 -07003593 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003594 if (QDF_IS_STATUS_ERROR(status))
3595 return qdf_status_to_os_return(status);
3596
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003597 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003598 if (QDF_IS_STATUS_ERROR(status))
3599 return qdf_status_to_os_return(status);
3600
3601 if (wma_capability_enhanced_mcast_filter())
3602 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3603 else
3604 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003605
3606 return qdf_status_to_os_return(status);
3607}
3608
Jeff Johnson9d295242017-08-29 14:39:48 -07003609int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003610{
3611 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003612 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003613 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003614 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003615
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003616 vdev_id = adapter->session_id;
3617 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003618
3619 /* vdev created sanity check */
3620 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003621 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003622 return -EINVAL;
3623 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003624 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003625
Dustin Brownd28772b2017-03-17 14:16:07 -07003626 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303627 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003628 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003629 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003630 if (QDF_IS_STATUS_ERROR(status)) {
3631 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003632 errno = qdf_status_to_os_return(status);
3633 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003634 }
3635
3636 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303637 status = qdf_wait_for_event_completion(
3638 &adapter->qdf_session_close_event,
3639 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3640 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003641 if (adapter->device_mode == QDF_NDI_MODE)
3642 hdd_ndp_session_end_handler(adapter);
3643 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303644 adapter->session_id = HDD_SESSION_ID_INVALID;
3645 if (QDF_STATUS_E_TIMEOUT != status) {
3646 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003647 errno = -ETIMEDOUT;
3648 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303649 } else if (adapter->qdf_session_close_event.force_set) {
3650 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003651 errno = -EINVAL;
3652 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303653 } else {
3654 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003655 errno = -EINVAL;
3656 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303657 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003658 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003659
Yue Maf9782842017-05-08 12:49:49 -07003660release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003661 /*
3662 * In SSR or driver unloading case, directly exit may cause objects
3663 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003664 */
Frank Liuc66d4bf2018-01-26 16:18:18 +08003665 if (errno && !(cds_is_driver_recovering() || cds_is_driver_unloading()))
Jiachao Wu2c42c222018-01-15 18:13:19 +08003666 return errno;
3667
Sandeep Puligillaef415362017-08-30 16:37:13 -07003668 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003669 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003670 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003671 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003672 return errno;
3673 }
3674
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003675 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003676
3677 return 0;
3678}
3679
Krunal Sonib51eec72017-11-20 21:53:01 -08003680static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3681 struct sme_session_params *session_param,
3682 csr_roam_completeCallback callback,
3683 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003684{
Dustin Brownd28772b2017-03-17 14:16:07 -07003685 uint32_t type;
3686 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003687 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003688
3689 /* determine vdev (sub)type */
3690 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303691 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003692 hdd_err("failed to get vdev type: %d", status);
3693 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003695 session_param->sme_session_id = adapter->session_id;
3696 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3697 session_param->type_of_persona = type;
3698 session_param->subtype_of_persona = sub_type;
3699 session_param->session_open_cb = hdd_sme_open_session_callback;
3700 session_param->session_close_cb = hdd_sme_close_session_callback;
3701 session_param->callback = callback;
3702 session_param->callback_ctx = callback_ctx;
3703
3704 return 0;
3705}
3706
3707int hdd_vdev_create(struct hdd_adapter *adapter,
3708 csr_roam_completeCallback callback, void *ctx)
3709{
3710 QDF_STATUS status;
3711 int errno;
3712 struct hdd_context *hdd_ctx;
3713 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003714
3715 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003716
3717 /* do vdev create via objmgr */
3718 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003719 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003720 if (errno) {
3721 hdd_err("failed to create objmgr vdev: %d", errno);
3722 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003724
3725 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303726 status = qdf_event_reset(&adapter->qdf_session_open_event);
3727 if (QDF_STATUS_SUCCESS != status) {
3728 hdd_err("failed to reinit session open event");
3729 return -EINVAL;
3730 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003731 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3732 callback, ctx);
3733 if (errno) {
3734 hdd_err("failed to populating SME params");
3735 goto objmgr_vdev_destroy_procedure;
3736 }
3737
3738 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003739 if (QDF_IS_STATUS_ERROR(status)) {
3740 hdd_err("failed to open sme session: %d", status);
3741 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003742 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003743 }
3744
3745 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303746 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3747 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3748 if (QDF_STATUS_SUCCESS != status) {
3749 if (adapter->qdf_session_open_event.force_set) {
3750 /*
3751 * SSR/PDR has caused shutdown, which has forcefully
3752 * set the event. Return without the closing session.
3753 */
3754 adapter->session_id = HDD_SESSION_ID_INVALID;
3755 hdd_err("Session open event forcefully set");
3756 return -EINVAL;
3757 } else {
3758 if (QDF_STATUS_E_TIMEOUT == status)
3759 hdd_err("Session failed to open within timeout period");
3760 else
3761 hdd_err("Failed to wait for session open event(status-%d)",
3762 status);
3763 errno = -ETIMEDOUT;
3764 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3765 goto hdd_vdev_destroy_procedure;
3766 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003767 }
3768
3769 /* firmware ready for component communication, raise vdev_ready event */
3770 errno = hdd_vdev_ready(adapter);
3771 if (errno) {
3772 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003773 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003774 }
3775
Jeff Johnson1b780e42017-10-31 14:11:45 -07003776 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003777
3778 return 0;
3779
3780 /*
3781 * Due to legacy constraints, we need to destroy in the same order as
3782 * create. So, split error handling into 2 cases to accommodate.
3783 */
3784
Krunal Soni4a020c72017-10-30 20:58:40 -07003785objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003786 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003787
3788 return errno;
3789
Krunal Soni4a020c72017-10-30 20:58:40 -07003790hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003791 QDF_BUG(!hdd_vdev_destroy(adapter));
3792
3793 return errno;
3794}
3795
Jeff Johnson9d295242017-08-29 14:39:48 -07003796QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003797{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003798 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003799 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003800 QDF_STATUS status;
3801 int ret_val;
3802
Dustin Brownd28772b2017-03-17 14:16:07 -07003803 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3804 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3805 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003806 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003808 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003809 status = hdd_register_wext(adapter->dev);
3810 if (QDF_IS_STATUS_ERROR(status)) {
3811 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003812 goto error_register_wext;
3813 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003814 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003815
Himanshu Agarwalb229a142017-12-21 10:16:45 +05303816 hdd_debug("Disabling Green AP");
3817 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev, false);
3818 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
3819
Jeff Johnsond377dce2017-10-04 10:32:42 -07003820 qdf_mem_set(sta_ctx->conn_info.staId,
3821 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303822
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003823 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003824 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303825 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003827 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003828 hdd_ctx->config->OperatingChannel;
3829
3830 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003831 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003832
3833 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303834 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003835 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003836 status, status);
3837 goto error_init_txrx;
3838 }
3839
3840 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3841
3842 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303843 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003844 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845 status, status);
3846 goto error_wmm_init;
3847 }
3848
3849 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3850
Jeff Johnson1b780e42017-10-31 14:11:45 -07003851 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003852 WMI_PDEV_PARAM_BURST_ENABLE,
3853 hdd_ctx->config->enableSifsBurst,
3854 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003855 if (ret_val)
3856 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303858 /*
3859 * In case of USB tethering, LRO is disabled. If SSR happened
3860 * during that time, then as part of SSR init, do not enable
3861 * the LRO again. Keep the LRO state same as before SSR.
3862 */
3863 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003864 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303865
3866 /* rcpi info initialization */
3867 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3868
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303869 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003871error_wmm_init:
3872 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3873 hdd_deinit_tx_rx(adapter);
3874error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003875 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003877 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003879 return status;
3880}
3881
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303882/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003883 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303884 * @hdd_ctx: global hdd context
3885 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003886 * @rtnl_held: Used to indicate whether or not the caller is holding
3887 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303888 *
3889 * This function De-initializes the STA/P2P/OCB adapter.
3890 *
3891 * Return: None.
3892 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003893static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003894 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003895 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303896{
3897 ENTER_DEV(adapter->dev);
3898
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303899 if (adapter->dev) {
3900 if (rtnl_held)
3901 adapter->dev->wireless_handlers = NULL;
3902 else {
3903 rtnl_lock();
3904 adapter->dev->wireless_handlers = NULL;
3905 rtnl_unlock();
3906 }
3907 }
3908
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303909 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3910 hdd_deinit_tx_rx(adapter);
3911 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3912 }
3913
3914 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3915 hdd_wmm_adapter_close(adapter);
3916 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3917 }
3918
Krunal Sonib51eec72017-11-20 21:53:01 -08003919
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303920 EXIT();
3921}
3922
Krunal Sonib51eec72017-11-20 21:53:01 -08003923void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3924 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925 bool rtnl_held)
3926{
3927 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303928
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003930 case QDF_STA_MODE:
3931 case QDF_P2P_CLIENT_MODE:
3932 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003933 case QDF_IBSS_MODE:
3934 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003936 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 break;
3938 }
3939
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003940 case QDF_SAP_MODE:
3941 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003943 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003944 break;
3945 }
3946
3947 default:
3948 break;
3949 }
3950
3951 EXIT();
3952}
3953
Jeff Johnson9d295242017-08-29 14:39:48 -07003954static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003955 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956{
Jeff Johnson5505db82017-11-02 21:19:23 -07003957 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958
3959 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003960 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003961 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003962 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963 return;
3964 }
3965
Rajeev Kumardca5f812016-02-04 17:28:06 -08003966 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303967
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968 /*
3969 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3970 * the driver is almost closed and cannot handle either control
3971 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003972 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3973 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974 * is not right. Setting this flag helps hdd_stop() to recognize that
3975 * the interface is closed and restricts any operations on that
3976 */
3977 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3978
3979 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003980 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003981 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003982 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003983 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984 /*
3985 * Note that the adapter is no longer valid at this point
3986 * since the memory has been reclaimed
3987 */
3988 }
3989}
3990
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003991static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003992 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993{
Jeff Johnson9d295242017-08-29 14:39:48 -07003994 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003995
Dustin Brown920397d2017-12-13 16:27:50 -08003996 hdd_for_each_adapter(hdd_ctx, adapter) {
3997 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
3998 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303999 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 }
Dustin Brown920397d2017-12-13 16:27:50 -08004002
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304003 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004005
Arun Khandavalli2358d522016-05-16 18:05:37 +05304006#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4007/**
4008 * hdd_set_fw_log_params() - Set log parameters to FW
4009 * @hdd_ctx: HDD Context
4010 * @adapter: HDD Adapter
4011 *
4012 * This function set the FW Debug log level based on the INI.
4013 *
4014 * Return: None
4015 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004016static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004017 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304018{
4019 uint8_t count = 0, numentries = 0,
4020 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4021 uint32_t value = 0;
4022 int ret;
4023
Arun Khandavallifae92942016-08-01 13:31:08 +05304024 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4025 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004026 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304027 return;
4028 }
4029
Arun Khandavallifae92942016-08-01 13:31:08 +05304030 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304031 hdd_ctx->fw_log_settings.dl_type =
4032 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004033 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304034 WMI_DBGLOG_TYPE,
4035 hdd_ctx->config->enableFwLogType,
4036 DBG_CMD);
4037 if (ret != 0)
4038 hdd_err("Failed to enable FW log type ret %d",
4039 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304040
4041 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304042 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004043 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304044 WMI_DBGLOG_LOG_LEVEL,
4045 hdd_ctx->config->enableFwLogLevel,
4046 DBG_CMD);
4047 if (ret != 0)
4048 hdd_err("Failed to enable FW log level ret %d",
4049 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304050
4051 hdd_string_to_u8_array(
4052 hdd_ctx->config->enableFwModuleLogLevel,
4053 moduleloglevel,
4054 &numentries,
4055 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4056
4057 while (count < numentries) {
4058 /*
4059 * FW module log level input string looks like
4060 * below:
4061 * gFwDebugModuleLoglevel=<FW Module ID>,
4062 * <Log Level>,...
4063 * For example:
4064 * gFwDebugModuleLoglevel=
4065 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4066 * Above input string means :
4067 * For FW module ID 1 enable log level 0
4068 * For FW module ID 2 enable log level 1
4069 * For FW module ID 3 enable log level 2
4070 * For FW module ID 4 enable log level 3
4071 * For FW module ID 5 enable log level 4
4072 * For FW module ID 6 enable log level 5
4073 * For FW module ID 7 enable log level 6
4074 */
4075
Nishank Aggarwale239d962017-03-03 12:26:02 +05304076 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4077 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4078 hdd_err("Module id %d and dbglog level %d input length is more than max",
4079 moduleloglevel[count],
4080 moduleloglevel[count + 1]);
4081 return;
4082 }
4083
4084 value = moduleloglevel[count] << 16;
4085 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004086 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304087 WMI_DBGLOG_MOD_LOG_LEVEL,
4088 value, DBG_CMD);
4089 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304090 hdd_err("Failed to enable FW module log level %d ret %d",
4091 value, ret);
4092
4093 count += 2;
4094 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304095
Arun Khandavalli2358d522016-05-16 18:05:37 +05304096}
4097#else
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}
4102
4103#endif
4104
4105/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004106 * hdd_configure_chain_mask() - programs chain mask to firmware
4107 * @adapter: HDD adapter
4108 *
4109 * Return: 0 on success or errno on failure
4110 */
4111static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4112{
4113 int ret_val;
4114 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4115
4116 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4117 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4118 hdd_ctx->config->txchainmask1x1,
4119 hdd_ctx->config->rxchainmask1x1);
4120 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4121 hdd_ctx->config->dual_mac_feature_disable,
4122 hdd_ctx->config->tx_chain_mask_2g,
4123 hdd_ctx->config->rx_chain_mask_2g);
4124 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4125 hdd_ctx->config->tx_chain_mask_5g,
4126 hdd_ctx->config->rx_chain_mask_5g);
4127
4128 if (hdd_ctx->config->enable2x2) {
4129 hdd_info("2x2 enabled. skip chain mask programming");
4130 return 0;
4131 }
4132
4133 if (hdd_ctx->config->txchainmask1x1) {
4134 ret_val = sme_cli_set_command(adapter->session_id,
4135 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4136 hdd_ctx->config->txchainmask1x1,
4137 PDEV_CMD);
4138 if (ret_val)
4139 goto error;
4140 }
4141
4142 if (hdd_ctx->config->rxchainmask1x1) {
4143 ret_val = sme_cli_set_command(adapter->session_id,
4144 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4145 hdd_ctx->config->rxchainmask1x1,
4146 PDEV_CMD);
4147 if (ret_val)
4148 goto error;
4149 }
4150
4151 if (hdd_ctx->lte_coex_ant_share) {
4152 hdd_info("lte ant sharing enabled. skip per band chain mask");
4153 return 0;
4154 }
4155
4156 if (hdd_ctx->config->txchainmask1x1 ||
4157 hdd_ctx->config->rxchainmask1x1) {
4158 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4159 return 0;
4160 }
4161
4162 if (!hdd_ctx->config->dual_mac_feature_disable) {
4163 hdd_info("DBS enabled. skip per band chain mask");
4164 return 0;
4165 }
4166
4167 if (hdd_ctx->config->tx_chain_mask_2g) {
4168 ret_val = sme_cli_set_command(adapter->session_id,
4169 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4170 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4171 if (0 != ret_val)
4172 goto error;
4173 }
4174
4175 if (hdd_ctx->config->rx_chain_mask_2g) {
4176 ret_val = sme_cli_set_command(adapter->session_id,
4177 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4178 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4179 if (0 != ret_val)
4180 goto error;
4181 }
4182
4183 if (hdd_ctx->config->tx_chain_mask_5g) {
4184 ret_val = sme_cli_set_command(adapter->session_id,
4185 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4186 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4187 if (0 != ret_val)
4188 goto error;
4189 }
4190
4191 if (hdd_ctx->config->rx_chain_mask_5g) {
4192 ret_val = sme_cli_set_command(adapter->session_id,
4193 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4194 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4195 if (0 != ret_val)
4196 goto error;
4197 }
4198
4199 return 0;
4200
4201error:
4202 hdd_err("WMI PDEV set param failed %d", ret_val);
4203 return -EINVAL;
4204}
4205
4206/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304207 * hdd_set_fw_params() - Set parameters to firmware
4208 * @adapter: HDD adapter
4209 *
4210 * This function Sets various parameters to fw once the
4211 * adapter is started.
4212 *
4213 * Return: 0 on success or errno on failure
4214 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004215int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304216{
4217 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004218 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304219
4220 ENTER_DEV(adapter->dev);
4221
4222 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4223 if (!hdd_ctx)
4224 return -EINVAL;
4225
Dustin Brown732ab9c2017-06-15 13:24:09 -07004226 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4227 hdd_debug("FTM Mode is active; nothing to do");
4228 return 0;
4229 }
4230
Jeff Johnson1b780e42017-10-31 14:11:45 -07004231 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304232 WMI_PDEV_PARAM_DTIM_SYNTH,
4233 hdd_ctx->config->enable_lprx, PDEV_CMD);
4234 if (ret) {
4235 hdd_err("Failed to set LPRx");
4236 goto error;
4237 }
4238
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304239 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004240 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304241 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4242 hdd_ctx->config->upper_brssi_thresh);
4243
Jeff Johnson1b780e42017-10-31 14:11:45 -07004244 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304245 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4246 hdd_ctx->config->lower_brssi_thresh);
4247
Jeff Johnson1b780e42017-10-31 14:11:45 -07004248 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304249 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4250 hdd_ctx->config->enable_dtim_1chrx);
4251 }
4252
Dustin Brown732ab9c2017-06-15 13:24:09 -07004253 if (hdd_ctx->config->enable2x2) {
4254 hdd_debug("configuring 2x2 mode fw params");
4255
Jeff Johnson1b780e42017-10-31 14:11:45 -07004256 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004257 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4258 hdd_ctx->config->enable_cck_tx_fir_override,
4259 PDEV_CMD);
4260 if (ret) {
4261 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4262 ret);
4263 goto error;
4264 }
4265 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304266#define HDD_DTIM_1CHAIN_RX_ID 0x5
4267#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004268 hdd_debug("configuring 1x1 mode fw params");
4269
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004270 /*
4271 * Disable DTIM 1 chain Rx when in 1x1,
4272 * we are passing two value
4273 * as param_id << 29 | param_value.
4274 * Below param_value = 0(disable)
4275 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004276 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004277 WMI_STA_SMPS_PARAM_CMDID,
4278 HDD_DTIM_1CHAIN_RX_ID <<
4279 HDD_SMPS_PARAM_VALUE_S,
4280 VDEV_CMD);
4281 if (ret) {
4282 hdd_err("DTIM 1 chain set failed %d", ret);
4283 goto error;
4284 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304285
Arun Khandavalli2358d522016-05-16 18:05:37 +05304286#undef HDD_DTIM_1CHAIN_RX_ID
4287#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004288
4289 if (hdd_configure_chain_mask(adapter))
4290 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004291 }
4292
Jeff Johnson1b780e42017-10-31 14:11:45 -07004293 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004294 WMI_PDEV_PARAM_HYST_EN,
4295 hdd_ctx->config->enableMemDeepSleep,
4296 PDEV_CMD);
4297 if (ret) {
4298 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4299 goto error;
4300 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304301
Jeff Johnson1b780e42017-10-31 14:11:45 -07004302 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004303 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4304 hdd_ctx->config->rts_profile,
4305 VDEV_CMD);
4306 if (ret) {
4307 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4308 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304309 }
4310
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004311 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4312
Jeff Johnson1b780e42017-10-31 14:11:45 -07004313 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004314 GEN_VDEV_PARAM_AMSDU,
4315 hdd_ctx->config->max_amsdu_num,
4316 GEN_CMD);
4317 if (ret != 0) {
4318 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4319 goto error;
4320 }
4321
Arun Khandavalli2358d522016-05-16 18:05:37 +05304322 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304323 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004324
Arun Khandavalli2358d522016-05-16 18:05:37 +05304325 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304326
Arun Khandavalli2358d522016-05-16 18:05:37 +05304327error:
4328 return -EINVAL;
4329}
4330
Ryan Hsu07495ea2016-01-21 15:25:39 -08004331/**
4332 * hdd_open_adapter() - open and setup the hdd adatper
4333 * @hdd_ctx: global hdd context
4334 * @session_type: type of the interface to be created
4335 * @iface_name: User-visible name of the interface
4336 * @macAddr: MAC address to assign to the interface
4337 * @name_assign_type: the name of assign type of the netdev
4338 * @rtnl_held: the rtnl lock hold flag
4339 *
4340 * This function open and setup the hdd adpater according to the device
4341 * type request, assign the name, the mac address assigned, and then prepared
4342 * the hdd related parameters, queue, lock and ready to start.
4343 *
4344 * Return: the pointer of hdd adapter, otherwise NULL.
4345 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004346struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004348 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004349 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350{
Jeff Johnson9d295242017-08-29 14:39:48 -07004351 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304352 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353
4354 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4355 /*
4356 * Max limit reached on the number of vdevs configured by the
4357 * host. Return error
4358 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304359 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4360 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004361 return NULL;
4362 }
4363
4364 if (macAddr == NULL) {
4365 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304366 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367 return NULL;
4368 }
4369 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304370 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304371 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4372 " already exists",
4373 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004374 return NULL;
4375 }
4376
4377 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004378 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004379 /* Reset locally administered bit if the device mode is STA */
4380 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304381 hdd_info("locally administered bit reset in sta mode: "
4382 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004384 case QDF_P2P_CLIENT_MODE:
4385 case QDF_P2P_DEVICE_MODE:
4386 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004387 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304388 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004389 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4390 name_assign_type,
4391 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004392
4393 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304394 hdd_err("failed to allocate adapter for session %d",
4395 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 return NULL;
4397 }
4398
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004399 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004401 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304403 else if (QDF_MONITOR_MODE == session_type)
4404 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405 else
4406 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4407
4408 adapter->device_mode = session_type;
4409
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004411 /*
4412 * Workqueue which gets scheduled in IPv4 notification
4413 * callback
4414 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004415 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004417
4418#ifdef WLAN_NS_OFFLOAD
4419 /*
4420 * Workqueue which gets scheduled in IPv6
4421 * notification callback.
4422 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004423 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 hdd_ipv6_notifier_work_queue);
4425#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004426 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004427 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004428 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429
4430 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004431 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304433 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4434 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304435
Ravi Joshi1a292562017-05-18 16:28:54 -07004436 /* Initialize NAN Data Interface */
4437 if (QDF_NDI_MODE == session_type) {
4438 status = hdd_init_nan_data_mode(adapter);
4439 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004440 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004441 }
4442
4443 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004444
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004445 case QDF_P2P_GO_MODE:
4446 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004447 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4448 name_assign_type,
4449 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004450 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004451 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304452 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004453 return NULL;
4454 }
4455
4456 adapter->wdev.iftype =
4457 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004458 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004459 NL80211_IFTYPE_P2P_GO;
4460 adapter->device_mode = session_type;
4461
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004462 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004463 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004465
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004466 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004467 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304468 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4469 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304470
4471 /*
4472 * Workqueue which gets scheduled in IPv4 notification
4473 * callback
4474 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004475 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304476 hdd_ipv4_notifier_work_queue);
4477
4478#ifdef WLAN_NS_OFFLOAD
4479 /*
4480 * Workqueue which gets scheduled in IPv6
4481 * notification callback.
4482 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004483 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304484 hdd_ipv6_notifier_work_queue);
4485#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304487 case QDF_FTM_MODE:
4488 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4489 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004490 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304491 if (NULL == adapter) {
4492 hdd_err("Failed to allocate adapter for FTM mode");
4493 return NULL;
4494 }
4495 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4496 adapter->device_mode = session_type;
4497 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004498 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004499 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004500
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304501 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004502 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304503 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304504 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4505 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304506 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004508 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304509 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004510 return NULL;
4511 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004512
hqueaa33ee2017-05-04 17:56:35 +08004513 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4514
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304515 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004516 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004517 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518 }
4519
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304520 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004521 if (NULL != adapter) {
4522 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4523 adapter = NULL;
4524 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004525
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004526 return NULL;
4527 }
4528
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304529 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004530 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4531 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004532
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004533 /* Adapter successfully added. Increment the vdev count */
4534 hdd_ctx->current_intf_count++;
4535
Jeff Johnson5880d792016-08-15 13:32:30 -07004536 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537 hdd_ctx->current_intf_count);
4538
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004539 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004540 }
4541
Rajeev Kumardca5f812016-02-04 17:28:06 -08004542 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004543 hdd_err("Interface %s wow debug_fs init failed",
4544 netdev_name(adapter->dev));
4545
4546 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4547 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004548
4549 return adapter;
4550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004551err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004552 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304553 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004554
4555 return NULL;
4556}
4557
Jeff Johnson9d295242017-08-29 14:39:48 -07004558QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004559 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004560{
Dustin Brown920397d2017-12-13 16:27:50 -08004561 /*
4562 * Here we are stopping global bus_bw timer & work per adapter.
4563 *
4564 * The reason is to fix one race condition between
4565 * bus bandwidth work and cleaning up an adapter.
4566 * Under some conditions, it is possible for the bus bandwidth
4567 * work to access a particularly destroyed adapter, leading to
4568 * use-after-free.
4569 */
4570 hdd_debug("wait for bus bw work to flush");
4571 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4572 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004573
Dustin Brown920397d2017-12-13 16:27:50 -08004574 /* cleanup adapter */
4575 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4576 adapter->device_mode);
4577 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4578 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004579
Dustin Brown920397d2017-12-13 16:27:50 -08004580 /* conditionally restart the bw timer */
4581 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004582
Dustin Brown920397d2017-12-13 16:27:50 -08004583 /* Adapter removed. Decrement vdev count */
4584 if (hdd_ctx->current_intf_count != 0)
4585 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004586
Dustin Brown920397d2017-12-13 16:27:50 -08004587 /* Fw will take care incase of concurrency */
4588 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004589}
4590
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004591/**
4592 * hdd_close_all_adapters - Close all open adapters
4593 * @hdd_ctx: Hdd context
4594 * rtnl_held: True if RTNL lock held
4595 *
4596 * Close all open adapters.
4597 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304598 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004599 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004600QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004601{
Dustin Brown920397d2017-12-13 16:27:50 -08004602 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304603 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004604
4605 ENTER();
4606
4607 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004608 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4609 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304610 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004611 adapter->mac_addr.bytes);
4612 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4613
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304614 /* Adapter removed. Decrement vdev count */
4615 if (hdd_ctx->current_intf_count != 0)
4616 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004617 }
Dustin Brown920397d2017-12-13 16:27:50 -08004618 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619
4620 EXIT();
4621
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304622 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004623}
4624
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004625void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004626{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304627 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004628 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004629
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004630 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004631 case QDF_STA_MODE:
4632 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004633 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004634 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004635 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004636 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004637 break;
4638 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004639 case QDF_SAP_MODE:
4640 case QDF_P2P_GO_MODE:
4641 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004642 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004643 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004644 break;
4645 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004646 case QDF_FTM_MODE:
4647 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004648 default:
4649 /*
4650 * wlan_hdd_reset_prob_rspies should not have been called
4651 * for these kind of devices
4652 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004653 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004654 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655 return;
4656 }
4657
Anurag Chouhanc5548422016-02-24 18:33:27 +05304658 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004659 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004660 updateIE.ieBufferlength = 0;
4661 updateIE.pAdditionIEBuffer = NULL;
4662 updateIE.append = true;
4663 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004664 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004665 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304666 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004667 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004668 }
4669}
4670
Dustin Browndb2a8be2017-12-20 11:49:56 -08004671QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4672 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004673{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304674 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004675 struct hdd_wext_state *pWextState =
4676 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004677 union iwreq_data wrqu;
4678 tSirUpdateIE updateIE;
4679 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304680 tsap_Config_t *sap_config;
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304681 bool is_enabled = false;
4682 uint8_t ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004683
4684 ENTER();
4685
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004686 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304687 wlan_hdd_netif_queue_control(adapter,
4688 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4689 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004690 /*
4691 * if this is the last active connection check & stop the
4692 * opportunistic timer first
4693 */
4694 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4695 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4696 policy_mgr_convert_device_mode_to_qdf_type(
4697 adapter->device_mode), NULL) == 1)) ||
4698 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4699 policy_mgr_check_and_stop_opportunistic_timer(
4700 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004701 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004702 case QDF_STA_MODE:
4703 case QDF_P2P_CLIENT_MODE:
4704 case QDF_IBSS_MODE:
4705 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004706 case QDF_NDI_MODE:
4707 if ((QDF_NDI_MODE == adapter->device_mode) ||
4708 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004709 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4710 hdd_is_connecting(
4711 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004712 INIT_COMPLETION(adapter->disconnect_comp_var);
4713 /*
4714 * For NDI do not use pWextState from sta_ctx, if needed
4715 * extract from ndi_ctx.
4716 */
4717 if (QDF_NDI_MODE == adapter->device_mode)
4718 qdf_ret_status = sme_roam_disconnect(
4719 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004720 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004721 eCSR_DISCONNECT_REASON_NDI_DELETE);
4722 else if (pWextState->roamProfile.BSSType ==
4723 eCSR_BSS_TYPE_START_IBSS)
4724 qdf_ret_status = sme_roam_disconnect(
4725 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004726 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004727 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004728 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004729 qdf_ret_status =
4730 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004731 hdd_debug("Send disconnected event to userspace");
4732 wlan_hdd_cfg80211_indicate_disconnect(
4733 adapter->dev, true,
4734 WLAN_REASON_UNSPECIFIED);
4735 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004736 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004737 qdf_ret_status = sme_roam_disconnect(
4738 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004739 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004740 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004741 /* success implies disconnect command got
4742 * queued up successfully
4743 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004744 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4745 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004746 rc = wait_for_completion_timeout(
4747 &adapter->disconnect_comp_var,
4748 msecs_to_jiffies
4749 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004750 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004751 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004752 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004753 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4754 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004755 memset(&wrqu, '\0', sizeof(wrqu));
4756 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4757 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4758 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4759 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304760 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004761 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004762
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304763 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304764 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004765
4766#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004767 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004768#endif
4769
4770 hdd_deregister_tx_flow_control(adapter);
4771
4772#ifdef WLAN_NS_OFFLOAD
4773#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004774 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004775#endif
4776#endif
4777
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304778 if (adapter->device_mode == QDF_STA_MODE)
4779 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4780 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004781
4782 if (wlan_hdd_try_disconnect(adapter)) {
4783 hdd_err("Error: Can't disconnect adapter");
4784 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004785 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004786
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304787 ret = hdd_check_green_ap_enable(hdd_ctx, &is_enabled);
4788 if (!ret) {
4789 hdd_debug("Green AP enable status: %d", is_enabled);
4790 if (is_enabled) {
4791 hdd_debug("Enabling Green AP");
4792 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
4793 true);
4794 wlan_green_ap_start(hdd_ctx->hdd_pdev);
4795 }
4796 } else {
4797 hdd_err("Failed to check if Green AP should be enabled or not");
4798 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004799
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304800 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004801 break;
4802
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004803 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004804 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304805 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304806 sap_config = &adapter->session.ap.sap_config;
4807 if (sap_config)
4808 wlansap_reset_sap_config_add_ie(sap_config,
4809 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304810 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004811 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004812
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004813 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004814 if (QDF_SAP_MODE == adapter->device_mode) {
4815 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4816 cds_flush_delayed_work(
4817 &adapter->acs_pending_work);
4818 clear_bit(ACS_PENDING, &adapter->event_flags);
4819 }
4820 }
Krunal Soni22208392017-09-29 18:10:34 -07004821 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004822
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004823 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004824 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004825 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004826 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4827
4828 hdd_deregister_tx_flow_control(adapter);
4829
Kapil Guptac1224bf2017-06-22 21:22:40 +05304830 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004831 mutex_lock(&hdd_ctx->sap_lock);
4832 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304833 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304834 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004835
4836 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004837 status = wlansap_stop_bss(
4838 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304840 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004841 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004842 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304843 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304844 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304845 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304846 qdf_wait_for_event_completion(
4847 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004848 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004849
Anurag Chouhance0dc992016-02-16 18:18:03 +05304850 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004851 hdd_err("failure waiting for wlansap_stop_bss %d",
4852 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004853 }
4854 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004855 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004856 }
4857 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004858 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4859 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004860 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004861
Anurag Chouhanc5548422016-02-24 18:33:27 +05304862 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004863 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004864 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004865 updateIE.ieBufferlength = 0;
4866 updateIE.pAdditionIEBuffer = NULL;
4867 updateIE.append = false;
4868 updateIE.notify = false;
4869 /* Probe bcn reset */
4870 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4871 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304872 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004873 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004874 }
4875 /* Assoc resp reset */
4876 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4877 &updateIE,
4878 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304879 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004880 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004881 }
4882 /* Reset WNI_CFG_PROBE_RSP Flags */
4883 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004884 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004885 qdf_mem_free(adapter->session.ap.beacon);
4886 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304887 /*
4888 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4889 */
4890 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4891 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4892
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304893#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004894 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304895#endif
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);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304900#endif
4901#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08004902
4903 hdd_vdev_destroy(adapter);
4904
Krunal Sonib51eec72017-11-20 21:53:01 -08004905 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004906 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004907 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004908 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004909 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004910 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004911 break;
4912 default:
4913 break;
4914 }
4915
Dustin Brown04348372017-12-14 16:13:39 -08004916 if (adapter->scan_info.default_scan_ies) {
4917 qdf_mem_free(adapter->scan_info.default_scan_ies);
4918 adapter->scan_info.default_scan_ies = NULL;
4919 }
4920
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004921 EXIT();
Dustin Brown04348372017-12-14 16:13:39 -08004922
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304923 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004924}
4925
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304926/**
4927 * hdd_deinit_all_adapters - deinit all adapters
4928 * @hdd_ctx: HDD context
4929 * @rtnl_held: True if RTNL lock held
4930 *
4931 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004932void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304933{
Jeff Johnson9d295242017-08-29 14:39:48 -07004934 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304935
4936 ENTER();
4937
Dustin Brown920397d2017-12-13 16:27:50 -08004938 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304939 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304940
4941 EXIT();
4942}
4943
Dustin Browndb2a8be2017-12-20 11:49:56 -08004944QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004945{
Jeff Johnson9d295242017-08-29 14:39:48 -07004946 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004947
4948 ENTER();
4949
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304950 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4951
Dustin Brown920397d2017-12-13 16:27:50 -08004952 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08004953 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004954
4955 EXIT();
4956
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304957 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004958}
4959
Paul Zhang84fa9382017-11-10 21:18:21 +08004960static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4961 struct hdd_adapter *adapter)
4962{
4963 switch (adapter->device_mode) {
4964 case QDF_STA_MODE:
4965 case QDF_P2P_CLIENT_MODE:
4966 case QDF_IBSS_MODE:
4967 case QDF_P2P_DEVICE_MODE:
4968 case QDF_NDI_MODE:
4969 wlan_hdd_scan_abort(adapter);
4970 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4971 if (adapter->device_mode == QDF_STA_MODE)
4972 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4973 adapter->dev);
4974 break;
4975 case QDF_P2P_GO_MODE:
4976 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4977 break;
4978 case QDF_SAP_MODE:
4979 wlan_hdd_undo_acs(adapter);
4980 break;
4981 default:
4982 break;
4983 }
4984}
4985
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004986QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004987{
Jeff Johnson9d295242017-08-29 14:39:48 -07004988 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004989 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004990 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08004991 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004992
4993 ENTER();
4994
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304995 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4996
Dustin Brown920397d2017-12-13 16:27:50 -08004997 hdd_for_each_adapter(hdd_ctx, adapter) {
Yue Ma42654682018-01-11 16:55:24 -08004998 hdd_notice("[SSR] reset adapter with device mode %s(%d)",
4999 hdd_device_mode_to_string(adapter->device_mode),
Yue Mad5b4b9f2017-05-26 16:23:40 -07005000 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305001
5002 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07005003 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305004 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005005 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305006
Arun Khandavallicc544b32017-01-30 19:52:16 +05305007 if (hdd_ctx->config->sap_internal_restart &&
5008 adapter->device_mode == QDF_SAP_MODE) {
5009 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305010 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305011 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005012 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005013 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005014 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005015 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5016 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305017 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305018 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005019 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005020 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005021
Paul Zhang84fa9382017-11-10 21:18:21 +08005022 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005023 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005024
5025 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005026 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005027 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5029 hdd_wmm_adapter_close(adapter);
5030 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5031 }
5032
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305033 if (adapter->device_mode == QDF_STA_MODE)
5034 hdd_clear_fils_connection_info(adapter);
5035
Wu Gao3545e642017-07-14 19:24:41 +08005036 if (adapter->device_mode == QDF_SAP_MODE) {
5037 /*
5038 * If adapter is SAP, set session ID to invalid
5039 * since SAP session will be cleanup during SSR.
5040 */
Wu Gao36717432016-11-21 15:09:48 +08005041 wlansap_set_invalid_session(
5042 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5043
Wu Gao3545e642017-07-14 19:24:41 +08005044 wlansap_cleanup_cac_timer(
5045 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5046 }
5047
Yue Ma42654682018-01-11 16:55:24 -08005048 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005049 if (adapter->device_mode == QDF_STA_MODE ||
5050 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005051 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005052 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005053 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005054
5055 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5056 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005057 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5058 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5059 if (adapter->sta_info[sta_id].in_use) {
5060 hdd_debug("[SSR] deregister STA with ID %d",
5061 sta_id);
5062 hdd_softap_deregister_sta(adapter,
5063 sta_id);
5064 adapter->sta_info[sta_id].in_use = 0;
5065 }
5066 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005067 }
5068
Yue Maf9782842017-05-08 12:49:49 -07005069 /* Destroy vdev which will be recreated during reinit. */
5070 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005071 }
5072
5073 EXIT();
5074
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305075 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005076}
5077
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005078bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305079{
Dustin Brown920397d2017-12-13 16:27:50 -08005080 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305081 bool close_modules = true;
5082
Arun Khandavalliba479c42017-07-26 21:29:40 +05305083 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5084 hdd_info("FTM mode, don't close the module");
5085 return false;
5086 }
5087
Dustin Brown920397d2017-12-13 16:27:50 -08005088 hdd_for_each_adapter(hdd_ctx, adapter) {
5089 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5090 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005091 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305092 close_modules = false;
5093 break;
5094 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305095 }
5096
5097 return close_modules;
5098}
5099
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305100bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305101{
5102 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5103 return true;
5104 else
5105 return false;
5106}
5107
Anurag Chouhanc4092922016-09-08 15:56:11 +05305108#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005109 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305110struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5111 struct ieee80211_channel *channel,
5112 const u8 *bssid, const u8 *ssid,
5113 size_t ssid_len)
5114{
5115 return cfg80211_get_bss(wiphy, channel, bssid,
5116 ssid, ssid_len,
5117 WLAN_CAPABILITY_ESS,
5118 WLAN_CAPABILITY_ESS);
5119}
5120#else
5121struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5122 struct ieee80211_channel *channel,
5123 const u8 *bssid, const u8 *ssid,
5124 size_t ssid_len)
5125{
5126 return cfg80211_get_bss(wiphy, channel, bssid,
5127 ssid, ssid_len,
5128 IEEE80211_BSS_TYPE_ESS,
5129 IEEE80211_PRIVACY_ANY);
5130}
5131#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305132
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305133#if defined CFG80211_CONNECT_BSS || \
5134 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305135#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305136 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305137/**
5138 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5139 * @timeout_reason: reason for connect timeout
5140 *
5141 * This function is used to convert host timeout
5142 * reason enum to kernel specific enum.
5143 *
5144 * Return: nl timeout enum
5145 */
5146static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5147 tSirResultCodes timeout_reason)
5148{
5149 switch (timeout_reason) {
5150 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5151 return NL80211_TIMEOUT_SCAN;
5152 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5153 return NL80211_TIMEOUT_AUTH;
5154 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5155 return NL80211_TIMEOUT_ASSOC;
5156 default:
5157 return NL80211_TIMEOUT_UNSPECIFIED;
5158 }
5159}
5160
5161/**
5162 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5163 * @dev: network device
5164 * @bssid: bssid to which we want to associate
5165 * @timeout_reason: reason for connect timeout
5166 *
5167 * This API is used to send connection timeout reason to supplicant
5168 *
5169 * Return: void
5170 */
5171static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5172 const u8 *bssid,
5173 tSirResultCodes timeout_reason)
5174{
5175 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005176
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305177 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5178
5179 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5180 nl_timeout_reason);
5181}
5182
5183/**
5184 * __hdd_connect_bss() - API to send connection status to supplicant
5185 * @dev: network device
5186 * @bssid: bssid to which we want to associate
5187 * @req_ie: Request Information Element
5188 * @req_ie_len: len of the req IE
5189 * @resp_ie: Response IE
5190 * @resp_ie_len: len of ht response IE
5191 * @status: status
5192 * @gfp: Kernel Flag
5193 * @timeout_reason: reason for connect timeout
5194 *
5195 * Return: void
5196 */
5197static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5198 struct cfg80211_bss *bss, const u8 *req_ie,
5199 size_t req_ie_len, const u8 *resp_ie,
5200 size_t resp_ie_len, int status, gfp_t gfp,
5201 tSirResultCodes timeout_reason)
5202{
5203 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005204
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305205 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5206
5207 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5208 resp_ie, resp_ie_len, status, gfp,
5209 nl_timeout_reason);
5210}
5211#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305212#if defined CFG80211_CONNECT_TIMEOUT || \
5213 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305214static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5215 const u8 *bssid,
5216 tSirResultCodes timeout_reason)
5217{
5218 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5219}
5220#endif
5221
5222static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5223 struct cfg80211_bss *bss, const u8 *req_ie,
5224 size_t req_ie_len, const u8 *resp_ie,
5225 size_t resp_ie_len, int status, gfp_t gfp,
5226 tSirResultCodes timeout_reason)
5227{
5228 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5229 resp_ie, resp_ie_len, status, gfp);
5230}
5231#endif
5232
Abhishek Singha84d3952016-09-13 13:45:05 +05305233/**
5234 * hdd_connect_bss() - API to send connection status to supplicant
5235 * @dev: network device
5236 * @bssid: bssid to which we want to associate
5237 * @req_ie: Request Information Element
5238 * @req_ie_len: len of the req IE
5239 * @resp_ie: Response IE
5240 * @resp_ie_len: len of ht response IE
5241 * @status: status
5242 * @gfp: Kernel Flag
5243 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305244 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305245 *
5246 * The API is a wrapper to send connection status to supplicant
5247 *
5248 * Return: Void
5249 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305250#if defined CFG80211_CONNECT_TIMEOUT || \
5251 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305252static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5253 struct cfg80211_bss *bss, const u8 *req_ie,
5254 size_t req_ie_len, const u8 *resp_ie,
5255 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305256 bool connect_timeout,
5257 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305258{
5259 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305260 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305261 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305262 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5263 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305264}
5265#else
5266static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5267 struct cfg80211_bss *bss, const u8 *req_ie,
5268 size_t req_ie_len, const u8 *resp_ie,
5269 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305270 bool connect_timeout,
5271 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305272{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305273 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5274 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305275}
5276#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305277
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305278#if defined(WLAN_FEATURE_FILS_SK)
5279#if defined(CFG80211_CONNECT_DONE) || \
5280 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5281#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5282 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305283/**
5284 * hdd_populate_fils_params() - Populate FILS keys to connect response
5285 * @fils_params: connect response to supplicant
5286 * @fils_kek: FILS kek
5287 * @fils_kek_len: FILS kek length
5288 * @pmk: FILS PMK
5289 * @pmk_len: FILS PMK length
5290 * @pmkid: PMKID
5291 * @fils_seq_num: FILS Seq number
5292 *
5293 * Return: None
5294 */
5295static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5296 *fils_params, const uint8_t *fils_kek,
5297 size_t fils_kek_len, const uint8_t *pmk,
5298 size_t pmk_len, const uint8_t *pmkid,
5299 uint16_t fils_seq_num)
5300{
5301 /* Increament seq number to be used for next FILS */
5302 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5303 fils_params->update_erp_next_seq_num = true;
5304 fils_params->fils_kek = fils_kek;
5305 fils_params->fils_kek_len = fils_kek_len;
5306 fils_params->pmk = pmk;
5307 fils_params->pmk_len = pmk_len;
5308 fils_params->pmkid = pmkid;
5309}
5310#else
5311static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5312 *fils_params, const uint8_t
5313 *fils_kek, size_t fils_kek_len,
5314 const uint8_t *pmk, size_t pmk_len,
5315 const uint8_t *pmkid,
5316 uint16_t fils_seq_num)
5317{ }
5318#endif
5319
Jeff Johnson172237b2017-11-07 15:32:59 -08005320void hdd_update_hlp_info(struct net_device *dev,
5321 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305322{
5323 struct sk_buff *skb;
5324 uint16_t skb_len;
5325 struct llc_snap_hdr_t *llc_hdr;
5326 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305327 uint8_t *hlp_data;
5328 uint16_t hlp_data_len;
5329 struct fils_join_rsp_params *roam_fils_params
5330 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305331 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5332
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305333 if (!roam_fils_params) {
5334 hdd_err("FILS Roam Param NULL");
5335 return;
5336 }
5337
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005338 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305339 hdd_err("FILS HLP Data NULL, len %d",
5340 roam_fils_params->hlp_data_len);
5341 return;
5342 }
5343
5344 hlp_data = roam_fils_params->hlp_data;
5345 hlp_data_len = roam_fils_params->hlp_data_len;
5346
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305347 /* Calculate skb length */
5348 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5349 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5350 if (skb == NULL) {
5351 hdd_err("HLP packet nbuf alloc fails");
5352 return;
5353 }
5354
5355 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5356 QDF_MAC_ADDR_SIZE);
5357 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5358 QDF_MAC_ADDR_SIZE);
5359
5360 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5361 if (IS_SNAP(llc_hdr)) {
5362 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5363 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5364 }
5365
5366 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5367
5368 /*
5369 * This HLP packet is formed from HLP info encapsulated
5370 * in assoc response frame which is AEAD encrypted.
5371 * Hence, this checksum validation can be set unnecessary.
5372 * i.e. network layer need not worry about checksum.
5373 */
5374 skb->ip_summed = CHECKSUM_UNNECESSARY;
5375
5376 status = hdd_rx_packet_cbk(padapter, skb);
5377 if (QDF_IS_STATUS_ERROR(status)) {
5378 hdd_err("Sending HLP packet fails");
5379 return;
5380 }
5381 hdd_debug("send HLP packet to netif successfully");
5382}
5383
5384/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305385 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5386 * @dev: network device
5387 * @bssid: bssid to which we want to associate
5388 * @bss: cfg80211 bss info
5389 * @roam_info: information about connected bss
5390 * @req_ie: Request Information Element
5391 * @req_ie_len: len of the req IE
5392 * @resp_ie: Response IE
5393 * @resp_ie_len: len of ht response IE
5394 * @status: status
5395 * @gfp: allocation flags
5396 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5397 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305398 *
5399 * This API is used as wrapper to send FILS key/sequence number
5400 * params etc. to supplicant in case of FILS connection
5401 *
5402 * Return: None
5403 */
5404static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005405 struct cfg80211_bss *bss,
5406 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305407 const u8 *req_ie, size_t req_ie_len,
5408 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005409 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305410 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305411{
5412 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305413 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5414 struct fils_join_rsp_params *roam_fils_params =
5415 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005416
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305417 qdf_mem_zero(&fils_params, sizeof(fils_params));
5418
5419 if (!roam_fils_params) {
5420 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5421 } else {
5422 fils_params.status = status;
5423 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005424 fils_params.timeout_reason =
5425 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305426 fils_params.req_ie = req_ie;
5427 fils_params.req_ie_len = req_ie_len;
5428 fils_params.resp_ie = resp_ie;
5429 fils_params.resp_ie_len = resp_ie_len;
5430 fils_params.bss = bss;
5431 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5432 roam_fils_params->kek_len,
5433 roam_fils_params->fils_pmk,
5434 roam_fils_params->fils_pmk_len,
5435 roam_fils_params->fils_pmkid,
5436 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305437 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305438 }
5439 hdd_debug("FILS indicate connect status %d seq no %d",
5440 fils_params.status,
5441 fils_params.fils_erp_next_seq_num);
5442
5443 cfg80211_connect_done(dev, &fils_params, gfp);
5444
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305445 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305446 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305447
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305448 /* Clear all the FILS key info */
5449 if (roam_fils_params && roam_fils_params->fils_pmk)
5450 qdf_mem_free(roam_fils_params->fils_pmk);
5451 if (roam_fils_params)
5452 qdf_mem_free(roam_fils_params);
5453 roam_info->fils_join_rsp = NULL;
5454}
5455#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005456static inline void
5457hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005458 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005459 const u8 *req_ie, size_t req_ie_len,
5460 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5461 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305462 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305463{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305464#endif
5465#endif
5466
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305467#if defined(WLAN_FEATURE_FILS_SK) && \
5468 (defined(CFG80211_CONNECT_DONE) || \
5469 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305470/**
5471 * hdd_fils_update_connect_results() - API to send fils connection status to
5472 * supplicant.
5473 * @dev: network device
5474 * @bssid: bssid to which we want to associate
5475 * @bss: cfg80211 bss info
5476 * @roam_info: information about connected bss
5477 * @req_ie: Request Information Element
5478 * @req_ie_len: len of the req IE
5479 * @resp_ie: Response IE
5480 * @resp_ie_len: len of ht response IE
5481 * @status: status
5482 * @gfp: allocation flags
5483 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5484 * @timeout_reason: reason for connect timeout
5485 *
5486 * The API is a wrapper to send connection status to supplicant
5487 *
5488 * Return: 0 if success else failure
5489 */
5490static int hdd_fils_update_connect_results(struct net_device *dev,
5491 const u8 *bssid,
5492 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005493 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305494 size_t req_ie_len, const u8 *resp_ie,
5495 size_t resp_ie_len, u16 status, gfp_t gfp,
5496 bool connect_timeout,
5497 tSirResultCodes timeout_reason)
5498{
5499 ENTER();
5500 if (!roam_info || !roam_info->is_fils_connection)
5501 return -EINVAL;
5502
5503 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5504 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305505 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305506 return 0;
5507}
5508#else
5509static inline int hdd_fils_update_connect_results(struct net_device *dev,
5510 const u8 *bssid,
5511 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005512 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305513 size_t req_ie_len, const u8 *resp_ie,
5514 size_t resp_ie_len, u16 status, gfp_t gfp,
5515 bool connect_timeout,
5516 tSirResultCodes timeout_reason)
5517{
5518 return -EINVAL;
5519}
5520#endif
5521
Anurag Chouhanc4092922016-09-08 15:56:11 +05305522/**
5523 * hdd_connect_result() - API to send connection status to supplicant
5524 * @dev: network device
5525 * @bssid: bssid to which we want to associate
5526 * @roam_info: information about connected bss
5527 * @req_ie: Request Information Element
5528 * @req_ie_len: len of the req IE
5529 * @resp_ie: Response IE
5530 * @resp_ie_len: len of ht response IE
5531 * @status: status
5532 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305533 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305534 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305535 *
5536 * The API is a wrapper to send connection status to supplicant
5537 * and allow runtime suspend
5538 *
5539 * Return: Void
5540 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305541void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005542 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305543 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305544 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305545 bool connect_timeout,
5546 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305547{
Jeff Johnson9d295242017-08-29 14:39:48 -07005548 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305549 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005550 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305551
5552 if (WLAN_STATUS_SUCCESS == status) {
5553 struct ieee80211_channel *chan;
5554 int freq;
5555 int chan_no = roam_info->pBssDesc->channelId;
5556
5557 if (chan_no <= 14)
5558 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005559 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305560 else
5561 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005562 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305563
5564 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5565 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5566 roam_info->u.pConnectedProfile->SSID.ssId,
5567 roam_info->u.pConnectedProfile->SSID.length);
5568 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305569
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305570 if (hdd_fils_update_connect_results(dev, bssid, bss,
5571 roam_info, req_ie, req_ie_len, resp_ie,
5572 resp_ie_len, status, gfp, connect_timeout,
5573 timeout_reason) != 0) {
5574 hdd_connect_bss(dev, bssid, bss, req_ie,
5575 req_ie_len, resp_ie, resp_ie_len,
5576 status, gfp, connect_timeout, timeout_reason);
5577 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305578
Jingxiang Geb49aa302018-01-17 20:54:15 +08005579 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005580 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305581}
5582#else
5583void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005584 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305585 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305586 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305587 bool connect_timeout,
5588 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305589{
Jeff Johnson9d295242017-08-29 14:39:48 -07005590 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005591 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305592
Anurag Chouhanc4092922016-09-08 15:56:11 +05305593 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5594 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005595
Jingxiang Geb49aa302018-01-17 20:54:15 +08005596 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005597 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305598}
5599#endif
5600
5601
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005602QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005603{
Jeff Johnson9d295242017-08-29 14:39:48 -07005604 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005605#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005606 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005607#endif
5608 eConnectionState connState;
5609
5610 ENTER();
5611
Dustin Brown920397d2017-12-13 16:27:50 -08005612 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305613 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005614 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305615
Yue Ma42654682018-01-11 16:55:24 -08005616 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5617 hdd_device_mode_to_string(adapter->device_mode),
5618 adapter->device_mode);
5619
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005620 hdd_wmm_init(adapter);
5621
5622 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005623 case QDF_STA_MODE:
5624 case QDF_P2P_CLIENT_MODE:
5625 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005626
5627 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5628 ->conn_info.connState;
5629
Krunal Sonib51eec72017-11-20 21:53:01 -08005630 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005632 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005633
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005634 /* Indicate disconnect event to supplicant
5635 * if associated previously
5636 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005637 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005638 eConnectionState_IbssConnected == connState ||
5639 eConnectionState_NotConnected == connState ||
5640 eConnectionState_IbssDisconnected == connState ||
5641 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005642 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005644 memset(&wrqu, '\0', sizeof(wrqu));
5645 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5646 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5647 wireless_send_event(adapter->dev, SIOCGIWAP,
5648 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005649 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005650 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005651
5652 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305653 wlan_hdd_cfg80211_indicate_disconnect(
5654 adapter->dev, false,
5655 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005656 } else if (eConnectionState_Connecting == connState) {
5657 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005658 * Indicate connect failure to supplicant if we
5659 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305661 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305662 NULL, 0, NULL, 0,
5663 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005664 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005665 }
5666
5667 hdd_register_tx_flow_control(adapter,
5668 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005669 hdd_tx_resume_cb,
5670 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671
5672 break;
5673
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005674 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005675 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005676 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305677
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005678 break;
5679
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005680 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005682 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005683 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5684#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005685 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005686 /* event supplicant to restart */
5687 cfg80211_del_sta(adapter->dev,
5688 (const u8 *)&bcastMac.bytes[0],
5689 GFP_KERNEL);
5690#endif
5691 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305692 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005693 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305694 hdd_set_mon_rx_cb(adapter->dev);
5695 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5696 adapter->mon_bandwidth);
5697 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005698 default:
5699 break;
5700 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005701 /*
5702 * Action frame registered in one adapter which will
5703 * applicable to all interfaces
5704 */
5705 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005706 }
5707
5708 EXIT();
5709
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305710 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005711}
5712
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005713QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005714 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305716 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005717 qdf_list_node_t *node;
5718
5719 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005720
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005721 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005722 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005723 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005724
5725 if (QDF_IS_STATUS_ERROR(status))
5726 return status;
5727
5728 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5729
5730 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005731}
5732
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005733QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005734 struct hdd_adapter *current_adapter,
5735 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005736{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305737 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005738 qdf_list_node_t *node;
5739
5740 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005741
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005742 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005743 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005744 &current_adapter->node,
5745 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005746 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005747
5748 if (QDF_IS_STATUS_ERROR(status))
5749 return status;
5750
5751 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5752
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005753 return status;
5754}
5755
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005756QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005757 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005758{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305759 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005760
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005761 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005762 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005763 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005765 return status;
5766}
5767
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005768QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005769 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005770{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305771 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005772 qdf_list_node_t *node;
5773
5774 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005775
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005776 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005777 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005778 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005779
5780 if (QDF_IS_STATUS_ERROR(status))
5781 return status;
5782
5783 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5784
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005785 return status;
5786}
5787
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005788QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005789 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005790{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305791 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005792
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005793 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005794 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005795 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005796
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005797 return status;
5798}
5799
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005800QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005801 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005802{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305803 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005804
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005805 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005806 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005807 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005808
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005809 return status;
5810}
5811
Jeff Johnson9d295242017-08-29 14:39:48 -07005812struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005813 tSirMacAddr macAddr)
5814{
Jeff Johnson9d295242017-08-29 14:39:48 -07005815 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005816
Dustin Brown920397d2017-12-13 16:27:50 -08005817 hdd_for_each_adapter(hdd_ctx, adapter) {
5818 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5819 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005820 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005821 }
5822
5823 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005824}
5825
Jeff Johnson9d295242017-08-29 14:39:48 -07005826struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005827 uint32_t vdev_id)
5828{
Jeff Johnson9d295242017-08-29 14:39:48 -07005829 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005830
Dustin Brown920397d2017-12-13 16:27:50 -08005831 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005832 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005833 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005834 }
5835
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005836 return NULL;
5837}
5838
Abhishek Singh7996eb72015-12-30 17:24:02 +05305839/**
5840 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5841 * the sessionid
5842 * @hdd_ctx: hdd context.
5843 * @sme_session_id: sme session is for the adapter to get.
5844 *
5845 * This function is used to get the adapter with provided session id
5846 *
5847 * Return: adapter pointer if found
5848 *
5849 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005850struct hdd_adapter *
5851hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5852 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305853{
Jeff Johnson9d295242017-08-29 14:39:48 -07005854 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305855
Dustin Brown920397d2017-12-13 16:27:50 -08005856 hdd_for_each_adapter(hdd_ctx, adapter) {
5857 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305858 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305859 }
Dustin Brown920397d2017-12-13 16:27:50 -08005860
Abhishek Singh7996eb72015-12-30 17:24:02 +05305861 return NULL;
5862}
5863
Jeff Johnson9d295242017-08-29 14:39:48 -07005864struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005865 const char *iface_name)
5866{
Jeff Johnson9d295242017-08-29 14:39:48 -07005867 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005868
Dustin Brown920397d2017-12-13 16:27:50 -08005869 hdd_for_each_adapter(hdd_ctx, adapter) {
5870 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07005871 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005872 }
Dustin Brown920397d2017-12-13 16:27:50 -08005873
Naveen Rawat4edb6822017-04-12 10:09:17 -07005874 return NULL;
5875}
5876
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005877/**
5878 * hdd_get_adapter() - to get adapter matching the mode
5879 * @hdd_ctx: hdd context
5880 * @mode: adapter mode
5881 *
5882 * This routine will return the pointer to adapter matching
5883 * with the passed mode.
5884 *
5885 * Return: pointer to adapter or null
5886 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005887struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005888 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005889{
Jeff Johnson9d295242017-08-29 14:39:48 -07005890 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005891
Dustin Brown920397d2017-12-13 16:27:50 -08005892 hdd_for_each_adapter(hdd_ctx, adapter) {
5893 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005894 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005895 }
5896
5897 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898}
5899
5900/**
5901 * hdd_get_operating_channel() - return operating channel of the device mode
5902 * @hdd_ctx: Pointer to the HDD context.
5903 * @mode: Device mode for which operating channel is required.
5904 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005905 * QDF_STA_MODE,
5906 * QDF_P2P_CLIENT_MODE,
5907 * QDF_SAP_MODE,
5908 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005909 *
5910 * This API returns the operating channel of the requested device mode
5911 *
5912 * Return: channel number. "0" id the requested device is not found OR it is
5913 * not connected.
5914 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005915uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005916 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005917{
Jeff Johnson9d295242017-08-29 14:39:48 -07005918 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005919 uint8_t operatingChannel = 0;
5920
Dustin Brown920397d2017-12-13 16:27:50 -08005921 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005922 if (mode == adapter->device_mode) {
5923 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005924 case QDF_STA_MODE:
5925 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005926 if (hdd_conn_is_connected
5927 (WLAN_HDD_GET_STATION_CTX_PTR
5928 (adapter))) {
5929 operatingChannel =
5930 (WLAN_HDD_GET_STATION_CTX_PTR
5931 (adapter))->conn_info.
5932 operationChannel;
5933 }
5934 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005935 case QDF_SAP_MODE:
5936 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005937 /* softap connection info */
5938 if (test_bit
5939 (SOFTAP_BSS_STARTED,
5940 &adapter->event_flags))
5941 operatingChannel =
5942 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005943 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005944 break;
5945 default:
5946 break;
5947 }
5948
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005949 /* Found the device of interest. break the loop */
5950 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005951 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005952 }
Dustin Brown920397d2017-12-13 16:27:50 -08005953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954 return operatingChannel;
5955}
5956
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005957static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005958 hdd_ctx)
5959{
Jeff Johnson9d295242017-08-29 14:39:48 -07005960 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005961
5962 ENTER();
5963
Dustin Brown920397d2017-12-13 16:27:50 -08005964 hdd_for_each_adapter(hdd_ctx, adapter) {
5965 if (adapter->device_mode == QDF_STA_MODE ||
5966 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5967 adapter->device_mode == QDF_IBSS_MODE ||
5968 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5969 adapter->device_mode == QDF_SAP_MODE ||
5970 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005971 wlan_hdd_cfg80211_deregister_frames(adapter);
5972 hdd_unregister_wext(adapter->dev);
5973 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005974 }
5975
5976 EXIT();
5977
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305978 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979}
5980
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005981QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005982{
Jeff Johnson9d295242017-08-29 14:39:48 -07005983 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005984
5985 ENTER();
5986
Dustin Brown920397d2017-12-13 16:27:50 -08005987 hdd_for_each_adapter(hdd_ctx, adapter) {
5988 if (adapter->device_mode == QDF_STA_MODE ||
5989 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5990 adapter->device_mode == QDF_IBSS_MODE ||
5991 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5992 adapter->device_mode == QDF_SAP_MODE ||
5993 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005994 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005995 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05305996 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005997 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005998 }
5999
6000 EXIT();
6001
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306002 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006003}
6004
Dustin Brownf27bce82016-11-03 12:52:27 -07006005/**
6006 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6007 * adapters
6008 * @hdd_ctx: The HDD context containing the adapters to operate on
6009 *
6010 * return: QDF_STATUS_SUCCESS
6011 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006012static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006013{
Jeff Johnson9d295242017-08-29 14:39:48 -07006014 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006015 int err;
6016
6017 ENTER();
6018
Dustin Brown920397d2017-12-13 16:27:50 -08006019 hdd_for_each_adapter(hdd_ctx, adapter) {
6020 if (adapter->device_mode == QDF_STA_MODE ||
6021 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6022 adapter->device_mode == QDF_IBSS_MODE ||
6023 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6024 adapter->device_mode == QDF_SAP_MODE ||
6025 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006026 err = wlan_hdd_sched_scan_stop(adapter->dev);
6027 if (err)
6028 hdd_err("Unable to stop scheduled scan");
6029 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006030 }
6031
6032 EXIT();
6033
6034 return QDF_STATUS_SUCCESS;
6035}
6036
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006037#ifdef WLAN_NS_OFFLOAD
6038/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006039 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006040 * @hdd_ctx: Pointer to hdd context
6041 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006042 * Unregister for IPv6 address change notifications.
6043 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044 * Return: None
6045 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006046static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006047{
6048 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006049}
6050
6051/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006052 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006053 * @hdd_ctx: Pointer to hdd context
6054 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006055 * Register for IPv6 address change notifications.
6056 *
6057 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006058 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006059static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006060{
6061 int ret;
6062
6063 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6064 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006065 if (ret) {
6066 hdd_err("Failed to register IPv6 notifier: %d", ret);
6067 goto out;
6068 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006069
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006070 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006071out:
6072 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073}
6074#else
6075/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006076 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006077 * @hdd_ctx: Pointer to hdd context
6078 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006079 * Unregister for IPv6 address change notifications.
6080 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006081 * Return: None
6082 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006083static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006084{
6085}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006086
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006087/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006088 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006089 * @hdd_ctx: Pointer to hdd context
6090 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006091 * Register for IPv6 address change notifications.
6092 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006093 * Return: None
6094 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006095static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006096{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006097 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006098}
6099#endif
6100
6101/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006102 * hdd_register_notifiers - Register netdev notifiers.
6103 * @hdd_ctx: HDD context
6104 *
6105 * Register netdev notifiers like IPv4 and IPv6.
6106 *
6107 * Return: 0 on success and errno on failure
6108 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006109static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006110{
6111 int ret;
6112
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006113 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6114 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306115 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006116
6117 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6118 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6119 if (ret) {
6120 hdd_err("Failed to register IPv4 notifier: %d", ret);
6121 goto unregister_ip6_notifier;
6122 }
6123
6124 return 0;
6125
6126unregister_ip6_notifier:
6127 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006128out:
6129 return ret;
6130
6131}
6132
6133/**
6134 * hdd_unregister_notifiers - Unregister netdev notifiers.
6135 * @hdd_ctx: HDD context
6136 *
6137 * Unregister netdev notifiers like IPv4 and IPv6.
6138 *
6139 * Return: None.
6140 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006141void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006142{
6143 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6144
6145 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006146}
6147
6148/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006149 * hdd_exit_netlink_services - Exit netlink services
6150 * @hdd_ctx: HDD context
6151 *
6152 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6153 * nl service.
6154 *
6155 * Return: None.
6156 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006157static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006158{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006159 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006160 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006161 ptt_sock_deactivate_svc();
6162
6163 nl_srv_exit();
6164}
6165
6166/**
6167 * hdd_init_netlink_services- Init netlink services
6168 * @hdd_ctx: HDD context
6169 *
6170 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6171 * nl service.
6172 *
6173 * Return: 0 on success and errno on failure.
6174 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006175static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006176{
6177 int ret;
6178
Ryan Hsuceddceb2016-04-28 10:20:14 -07006179 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006180 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006181 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006182 goto out;
6183 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006184 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006185
Naveen Rawat910726a2017-03-06 11:42:51 -08006186 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006187 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006188 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006189 goto err_nl_srv;
6190 }
6191
6192 ret = ptt_sock_activate_svc();
6193 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006194 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006195 goto err_nl_srv;
6196 }
6197
6198 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006199 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006200 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006201
6202 ret = cnss_diag_activate_service();
6203 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006204 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006205 goto err_close_cesium;
6206 }
6207
6208 return 0;
6209
6210err_close_cesium:
6211 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006212 ptt_sock_deactivate_svc();
6213err_nl_srv:
6214 nl_srv_exit();
6215out:
6216 return ret;
6217}
6218
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006219/**
6220 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6221 * @hdd_ctx: HDD context.
6222 *
6223 * Destroy RX wakelock.
6224 *
6225 * Return: None.
6226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006227static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006228{
6229 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6230}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006231
6232/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006233 * hdd_rx_wake_lock_create() - Create RX wakelock
6234 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006235 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006236 * Create RX wakelock.
6237 *
6238 * Return: None.
6239 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006240static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006241{
6242 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6243}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006244
6245/**
Houston Hoffman160db392016-10-10 17:37:51 -07006246 * hdd_context_deinit() - Deinitialize HDD context
6247 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006248 *
Houston Hoffman160db392016-10-10 17:37:51 -07006249 * Deinitialize HDD context along with all the feature specific contexts but
6250 * do not free hdd context itself. Caller of this API is supposed to free
6251 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006252 *
Houston Hoffman160db392016-10-10 17:37:51 -07006253 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006254 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006255static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006256{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306257 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6258
Houston Hoffman160db392016-10-10 17:37:51 -07006259 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006260
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006261 hdd_sap_context_destroy(hdd_ctx);
6262
6263 hdd_rx_wake_lock_destroy(hdd_ctx);
6264
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006265 hdd_scan_context_destroy(hdd_ctx);
6266
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006267 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006268
Houston Hoffman160db392016-10-10 17:37:51 -07006269 return 0;
6270}
6271
6272/**
6273 * hdd_context_destroy() - Destroy HDD context
6274 * @hdd_ctx: HDD context to be destroyed.
6275 *
6276 * Free config and HDD context as well as destroy all the resources.
6277 *
6278 * Return: None
6279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006280static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006281{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006282 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306283
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306284 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6285
Houston Hoffman160db392016-10-10 17:37:51 -07006286 hdd_context_deinit(hdd_ctx);
6287
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306288 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006289 hdd_ctx->config = NULL;
6290
6291 wiphy_free(hdd_ctx->wiphy);
6292}
6293
6294/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306295 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6296 *
6297 * This function is used to destroy bug report lock
6298 *
6299 * Return: None
6300 */
6301static void wlan_destroy_bug_report_lock(void)
6302{
6303 p_cds_contextType p_cds_context;
6304
6305 p_cds_context = cds_get_global_context();
6306 if (!p_cds_context) {
6307 hdd_err("cds context is NULL");
6308 return;
6309 }
6310
6311 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6312}
6313
6314/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315 * hdd_wlan_exit() - HDD WLAN exit function
6316 * @hdd_ctx: Pointer to the HDD Context
6317 *
6318 * This is the driver exit point (invoked during rmmod)
6319 *
6320 * Return: None
6321 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006322static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006323{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006324 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306325 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006326
6327 ENTER();
6328
Dustin Brown6f427922017-09-19 12:19:00 -07006329 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306330
6331 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006332
Prashanth Bhattaab004382016-10-11 16:08:11 -07006333 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006334
6335#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306336 if (QDF_TIMER_STATE_RUNNING ==
6337 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6338 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339 }
6340
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306341 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306342 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006343 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006344 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006345 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6346 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6347 hdd_ctx->last_acs_channel_list = NULL;
6348 hdd_ctx->num_of_channels = 0;
6349 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006350#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006351
Arun Khandavallifae92942016-08-01 13:31:08 +05306352 mutex_lock(&hdd_ctx->iface_change_lock);
6353 driver_status = hdd_ctx->driver_status;
6354 mutex_unlock(&hdd_ctx->iface_change_lock);
6355
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006356 /*
6357 * Powersave Offload Case
6358 * Disable Idle Power Save Mode
6359 */
6360 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006361 /* clear the scan queue in all the scenarios */
6362 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006363
Arun Khandavallifae92942016-08-01 13:31:08 +05306364 if (driver_status != DRIVER_MODULES_CLOSED) {
6365 hdd_unregister_wext_all_adapters(hdd_ctx);
6366 /*
6367 * Cancel any outstanding scan requests. We are about to close
6368 * all of our adapters, but an adapter structure is what SME
6369 * passes back to our callback function. Hence if there
6370 * are any outstanding scan requests then there is a
6371 * race condition between when the adapter is closed and
6372 * when the callback is invoked. We try to resolve that
6373 * race condition here by canceling any outstanding scans
6374 * before we close the adapters.
6375 * Note that the scans may be cancelled in an asynchronous
6376 * manner, so ideally there needs to be some kind of
6377 * synchronization. Rather than introduce a new
6378 * synchronization here, we will utilize the fact that we are
6379 * about to Request Full Power, and since that is synchronized,
6380 * the expectation is that by the time Request Full Power has
6381 * completed, all scans will be cancelled
6382 */
6383 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006384 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006385 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006386 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006387 }
6388
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306389 unregister_netdevice_notifier(&hdd_netdev_notifier);
6390
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006391 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306392
Dustin Brown021cecd2017-12-11 13:56:43 -08006393 hdd_driver_memdump_deinit();
6394
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306395 qdf_nbuf_deinit_replenish_timer();
6396
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306397 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6398 hdd_info("Release wakelock for monitor mode!");
6399 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6400 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6401 }
6402
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306403 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6404 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6405 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6406
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006407 /*
6408 * Close CDS
6409 * This frees pMac(HAL) context. There should not be any call
6410 * that requires pMac access after this.
6411 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006412
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006413 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006414
Dustin Brownd005ad82018-01-19 10:32:13 -08006415 hdd_close_all_adapters(hdd_ctx, false);
6416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006417 hdd_ipa_cleanup(hdd_ctx);
6418
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306419 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306420 /*
6421 * If there is re_init failure wiphy would have already de-registered
6422 * check the wiphy status before un-registering again
6423 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306424 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306425 wiphy_unregister(wiphy);
6426 wlan_hdd_cfg80211_deinit(wiphy);
6427 hdd_lpass_notify_stop(hdd_ctx);
6428 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006429
Arun Khandavallifae92942016-08-01 13:31:08 +05306430 hdd_exit_netlink_services(hdd_ctx);
6431 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306432#ifdef FEATURE_WLAN_CH_AVOID
6433 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6434#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306435
Abhishek Singhe9068f12017-03-31 14:14:52 +05306436 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6437 if (driver_status)
6438 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006439
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006440 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006441}
6442
6443void __hdd_wlan_exit(void)
6444{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006445 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006446
6447 ENTER();
6448
Anurag Chouhan6d760662016-02-20 16:05:43 +05306449 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006451 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006452 EXIT();
6453 return;
6454 }
6455
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006456 /* Do all the cleanup before deregistering the driver */
6457 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006458
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006459 EXIT();
6460}
6461
6462#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006463/**
6464 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006465 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006466 *
6467 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6468 * Then new ACS request will do a fresh scan without reusing the cached
6469 * scan information.
6470 *
6471 * Return: void
6472 */
Tang Yingying523322d2017-01-17 23:28:43 +08006473static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006474{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006475 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006476
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006477 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006478 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006479 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6480 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6481 hdd_ctx->last_acs_channel_list = NULL;
6482 hdd_ctx->num_of_channels = 0;
6483 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006484
6485 if (!hdd_ctx->hHal)
6486 return;
6487 sme_scan_flush_result(hdd_ctx->hHal);
6488}
6489#endif
6490
6491#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006492int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6493 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006494{
6495 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306496 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006497 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006498
6499 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6500
6501 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306502 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006503 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306504
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006505 if (!hdd_ctx->hHal)
6506 return -EINVAL;
6507
Jeff Johnsone7672e72017-10-21 15:10:04 -07006508 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006509 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306510 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006511 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006512 return -EINVAL;
6513 }
6514
6515 return 0;
6516}
6517#endif
6518
6519/**
6520 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6521 * @state: state
6522 *
6523 * This function notifies FW with modem power status
6524 *
6525 * Return: 0 if successful, error number otherwise
6526 */
6527int hdd_wlan_notify_modem_power_state(int state)
6528{
6529 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306530 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006531 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006532
Anurag Chouhan6d760662016-02-20 16:05:43 +05306533 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006534 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306535 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006536 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006538 if (!hdd_ctx->hHal)
6539 return -EINVAL;
6540
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306541 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6542 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006543 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006544 state);
6545 return -EINVAL;
6546 }
6547 return 0;
6548}
6549
6550/**
6551 *
6552 * hdd_post_cds_enable_config() - HDD post cds start config helper
6553 * @adapter - Pointer to the HDD
6554 *
6555 * Return: None
6556 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006557QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006558{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306559 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006560
6561 /*
6562 * Send ready indication to the HDD. This will kick off the MAC
6563 * into a 'running' state and should kick off an initial scan.
6564 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306565 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6566 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006567 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6568 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306569 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006570 }
6571
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306572 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006573}
6574
6575/* wake lock APIs for HDD */
6576void hdd_prevent_suspend(uint32_t reason)
6577{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306578 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006579}
6580
6581void hdd_allow_suspend(uint32_t reason)
6582{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306583 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584}
6585
6586void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6587{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306588 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6589 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006590}
6591
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006592/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006593QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006595
Amar Singhal6f8592b2017-04-26 14:31:58 -07006596 return sme_init_chan_list(hdd_ctx->hHal,
6597 hdd_ctx->reg.alpha2,
6598 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599}
6600
6601/**
6602 * hdd_is_5g_supported() - check if hardware supports 5GHz
6603 * @hdd_ctx: Pointer to the hdd context
6604 *
6605 * HDD function to know if hardware supports 5GHz
6606 *
6607 * Return: true if hardware supports 5GHz
6608 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006609bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006610{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006611 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006612 return true;
6613
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006614 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006615 return true;
6616 else
6617 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006618}
6619
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006620static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006621{
6622 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006623 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006624
6625 wiphy = hdd_ctx->wiphy;
6626
6627 /*
6628 * The channel information in
6629 * wiphy needs to be initialized before wiphy registration
6630 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006631 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6632 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006633 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006634 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006635 }
6636
6637#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6638 wiphy->wowlan = &wowlan_support_reg_init;
6639#else
6640 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6641 WIPHY_WOWLAN_MAGIC_PKT |
6642 WIPHY_WOWLAN_DISCONNECT |
6643 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6644 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6645 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6646 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6647 WIPHY_WOWLAN_RFKILL_RELEASE;
6648
6649 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6650 WOW_MAX_FILTERS_PER_LIST);
6651 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6652 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6653#endif
6654
6655 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006656 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306657 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006658 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306659 return ret_val;
6660 }
6661
Amar Singhal5cccafe2017-02-15 12:42:58 -08006662 if (!hdd_ctx->reg_offload)
6663 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006664
Amar Singhale4f28ee2015-10-21 14:36:56 -07006665 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666}
6667
Mohit Khannaca4173b2017-09-12 21:52:19 -07006668#ifdef MSM_PLATFORM
6669/**
6670 * hdd_display_periodic_stats() - Function to display periodic stats
6671 * @hdd_ctx - handle to hdd context
6672 * @bool data_in_interval - true, if data detected in bw time interval
6673 *
6674 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6675 * Stats show up in wlan driver logs.
6676 *
6677 * Returns: None
6678 */
6679static inline
6680void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6681 bool data_in_interval)
6682{
6683 static u32 counter;
6684 static bool data_in_time_period;
6685 ol_txrx_pdev_handle pdev;
6686
6687 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6688 return;
6689
6690 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6691 if (!pdev) {
6692 hdd_err("pdev is NULL");
6693 return;
6694 }
6695
6696 counter++;
6697 if (data_in_interval)
6698 data_in_time_period = data_in_interval;
6699
6700 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6701 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6702 if (data_in_time_period) {
6703 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6704 CDP_TXRX_PATH_STATS,
6705 QDF_STATS_VERBOSITY_LEVEL_LOW);
6706 wlan_hdd_display_netif_queue_history
6707 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6708 qdf_dp_trace_dump_stats();
6709 }
6710 counter = 0;
6711 data_in_time_period = false;
6712 }
6713}
6714
Ravi Joshie2331e82015-07-01 18:18:54 -07006715/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006716 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006717 * @hdd_ctx - handle to hdd context
6718 * @tx_packets - transmit packet count
6719 * @rx_packets - receive packet count
6720 *
6721 * The function controls the bus bandwidth and dynamic control of
6722 * tcp delayed ack configuration
6723 *
6724 * Returns: None
6725 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006726
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006727static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006728 const uint64_t tx_packets,
6729 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006730{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006731 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006732 uint64_t temp_rx = 0;
6733 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006734 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006735 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006736 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006737 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006738 uint16_t index = 0;
6739 bool vote_level_change = false;
6740 bool rx_level_change = false;
6741 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006742
Mohit Khannaca4173b2017-09-12 21:52:19 -07006743 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006744 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006745 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006746 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006747 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006748 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006749 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006750 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006751
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006752 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006753 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6754 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006755 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006756 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006757 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306758 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306759 if (hdd_ctx->hbw_requested) {
6760 pld_remove_pm_qos(hdd_ctx->parent_dev);
6761 hdd_ctx->hbw_requested = false;
6762 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306763 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006764 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006765 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306766 if (!hdd_ctx->hbw_requested) {
6767 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6768 hdd_ctx->hbw_requested = true;
6769 }
6770
Nirav Shah3bbfa512016-05-12 16:43:49 +05306771 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006772 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006773 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006774 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006776
Mohit Khannaf8f96822017-05-17 17:11:59 -07006777 qdf_dp_trace_throttle_live_mode(
6778 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6779
Mohit Khannae71e2262015-11-10 09:37:24 -08006780 /* fine-tuning parameters for RX Flows */
6781 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6782
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006783 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006784
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306785 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6786 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6787 else
6788 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6789
Ravi Joshifed83572016-10-07 16:20:37 -07006790 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6791 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6792 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6793 next_rx_level = WLAN_SVC_TP_HIGH;
6794 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006795 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006796 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006797 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006798 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006799
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006801 struct wlan_rx_tp_data rx_tp_data = {0};
6802
Ravi Joshie2331e82015-07-01 18:18:54 -07006803 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006804 next_rx_level, temp_rx);
6805 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006806 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006807 /* Send throughput indication only if it is enabled.
6808 * Disabling tcp_del_ack will revert the tcp stack behavior
6809 * to default delayed ack. Note that this will disable the
6810 * dynamic delayed ack mechanism across the system
6811 */
6812 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006813 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6814
Mohit Khanna6272fb682017-04-13 09:34:36 -07006815 if (hdd_ctx->config->enable_tcp_adv_win_scale)
6816 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6817
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006818 rx_tp_data.level = next_rx_level;
6819 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6820 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6821 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006822 }
6823
Mohit Khannae71e2262015-11-10 09:37:24 -08006824 /* fine-tuning parameters for TX Flows */
6825 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6826 hdd_ctx->prev_tx = tx_packets;
6827 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6828 next_tx_level = WLAN_SVC_TP_HIGH;
6829 else
6830 next_tx_level = WLAN_SVC_TP_LOW;
6831
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006832 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006833 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6834 next_tx_level, temp_tx);
6835 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006836 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306837 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6838 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006839 &next_tx_level,
6840 sizeof(next_tx_level));
6841 }
6842
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006843 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006844 if (vote_level_change || tx_level_change || rx_level_change) {
6845 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6846 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6847 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6848 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6849 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6850 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6851 hdd_ctx->hdd_txrx_hist_idx++;
6852 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6853 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07006854
6855 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006856}
6857
6858#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306859static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006860{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006861 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306862 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006863 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306864 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306865 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6866 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006867 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306868 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869 bool connected = false;
6870 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6871
Prashanth Bhattaab004382016-10-11 16:08:11 -07006872 if (wlan_hdd_validate_context(hdd_ctx))
6873 return;
6874
Jeff Johnson214671b2017-10-30 19:45:23 -07006875 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006876 goto restart_timer;
6877
Dustin Brown920397d2017-12-13 16:27:50 -08006878 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05306879 /*
6880 * Validate magic so we don't end up accessing
6881 * an invalid adapter.
6882 */
6883 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6884 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006885
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006886 if ((adapter->device_mode == QDF_STA_MODE ||
6887 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6889 != eConnectionState_Associated) {
6890
6891 continue;
6892 }
6893
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006894 if ((adapter->device_mode == QDF_SAP_MODE ||
6895 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006896 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006897
6898 continue;
6899 }
6900
6901 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6902 adapter->prev_tx_packets);
6903 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6904 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306905
6906 if (adapter->device_mode == QDF_SAP_MODE ||
6907 adapter->device_mode == QDF_P2P_GO_MODE ||
6908 adapter->device_mode == QDF_IBSS_MODE) {
6909
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006910 ret = cdp_get_intra_bss_fwd_pkts_count(
6911 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006912 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306913 &fwd_tx_packets, &fwd_rx_packets);
6914 if (ret == A_OK) {
6915 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6916 fwd_tx_packets,
6917 adapter->prev_fwd_tx_packets);
6918 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6919 fwd_tx_packets,
6920 adapter->prev_fwd_rx_packets);
6921 }
6922 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923
6924 total_rx += adapter->stats.rx_packets;
6925 total_tx += adapter->stats.tx_packets;
6926
6927 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6928 adapter->prev_tx_packets = adapter->stats.tx_packets;
6929 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306930 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6931 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006932 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6933 connected = true;
6934 }
6935
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306936 /* add intra bss forwarded tx and rx packets */
6937 tx_packets += fwd_tx_packets_diff;
6938 rx_packets += fwd_rx_packets_diff;
6939
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006940 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6941 tx_packets += (uint64_t)ipa_tx_packets;
6942 rx_packets += (uint64_t)ipa_rx_packets;
6943
Yun Park2aa880c2017-08-22 10:58:10 -07006944 if (adapter) {
6945 adapter->stats.tx_packets += ipa_tx_packets;
6946 adapter->stats.rx_packets += ipa_rx_packets;
6947 }
6948
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006949 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006950 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951 return;
6952 }
6953
Yuanyuan Liu13738502016-04-06 17:41:37 -07006954 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006955
6956 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6957 hdd_ipa_uc_stat_request(adapter, 2);
6958
Jingxiang Gec64e1932017-08-22 14:38:59 +08006959restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006960 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006961 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006962 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306963 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006964 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006965 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006966}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006967
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306968/**
6969 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6970 * @arg: Argument of timer function
6971 *
6972 * Schedule a workqueue in this function where all the processing is done.
6973 *
6974 * Return: None.
6975 */
6976static void __hdd_bus_bw_cbk(void *arg)
6977{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006978 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306979
6980 if (wlan_hdd_validate_context(hdd_ctx))
6981 return;
6982
6983 schedule_work(&hdd_ctx->bus_bw_work);
6984}
6985
6986/**
6987 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6988 * @arg: Argument of timer function
6989 *
6990 * Return: None.
6991 */
6992static void hdd_bus_bw_cbk(void *arg)
6993{
6994 cds_ssr_protect(__func__);
6995 __hdd_bus_bw_cbk(arg);
6996 cds_ssr_unprotect(__func__);
6997}
6998
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006999int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007000{
7001 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307002 INIT_WORK(&hdd_ctx->bus_bw_work,
7003 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007004 hdd_ctx->bus_bw_timer_running = false;
7005 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307006 qdf_timer_init(NULL,
7007 &hdd_ctx->bus_bw_timer,
7008 hdd_bus_bw_cbk, (void *)hdd_ctx,
7009 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007010
7011 return 0;
7012}
7013
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007014void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007015{
Dustin Brownfce08d12017-01-17 16:29:38 -08007016 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007017 hdd_reset_tcp_delack(hdd_ctx);
7018
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007019 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307020 cancel_work_sync(&hdd_ctx->bus_bw_work);
7021 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007022 hdd_ctx->bus_bw_timer_running = false;
7023 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007024}
Lin Baic5c06882017-09-21 13:58:43 +08007025
7026void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7027{
7028 if (hdd_ctx)
7029 cancel_work_sync(&hdd_ctx->bus_bw_work);
7030}
jiadcdaf9bd2017-10-26 12:20:21 +08007031
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007032#endif
7033
7034/**
Nirav Shahed34b212016-04-25 10:59:16 +05307035 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7036 * @hdd_ctx: hdd context
7037 *
7038 * Return: 0 for success or error code
7039 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007040static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307041{
7042 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7043 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7044 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007045 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307046 return -ENOMEM;
7047 }
7048 return 0;
7049}
7050
7051/**
7052 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7053 * @hdd_ctx: hdd context
7054 *
7055 * Return: none
7056 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007057void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307058{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307059 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7060 return;
7061
7062 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7063 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307064}
7065
Nirav Shahda008342016-05-17 18:50:40 +05307066static uint8_t *convert_level_to_string(uint32_t level)
7067{
7068 switch (level) {
7069 /* initialize the wlan sub system */
7070 case WLAN_SVC_TP_NONE:
7071 return "NONE";
7072 case WLAN_SVC_TP_LOW:
7073 return "LOW";
7074 case WLAN_SVC_TP_MEDIUM:
7075 return "MED";
7076 case WLAN_SVC_TP_HIGH:
7077 return "HIGH";
7078 default:
7079 return "INVAL";
7080 }
7081}
7082
Nirav Shahed34b212016-04-25 10:59:16 +05307083
7084/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007085 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7086 * @hdd_ctx: hdd context
7087 *
7088 * Return: none
7089 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007090void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007091{
7092 int i;
7093
7094#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007095 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307096 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007097 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007098 hdd_ctx->config->busBandwidthHighThreshold,
7099 hdd_ctx->config->busBandwidthMediumThreshold,
7100 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007101 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307102 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007103 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007104 hdd_ctx->config->tcpDelackThresholdHigh,
7105 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007106 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307107 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007108#endif
7109
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007110 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307111 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7112
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007113 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007114
7115 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007116 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007117 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07007118 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007119 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7120 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007121 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007122 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7123 convert_level_to_string(
7124 hdd_ctx->hdd_txrx_hist[i].
7125 next_vote_level),
7126 convert_level_to_string(
7127 hdd_ctx->hdd_txrx_hist[i].
7128 next_rx_level),
7129 convert_level_to_string(
7130 hdd_ctx->hdd_txrx_hist[i].
7131 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007132 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007133}
7134
7135/**
7136 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7137 * @hdd_ctx: hdd context
7138 *
7139 * Return: none
7140 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007141void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007142{
7143 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307144 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7145 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007146}
7147
Mohit Khannaca4173b2017-09-12 21:52:19 -07007148/* length of the netif queue log needed per adapter */
7149#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7150
7151/**
7152 *
7153 * hdd_display_netif_queue_history_compact() - display compact netifq history
7154 * @hdd_ctx: hdd context
7155 *
7156 * Return: none
7157 */
7158static void
7159hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7160{
7161 int adapter_num = 0;
7162 int i;
7163 int bytes_written;
7164 u32 tbytes;
7165 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007166 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007167 char *comb_log_str;
7168 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007169 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007170
jiadbdefb252018-01-03 14:27:06 +08007171 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7172 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7173 if (!comb_log_str) {
7174 hdd_err("failed to alloc comb_log_str");
7175 return;
7176 }
7177
Mohit Khannaca4173b2017-09-12 21:52:19 -07007178 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007179
Dustin Brown920397d2017-12-13 16:27:50 -08007180 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007181 curr_time = qdf_system_ticks();
7182 total = curr_time - adapter->start_time;
7183 delta = curr_time - adapter->last_time;
7184
7185 if (adapter->pause_map) {
7186 pause = adapter->total_pause_time + delta;
7187 unpause = adapter->total_unpause_time;
7188 } else {
7189 unpause = adapter->total_unpause_time + delta;
7190 pause = adapter->total_pause_time;
7191 }
7192
7193 tbytes = 0;
7194 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7195 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7196 if (adapter->queue_oper_stats[i].pause_count == 0)
7197 continue;
7198 tbytes +=
7199 snprintf(
7200 &temp_str[tbytes],
7201 (tbytes >= sizeof(temp_str) ?
7202 0 : sizeof(temp_str) - tbytes),
7203 "%d(%d,%d) ",
7204 i,
7205 adapter->queue_oper_stats[i].
7206 pause_count,
7207 adapter->queue_oper_stats[i].
7208 unpause_count);
7209 }
7210 if (tbytes >= sizeof(temp_str))
7211 hdd_warn("log truncated");
7212
7213 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007214 bytes_written >= comb_log_str_size ? 0 :
7215 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007216 "[%d %d] (%d) %u/%ums %s|",
7217 adapter->session_id, adapter->device_mode,
7218 adapter->pause_map,
7219 qdf_system_ticks_to_msecs(pause),
7220 qdf_system_ticks_to_msecs(total),
7221 temp_str);
7222
Mohit Khannaca4173b2017-09-12 21:52:19 -07007223 adapter_num++;
7224 }
7225
7226 /* using QDF_TRACE to avoid printing function name */
7227 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7228 "STATS |%s", comb_log_str);
7229
jiadbdefb252018-01-03 14:27:06 +08007230 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007231 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007232
7233 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007234}
7235
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007236/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007237 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007238 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007239 *
7240 * Return: none
7241 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007242void
7243wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7244 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007245{
7246
Jeff Johnson9d295242017-08-29 14:39:48 -07007247 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007248 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307249 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007250
Mohit Khannaca4173b2017-09-12 21:52:19 -07007251 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7252 hdd_display_netif_queue_history_compact(hdd_ctx);
7253 return;
7254 }
7255
Dustin Brown920397d2017-12-13 16:27:50 -08007256 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007257 hdd_debug("Netif queue operation statistics:");
7258 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007259 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007260 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307261 curr_time = qdf_system_ticks();
7262 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307263 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307264 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307265 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307266 unpause = adapter->total_unpause_time;
7267 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307268 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307269 pause = adapter->total_pause_time;
7270 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007271 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307272 qdf_system_ticks_to_msecs(total),
7273 qdf_system_ticks_to_msecs(pause),
7274 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007275 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007276
Nirav Shahda008342016-05-17 18:50:40 +05307277 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7278 qdf_time_t pause_delta = 0;
7279
7280 if (adapter->pause_map & (1 << i))
7281 pause_delta = delta;
7282
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007283 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07007284 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007285 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007286 hdd_reason_type_to_string(i),
7287 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05307288 adapter->queue_oper_stats[i].unpause_count,
7289 qdf_system_ticks_to_msecs(
7290 adapter->queue_oper_stats[i].total_pause_time +
7291 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007292 }
7293
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007294 hdd_debug("Netif queue operation history:");
7295 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307296 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7297
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007298 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007299
7300 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007301 /* using hdd_log to avoid printing function name */
7302 if (adapter->queue_oper_history[i].time == 0)
7303 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07007304 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007305 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05307306 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007307 adapter->queue_oper_history[i].time),
7308 hdd_action_type_to_string(
7309 adapter->queue_oper_history[i].netif_action),
7310 hdd_reason_type_to_string(
7311 adapter->queue_oper_history[i].netif_reason),
7312 adapter->queue_oper_history[i].pause_map);
7313 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007314 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007315}
7316
7317/**
7318 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7319 * @hdd_ctx: hdd context
7320 *
7321 * Return: none
7322 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007323void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007324{
Jeff Johnson9d295242017-08-29 14:39:48 -07007325 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007326
Dustin Brown920397d2017-12-13 16:27:50 -08007327 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307328 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007329 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307330 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007331 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307332 adapter->history_index = 0;
7333 adapter->start_time = adapter->last_time = qdf_system_ticks();
7334 adapter->total_pause_time = 0;
7335 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007336 }
7337}
7338
7339/**
7340 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7341 * @halHandle: Hal handle
7342 * @pContext: Pointer to the context
7343 * @sessionId: Session ID
7344 * @scanId: Scan ID
7345 * @status: Status
7346 *
7347 * This is the callback to be executed when 11d scan is completed to flush out
7348 * the scan results
7349 *
7350 * 11d scan is done during driver load and is a passive scan on all
7351 * channels supported by the device, 11d scans may find some APs on
7352 * frequencies which are forbidden to be used in the regulatory domain
7353 * the device is operating in. If these APs are notified to the supplicant
7354 * it may try to connect to these APs, thus flush out all the scan results
7355 * which are present in SME after 11d scan is done.
7356 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307357 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007358 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307359static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007360 uint8_t sessionId, uint32_t scanId,
7361 eCsrScanStatus status)
7362{
7363 ENTER();
7364
7365 sme_scan_flush_result(halHandle);
7366
7367 EXIT();
7368
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307369 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007370}
7371
7372#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7373/**
7374 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7375 * @hdd_ctx: hdd global context
7376 *
7377 * Return: none
7378 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007379static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007380{
7381 uint8_t i;
7382
7383 mutex_init(&hdd_ctx->op_ctx.op_lock);
7384 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7385 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7386 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7387 }
7388}
7389#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007390static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007391{
7392}
7393#endif
7394
Yingying Tang95409972016-10-20 15:16:15 +08007395#ifdef WLAN_FEATURE_WOW_PULSE
7396/**
7397 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007398 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007399 * @enable: enable or disable this behaviour
7400 *
7401 * Return: int
7402 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007403static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007404{
7405 struct hdd_config *pcfg_ini = phddctx->config;
7406 struct wow_pulse_mode wow_pulse_set_info;
7407 QDF_STATUS status;
7408
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007409 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007410
7411 if (false == phddctx->config->wow_pulse_support)
7412 return 0;
7413
7414 /* prepare the request to send to SME */
7415 if (enable == true) {
7416 wow_pulse_set_info.wow_pulse_enable = true;
7417 wow_pulse_set_info.wow_pulse_pin =
7418 pcfg_ini->wow_pulse_pin;
7419 wow_pulse_set_info.wow_pulse_interval_low =
7420 pcfg_ini->wow_pulse_interval_low;
7421 wow_pulse_set_info.wow_pulse_interval_high =
7422 pcfg_ini->wow_pulse_interval_high;
7423 } else {
7424 wow_pulse_set_info.wow_pulse_enable = false;
7425 wow_pulse_set_info.wow_pulse_pin = 0;
7426 wow_pulse_set_info.wow_pulse_interval_low = 0;
7427 wow_pulse_set_info.wow_pulse_interval_high = 0;
7428 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007429 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007430 wow_pulse_set_info.wow_pulse_enable,
7431 wow_pulse_set_info.wow_pulse_pin,
7432 wow_pulse_set_info.wow_pulse_interval_low,
7433 wow_pulse_set_info.wow_pulse_interval_high);
7434
7435 status = sme_set_wow_pulse(&wow_pulse_set_info);
7436 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007437 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007438 return -EIO;
7439 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007440 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007441 return 0;
7442}
7443#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007444static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007445{
7446 return 0;
7447}
7448#endif
7449
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007450#ifdef WLAN_FEATURE_FASTPATH
7451/**
7452 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7453 * @hdd_cfg: hdd config
7454 * @context: lower layer context
7455 *
7456 * Return: none
7457 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307458void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007459 void *context)
7460{
7461 if (hdd_cfg->fastpath_enable)
7462 hif_enable_fastpath(context);
7463}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007464#endif
7465
Yuanyuan Liu13738502016-04-06 17:41:37 -07007466#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007467/**
7468 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007469 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007470 * @level: thermal level
7471 *
7472 * Change IPA data path to SW path when the thermal throttle level greater
7473 * than 0, and restore the original data path when throttle level is 0
7474 *
7475 * Return: none
7476 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007477static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007478{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007479 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007480
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007481 /* Change IPA to SW path when throttle level greater than 0 */
7482 if (level > THROTTLE_LEVEL_0)
7483 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7484 else
7485 /* restore original concurrency mode */
7486 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7487}
7488
7489/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307490 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7491 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307492 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007493 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307494 * Get a safe channel to restart SAP. PCL already takes into account the
7495 * unsafe channels. So, the PCL is validated with the ACS range to provide
7496 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007497 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307498 * Return: Channel number to restart SAP in case of success. In case of any
7499 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007500 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307501static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007502 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007503{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307504 struct sir_pcl_list pcl;
7505 QDF_STATUS status;
7506 uint32_t i, j;
7507 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007508 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307509 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007510 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007511
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307512 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7513 if (!hdd_ctx) {
7514 hdd_err("invalid HDD context");
7515 return INVALID_CHANNEL_ID;
7516 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007517
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307518 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7519 if (!hal_handle) {
7520 hdd_err("invalid HAL handle");
7521 return INVALID_CHANNEL_ID;
7522 }
7523
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007524 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7525 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007526 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7527 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307528 if (QDF_IS_STATUS_ERROR(status)) {
7529 hdd_err("Get PCL failed");
7530 return INVALID_CHANNEL_ID;
7531 }
7532
Frank Liudc2cefb2017-06-21 15:38:18 +08007533 /*
7534 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7535 * channel is unsafe channel, the pcl may be empty, instead of return,
7536 * try to choose a safe channel from acs range.
7537 */
7538 if (!pcl.pcl_len)
7539 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307540
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007541 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007542 adapter->session.ap.sap_config.acs_cfg.start_ch,
7543 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307544
7545 /* PCL already takes unsafe channel into account */
7546 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007547 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307548 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007549 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307550 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007551 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007552 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307553 return pcl.pcl_list[i];
7554 }
7555 }
7556
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007557 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307558
7559 /* Try for safe channel from all valid channel */
7560 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007561 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7562 &pcl.pcl_len);
7563 if (ret) {
7564 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307565 return INVALID_CHANNEL_ID;
7566 }
7567
7568 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007569 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307570 found = false;
7571 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007572 if (pcl.pcl_list[i] ==
7573 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007574 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307575 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007576 break;
7577 }
7578 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307579
7580 if (found)
7581 continue;
7582
7583 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007584 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307585 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007586 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007587 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307588 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007589 }
7590 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307591
7592 return INVALID_CHANNEL_ID;
7593}
7594
7595/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007596 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307597 * @adapter: AP adapter
7598 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007599 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307600 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007601 * Moves the SAP interface by invoking the function which
7602 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307603 *
7604 * Return: None
7605 */
Min Liu2fef5792018-01-19 17:59:42 +08007606void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7607 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307608{
Jeff Johnson87251032017-08-29 13:31:11 -07007609 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307610 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007611 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307612
7613 if (!adapter) {
7614 hdd_err("invalid adapter");
7615 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007616 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307617
7618 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7619
7620 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7621 if (!hal_handle) {
7622 hdd_err("invalid HAL handle");
7623 return;
7624 }
7625
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007626 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7627
Jeff Johnson91df29d2017-10-27 19:29:50 -07007628 hdd_ap_ctx->sap_config.channel = channel;
7629 hdd_ap_ctx->sap_config.ch_params.ch_width =
7630 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307631
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007632 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007633 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307634
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007635 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007636 hdd_ap_ctx->sap_config.channel,
7637 hdd_ap_ctx->sap_config.sec_ch,
7638 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307639
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007640 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007641 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007642 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007643}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307644
Jeff Johnson9d295242017-08-29 14:39:48 -07007645int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307646{
7647 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307648 int status;
7649 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307650
7651 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7652
7653 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007654 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307655 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007656 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307657 }
7658 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007659 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307660 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307661 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007662 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307663 WLAN_VENDOR_ACS_WAIT_TIME);
7664 if (qdf_status != QDF_STATUS_SUCCESS) {
7665 hdd_err("failed to start external acs timer");
7666 return -ENOSPC;
7667 }
7668 /* Update config to application */
7669 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307670 hdd_notice("Updated ACS config to nl with reason %d", reason);
7671
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307672 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307673}
7674
Agrawal Ashish467dde42016-09-08 18:44:22 +05307675/**
7676 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7677 * @hdd_ctx: hdd context pointer
7678 *
7679 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7680 * and if ACS is enabled, driver will ask userspace to restart the
7681 * sap. User space on LTE coex indication restart driver.
7682 *
7683 * Return - none
7684 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007685void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307686{
Dustin Brown920397d2017-12-13 16:27:50 -08007687 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307688 uint32_t i;
7689 bool found = false;
7690 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007691
Dustin Brown920397d2017-12-13 16:27:50 -08007692 hdd_for_each_adapter(hdd_ctxt, adapter) {
7693 if (!(adapter->device_mode == QDF_SAP_MODE &&
7694 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007695 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007696 adapter->device_mode,
7697 adapter->session.ap.sap_config.
7698 acs_cfg.acs_mode);
7699 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307700 }
7701
7702 found = false;
7703 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007704 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307705 hdd_ctxt->unsafe_channel_list[i]) {
7706 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007707 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007708 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307709 break;
7710 }
7711 }
7712
7713 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007714 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007715 adapter->session.ap.operating_channel);
7716 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307717 }
7718
Kapil Gupta8878ad92017-02-13 11:56:04 +05307719 if (hdd_ctxt->config->vendor_acs_support &&
7720 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007721 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307722 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007723 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307724 } else
7725 restart_chan =
7726 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007727 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307728 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007729 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307730 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007731 /*
7732 * SAP restart due to unsafe channel. While
7733 * restarting the SAP, make sure to clear
7734 * acs_channel, channel to reset to
7735 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307736 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007737 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307738 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007739 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307740 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007741 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307742 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7743 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007744 hdd_debug("driver to start sap: %d",
7745 hdd_ctxt->config->sap_internal_restart);
7746 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08007747 hdd_switch_sap_channel(adapter, restart_chan,
7748 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04007749 else
7750 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307751 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307752 }
7753}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307754
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007755/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007756 * hdd_init_channel_avoidance() - Initialize channel avoidance
7757 * @hdd_ctx: HDD global context
7758 *
7759 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007760 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007761 * down to the lower layers. Then subscribe to subsequent channel
7762 * avoidance events.
7763 *
7764 * Return: None
7765 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007766static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007767{
7768 uint16_t unsafe_channel_count;
7769 int index;
7770
Yuanyuan Liu13738502016-04-06 17:41:37 -07007771 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7772 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007773 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007774 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007775
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007776 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007777 hdd_ctx->unsafe_channel_count);
7778
Anurag Chouhan6d760662016-02-20 16:05:43 +05307779 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007780 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007781
7782 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007783 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007784 hdd_ctx->unsafe_channel_list[index]);
7785
7786 }
7787
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007788}
Dustin Brown676a2322017-08-15 13:16:13 -07007789
Jeff Johnson9d295242017-08-29 14:39:48 -07007790static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007791 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007792{
7793 uint8_t restart_chan;
7794
7795 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7796 if (!restart_chan) {
7797 hdd_alert("fail to restart SAP");
7798 return;
7799 }
7800
7801 /* SAP restart due to unsafe channel. While restarting
7802 * the SAP, make sure to clear acs_channel, channel to
7803 * reset to 0. Otherwise these settings will override
7804 * the ACS while restart.
7805 */
7806 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007807 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007808
7809 hdd_debug("sending coex indication");
7810
7811 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7812 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08007813 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07007814}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007815
7816int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7817 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7818{
7819 uint32_t size;
7820 uint16_t *unsafe_list;
7821 uint16_t chan_count;
7822
7823 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7824 return -EINVAL;
7825
7826 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7827 NUM_CHANNELS);
7828 if (chan_count) {
7829 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7830 unsafe_list = qdf_mem_malloc(size);
7831 if (!unsafe_list) {
7832 hdd_err("No memory for unsafe chan list size%d",
7833 size);
7834 return -ENOMEM;
7835 }
7836 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7837 } else {
7838 unsafe_list = NULL;
7839 }
7840
7841 *local_unsafe_list = unsafe_list;
7842 *local_unsafe_list_count = chan_count;
7843
7844 return 0;
7845}
7846
7847bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7848 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7849{
7850 int i, j;
7851
7852 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7853 return true;
7854 if (local_unsafe_list_count == 0)
7855 return false;
7856 for (i = 0; i < local_unsafe_list_count; i++) {
7857 for (j = 0; j < local_unsafe_list_count; j++)
7858 if (local_unsafe_list[i] ==
7859 hdd_ctx->unsafe_channel_list[j])
7860 break;
7861 if (j >= local_unsafe_list_count)
7862 break;
7863 }
7864 if (i >= local_unsafe_list_count) {
7865 hdd_info("unsafe chan list same");
7866 return false;
7867 }
7868
7869 return true;
7870}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007871#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007872static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007873{
7874}
Dustin Brown676a2322017-08-15 13:16:13 -07007875
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007876static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007877{
7878}
Dustin Brown676a2322017-08-15 13:16:13 -07007879
Jeff Johnson9d295242017-08-29 14:39:48 -07007880static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007881 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007882{
7883 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7884}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007885#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007886
7887/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007888 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7889 * user space
7890 * @frame_ind: Management frame data to be informed.
7891 *
7892 * This function is used to indicate management frame to
7893 * user space
7894 *
7895 * Return: None
7896 *
7897 */
7898void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7899{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007900 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007901 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007902 int i;
7903
Rajeev Kumard004abc2016-02-17 12:09:56 -08007904 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007905 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007906
7907 if (0 != wlan_hdd_validate_context(hdd_ctx))
7908 return;
7909
7910 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7911 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7912 adapter =
7913 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7914 if (adapter)
7915 break;
7916 }
Wu Gaoa0230a62018-01-04 20:56:57 +08007917 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
7918 hdd_for_each_adapter(hdd_ctx, adapter) {
7919 if ((NULL != adapter) &&
7920 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
7921 __hdd_indicate_mgmt_frame(adapter,
7922 frame_ind->frame_len,
7923 frame_ind->frameBuf,
7924 frame_ind->frameType,
7925 frame_ind->rxChan,
7926 frame_ind->rxRssi);
7927 }
7928 }
7929 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007930 } else {
7931 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7932 frame_ind->sessionId);
7933 }
7934
7935 if ((NULL != adapter) &&
7936 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7937 __hdd_indicate_mgmt_frame(adapter,
7938 frame_ind->frame_len,
7939 frame_ind->frameBuf,
7940 frame_ind->frameType,
7941 frame_ind->rxChan,
7942 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007943}
7944
Kapil Gupta8878ad92017-02-13 11:56:04 +05307945void hdd_acs_response_timeout_handler(void *context)
7946{
7947 struct hdd_external_acs_timer_context *timer_context =
7948 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007949 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007950 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307951 uint8_t reason;
7952
7953 ENTER();
7954 if (!timer_context) {
7955 hdd_err("invlaid timer context");
7956 return;
7957 }
7958 adapter = timer_context->adapter;
7959 reason = timer_context->reason;
7960
7961
7962 if ((!adapter) ||
7963 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7964 hdd_err("invalid adapter or adapter has invalid magic");
7965 return;
7966 }
7967 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7968 if (wlan_hdd_validate_context(hdd_ctx))
7969 return;
7970
7971 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7972 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7973 else
7974 return;
7975
7976 hdd_err("ACS timeout happened for %s reason %d",
7977 adapter->dev->name, reason);
7978 switch (reason) {
7979 /* SAP init case */
7980 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7981 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7982 false);
7983 wlan_hdd_cfg80211_start_acs(adapter);
7984 break;
7985 /* DFS detected on current channel */
7986 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7987 wlan_sap_update_next_channel(
7988 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7989 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007990 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307991 break;
7992 /* LTE coex event on current channel */
7993 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7994 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7995 break;
7996 default:
7997 hdd_info("invalid reason for timer invoke");
7998
7999 }
8000}
8001
Rajeev Kumard004abc2016-02-17 12:09:56 -08008002/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008003 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
8004 * @hdd_ctx: HDD context
8005 *
8006 * Disables all the dual mac features like DBS, Agile DFS etc.
8007 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308008 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008009 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008010static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008011{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008012 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308013 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008014
8015 if (!hdd_ctx) {
8016 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308017 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008018 }
8019
8020 cfg.scan_config = 0;
8021 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008022 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008023
8024 hdd_debug("Disabling all dual mac features...");
8025
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008026 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308027 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008028 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8029 return status;
8030 }
8031
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308032 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008033}
8034
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008035static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008036wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008037{
8038 struct policy_mgr_dual_mac_config cfg = {0};
8039 QDF_STATUS status;
8040
8041 if (!hdd_ctx) {
8042 hdd_err("HDD context is NULL");
8043 return QDF_STATUS_E_FAILURE;
8044 }
8045
8046 cfg.scan_config = 0;
8047 cfg.fw_mode_config = 0;
8048 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
8049 status = policy_mgr_get_updated_scan_and_fw_mode_config(
8050 hdd_ctx->hdd_psoc, &cfg.scan_config,
8051 &cfg.fw_mode_config,
8052 hdd_ctx->config->dual_mac_feature_disable);
8053
8054 if (status != QDF_STATUS_SUCCESS) {
8055 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
8056 status);
8057 return status;
8058 }
8059
8060 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
8061 cfg.scan_config, cfg.fw_mode_config);
8062
8063 status = sme_soc_set_dual_mac_config(cfg);
8064 if (status != QDF_STATUS_SUCCESS) {
8065 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8066 return status;
8067 }
8068
8069 return QDF_STATUS_SUCCESS;
8070}
8071
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008072/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008073 * hdd_override_ini_config - Override INI config
8074 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008075 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008076 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008077 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008078 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008079 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008080static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008081{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008082
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008083 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8084 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008085 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008086 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008087 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008088 if (0 == enable_11d || 1 == enable_11d) {
8089 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008090 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008091 }
Leo Chang11545d62016-10-17 14:53:50 -07008092
8093 if (!hdd_ipa_is_present(hdd_ctx))
8094 hdd_ctx->config->IpaConfig = 0;
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308095
8096 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8097 !hdd_ctx->config->enable_bcast_probe_rsp) {
8098 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8099 hdd_ctx->config->rssi_assoc_reject_enabled,
8100 hdd_ctx->config->enable_bcast_probe_rsp);
8101 hdd_ctx->config->oce_sta_enabled = 0;
8102 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008103}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008104
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008105/**
8106 * hdd_set_trace_level_for_each - Set trace level for each INI config
8107 * @hdd_ctx - HDD context
8108 *
8109 * Set trace level for each module based on INI config.
8110 *
8111 * Return: None
8112 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008113static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008114{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308115 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8116 hdd_ctx->config->qdf_trace_enable_wdi);
8117 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8118 hdd_ctx->config->qdf_trace_enable_hdd);
8119 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8120 hdd_ctx->config->qdf_trace_enable_sme);
8121 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8122 hdd_ctx->config->qdf_trace_enable_pe);
8123 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8124 hdd_ctx->config->qdf_trace_enable_wma);
8125 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8126 hdd_ctx->config->qdf_trace_enable_sys);
8127 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8128 hdd_ctx->config->qdf_trace_enable_qdf);
8129 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8130 hdd_ctx->config->qdf_trace_enable_sap);
8131 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8132 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8133 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8134 hdd_ctx->config->qdf_trace_enable_bmi);
8135 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8136 hdd_ctx->config->qdf_trace_enable_cfg);
8137 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8138 hdd_ctx->config->qdf_trace_enable_epping);
8139 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8140 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8141 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008142 hdd_ctx->config->qdf_trace_enable_txrx);
8143 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8144 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308145 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8146 hdd_ctx->config->qdf_trace_enable_htc);
8147 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8148 hdd_ctx->config->qdf_trace_enable_hif);
8149 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8150 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8151 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8152 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008153 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8154 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008155 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8156 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008157 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8158 hdd_ctx->config->qdf_trace_enable_regulatory);
8159
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008160 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008161}
8162
8163/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008164 * hdd_context_init() - Initialize HDD context
8165 * @hdd_ctx: HDD context.
8166 *
8167 * Initialize HDD context along with all the feature specific contexts.
8168 *
8169 * return: 0 on success and errno on failure.
8170 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008171static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008172{
8173 int ret;
8174
8175 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8176 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8177
8178 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308179 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008180
8181 init_completion(&hdd_ctx->mc_sus_event_var);
8182 init_completion(&hdd_ctx->ready_to_suspend);
8183
8184 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308185 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008186 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308187
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008188 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008189
8190 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8191
8192 ret = hdd_scan_context_init(hdd_ctx);
8193 if (ret)
8194 goto list_destroy;
8195
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008196 hdd_rx_wake_lock_create(hdd_ctx);
8197
8198 ret = hdd_sap_context_init(hdd_ctx);
8199 if (ret)
8200 goto scan_destroy;
8201
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008202 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8203
8204 hdd_init_offloaded_packets_ctx(hdd_ctx);
8205
8206 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8207 hdd_ctx->config);
8208 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008209 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008210
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308211 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8212 "monitor_mode_wakelock");
8213
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008214 return 0;
8215
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008216sap_destroy:
8217 hdd_sap_context_destroy(hdd_ctx);
8218
8219scan_destroy:
8220 hdd_scan_context_destroy(hdd_ctx);
8221 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008222list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008223 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008224
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008225 return ret;
8226}
8227
8228/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308229 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8230 * @hdd_ctx: pointer to hdd context
8231 *
8232 * Return: status of initialization
8233 * 0 - success
8234 * negative value - failure
8235 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008236static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308237{
8238 int ret;
8239
8240 if (!hdd_ctx->config->probe_req_ie_whitelist)
8241 return 0;
8242
8243 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8244 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8245 hdd_ctx->config->probe_req_ie_whitelist = false;
8246 return -EINVAL;
8247 }
8248
8249 /* parse ini string probe req oui */
8250 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8251 if (ret) {
8252 hdd_err("parsing error: disable ie whitelisting");
8253 hdd_ctx->config->probe_req_ie_whitelist = false;
8254 }
8255
8256 return ret;
8257}
8258
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308259
8260/**
8261 * hdd_iface_change_callback() - Function invoked when stop modules expires
8262 * @priv: pointer to hdd context
8263 *
8264 * This function is invoked when the timer waiting for the interface change
8265 * expires, it shall cut-down the power to wlan and stop all the modules.
8266 *
8267 * Return: void
8268 */
8269static void hdd_iface_change_callback(void *priv)
8270{
8271 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8272 int ret;
8273 int status = wlan_hdd_validate_context(hdd_ctx);
8274
8275 if (status)
8276 return;
8277
8278 ENTER();
8279 hdd_debug("Interface change timer expired close the modules!");
8280 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8281 if (ret)
8282 hdd_err("Failed to stop modules");
8283 EXIT();
8284}
8285
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308286/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008287 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308288 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008289 *
8290 * Allocate and initialize HDD context. HDD context is allocated as part of
8291 * wiphy allocation and then context is initialized.
8292 *
8293 * Return: HDD context on success and ERR_PTR on failure
8294 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008295static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008296{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308297 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008298 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008299 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008300
8301 ENTER();
8302
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008303 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008304 if (hdd_ctx == NULL) {
8305 ret = -ENOMEM;
8306 goto err_out;
8307 }
8308
Dustin Brown6f427922017-09-19 12:19:00 -07008309 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8310 hdd_iface_change_callback,
8311 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308312
8313 mutex_init(&hdd_ctx->iface_change_lock);
8314
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008315 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308316 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008317
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308318 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008319 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008320 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008321 ret = -ENOMEM;
8322 goto err_free_hdd_context;
8323 }
8324
8325 /* Read and parse the qcom_cfg.ini file */
8326 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308327 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308328 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008329 WLAN_INI_FILE);
8330 ret = -EINVAL;
8331 goto err_free_config;
8332 }
8333
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308334 ie_whitelist_attrs_init(hdd_ctx);
8335
Dustin Brown7f939932017-05-18 15:02:17 -07008336 hdd_debug("setting timer multiplier: %u",
8337 hdd_ctx->config->timer_multiplier);
8338 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8339
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008340
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308341 if (hdd_ctx->config->fhostNSOffload)
8342 hdd_ctx->ns_offload_enable = true;
8343
Abhishek Singh5ea86532016-04-27 14:10:53 +05308344 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8345
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008346 hdd_override_ini_config(hdd_ctx);
8347
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008348 ret = hdd_context_init(hdd_ctx);
8349
8350 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008351 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008352
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008353 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308354 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008355
Anurag Chouhan6d760662016-02-20 16:05:43 +05308356 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008357 goto skip_multicast_logging;
8358
8359 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8360
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008361 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8362 if (ret)
8363 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308364
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008365 ret = hdd_init_netlink_services(hdd_ctx);
8366 if (ret)
8367 goto err_deinit_txrx_histogram;
8368
Dustin Brown7b3dea22017-07-10 13:02:47 -07008369 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
8370 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05308371
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008372skip_multicast_logging:
8373 hdd_set_trace_level_for_each(hdd_ctx);
8374
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008375 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8376
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008377 EXIT();
8378
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008379 return hdd_ctx;
8380
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008381err_deinit_txrx_histogram:
8382 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8383
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008384err_deinit_hdd_context:
8385 hdd_context_deinit(hdd_ctx);
8386
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008387err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308388 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008389
8390err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308391 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008392 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008393
8394err_out:
8395 return ERR_PTR(ret);
8396}
8397
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008398#ifdef WLAN_OPEN_P2P_INTERFACE
8399/**
8400 * hdd_open_p2p_interface - Open P2P interface
8401 * @hdd_ctx: HDD context
8402 * @rtnl_held: True if RTNL lock held
8403 *
8404 * Open P2P interface during probe. This function called to open the P2P
8405 * interface at probe along with STA interface.
8406 *
8407 * Return: 0 on success and errno on failure
8408 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008409static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008410{
Jeff Johnson9d295242017-08-29 14:39:48 -07008411 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008412 uint8_t *p2p_dev_addr;
8413
8414 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8415 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008416 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008417 hdd_ctx->config->intfMacAddr[0].bytes,
8418 sizeof(tSirMacAddr));
8419
8420 /*
8421 * Generate the P2P Device Address. This consists of
8422 * the device's primary MAC address with the locally
8423 * administered bit set.
8424 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008425 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008426 } else {
8427 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8428 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008429 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008430 return -ENOSPC;
8431 }
8432
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008433 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8434 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008435 }
8436
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008437 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008438 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008439 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008440
8441 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008442 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008443 return -ENOSPC;
8444 }
8445
8446 return 0;
8447}
8448#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008449static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008450 bool rtnl_held)
8451{
8452 return 0;
8453}
8454#endif
8455
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008456static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008457{
Jeff Johnson9d295242017-08-29 14:39:48 -07008458 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008459 int ret = 0;
8460
8461 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8462 wlan_hdd_get_intf_addr(hdd_ctx),
8463 NET_NAME_UNKNOWN, rtnl_held);
8464 if (adapter == NULL) {
8465 hdd_err("Failed to open 802.11p interface");
8466 ret = -ENOSPC;
8467 }
8468
8469 return ret;
8470}
8471
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008472/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308473 * hdd_start_station_adapter()- Start the Station Adapter
8474 * @adapter: HDD adapter
8475 *
8476 * This function initializes the adapter for the station mode.
8477 *
8478 * Return: 0 on success or errno on failure.
8479 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008480int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308481{
8482 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008483 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308484
8485 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008486 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8487 hdd_err("session is already opened, %d",
8488 adapter->session_id);
8489 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8490 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308491
Krunal Sonib51eec72017-11-20 21:53:01 -08008492 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8493 if (ret) {
8494 hdd_err("failed to create vdev: %d", ret);
8495 return ret;
8496 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308497 status = hdd_init_station_mode(adapter);
8498
8499 if (QDF_STATUS_SUCCESS != status) {
8500 hdd_err("Error Initializing station mode: %d", status);
8501 return qdf_status_to_os_return(status);
8502 }
8503
Arun Khandavallifae92942016-08-01 13:31:08 +05308504 hdd_register_tx_flow_control(adapter,
8505 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008506 hdd_tx_resume_cb,
8507 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308508
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308509 EXIT();
8510 return 0;
8511}
8512
8513/**
8514 * hdd_start_ap_adapter()- Start AP Adapter
8515 * @adapter: HDD adapter
8516 *
8517 * This function initializes the adapter for the AP mode.
8518 *
8519 * Return: 0 on success errno on failure.
8520 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008521int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308522{
8523 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008524 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008525 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008526 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308527
8528 ENTER();
8529
Krunal Sonib51eec72017-11-20 21:53:01 -08008530 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8531 hdd_err("session is already opened, %d",
8532 adapter->session_id);
8533 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8534 }
8535 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008536 * In SSR case no need to create new sap context.
8537 * Otherwise create sap context first and then create
8538 * vdev as while creating the vdev, driver needs to
8539 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008540 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008541 if (adapter->session.ap.sap_context) {
8542 is_ssr = true;
8543 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008544 hdd_err("sap creation failed");
8545 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8546 }
8547
8548 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8549 adapter->session.ap.sap_context);
8550 if (ret) {
8551 hdd_err("failed to create vdev, status:%d", ret);
8552 hdd_sap_destroy_ctx(adapter);
8553 return ret;
8554 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008555
8556 if (adapter->device_mode == QDF_SAP_MODE)
8557 sme_cli_set_command(adapter->session_id,
8558 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8559 (bool)(hdd_ctx->config->fine_time_meas_cap &
8560 WMI_FW_AP_RTT_RESPR),
8561 VDEV_CMD);
8562
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008563 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308564
8565 if (QDF_STATUS_SUCCESS != status) {
8566 hdd_err("Error Initializing the AP mode: %d", status);
8567 return qdf_status_to_os_return(status);
8568 }
8569
Arun Khandavallifae92942016-08-01 13:31:08 +05308570 hdd_register_tx_flow_control(adapter,
8571 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008572 hdd_softap_tx_resume_cb,
8573 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308574
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308575 EXIT();
8576 return 0;
8577}
8578
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308579static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8580 bool rtnl_held)
8581{
8582 struct hdd_adapter *adapter;
8583
8584 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8585 hdd_ctx->config->enableConcurrentSTA,
8586 wlan_hdd_get_intf_addr(hdd_ctx),
8587 NET_NAME_UNKNOWN, rtnl_held);
8588
8589 if (!adapter)
8590 return -ENOSPC;
8591
8592 return 0;
8593}
8594
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308595/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008596 * hdd_open_interfaces - Open all required interfaces
8597 * hdd_ctx: HDD context
8598 * rtnl_held: True if RTNL lock is held
8599 *
8600 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8601 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008602 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008603 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008604static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008605{
Jeff Johnson9d295242017-08-29 14:39:48 -07008606 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008607 int ret;
8608
Ravi Joshia307f632017-07-17 23:41:41 -07008609 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008610 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8611 con_mode == QDF_GLOBAL_FTM_MODE) {
8612 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8613 QDF_MONITOR_MODE : QDF_FTM_MODE;
8614
8615 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8616 wlan_hdd_get_intf_addr(hdd_ctx),
8617 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008618 if (!adapter) {
8619 hdd_err("open adapter failed");
8620 return -ENOSPC;
8621 }
Lin Bai1c678482017-12-18 18:29:11 +08008622
Ravi Joshia307f632017-07-17 23:41:41 -07008623 return 0;
8624 }
8625
Jeff Johnson957bc272017-02-02 08:54:48 -08008626 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308627 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008628 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008629
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008630 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008631 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008632 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008633
8634 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008635 return -ENOSPC;
8636
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308637 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8638 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8639 if (ret)
8640 hdd_err("Cannot create concurrent STA interface");
8641 }
8642
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008643 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8644 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008645 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008646
8647 /* Open 802.11p Interface */
8648 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008649 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8650 if (ret)
8651 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008652 }
8653
Jeff Johnson957bc272017-02-02 08:54:48 -08008654 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008655
Jeff Johnson957bc272017-02-02 08:54:48 -08008656err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008657 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008658 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008659}
8660
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008661
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308662#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8663/**
8664 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8665 * @cds_cfg: CDS Configuration
8666 * @hdd_ctx: Pointer to hdd context
8667 *
8668 * Return: none
8669 */
8670static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8671 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008672 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308673{
8674 cds_cfg->tx_flow_stop_queue_th =
8675 hdd_ctx->config->TxFlowStopQueueThreshold;
8676 cds_cfg->tx_flow_start_queue_offset =
8677 hdd_ctx->config->TxFlowStartQueueOffset;
8678}
8679#else
8680static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8681 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008682 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308683{
8684}
8685#endif
8686
8687#ifdef FEATURE_WLAN_RA_FILTERING
8688/**
8689 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8690 * @cds_cfg: CDS Configuration
8691 * @hdd_ctx: Pointer to hdd context
8692 *
8693 * Return: none
8694 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308695static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008696 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308697{
8698 cds_cfg->ra_ratelimit_interval =
8699 hdd_ctx->config->RArateLimitInterval;
8700 cds_cfg->is_ra_ratelimit_enabled =
8701 hdd_ctx->config->IsRArateLimitEnabled;
8702}
8703#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308704static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008705 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308706{
8707}
8708#endif
8709
8710/**
8711 * hdd_update_cds_config() - API to update cds configuration parameters
8712 * @hdd_ctx: HDD Context
8713 *
8714 * Return: 0 for Success, errno on failure
8715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008716static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308717{
8718 struct cds_config_info *cds_cfg;
8719
8720 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8721 if (!cds_cfg) {
8722 hdd_err("failed to allocate cds config");
8723 return -ENOMEM;
8724 }
8725
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008726 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008727 if (!hdd_ctx->config->nMaxPsPoll ||
8728 !hdd_ctx->config->enablePowersaveOffload) {
8729 cds_cfg->powersave_offload_enabled =
8730 hdd_ctx->config->enablePowersaveOffload;
8731 } else {
8732 if ((hdd_ctx->config->enablePowersaveOffload ==
8733 PS_QPOWER_NODEEPSLEEP) ||
8734 (hdd_ctx->config->enablePowersaveOffload ==
8735 PS_LEGACY_NODEEPSLEEP))
8736 cds_cfg->powersave_offload_enabled =
8737 PS_LEGACY_NODEEPSLEEP;
8738 else
8739 cds_cfg->powersave_offload_enabled =
8740 PS_LEGACY_DEEPSLEEP;
8741 hdd_info("Qpower disabled in cds config, %d",
8742 cds_cfg->powersave_offload_enabled);
8743 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308744 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8745 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8746 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8747 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8748 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8749
8750 /* Here ol_ini_info is used to store ini status of arp offload
8751 * ns offload and others. Currently 1st bit is used for arp
8752 * off load and 2nd bit for ns offload currently, rest bits are unused
8753 */
8754 if (hdd_ctx->config->fhostArpOffload)
8755 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8756 if (hdd_ctx->config->fhostNSOffload)
8757 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8758
8759 /*
8760 * Copy the DFS Phyerr Filtering Offload status.
8761 * This parameter reflects the value of the
8762 * dfs_phyerr_filter_offload flag as set in the ini.
8763 */
8764 cds_cfg->dfs_phyerr_filter_offload =
8765 hdd_ctx->config->fDfsPhyerrFilterOffload;
8766 if (hdd_ctx->config->ssdp)
8767 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8768
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308769 cds_cfg->force_target_assert_enabled =
8770 hdd_ctx->config->crash_inject_enabled;
8771
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308772 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8773 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8774
8775 cds_cfg->ap_maxoffload_reorderbuffs =
8776 hdd_ctx->config->apMaxOffloadReorderBuffs;
8777
8778 cds_cfg->ap_disable_intrabss_fwd =
8779 hdd_ctx->config->apDisableIntraBssFwd;
8780
8781 cds_cfg->dfs_pri_multiplier =
8782 hdd_ctx->config->dfsRadarPriMultiplier;
8783 cds_cfg->reorder_offload =
8784 hdd_ctx->config->reorderOffloadSupport;
8785
8786 /* IPA micro controller data path offload resource config item */
8787 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008788 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8789 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008790 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008791 hdd_ctx->config->IpaUcTxBufCount);
8792 hdd_ctx->config->IpaUcTxBufCount =
8793 rounddown_pow_of_two(
8794 hdd_ctx->config->IpaUcTxBufCount);
8795 if (!hdd_ctx->config->IpaUcTxBufCount) {
8796 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308797 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008798 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008799 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008800 hdd_ctx->config->IpaUcTxBufCount);
8801 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308802 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8803 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008804 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8805 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008806 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008807 hdd_ctx->config->IpaUcRxIndRingCount);
8808 hdd_ctx->config->IpaUcRxIndRingCount =
8809 rounddown_pow_of_two(
8810 hdd_ctx->config->IpaUcRxIndRingCount);
8811 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8812 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308813 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008814 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008815 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008816 hdd_ctx->config->IpaUcRxIndRingCount);
8817 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308818 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008819 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308820 cds_cfg->uc_tx_partition_base =
8821 hdd_ctx->config->IpaUcTxPartitionBase;
8822 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8823
8824 cds_cfg->ip_tcp_udp_checksum_offload =
8825 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008826 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308827 cds_cfg->ce_classify_enabled =
8828 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008829 cds_cfg->bpf_packet_filter_enable =
8830 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308831 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8832 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8833 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008834 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008835 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008836 cds_cfg->max_msdus_per_rxinorderind =
8837 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008838 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008839 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308840 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8841 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308842 cds_cfg->auto_power_save_fail_mode =
8843 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308844
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308845 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008846 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308847
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308848 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8849 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8850 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008851 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308852 cds_init_ini_config(cds_cfg);
8853 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308854
8855exit:
8856 qdf_mem_free(cds_cfg);
8857 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308858}
8859
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008860/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008861 * hdd_update_user_config() - API to update user configuration
8862 * parameters to obj mgr which are used by multiple components
8863 * @hdd_ctx: HDD Context
8864 *
8865 * Return: 0 for Success, errno on failure
8866 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008867static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008868{
8869 struct wlan_objmgr_psoc_user_config *user_config;
8870
8871 user_config = qdf_mem_malloc(sizeof(*user_config));
8872 if (user_config == NULL) {
8873 hdd_alert("Failed to alloc memory for user_config!");
8874 return -ENOMEM;
8875 }
8876
8877 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8878 user_config->dual_mac_feature_disable =
8879 hdd_ctx->config->dual_mac_feature_disable;
8880 user_config->indoor_channel_support =
8881 hdd_ctx->config->indoor_channel_support;
8882 user_config->is_11d_support_enabled =
8883 hdd_ctx->config->Is11dSupportEnabled;
8884 user_config->is_11h_support_enabled =
8885 hdd_ctx->config->Is11hSupportEnabled;
8886 user_config->optimize_chan_avoid_event =
8887 hdd_ctx->config->goptimize_chan_avoid_event;
8888 user_config->skip_dfs_chnl_in_p2p_search =
8889 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008890 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008891 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8892
8893 qdf_mem_free(user_config);
8894 return 0;
8895}
8896
8897/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008898 * hdd_init_thermal_info - Initialize thermal level
8899 * @hdd_ctx: HDD context
8900 *
8901 * Initialize thermal level at SME layer and set the thermal level callback
8902 * which would be called when a configured thermal threshold is hit.
8903 *
8904 * Return: 0 on success and errno on failure
8905 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008906static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008907{
8908 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308909 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008910
8911 thermal_param.smeThermalMgmtEnabled =
8912 hdd_ctx->config->thermalMitigationEnable;
8913 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8914
Poddar, Siddarth83905022016-04-16 17:56:08 -07008915 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8916 hdd_ctx->config->throttle_dutycycle_level0;
8917 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8918 hdd_ctx->config->throttle_dutycycle_level1;
8919 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8920 hdd_ctx->config->throttle_dutycycle_level2;
8921 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8922 hdd_ctx->config->throttle_dutycycle_level3;
8923
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008924 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8925 hdd_ctx->config->thermalTempMinLevel0;
8926 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8927 hdd_ctx->config->thermalTempMaxLevel0;
8928 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8929 hdd_ctx->config->thermalTempMinLevel1;
8930 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8931 hdd_ctx->config->thermalTempMaxLevel1;
8932 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8933 hdd_ctx->config->thermalTempMinLevel2;
8934 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8935 hdd_ctx->config->thermalTempMaxLevel2;
8936 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8937 hdd_ctx->config->thermalTempMinLevel3;
8938 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8939 hdd_ctx->config->thermalTempMaxLevel3;
8940
8941 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8942
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308943 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308944 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008945
8946 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8947 hdd_set_thermal_level_cb);
8948
8949 return 0;
8950
8951}
8952
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008953#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8954/**
8955 * hdd_hold_rtnl_lock - Hold RTNL lock
8956 *
8957 * Hold RTNL lock
8958 *
8959 * Return: True if held and false otherwise
8960 */
8961static inline bool hdd_hold_rtnl_lock(void)
8962{
8963 rtnl_lock();
8964 return true;
8965}
8966
8967/**
8968 * hdd_release_rtnl_lock - Release RTNL lock
8969 *
8970 * Release RTNL lock
8971 *
8972 * Return: None
8973 */
8974static inline void hdd_release_rtnl_lock(void)
8975{
8976 rtnl_unlock();
8977}
8978#else
8979static inline bool hdd_hold_rtnl_lock(void) { return false; }
8980static inline void hdd_release_rtnl_lock(void) { }
8981#endif
8982
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008983#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008984
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308985/* MAX iwpriv command support */
8986#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308987#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308988#define MAX_PKTLOG_SIZE 16
8989
8990/**
8991 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8992 * @hdd_ctx: hdd context
8993 * @set_value2: pktlog buffer size value
8994 *
8995 *
8996 * Return: 0 for success or error.
8997 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008998static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308999{
9000 struct sir_wifi_start_log start_log = { 0 };
9001 QDF_STATUS status;
9002
9003 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9004 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9005 start_log.ini_triggered = cds_is_packet_log_enabled();
9006 start_log.user_triggered = 1;
9007 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309008 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309009
9010 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9011 if (!QDF_IS_STATUS_SUCCESS(status)) {
9012 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9013 EXIT();
9014 return -EINVAL;
9015 }
9016
9017 return 0;
9018}
9019
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009020/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309021 * hdd_pktlog_clear_buff() - clear pktlog buffer
9022 * @hdd_ctx: hdd context
9023 *
9024 * Return: 0 for success or error.
9025 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009026static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309027{
9028 struct sir_wifi_start_log start_log;
9029 QDF_STATUS status;
9030
9031 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9032 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9033 start_log.ini_triggered = cds_is_packet_log_enabled();
9034 start_log.user_triggered = 1;
9035 start_log.size = 0;
9036 start_log.is_pktlog_buff_clear = true;
9037
9038 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9039 if (!QDF_IS_STATUS_SUCCESS(status)) {
9040 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9041 EXIT();
9042 return -EINVAL;
9043 }
9044
9045 return 0;
9046}
9047
9048
9049/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009050 * hdd_process_pktlog_command() - process pktlog command
9051 * @hdd_ctx: hdd context
9052 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309053 * @set_value2: pktlog buffer size value
9054 *
9055 * This function process pktlog command.
9056 * set_value2 only matters when set_value is 3 (set buff size)
9057 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009058 *
9059 * Return: 0 for success or error.
9060 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009061int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309062 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009063{
9064 int ret;
9065 bool enable;
9066 uint8_t user_triggered = 0;
9067
9068 ret = wlan_hdd_validate_context(hdd_ctx);
9069 if (0 != ret)
9070 return ret;
9071
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009072 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009073
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309074 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009075 hdd_err("invalid pktlog value %d", set_value);
9076 return -EINVAL;
9077 }
9078
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309079 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9080 if (set_value2 <= 0) {
9081 hdd_err("invalid pktlog size %d", set_value2);
9082 return -EINVAL;
9083 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9084 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9085 return -EINVAL;
9086 }
9087 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309088 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9089 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309090 }
9091
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009092 /*
9093 * set_value = 0 then disable packetlog
9094 * set_value = 1 enable packetlog forcefully
9095 * set_vlaue = 2 then disable packetlog if disabled through ini or
9096 * enable packetlog with AUTO type.
9097 */
9098 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9099 true : false;
9100
9101 if (1 == set_value) {
9102 enable = true;
9103 user_triggered = 1;
9104 }
9105
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309106 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009107}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009108
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009109/**
9110 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9111 * @hdd_ctx: HDD context
9112 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309113 * @user_triggered: triggered through iwpriv
9114 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009115 *
9116 * Return: 0 on success; error number otherwise
9117 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009118int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309119 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009120{
9121 struct sir_wifi_start_log start_log;
9122 QDF_STATUS status;
9123
9124 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9125 start_log.verbose_level =
9126 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009127 start_log.ini_triggered = cds_is_packet_log_enabled();
9128 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309129 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309130 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309131 /*
9132 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9133 * commands. Host uses this flag to decide whether to send pktlog
9134 * disable command to fw without sending pktlog enable command
9135 * previously. For eg, If vendor sends pktlog disable command without
9136 * sending pktlog enable command, then host discards the packet
9137 * but for iwpriv command, host will send it to fw.
9138 */
9139 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009140 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9141 if (!QDF_IS_STATUS_SUCCESS(status)) {
9142 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9143 EXIT();
9144 return -EINVAL;
9145 }
9146
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309147 if (enable == true)
9148 hdd_ctx->is_pktlog_enabled = 1;
9149 else
9150 hdd_ctx->is_pktlog_enabled = 0;
9151
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009152 return 0;
9153}
9154#endif /* REMOVE_PKT_LOG */
9155
Komal Seelam92fff912016-03-24 11:51:41 +05309156/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009157 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9158 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309159 * @dev: Device Pointer
9160 * @num: Number of Valid Mac address
9161 *
9162 * Return: Pointer to MAC address buffer
9163 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009164static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9165 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309166{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009167 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309168}
Komal Seelam92fff912016-03-24 11:51:41 +05309169
9170/**
9171 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9172 * @hdd_ctx: HDD Context
9173 * @num: Number of random mac addresses needed
9174 *
9175 * Generate random addresses using bit manipulation on the base mac address
9176 *
9177 * Return: None
9178 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009179void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309180{
9181 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9182 uint32_t iter;
9183 struct hdd_config *ini = hdd_ctx->config;
9184 uint8_t *buf = NULL;
9185 uint8_t macaddr_b3, tmp_br3;
9186 uint8_t *src = ini->intfMacAddr[0].bytes;
9187
9188 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9189 buf = ini->intfMacAddr[iter].bytes;
9190 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9191 macaddr_b3 = buf[3];
9192 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9193 INTF_MACADDR_MASK;
9194 macaddr_b3 += tmp_br3;
9195 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9196 buf[0] |= 0x02;
9197 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009198 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309199 }
9200}
9201
9202/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009203 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309204 * @hdd_ctx: HDD Context
9205 *
9206 * API to get mac addresses from platform driver and update the driver
9207 * structures and configure FW with the base mac address.
9208 * Return: int
9209 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009210static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309211{
9212 uint32_t no_of_mac_addr, iter;
9213 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9214 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9215 uint8_t *addr, *buf;
9216 struct device *dev = hdd_ctx->parent_dev;
9217 struct hdd_config *ini = hdd_ctx->config;
9218 tSirMacAddr mac_addr;
9219 QDF_STATUS status;
9220
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009221 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309222
9223 if (no_of_mac_addr == 0 || !addr) {
9224 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9225 return -EINVAL;
9226 }
9227
9228 if (no_of_mac_addr > max_mac_addr)
9229 no_of_mac_addr = max_mac_addr;
9230
9231 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9232
9233 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9234 buf = ini->intfMacAddr[iter].bytes;
9235 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009236 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309237 }
9238
9239 status = sme_set_custom_mac_addr(mac_addr);
9240
9241 if (!QDF_IS_STATUS_SUCCESS(status))
9242 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009243
Komal Seelam92fff912016-03-24 11:51:41 +05309244 if (no_of_mac_addr < max_mac_addr)
9245 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9246 no_of_mac_addr);
9247 return 0;
9248}
9249
9250/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009251 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9252 * @hdd_ctx: HDD Context
9253 *
9254 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9255 * will generate its own MAC and update it to FW.
9256 *
9257 * Return: 0 for success
9258 * Non-zero error code for failure
9259 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009260static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009261{
9262 tSirMacAddr customMacAddr;
9263 QDF_STATUS status;
9264
9265 qdf_mem_copy(&customMacAddr,
9266 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9267 sizeof(tSirMacAddr));
9268 status = sme_set_custom_mac_addr(customMacAddr);
9269 if (!QDF_IS_STATUS_SUCCESS(status))
9270 return -EAGAIN;
9271 return 0;
9272}
9273
9274/**
Komal Seelam92fff912016-03-24 11:51:41 +05309275 * hdd_initialize_mac_address() - API to get wlan mac addresses
9276 * @hdd_ctx: HDD Context
9277 *
9278 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9279 * is provisioned with mac addresses, driver uses it, else it will use
9280 * wlan_mac.bin to update HW MAC addresses.
9281 *
9282 * Return: None
9283 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009284static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309285{
9286 QDF_STATUS status;
9287 int ret;
9288
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009289 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309290 if (ret == 0)
9291 return;
9292
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009293 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9294 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309295
9296 status = hdd_update_mac_config(hdd_ctx);
9297
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009298 if (QDF_IS_STATUS_SUCCESS(status))
9299 return;
9300
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009301 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9302 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009303
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009304 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009305 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009306 if (ret != 0) {
9307 hdd_err("MAC address out-of-sync, ret:%d", ret);
9308 QDF_ASSERT(ret);
9309 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009310 }
Komal Seelam92fff912016-03-24 11:51:41 +05309311}
9312
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009313static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009314{
9315 int vdev_id = 0;
9316 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9317 int value = hdd_ctx->config->smart_chainmask_enabled;
9318 int vpdev = PDEV_CMD;
9319 int ret;
9320
Naveen Rawat247a8682017-06-05 15:00:31 -07009321 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009322 if (ret)
9323 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9324
9325 return ret;
9326}
9327
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009328static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009329{
9330 int vdev_id = 0;
9331 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9332 int value = hdd_ctx->config->alternative_chainmask_enabled;
9333 int vpdev = PDEV_CMD;
9334 int ret;
9335
Naveen Rawat247a8682017-06-05 15:00:31 -07009336 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009337 if (ret)
9338 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9339 ret);
9340
9341 return ret;
9342}
9343
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009344static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009345{
9346 int vdev_id = 0;
9347 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9348 int value = hdd_ctx->config->ani_enabled;
9349 int vpdev = PDEV_CMD;
9350 int ret;
9351
Naveen Rawat247a8682017-06-05 15:00:31 -07009352 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009353 if (ret)
9354 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9355
9356 return ret;
9357}
9358
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009359/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009360 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9361 * @hdd_ctx: HDD context
9362 *
9363 * Pre configurations to be done at lower layer before calling cds enable.
9364 *
9365 * Return: 0 on success and errno on failure.
9366 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009367static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009368{
9369 int ret;
9370 QDF_STATUS status;
9371 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009372 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009373
Leo Changfdb45c32016-10-28 11:09:23 -07009374 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009375 /*
9376 * Set 802.11p config
9377 * TODO-OCB: This has been temporarily added here to ensure this
9378 * parameter is set in CSR when we init the channel list. This should
9379 * be removed once the 5.9 GHz channels are added to the regulatory
9380 * domain.
9381 */
9382 hdd_set_dot11p_config(hdd_ctx);
9383
9384 /*
9385 * Note that the cds_pre_enable() sequence triggers the cfg download.
9386 * The cfg download must occur before we update the SME config
9387 * since the SME config operation must access the cfg database
9388 */
9389 status = hdd_set_sme_config(hdd_ctx);
9390
9391 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009392 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009393 ret = qdf_status_to_os_return(status);
9394 goto out;
9395 }
9396
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009397 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9398 if (QDF_STATUS_SUCCESS != status) {
9399 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9400 ret = qdf_status_to_os_return(status);
9401 goto out;
9402 }
9403
Naveen Rawat247a8682017-06-05 15:00:31 -07009404 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009405 hdd_ctx->config->tx_chain_mask_1ss,
9406 PDEV_CMD);
9407 if (0 != ret) {
9408 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9409 goto out;
9410 }
9411
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009412 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9413 if (ret)
9414 goto out;
9415
9416 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9417 if (ret)
9418 goto out;
9419
Jeff Johnson12a744b2017-04-04 08:19:37 -07009420 ret = hdd_set_ani_enabled(hdd_ctx);
9421 if (ret)
9422 goto out;
9423
Naveen Rawat247a8682017-06-05 15:00:31 -07009424 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009425 hdd_ctx->config->arp_ac_category,
9426 PDEV_CMD);
9427 if (0 != ret) {
9428 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9429 hdd_ctx->config->arp_ac_category, ret);
9430 goto out;
9431 }
9432
Prashanth Bhatta07998752016-04-28 12:35:33 -07009433 status = hdd_set_sme_chan_list(hdd_ctx);
9434 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009435 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009436 ret = qdf_status_to_os_return(status);
9437 goto out;
9438 }
9439
9440 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009441 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009442 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009443 ret = -EINVAL;
9444 goto out;
9445 }
9446
Prashanth Bhatta07998752016-04-28 12:35:33 -07009447 /*
9448 * Set the MAC Address Currently this is used by HAL to add self sta.
9449 * Remove this once self sta is added as part of session open.
9450 */
9451 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9452 hdd_ctx->config->intfMacAddr[0].bytes,
9453 sizeof(hdd_ctx->config->intfMacAddr[0]));
9454
9455 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9456 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9457 hal_status, hal_status);
9458 ret = -EINVAL;
9459 goto out;
9460 }
9461
9462 hdd_init_channel_avoidance(hdd_ctx);
9463
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309464 /* update enable sap mandatory chan list */
9465 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9466 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009467out:
9468 return ret;
9469}
9470
9471/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009472 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9473 * @context_ptr - hdd context pointer
9474 * @event_ptr - event structure pointer
9475 *
9476 * This is the p2p listen offload stop event handler, it sends vendor
9477 * event back to supplicant to notify the stop reason.
9478 *
9479 * Return: None
9480 */
9481static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9482 void *event_ptr)
9483{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009484 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009485 struct sir_p2p_lo_event *evt = event_ptr;
9486 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009487 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009488
9489 ENTER();
9490
9491 if (hdd_ctx == NULL) {
9492 hdd_err("Invalid HDD context pointer");
9493 return;
9494 }
9495
Peng Xu5c682812017-08-06 07:39:13 -07009496 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9497 if (!adapter) {
9498 hdd_err("Cannot find adapter by vdev_id = %d",
9499 evt->vdev_id);
9500 return;
9501 }
9502
Peng Xu8fdaa492016-06-22 10:20:47 -07009503 vendor_event =
9504 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009505 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009506 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9507 GFP_KERNEL);
9508
9509 if (!vendor_event) {
9510 hdd_err("cfg80211_vendor_event_alloc failed");
9511 return;
9512 }
9513
9514 if (nla_put_u32(vendor_event,
9515 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9516 evt->reason_code)) {
9517 hdd_err("nla put failed");
9518 kfree_skb(vendor_event);
9519 return;
9520 }
9521
9522 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009523 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9524 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009525}
9526
9527/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309528 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9529 * @hdd_ctx: HDD context
9530 *
9531 * This function sends the adaptive dwell time config configuration to the
9532 * firmware via WMA
9533 *
9534 * Return: 0 - success, < 0 - failure
9535 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009536static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309537{
9538 QDF_STATUS status;
9539 struct adaptive_dwelltime_params dwelltime_params;
9540
9541 dwelltime_params.is_enabled =
9542 hdd_ctx->config->adaptive_dwell_mode_enabled;
9543 dwelltime_params.dwelltime_mode =
9544 hdd_ctx->config->global_adapt_dwelltime_mode;
9545 dwelltime_params.lpf_weight =
9546 hdd_ctx->config->adapt_dwell_lpf_weight;
9547 dwelltime_params.passive_mon_intval =
9548 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9549 dwelltime_params.wifi_act_threshold =
9550 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9551
9552 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9553 &dwelltime_params);
9554
9555 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9556 if (!QDF_IS_STATUS_SUCCESS(status)) {
9557 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9558 return -EAGAIN;
9559 }
9560 return 0;
9561}
9562
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009563int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309564{
9565 QDF_STATUS status;
9566 struct wmi_dbs_scan_sel_params dbs_scan_params;
9567 uint32_t i = 0;
9568 uint8_t count = 0, numentries = 0;
9569 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9570 * CDS_DBS_SCAN_CLIENTS_MAX];
9571
9572 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009573 if (hdd_ctx->config->dual_mac_feature_disable ==
9574 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309575 return -EINVAL;
9576
9577 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9578 dbs_scan_config, &numentries,
9579 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9580 * CDS_DBS_SCAN_CLIENTS_MAX));
9581
9582 hdd_info("numentries %hu", numentries);
9583 if (!numentries) {
9584 hdd_info("Donot send scan_selection_config");
9585 return 0;
9586 }
9587
9588 /* hdd_set_fw_log_params */
9589 dbs_scan_params.num_clients = 0;
9590 while (count < (numentries - 2)) {
9591 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9592 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9593 dbs_scan_params.num_non_dbs_scans[i] =
9594 dbs_scan_config[count + 2];
9595 dbs_scan_params.num_clients++;
9596 hdd_debug("module:%d NDS:%d NNDS:%d",
9597 dbs_scan_params.module_id[i],
9598 dbs_scan_params.num_dbs_scans[i],
9599 dbs_scan_params.num_non_dbs_scans[i]);
9600 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9601 i++;
9602 }
9603
9604 dbs_scan_params.pdev_id = 0;
9605
9606 hdd_debug("clients:%d pdev:%d",
9607 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9608
9609 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9610 &dbs_scan_params);
9611 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9612 if (!QDF_IS_STATUS_SUCCESS(status)) {
9613 hdd_err("Failed to send DBS Scan selection configuration!");
9614 return -EAGAIN;
9615 }
9616 return 0;
9617}
9618
Arun Khandavallid4349a92016-07-25 11:10:43 +05309619#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9620/**
9621 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9622 * @hdd_ctx: HDD context
9623 *
9624 * Set auto shutdown callback to get indications from firmware to indicate
9625 * userspace to shutdown WLAN after a configured amount of inactivity.
9626 *
9627 * Return: 0 on success and errno on failure.
9628 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009629static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309630{
9631 QDF_STATUS status;
9632
9633 if (!hdd_ctx->config->WlanAutoShutdown)
9634 return 0;
9635
9636 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9637 wlan_hdd_auto_shutdown_cb);
9638 if (status != QDF_STATUS_SUCCESS)
9639 hdd_err("Auto shutdown feature could not be enabled: %d",
9640 status);
9641
9642 return qdf_status_to_os_return(status);
9643}
9644#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009645static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309646{
9647 return 0;
9648}
9649#endif
9650
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009651static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009652{
9653 QDF_STATUS status = QDF_STATUS_SUCCESS;
9654
9655 switch (hdd_ctx->config->dual_mac_feature_disable) {
9656 case DISABLE_DBS_CXN_AND_SCAN:
9657 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9658 if (status != QDF_STATUS_SUCCESS)
9659 hdd_err("Failed to disable dual mac features");
9660 break;
9661 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9662 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9663 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9664 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9665 if (status != QDF_STATUS_SUCCESS)
9666 hdd_err("Failed to set dbs scan and fw mode config");
9667 break;
9668 default:
9669 break;
9670 }
9671
9672 return status;
9673}
9674
Arun Khandavallid4349a92016-07-25 11:10:43 +05309675/**
9676 * hdd_features_init() - Init features
9677 * @hdd_ctx: HDD context
9678 * @adapter: Primary adapter context
9679 *
9680 * Initialize features and their feature context after WLAN firmware is up.
9681 *
9682 * Return: 0 on success and errno on failure.
9683 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009684static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309685{
9686 tSirTxPowerLimit hddtxlimit;
9687 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309688 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309689 int ret;
9690
9691 ENTER();
9692
Arun Khandavallid4349a92016-07-25 11:10:43 +05309693 /* FW capabilities received, Set the Dot11 mode */
9694 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009695 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9696 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309697
Arun Khandavallid4349a92016-07-25 11:10:43 +05309698
9699 if (hdd_ctx->config->fIsImpsEnabled)
9700 hdd_set_idle_ps_config(hdd_ctx, true);
9701 else
9702 hdd_set_idle_ps_config(hdd_ctx, false);
9703
Poddar, Siddarth37033032017-10-11 15:47:40 +05309704 /* Send Enable/Disable data stall detection cmd to FW */
9705 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9706 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9707
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309708 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009709 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309710
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309711 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9712 hdd_warn("Error in setting Voltage Corner mode config to FW");
9713
Arun Khandavallid4349a92016-07-25 11:10:43 +05309714 if (hdd_lro_init(hdd_ctx))
9715 hdd_err("Unable to initialize LRO in fw");
9716
9717 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9718 hdd_err("Unable to send adaptive dwelltime setting to FW");
9719
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309720 if (hdd_dbs_scan_selection_init(hdd_ctx))
9721 hdd_err("Unable to send DBS scan selection setting to FW");
9722
Arun Khandavallid4349a92016-07-25 11:10:43 +05309723 ret = hdd_init_thermal_info(hdd_ctx);
9724 if (ret) {
9725 hdd_err("Error while initializing thermal information");
9726 goto deregister_frames;
9727 }
9728
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309729 /**
9730 * In case of SSR/PDR, if pktlog was enabled manually before
9731 * SSR/PDR, Then enabled it again automatically after Wlan
9732 * device up.
9733 */
9734 if (cds_is_driver_recovering()) {
9735 if (hdd_ctx->is_pktlog_enabled)
9736 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9737 } else if (cds_is_packet_log_enabled())
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309738 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9739
Arun Khandavallid4349a92016-07-25 11:10:43 +05309740 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9741 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9742 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9743 if (!QDF_IS_STATUS_SUCCESS(status))
9744 hdd_err("Error setting txlimit in sme: %d", status);
9745
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009746 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309747
Arun Khandavallid4349a92016-07-25 11:10:43 +05309748 ret = hdd_register_cb(hdd_ctx);
9749 if (ret) {
9750 hdd_err("Failed to register HDD callbacks!");
9751 goto deregister_frames;
9752 }
9753
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009754 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9755 if (!QDF_IS_STATUS_SUCCESS(status)) {
9756 hdd_err("Failed to set dbs scan and fw mode cfg");
9757 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309758 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009759
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309760 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9761 status = sme_enable_disable_chanavoidind_event(
9762 hdd_ctx->hHal, 0);
9763 if (!QDF_IS_STATUS_SUCCESS(status)) {
9764 hdd_err("Failed to disable Chan Avoidance Indication");
9765 goto deregister_cb;
9766 }
9767 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309768
Manjeet Singha9cae432017-02-28 11:58:22 +05309769 if (hdd_ctx->config->enable_5g_band_pref) {
9770 band_pref_params.rssi_boost_threshold_5g =
9771 hdd_ctx->config->rssi_boost_threshold_5g;
9772 band_pref_params.rssi_boost_factor_5g =
9773 hdd_ctx->config->rssi_boost_factor_5g;
9774 band_pref_params.max_rssi_boost_5g =
9775 hdd_ctx->config->max_rssi_boost_5g;
9776 band_pref_params.rssi_penalize_threshold_5g =
9777 hdd_ctx->config->rssi_penalize_threshold_5g;
9778 band_pref_params.rssi_penalize_factor_5g =
9779 hdd_ctx->config->rssi_penalize_factor_5g;
9780 band_pref_params.max_rssi_penalize_5g =
9781 hdd_ctx->config->max_rssi_penalize_5g;
9782 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9783 }
9784
Arun Khandavallid4349a92016-07-25 11:10:43 +05309785 /* register P2P Listen Offload event callback */
9786 if (wma_is_p2p_lo_capable())
9787 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9788 wlan_hdd_p2p_lo_event_callback);
9789
9790 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9791
9792 if (ret)
9793 goto deregister_cb;
9794
Dustin Brown11638b72018-01-25 17:37:25 +05309795 wlan_hdd_init_chan_info(hdd_ctx);
9796
Arun Khandavallid4349a92016-07-25 11:10:43 +05309797 EXIT();
9798 return 0;
9799
9800deregister_cb:
9801 hdd_deregister_cb(hdd_ctx);
9802deregister_frames:
9803 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309804 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309805}
9806
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009807/**
9808 * hdd_features_deinit() - Deinit features
9809 * @hdd_ctx: HDD context
9810 *
9811 * De-Initialize features and their feature context.
9812 *
9813 * Return: none.
9814 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009815static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009816{
Dustin Brown11638b72018-01-25 17:37:25 +05309817 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009818 wlan_hdd_tsf_deinit(hdd_ctx);
9819}
9820
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309821/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009822 * hdd_register_bcn_cb() - register scan beacon callback
9823 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309824 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009825 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309826 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009827static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309828{
9829 QDF_STATUS status;
9830
9831 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9832 wlan_cfg80211_inform_bss_frame,
9833 SCAN_CB_TYPE_INFORM_BCN);
9834 if (!QDF_IS_STATUS_SUCCESS(status)) {
9835 hdd_err("failed with status code %08d [x%08x]",
9836 status, status);
9837 return status;
9838 }
9839
9840 return QDF_STATUS_SUCCESS;
9841}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309842
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309843/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309844 * hdd_configure_cds() - Configure cds modules
9845 * @hdd_ctx: HDD context
9846 * @adapter: Primary adapter context
9847 *
9848 * Enable Cds modules after WLAN firmware is up.
9849 *
9850 * Return: 0 on success and errno on failure.
9851 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009852int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309853{
9854 int ret;
9855 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309856 int set_value;
9857 uint32_t num_abg_tx_chains = 0;
9858 uint32_t num_11b_tx_chains = 0;
9859 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009860 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309861
9862 if (hdd_ctx->config->sifs_burst_duration) {
9863 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9864 hdd_ctx->config->sifs_burst_duration;
9865
9866 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9867 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9868 set_value, PDEV_CMD);
9869 }
9870
9871 if (hdd_ctx->config->is_force_1x1)
9872 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9873 1, PDEV_CMD);
9874 /* set chip power save failure detected callback */
9875 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9876 hdd_chip_pwr_save_fail_detected_cb);
9877
9878 if (hdd_ctx->config->max_mpdus_inampdu) {
9879 set_value = hdd_ctx->config->max_mpdus_inampdu;
9880 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9881 set_value, PDEV_CMD);
9882 }
9883
9884 if (hdd_ctx->config->enable_rts_sifsbursting) {
9885 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9886 sme_cli_set_command(0,
9887 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9888 set_value, PDEV_CMD);
9889 }
9890
9891 if (hdd_ctx->config->sap_get_peer_info) {
9892 set_value = hdd_ctx->config->sap_get_peer_info;
9893 sme_cli_set_command(0,
9894 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9895 set_value, PDEV_CMD);
9896 }
9897
9898 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9899 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9900 if (!hdd_ctx->config->enable2x2) {
9901 if (num_11b_tx_chains > 1)
9902 num_11b_tx_chains = 1;
9903 if (num_11ag_tx_chains > 1)
9904 num_11ag_tx_chains = 1;
9905 }
9906 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9907 num_11b_tx_chains);
9908 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9909 num_11ag_tx_chains);
9910 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9911 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309912
9913 ret = hdd_pre_enable_configure(hdd_ctx);
9914 if (ret) {
9915 hdd_err("Failed to pre-configure cds");
9916 goto out;
9917 }
9918
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009919 /* Always get latest IPA resources allocated from cds_open and configure
9920 * IPA module before configuring them to FW. Sequence required as crash
9921 * observed otherwise.
9922 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009923 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9924 hdd_err("Failed to setup pipes");
9925 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009926 }
9927
Arun Khandavallifae92942016-08-01 13:31:08 +05309928 /*
9929 * Start CDS which starts up the SME/MAC/HAL modules and everything
9930 * else
9931 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009932 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309933
9934 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009935 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309936 goto out;
9937 }
9938
9939 status = hdd_post_cds_enable_config(hdd_ctx);
9940 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009941 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009942 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309943 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309944 status = hdd_register_bcn_cb(hdd_ctx);
9945 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +08009946 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309947 goto cds_disable;
9948 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309949
9950 ret = hdd_features_init(hdd_ctx, adapter);
9951 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009952 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309953
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009954 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009955 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009956 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9957 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009958 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009959 goto cds_disable;
9960 }
9961
Himanshu Agarwalb229a142017-12-21 10:16:45 +05309962 if (ucfg_green_ap_enable_egap(hdd_ctx->hdd_pdev))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309963 hdd_debug("enhance green ap is not enabled");
9964
Nachiket Kukadedd302662017-07-13 17:31:44 +05309965 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9966 hdd_debug("Failed to set wow pulse");
9967
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +05309968 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
9969 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309970 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9971 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9972
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309973
9974 if (hdd_ctx->config->enable_phy_reg_retention)
9975 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9976 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9977
Arun Khandavallifae92942016-08-01 13:31:08 +05309978 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009979
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009980cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009981 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009982
Arun Khandavallifae92942016-08-01 13:31:08 +05309983out:
9984 return -EINVAL;
9985}
9986
9987/**
9988 * hdd_deconfigure_cds() -De-Configure cds
9989 * @hdd_ctx: HDD context
9990 *
9991 * Deconfigure Cds modules before WLAN firmware is down.
9992 *
9993 * Return: 0 on success and errno on failure.
9994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009995static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309996{
9997 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009998 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309999
10000 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010001
10002 /* De-init features */
10003 hdd_features_deinit(hdd_ctx);
10004
Arun Khandavallifae92942016-08-01 13:31:08 +053010005 /* De-register the SME callbacks */
10006 hdd_deregister_cb(hdd_ctx);
10007
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010008 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010009 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10010 hdd_err("Failed to Disable the CDS Modules! :%d",
10011 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010012 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010013 }
10014
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010015 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
10016 hdd_err("Failed to disconnect pipes");
10017 ret = -EINVAL;
10018 }
10019
Arun Khandavallifae92942016-08-01 13:31:08 +053010020 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010021 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010022}
10023
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010024#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10025static void hdd_deregister_policy_manager_callback(
10026 struct wlan_objmgr_psoc *psoc)
10027{
10028 if (QDF_STATUS_SUCCESS !=
10029 policy_mgr_deregister_hdd_cb(psoc)) {
10030 hdd_err("HDD callback deregister with policy manager failed");
10031 }
10032}
10033#else
10034static void hdd_deregister_policy_manager_callback(
10035 struct wlan_objmgr_psoc *psoc)
10036{
10037}
10038#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010039
10040/**
10041 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10042 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010043 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010044 *
10045 * This function maintains the driver state machine it will be invoked from
10046 * exit, shutdown and con_mode change handler. Depending on the driver state
10047 * shall perform the stopping/closing of the modules.
10048 *
10049 * Return: 0 for success; non-zero for failure
10050 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010051int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010052{
10053 void *hif_ctx;
10054 qdf_device_t qdf_ctx;
10055 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010056 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010057 bool is_recovery_stop = cds_is_driver_recovering();
10058 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop;
Dustin Brown70111822017-03-30 15:31:40 -070010059 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +053010060
10061 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -070010062 hdd_alert("stop WLAN module: entering driver status=%d",
10063 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010064
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010065 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10066
Arun Khandavallifae92942016-08-01 13:31:08 +053010067 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10068 if (!qdf_ctx) {
10069 hdd_err("QDF device context NULL");
10070 return -EINVAL;
10071 }
10072
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010073 mutex_lock(&hdd_ctx->iface_change_lock);
10074 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010075 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010076
Dustin Brown70111822017-03-30 15:31:40 -070010077 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010078 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010079 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010080 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010081
10082 cds_print_external_threads();
10083
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010084 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010085 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010086 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10087 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010088 hdd_prevent_suspend_timeout(
10089 hdd_ctx->config->iface_change_wait_time,
10090 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010091 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010092 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010093 return 0;
10094 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010095 }
10096
Arun Khandavallifae92942016-08-01 13:31:08 +053010097 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10098
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010099 /* free user wowl patterns */
10100 hdd_free_user_wowl_ptrns();
10101
Arun Khandavallifae92942016-08-01 13:31:08 +053010102 switch (hdd_ctx->driver_status) {
10103 case DRIVER_MODULES_UNINITIALIZED:
10104 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010105 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010106 case DRIVER_MODULES_CLOSED:
10107 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010108 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010109 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010110 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10111
Komal Seelamf2136bb2016-09-28 18:30:44 +053010112 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010113 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010114 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010115 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010116 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010117 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010118 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010119
Arun Khandavallifae92942016-08-01 13:31:08 +053010120 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010121 hdd_info("Wlan transitioned (now OPENED)");
10122
10123 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010124 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010125 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010126 break;
10127 default:
10128 hdd_err("Trying to stop wlan in a wrong state: %d",
10129 hdd_ctx->driver_status);
10130 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010131 ret = -EINVAL;
10132 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010133 }
10134
Dustin Brown550f6d22017-12-14 15:44:01 -080010135 hdd_debug("Closing CDS modules!");
Rajeev Kumarbe021242017-02-16 16:12:23 -080010136 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010137 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10138 hdd_err("Failed to process post CDS disable Modules! :%d",
10139 qdf_status);
10140 ret = -EINVAL;
10141 QDF_ASSERT(0);
10142 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010143
psimhadeea0a12017-12-18 14:50:02 -080010144 hdd_runtime_suspend_context_deinit(hdd_ctx);
10145
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010146 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10147 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10148 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10149 ret = -EINVAL;
10150 QDF_ASSERT(0);
10151 }
10152
Jeff Johnsone4b14592017-09-13 14:23:33 -070010153 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010154 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010155 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010156 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010157 QDF_ASSERT(0);
10158 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010159
Amar Singhal410675c2018-01-10 12:14:21 -080010160 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010161 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10162 if (ret) {
10163 hdd_err("Failed to destroy pdev; errno:%d", ret);
10164 QDF_ASSERT(0);
10165 }
10166
10167 /*
10168 * Reset total mac phy during module stop such that during
10169 * next module start same psoc is used to populate new service
10170 * ready data
10171 */
10172 hdd_ctx->hdd_psoc->total_mac_phy = 0;
10173
Arun Khandavallifae92942016-08-01 13:31:08 +053010174 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10175 if (!hif_ctx) {
10176 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010177 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010178 }
10179
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010180 if (hdd_ctx->target_hw_name) {
10181 qdf_mem_free(hdd_ctx->target_hw_name);
10182 hdd_ctx->target_hw_name = NULL;
10183 }
10184
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010185 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010186
10187 ol_cds_free();
10188
Dustin Brown70111822017-03-30 15:31:40 -070010189 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010190 ret = pld_power_off(qdf_ctx->dev);
10191 if (ret)
10192 hdd_err("CNSS power down failed put device into Low power mode:%d",
10193 ret);
10194 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010195
Dustin Brown4bc0a622017-12-06 15:56:50 -080010196 /* many adapter resources are not freed by design in SSR case */
10197 if (!is_recovery_stop)
10198 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010199 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010200
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010201 /* Once the firmware sequence is completed reset this flag */
10202 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010203 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010204 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010205
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010206done:
10207 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010208 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010209 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010210 hdd_alert("stop WLAN module: exit driver status=%d",
10211 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010212
Arun Khandavallifae92942016-08-01 13:31:08 +053010213 EXIT();
10214
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010215 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010216}
10217
Arun Khandavallifae92942016-08-01 13:31:08 +053010218
10219/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010220 * hdd_state_info_dump() - prints state information of hdd layer
10221 * @buf: buffer pointer
10222 * @size: size of buffer to be filled
10223 *
10224 * This function is used to dump state information of hdd layer
10225 *
10226 * Return: None
10227 */
10228static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10229{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010230 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010231 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010232 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010233 uint16_t len = 0;
10234 char *buf = *buf_ptr;
10235
10236 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10237 if (!hdd_ctx) {
10238 hdd_err("Failed to get hdd context ");
10239 return;
10240 }
10241
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010242 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010243
10244 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010245 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010246 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010247 "\n is_scheduler_suspended %d",
10248 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010249
Dustin Brown920397d2017-12-13 16:27:50 -080010250 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010251 if (adapter->dev)
10252 len += scnprintf(buf + len, *size - len,
10253 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010254 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010255 "\n device_mode: %d", adapter->device_mode);
10256 switch (adapter->device_mode) {
10257 case QDF_STA_MODE:
10258 case QDF_P2P_CLIENT_MODE:
10259 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10260 len += scnprintf(buf + len, *size - len,
10261 "\n connState: %d",
10262 hdd_sta_ctx->conn_info.connState);
10263 break;
10264
10265 default:
10266 break;
10267 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010268 }
10269
10270 *size -= len;
10271 *buf_ptr += len;
10272}
10273
10274/**
10275 * hdd_register_debug_callback() - registration function for hdd layer
10276 * to print hdd state information
10277 *
10278 * Return: None
10279 */
10280static void hdd_register_debug_callback(void)
10281{
10282 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10283}
10284
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010285/*
10286 * wlan_init_bug_report_lock() - Initialize bug report lock
10287 *
10288 * This function is used to create bug report lock
10289 *
10290 * Return: None
10291 */
10292static void wlan_init_bug_report_lock(void)
10293{
10294 p_cds_contextType p_cds_context;
10295
10296 p_cds_context = cds_get_global_context();
10297 if (!p_cds_context) {
10298 hdd_err("cds context is NULL");
10299 return;
10300 }
10301
10302 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10303}
10304
Mohit Khannaf8f96822017-05-17 17:11:59 -070010305void hdd_dp_trace_init(struct hdd_config *config)
10306{
10307
10308 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10309 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10310 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10311 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10312 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10313 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10314 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010315 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010316
10317 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10318 &num_entries, sizeof(config_params));
10319
10320 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010321 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010322 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010323 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010324 else if (bw_compute_interval > 1000) {
10325 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10326 thresh_time_limit = 1;
10327 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010328 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10329
10330 switch (num_entries) {
10331 case 4:
10332 proto_bitmap = config_params[3];
10333 case 3:
10334 verbosity = config_params[2];
10335 case 2:
10336 thresh = config_params[1];
10337 case 1:
10338 live_mode = config_params[0];
10339 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010340 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010341 live_mode, thresh, thresh_time_limit,
10342 verbosity, proto_bitmap);
10343 };
10344
10345 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10346 verbosity, proto_bitmap);
10347
10348}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010349/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010350 * hdd_wlan_startup() - HDD init function
10351 * @dev: Pointer to the underlying device
10352 *
10353 * This is the driver startup code executed once a WLAN device has been detected
10354 *
10355 * Return: 0 for success, < 0 for failure
10356 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010357int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010358{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010359 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010360 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010361 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010362 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010363
10364 ENTER();
10365
Arun Khandavallifae92942016-08-01 13:31:08 +053010366 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010367
10368 if (IS_ERR(hdd_ctx))
10369 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010370
Abhishek Singhe9068f12017-03-31 14:14:52 +053010371 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10372 DEFAULT_PSOC_ID);
10373 if (ret) {
10374 hdd_err("Psoc creation fails!");
10375 QDF_BUG(0);
10376 goto err_hdd_free_context;
10377 }
10378
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010379 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010380#ifdef FEATURE_WLAN_CH_AVOID
10381 mutex_init(&hdd_ctx->avoid_freq_lock);
10382#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010383
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010384 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010385 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010386
Dustin Brown021cecd2017-12-11 13:56:43 -080010387 hdd_driver_memdump_init();
10388
Jeff Johnson957bc272017-02-02 08:54:48 -080010389 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010390 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010391 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010392 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010393 }
10394
Yingying Tang80e15f32016-09-27 18:23:01 +080010395 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010396
Anurag Chouhan6d760662016-02-20 16:05:43 +053010397 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010398
10399 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010400 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010401 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010402 }
10403
Prashanth Bhatta07998752016-04-28 12:35:33 -070010404 ret = hdd_wiphy_init(hdd_ctx);
10405 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010406 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010407 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010408 }
10409
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010410 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010411 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010412
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010413 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010414 goto err_wiphy_unregister;
10415
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010416 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010417
Paul Zhangfb02f452017-12-22 11:58:43 +080010418 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10419 if (ret) {
10420 hdd_err("register_netdevice_notifier failed: %d", ret);
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010421 goto err_ipa_cleanup;
Paul Zhangfb02f452017-12-22 11:58:43 +080010422 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010423
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010424 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010425
Jeff Johnson957bc272017-02-02 08:54:48 -080010426 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10427 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010428 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010429 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010430 }
10431
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010432 hdd_release_rtnl_lock();
10433 rtnl_held = false;
10434
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010435 wlan_hdd_update_11n_mode(hdd_ctx->config);
10436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010437#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010438 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010439 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010440 hdd_skip_acs_scan_timer_handler,
10441 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010442 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010443 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010444 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010445#endif
10446
Prashanth Bhattaab004382016-10-11 16:08:11 -070010447 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010448
Jeff Johnson9afc5012016-09-23 13:56:27 -070010449 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010450
Nirav Shahbd36b062016-07-18 11:12:59 +053010451 if (hdd_ctx->rps)
10452 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010453
Paul Zhangfb02f452017-12-22 11:58:43 +080010454 ret = hdd_register_notifiers(hdd_ctx);
10455 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010456 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010457
Paul Zhangfb02f452017-12-22 11:58:43 +080010458 status = wlansap_global_init();
10459 if (QDF_IS_STATUS_ERROR(status)) {
10460 hdd_unregister_notifiers(hdd_ctx);
10461 goto err_close_adapters;
10462 }
10463
Arun Khandavallifae92942016-08-01 13:31:08 +053010464 if (hdd_ctx->config->fIsImpsEnabled)
10465 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010466 else
10467 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010468
Mukul Sharma07bd8752017-10-10 16:58:14 +053010469 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010470 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10471 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010472 hdd_prevent_suspend_timeout(
10473 hdd_ctx->config->iface_change_wait_time,
10474 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10475 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010476
Sachin Ahujadddd2632017-03-07 19:07:24 +053010477 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010478 goto success;
10479
Jeff Johnson957bc272017-02-02 08:54:48 -080010480err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010481 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010482
Jeff Johnson46bde382017-02-01 15:31:16 -080010483err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010484 if (rtnl_held)
10485 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010486
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010487 unregister_netdevice_notifier(&hdd_netdev_notifier);
10488
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010489err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010490 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010492err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010493 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010494
Arun Khandavallifae92942016-08-01 13:31:08 +053010495err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010496 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010497
Dustin Brown021cecd2017-12-11 13:56:43 -080010498err_memdump_deinit:
10499 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010500
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010501 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010502 hdd_exit_netlink_services(hdd_ctx);
10503
Dustin Brown20912462017-06-07 13:48:25 -070010504 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10505
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010506err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010507 if (cds_is_fw_down())
10508 hdd_err("Not setting the complete event as fw is down");
10509 else
10510 hdd_start_complete(ret);
10511
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010512 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010513 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010514 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010515
10516success:
10517 EXIT();
10518 return 0;
10519}
10520
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010521/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010522 * hdd_wlan_update_target_info() - update target type info
10523 * @hdd_ctx: HDD context
10524 * @context: hif context
10525 *
10526 * Update target info received from firmware in hdd context
10527 * Return:None
10528 */
10529
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010530void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010531{
10532 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10533
10534 if (!tgt_info) {
10535 hdd_err("Target info is Null");
10536 return;
10537 }
10538
10539 hdd_ctx->target_type = tgt_info->target_type;
10540}
10541
10542/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010543 * hdd_get_nud_stats_cb() - callback api to update the stats
10544 * received from the firmware
10545 * @data: pointer to adapter.
10546 * @rsp: pointer to data received from FW.
10547 *
10548 * This is called when wlan driver received response event for
10549 * get arp stats to firmware.
10550 *
10551 * Return: None
10552 */
10553static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10554{
10555 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10556 struct hdd_nud_stats_context *context;
10557 int status;
10558 struct hdd_adapter *adapter = NULL;
10559
10560 ENTER();
10561
10562 if (!rsp) {
10563 hdd_err("data is null");
10564 return;
10565 }
10566
10567 status = wlan_hdd_validate_context(hdd_ctx);
10568 if (0 != status)
10569 return;
10570
10571 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10572 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10573 hdd_err("Invalid adapter or adapter has invalid magic");
10574 return;
10575 }
10576
10577 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10578 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10579 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10580 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10581 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10582 rsp->out_of_order_arp_rsp_drop_cnt);
10583 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10584 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10585 hdd_notice("rsp->ba_session_establishment_status :%x",
10586 rsp->ba_session_establishment_status);
10587
10588 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10589 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10590 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10591 adapter->dad |= rsp->dad_detected;
10592 adapter->con_status = rsp->connect_status;
10593
10594 spin_lock(&hdd_context_lock);
10595 context = &hdd_ctx->nud_stats_context;
10596 complete(&context->response_event);
10597 spin_unlock(&hdd_context_lock);
10598
10599 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010600}
10601
10602/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010603 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010604 * @hdd_ctx: HDD context
10605 *
10606 * Register the HDD callbacks to CDS/SME.
10607 *
10608 * Return: 0 for success or Error code for failure
10609 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010610int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010611{
10612 QDF_STATUS status;
10613 int ret = 0;
10614
10615 ENTER();
10616
10617 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10618
10619 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10620 hdd_send_oem_data_rsp_msg);
10621
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010622 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10623 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010624 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10625 sme_nan_register_callback(hdd_ctx->hHal,
10626 wlan_hdd_cfg80211_nan_callback);
10627 sme_stats_ext_register_callback(hdd_ctx->hHal,
10628 wlan_hdd_cfg80211_stats_ext_callback);
10629
10630 sme_ext_scan_register_callback(hdd_ctx->hHal,
10631 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010632 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10633 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010634
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010635 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10636 hdd_rssi_threshold_breached);
10637
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010638 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10639
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010640 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10641 wlan_hdd_cfg80211_link_layer_stats_callback);
10642
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010643 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10644
Zhang Qianca38fb12016-12-23 11:10:48 +080010645 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10646 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10647
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010648 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10649 hdd_lost_link_info_cb);
10650 /* print error and not block the startup process */
10651 if (!QDF_IS_STATUS_SUCCESS(status))
10652 hdd_err("set lost link info callback failed");
10653
Poddar, Siddarth34872782017-08-10 14:08:51 +053010654 ret = hdd_register_data_stall_detect_cb();
10655 if (ret) {
10656 hdd_err("Register data stall detect detect callback failed.");
10657 return ret;
10658 }
10659
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010660 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10661
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010662 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010663 hdd_set_connection_in_progress,
10664 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010665
10666 status = sme_congestion_register_callback(hdd_ctx->hHal,
10667 hdd_update_cca_info_cb);
10668 if (!QDF_IS_STATUS_SUCCESS(status))
10669 hdd_err("set congestion callback failed");
10670
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010671 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10672 hdd_bt_activity_cb);
10673 if (!QDF_IS_STATUS_SUCCESS(status))
10674 hdd_err("set bt activity info callback failed");
10675
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010676 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10677 hdd_tx_queue_cb);
10678 if (!QDF_IS_STATUS_SUCCESS(status))
10679 hdd_err("Register tx queue callback failed");
10680
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010681 EXIT();
10682
10683 return ret;
10684}
10685
10686/**
10687 * hdd_deregister_cb() - De-Register HDD callbacks.
10688 * @hdd_ctx: HDD context
10689 *
10690 * De-Register the HDD callbacks to CDS/SME.
10691 *
10692 * Return: void
10693 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010694void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010695{
10696 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010697 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010698
10699 ENTER();
10700
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010701 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010702 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10703 if (!QDF_IS_STATUS_SUCCESS(status))
10704 hdd_err("De-register of dcc stats callback failed: %d",
10705 status);
10706
10707 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010708 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10709
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010710 sme_stats_ext_register_callback(hdd_ctx->hHal,
10711 wlan_hdd_cfg80211_stats_ext_callback);
10712
10713 sme_nan_deregister_callback(hdd_ctx->hHal);
10714 status = sme_reset_tsfcb(hdd_ctx->hHal);
10715 if (!QDF_IS_STATUS_SUCCESS(status))
10716 hdd_err("Failed to de-register tsfcb the callback:%d",
10717 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010718
Poddar, Siddarth34872782017-08-10 14:08:51 +053010719 ret = hdd_deregister_data_stall_detect_cb();
10720 if (ret)
10721 hdd_err("Failed to de-register data stall detect event callback");
10722
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010723 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10724 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10725
10726 EXIT();
10727}
10728
10729/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010730 * hdd_softap_sta_deauth() - handle deauth req from HDD
10731 * @adapter: Pointer to the HDD
10732 * @enable: bool value
10733 *
10734 * This to take counter measure to handle deauth req from HDD
10735 *
10736 * Return: None
10737 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010738QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010739 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010741 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010742
10743 ENTER();
10744
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010745 /* Ignore request to deauth bcmc station */
10746 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010747 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010748
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010749 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010750 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10751 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010752
10753 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010754 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010755}
10756
10757/**
10758 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10759 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010760 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010761 *
10762 * This to take counter measure to handle deauth req from HDD
10763 *
10764 * Return: None
10765 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010766void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010767 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010768{
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010769 struct sir_peer_sta_info peer_sta_info;
10770 struct hdd_station_info *stainfo;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010771 ENTER();
10772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010773 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010774 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010775 return;
10776
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010777 wlan_hdd_get_peer_rssi(adapter, &pDelStaParams->peerMacAddr,
10778 &peer_sta_info);
10779 stainfo = hdd_get_stainfo(adapter->cache_sta_info,
10780 pDelStaParams->peerMacAddr);
10781 if (stainfo) {
10782 stainfo->rssi = peer_sta_info.info[0].rssi;
10783 stainfo->tx_rate = peer_sta_info.info[0].tx_rate;
10784 stainfo->rx_rate = peer_sta_info.info[0].rx_rate;
Jiachao Wuf610d912018-01-23 17:47:32 +080010785 stainfo->reason_code = pDelStaParams->reason_code;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010786 }
10787
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010788 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010789 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010790}
10791
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010792/**
10793 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10794 * @hdd_ctx: HDD Context
10795 *
10796 * API to find if there is any STA or P2P-Client is connected
10797 *
10798 * Return: true if connected; false otherwise
10799 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010800QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010801{
10802 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10803}
10804
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010805/**
10806 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10807 * @adapter: HDD adapter pointer
10808 *
10809 * This function loop through each adapter and disable roaming on each STA
10810 * device mode except the input adapter.
10811 *
10812 * Note: On the input adapter roaming is not enabled yet hence no need to
10813 * disable.
10814 *
10815 * Return: None
10816 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010817void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010818{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010819 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010820 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010821
10822 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010823 hdd_ctx->config->isRoamOffloadScanEnabled &&
10824 QDF_STA_MODE == adapter->device_mode &&
10825 policy_mgr_is_sta_active_connection_exists(
10826 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010827 hdd_debug("Connect received on STA session Id(%d)",
10828 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010829 /*
10830 * Loop through adapter and disable roaming for each STA device
10831 * mode except the input adapter.
10832 */
Dustin Brown920397d2017-12-13 16:27:50 -080010833 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010834 if (QDF_STA_MODE == adapterIdx->device_mode &&
10835 adapter->session_id != adapterIdx->session_id) {
10836 hdd_debug("Disable Roaming on session Id(%d)",
10837 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010838 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10839 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010840 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010841 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010842 }
10843 }
10844}
10845
10846/**
10847 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10848 * @adapter: HDD adapter pointer
10849 *
10850 * This function loop through each adapter and enable roaming on each STA
10851 * device mode except the input adapter.
10852 * Note: On the input adapter no need to enable roaming because link got
10853 * disconnected on this.
10854 *
10855 * Return: None
10856 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010857void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010858{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010859 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010860 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010861
10862 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010863 hdd_ctx->config->isRoamOffloadScanEnabled &&
10864 QDF_STA_MODE == adapter->device_mode &&
10865 policy_mgr_is_sta_active_connection_exists(
10866 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010867 hdd_debug("Disconnect received on STA session Id(%d)",
10868 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010869 /*
10870 * Loop through adapter and enable roaming for each STA device
10871 * mode except the input adapter.
10872 */
Dustin Brown920397d2017-12-13 16:27:50 -080010873 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010874 if (QDF_STA_MODE == adapterIdx->device_mode &&
10875 adapter->session_id != adapterIdx->session_id) {
10876 hdd_debug("Enabling Roaming on session Id(%d)",
10877 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010878 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10879 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010880 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010881 REASON_CONNECT);
10882 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010883 }
10884 }
10885}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010886
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010887/**
10888 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10889 * @skb: sk buffer pointer
10890 *
10891 * Sends the bcast message to SVC multicast group with generic nl socket
10892 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10893 *
10894 * Return: None
10895 */
10896static void nl_srv_bcast_svc(struct sk_buff *skb)
10897{
10898#ifdef CNSS_GENL
10899 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10900#else
10901 nl_srv_bcast(skb);
10902#endif
10903}
10904
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010905void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010906{
10907 struct sk_buff *skb;
10908 struct nlmsghdr *nlh;
10909 tAniMsgHdr *ani_hdr;
10910 void *nl_data = NULL;
10911 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010912 struct radio_index_tlv *radio_info;
10913 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010914
10915 if (in_interrupt() || irqs_disabled() || in_atomic())
10916 flags = GFP_ATOMIC;
10917
10918 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10919
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010920 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010921 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010922
10923 nlh = (struct nlmsghdr *)skb->data;
10924 nlh->nlmsg_pid = 0; /* from kernel */
10925 nlh->nlmsg_flags = 0;
10926 nlh->nlmsg_seq = 0;
10927 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10928
10929 ani_hdr = NLMSG_DATA(nlh);
10930 ani_hdr->type = type;
10931
10932 switch (type) {
10933 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010934 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010935 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010936 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010937 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010938 ani_hdr->length = 0;
10939 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010940 break;
10941 case WLAN_SVC_WLAN_STATUS_IND:
10942 case WLAN_SVC_WLAN_VERSION_IND:
10943 case WLAN_SVC_DFS_CAC_START_IND:
10944 case WLAN_SVC_DFS_CAC_END_IND:
10945 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10946 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10947 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010948 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010949 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010950 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010951 ani_hdr->length = len;
10952 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10953 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10954 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010955 break;
10956
10957 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010958 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010959 type);
10960 kfree_skb(skb);
10961 return;
10962 }
10963
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010964 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010965 * Add radio index at the end of the svc event in TLV format
10966 * to maintain the backward compatibility with userspace
10967 * applications.
10968 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010969
10970 tlv_len = 0;
10971
10972 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10973 < WLAN_NL_MAX_PAYLOAD) {
10974 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10975 sizeof(*ani_hdr) + len);
10976 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10977 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10978 radio_info->radio = radio;
10979 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010980 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010981 "Added radio index tlv - radio index %d",
10982 radio_info->radio);
10983 }
10984
10985 nlh->nlmsg_len += tlv_len;
10986 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10987
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010988 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010989}
10990
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010991#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10992void wlan_hdd_auto_shutdown_cb(void)
10993{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010994 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010995
10996 if (!hdd_ctx)
10997 return;
10998
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010999 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011000 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11001 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011002}
11003
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011004void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011005{
Jeff Johnson9d295242017-08-29 14:39:48 -070011006 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011007 bool ap_connected = false, sta_connected = false;
11008 tHalHandle hal_handle;
11009
11010 hal_handle = hdd_ctx->hHal;
11011 if (hal_handle == NULL)
11012 return;
11013
11014 if (hdd_ctx->config->WlanAutoShutdown == 0)
11015 return;
11016
11017 if (enable == false) {
11018 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011019 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011020 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011021 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011022 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011023 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011024 return;
11025 }
11026
11027 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011028 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11029 hdd_for_each_adapter(hdd_ctx, adapter) {
11030 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011031 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11032 conn_info.connState ==
11033 eConnectionState_Associated) {
11034 sta_connected = true;
11035 break;
11036 }
11037 }
Dustin Brown920397d2017-12-13 16:27:50 -080011038
11039 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011040 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011041 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011042 ap_connected = true;
11043 break;
11044 }
11045 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011046 }
11047 }
11048
11049 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011050 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011051 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011052 }
Jeff Johnson68755312017-02-10 11:46:55 -080011053
11054 if (sme_set_auto_shutdown_timer(hal_handle,
11055 hdd_ctx->config->WlanAutoShutdown)
11056 != QDF_STATUS_SUCCESS)
11057 hdd_err("Failed to start wlan auto shutdown timer");
11058 else
11059 hdd_notice("Auto Shutdown timer for %d seconds enabled",
11060 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011061}
11062#endif
11063
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011064struct hdd_adapter *
11065hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11066 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011067{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011068 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011069 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011070
11071 con_sap_adapter = NULL;
11072
Dustin Brown920397d2017-12-13 16:27:50 -080011073 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011074 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11075 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011076 adapter != this_sap_adapter) {
11077 if (check_start_bss) {
11078 if (test_bit(SOFTAP_BSS_STARTED,
11079 &adapter->event_flags)) {
11080 con_sap_adapter = adapter;
11081 break;
11082 }
11083 } else {
11084 con_sap_adapter = adapter;
11085 break;
11086 }
11087 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011088 }
11089
11090 return con_sap_adapter;
11091}
11092
11093#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011094static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011095{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011096 return adapter->device_mode == QDF_STA_MODE ||
11097 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011098}
11099
Jeff Johnson9d295242017-08-29 14:39:48 -070011100static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011101{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011102 return adapter->device_mode == QDF_SAP_MODE ||
11103 adapter->device_mode == QDF_P2P_GO_MODE;
11104}
11105
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011106static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011107{
Dustin Brown920397d2017-12-13 16:27:50 -080011108 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011109
Dustin Brown920397d2017-12-13 16:27:50 -080011110 hdd_for_each_adapter(hdd_ctx, adapter) {
11111 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011112 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11113 conn_info.connState == eConnectionState_Associated) {
11114 return true;
11115 }
11116
Dustin Brown920397d2017-12-13 16:27:50 -080011117 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011118 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011119 return true;
11120 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011121 }
11122
11123 return false;
11124}
11125
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011126static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011127{
11128 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011129
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011130 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011131 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011132 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011133
Dustin Brown5ec6b552017-03-31 12:11:40 -070011134 return is_running;
11135}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011136
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011137static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011138{
11139 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11140 hdd_ctx->bus_bw_timer_running = true;
11141 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11142 hdd_ctx->config->busBandwidthComputeInterval);
11143 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11144}
11145
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011146void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011147{
11148 ENTER();
11149
11150 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11151 hdd_debug("Bandwidth compute timer already started");
11152 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011153 }
11154
Dustin Brown5ec6b552017-03-31 12:11:40 -070011155 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11156
11157 EXIT();
11158}
11159
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011160void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011161{
11162 ENTER();
11163
11164 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11165 hdd_debug("Bandwidth compute timer already started");
11166 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011167 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011168
11169 if (hdd_any_adapter_is_assoc(hdd_ctx))
11170 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11171
11172 EXIT();
11173}
11174
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011175static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011176{
11177 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
11178
11179 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11180 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11181 hdd_ctx->bus_bw_timer_running = false;
11182 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11183
11184 hdd_reset_tcp_delack(hdd_ctx);
11185}
11186
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011187void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011188{
11189 ENTER();
11190
11191 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11192 hdd_debug("Bandwidth compute timer already stopped");
11193 return;
11194 }
11195
11196 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11197
11198 EXIT();
11199}
11200
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011201void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011202{
11203 ENTER();
11204
11205 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11206 hdd_debug("Bandwidth compute timer already stopped");
11207 return;
11208 }
11209
11210 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11211 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11212
11213 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011214}
11215#endif
11216
11217/**
11218 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11219 * and sta's operating channel.
11220 * @sta_adapter: Describe the first argument to foobar.
11221 * @ap_adapter: Describe the second argument to foobar.
11222 * @roam_profile: Roam profile of AP to which STA wants to connect.
11223 * @concurrent_chnl_same: If both SAP and STA channels are same then
11224 * set this flag to true else false.
11225 *
11226 * This function checks the sap's operating channel and sta's operating channel.
11227 * if both are same then it will return false else it will restart the sap in
11228 * sta's channel and return true.
11229 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011230 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011231 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011232QDF_STATUS
11233wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11234 struct hdd_adapter *ap_adapter,
11235 tCsrRoamProfile *roam_profile,
11236 tScanResultHandle *scan_cache,
11237 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011238{
Jeff Johnson87251032017-08-29 13:31:11 -070011239 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011240 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011241 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011242 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011243 *concurrent_chnl_same = true;
11244
11245 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11246 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011247 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011248 scan_cache,
11249 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011250 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011251 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011252 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011253 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011254 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011255 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011256 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011257 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011258 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011259 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011260 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011261 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011262 }
11263 }
11264 } else {
11265 /*
11266 * Lets handle worst case scenario here, Scan cache lookup is
11267 * failed so we have to stop the SAP to avoid any channel
11268 * discrepancy between SAP's channel and STA's channel.
11269 * Return the status as failure so caller function could know
11270 * that scan look up is failed.
11271 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011272 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011273 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011274 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011275 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011276}
11277
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011278/**
11279 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11280 * @ap_adapter: SAP adapter
11281 *
11282 * This function will process the stopping of sap adapter.
11283 *
11284 * Return: None
11285 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011286void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011287{
Jeff Johnson87251032017-08-29 13:31:11 -070011288 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011289 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011290 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011291 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011292
11293 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011294 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011295 return;
11296 }
11297
11298 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11299 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011300 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011301 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011302
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011303 mutex_lock(&hdd_ctx->sap_lock);
11304 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011305 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011306 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011307 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011308 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011309 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011310 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011311 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011312 qdf_stop_bss_event,
11313 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011314 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011315 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011316 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011317 return;
11318 }
11319 }
11320 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011321 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11322 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011323 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011324 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011325 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011326 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011327 }
11328 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011329}
11330
11331/**
11332 * wlan_hdd_start_sap() - this function starts bss of SAP.
11333 * @ap_adapter: SAP adapter
11334 *
11335 * This function will process the starting of sap adapter.
11336 *
11337 * Return: None
11338 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011339void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011340{
Jeff Johnson87251032017-08-29 13:31:11 -070011341 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011342 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011343 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011344 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011345 tsap_Config_t *sap_config;
11346
11347 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011348 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011349 return;
11350 }
11351
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011352 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011353 hdd_err("SoftAp role has not been enabled");
11354 return;
11355 }
11356
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011357 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11358 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11359 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011360 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011361
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011362 mutex_lock(&hdd_ctx->sap_lock);
11363 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11364 goto end;
11365
11366 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011367 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011368 goto end;
11369 }
11370
Wei Song2f76f642016-11-18 16:32:53 +080011371 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011372 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011373 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011374 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011375 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011376 goto end;
11377
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011378 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011379 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011380 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011381 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011382 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011383 goto end;
11384 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011385 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011386 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011387 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011388 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011389 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11390 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011391 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011392 mutex_unlock(&hdd_ctx->sap_lock);
11393
11394 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011395end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011396 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011397 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011398 /* SAP context and beacon cleanup will happen during driver unload
11399 * in hdd_stop_adapter
11400 */
11401 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11402
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011403}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011404
11405/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011406 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11407 * mac scan config
11408 * @status: Status of set antenna mode
11409 *
11410 * Callback on setting the dual mac configuration
11411 *
11412 * Return: None
11413 */
11414void wlan_hdd_soc_set_antenna_mode_cb(
11415 enum set_antenna_mode_status status)
11416{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011417 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011418
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011419 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011420
11421 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11422 if (0 != wlan_hdd_validate_context(hdd_ctx))
11423 return;
11424
11425 /* Signal the completion of set dual mac config */
11426 complete(&hdd_ctx->set_antenna_mode_cmpl);
11427}
11428
11429/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011430 * hdd_get_fw_version() - Get FW version
11431 * @hdd_ctx: pointer to HDD context.
11432 * @major_spid: FW version - major spid.
11433 * @minor_spid: FW version - minor spid
11434 * @ssid: FW version - ssid
11435 * @crmid: FW version - crmid
11436 *
11437 * This function is called to get the firmware build version stored
11438 * as part of the HDD context
11439 *
11440 * Return: None
11441 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011442void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011443 uint32_t *major_spid, uint32_t *minor_spid,
11444 uint32_t *siid, uint32_t *crmid)
11445{
11446 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11447 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11448 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11449 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11450}
11451
11452#ifdef QCA_CONFIG_SMP
11453/**
11454 * wlan_hdd_get_cpu() - get cpu_index
11455 *
11456 * Return: cpu_index
11457 */
11458int wlan_hdd_get_cpu(void)
11459{
11460 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011461
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011462 put_cpu();
11463 return cpu_index;
11464}
11465#endif
11466
11467/**
11468 * hdd_get_fwpath() - get framework path
11469 *
11470 * This function is used to get the string written by
11471 * userspace to start the wlan driver
11472 *
11473 * Return: string
11474 */
11475const char *hdd_get_fwpath(void)
11476{
11477 return fwpath.string;
11478}
11479
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011480static int hdd_qdf_print_init(void)
11481{
11482 int qdf_print_idx;
11483 QDF_STATUS status;
11484
11485 status = qdf_print_setup();
11486 if (status != QDF_STATUS_SUCCESS) {
11487 pr_err("qdf_print_setup failed\n");
11488 return -EINVAL;
11489 }
11490
11491 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11492
11493 if (qdf_print_idx < 0) {
11494 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11495 qdf_print_idx);
11496 return -EINVAL;
11497 }
11498
11499 qdf_set_pidx(qdf_print_idx);
11500
11501 return 0;
11502}
11503
11504static void hdd_qdf_print_deinit(void)
11505{
11506 int qdf_print_idx;
11507
11508 qdf_print_idx = qdf_get_pidx();
11509 qdf_print_ctrl_cleanup(qdf_print_idx);
11510}
11511
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011512/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011513 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011514 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011515 * This function initilizes CDS global context with the help of cds_init. This
11516 * has to be the first function called after probe to get a valid global
11517 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011518 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011519 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011520 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011521int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011522{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011523 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011524 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011525
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011526 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011527 if (QDF_IS_STATUS_ERROR(status)) {
11528 hdd_err("Failed to allocate CDS context");
11529 ret = -ENOMEM;
11530 goto err_out;
11531 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011532
11533 wlan_init_bug_report_lock();
11534
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011535#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11536 wlan_logging_sock_init_svc();
11537#endif
11538
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011539 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11540 (void *)hdd_drv_ops_inactivity_handler, NULL,
11541 QDF_TIMER_TYPE_SW);
11542
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011543 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011544 hdd_qdf_print_init();
11545
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011546 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011547
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011548err_out:
11549 return ret;
11550}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011551
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011552/**
11553 * hdd_deinit() - Deinitialize Driver
11554 *
11555 * This function frees CDS global context with the help of cds_deinit. This
11556 * has to be the last function call in remove callback to free the global
11557 * context.
11558 */
11559void hdd_deinit(void)
11560{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011561 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011562
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011563 wlan_destroy_bug_report_lock();
11564 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011565
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011566 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011567#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11568 wlan_logging_sock_deinit_svc();
11569#endif
11570}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011571
Yue Ma6e7b1a02017-04-03 14:17:46 -070011572#ifdef QCA_WIFI_NAPIER_EMULATION
11573#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11574#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011575#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011576#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011577
Sachin Ahujadddd2632017-03-07 19:07:24 +053011578static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11579 struct file *file)
11580{
11581 return 0;
11582}
11583
11584static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11585 const char __user *user_buf,
11586 size_t count,
11587 loff_t *f_pos)
11588{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011589 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011590 static const char wlan_off_str[] = "OFF";
11591 static const char wlan_on_str[] = "ON";
11592 int ret;
11593 unsigned long rc;
11594
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011595 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011596 pr_err("Failed to read buffer\n");
11597 return -EINVAL;
11598 }
11599
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011600 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011601 pr_debug("Wifi turning off from UI\n");
11602 goto exit;
11603 }
11604
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011605 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011606 pr_err("Invalid value received from framework");
11607 goto exit;
11608 }
11609
11610 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011611 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011612 rc = wait_for_completion_timeout(&wlan_start_comp,
11613 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11614 if (!rc) {
11615 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11616 ret = -EINVAL;
11617 hdd_start_complete(ret);
11618 return ret;
11619 }
11620
11621 hdd_start_complete(0);
11622 }
11623
11624exit:
11625 return count;
11626}
11627
11628
11629const struct file_operations wlan_hdd_state_fops = {
11630 .owner = THIS_MODULE,
11631 .open = wlan_hdd_state_ctrl_param_open,
11632 .write = wlan_hdd_state_ctrl_param_write,
11633};
11634
11635static int wlan_hdd_state_ctrl_param_create(void)
11636{
11637 unsigned int wlan_hdd_state_major = 0;
11638 int ret;
11639 struct device *dev;
11640
11641 device = MKDEV(wlan_hdd_state_major, 0);
11642
11643 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11644 if (ret) {
11645 pr_err("Failed to register qcwlanstate");
11646 goto dev_alloc_err;
11647 }
11648 wlan_hdd_state_major = MAJOR(device);
11649
11650 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11651 if (IS_ERR(class)) {
11652 pr_err("wlan_hdd_state class_create error");
11653 goto class_err;
11654 }
11655
11656 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11657 if (IS_ERR(dev)) {
11658 pr_err("wlan_hdd_statedevice_create error");
11659 goto err_class_destroy;
11660 }
11661
11662 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11663 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11664 if (ret) {
11665 pr_err("Failed to add cdev error");
11666 goto cdev_add_err;
11667 }
11668
11669 pr_info("wlan_hdd_state %s major(%d) initialized",
11670 WLAN_MODULE_NAME, wlan_hdd_state_major);
11671
11672 return 0;
11673
11674cdev_add_err:
11675 device_destroy(class, device);
11676err_class_destroy:
11677 class_destroy(class);
11678class_err:
11679 unregister_chrdev_region(device, dev_num);
11680dev_alloc_err:
11681 return -ENODEV;
11682}
11683
11684static void wlan_hdd_state_ctrl_param_destroy(void)
11685{
11686 cdev_del(&wlan_hdd_state_cdev);
11687 device_destroy(class, device);
11688 class_destroy(class);
11689 unregister_chrdev_region(device, dev_num);
11690
11691 pr_info("Device node unregistered");
11692}
11693
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011694/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011695 * component_init - API to init cld component's
11696 *
11697 * Return: None
11698 */
11699static void component_init(void)
11700{
11701 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011702 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011703 ucfg_ocb_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011704}
11705
11706/**
11707 * component_deinit - API to deinit cld component's
11708 *
11709 * Return: None
11710 */
11711static void component_deinit(void)
11712{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011713 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011714 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011715 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011716}
11717
11718void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11719{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011720 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011721 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011722}
11723
11724void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11725{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011726 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011727 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011728}
11729
11730/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011731 * __hdd_module_init - Module init helper
11732 *
11733 * Module init helper function used by both module and static driver.
11734 *
11735 * Return: 0 for success, errno on failure
11736 */
11737static int __hdd_module_init(void)
11738{
11739 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011740
Dustin Brown96cd9632017-11-13 12:45:04 -080011741 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011742 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011743 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011744 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011745
Sachin Ahujadddd2632017-03-07 19:07:24 +053011746 ret = wlan_hdd_state_ctrl_param_create();
11747 if (ret) {
11748 pr_err("wlan_hdd_state_create:%x\n", ret);
11749 goto err_dev_state;
11750 }
11751
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011752 pld_init();
11753
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011754 ret = hdd_init();
11755 if (ret) {
11756 pr_err("hdd_init failed %x\n", ret);
11757 goto err_hdd_init;
11758 }
11759
Rajeev Kumar97767a02016-11-30 11:20:40 -080011760 dispatcher_init();
11761
Mukul Sharmad75a6672017-06-22 15:40:53 +053011762 /* Ensure to call post objmgr init */
11763 component_init();
11764
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011765 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011766
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011767 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011768
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011769 ret = wlan_hdd_register_driver();
11770 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011771 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11772 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011773 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011774 }
11775
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011776 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011777
11778 return 0;
11779out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011780 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011781 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011782 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011783 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011784
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011785err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011786 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011787 wlan_hdd_state_ctrl_param_destroy();
11788err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011789 return ret;
11790}
11791
11792/**
11793 * __hdd_module_exit - Module exit helper
11794 *
11795 * Module exit helper function used by both module and static driver.
11796 */
11797static void __hdd_module_exit(void)
11798{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011799
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011800 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11801 QWLAN_VERSIONSTR);
11802
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011803 hdd_wait_for_recovery_completion();
11804
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011805 wlan_hdd_unregister_driver();
11806
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011807 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011808
Mukul Sharmad75a6672017-06-22 15:40:53 +053011809 /* Ensure to call prior to objmgr deinit */
11810 component_deinit();
11811
Rajeev Kumar97767a02016-11-30 11:20:40 -080011812 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011813
11814 hdd_sysfs_destroy_version_interface();
11815
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011816 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011817 pld_deinit();
11818
Sachin Ahujadddd2632017-03-07 19:07:24 +053011819 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011820}
11821
Arun Khandavallifae92942016-08-01 13:31:08 +053011822#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011823/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011824 * wlan_boot_cb() - Wlan boot callback
11825 * @kobj: object whose directory we're creating the link in.
11826 * @attr: attribute the user is interacting with
11827 * @buff: the buffer containing the user data
11828 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011829 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011830 * This callback is invoked when the fs is ready to start the
11831 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011832 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011833 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011834 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011835static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011836 struct kobj_attribute *attr,
11837 const char *buf,
11838 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011839{
Arun Khandavallifae92942016-08-01 13:31:08 +053011840
Arun Khandavallifae92942016-08-01 13:31:08 +053011841 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011842 pr_err("%s: wlan driver already initialized\n", __func__);
11843 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011844 }
11845
Arun Khandavallifae92942016-08-01 13:31:08 +053011846 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011847 pr_err("%s: wlan driver initialization failed\n", __func__);
11848 return -EIO;
11849 }
11850
11851 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011852
11853 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011854}
Arun Khandavallifae92942016-08-01 13:31:08 +053011855
11856/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011857 * hdd_sysfs_cleanup() - cleanup sysfs
11858 *
11859 * Return: None
11860 *
11861 */
11862static void hdd_sysfs_cleanup(void)
11863{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011864 /* remove from group */
11865 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11866 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11867 wlan_loader->attr_group);
11868
11869 /* unlink the object from parent */
11870 kobject_del(wlan_loader->boot_wlan_obj);
11871
11872 /* free the object */
11873 kobject_put(wlan_loader->boot_wlan_obj);
11874
11875 kfree(wlan_loader->attr_group);
11876 kfree(wlan_loader);
11877
11878 wlan_loader = NULL;
11879}
11880
11881/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011882 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11883 * ready
11884 *
11885 * This is creates the syfs entry boot_wlan. Which shall be invoked
11886 * when the filesystem is ready.
11887 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011888 * QDF API cannot be used here since this function is called even before
11889 * initializing WLAN driver.
11890 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011891 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011892 */
11893static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011894{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011895 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011896
11897 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011898 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011899 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011900
11901 wlan_loader->boot_wlan_obj = NULL;
11902 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11903 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011904 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011905 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011906
11907 wlan_loader->loaded_state = 0;
11908 wlan_loader->attr_group->attrs = attrs;
11909
11910 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11911 kernel_kobj);
11912 if (!wlan_loader->boot_wlan_obj) {
11913 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011914 goto error_return;
11915 }
11916
11917 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11918 wlan_loader->attr_group);
11919 if (ret) {
11920 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11921 goto error_return;
11922 }
11923
11924 return 0;
11925
11926error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011927 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011928
11929 return ret;
11930}
11931
11932/**
11933 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11934 *
11935 * Return: 0 on success or errno on failure
11936 */
11937static int wlan_deinit_sysfs(void)
11938{
Arun Khandavallifae92942016-08-01 13:31:08 +053011939 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011940 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011941 return -EINVAL;
11942 }
11943
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011944 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011945 return 0;
11946}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011947
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011948#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011949
11950#ifdef MODULE
11951/**
11952 * __hdd_module_init - Module init helper
11953 *
11954 * Module init helper function used by both module and static driver.
11955 *
11956 * Return: 0 for success, errno on failure
11957 */
11958static int hdd_module_init(void)
11959{
Arun Khandavallifae92942016-08-01 13:31:08 +053011960 if (__hdd_module_init()) {
11961 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011962 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011963 }
11964
Dustin Brownab482ac2017-06-09 17:00:44 -070011965 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011966}
11967#else
11968static int __init hdd_module_init(void)
11969{
11970 int ret = -EINVAL;
11971
11972 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011973 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011974 pr_err("Failed to create sysfs entry for loading wlan");
11975
11976 return ret;
11977}
11978#endif
11979
11980
11981#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011982/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011983 * hdd_module_exit() - Exit function
11984 *
11985 * This is the driver exit point (invoked when module is unloaded using rmmod)
11986 *
11987 * Return: None
11988 */
11989static void __exit hdd_module_exit(void)
11990{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011991 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011992}
Arun Khandavallifae92942016-08-01 13:31:08 +053011993#else
11994static void __exit hdd_module_exit(void)
11995{
11996 __hdd_module_exit();
11997 wlan_deinit_sysfs();
11998}
11999#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012000
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012001static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
12002{
12003 return param_set_copystring(kmessage, kp);
12004}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012005
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012006/**
12007 * is_con_mode_valid() check con mode is valid or not
12008 * @mode: global con mode
12009 *
12010 * Return: TRUE on success FALSE on failure
12011 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012012static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012013{
12014 switch (mode) {
12015 case QDF_GLOBAL_MONITOR_MODE:
12016 case QDF_GLOBAL_FTM_MODE:
12017 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012018 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012019 return true;
12020 default:
12021 return false;
12022 }
12023}
12024
12025/**
12026 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12027 * @mode: global con mode
12028 *
12029 * Return: adapter mode
12030 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012031static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012032 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012033{
12034
12035 switch (mode) {
12036 case QDF_GLOBAL_MISSION_MODE:
12037 return QDF_STA_MODE;
12038 case QDF_GLOBAL_MONITOR_MODE:
12039 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012040 case QDF_GLOBAL_EPPING_MODE:
12041 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012042 case QDF_GLOBAL_FTM_MODE:
12043 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012044 case QDF_GLOBAL_QVIT_MODE:
12045 return QDF_QVIT_MODE;
12046 default:
12047 return QDF_MAX_NO_OF_MODE;
12048 }
12049}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012050
Dustin Brown27cd9942017-09-27 16:11:44 -070012051static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012052 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012053{
12054 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12055 return;
12056
12057 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012058 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012059 hdd_info("Release wakelock for monitor mode!");
12060 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12061 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12062 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012063 case QDF_GLOBAL_FTM_MODE:
12064 hdd_abort_mac_scan_all_adapters(hdd_ctx);
12065 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012066 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012067
Dustin Brown27cd9942017-09-27 16:11:44 -070012068 break;
12069 default:
12070 break;
12071 }
12072}
12073
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012074static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012075 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012076{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012077 int driver_status;
12078
12079 driver_status = hdd_ctx->driver_status;
12080
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012081 switch (curr_mode) {
12082 case QDF_GLOBAL_MISSION_MODE:
12083 case QDF_GLOBAL_MONITOR_MODE:
12084 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012085 hdd_deinit_all_adapters(hdd_ctx, false);
12086 hdd_close_all_adapters(hdd_ctx, false);
12087 break;
12088 case QDF_GLOBAL_EPPING_MODE:
12089 epping_disable();
12090 epping_close();
12091 break;
12092 default:
12093 return;
12094 }
12095}
12096
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012097static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012098 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012099{
Jeff Johnson9d295242017-08-29 14:39:48 -070012100 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012101 int ret = 0;
12102 bool rtnl_held;
12103 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12104 QDF_STATUS status;
12105
12106 if (!qdf_dev) {
12107 hdd_err("qdf device context is Null return!");
12108 return -EINVAL;
12109 }
12110
12111 rtnl_held = hdd_hold_rtnl_lock();
12112 switch (mode) {
12113 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012114 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12115 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012116 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012117 break;
12118 case QDF_GLOBAL_FTM_MODE:
12119 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12120 wlan_hdd_get_intf_addr(hdd_ctx),
12121 NET_NAME_UNKNOWN, rtnl_held);
12122 if (adapter == NULL)
12123 ret = -EINVAL;
12124 break;
12125 case QDF_GLOBAL_MONITOR_MODE:
12126 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12127 wlan_hdd_get_intf_addr(hdd_ctx),
12128 NET_NAME_UNKNOWN, rtnl_held);
12129 if (adapter == NULL)
12130 ret = -EINVAL;
12131 break;
12132 case QDF_GLOBAL_EPPING_MODE:
12133 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012134 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012135 hdd_err("Failed to open in eeping mode: %d", status);
12136 ret = -EINVAL;
12137 break;
12138 }
12139 ret = epping_enable(qdf_dev->dev);
12140 if (ret) {
12141 hdd_err("Failed to enable in epping mode : %d", ret);
12142 epping_close();
12143 }
12144 break;
12145 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012146 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012147 ret = -ENOTSUPP;
12148 break;
12149 }
12150 hdd_release_rtnl_lock();
12151 rtnl_held = false;
12152 return ret;
12153}
12154
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012155/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012156 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012157 * @kmessage: con mode name on which driver to be bring up
12158 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012159 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012160 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012161 * This function is invoked when user updates con mode using sys entry,
12162 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012163 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012164 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012165 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012166static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012167 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012168{
12169 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012170 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012171 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012172 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012173 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012174
Dustin Brownab6029b2017-05-24 13:04:19 -070012175 hdd_info("con_mode handler: %s", kmessage);
12176
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012177 ret = wlan_hdd_validate_context(hdd_ctx);
12178 if (ret)
12179 return ret;
12180
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012181 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012182 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012183
Dustin Brown20024e32018-01-03 12:34:58 -080012184 ret = kstrtoint(kmessage, 0, &new_con_mode);
12185 if (ret) {
12186 hdd_err("Failed to parse con_mode '%s'", kmessage);
12187 goto reset_flags;
12188 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012189 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012190
Dustin Brown20024e32018-01-03 12:34:58 -080012191 if (!is_con_mode_valid(new_con_mode)) {
12192 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012193 ret = -EINVAL;
12194 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012195 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012196
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012197 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012198 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012199 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012200 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012201 ret = 0;
12202 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012203 }
12204
Dustin Brown27cd9942017-09-27 16:11:44 -070012205 /* ensure adapters are stopped */
12206 hdd_stop_present_mode(hdd_ctx, curr_mode);
12207
Frank Liu6666f832018-01-04 10:06:05 +080012208 /* Cleanup present mode before switching to new mode */
12209 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12210
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012211 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012212 if (ret) {
12213 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012214 goto reset_flags;
12215 }
12216
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012217
Dustin Brown20024e32018-01-03 12:34:58 -080012218 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012219
Frank Liu6666f832018-01-04 10:06:05 +080012220 /*
12221 * Set ACTIVE domain before adapters created, otherwise check domain
12222 * match will fail when cleanup adapters.
12223 */
12224 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012225 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012226 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012227 if (ret) {
12228 hdd_err("Failed to register for new mode");
12229 goto reset_flags;
12230 }
12231
Dustin Brown20024e32018-01-03 12:34:58 -080012232 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012233 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12234 hdd_err("invalid adapter");
12235 ret = -EINVAL;
12236 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012237 }
12238
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012239 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012240 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012241 hdd_err("Failed to get adapter:%d", adapter_mode);
12242 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012243 }
12244
12245 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12246 if (ret) {
12247 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012248 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012249 }
12250
Dustin Brown20024e32018-01-03 12:34:58 -080012251 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012252 if (hdd_start_adapter(adapter)) {
12253 hdd_err("Failed to start %s adapter", kmessage);
12254 ret = -EINVAL;
12255 goto reset_flags;
12256 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012257
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012258 hdd_info("Acquire wakelock for monitor mode!");
12259 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12260 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12261 }
12262
Dustin Brown20024e32018-01-03 12:34:58 -080012263 /* con_mode is a global module parameter */
12264 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012265 hdd_info("Mode successfully changed to %s", kmessage);
12266 ret = 0;
12267
12268reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012269 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012270 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012271 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012272 return ret;
12273}
12274
12275
12276static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12277{
12278 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012279 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012280
12281 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12282 ret = wlan_hdd_validate_context(hdd_ctx);
12283 if (ret)
12284 return ret;
12285
12286 cds_ssr_protect(__func__);
12287 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12288 cds_ssr_unprotect(__func__);
12289
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012290 return ret;
12291}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012292
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012293static int con_mode_handler_ftm(const char *kmessage,
12294 struct kernel_param *kp)
12295{
12296 int ret;
12297
12298 ret = param_set_int(kmessage, kp);
12299
12300 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12301 pr_err("Only FTM mode supported!");
12302 return -ENOTSUPP;
12303 }
12304
12305 hdd_set_conparam(con_mode_ftm);
12306 con_mode = con_mode_ftm;
12307
12308 return ret;
12309}
12310
Ravi Joshia307f632017-07-17 23:41:41 -070012311static int con_mode_handler_monitor(const char *kmessage,
12312 struct kernel_param *kp)
12313{
12314 int ret;
12315
12316 ret = param_set_int(kmessage, kp);
12317
12318 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12319 pr_err("Only Monitor mode supported!");
12320 return -ENOTSUPP;
12321 }
12322
12323 hdd_set_conparam(con_mode_monitor);
12324 con_mode = con_mode_monitor;
12325
12326 return ret;
12327}
12328
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012329/**
12330 * hdd_get_conparam() - driver exit point
12331 *
12332 * This is the driver exit point (invoked when module is unloaded using rmmod)
12333 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012334 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012335 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012336enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012337{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012338 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012339}
12340
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012341void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012342{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012343 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012344}
12345
Komal Seelamc11bb222016-01-27 18:57:10 +053012346/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012347 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12348 * @hdd_ctx: HDD context
12349 *
12350 * Cleans up the pre cac interface, if it exists
12351 *
12352 * Return: None
12353 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012354void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012355{
12356 uint8_t session_id;
12357 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012358 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012359
12360 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12361 if (QDF_IS_STATUS_ERROR(status)) {
12362 hdd_err("failed to get pre cac vdev id");
12363 return;
12364 }
12365
12366 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12367 if (!precac_adapter) {
12368 hdd_err("invalid pre cac adapater");
12369 return;
12370 }
12371
12372 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12373 wlan_hdd_sap_pre_cac_failure,
12374 (void *)precac_adapter);
12375 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12376
12377}
12378
12379/**
Komal Seelamec702b02016-02-24 18:42:16 +053012380 * hdd_update_ol_config - API to update ol configuration parameters
12381 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012382 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012383 * Return: void
12384 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012385static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012386{
Komal Seelamec702b02016-02-24 18:42:16 +053012387 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012388 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012389
Komal Seelamec702b02016-02-24 18:42:16 +053012390 if (!ol_ctx)
12391 return;
12392
12393 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12394 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12395 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12396 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012397 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012398
12399 ol_init_ini_config(ol_ctx, &cfg);
12400}
12401
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012402#ifdef FEATURE_RUNTIME_PM
12403/**
12404 * hdd_populate_runtime_cfg() - populate runtime configuration
12405 * @hdd_ctx: hdd context
12406 * @cfg: pointer to the configuration memory being populated
12407 *
12408 * Return: void
12409 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012410static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012411 struct hif_config_info *cfg)
12412{
12413 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12414 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12415}
12416#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012417static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012418 struct hif_config_info *cfg)
12419{
12420}
12421#endif
12422
Komal Seelamec702b02016-02-24 18:42:16 +053012423/**
12424 * hdd_update_hif_config - API to update HIF configuration parameters
12425 * @hdd_ctx: HDD Context
12426 *
12427 * Return: void
12428 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012429static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012430{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012431 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012432 struct hif_config_info cfg;
12433
12434 if (!scn)
12435 return;
12436
12437 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012438 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012439 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012440
12441 if (hdd_ctx->config->prevent_link_down)
12442 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012443}
12444
12445/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012446 * hdd_update_dp_config() - Propagate config parameters to Lithium
12447 * datapath
12448 * @hdd_ctx: HDD Context
12449 *
12450 * Return: 0 for success/errno for failure
12451 */
12452static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12453{
12454 struct cdp_config_params params;
12455 QDF_STATUS status;
12456
12457 params.tso_enable = hdd_ctx->config->tso_enable;
12458 params.lro_enable = hdd_ctx->config->lro_enable;
12459#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12460 params.tx_flow_stop_queue_threshold =
12461 hdd_ctx->config->TxFlowStopQueueThreshold;
12462 params.tx_flow_start_queue_offset =
12463 hdd_ctx->config->TxFlowStartQueueOffset;
12464#endif
12465 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12466 params.napi_enable = hdd_ctx->napi_enable;
12467 params.tcp_udp_checksumoffload =
12468 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12469
12470 status = cdp_update_config_parameters(
12471 cds_get_context(QDF_MODULE_ID_SOC),
12472 &params);
12473 if (status) {
12474 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12475 "%s: Failed to attach config parameters", __func__);
12476 return status;
12477 }
12478
12479 return 0;
12480}
12481
12482/**
Komal Seelamec702b02016-02-24 18:42:16 +053012483 * hdd_update_config() - Initialize driver per module ini parameters
12484 * @hdd_ctx: HDD Context
12485 *
12486 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012487 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012488 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012489int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012490{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012491 int ret;
12492
Komal Seelamec702b02016-02-24 18:42:16 +053012493 hdd_update_ol_config(hdd_ctx);
12494 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012495 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12496 ret = hdd_update_cds_config_ftm(hdd_ctx);
12497 else
12498 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012499 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012500
12501 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012502}
12503
Mukul Sharma9d797a02017-01-05 20:26:03 +053012504#ifdef FEATURE_WLAN_RA_FILTERING
12505/**
12506 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12507 * @psoc_cfg: pmo psoc Configuration
12508 * @hdd_ctx: Pointer to hdd context
12509 *
12510 * Return: none
12511 */
12512static inline void hdd_ra_populate_pmo_config(
12513 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012514 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012515{
12516 psoc_cfg->ra_ratelimit_interval =
12517 hdd_ctx->config->RArateLimitInterval;
12518 psoc_cfg->ra_ratelimit_enable =
12519 hdd_ctx->config->IsRArateLimitEnabled;
12520}
12521#else
12522static inline void hdd_ra_populate_pmo_config(
12523 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012524 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012525{
12526}
12527#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012528
Mukul Sharma9d797a02017-01-05 20:26:03 +053012529/**
12530 * hdd_update_pmo_config - API to update pmo configuration parameters
12531 * @hdd_ctx: HDD context
12532 *
12533 * Return: void
12534 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012535static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012536{
12537 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12538 struct pmo_psoc_cfg psoc_cfg;
12539 QDF_STATUS status;
12540
12541 /*
12542 * Value of hdd_ctx->wowEnable can be,
12543 * 0 - Disable both magic pattern match and pattern byte match.
12544 * 1 - Enable magic pattern match on all interfaces.
12545 * 2 - Enable pattern byte match on all interfaces.
12546 * 3 - Enable both magic patter and pattern byte match on
12547 * all interfaces.
12548 */
12549 psoc_cfg.magic_ptrn_enable =
12550 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12551 psoc_cfg.ptrn_match_enable_all_vdev =
12552 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012553 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
Sourav Mohapatra89c85d12017-12-01 09:17:54 +053012554 wmi_service_unified_wow_capability);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012555 psoc_cfg.bpf_enable =
12556 hdd_ctx->config->bpf_packet_filter_enable;
12557 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012558 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012559 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12560 if (hdd_ctx->config->fhostNSOffload)
12561 psoc_cfg.ns_offload_enable_dynamic = true;
12562 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12563 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12564 psoc_cfg.active_mode_offload =
12565 hdd_ctx->config->active_mode_offload;
12566 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012567 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012568 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012569 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12570 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12571 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12572 psoc_cfg.power_save_mode =
12573 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012574 psoc_cfg.auto_power_save_fail_mode =
12575 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012576
12577 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012578 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12579 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012580 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012581 if (status != QDF_STATUS_SUCCESS) {
12582 hdd_err("failed pmo psoc configuration");
12583 return -EINVAL;
12584 }
12585
12586 return 0;
12587}
12588
Abhishek Singhb20db962017-03-03 21:28:46 +053012589#ifdef FEATURE_WLAN_SCAN_PNO
12590static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12591 struct hdd_config *cfg)
12592{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012593 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12594
Abhishek Singhb20db962017-03-03 21:28:46 +053012595 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12596 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12597 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12598 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12599 pno_cfg->channel_prediction_full_scan =
12600 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012601 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12602 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12603 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12604 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012605}
12606#else
12607static inline void
12608hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012609 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012610{
Abhishek Singhb20db962017-03-03 21:28:46 +053012611}
12612#endif
12613
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012614void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12615 struct hdd_config *cfg)
12616{
12617 uint8_t i = 0;
12618
12619 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12620 if (!ie_whitelist->white_list)
12621 return;
12622
12623 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12624 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12625 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12626 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12627 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12628 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12629 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12630 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12631
12632 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12633 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12634 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12635}
12636
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012637uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12638{
12639 uint8_t i, score;
12640
12641 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12642 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12643 if (score > MAX_INDEX_SCORE)
12644 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12645 MAX_INDEX_SCORE, i);
12646 }
12647
12648 return per_index_score;
12649}
12650
12651/**
12652 * hdd_update_score_config - API to update candidate scoring related params
12653 * configuration parameters
12654 * @score_config: score config to update
12655 * @cfg: config params
12656 *
12657 * Return: 0 if success else err
12658 */
12659static void hdd_update_score_config(
12660 struct scoring_config *score_config, struct hdd_config *cfg)
12661{
12662 int total_weight;
12663
12664 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12665 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12666 score_config->weight_cfg.vht_caps_weightage =
12667 cfg->vht_caps_weightage;
12668 score_config->weight_cfg.he_caps_weightage =
12669 cfg->he_caps_weightage;
12670 score_config->weight_cfg.chan_width_weightage =
12671 cfg->chan_width_weightage;
12672 score_config->weight_cfg.chan_band_weightage =
12673 cfg->chan_band_weightage;
12674 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12675 score_config->weight_cfg.beamforming_cap_weightage =
12676 cfg->beamforming_cap_weightage;
12677 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12678 score_config->weight_cfg.channel_congestion_weightage =
12679 cfg->channel_congestion_weightage;
12680 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12681
12682 total_weight = score_config->weight_cfg.rssi_weightage +
12683 score_config->weight_cfg.ht_caps_weightage +
12684 score_config->weight_cfg.vht_caps_weightage +
12685 score_config->weight_cfg.he_caps_weightage +
12686 score_config->weight_cfg.chan_width_weightage +
12687 score_config->weight_cfg.chan_band_weightage +
12688 score_config->weight_cfg.nss_weightage +
12689 score_config->weight_cfg.beamforming_cap_weightage +
12690 score_config->weight_cfg.pcl_weightage +
12691 score_config->weight_cfg.channel_congestion_weightage +
12692 score_config->weight_cfg.oce_wan_weightage;
12693
12694 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12695 hdd_err("total weight is greater than %d fallback to default values",
12696 BEST_CANDIDATE_MAX_WEIGHT);
12697
12698 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12699 score_config->weight_cfg.ht_caps_weightage =
12700 HT_CAPABILITY_WEIGHTAGE;
12701 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12702 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12703 score_config->weight_cfg.chan_width_weightage =
12704 CHAN_WIDTH_WEIGHTAGE;
12705 score_config->weight_cfg.chan_band_weightage =
12706 CHAN_BAND_WEIGHTAGE;
12707 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12708 score_config->weight_cfg.beamforming_cap_weightage =
12709 BEAMFORMING_CAP_WEIGHTAGE;
12710 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12711 score_config->weight_cfg.channel_congestion_weightage =
12712 CHANNEL_CONGESTION_WEIGHTAGE;
12713 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12714 }
12715
12716 score_config->bandwidth_weight_per_index =
12717 hdd_limit_max_per_index_score(
12718 cfg->bandwidth_weight_per_index);
12719 score_config->nss_weight_per_index =
12720 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12721 score_config->band_weight_per_index =
12722 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12723
12724 score_config->rssi_score.best_rssi_threshold =
12725 cfg->best_rssi_threshold;
12726 score_config->rssi_score.good_rssi_threshold =
12727 cfg->good_rssi_threshold;
12728 score_config->rssi_score.bad_rssi_threshold =
12729 cfg->bad_rssi_threshold;
12730 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12731 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12732 score_config->rssi_score.good_rssi_bucket_size =
12733 cfg->good_rssi_bucket_size;
12734 score_config->rssi_score.bad_rssi_bucket_size =
12735 cfg->bad_rssi_bucket_size;
12736 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12737 cfg->rssi_pref_5g_rssi_thresh;
12738
12739 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12740 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12741 hdd_limit_max_per_index_score(
12742 cfg->esp_qbss_score_slots3_to_0);
12743 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12744 hdd_limit_max_per_index_score(
12745 cfg->esp_qbss_score_slots7_to_4);
12746 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12747 hdd_limit_max_per_index_score(
12748 cfg->esp_qbss_score_slots11_to_8);
12749 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12750 hdd_limit_max_per_index_score(
12751 cfg->esp_qbss_score_slots15_to_12);
12752
12753 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12754 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12755 hdd_limit_max_per_index_score(
12756 cfg->oce_wan_score_slots3_to_0);
12757 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12758 hdd_limit_max_per_index_score(
12759 cfg->oce_wan_score_slots7_to_4);
12760 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12761 hdd_limit_max_per_index_score(
12762 cfg->oce_wan_score_slots11_to_8);
12763 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12764 hdd_limit_max_per_index_score(
12765 cfg->oce_wan_score_slots15_to_12);
12766
12767
12768 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12769 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12770 score_config->nss = cfg->enable2x2 ? 2 : 1;
12771
12772 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12773 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12774 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12775 score_config->he_cap = 1;
12776
12777 if (score_config->he_cap ||
12778 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12779 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12780 score_config->vht_cap = 1;
12781
12782 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12783 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12784 score_config->ht_cap = 1;
12785
12786 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12787 score_config->vht_24G_cap = 1;
12788
12789 if (cfg->enableTxBF)
12790 score_config->beamformee_cap = 1;
12791
12792}
12793
Abhishek Singh257a9482017-03-06 16:52:39 +053012794/**
bings81fe50a2017-11-27 14:33:26 +080012795 * hdd_update_dfs_config() - API to update dfs configuration parameters.
12796 * @hdd_ctx: HDD context
12797 *
12798 * Return: 0 if success else err
12799 */
12800static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
12801{
12802 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12803 struct hdd_config *cfg = hdd_ctx->config;
12804 struct dfs_user_config dfs_cfg;
12805 QDF_STATUS status;
12806
12807 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
12808 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
12809 if (QDF_IS_STATUS_ERROR(status)) {
12810 hdd_err("failed dfs psoc configuration");
12811 return -EINVAL;
12812 }
12813
12814 return 0;
12815}
12816
12817/**
Abhishek Singh257a9482017-03-06 16:52:39 +053012818 * hdd_update_scan_config - API to update scan configuration parameters
12819 * @hdd_ctx: HDD context
12820 *
12821 * Return: 0 if success else err
12822 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012823static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012824{
12825 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12826 struct scan_user_cfg scan_cfg;
12827 struct hdd_config *cfg = hdd_ctx->config;
12828 QDF_STATUS status;
12829
12830 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12831 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12832 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12833 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12834 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12835 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12836 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012837 /* convert to ms */
12838 scan_cfg.scan_cache_aging_time =
12839 cfg->scanAgingTimeout * 1000;
12840 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12841 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12842 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12843 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012844 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012845 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012846 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12847 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012848 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012849 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012850
Abhishek Singhb20db962017-03-03 21:28:46 +053012851 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012852 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012853 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012854
Abhishek Singh257a9482017-03-06 16:52:39 +053012855 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12856 if (status != QDF_STATUS_SUCCESS) {
12857 hdd_err("failed pmo psoc configuration");
12858 return -EINVAL;
12859 }
12860
12861 return 0;
12862}
Abhishek Singh257a9482017-03-06 16:52:39 +053012863
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012864int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012865{
12866 int ret;
12867
12868 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012869 if (ret)
12870 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012871
Abhishek Singh257a9482017-03-06 16:52:39 +053012872 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012873 if (ret)
12874 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012875
Frank Liud4b2fa02017-03-29 11:46:48 +080012876 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012877 if (ret)
12878 return ret;
12879
12880 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080012881 if (ret)
12882 return ret;
12883
12884 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012885
12886 return ret;
12887}
12888
Agrawal Ashish65634612016-08-18 13:24:32 +053012889/**
12890 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12891 * @mode : cfg80211 DFS mode
12892 *
12893 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12894 */
12895enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12896{
12897 switch (mode) {
12898 case DFS_MODE_ENABLE:
12899 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012900 case DFS_MODE_DISABLE:
12901 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012902 case DFS_MODE_DEPRIORITIZE:
12903 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012904 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012905 hdd_debug("ACS dfs mode is NONE");
12906 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012907 }
12908}
12909
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012910/**
12911 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12912 * @hddctx: pointer to hdd context
12913 * @set_value: enable/disable
12914 *
12915 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12916 * Host(even though it is duplicate). When Host send vendor command
12917 * disable,FW doesn't perform any action. Whenever any change in
12918 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12919 *
12920 * return - 0 on success, appropriate error values on failure.
12921 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012922int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012923{
12924 QDF_STATUS status;
12925
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012926 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012927 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012928
12929 if (!hddctx->config->goptimize_chan_avoid_event) {
12930 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12931 return -EINVAL;
12932 }
12933
12934 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12935 if (!QDF_IS_STATUS_SUCCESS(status)) {
12936 hdd_err("Failed to send chan avoid command to SME");
12937 return -EINVAL;
12938 }
12939 return 0;
12940}
Agrawal Ashish65634612016-08-18 13:24:32 +053012941
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012942/**
12943 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12944 * @value: value to set
12945 *
12946 * This function will set the passed value to roaming in progress flag.
12947 *
12948 * Return: None
12949 */
12950void hdd_set_roaming_in_progress(bool value)
12951{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012952 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012953
12954 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12955 if (!hdd_ctx) {
12956 hdd_err("HDD context is NULL");
12957 return;
12958 }
12959
12960 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012961 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012962}
12963
12964/**
12965 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012966 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012967 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012968 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012969 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012970bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012971{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012972 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012973 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012974
12975 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12976 if (!hdd_ctx) {
12977 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012978 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012979 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012980 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12981 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012982 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12983 hdd_ctx->roaming_in_progress);
12984
12985 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012986}
12987
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012988/**
12989 * hdd_is_connection_in_progress() - check if connection is in
12990 * progress
12991 * @session_id: session id
12992 * @reason: scan reject reason
12993 *
12994 * Go through each adapter and check if Connection is in progress
12995 *
12996 * Return: true if connection is in progress else false
12997 */
12998bool hdd_is_connection_in_progress(uint8_t *session_id,
12999 enum scan_reject_states *reason)
13000{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013001 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013002 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013003 uint8_t sta_id = 0;
13004 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013005 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013006
13007 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13008 if (!hdd_ctx) {
13009 hdd_err("HDD context is NULL");
13010 return false;
13011 }
13012
Dustin Brown920397d2017-12-13 16:27:50 -080013013 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013014 hdd_info("Adapter with device mode %s(%d) exists",
13015 hdd_device_mode_to_string(adapter->device_mode),
13016 adapter->device_mode);
13017 if (((QDF_STA_MODE == adapter->device_mode)
13018 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13019 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13020 && (eConnectionState_Connecting ==
13021 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13022 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013023 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013024 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013025 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013026 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013027 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013028 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013029 }
13030 return true;
13031 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013032 /*
13033 * sme_neighbor_middle_of_roaming is for LFR2
13034 * hdd_is_roaming_in_progress is for LFR3
13035 */
13036 if (((QDF_STA_MODE == adapter->device_mode) &&
13037 sme_neighbor_middle_of_roaming(
13038 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013039 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013040 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013041 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013042 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013043 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013044 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013045 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013046 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013047 }
13048 return true;
13049 }
13050 if ((QDF_STA_MODE == adapter->device_mode) ||
13051 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13052 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13053 hdd_sta_ctx =
13054 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13055 if ((eConnectionState_Associated ==
13056 hdd_sta_ctx->conn_info.connState)
13057 && (false ==
13058 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
13059 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013060 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013061 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013062 " is in middle of WPS/EAPOL exchange.",
13063 MAC_ADDR_ARRAY(sta_mac));
13064 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013065 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013066 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013067 }
13068 return true;
13069 }
13070 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13071 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13072 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13073 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013074 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013075 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013076 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013077 continue;
13078
13079 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013080 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013081 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013082 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013083 " of SAP/GO is in middle of WPS/EAPOL exchange",
13084 MAC_ADDR_ARRAY(sta_mac));
13085 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013086 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013087 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013088 }
13089 return true;
13090 }
13091 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013092 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013093 return true;
13094 }
13095 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013096 }
Dustin Brown920397d2017-12-13 16:27:50 -080013097
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013098 return false;
13099}
13100
13101/**
13102 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013103 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013104 *
13105 * Return: None
13106 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013107void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013108{
Jeff Johnson87251032017-08-29 13:31:11 -070013109 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013110 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013111 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013112 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013113 tsap_Config_t *sap_config;
13114 void *sap_ctx;
13115
13116 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013117 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013118 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013119
13120 mutex_lock(&hdd_ctx->sap_lock);
13121 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13122 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013123 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13124 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13125 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13126 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013127 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013128 qdf_stop_bss_event,
13129 SME_CMD_TIMEOUT_VALUE);
13130
13131 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013132 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013133 goto end;
13134 }
13135 }
13136 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013137 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013138 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013139 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013140
13141 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013142 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013143 wlansap_reset_sap_config_add_ie(sap_config,
13144 eUPDATE_IE_ALL);
13145 goto end;
13146 }
13147
13148 qdf_event_reset(&hostapd_state->qdf_event);
13149 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13150 sap_config,
13151 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013152 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013153 wlansap_reset_sap_config_add_ie(sap_config,
13154 eUPDATE_IE_ALL);
13155 goto end;
13156 }
13157
Jeff Johnson6867ec32017-09-29 20:30:20 -070013158 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013159 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013160 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013161 SME_CMD_TIMEOUT_VALUE);
13162 wlansap_reset_sap_config_add_ie(sap_config,
13163 eUPDATE_IE_ALL);
13164 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013165 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013166 goto end;
13167 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013168 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013169 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070013170 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013171 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13172 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013173 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013174 }
13175end:
13176 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013177}
13178
13179/**
13180 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13181 * with non dfs acs
13182 *
13183 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13184 *
13185 * Return: None
13186 */
13187void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13188{
Jeff Johnson9d295242017-08-29 14:39:48 -070013189 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013190 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013191 cds_context_type *cds_ctx;
13192
13193 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13194 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013195 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013196 return;
13197 }
13198
13199 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13200 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013201 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013202 return;
13203 }
13204
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013205 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13206 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013207 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013208 return;
13209 }
13210
13211 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013212 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13213 &ap_adapter->event_flags) &&
13214 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013215 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013216
Jeff Johnson6867ec32017-09-29 20:30:20 -070013217 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013218 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013219 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013220 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013221 acs_cfg.acs_mode = true;
13222
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013223 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013224 }
13225}
13226
13227/**
13228 * hdd_set_connection_in_progress() - to set the connection in
13229 * progress flag
13230 * @value: value to set
13231 *
13232 * This function will set the passed value to connection in progress flag.
13233 * If value is previously being set to true then no need to set it again.
13234 *
13235 * Return: true if value is being set correctly and false otherwise.
13236 */
13237bool hdd_set_connection_in_progress(bool value)
13238{
13239 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013240 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013241
13242 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13243 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013244 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013245 return false;
13246 }
13247
13248 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13249 /*
13250 * if the value is set to true previously and if someone is
13251 * trying to make it true again then it could be some race
13252 * condition being triggered. Avoid this situation by returning
13253 * false
13254 */
13255 if (hdd_ctx->connection_in_progress && value)
13256 status = false;
13257 else
13258 hdd_ctx->connection_in_progress = value;
13259 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13260 return status;
13261}
13262
Jeff Johnson9d295242017-08-29 14:39:48 -070013263int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013264{
13265 if (!adapter) {
13266 hdd_err("Invalid adapter");
13267 return -EINVAL;
13268 }
13269 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013270 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013271 WMA_VDEV_MCC_SET_TIME_QUOTA,
13272 set_value, VDEV_CMD);
13273 return 0;
13274
13275}
13276
Jeff Johnson9d295242017-08-29 14:39:48 -070013277int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013278{
13279 if (!adapter) {
13280 hdd_err("Invalid adapter");
13281 return -EINVAL;
13282 }
13283
13284 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013285 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013286 WMA_VDEV_MCC_SET_TIME_LATENCY,
13287 set_value, VDEV_CMD);
13288 return 0;
13289}
13290
Jeff Johnson9d295242017-08-29 14:39:48 -070013291struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013292 *psoc, uint8_t vdev_id)
13293{
Jeff Johnson9d295242017-08-29 14:39:48 -070013294 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013295 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013296
13297 /*
13298 * Currently PSOC is not being used. But this logic will
13299 * change once we have the converged implementation of
13300 * HDD context per PSOC in place. This would break if
13301 * multiple vdev objects reuse the vdev id.
13302 */
13303 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13304 if (!adapter)
13305 hdd_err("Get adapter by vdev id failed");
13306
13307 return adapter;
13308}
13309
Jeff Johnson9d295242017-08-29 14:39:48 -070013310int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013311 int8_t *rssi, int8_t *snr)
13312{
13313 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070013314 struct hdd_wext_state *wext_state =
13315 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013316 tCsrRoamProfile *profile = &wext_state->roamProfile;
13317
13318 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
13319 profile, bssid, rssi, snr);
13320 if (QDF_STATUS_SUCCESS != status) {
13321 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13322 return -EINVAL;
13323 }
13324
13325 return 0;
13326}
13327
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013328/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013329 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13330 * @adapter - HDD adapter
13331 * @tos - type of service
13332 * @status - status of the traffic
13333 *
13334 * Return: 0 on success and non zero value on failure
13335 */
13336
13337int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13338 bool is_tos_active)
13339{
13340 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013341 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013342 uint32_t max_off_chan_time = 0;
13343 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013344 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013345 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013346
13347 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13348 ret = wlan_hdd_validate_context(hdd_ctx);
13349
13350 if (ret < 0) {
13351 hdd_err("failed to set limit off chan params");
13352 return ret;
13353 }
13354
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013355 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13356
13357 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013358 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013359 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013360 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013361
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013362 if (adapter->active_ac) {
13363 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013364 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013365 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13366 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13367 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013368 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013369 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013370 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13371 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13372 PM_LATENCY);
13373 } else {
13374 /*ignore this command if only BE/BK is active */
13375 is_tos_active = false;
13376 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13377 hdd_ctx->config->conc_system_pref);
13378 }
13379 } else {
13380 /* No active tos */
13381 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13382 hdd_ctx->config->conc_system_pref);
13383 }
13384
Jeff Johnson1b780e42017-10-31 14:11:45 -070013385 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013386 is_tos_active, max_off_chan_time,
13387 hdd_ctx->config->nRestTimeConc, true);
13388 if (!QDF_IS_STATUS_SUCCESS(status)) {
13389 hdd_err("failed to set limit off chan params");
13390 ret = -EINVAL;
13391 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013392
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013393 return ret;
13394}
13395
13396/**
13397 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13398 * @adapter - HDD adapter
13399 *
13400 * Return: 0 on success and non zero value on failure
13401 */
13402int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13403{
13404 struct hdd_context *hdd_ctx;
13405 int ret;
13406 QDF_STATUS status;
13407 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13408
13409 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13410 ret = wlan_hdd_validate_context(hdd_ctx);
13411 if (ret < 0)
13412 return ret;
13413
13414 /* set the system preferece to default */
13415 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13416 hdd_ctx->config->conc_system_pref);
13417
13418 /* clear the bitmap */
13419 adapter->active_ac = 0;
13420
13421 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013422 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013423
Jeff Johnson1b780e42017-10-31 14:11:45 -070013424 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013425 false, 0, 0, false);
13426 if (!QDF_IS_STATUS_SUCCESS(status)) {
13427 hdd_err("failed to reset limit off chan params");
13428 ret = -EINVAL;
13429 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013430
13431 return ret;
13432}
13433
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013434/**
13435 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13436 * @drv_op: Enum indicating driver op
13437 *
13438 * Return: none
13439 */
13440void hdd_start_driver_ops_timer(int drv_op)
13441{
13442 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13443 switch (drv_op) {
13444 case eHDD_DRV_OP_PROBE:
13445 memcpy(drv_ops_string, "probe", sizeof("probe"));
13446 break;
13447 case eHDD_DRV_OP_REMOVE:
13448 memcpy(drv_ops_string, "remove", sizeof("remove"));
13449 break;
13450 case eHDD_DRV_OP_SHUTDOWN:
13451 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13452 break;
13453 case eHDD_DRV_OP_REINIT:
13454 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13455 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013456 case eHDD_DRV_OP_IFF_UP:
13457 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13458 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013459 }
13460
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013461 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013462 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13463 HDD_OPS_INACTIVITY_TIMEOUT);
13464}
13465
13466/**
13467 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13468 *
13469 * Return: none
13470 */
13471void hdd_stop_driver_ops_timer(void)
13472{
13473 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13474}
13475
13476/**
13477 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13478 * inactivity timer
13479 *
13480 * Return: None
13481 */
13482void hdd_drv_ops_inactivity_handler(void)
13483{
13484 hdd_err("%s: %d Sec timer expired while in .%s",
13485 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13486
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013487 if (hdd_drv_ops_task) {
13488 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13489 qdf_print_thread_trace(hdd_drv_ops_task);
13490 } else {
13491 hdd_err("hdd_drv_ops_task is null");
13492 }
13493
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013494 /* Driver shutdown is stuck, no recovery possible at this point */
13495 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13496 sizeof("shutdown")))
13497 QDF_BUG(0);
13498
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013499 if (cds_is_fw_down()) {
13500 hdd_err("FW is down");
13501 return;
13502 }
13503
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013504 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013505 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013506 else
13507 QDF_BUG(0);
13508}
13509
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013510void hdd_pld_ipa_uc_shutdown_pipes(void)
13511{
13512 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13513
13514 if (!hdd_ctx)
13515 return;
13516
13517 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13518}
13519
Yun Parkff6a16a2017-09-26 16:38:18 -070013520/**
13521 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13522 * @struct hdd_context *hdd_ctx
13523 * @struct hdd_adapter *padapter
13524 * @bool enble
13525 *
13526 * Return: none
13527 */
13528void hdd_set_rx_mode_rps(bool enable)
13529{
13530 struct cds_config_info *cds_cfg = cds_get_ini_config();
13531 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13532 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13533
13534 if (adapter && hdd_ctx &&
13535 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13536 if (enable && !cds_cfg->rps_enabled)
13537 hdd_send_rps_ind(adapter);
13538 else if (!enable && cds_cfg->rps_enabled)
13539 hdd_send_rps_disable_ind(adapter);
13540 }
13541}
13542
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013543/* Register the module init/exit functions */
13544module_init(hdd_module_init);
13545module_exit(hdd_module_exit);
13546
13547MODULE_LICENSE("Dual BSD/GPL");
13548MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13549MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013551module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13552 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013553
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013554module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13555 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13556
Ravi Joshia307f632017-07-17 23:41:41 -070013557module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13558 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13559
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013560module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13561 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13562
13563module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13564
13565module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13566
13567module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);