blob: 657a0ebd922ec5dbf962ca784994b37ff43c8479 [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"
Naveen Rawate02f8f52018-04-05 11:58:04 -070058#include <wlan_osif_request_manager.h>
Dustin Brown26b3d042017-12-21 11:13:27 -080059#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080060#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080061#endif
Dustin Brownd4241942018-02-26 12:51:37 -080062#include "qdf_str.h"
63#include "qdf_trace.h"
64#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070065#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080066#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070067#include <cdp_txrx_stats.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080068
69#include <net/addrconf.h>
70#include <linux/wireless.h>
71#include <net/cfg80211.h>
72#include <linux/inetdevice.h>
73#include <net/addrconf.h>
74#include "wlan_hdd_cfg80211.h"
75#include "wlan_hdd_ext_scan.h"
76#include "wlan_hdd_p2p.h"
77#include <linux/rtnetlink.h>
78#include "sap_api.h"
79#include <linux/semaphore.h>
80#include <linux/ctype.h>
81#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053082#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080084#include <soc/qcom/subsystem_restart.h>
85#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080086#include <wlan_hdd_hostapd.h>
87#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070088#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080089#include "cfg_api.h"
90#include "qwlan_version.h"
91#include "wma_types.h"
92#include "wlan_hdd_tdls.h"
93#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053094#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070096#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070097#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080098#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080099#include "wlan_hdd_nan.h"
100#include "wlan_hdd_debugfs.h"
101#include "wlan_hdd_driver_ops.h"
102#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530103#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800104
105#include <wlan_hdd_ipa.h>
106#include "hif.h"
107#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800108#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700109#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530110#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700111#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700112#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530113#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700114#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530115#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800116#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800117#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530118#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800119#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800120#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530121#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530122#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800123#include "os_if_wifi_pos.h"
124#include "wifi_pos_api.h"
125#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800126#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700127#include "os_if_nan.h"
128#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700129#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800130#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700131#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530132#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530133#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700134#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800135#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530136#include "wlan_disa_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530137#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530138#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530139#include "wlan_hdd_nud_tracking.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530140
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530141#ifdef CNSS_GENL
142#include <net/cnss_nl.h>
143#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800144#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800145#include "wlan_ocb_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530146
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800147#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800148#ifdef MODULE
149#define WLAN_MODULE_NAME module_name(THIS_MODULE)
150#else
151#define WLAN_MODULE_NAME "wlan"
152#endif
153
154#ifdef TIMER_MANAGER
155#define TIMER_MANAGER_STR " +TIMER_MANAGER"
156#else
157#define TIMER_MANAGER_STR ""
158#endif
159
160#ifdef MEMORY_DEBUG
161#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
162#else
163#define MEMORY_DEBUG_STR ""
164#endif
165
Dustin Brownc1034df2018-02-07 14:51:32 -0800166#ifdef PANIC_ON_BUG
167#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
168#else
169#define PANIC_ON_BUG_STR ""
170#endif
171
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530172bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530173int wlan_start_ret_val;
174static DECLARE_COMPLETION(wlan_start_comp);
175static unsigned int dev_num = 1;
176static struct cdev wlan_hdd_state_cdev;
177static struct class *class;
178static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530179#ifndef MODULE
180static struct gwlan_loader *wlan_loader;
181static ssize_t wlan_boot_cb(struct kobject *kobj,
182 struct kobj_attribute *attr,
183 const char *buf, size_t count);
184struct gwlan_loader {
185 bool loaded_state;
186 struct kobject *boot_wlan_obj;
187 struct attribute_group *attr_group;
188};
189
190static struct kobj_attribute wlan_boot_attribute =
191 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
192
193static struct attribute *attrs[] = {
194 &wlan_boot_attribute.attr,
195 NULL,
196};
197
198#define MODULE_INITIALIZED 1
199#endif
200
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530201#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
202#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800203#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530204
205static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800206static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530207static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
208
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800209/* the Android framework expects this param even though we don't use it */
210#define BUF_LEN 20
211static char fwpath_buffer[BUF_LEN];
212static struct kparam_string fwpath = {
213 .string = fwpath_buffer,
214 .maxlen = BUF_LEN,
215};
216
217static char *country_code;
218static int enable_11d = -1;
219static int enable_dfs_chan_scan = -1;
220
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800221/*
222 * spinlock for synchronizing asynchronous request/response
223 * (full description of use in wlan_hdd_main.h)
224 */
225DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530226DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800227
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800228#define WLAN_NLINK_CESIUM 30
229
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530230static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800231
232#define WOW_MAX_FILTER_LISTS 1
233#define WOW_MAX_FILTERS_PER_LIST 4
234#define WOW_MIN_PATTERN_SIZE 6
235#define WOW_MAX_PATTERN_SIZE 64
236
237#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
238static const struct wiphy_wowlan_support wowlan_support_reg_init = {
239 .flags = WIPHY_WOWLAN_ANY |
240 WIPHY_WOWLAN_MAGIC_PKT |
241 WIPHY_WOWLAN_DISCONNECT |
242 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
243 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
244 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
245 WIPHY_WOWLAN_4WAY_HANDSHAKE |
246 WIPHY_WOWLAN_RFKILL_RELEASE,
247 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
248 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
249 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
250};
251#endif
252
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700253static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
254 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
266 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
267 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
268 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
269 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
270 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700288 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700289 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700290 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530291 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800292 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530293 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700294};
295
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530296int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
297 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
298 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
299 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
300 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
301};
302
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530303struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530304struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800305
306struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800307#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700308static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800309#endif
310
Sachin Ahujadddd2632017-03-07 19:07:24 +0530311void hdd_start_complete(int ret)
312{
313 wlan_start_ret_val = ret;
314
315 complete(&wlan_start_comp);
316}
317
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800318/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530319 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700320 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530321 *
322 * Return: none
323 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700324static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530325{
Jeff Johnson9d295242017-08-29 14:39:48 -0700326 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530327
Dustin Brown920397d2017-12-13 16:27:50 -0800328 hdd_for_each_adapter(hdd_ctx, adapter)
329 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530330}
331
332/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800333 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
334 * @vdev_id: vdev_id
335 * @action: action type
336 * @reason: reason type
337 *
338 * Return: none
339 */
340void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
341 enum netif_action_type action, enum netif_reason_type reason)
342{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700343 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700344 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800345
346 if (!hdd_ctx) {
347 hdd_err("hdd ctx is NULL");
348 return;
349 }
350 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
351
352 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800353}
354
355/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700356 * Store WLAN driver version and timestamp info in global variables such that
357 * crash debugger can extract them from driver debug symbol and crashdump for
358 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800359 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800360#ifdef BUILD_TAG
361uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
362#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800363uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700364#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800365
366/**
367 * hdd_device_mode_to_string() - return string conversion of device mode
368 * @device_mode: device mode
369 *
370 * This utility function helps log string conversion of device mode.
371 *
372 * Return: string conversion of device mode, if match found;
373 * "Unknown" otherwise.
374 */
375const char *hdd_device_mode_to_string(uint8_t device_mode)
376{
377 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800378 CASE_RETURN_STRING(QDF_STA_MODE);
379 CASE_RETURN_STRING(QDF_SAP_MODE);
380 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
381 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
382 CASE_RETURN_STRING(QDF_FTM_MODE);
383 CASE_RETURN_STRING(QDF_IBSS_MODE);
384 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
385 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700386 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800387 default:
388 return "Unknown";
389 }
390}
391
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530392/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500393 * hdd_get_valid_chan() - return current chan list from regulatory.
394 * @hdd_ctx: HDD context
395 * @chan_list: buf hold returned chan list
396 * @chan_num: input buf size and output returned chan num
397 *
398 * This function helps get current available chan list from regulatory
399 * module. It excludes the "disabled" and "invalid" channels.
400 *
401 * Return: 0 for success.
402 */
403static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
404 uint8_t *chan_list,
405 uint32_t *chan_num)
406{
407 int i = 0, j = 0;
408 struct regulatory_channel *cur_chan_list;
409 struct wlan_objmgr_pdev *pdev;
410
411 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
412 return -EINVAL;
413
414 pdev = hdd_ctx->hdd_pdev;
415 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
416 sizeof(struct regulatory_channel));
417 if (!cur_chan_list)
418 return -ENOMEM;
419
420 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
421 QDF_STATUS_SUCCESS) {
422 qdf_mem_free(cur_chan_list);
423 return -EINVAL;
424 }
425
426 for (i = 0; i < NUM_CHANNELS; i++) {
427 uint32_t ch = cur_chan_list[i].chan_num;
428 enum channel_state state = wlan_reg_get_channel_state(pdev,
429 ch);
430
431 if (state != CHANNEL_STATE_DISABLE &&
432 state != CHANNEL_STATE_INVALID &&
433 j < *chan_num) {
434 chan_list[j] = (uint8_t)ch;
435 j++;
436 }
437 }
438 *chan_num = j;
439 qdf_mem_free(cur_chan_list);
440 return 0;
441}
442
443/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530444 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
445 * @adapter: HDD adapter
446 * @chan_number: Channel number
447 * @chan_bw: Bandwidth
448 *
449 * Checks if the given bandwidth is valid for the given channel number.
450 *
451 * Return: 0 for success, non-zero for failure
452 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700453int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530454 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800455 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530456{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500457 uint8_t chan[NUM_CHANNELS];
458 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530459 bool found = false;
460 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500461 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530462
463 hal = WLAN_HDD_GET_HAL_CTX(adapter);
464 if (!hal) {
465 hdd_err("Invalid HAL context");
466 return -EINVAL;
467 }
468
Liangwei Dong17bf2662018-01-05 02:02:05 -0500469 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
470 &len);
471 if (ret) {
472 hdd_err("error %d in getting valid channel list", ret);
473 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530474 }
475
476 for (i = 0; i < len; i++) {
477 if (chan[i] == chan_number) {
478 found = true;
479 break;
480 }
481 }
482
483 if (found == false) {
484 hdd_err("Channel not in driver's valid channel list");
485 return -EOPNOTSUPP;
486 }
487
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700488 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
489 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530490 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
491 return -EINVAL;
492 }
493
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700494 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530495 if (chan_bw == CH_WIDTH_80MHZ) {
496 hdd_err("BW80 not possible in 2.4GHz band");
497 return -EINVAL;
498 }
499 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
500 (chan_bw != CH_WIDTH_MAX)) {
501 hdd_err("Only BW20 possible on channel 14");
502 return -EINVAL;
503 }
504 }
505
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700506 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530507 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
508 (chan_bw != CH_WIDTH_MAX)) {
509 hdd_err("Only BW20 possible on channel 165");
510 return -EINVAL;
511 }
512 }
513
514 return 0;
515}
516
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530517/**
518 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
519 *
520 * Block the unloading of the driver (or) interface up until the
521 * cds recovery is completed
522 *
523 * Return: true for recovery completion else false
524 */
525static bool hdd_wait_for_recovery_completion(void)
526{
527 int retry = 0;
528
529 /* Wait for recovery to complete */
530 while (cds_is_driver_recovering()) {
531 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
532 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530533
534 if (g_is_system_reboot_triggered) {
535 hdd_info("System Reboot happening ignore unload!!");
536 return false;
537 }
538
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530539 msleep(1000);
540 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
541 hdd_err("SSR never completed, error");
542 /*
543 * Trigger the bug_on in the internal builds, in the
544 * customer builds self-recovery will be enabled
545 * in those cases just return error.
546 */
547 if (cds_is_self_recovery_enabled())
548 return false;
549 QDF_BUG(0);
550 }
551 }
552
553 hdd_info("Recovery completed successfully!");
554 return true;
555}
556
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530557
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558static int __hdd_netdev_notifier_call(struct notifier_block *nb,
559 unsigned long state, void *data)
560{
561#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
562 struct netdev_notifier_info *dev_notif_info = data;
563 struct net_device *dev = dev_notif_info->dev;
564#else
565 struct net_device *dev = data;
566#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700567 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700568 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800569
Dustin Brownfdf17c12018-03-14 12:55:34 -0700570 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800572 /* Make sure that this callback corresponds to our device. */
573 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
574 return NOTIFY_DONE;
575
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530576 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800577 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700578 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800579 return NOTIFY_DONE;
580 }
581
582 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700583 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584 return NOTIFY_DONE;
585 }
586
587 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
588 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800589 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530590 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800591 return NOTIFY_DONE;
592 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800593
594 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
595 hdd_err("%s: Driver module is closed", __func__);
596 return NOTIFY_DONE;
597 }
598
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530599 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600 return NOTIFY_DONE;
601
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800602 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800603 dev->name, state);
604
605 switch (state) {
606 case NETDEV_REGISTER:
607 break;
608
609 case NETDEV_UNREGISTER:
610 break;
611
612 case NETDEV_UP:
613 sme_ch_avoid_update_req(hdd_ctx->hHal);
614 break;
615
616 case NETDEV_DOWN:
617 break;
618
619 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700620 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800621 complete(&adapter->linkup_event_var);
622 break;
623
624 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700625 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
626 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530627 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700628 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800629 } else {
hqueaa33ee2017-05-04 17:56:35 +0800630 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800631 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800632 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530633 /*
634 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
635 * of return status of hdd_stop call, kernel resets the IFF_UP
636 * flag after which driver does not send the cfg80211_scan_done.
637 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
638 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530639 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800640 break;
641
642 default:
643 break;
644 }
645
646 return NOTIFY_DONE;
647}
648
649/**
650 * hdd_netdev_notifier_call() - netdev notifier callback function
651 * @nb: pointer to notifier block
652 * @state: state
653 * @ndev: ndev pointer
654 *
655 * Return: 0 on success, error number otherwise.
656 */
657static int hdd_netdev_notifier_call(struct notifier_block *nb,
658 unsigned long state,
659 void *ndev)
660{
661 int ret;
662
663 cds_ssr_protect(__func__);
664 ret = __hdd_netdev_notifier_call(nb, state, ndev);
665 cds_ssr_unprotect(__func__);
666
667 return ret;
668}
669
670struct notifier_block hdd_netdev_notifier = {
671 .notifier_call = hdd_netdev_notifier_call,
672};
673
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530674static int system_reboot_notifier_call(struct notifier_block *nb,
675 unsigned long msg_type, void *_unused)
676{
677 switch (msg_type) {
678 case SYS_DOWN:
679 case SYS_HALT:
680 case SYS_POWER_OFF:
681 g_is_system_reboot_triggered = true;
682 hdd_info("reboot, reason: %ld", msg_type);
683 break;
684 default:
685 break;
686 }
687
688 return NOTIFY_OK;
689}
690
691struct notifier_block system_reboot_notifier = {
692 .notifier_call = system_reboot_notifier_call,
693};
694
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800695/* variable to hold the insmod parameters */
696static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800697
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530698static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700699int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530700
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800701/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800702static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800703
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530704/**
705 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
706 * @ch_width: NL channel width
707 *
708 * Converts the NL channel width to the driver's internal representation
709 *
710 * Return: Converted channel width. In case of non matching NL channel width,
711 * CH_WIDTH_MAX will be returned.
712 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800713enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530714{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800715 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700716
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800717 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530718 switch (ch_width) {
719 case NL80211_CHAN_WIDTH_20_NOHT:
720 case NL80211_CHAN_WIDTH_20:
721 return CH_WIDTH_20MHZ;
722 case NL80211_CHAN_WIDTH_40:
723 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530724 case NL80211_CHAN_WIDTH_80:
725 return CH_WIDTH_80MHZ;
726 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800727 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
728 return CH_WIDTH_80P80MHZ;
729 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
730 return CH_WIDTH_160MHZ;
731 else
732 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530733 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800734 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
735 return CH_WIDTH_160MHZ;
736 else
737 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530738 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800739 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530740 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800741 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530742 default:
743 hdd_err("Invalid channel width %d, setting to default",
744 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800745 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530746 }
747}
748
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530749/* wlan_hdd_find_opclass() - Find operating class for a channel
750 * @hal: handler to HAL
751 * @channel: channel id
752 * @bw_offset: bandwidth offset
753 *
754 * Function invokes sme api to find the operating class
755 *
756 * Return: operating class
757 */
758uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
759 uint8_t bw_offset)
760{
761 uint8_t opclass = 0;
762
763 sme_get_opclass(hal, channel, bw_offset, &opclass);
764 return opclass;
765}
766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530768 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530769 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800770 * @bitmask: Bitmask of log levels to be enabled
771 *
772 * Called immediately after the cfg.ini is read in order to configure
773 * the desired trace levels.
774 *
775 * Return: None
776 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530777int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800778{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530779 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530780 int qdf_print_idx = -1;
781 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782 /*
783 * if the bitmask is the default value, then a bitmask was not
784 * specified in cfg.ini, so leave the logging level alone (it
785 * will remain at the "compiled in" default value)
786 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700787 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530788 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800789
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530790 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530792 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530793 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530794 QDF_TRACE_LEVEL_NONE, 0);
795
796 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530797 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800798 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530799 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800 while (0 != bitmask) {
801 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530802 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530803 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530804 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530805 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800806 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800808 level++;
809 bitmask >>= 1;
810 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530811 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812}
813
814/**
Chris Guo1751acf2017-07-03 14:09:01 +0800815 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
816 * @hdd_ctx: HDD context pointer
817 *
818 * Return: 0 if the context is valid. Error code otherwise
819 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700820int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800821{
822 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
823 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
824 return -ENODEV;
825 }
826
827 if (cds_is_driver_recovering()) {
828 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
829 (void *)_RET_IP_, cds_get_driver_state());
830 return -EAGAIN;
831 }
832
833 if (hdd_ctx->start_modules_in_progress ||
834 hdd_ctx->stop_modules_in_progress) {
835 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
836 (void *)_RET_IP_);
837 return -EAGAIN;
838 }
839
840 return 0;
841}
842
843
844/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 * wlan_hdd_validate_context() - check the HDD context
846 * @hdd_ctx: HDD context pointer
847 *
848 * Return: 0 if the context is valid. Error code otherwise
849 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700850int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800852 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530853 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 return -ENODEV;
855 }
856
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800857 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800858 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530859 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860 return -EAGAIN;
861 }
862
Yue Ma9f275d92017-09-14 16:58:41 -0700863 if (cds_is_load_or_unload_in_progress()) {
864 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
865 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700867 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530868
869 if (hdd_ctx->start_modules_in_progress ||
870 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800871 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530872 (void *)_RET_IP_);
873 return -EAGAIN;
874 }
875
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530876 if (cds_is_driver_in_bad_state()) {
877 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
878 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530879 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530880 }
881
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530882 if (cds_is_fw_down()) {
883 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
884 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530885 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530886 }
887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800888 return 0;
889}
890
Jeff Johnson9d295242017-08-29 14:39:48 -0700891int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700892{
893 if (!adapter) {
894 hdd_err("adapter is null");
895 return -EINVAL;
896 }
897
898 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
899 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
900 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
901 return -EINVAL;
902 }
903
904 if (!adapter->dev) {
905 hdd_err("adapter net_device is null");
906 return -EINVAL;
907 }
908
909 if (!(adapter->dev->flags & IFF_UP)) {
910 hdd_info("adapter net_device is not up");
911 return -EAGAIN;
912 }
913
Jeff Johnson1b780e42017-10-31 14:11:45 -0700914 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700915 hdd_info("adapter session is not open");
916 return -EAGAIN;
917 }
918
Jeff Johnson1b780e42017-10-31 14:11:45 -0700919 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
920 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700921 return -EINVAL;
922 }
923
924 return 0;
925}
926
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530928 * wlan_hdd_validate_modules_state() - Check modules status
929 * @hdd_ctx: HDD context pointer
930 *
931 * Check's the driver module's state and returns true if the
932 * modules are enabled returns false if modules are closed.
933 *
934 * Return: True if modules are enabled or false.
935 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700936bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530937{
938 mutex_lock(&hdd_ctx->iface_change_lock);
939 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
940 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700941 hdd_info("Modules not enabled, Present status: %d",
942 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530943 return false;
944 }
945 mutex_unlock(&hdd_ctx->iface_change_lock);
946 return true;
947}
948
949/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700951 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800952 *
953 * This function sets the IBSS power save config parameters to WMA
954 * which will send it to firmware if FW supports IBSS power save
955 * before vdev start.
956 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530957 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 * on failure.
959 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700960QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961{
962 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700963 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964
965 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700966 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530967 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 }
969
Jeff Johnson1b780e42017-10-31 14:11:45 -0700970 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
972 hdd_ctx->config->ibssATIMWinSize,
973 VDEV_CMD);
974 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700975 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", 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_SET_POWER_SAVE_ALLOWED,
981 hdd_ctx->config->isIbssPowerSaveAllowed,
982 VDEV_CMD);
983 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700984 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED 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_SET_POWER_COLLAPSE_ALLOWED,
991 hdd_ctx->config->
992 isIbssPowerCollapseAllowed, VDEV_CMD);
993 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700994 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED 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
Jeff Johnson1b780e42017-10-31 14:11:45 -0700999 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1001 hdd_ctx->config->isIbssAwakeOnTxRx,
1002 VDEV_CMD);
1003 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001004 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301005 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001006 }
1007
Jeff Johnson1b780e42017-10-31 14:11:45 -07001008 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1010 hdd_ctx->config->ibssInactivityCount,
1011 VDEV_CMD);
1012 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001013 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301014 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001015 }
1016
Jeff Johnson1b780e42017-10-31 14:11:45 -07001017 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1019 hdd_ctx->config->ibssTxSpEndInactivityTime,
1020 VDEV_CMD);
1021 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001022 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
1023 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301024 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001025 }
1026
Jeff Johnson1b780e42017-10-31 14:11:45 -07001027 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1029 hdd_ctx->config->ibssPsWarmupTime,
1030 VDEV_CMD);
1031 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001032 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
1033 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301034 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001035 }
1036
Jeff Johnson1b780e42017-10-31 14:11:45 -07001037 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1039 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1040 VDEV_CMD);
1041 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001042 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1043 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301044 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001045 }
1046
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301047 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001048}
1049
Yue Macd359b72017-10-03 15:21:00 -07001050#ifdef FEATURE_RUNTIME_PM
1051/**
1052 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1053 * @hdd_ctx: HDD context
1054 *
1055 * Return: None
1056 */
1057static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1058{
1059 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1060
Yue Macd359b72017-10-03 15:21:00 -07001061 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001062 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001063
1064 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1065}
1066
1067/**
1068 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1069 * @hdd_ctx: HDD Context
1070 *
1071 * Return: None
1072 */
1073static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1074{
1075 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1076
Yue Macd359b72017-10-03 15:21:00 -07001077 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001078 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001079
1080 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1081}
1082
Yue Macd359b72017-10-03 15:21:00 -07001083#else /* FEATURE_RUNTIME_PM */
1084static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1085static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001086#endif /* FEATURE_RUNTIME_PM */
1087
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001088#define INTF_MACADDR_MASK 0x7
1089
1090/**
1091 * hdd_update_macaddr() - update mac address
1092 * @config: hdd configuration
1093 * @hw_macaddr: mac address
1094 *
1095 * Mac address for multiple virtual interface is found as following
1096 * i) The mac address of the first interface is just the actual hw mac address.
1097 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1098 * define the mac address for the remaining interfaces and locally
1099 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1100 * supported virtual interfaces, right now this is 0x07 (meaning 8
1101 * interface).
1102 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1103 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1104 *
1105 * Return: None
1106 */
1107void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301108 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109{
1110 int8_t i;
1111 uint8_t macaddr_b3, tmp_br3;
1112
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301113 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301114 QDF_MAC_ADDR_SIZE);
1115 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301116 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301117 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001118 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1119 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1120 INTF_MACADDR_MASK;
1121 macaddr_b3 += tmp_br3;
1122
1123 /* XOR-ing bit-24 of the mac address. This will give enough
1124 * mac address range before collision
1125 */
1126 macaddr_b3 ^= (1 << 7);
1127
1128 /* Set locally administered bit */
1129 config->intfMacAddr[i].bytes[0] |= 0x02;
1130 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001131 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001132 MAC_ADDRESS_STR, i,
1133 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1134 }
1135}
1136
Kabilan Kannan44a58372017-12-06 18:16:11 -08001137static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1138{
1139 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1140 struct tdls_start_params tdls_cfg;
1141 struct tdls_user_config *config = &tdls_cfg.config;
1142 struct hdd_config *cfg = hdd_ctx->config;
1143 QDF_STATUS status;
1144
1145 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1146 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1147 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1148 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1149 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1150 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1151 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1152 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1153 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1154 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1155 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1156 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1157 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1158 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1159 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1160 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1161 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1162 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1163 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1164 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1165 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1166 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1167 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1168 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1169 (cfg->fEnableTDLSImplicitTrigger ?
1170 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1171 (cfg->fTDLSExternalControl ?
1172 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1173 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1174 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1175
1176 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1177 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1178 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1179 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1180 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1181 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1182 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1183 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001184 tdls_cfg.tdls_peer_context = hdd_ctx;
1185 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1186 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001187 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1188 tdls_cfg.tdls_wmm_cb_data = psoc;
1189 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1190 tdls_cfg.tdls_rx_cb_data = psoc;
1191 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1192
1193 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1194 if (status != QDF_STATUS_SUCCESS) {
1195 hdd_err("failed pmo psoc configuration");
1196 return -EINVAL;
1197 }
1198
1199 hdd_ctx->tdls_umac_comp_active = true;
1200 /* enable napier specific tdls data path */
1201 hdd_ctx->tdls_nap_active = true;
1202
1203 return 0;
1204}
1205
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001206static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001207 struct wma_tgt_services *cfg)
1208{
1209 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001210
1211 /* Set up UAPSD */
1212 config->apUapsdEnabled &= cfg->uapsd;
1213
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001214 /* 11AX mode support */
1215 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1216 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1217 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001219 /* 11AC mode support */
1220 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1221 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1222 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001223
1224 /* ARP offload: override user setting if invalid */
1225 config->fhostArpOffload &= cfg->arp_offload;
1226
1227#ifdef FEATURE_WLAN_SCAN_PNO
1228 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001229 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001230 if (cfg->pno_offload)
1231 config->PnoOffload = true;
1232#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001233#ifdef FEATURE_WLAN_TDLS
1234 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301235 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1236 cfg->en_tdls_offchan;
1237 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1238 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001239 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001241 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1245 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1246#endif
Will Huang496b36c2017-07-11 16:38:50 +08001247 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001248 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001249 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001250 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251
1252}
1253
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001254/**
1255 * hdd_update_vdev_nss() - sets the vdev nss
1256 * @hdd_ctx: HDD context
1257 *
1258 * Sets the Nss per vdev type based on INI
1259 *
1260 * Return: None
1261 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001262static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001263{
1264 struct hdd_config *cfg_ini = hdd_ctx->config;
1265 uint8_t max_supp_nss = 1;
1266
Naveen Rawat10b1c152017-01-18 11:16:06 -08001267 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001268 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001269 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1270 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1271 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001272
1273 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001274 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001275
1276 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001277 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001278}
1279
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301280/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301281 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1282 * @hdd_ctx: HDD context
1283 *
1284 * Updates wiphy vhtcap fields
1285 *
1286 * Return: None
1287 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001288static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301289{
1290 struct ieee80211_supported_band *band_5g =
1291 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1292 uint32_t val;
1293
1294 if (!band_5g) {
1295 hdd_debug("5GHz band disabled, skipping capability population");
1296 return;
1297 }
1298
1299 val = hdd_ctx->config->txBFCsnValue;
1300 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1301
1302 val = NUM_OF_SOUNDING_DIMENSIONS;
1303 band_5g->vht_cap.cap |=
1304 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1305
1306 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1307 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1308}
1309
1310/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301311 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1312 * @hdd_ctx: HDD context
1313 *
1314 * Sets the DBS capability as per INI and firmware capability
1315 *
1316 * Return: None
1317 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001318static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301319{
1320 struct hdd_config *cfg_ini = hdd_ctx->config;
1321 uint8_t hw_dbs_capable = 0;
1322
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001323 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1324 ((cfg_ini->dual_mac_feature_disable ==
1325 ENABLE_DBS_CXN_AND_SCAN) ||
1326 (cfg_ini->dual_mac_feature_disable ==
1327 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301328 hw_dbs_capable = 1;
1329
1330 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1331}
1332
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001333static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001334 struct wma_tgt_ht_cap *cfg)
1335{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301336 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337 uint32_t value, val32;
1338 uint16_t val16;
1339 struct hdd_config *pconfig = hdd_ctx->config;
1340 tSirMacHTCapabilityInfo *phtCapInfo;
1341 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1342 uint8_t enable_tx_stbc;
1343
1344 /* check and update RX STBC */
1345 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1346 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1347
1348 /* get the MPDU density */
1349 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1350
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301351 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001352 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001353 value = 0;
1354 }
1355
1356 /*
1357 * MPDU density:
1358 * override user's setting if value is larger
1359 * than the one supported by target
1360 */
1361 if (value > cfg->mpdu_density) {
1362 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1363 cfg->mpdu_density);
1364
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301365 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001366 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001367 }
1368
1369 /* get the HT capability info */
1370 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301371 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001372 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 return;
1374 }
1375 val16 = (uint16_t) val32;
1376 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1377
1378 /* Set the LDPC capability */
1379 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1380
1381 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1382 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1383
1384 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1385 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1386
1387 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1388 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1389
1390 enable_tx_stbc = pconfig->enableTxSTBC;
1391
1392 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1393 pconfig->enable2x2 = 1;
1394 } else {
1395 pconfig->enable2x2 = 0;
1396 enable_tx_stbc = 0;
1397
1398 /* 1x1 */
1399 /* Update Rx Highest Long GI data Rate */
1400 if (sme_cfg_set_int(hdd_ctx->hHal,
1401 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001402 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301403 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001404 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001405 }
1406
1407 /* Update Tx Highest Long GI data Rate */
1408 if (sme_cfg_set_int
1409 (hdd_ctx->hHal,
1410 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001411 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301412 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001413 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414 }
1415 }
1416 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1417 enable_tx_stbc = 0;
1418 phtCapInfo->txSTBC = enable_tx_stbc;
1419
1420 val32 = val16;
1421 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301422 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001423 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001424#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1425 value = SIZE_OF_SUPPORTED_MCS_SET;
1426 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301427 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001428 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001429
1430 if (pconfig->enable2x2) {
1431 for (value = 0; value < cfg->num_rf_chains; value++)
1432 mcs_set[value] =
1433 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1434
1435 status =
1436 sme_cfg_set_str(hdd_ctx->hHal,
1437 WNI_CFG_SUPPORTED_MCS_SET,
1438 mcs_set,
1439 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301440 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001441 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 }
1443 }
1444#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1445}
1446
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001447static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 struct wma_tgt_vht_cap *cfg)
1449{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301450 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451 uint32_t value = 0;
1452 struct hdd_config *pconfig = hdd_ctx->config;
1453 struct wiphy *wiphy = hdd_ctx->wiphy;
1454 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001455 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001456 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001457 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001458 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001459 struct wma_caps_per_phy caps_per_phy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460
Dustin Brown5e06bd32016-10-04 12:49:10 -07001461 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001462 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001463 return;
1464 }
1465
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466 /* Get the current MPDU length */
1467 status =
1468 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1469 &value);
1470
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301471 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001472 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001473 value = 0;
1474 }
1475
1476 /*
1477 * VHT max MPDU length:
1478 * override if user configured value is too high
1479 * that the target cannot support
1480 */
1481 if (value > cfg->vht_max_mpdu) {
1482 status = sme_cfg_set_int(hdd_ctx->hHal,
1483 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1484 cfg->vht_max_mpdu);
1485
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001486 if (status == QDF_STATUS_E_FAILURE)
1487 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 }
1489
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001490 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1491 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1492
1493 if (pconfig->enable2x2)
1494 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1495
1496 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1497 QDF_STATUS_E_FAILURE) {
1498 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1499 }
1500
1501 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1502 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1503 if (pconfig->enable2x2)
1504 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1505
1506 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1507 QDF_STATUS_E_FAILURE) {
1508 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1509 }
1510
1511 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1512 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1513 if (pconfig->enable2x2)
1514 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1515
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001516 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001517 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1518
1519 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1520 QDF_STATUS_E_FAILURE) {
1521 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1522 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001523 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001524 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001525 &value);
1526
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301527 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001528 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529 value = 0;
1530 }
1531
jiad4a7a33c2017-08-08 15:32:24 +08001532 /* Set HW RX LDPC capability */
1533 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1534 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001535 status = sme_cfg_set_int(hdd_ctx->hHal,
1536 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001537 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001538
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001539 if (status == QDF_STATUS_E_FAILURE)
1540 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001541 }
1542
1543 /* Get current GI 80 value */
1544 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1545 &value);
1546
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301547 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001548 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549 value = 0;
1550 }
1551
1552 /* set the Guard interval 80MHz */
1553 if (value && !cfg->vht_short_gi_80) {
1554 status = sme_cfg_set_int(hdd_ctx->hHal,
1555 WNI_CFG_VHT_SHORT_GI_80MHZ,
1556 cfg->vht_short_gi_80);
1557
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001558 if (status == QDF_STATUS_E_FAILURE)
1559 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 }
1561
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001562 /* Get VHT TX STBC cap */
1563 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1564
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301565 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001566 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001567 value = 0;
1568 }
1569
1570 /* VHT TX STBC cap */
1571 if (value && !cfg->vht_tx_stbc) {
1572 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1573 cfg->vht_tx_stbc);
1574
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001575 if (status == QDF_STATUS_E_FAILURE)
1576 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577 }
1578
1579 /* Get VHT RX STBC cap */
1580 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1581
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301582 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001583 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584 value = 0;
1585 }
1586
1587 /* VHT RX STBC cap */
1588 if (value && !cfg->vht_rx_stbc) {
1589 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1590 cfg->vht_rx_stbc);
1591
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001592 if (status == QDF_STATUS_E_FAILURE)
1593 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594 }
1595
1596 /* Get VHT SU Beamformer cap */
1597 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1598 &value);
1599
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301600 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001601 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001602 value = 0;
1603 }
1604
1605 /* set VHT SU Beamformer cap */
1606 if (value && !cfg->vht_su_bformer) {
1607 status = sme_cfg_set_int(hdd_ctx->hHal,
1608 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1609 cfg->vht_su_bformer);
1610
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001611 if (status == QDF_STATUS_E_FAILURE)
1612 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001613 }
1614
1615 /* check and update SU BEAMFORMEE capabality */
1616 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1617 pconfig->enableTxBF = cfg->vht_su_bformee;
1618
1619 status = sme_cfg_set_int(hdd_ctx->hHal,
1620 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1621 pconfig->enableTxBF);
1622
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001623 if (status == QDF_STATUS_E_FAILURE)
1624 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625
1626 /* Get VHT MU Beamformer cap */
1627 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1628 &value);
1629
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301630 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001631 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 value = 0;
1633 }
1634
1635 /* set VHT MU Beamformer cap */
1636 if (value && !cfg->vht_mu_bformer) {
1637 status = sme_cfg_set_int(hdd_ctx->hHal,
1638 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1639 cfg->vht_mu_bformer);
1640
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001641 if (status == QDF_STATUS_E_FAILURE)
1642 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643 }
1644
1645 /* Get VHT MU Beamformee cap */
1646 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1647 &value);
1648
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301649 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001650 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001651 value = 0;
1652 }
1653
1654 /* set VHT MU Beamformee cap */
1655 if (value && !cfg->vht_mu_bformee) {
1656 status = sme_cfg_set_int(hdd_ctx->hHal,
1657 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1658 cfg->vht_mu_bformee);
1659
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001660 if (status == QDF_STATUS_E_FAILURE)
1661 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001662 }
1663
1664 /* Get VHT MAX AMPDU Len exp */
1665 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1666 &value);
1667
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301668 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001669 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670 value = 0;
1671 }
1672
1673 /*
1674 * VHT max AMPDU len exp:
1675 * override if user configured value is too high
1676 * that the target cannot support.
1677 * Even though Rome publish ampdu_len=7, it can
1678 * only support 4 because of some h/w bug.
1679 */
1680
1681 if (value > cfg->vht_max_ampdu_len_exp) {
1682 status = sme_cfg_set_int(hdd_ctx->hHal,
1683 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1684 cfg->vht_max_ampdu_len_exp);
1685
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001686 if (status == QDF_STATUS_E_FAILURE)
1687 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688 }
1689
1690 /* Get VHT TXOP PS CAP */
1691 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1692
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301693 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001694 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695 value = 0;
1696 }
1697
1698 /* set VHT TXOP PS cap */
1699 if (value && !cfg->vht_txop_ps) {
1700 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1701 cfg->vht_txop_ps);
1702
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001703 if (status == QDF_STATUS_E_FAILURE)
1704 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001705 }
1706
1707 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1708 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1709 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1710 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1711 else
1712 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1713
1714
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001715 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1716 status = sme_cfg_set_int(hdd_ctx->hHal,
1717 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1718 VHT_CAP_160_AND_80P80_SUPP);
1719 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001720 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001721 band_5g->vht_cap.cap |=
1722 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001723 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1724 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1725 status = sme_cfg_set_int(hdd_ctx->hHal,
1726 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1727 VHT_CAP_160_SUPP);
1728 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001729 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730 band_5g->vht_cap.cap |=
1731 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001732 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1733 }
1734 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1735 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301736 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001737 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301738 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001739 &value);
1740 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301741 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001742 value = 0;
1743 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301744 /* set the Guard interval 160MHz */
1745 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001746 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301747 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1748 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001749
1750 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301751 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001752 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001753
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001754 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001755 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001756 hdd_debug("VHT RxLDPC capability is set");
1757 } else {
1758 /*
1759 * Get the RX LDPC capability for the NON DBS
1760 * hardware mode for 5G band
1761 */
1762 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1763 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1764 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1765 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1766 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1767 hdd_debug("VHT RX LDPC capability is set");
1768 }
1769 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770
1771 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1772 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1773 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1774 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1775
1776 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1777 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1778
1779 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1780 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1781 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1782 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1783 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1784 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1785
1786 band_5g->vht_cap.cap |=
1787 (cfg->vht_max_ampdu_len_exp <<
1788 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1789
1790 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1791 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1792 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1793 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1794 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1795 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1796 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1797 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1798
1799 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1800 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1801
1802}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001803
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001804/**
1805 * hdd_generate_macaddr_auto() - Auto-generate mac address
1806 * @hdd_ctx: Pointer to the HDD context
1807 *
1808 * Auto-generate mac address using device serial number.
1809 * Keep the first 3 bytes of OUI as before and replace
1810 * the last 3 bytes with the lower 3 bytes of serial number.
1811 *
1812 * Return: 0 for success
1813 * Non zero failure code for errors
1814 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001815static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001816{
1817 unsigned int serialno = 0;
1818 struct qdf_mac_addr mac_addr = {
1819 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1820 };
1821
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001822 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001823 if (serialno == 0)
1824 return -EINVAL;
1825
1826 serialno &= 0x00ffffff;
1827
1828 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1829 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1830 mac_addr.bytes[5] = serialno & 0xff;
1831
1832 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1833 return 0;
1834}
1835
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301836/**
1837 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1838 * configuration to cfg_ini in HDD
1839 * @hdd_ctx: Pointer to hdd_ctx
1840 * @cfg: target configuration
1841 *
1842 * Return: None
1843 */
1844#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001845static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301846 struct wma_tgt_cfg *cfg)
1847{
1848 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1849}
1850#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001851static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301852 struct wma_tgt_cfg *cfg)
1853{
1854}
1855#endif
1856
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001857void hdd_update_tgt_cfg(void *context, void *param)
1858{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001859 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001860 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001861 struct wma_tgt_cfg *cfg = param;
1862 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001863 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301864 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001865 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301866
Dustin Brownbd68fe12017-11-21 15:28:52 -08001867 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1868 if (ret) {
1869 hdd_err("Failed to create pdev; errno:%d", ret);
1870 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001871 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001872 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001873 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001874 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1875 hdd_err("dispatcher pdev open failed");
1876 QDF_BUG(0);
1877 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301878 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001879
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001880 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301881
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301882 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1883 cds_get_context(QDF_MODULE_ID_SOC));
1884 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1885 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301886 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1887 hdd_softap_hard_start_xmit);
1888 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1889 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301890
Naveen Rawat64e477e2016-05-20 10:34:56 -07001891 if (cds_cfg) {
1892 if (hdd_ctx->config->enable_sub_20_channel_width !=
1893 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1894 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1895 cds_cfg->sub_20_channel_width =
1896 WLAN_SUB_20_CH_WIDTH_NONE;
1897 } else {
1898 cds_cfg->sub_20_channel_width =
1899 hdd_ctx->config->enable_sub_20_channel_width;
1900 }
1901 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001902
1903 /* first store the INI band capability */
1904 temp_band_cap = hdd_ctx->config->nBandCapability;
1905
1906 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301907 hdd_ctx->is_fils_roaming_supported =
1908 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001909
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301910 hdd_ctx->config->is_11k_offload_supported =
1911 cfg->services.is_11k_offload_supported;
1912
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001913 /*
1914 * now overwrite the target band capability with INI
1915 * setting if INI setting is a subset
1916 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001917
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001918 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1919 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001920 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001921 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1922 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001923 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001924 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925 }
1926
Amar Singhal58b45ef2017-08-01 13:43:54 -07001927 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1928
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301929 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1931 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1932 }
1933
1934 /* This can be extended to other configurations like ht, vht cap... */
1935
Anurag Chouhanc5548422016-02-24 18:33:27 +05301936 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001937 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001938 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001939 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001940 static struct qdf_mac_addr default_mac_addr = {
1941 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1942 };
1943 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1944 &default_mac_addr)) {
1945 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1946 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1947 MAC_ADDRESS_STR,
1948 MAC_ADDR_ARRAY(hdd_ctx->config->
1949 intfMacAddr[0].bytes));
1950 } else {
1951 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1952 MAC_ADDRESS_STR,
1953 MAC_ADDR_ARRAY(hdd_ctx->config->
1954 intfMacAddr[0].bytes));
1955 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001956 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 }
1958
1959 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001960 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001961
1962 hdd_ctx->max_intf_count = cfg->max_intf_count;
1963
Jeff Johnsonc875e242016-09-23 18:12:34 -07001964 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001965
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001966 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1967 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1968
1969 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1970
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001971 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001972 if (cfg->services.en_11ax) {
1973 hdd_info("11AX: 11ax is enabled - update HDD config");
1974 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1975 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001976
1977 hdd_update_vdev_nss(hdd_ctx);
1978
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301979 hdd_update_hw_dbs_capable(hdd_ctx);
1980
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001981 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001982 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001983 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001984 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001985
Nitesh Shahe50711f2017-04-26 16:30:45 +05301986 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1987 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1988 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001989 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001990 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001991
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001992 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1993 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301994 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301995 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301996
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301997 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001998 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1999 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302000 hdd_ctx->config->txBFCsnValue =
2001 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
2002
Arif Hussainee10f902017-12-27 16:30:17 -08002003 status = sme_cfg_set_int(hdd_ctx->hHal,
2004 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
2005 hdd_ctx->config->txBFCsnValue);
2006 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302007 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2008
2009
2010 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002011 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
2012 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302013
2014 /*
2015 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2016 */
2017 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302018
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302019 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2020
Yue Macd359b72017-10-03 15:21:00 -07002021 /*
2022 * This needs to be done after HDD pdev is created and stored since
2023 * it will access the HDD pdev object lock.
2024 */
2025 hdd_runtime_suspend_context_init(hdd_ctx);
2026
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002027 /* Configure NAN datapath features */
2028 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002029 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002030 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002031 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2032 cfg->obss_detection_offloaded);
2033 if (QDF_IS_STATUS_ERROR(status))
2034 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002035
2036 status = sme_cfg_set_int(hdd_ctx->hHal,
2037 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2038 cfg->obss_color_collision_offloaded);
2039 if (QDF_IS_STATUS_ERROR(status))
2040 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002041}
2042
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002043bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044{
Jeff Johnson9d295242017-08-29 14:39:48 -07002045 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002046 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002047
Jiachao Wuf610d912018-01-23 17:47:32 +08002048 if (!hdd_ctx) {
2049 hdd_info("Couldn't get hdd_ctx");
2050 return true;
2051 }
2052
2053 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002054 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002055 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302056 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002057 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002058
Dustin Brown920397d2017-12-13 16:27:50 -08002059 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002060 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2061
2062 if ((QDF_SAP_MODE == adapter->device_mode ||
2063 QDF_P2P_GO_MODE == adapter->device_mode) &&
2064 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002065 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002066 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2067 true;
2068 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002069 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302070 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002071 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302072
2073 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002074}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002075
2076/**
2077 * hdd_is_valid_mac_address() - validate MAC address
2078 * @pMacAddr: Pointer to the input MAC address
2079 *
2080 * This function validates whether the given MAC address is valid or not
2081 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2082 * where X is the hexa decimal digit character and separated by ':'
2083 * This algorithm works even if MAC address is not separated by ':'
2084 *
2085 * This code checks given input string mac contains exactly 12 hexadecimal
2086 * digits and a separator colon : appears in the input string only after
2087 * an even number of hex digits.
2088 *
2089 * Return: 1 for valid and 0 for invalid
2090 */
2091bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2092{
2093 int xdigit = 0;
2094 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002095
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002096 while (*pMacAddr) {
2097 if (isxdigit(*pMacAddr)) {
2098 xdigit++;
2099 } else if (':' == *pMacAddr) {
2100 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2101 break;
2102
2103 ++separator;
2104 } else {
2105 /* Invalid MAC found */
2106 return 0;
2107 }
2108 ++pMacAddr;
2109 }
2110 return xdigit == 12 && (separator == 5 || separator == 0);
2111}
2112
2113/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302114 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2115 * @dev: Handle to struct net_device to be updated.
2116 *
2117 * Return: None
2118 */
2119static void hdd_mon_mode_ether_setup(struct net_device *dev)
2120{
2121 dev->header_ops = NULL;
2122 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2123 dev->hard_header_len = ETH_HLEN;
2124 dev->mtu = ETH_DATA_LEN;
2125 dev->addr_len = ETH_ALEN;
2126 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2127 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2128 dev->priv_flags |= IFF_TX_SKB_SHARING;
2129
2130 memset(dev->broadcast, 0xFF, ETH_ALEN);
2131}
2132
2133/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002134 * __hdd__mon_open() - HDD Open function
2135 * @dev: Pointer to net_device structure
2136 *
2137 * This is called in response to ifconfig up
2138 *
2139 * Return: 0 for success; non-zero for failure
2140 */
2141static int __hdd_mon_open(struct net_device *dev)
2142{
2143 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002144 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2145 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002146
Dustin Brownfdf17c12018-03-14 12:55:34 -07002147 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002148
2149 ret = wlan_hdd_validate_context(hdd_ctx);
2150 if (ret)
2151 return ret;
2152
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302153 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002154
2155 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2156 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2157 if (ret) {
2158 hdd_err("Failed to start WLAN modules return");
2159 return ret;
2160 }
2161 hdd_err("hdd_wlan_start_modules() successful !");
2162
2163 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2164 ret = hdd_start_adapter(adapter);
2165 if (ret) {
2166 hdd_err("Failed to start adapter :%d",
2167 adapter->device_mode);
2168 return ret;
2169 }
2170 hdd_err("hdd_start_adapters() successful !");
2171 }
2172 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2173 }
2174
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002175 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002176
2177 if (!ret)
2178 ret = hdd_enable_monitor_mode(dev);
2179
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002180 return ret;
2181}
2182
2183/**
2184 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2185 * @dev: Pointer to net_device structure
2186 *
2187 * This is called in response to ifconfig up
2188 *
2189 * Return: 0 for success; non-zero for failure
2190 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002191static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002192{
2193 int ret;
2194
2195 cds_ssr_protect(__func__);
2196 ret = __hdd_mon_open(dev);
2197 cds_ssr_unprotect(__func__);
2198
2199 return ret;
2200}
2201
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002202static QDF_STATUS
2203wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2204{
2205 struct policy_mgr_dual_mac_config cfg = {0};
2206 QDF_STATUS status;
2207 uint32_t channel_select_logic_conc;
2208 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2209
2210 if (!hdd_ctx) {
2211 hdd_err("HDD context is NULL");
2212 return QDF_STATUS_E_FAILURE;
2213 }
2214
2215
2216 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2217 return QDF_STATUS_SUCCESS;
2218
2219 cfg.scan_config = 0;
2220 cfg.fw_mode_config = 0;
2221 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2222
2223 channel_select_logic_conc = hdd_ctx->config->
2224 channel_select_logic_conc;
2225
2226 if (hdd_ctx->config->dual_mac_feature_disable !=
2227 DISABLE_DBS_CXN_AND_SCAN) {
2228 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2229 hdd_ctx->hdd_psoc, &cfg.scan_config,
2230 &cfg.fw_mode_config,
2231 hdd_ctx->config->dual_mac_feature_disable,
2232 channel_select_logic_conc);
2233
2234 if (status != QDF_STATUS_SUCCESS) {
2235 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2236 status);
2237 return status;
2238 }
2239 }
2240
2241 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2242 cfg.scan_config, cfg.fw_mode_config);
2243
2244 status = sme_soc_set_dual_mac_config(cfg);
2245 if (status != QDF_STATUS_SUCCESS) {
2246 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2247 return status;
2248 }
2249
2250 return QDF_STATUS_SUCCESS;
2251}
2252
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002253/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302254 * hdd_start_adapter() - Wrapper function for device specific adapter
2255 * @adapter: pointer to HDD adapter
2256 *
2257 * This function is called to start the device specific adapter for
2258 * the mode passed in the adapter's device_mode.
2259 *
2260 * Return: 0 for success; non-zero for failure
2261 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002262int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302263{
2264
2265 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002266 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302267
Dustin Brownfdf17c12018-03-14 12:55:34 -07002268 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002269 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302270
2271 switch (device_mode) {
2272 case QDF_P2P_CLIENT_MODE:
2273 case QDF_P2P_DEVICE_MODE:
2274 case QDF_OCB_MODE:
2275 case QDF_STA_MODE:
2276 case QDF_MONITOR_MODE:
2277 ret = hdd_start_station_adapter(adapter);
2278 if (ret)
2279 goto err_start_adapter;
2280 break;
2281 case QDF_P2P_GO_MODE:
2282 case QDF_SAP_MODE:
2283 ret = hdd_start_ap_adapter(adapter);
2284 if (ret)
2285 goto err_start_adapter;
2286 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302287 case QDF_IBSS_MODE:
2288 /*
2289 * For IBSS interface is initialized as part of
2290 * hdd_init_station_mode()
2291 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002292 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302293 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002294 /* vdevs are dynamically managed by firmware in FTM */
2295 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302296 default:
2297 hdd_err("Invalid session type %d", device_mode);
2298 QDF_ASSERT(0);
2299 goto err_start_adapter;
2300 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002301
Arun Khandavallifae92942016-08-01 13:31:08 +05302302 if (hdd_set_fw_params(adapter))
2303 hdd_err("Failed to set the FW params for the adapter!");
2304
2305 /*
2306 * Action frame registered in one adapter which will
2307 * applicable to all interfaces
2308 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302309 ret = wlan_hdd_cfg80211_register_frames(adapter);
2310 if (ret < 0) {
2311 hdd_err("Failed to register frames - ret %d", ret);
2312 goto err_start_adapter;
2313 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002314 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302315
Dustin Browndb2a8be2017-12-20 11:49:56 -08002316exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002317 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002318
Arun Khandavallifae92942016-08-01 13:31:08 +05302319 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002320
Arun Khandavallifae92942016-08-01 13:31:08 +05302321err_start_adapter:
2322 return -EINVAL;
2323}
2324
2325/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302326 * hdd_enable_power_management() - API to Enable Power Management
2327 *
2328 * API invokes Bus Interface Layer power management functionality
2329 *
2330 * Return: None
2331 */
2332static void hdd_enable_power_management(void)
2333{
2334 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2335
2336 if (!hif_ctx) {
2337 hdd_err("Bus Interface Context is Invalid");
2338 return;
2339 }
2340
2341 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2342}
2343
2344/**
2345 * hdd_disable_power_management() - API to disable Power Management
2346 *
2347 * API disable Bus Interface Layer Power management functionality
2348 *
2349 * Return: None
2350 */
2351static void hdd_disable_power_management(void)
2352{
2353 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2354
2355 if (!hif_ctx) {
2356 hdd_err("Bus Interface Context is Invalid");
2357 return;
2358 }
2359
2360 hif_disable_power_management(hif_ctx);
2361}
2362
2363/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302364 * hdd_update_hw_sw_info() - API to update the HW/SW information
2365 *
2366 * API to update the HW and SW information in the driver
2367 *
2368 * Return: None
2369 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002370static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302371{
2372 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002373 size_t target_hw_name_len;
2374 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302375
2376 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2377 if (!hif_sc) {
2378 hdd_err("HIF context is NULL");
2379 return;
2380 }
2381
2382 /*
2383 * target hw version/revision would only be retrieved after firmware
2384 * download
2385 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002386 hif_get_hw_info(hif_sc,
2387 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302388 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002389 &target_hw_name);
2390
2391 if (hdd_ctx->target_hw_name)
2392 qdf_mem_free(hdd_ctx->target_hw_name);
2393
2394 target_hw_name_len = strlen(target_hw_name) + 1;
2395 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2396 if (hdd_ctx->target_hw_name)
2397 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2398 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302399
2400 /* Get the wlan hw/fw version */
2401 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302402}
2403
2404/**
gbian62edd7e2017-03-07 13:12:13 +08002405 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2406 * @hdd_ctx: Pointer to hdd context
2407 *
2408 * Return: none
2409 */
2410static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002411hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002412{
2413 uint8_t num_entries = 0;
2414 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2415 uint8_t *tx_sched_wrr_ac;
2416 int i;
2417 cds_context_type *cds_ctx;
2418
2419 if (NULL == hdd_ctx)
2420 return;
2421
2422 if (NULL == hdd_ctx->config) {
2423 /* Do nothing if hdd_ctx is invalid */
2424 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2425 return;
2426 }
2427
2428 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2429
2430 if (!cds_ctx) {
2431 hdd_err("Invalid CDS Context");
2432 return;
2433 }
2434
2435 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2436 switch (i) {
2437 case OL_TX_WMM_AC_BE:
2438 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2439 break;
2440 case OL_TX_WMM_AC_BK:
2441 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2442 break;
2443 case OL_TX_WMM_AC_VI:
2444 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2445 break;
2446 case OL_TX_WMM_AC_VO:
2447 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2448 break;
2449 default:
2450 tx_sched_wrr_ac = NULL;
2451 break;
2452 }
2453
2454 hdd_string_to_u8_array(tx_sched_wrr_ac,
2455 tx_sched_wrr_param,
2456 &num_entries,
2457 sizeof(tx_sched_wrr_param));
2458
2459 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2460 cds_ctx->ac_specs[i].wrr_skip_weight =
2461 tx_sched_wrr_param[0];
2462 cds_ctx->ac_specs[i].credit_threshold =
2463 tx_sched_wrr_param[1];
2464 cds_ctx->ac_specs[i].send_limit =
2465 tx_sched_wrr_param[2];
2466 cds_ctx->ac_specs[i].credit_reserve =
2467 tx_sched_wrr_param[3];
2468 cds_ctx->ac_specs[i].discard_weight =
2469 tx_sched_wrr_param[4];
2470 }
2471
2472 num_entries = 0;
2473 }
2474}
2475
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302476#ifdef IPA_OFFLOAD
2477/**
2478 * hdd_update_ipa_component_config() - update ipa config
2479 * @hdd_ctx: Pointer to hdd context
2480 *
2481 * Return: none
2482 */
2483static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2484{
2485 struct hdd_config *cfg = hdd_ctx->config;
2486 struct wlan_ipa_config ipa_cfg;
2487
2488 ipa_cfg.ipa_config = cfg->IpaConfig;
2489 ipa_cfg.desc_size = cfg->IpaDescSize;
2490 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2491 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2492 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2493 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2494 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2495 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2496 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2497
2498 ucfg_ipa_update_config(&ipa_cfg);
2499}
2500#else
2501static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2502{
2503}
2504#endif
2505
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002506#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002507static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2508 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2509{
Jeff Johnson9d295242017-08-29 14:39:48 -07002510 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002511 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002512
2513 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2514 if (!adapter) {
2515 hdd_err("Adapter is NULL");
2516 return PM_MAX_NUM_OF_MODE;
2517 }
2518
2519 return policy_mgr_convert_device_mode_to_qdf_type(
2520 adapter->device_mode);
2521}
2522
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002523static void hdd_register_policy_manager_callback(
2524 struct wlan_objmgr_psoc *psoc)
2525{
2526 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002527
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002528 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002529 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002530 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2531 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002532 hdd_cbacks.get_mode_for_non_connected_vdev =
2533 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302534 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002535
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002536 if (QDF_STATUS_SUCCESS !=
2537 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2538 hdd_err("HDD callback registration with policy manager failed");
2539 }
2540}
2541#else
2542static void hdd_register_policy_manager_callback(
2543 struct wlan_objmgr_psoc *psoc)
2544{
2545}
2546#endif
2547
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002548static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002549{
2550 struct nan_callbacks cb_obj = {0};
2551
2552 cb_obj.ndi_open = hdd_ndi_open;
2553 cb_obj.ndi_close = hdd_ndi_close;
2554 cb_obj.ndi_start = hdd_ndi_start;
2555 cb_obj.ndi_delete = hdd_ndi_delete;
2556 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2557 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2558
Naveen Rawat37f62c82017-03-26 22:24:43 -07002559 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2560 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002561 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002562
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002563 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2564}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002565
Dustin Brown26b3d042017-12-21 11:13:27 -08002566#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002567/**
2568 * hdd_check_for_leaks() - Perform runtime memory leak checks
2569 *
2570 * This API triggers runtime memory leak detection. This feature enforces the
2571 * policy that any memory allocated at runtime must also be released at runtime.
2572 *
2573 * Allocating memory at runtime and releasing it at unload is effectively a
2574 * memory leak for configurations which never unload (e.g. LONU, statically
2575 * compiled driver). Such memory leaks are NOT false positives, and must be
2576 * fixed.
2577 *
2578 * Return: None
2579 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002580static void hdd_check_for_leaks(void)
2581{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002582 /* DO NOT REMOVE these checks; for false positives, read above first */
2583
Dustin Brown677e0862017-10-10 16:30:09 -07002584 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002585 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002586 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002587}
2588
Dustin Brown26b3d042017-12-21 11:13:27 -08002589#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2590#else
2591static inline void hdd_check_for_leaks(void) {}
2592
2593#define hdd_debug_domain_set(domain)
2594#endif /* CONFIG_LEAK_DETECTION */
2595
gbian62edd7e2017-03-07 13:12:13 +08002596/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002597 * hdd_update_country_code - Update country code
2598 * @hdd_ctx: HDD context
2599 *
2600 * Update country code based on module parameter country_code
2601 *
2602 * Return: 0 on success and errno on failure
2603 */
2604static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2605{
2606 if (!country_code)
2607 return 0;
2608
2609 return hdd_reg_set_country(hdd_ctx, country_code);
2610}
2611
2612/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302613 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2614 * @hdd_ctx: HDD context
2615 * @adapter: HDD adapter
2616 * @reinit: flag to indicate from SSR or normal path
2617 *
2618 * This function maintains the driver state machine it will be invoked from
2619 * startup, reinit and change interface. Depending on the driver state shall
2620 * perform the opening of the modules.
2621 *
2622 * Return: 0 for success; non-zero for failure
2623 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002624int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2625 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302626 bool reinit)
2627{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002628 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302629 qdf_device_t qdf_dev;
2630 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302631 bool unint = false;
2632 void *hif_ctx;
2633
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002634 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302635
2636 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2637 if (!qdf_dev) {
2638 hdd_err("QDF Device Context is Invalid return");
2639 return -EINVAL;
2640 }
2641
Dustin Brown6f427922017-09-19 12:19:00 -07002642 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302643
Dustin Brown1fe30a82017-10-03 16:13:36 -07002644 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302645 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2646 mutex_unlock(&hdd_ctx->iface_change_lock);
2647 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002648 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302649 return 0;
2650 }
2651
Dustin Brown1fe30a82017-10-03 16:13:36 -07002652 hdd_ctx->start_modules_in_progress = true;
2653
Arun Khandavallifae92942016-08-01 13:31:08 +05302654 switch (hdd_ctx->driver_status) {
2655 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002656 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302657 unint = true;
2658 /* Fall through dont add break here */
2659 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002660 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2661
Dustin Brown26b3d042017-12-21 11:13:27 -08002662 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002663
Arun Khandavallifae92942016-08-01 13:31:08 +05302664 if (!reinit && !unint) {
2665 ret = pld_power_on(qdf_dev->dev);
2666 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002667 hdd_err("Failed to Powerup the device; errno: %d",
2668 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302669 goto release_lock;
2670 }
2671 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002672
2673 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2674 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302675 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2676 qdf_dev->bus_type,
2677 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2678 HIF_ENABLE_TYPE_PROBE);
2679 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002680 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302681 goto power_down;
2682 }
2683
2684 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302685 if (!hif_ctx) {
2686 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002687 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302688 goto power_down;
2689 }
2690
Arun Khandavallifae92942016-08-01 13:31:08 +05302691 status = ol_cds_init(qdf_dev, hif_ctx);
2692 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002693 hdd_err("No Memory to Create BMI Context; status: %d",
2694 status);
2695 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302696 goto hif_close;
2697 }
2698
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302699 hdd_update_ipa_component_config(hdd_ctx);
2700
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002701 ret = hdd_update_config(hdd_ctx);
2702 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002703 hdd_err("Failed to update configuration; errno: %d",
2704 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002705 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002706 }
2707
gbian62edd7e2017-03-07 13:12:13 +08002708 hdd_update_cds_ac_specs_params(hdd_ctx);
2709
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302710 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002711 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002712 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002713 ret = qdf_status_to_os_return(status);
2714 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302715 }
2716
Mukul Sharma9d797a02017-01-05 20:26:03 +05302717 /* initalize components configurations after psoc open */
2718 ret = hdd_update_components_config(hdd_ctx);
2719 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002720 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302721 ret);
2722 goto close;
2723 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002724 status = cds_dp_open(hdd_ctx->hdd_psoc);
2725 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002726 hdd_err("Failed to Open cds post open; status: %d",
2727 status);
2728 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002729 goto close;
2730 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302731
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002732 /*
2733 * NAN compoenet requires certian operations like, open adapter,
2734 * close adapter, etc. to be initiated by HDD, for those
2735 * register HDD callbacks with UMAC's NAN componenet.
2736 */
2737 hdd_nan_register_callbacks(hdd_ctx);
2738
Arun Khandavallifae92942016-08-01 13:31:08 +05302739 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2740
Jeff Johnson3a280122017-09-13 07:42:00 -07002741 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302742 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002743 hdd_err("Failed to pre-enable CDS; status: %d", status);
2744 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002745 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302746 }
2747
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002748 hdd_register_policy_manager_callback(
2749 hdd_ctx->hdd_psoc);
2750
Amar Singhal0928b192017-12-01 10:50:54 -08002751 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2752
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302753 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302754 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002755 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302756
Arun Khandavallifae92942016-08-01 13:31:08 +05302757 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002758 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302759 break;
2760 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302761
Arun Khandavallifae92942016-08-01 13:31:08 +05302762 /* Fall through dont add break here */
2763 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002764 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2765
Arun Khandavallifae92942016-08-01 13:31:08 +05302766 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002767 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002768 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002769 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302770 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302771 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2772 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002773 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302774 break;
2775 }
Dustin Browndca39692017-11-09 15:30:25 -08002776
2777 ret = hdd_configure_cds(hdd_ctx, adapter);
2778 if (ret) {
2779 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002780 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302781 }
Dustin Browndca39692017-11-09 15:30:25 -08002782
Komal Seelamf2136bb2016-09-28 18:30:44 +05302783 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002784
Arun Khandavallifae92942016-08-01 13:31:08 +05302785 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002786 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302787 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002788
Arun Khandavallifae92942016-08-01 13:31:08 +05302789 default:
2790 hdd_err("WLAN start invoked in wrong state! :%d\n",
2791 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002792 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302793 goto release_lock;
2794 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002795
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302796 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002797 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2798 ret = hdd_update_country_code(hdd_ctx);
2799 if (ret)
2800 hdd_err("Failed to update command line country code!");
2801 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302802 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002803
Dustin Browne74003f2018-03-14 12:51:58 -07002804 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002805
Arun Khandavallifae92942016-08-01 13:31:08 +05302806 return 0;
2807
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002808post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002809 cds_post_disable();
Amar Singhal410675c2018-01-10 12:14:21 -08002810 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Dustin Brownbd68fe12017-11-21 15:28:52 -08002811 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002812
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002813cds_txrx_free:
2814 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002815
Arun Khandavallifae92942016-08-01 13:31:08 +05302816close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002817 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002818 hdd_info("Wlan transition aborted (now CLOSED)");
2819
Jeff Johnsone4b14592017-09-13 14:23:33 -07002820 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302821
Dustin Brown28b17892017-10-10 13:29:38 -07002822deinit_config:
2823 cds_deinit_ini_config();
2824
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002825cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302826 ol_cds_free();
2827
2828hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002829 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2830 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302831power_down:
2832 if (!reinit && !unint)
2833 pld_power_off(qdf_dev->dev);
2834release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302835 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302836 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002837
2838 /* many adapter resources are not freed by design in SSR case */
2839 if (!reinit)
2840 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002841 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002842
Dustin Browne74003f2018-03-14 12:51:58 -07002843 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002844
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002845 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302846}
2847
Naveen Rawat910726a2017-03-06 11:42:51 -08002848#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002849static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002850{
2851 int ret = os_if_wifi_pos_register_nl();
2852
2853 if (ret)
2854 hdd_err("os_if_wifi_pos_register_nl failed");
2855
2856 return ret;
2857}
2858
2859static int hdd_deactivate_wifi_pos(void)
2860{
2861 int ret = os_if_wifi_pos_deregister_nl();
2862
2863 if (ret)
2864 hdd_err("os_if_wifi_pos_deregister_nl failed");
2865
2866 return ret;
2867}
2868
2869/**
2870 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2871 * @hdd_ctx: hdd context
2872 *
2873 * Return: status of operation
2874 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002875static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002876{
2877 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2878 struct hdd_config *cfg = hdd_ctx->config;
2879
2880 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2881 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2882 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2883 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2884 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2885 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2886 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2887 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2888}
2889#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002890static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002891{
2892 return oem_activate_service(hdd_ctx);
2893}
2894
2895static int hdd_deactivate_wifi_pos(void)
2896{
2897 return 0;
2898}
2899
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002900static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002901{
2902}
2903#endif
2904
Arun Khandavallifae92942016-08-01 13:31:08 +05302905/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002906 * __hdd_open() - HDD Open function
2907 * @dev: Pointer to net_device structure
2908 *
2909 * This is called in response to ifconfig up
2910 *
2911 * Return: 0 for success; non-zero for failure
2912 */
2913static int __hdd_open(struct net_device *dev)
2914{
Jeff Johnson9d295242017-08-29 14:39:48 -07002915 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002916 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002917 int ret;
2918
Dustin Brownfdf17c12018-03-14 12:55:34 -07002919 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302920 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002921 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302923 /* Nothing to be done if device is unloading */
2924 if (cds_is_driver_unloading()) {
2925 hdd_err("Driver is unloading can not open the hdd");
2926 return -EBUSY;
2927 }
2928
Dustin Brown01847752017-10-25 13:56:27 -07002929 if (cds_is_driver_recovering()) {
2930 hdd_err("WLAN is currently recovering; Please try again.");
2931 return -EBUSY;
2932 }
2933
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302934 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2935 hdd_err("con_mode_handler is in progress; Please try again.");
2936 return -EBUSY;
2937 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302938
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302939 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302940 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2941
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302942 /*
2943 * This scenario can be hit in cases where in the wlan driver after
2944 * registering the netdevices and there is a failure in driver
2945 * initialization. So return error gracefully because the netdevices
2946 * will be de-registered as part of the load failure.
2947 */
2948
2949 if (!cds_is_driver_loaded()) {
2950 hdd_err("Failed to start the wlan driver!!");
2951 ret = -EIO;
2952 goto err_hdd_hdd_init_deinit_lock;
2953 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302954
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002955
Arun Khandavallifae92942016-08-01 13:31:08 +05302956 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2957 if (ret) {
2958 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302959 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302960 }
2961
2962
2963 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2964 ret = hdd_start_adapter(adapter);
2965 if (ret) {
2966 hdd_err("Failed to start adapter :%d",
2967 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302968 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302969 }
2970 }
2971
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002972 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2973 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002974 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002975 /* Enable TX queues only when we are connected */
2976 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302977 WLAN_START_ALL_NETIF_QUEUE,
2978 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002979 }
2980
Naveen Rawat286def52016-09-23 15:38:02 -07002981 /* Enable carrier and transmit queues for NDI */
2982 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002983 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002984 wlan_hdd_netif_queue_control(adapter,
2985 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2986 WLAN_CONTROL_PATH);
2987 }
2988
Naveen Rawat910726a2017-03-06 11:42:51 -08002989 hdd_populate_wifi_pos_cfg(hdd_ctx);
2990
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302991err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302992 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302993 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002994 return ret;
2995}
2996
Arun Khandavallifae92942016-08-01 13:31:08 +05302997
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002998/**
2999 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3000 * @dev: Pointer to net_device structure
3001 *
3002 * This is called in response to ifconfig up
3003 *
3004 * Return: 0 for success; non-zero for failure
3005 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003006static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003007{
3008 int ret;
3009
3010 cds_ssr_protect(__func__);
3011 ret = __hdd_open(dev);
3012 cds_ssr_unprotect(__func__);
3013
3014 return ret;
3015}
3016
3017/**
3018 * __hdd_stop() - HDD stop function
3019 * @dev: Pointer to net_device structure
3020 *
3021 * This is called in response to ifconfig down
3022 *
3023 * Return: 0 for success; non-zero for failure
3024 */
3025static int __hdd_stop(struct net_device *dev)
3026{
Jeff Johnson9d295242017-08-29 14:39:48 -07003027 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003028 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 int ret;
3030
Dustin Brownfdf17c12018-03-14 12:55:34 -07003031 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003032
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303033 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003034 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003035
3036 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303037 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003038 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003039
3040 /* Nothing to be done if the interface is not opened */
3041 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003042 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003043 return -ENODEV;
3044 }
3045
3046 /* Make sure the interface is marked as closed */
3047 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303048
3049 hdd_debug("Disabling Auto Power save timer");
3050 sme_ps_disable_auto_ps_timer(
3051 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07003052 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303053
3054 /*
3055 * Disable TX on the interface, after this hard_start_xmit() will not
3056 * be called on that interface
3057 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003058 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003059 hdd_device_mode_to_string(adapter->device_mode),
3060 adapter->device_mode);
3061
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303062 wlan_hdd_netif_queue_control(adapter,
3063 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3064 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003065
3066 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003067 * NAN data interface is different in some sense. The traffic on NDI is
3068 * bursty in nature and depends on the need to transfer. The service
3069 * layer may down the interface after the usage and up again when
3070 * required. In some sense, the NDI is expected to be available
3071 * (like SAP) iface until NDI delete request is issued by the service
3072 * layer. Skip BSS termination and adapter deletion for NAN Data
3073 * interface (NDI).
3074 */
3075 if (WLAN_HDD_IS_NDI(adapter))
3076 return 0;
3077
3078 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003079 * The interface is marked as down for outside world (aka kernel)
3080 * But the driver is pretty much alive inside. The driver needs to
3081 * tear down the existing connection on the netdev (session)
3082 * cleanup the data pipes and wait until the control plane is stabilized
3083 * for this interface. The call also needs to wait until the above
3084 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003085 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003086 * That is intentional to be able to scan if it is a STA/P2P interface
3087 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003088 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003089
3090 /* DeInit the adapter. This ensures datapath cleanup as well */
3091 hdd_deinit_adapter(hdd_ctx, adapter, true);
3092
Arun Khandavallifae92942016-08-01 13:31:08 +05303093
3094 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303095 * Upon wifi turn off, DUT has to flush the scan results so if
3096 * this is the last cli iface, flush the scan database.
3097 */
3098 if (!hdd_is_cli_iface_up(hdd_ctx))
3099 sme_scan_flush_result(hdd_ctx->hHal);
3100
3101 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303102 * Find if any iface is up. If any iface is up then can't put device to
3103 * sleep/power save mode
3104 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303105 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003106 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003107 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3108 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303109 hdd_prevent_suspend_timeout(
3110 hdd_ctx->config->iface_change_wait_time,
3111 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303112 }
3113
Dustin Browne74003f2018-03-14 12:51:58 -07003114 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003115 return 0;
3116}
3117
3118/**
3119 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3120 * @dev: pointer to net_device structure
3121 *
3122 * This is called in response to ifconfig down
3123 *
3124 * Return: 0 for success and error number for failure
3125 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003126static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127{
3128 int ret;
3129
3130 cds_ssr_protect(__func__);
3131 ret = __hdd_stop(dev);
3132 cds_ssr_unprotect(__func__);
3133
3134 return ret;
3135}
3136
3137/**
3138 * __hdd_uninit() - HDD uninit function
3139 * @dev: Pointer to net_device structure
3140 *
3141 * This is called during the netdev unregister to uninitialize all data
3142 * associated with the device
3143 *
3144 * Return: None
3145 */
3146static void __hdd_uninit(struct net_device *dev)
3147{
Jeff Johnson9d295242017-08-29 14:39:48 -07003148 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003149 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150
Dustin Brownfdf17c12018-03-14 12:55:34 -07003151 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152
3153 do {
3154 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003155 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003156 break;
3157 }
3158
Jeff Johnson399c6272017-08-30 10:51:00 -07003159 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3160 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003161 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003162 break;
3163 }
3164
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003165 if (dev != adapter->dev)
3166 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003167
Jeff Johnson399c6272017-08-30 10:51:00 -07003168 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169
3170 /* after uninit our adapter structure will no longer be valid */
3171 adapter->dev = NULL;
3172 adapter->magic = 0;
3173 } while (0);
3174
Dustin Browne74003f2018-03-14 12:51:58 -07003175 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003176}
3177
3178/**
3179 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3180 * @dev: pointer to net_device structure
3181 *
3182 * This is called during the netdev unregister to uninitialize all data
3183 * associated with the device
3184 *
3185 * Return: none
3186 */
3187static void hdd_uninit(struct net_device *dev)
3188{
3189 cds_ssr_protect(__func__);
3190 __hdd_uninit(dev);
3191 cds_ssr_unprotect(__func__);
3192}
3193
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003194static int hdd_open_cesium_nl_sock(void)
3195{
3196#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3197 struct netlink_kernel_cfg cfg = {
3198 .groups = WLAN_NLINK_MCAST_GRP_ID,
3199 .input = NULL
3200 };
3201#endif
3202 int ret = 0;
3203
3204#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3205 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3206#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3207 THIS_MODULE,
3208#endif
3209 &cfg);
3210#else
3211 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3212 WLAN_NLINK_MCAST_GRP_ID,
3213 NULL, NULL, THIS_MODULE);
3214#endif
3215
3216 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003217 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003218 ret = -ECONNREFUSED;
3219 }
3220
3221 return ret;
3222}
3223
3224static void hdd_close_cesium_nl_sock(void)
3225{
3226 if (NULL != cesium_nl_srv_sock) {
3227 netlink_kernel_release(cesium_nl_srv_sock);
3228 cesium_nl_srv_sock = NULL;
3229 }
3230}
3231
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003232/**
3233 * __hdd_set_mac_address() - set the user specified mac address
3234 * @dev: Pointer to the net device.
3235 * @addr: Pointer to the sockaddr.
3236 *
3237 * This function sets the user specified mac address using
3238 * the command ifconfig wlanX hw ether <mac adress>.
3239 *
3240 * Return: 0 for success, non zero for failure
3241 */
3242static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3243{
Jeff Johnson9d295242017-08-29 14:39:48 -07003244 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003245 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003246 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303247 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303249 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250
Dustin Brownfdf17c12018-03-14 12:55:34 -07003251 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003252
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303253 if (netif_running(dev)) {
3254 hdd_err("On iface up, set mac address change isn't supported");
3255 return -EBUSY;
3256 }
3257
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003258 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3259 ret = wlan_hdd_validate_context(hdd_ctx);
3260 if (0 != ret)
3261 return ret;
3262
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303263 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
3264
3265 if (qdf_is_macaddr_zero(&mac_addr)) {
3266 hdd_err("MAC is all zero");
3267 return -EINVAL;
3268 }
3269
3270 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3271 hdd_err("MAC is Broadcast");
3272 return -EINVAL;
3273 }
3274
3275 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3276 hdd_err("MAC is Multicast");
3277 return -EINVAL;
3278 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303279 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3280 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303281
Jeff Johnson1e851a12017-10-28 14:36:12 -07003282 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3284
Dustin Browne74003f2018-03-14 12:51:58 -07003285 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303286 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003287}
3288
3289/**
3290 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3291 * function from SSR
3292 * @dev: pointer to net_device structure
3293 * @addr: Pointer to the sockaddr
3294 *
3295 * This function sets the user specified mac address using
3296 * the command ifconfig wlanX hw ether <mac adress>.
3297 *
3298 * Return: 0 for success.
3299 */
3300static int hdd_set_mac_address(struct net_device *dev, void *addr)
3301{
3302 int ret;
3303
3304 cds_ssr_protect(__func__);
3305 ret = __hdd_set_mac_address(dev, addr);
3306 cds_ssr_unprotect(__func__);
3307
3308 return ret;
3309}
3310
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003311uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312{
3313 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003314
Anurag Chouhan6d760662016-02-20 16:05:43 +05303315 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3317 break;
3318 }
3319
Anurag Chouhan6d760662016-02-20 16:05:43 +05303320 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003321 return NULL;
3322
3323 hdd_ctx->config->intfAddrMask |= (1 << i);
3324 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3325}
3326
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003327void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3328 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003329{
3330 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003331
Anurag Chouhan6d760662016-02-20 16:05:43 +05303332 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003333 if (!memcmp(releaseAddr,
3334 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3335 6)) {
3336 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3337 break;
3338 }
3339 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003340}
3341
3342#ifdef WLAN_FEATURE_PACKET_FILTERING
3343/**
3344 * __hdd_set_multicast_list() - set the multicast address list
3345 * @dev: Pointer to the WLAN device.
3346 * @skb: Pointer to OS packet (sk_buff).
3347 *
3348 * This funciton sets the multicast address list.
3349 *
3350 * Return: None
3351 */
3352static void __hdd_set_multicast_list(struct net_device *dev)
3353{
Jeff Johnson9d295242017-08-29 14:39:48 -07003354 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355 int i = 0, status;
3356 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003357 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303358 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3359 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3360 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361
Dustin Brownfdf17c12018-03-14 12:55:34 -07003362 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303363 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303364 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303365
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303367 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303368 goto out;
3369
Dustin Brownc788acb2017-08-01 17:43:51 -07003370 status = hdd_validate_adapter(adapter);
3371 if (status)
3372 goto out;
3373
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303374 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3375 hdd_err("%s: Driver module is closed", __func__);
3376 return;
3377 }
3378
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303379 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3380 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003381 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303382 goto out;
3383 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003384
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303385 /* Delete already configured multicast address list */
3386 if (adapter->mc_addr_list.mc_cnt > 0) {
3387 hdd_info("clear previously configured MC address list");
3388 hdd_disable_and_flush_mc_addr_list(adapter,
3389 pmo_mc_list_change_notify);
3390 }
3391
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003392 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003393 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303394 hdd_disable_and_flush_mc_addr_list(adapter,
3395 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396 } else {
3397 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303398 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003399 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303400 pmo_ucfg_max_mc_addr_supported(psoc));
3401 hdd_disable_and_flush_mc_addr_list(adapter,
3402 pmo_mc_list_change_notify);
3403 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003406 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303407 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408 if (i == mc_count)
3409 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303410 memset(&(mc_list_request->mc_addr[i].bytes),
3411 0, ETH_ALEN);
3412 memcpy(&(mc_list_request->mc_addr[i].bytes),
3413 ha->addr, ETH_ALEN);
3414 hdd_info("mlist[%d] = %pM", i,
3415 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 i++;
3417 }
3418 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303419
3420 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003421 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303422 mc_list_request->count = mc_count;
3423 status = hdd_cache_mc_addr_list(mc_list_request);
3424 if (status == 0) {
3425 hdd_enable_mc_addr_filtering(adapter,
3426 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003427 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303428 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303430out:
3431 if (mc_list_request)
3432 qdf_mem_free(mc_list_request);
Dustin Browne74003f2018-03-14 12:51:58 -07003433 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434}
3435
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437/**
3438 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3439 * @dev: pointer to net_device
3440 *
3441 * Return: none
3442 */
3443static void hdd_set_multicast_list(struct net_device *dev)
3444{
3445 cds_ssr_protect(__func__);
3446 __hdd_set_multicast_list(dev);
3447 cds_ssr_unprotect(__func__);
3448}
3449#endif
3450
3451/**
3452 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3453 * @dev: Pointer to the WLAN device.
3454 * @skb: Pointer to OS packet (sk_buff).
3455 *
3456 * This function is registered with the Linux OS for network
3457 * core to decide which queue to use first.
3458 *
3459 * Return: ac, Queue Index/access category corresponding to UP in IP header
3460 */
3461static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3462#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3463 , void *accel_priv
3464#endif
3465#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3466 , select_queue_fallback_t fallback
3467#endif
3468)
3469{
3470 return hdd_wmm_select_queue(dev, skb);
3471}
3472
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003473static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474 .ndo_open = hdd_open,
3475 .ndo_stop = hdd_stop,
3476 .ndo_uninit = hdd_uninit,
3477 .ndo_start_xmit = hdd_hard_start_xmit,
3478 .ndo_tx_timeout = hdd_tx_timeout,
3479 .ndo_get_stats = hdd_get_stats,
3480 .ndo_do_ioctl = hdd_ioctl,
3481 .ndo_set_mac_address = hdd_set_mac_address,
3482 .ndo_select_queue = hdd_select_queue,
3483#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003484 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485#endif
3486};
3487
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003488/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003489static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003490 .ndo_open = hdd_mon_open,
3491 .ndo_stop = hdd_stop,
3492 .ndo_get_stats = hdd_get_stats,
3493};
3494
3495/**
3496 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003497 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003498 * Return: None
3499 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003500void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003502 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003503 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003504 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003505 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003506}
3507
3508/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003509 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3510 * @hdd_ctx: global hdd context
3511 * @macAddr: mac address to assign to the interface
3512 * @name: User-visible name of the interface
3513 *
3514 * hdd adapter pointer would point to the netdev->priv space, this function
3515 * would retrive the pointer, and setup the hdd adapter configuration.
3516 *
3517 * Return: the pointer to hdd adapter, otherwise NULL
3518 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003519static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003521 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522 const char *name)
3523{
Jeff Johnson5505db82017-11-02 21:19:23 -07003524 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003525 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003526 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303527 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528 /*
3529 * cfg80211 initialization and registration....
3530 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003531 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003532#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3533 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003534#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003535 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3536 hdd_mon_mode_ether_setup : ether_setup),
3537 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538
Jeff Johnson5505db82017-11-02 21:19:23 -07003539 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540
3541 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003542 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543
Jeff Johnson9d295242017-08-29 14:39:48 -07003544 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003545 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303546 qdf_mem_set(sta_ctx->conn_info.staId,
3547 sizeof(sta_ctx->conn_info.staId),
3548 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003549 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003550 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003551 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003552 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303554 qdf_status = qdf_event_create(
3555 &adapter->qdf_session_open_event);
3556 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3557 hdd_err("Session open QDF event init failed!");
3558 free_netdev(adapter->dev);
3559 return NULL;
3560 }
3561
3562 qdf_status = qdf_event_create(
3563 &adapter->qdf_session_close_event);
3564 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3565 hdd_err("Session close QDF event init failed!");
3566 free_netdev(adapter->dev);
3567 return NULL;
3568 }
3569
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003570 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303571 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003572 init_completion(&adapter->linkup_event_var);
3573 init_completion(&adapter->cancel_rem_on_chan_var);
3574 init_completion(&adapter->rem_on_chan_ready_event);
3575 init_completion(&adapter->sta_authorized_event);
3576 init_completion(&adapter->offchannel_tx_event);
3577 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003578 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303579 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580
3581 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003582 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303583 adapter->disconnection_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003585 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003586
Jeff Johnson5505db82017-11-02 21:19:23 -07003587 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003589 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003591 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592
3593 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003594 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003596 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003597
Jeff Johnson5505db82017-11-02 21:19:23 -07003598 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003599
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 hdd_set_station_ops(adapter->dev);
3601
Jeff Johnson5505db82017-11-02 21:19:23 -07003602 hdd_dev_setup_destructor(dev);
3603 dev->ieee80211_ptr = &adapter->wdev;
3604 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003606 adapter->wdev.netdev = dev;
3607 /* set dev's parent to underlying device */
3608 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609 hdd_wmm_init(adapter);
3610 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303611 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003612 }
3613
3614 return adapter;
3615}
3616
Jeff Johnson9d295242017-08-29 14:39:48 -07003617static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003619 struct net_device *dev = adapter->dev;
3620 int ret;
3621
Dustin Brown491d54b2018-03-14 12:39:11 -07003622 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003623
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003624 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003625 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3626
3627 ret = dev_alloc_name(dev, dev->name);
3628 if (ret < 0) {
3629 hdd_err(
3630 "unable to get dev name: %s, err = 0x%x",
3631 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303632 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003633 }
3634 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003635
3636 ret = register_netdevice(dev);
3637 if (ret) {
3638 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3639 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303640 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 }
3642 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003643 ret = register_netdev(dev);
3644 if (ret) {
3645 hdd_err("register_netdev(%s) failed, err = 0x%x",
3646 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303647 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003648 }
3649 }
3650 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3651
Dustin Browne74003f2018-03-14 12:51:58 -07003652 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003653
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303654 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655}
3656
Krunal Sonib51eec72017-11-20 21:53:01 -08003657QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003658{
Krunal Sonib51eec72017-11-20 21:53:01 -08003659 struct hdd_adapter *adapter;
3660 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661
Krunal Sonib51eec72017-11-20 21:53:01 -08003662 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3663 if (!hdd_ctx) {
3664 hdd_err("Invalid HDD_CTX");
3665 return QDF_STATUS_E_FAILURE;
3666 }
3667
3668 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3669 if (NULL == adapter) {
3670 hdd_err("NULL adapter");
3671 return QDF_STATUS_E_INVAL;
3672 }
3673 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303674 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003675 hdd_debug("session %d opened", adapter->session_id);
3676
3677 return QDF_STATUS_SUCCESS;
3678}
3679
3680QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3681{
3682 struct hdd_adapter *adapter;
3683 struct hdd_context *hdd_ctx;
3684
3685 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3686 if (!hdd_ctx) {
3687 hdd_err("Invalid HDD_CTX");
3688 return QDF_STATUS_E_FAILURE;
3689 }
3690
3691 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003693 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303694 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003695 }
3696
3697 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003698 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303699 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700 }
3701
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003702 /*
3703 * For NAN Data interface, the close session results in the final
3704 * indication to the userspace
3705 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003706 if (adapter->device_mode == QDF_NDI_MODE)
3707 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003708
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3710
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003711 /*
3712 * We can be blocked while waiting for scheduled work to be
3713 * flushed, and the adapter structure can potentially be freed, in
3714 * which case the magic will have been reset. So make sure the
3715 * magic is still good, and hence the adapter structure is still
3716 * valid, before signaling completion
3717 */
3718 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303719 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003720
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303721 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003722}
3723
Jeff Johnson9d295242017-08-29 14:39:48 -07003724int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003725{
Dustin Brownd28772b2017-03-17 14:16:07 -07003726 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003727
Dustin Brownd28772b2017-03-17 14:16:07 -07003728 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003729 if (QDF_IS_STATUS_ERROR(status))
3730 return qdf_status_to_os_return(status);
3731
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003732 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003733 if (QDF_IS_STATUS_ERROR(status))
3734 return qdf_status_to_os_return(status);
3735
3736 if (wma_capability_enhanced_mcast_filter())
3737 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3738 else
3739 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003740
3741 return qdf_status_to_os_return(status);
3742}
3743
Jeff Johnson9d295242017-08-29 14:39:48 -07003744int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003745{
3746 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003747 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003748 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003749 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003750
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003751 vdev_id = adapter->session_id;
3752 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003753
3754 /* vdev created sanity check */
3755 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003756 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003757 return -EINVAL;
3758 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003759 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003760
Dustin Brownd28772b2017-03-17 14:16:07 -07003761 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303762 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003763 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003764 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003765 if (QDF_IS_STATUS_ERROR(status)) {
3766 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003767 errno = qdf_status_to_os_return(status);
3768 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003769 }
3770
3771 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303772 status = qdf_wait_for_event_completion(
3773 &adapter->qdf_session_close_event,
3774 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3775 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003776 if (adapter->device_mode == QDF_NDI_MODE)
3777 hdd_ndp_session_end_handler(adapter);
3778 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303779 adapter->session_id = HDD_SESSION_ID_INVALID;
3780 if (QDF_STATUS_E_TIMEOUT != status) {
3781 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003782 errno = -ETIMEDOUT;
3783 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303784 } else if (adapter->qdf_session_close_event.force_set) {
3785 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003786 errno = -EINVAL;
3787 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303788 } else {
3789 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003790 errno = -EINVAL;
3791 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303792 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003793 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003794
Yue Maf9782842017-05-08 12:49:49 -07003795release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003796 /*
3797 * In SSR or driver unloading case, directly exit may cause objects
3798 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003799 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003800 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003801 return errno;
3802
Sandeep Puligillaef415362017-08-30 16:37:13 -07003803 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003804 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003805 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003806 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003807 return errno;
3808 }
3809
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003810 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003811
3812 return 0;
3813}
3814
Krunal Sonib51eec72017-11-20 21:53:01 -08003815static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3816 struct sme_session_params *session_param,
3817 csr_roam_completeCallback callback,
3818 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003819{
Dustin Brownd28772b2017-03-17 14:16:07 -07003820 uint32_t type;
3821 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003822 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003823
3824 /* determine vdev (sub)type */
3825 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303826 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003827 hdd_err("failed to get vdev type: %d", status);
3828 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003829 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003830 session_param->sme_session_id = adapter->session_id;
3831 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3832 session_param->type_of_persona = type;
3833 session_param->subtype_of_persona = sub_type;
3834 session_param->session_open_cb = hdd_sme_open_session_callback;
3835 session_param->session_close_cb = hdd_sme_close_session_callback;
3836 session_param->callback = callback;
3837 session_param->callback_ctx = callback_ctx;
3838
3839 return 0;
3840}
3841
3842int hdd_vdev_create(struct hdd_adapter *adapter,
3843 csr_roam_completeCallback callback, void *ctx)
3844{
3845 QDF_STATUS status;
3846 int errno;
3847 struct hdd_context *hdd_ctx;
3848 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003849
3850 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003851
3852 /* do vdev create via objmgr */
3853 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003854 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003855 if (errno) {
3856 hdd_err("failed to create objmgr vdev: %d", errno);
3857 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003859
3860 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303861 status = qdf_event_reset(&adapter->qdf_session_open_event);
3862 if (QDF_STATUS_SUCCESS != status) {
3863 hdd_err("failed to reinit session open event");
3864 return -EINVAL;
3865 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003866 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3867 callback, ctx);
3868 if (errno) {
3869 hdd_err("failed to populating SME params");
3870 goto objmgr_vdev_destroy_procedure;
3871 }
3872
3873 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003874 if (QDF_IS_STATUS_ERROR(status)) {
3875 hdd_err("failed to open sme session: %d", status);
3876 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003877 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003878 }
3879
3880 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303881 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3882 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3883 if (QDF_STATUS_SUCCESS != status) {
3884 if (adapter->qdf_session_open_event.force_set) {
3885 /*
3886 * SSR/PDR has caused shutdown, which has forcefully
3887 * set the event. Return without the closing session.
3888 */
3889 adapter->session_id = HDD_SESSION_ID_INVALID;
3890 hdd_err("Session open event forcefully set");
3891 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303892 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003893
3894 if (QDF_STATUS_E_TIMEOUT == status)
3895 hdd_err("Session failed to open within timeout period");
3896 else
3897 hdd_err("Failed to wait for session open event(status-%d)",
3898 status);
3899 errno = -ETIMEDOUT;
3900 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3901 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003902 }
3903
3904 /* firmware ready for component communication, raise vdev_ready event */
3905 errno = hdd_vdev_ready(adapter);
3906 if (errno) {
3907 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003908 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003909 }
3910
Naveen Rawat2b430892018-03-13 13:58:18 -07003911 if (adapter->device_mode == QDF_STA_MODE) {
3912 hdd_debug("setting RTT mac randomization param: %d",
3913 hdd_ctx->config->enable_rtt_mac_randomization);
3914 errno = sme_cli_set_command(adapter->session_id,
3915 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
3916 hdd_ctx->config->enable_rtt_mac_randomization,
3917 VDEV_CMD);
3918 if (0 != errno)
3919 hdd_err("RTT mac randomization param set failed %d",
3920 errno);
3921 }
3922
Jeff Johnson1b780e42017-10-31 14:11:45 -07003923 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003924
3925 return 0;
3926
3927 /*
3928 * Due to legacy constraints, we need to destroy in the same order as
3929 * create. So, split error handling into 2 cases to accommodate.
3930 */
3931
Krunal Soni4a020c72017-10-30 20:58:40 -07003932objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003933 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003934
3935 return errno;
3936
Krunal Soni4a020c72017-10-30 20:58:40 -07003937hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003938 QDF_BUG(!hdd_vdev_destroy(adapter));
3939
3940 return errno;
3941}
3942
Jeff Johnson9d295242017-08-29 14:39:48 -07003943QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003944{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003945 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003946 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003947 QDF_STATUS status;
3948 int ret_val;
3949
Dustin Brownd28772b2017-03-17 14:16:07 -07003950 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3951 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3952 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003953 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003954
Jeff Johnson7f2c5912018-03-23 11:42:28 -07003955 hdd_roam_profile_init(adapter);
3956 hdd_register_wext(adapter->dev);
3957
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003958 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003959
Jeff Johnsond377dce2017-10-04 10:32:42 -07003960 qdf_mem_set(sta_ctx->conn_info.staId,
3961 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303962
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003963 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003964 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303965 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003967 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968 hdd_ctx->config->OperatingChannel;
3969
3970 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003971 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972
3973 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303974 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003975 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976 status, status);
3977 goto error_init_txrx;
3978 }
3979
3980 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3981
3982 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303983 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003984 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985 status, status);
3986 goto error_wmm_init;
3987 }
3988
3989 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3990
Jeff Johnson1b780e42017-10-31 14:11:45 -07003991 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992 WMI_PDEV_PARAM_BURST_ENABLE,
3993 hdd_ctx->config->enableSifsBurst,
3994 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003995 if (ret_val)
3996 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003997
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303998 /*
3999 * In case of USB tethering, LRO is disabled. If SSR happened
4000 * during that time, then as part of SSR init, do not enable
4001 * the LRO again. Keep the LRO state same as before SSR.
4002 */
4003 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07004004 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304005
4006 /* rcpi info initialization */
4007 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4008
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304009 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004011error_wmm_init:
4012 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4013 hdd_deinit_tx_rx(adapter);
4014error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004015 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004016 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 return status;
4019}
4020
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304021/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004022 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304023 * @hdd_ctx: global hdd context
4024 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004025 * @rtnl_held: Used to indicate whether or not the caller is holding
4026 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304027 *
4028 * This function De-initializes the STA/P2P/OCB adapter.
4029 *
4030 * Return: None.
4031 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004032static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004033 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004034 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304035{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004036 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304037
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304038 if (adapter->dev) {
4039 if (rtnl_held)
4040 adapter->dev->wireless_handlers = NULL;
4041 else {
4042 rtnl_lock();
4043 adapter->dev->wireless_handlers = NULL;
4044 rtnl_unlock();
4045 }
4046 }
4047
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304048 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4049 hdd_deinit_tx_rx(adapter);
4050 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4051 }
4052
4053 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4054 hdd_wmm_adapter_close(adapter);
4055 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4056 }
4057
Krunal Sonib51eec72017-11-20 21:53:01 -08004058
Dustin Browne74003f2018-03-14 12:51:58 -07004059 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304060}
4061
Krunal Sonib51eec72017-11-20 21:53:01 -08004062void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4063 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004064 bool rtnl_held)
4065{
Dustin Brown491d54b2018-03-14 12:39:11 -07004066 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304067
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004069 case QDF_STA_MODE:
4070 case QDF_P2P_CLIENT_MODE:
4071 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004072 case QDF_IBSS_MODE:
4073 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004075 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 break;
4077 }
4078
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004079 case QDF_SAP_MODE:
4080 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004081 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004082 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004083 break;
4084 }
4085
4086 default:
4087 break;
4088 }
4089
Dustin Browne74003f2018-03-14 12:51:58 -07004090 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004091}
4092
Jeff Johnson9d295242017-08-29 14:39:48 -07004093static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004094 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095{
Jeff Johnson5505db82017-11-02 21:19:23 -07004096 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097
4098 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004099 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004101 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004102 return;
4103 }
4104
Alok Kumarb64650c2018-03-23 17:05:11 +05304105 hdd_nud_deinit_tracking(adapter);
4106 qdf_mutex_destroy(&adapter->disconnection_status_lock);
4107
Rajeev Kumardca5f812016-02-04 17:28:06 -08004108 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110 /*
4111 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4112 * the driver is almost closed and cannot handle either control
4113 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004114 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4115 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 * is not right. Setting this flag helps hdd_stop() to recognize that
4117 * the interface is closed and restricts any operations on that
4118 */
4119 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4120
4121 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004122 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004123 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004124 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004125 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004126 /*
4127 * Note that the adapter is no longer valid at this point
4128 * since the memory has been reclaimed
4129 */
4130 }
4131}
4132
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004133static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004134 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004135{
Jeff Johnson9d295242017-08-29 14:39:48 -07004136 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004137
Dustin Brown920397d2017-12-13 16:27:50 -08004138 hdd_for_each_adapter(hdd_ctx, adapter) {
4139 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4140 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304141 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004143 }
Dustin Brown920397d2017-12-13 16:27:50 -08004144
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304145 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004147
Arun Khandavalli2358d522016-05-16 18:05:37 +05304148#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4149/**
4150 * hdd_set_fw_log_params() - Set log parameters to FW
4151 * @hdd_ctx: HDD Context
4152 * @adapter: HDD Adapter
4153 *
4154 * This function set the FW Debug log level based on the INI.
4155 *
4156 * Return: None
4157 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004158static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004159 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304160{
4161 uint8_t count = 0, numentries = 0,
4162 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4163 uint32_t value = 0;
4164 int ret;
4165
Arun Khandavallifae92942016-08-01 13:31:08 +05304166 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4167 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004168 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304169 return;
4170 }
4171
Arun Khandavallifae92942016-08-01 13:31:08 +05304172 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304173 hdd_ctx->fw_log_settings.dl_type =
4174 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004175 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304176 WMI_DBGLOG_TYPE,
4177 hdd_ctx->config->enableFwLogType,
4178 DBG_CMD);
4179 if (ret != 0)
4180 hdd_err("Failed to enable FW log type ret %d",
4181 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304182
4183 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304184 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004185 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304186 WMI_DBGLOG_LOG_LEVEL,
4187 hdd_ctx->config->enableFwLogLevel,
4188 DBG_CMD);
4189 if (ret != 0)
4190 hdd_err("Failed to enable FW log level ret %d",
4191 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304192
4193 hdd_string_to_u8_array(
4194 hdd_ctx->config->enableFwModuleLogLevel,
4195 moduleloglevel,
4196 &numentries,
4197 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4198
4199 while (count < numentries) {
4200 /*
4201 * FW module log level input string looks like
4202 * below:
4203 * gFwDebugModuleLoglevel=<FW Module ID>,
4204 * <Log Level>,...
4205 * For example:
4206 * gFwDebugModuleLoglevel=
4207 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4208 * Above input string means :
4209 * For FW module ID 1 enable log level 0
4210 * For FW module ID 2 enable log level 1
4211 * For FW module ID 3 enable log level 2
4212 * For FW module ID 4 enable log level 3
4213 * For FW module ID 5 enable log level 4
4214 * For FW module ID 6 enable log level 5
4215 * For FW module ID 7 enable log level 6
4216 */
4217
Nishank Aggarwale239d962017-03-03 12:26:02 +05304218 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4219 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4220 hdd_err("Module id %d and dbglog level %d input length is more than max",
4221 moduleloglevel[count],
4222 moduleloglevel[count + 1]);
4223 return;
4224 }
4225
4226 value = moduleloglevel[count] << 16;
4227 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004228 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304229 WMI_DBGLOG_MOD_LOG_LEVEL,
4230 value, DBG_CMD);
4231 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304232 hdd_err("Failed to enable FW module log level %d ret %d",
4233 value, ret);
4234
4235 count += 2;
4236 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304237
Arun Khandavalli2358d522016-05-16 18:05:37 +05304238}
4239#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004240static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004241 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304242{
4243}
4244
4245#endif
4246
4247/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004248 * hdd_configure_chain_mask() - programs chain mask to firmware
4249 * @adapter: HDD adapter
4250 *
4251 * Return: 0 on success or errno on failure
4252 */
4253static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4254{
4255 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004256 QDF_STATUS status;
4257 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004258 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4259
4260 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4261 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4262 hdd_ctx->config->txchainmask1x1,
4263 hdd_ctx->config->rxchainmask1x1);
4264 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4265 hdd_ctx->config->dual_mac_feature_disable,
4266 hdd_ctx->config->tx_chain_mask_2g,
4267 hdd_ctx->config->rx_chain_mask_2g);
4268 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4269 hdd_ctx->config->tx_chain_mask_5g,
4270 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004271 hdd_debug("enable_bt_chain_separation %d",
4272 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004273
Naveen Rawat98322472018-03-06 10:29:42 -08004274 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4275 HW_MODE_DBS_NONE,
4276 CDS_BAND_ALL);
4277 if (QDF_IS_STATUS_ERROR(status)) {
4278 hdd_err("couldn't get phy caps. skip chain mask programming");
4279 return qdf_status_to_os_return(status);
4280 }
4281
4282 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4283 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4284 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4285 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
4286 hdd_info("firmware not capable. skip chain mask programming");
4287 return 0;
4288 }
4289
Liangwei Dong22810e82018-03-15 03:42:12 -04004290 if (hdd_ctx->config->enable2x2 &&
4291 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004292 hdd_info("2x2 enabled. skip chain mask programming");
4293 return 0;
4294 }
4295
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004296 if (hdd_ctx->config->dual_mac_feature_disable !=
4297 DISABLE_DBS_CXN_AND_SCAN) {
4298 hdd_info("DBS enabled(%d). skip chain mask programming",
4299 hdd_ctx->config->dual_mac_feature_disable);
4300 return 0;
4301 }
4302
Naveen Rawatdacb5032018-02-08 15:23:24 -08004303 if (hdd_ctx->lte_coex_ant_share) {
4304 hdd_info("lte ant sharing enabled. skip chainmask programming");
4305 return 0;
4306 }
4307
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004308 if (hdd_ctx->config->txchainmask1x1) {
4309 ret_val = sme_cli_set_command(adapter->session_id,
4310 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4311 hdd_ctx->config->txchainmask1x1,
4312 PDEV_CMD);
4313 if (ret_val)
4314 goto error;
4315 }
4316
4317 if (hdd_ctx->config->rxchainmask1x1) {
4318 ret_val = sme_cli_set_command(adapter->session_id,
4319 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4320 hdd_ctx->config->rxchainmask1x1,
4321 PDEV_CMD);
4322 if (ret_val)
4323 goto error;
4324 }
4325
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004326 if (hdd_ctx->config->txchainmask1x1 ||
4327 hdd_ctx->config->rxchainmask1x1) {
4328 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4329 return 0;
4330 }
4331
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004332 if (hdd_ctx->config->tx_chain_mask_2g) {
4333 ret_val = sme_cli_set_command(adapter->session_id,
4334 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4335 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4336 if (0 != ret_val)
4337 goto error;
4338 }
4339
4340 if (hdd_ctx->config->rx_chain_mask_2g) {
4341 ret_val = sme_cli_set_command(adapter->session_id,
4342 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4343 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4344 if (0 != ret_val)
4345 goto error;
4346 }
4347
4348 if (hdd_ctx->config->tx_chain_mask_5g) {
4349 ret_val = sme_cli_set_command(adapter->session_id,
4350 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4351 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4352 if (0 != ret_val)
4353 goto error;
4354 }
4355
4356 if (hdd_ctx->config->rx_chain_mask_5g) {
4357 ret_val = sme_cli_set_command(adapter->session_id,
4358 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4359 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4360 if (0 != ret_val)
4361 goto error;
4362 }
4363
4364 return 0;
4365
4366error:
4367 hdd_err("WMI PDEV set param failed %d", ret_val);
4368 return -EINVAL;
4369}
4370
4371/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304372 * hdd_set_fw_params() - Set parameters to firmware
4373 * @adapter: HDD adapter
4374 *
4375 * This function Sets various parameters to fw once the
4376 * adapter is started.
4377 *
4378 * Return: 0 on success or errno on failure
4379 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004380int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304381{
4382 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004383 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304384
Dustin Brownfdf17c12018-03-14 12:55:34 -07004385 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304386
4387 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4388 if (!hdd_ctx)
4389 return -EINVAL;
4390
Dustin Brown732ab9c2017-06-15 13:24:09 -07004391 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4392 hdd_debug("FTM Mode is active; nothing to do");
4393 return 0;
4394 }
4395
Jeff Johnson1b780e42017-10-31 14:11:45 -07004396 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304397 WMI_PDEV_PARAM_DTIM_SYNTH,
4398 hdd_ctx->config->enable_lprx, PDEV_CMD);
4399 if (ret) {
4400 hdd_err("Failed to set LPRx");
4401 goto error;
4402 }
4403
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304404
4405 ret = sme_cli_set_command(
4406 adapter->session_id,
4407 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4408 hdd_ctx->config->enable_dtim_selection_diversity,
4409 PDEV_CMD);
4410 if (ret) {
4411 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4412 goto error;
4413 }
4414
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304415 ret = sme_cli_set_command(
4416 adapter->session_id,
4417 WMI_PDEV_PARAM_TX_SCH_DELAY,
4418 hdd_ctx->config->enable_tx_sch_delay,
4419 PDEV_CMD);
4420 if (ret) {
4421 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4422 goto error;
4423 }
4424
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304425 ret = sme_cli_set_command(
4426 adapter->session_id,
4427 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4428 hdd_ctx->config->enable_secondary_rate,
4429 PDEV_CMD);
4430 if (ret) {
4431 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4432 goto error;
4433 }
4434
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304435 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004436 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304437 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4438 hdd_ctx->config->upper_brssi_thresh);
4439
Jeff Johnson1b780e42017-10-31 14:11:45 -07004440 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304441 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4442 hdd_ctx->config->lower_brssi_thresh);
4443
Jeff Johnson1b780e42017-10-31 14:11:45 -07004444 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304445 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4446 hdd_ctx->config->enable_dtim_1chrx);
4447 }
4448
Dustin Brown732ab9c2017-06-15 13:24:09 -07004449 if (hdd_ctx->config->enable2x2) {
4450 hdd_debug("configuring 2x2 mode fw params");
4451
Jeff Johnson1b780e42017-10-31 14:11:45 -07004452 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004453 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4454 hdd_ctx->config->enable_cck_tx_fir_override,
4455 PDEV_CMD);
4456 if (ret) {
4457 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4458 ret);
4459 goto error;
4460 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004461
4462 if (hdd_configure_chain_mask(adapter))
4463 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004464 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304465#define HDD_DTIM_1CHAIN_RX_ID 0x5
4466#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004467 hdd_debug("configuring 1x1 mode fw params");
4468
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004469 /*
4470 * Disable DTIM 1 chain Rx when in 1x1,
4471 * we are passing two value
4472 * as param_id << 29 | param_value.
4473 * Below param_value = 0(disable)
4474 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004475 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004476 WMI_STA_SMPS_PARAM_CMDID,
4477 HDD_DTIM_1CHAIN_RX_ID <<
4478 HDD_SMPS_PARAM_VALUE_S,
4479 VDEV_CMD);
4480 if (ret) {
4481 hdd_err("DTIM 1 chain set failed %d", ret);
4482 goto error;
4483 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304484
Arun Khandavalli2358d522016-05-16 18:05:37 +05304485#undef HDD_DTIM_1CHAIN_RX_ID
4486#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004487
4488 if (hdd_configure_chain_mask(adapter))
4489 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004490 }
4491
Jeff Johnson1b780e42017-10-31 14:11:45 -07004492 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004493 WMI_PDEV_PARAM_HYST_EN,
4494 hdd_ctx->config->enableMemDeepSleep,
4495 PDEV_CMD);
4496 if (ret) {
4497 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4498 goto error;
4499 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304500
Jeff Johnson1b780e42017-10-31 14:11:45 -07004501 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004502 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4503 hdd_ctx->config->rts_profile,
4504 VDEV_CMD);
4505 if (ret) {
4506 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4507 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304508 }
4509
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004510 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4511
Jeff Johnson1b780e42017-10-31 14:11:45 -07004512 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004513 GEN_VDEV_PARAM_AMSDU,
4514 hdd_ctx->config->max_amsdu_num,
4515 GEN_CMD);
4516 if (ret != 0) {
4517 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4518 goto error;
4519 }
4520
Arun Khandavalli2358d522016-05-16 18:05:37 +05304521 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004522 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004523
Arun Khandavalli2358d522016-05-16 18:05:37 +05304524 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304525
Arun Khandavalli2358d522016-05-16 18:05:37 +05304526error:
4527 return -EINVAL;
4528}
4529
Ryan Hsu07495ea2016-01-21 15:25:39 -08004530/**
4531 * hdd_open_adapter() - open and setup the hdd adatper
4532 * @hdd_ctx: global hdd context
4533 * @session_type: type of the interface to be created
4534 * @iface_name: User-visible name of the interface
4535 * @macAddr: MAC address to assign to the interface
4536 * @name_assign_type: the name of assign type of the netdev
4537 * @rtnl_held: the rtnl lock hold flag
4538 *
4539 * This function open and setup the hdd adpater according to the device
4540 * type request, assign the name, the mac address assigned, and then prepared
4541 * the hdd related parameters, queue, lock and ready to start.
4542 *
4543 * Return: the pointer of hdd adapter, otherwise NULL.
4544 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004545struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004546 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004547 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004548 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004549{
Jeff Johnson9d295242017-08-29 14:39:48 -07004550 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304551 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004552
4553 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4554 /*
4555 * Max limit reached on the number of vdevs configured by the
4556 * host. Return error
4557 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304558 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4559 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004560 return NULL;
4561 }
4562
4563 if (macAddr == NULL) {
4564 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304565 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004566 return NULL;
4567 }
4568 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304569 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304570 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4571 " already exists",
4572 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004573 return NULL;
4574 }
4575
4576 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004577 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004578 /* Reset locally administered bit if the device mode is STA */
4579 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304580 hdd_info("locally administered bit reset in sta mode: "
4581 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004582 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004583 case QDF_P2P_CLIENT_MODE:
4584 case QDF_P2P_DEVICE_MODE:
4585 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004586 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304587 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004588 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4589 name_assign_type,
4590 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004591
4592 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304593 hdd_err("failed to allocate adapter for session %d",
4594 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004595 return NULL;
4596 }
4597
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004598 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004599 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004600 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004601 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304602 else if (QDF_MONITOR_MODE == session_type)
4603 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004604 else
4605 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4606
4607 adapter->device_mode = session_type;
4608
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004610 /*
4611 * Workqueue which gets scheduled in IPv4 notification
4612 * callback
4613 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004614 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004615 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004616
4617#ifdef WLAN_NS_OFFLOAD
4618 /*
4619 * Workqueue which gets scheduled in IPv6
4620 * notification callback.
4621 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004622 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004623 hdd_ipv6_notifier_work_queue);
4624#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004626 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004627 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004628
4629 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004630 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004631 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304632 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4633 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304634
Ravi Joshi1a292562017-05-18 16:28:54 -07004635 /* Initialize NAN Data Interface */
4636 if (QDF_NDI_MODE == session_type) {
4637 status = hdd_init_nan_data_mode(adapter);
4638 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004639 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004640 }
4641
Alok Kumarb64650c2018-03-23 17:05:11 +05304642 hdd_nud_init_tracking(adapter);
4643
4644 qdf_mutex_create(&adapter->disconnection_status_lock);
4645
Ravi Joshi1a292562017-05-18 16:28:54 -07004646 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004647
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004648 case QDF_P2P_GO_MODE:
4649 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004650 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4651 name_assign_type,
4652 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004654 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304655 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004656 return NULL;
4657 }
4658
4659 adapter->wdev.iftype =
4660 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004661 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 NL80211_IFTYPE_P2P_GO;
4663 adapter->device_mode = session_type;
4664
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004665 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004666 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004668
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004669 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004670 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304671 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4672 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304673
4674 /*
4675 * Workqueue which gets scheduled in IPv4 notification
4676 * callback
4677 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004678 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304679 hdd_ipv4_notifier_work_queue);
4680
4681#ifdef WLAN_NS_OFFLOAD
4682 /*
4683 * Workqueue which gets scheduled in IPv6
4684 * notification callback.
4685 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004686 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304687 hdd_ipv6_notifier_work_queue);
4688#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004689 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304690 case QDF_FTM_MODE:
4691 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4692 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004693 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304694 if (NULL == adapter) {
4695 hdd_err("Failed to allocate adapter for FTM mode");
4696 return NULL;
4697 }
4698 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4699 adapter->device_mode = session_type;
4700 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004701 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004702 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004703
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304704 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004705 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304706 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304707 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4708 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304709 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004710 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004711 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304712 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004713 return NULL;
4714 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004715
hqueaa33ee2017-05-04 17:56:35 +08004716 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4717
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304718 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004719 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004720 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004721 }
4722
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304723 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004724 if (NULL != adapter) {
4725 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4726 adapter = NULL;
4727 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004728
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729 return NULL;
4730 }
4731
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304732 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004733 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4734 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004735
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004736 /* Adapter successfully added. Increment the vdev count */
4737 hdd_ctx->current_intf_count++;
4738
Jeff Johnson5880d792016-08-15 13:32:30 -07004739 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004740 hdd_ctx->current_intf_count);
4741
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004742 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004743 }
4744
Rajeev Kumardca5f812016-02-04 17:28:06 -08004745 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004746 hdd_err("Interface %s wow debug_fs init failed",
4747 netdev_name(adapter->dev));
4748
4749 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4750 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004751
4752 return adapter;
4753
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004754err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004755 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304756 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004757
4758 return NULL;
4759}
4760
Nirav Shaheb017be2018-02-15 11:20:58 +05304761#ifdef MSM_PLATFORM
4762static inline
4763void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4764{
4765 cancel_work_sync(&hdd_ctx->bus_bw_work);
4766}
4767#else
4768static inline
4769void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4770{
4771}
4772#endif
4773
Jeff Johnson9d295242017-08-29 14:39:48 -07004774QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004775 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004776{
Dustin Brown920397d2017-12-13 16:27:50 -08004777 /*
4778 * Here we are stopping global bus_bw timer & work per adapter.
4779 *
4780 * The reason is to fix one race condition between
4781 * bus bandwidth work and cleaning up an adapter.
4782 * Under some conditions, it is possible for the bus bandwidth
4783 * work to access a particularly destroyed adapter, leading to
4784 * use-after-free.
4785 */
4786 hdd_debug("wait for bus bw work to flush");
4787 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4788 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004789
Dustin Brown920397d2017-12-13 16:27:50 -08004790 /* cleanup adapter */
4791 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4792 adapter->device_mode);
4793 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4794 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004795
Dustin Brown920397d2017-12-13 16:27:50 -08004796 /* conditionally restart the bw timer */
4797 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004798
Dustin Brown920397d2017-12-13 16:27:50 -08004799 /* Adapter removed. Decrement vdev count */
4800 if (hdd_ctx->current_intf_count != 0)
4801 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004802
Dustin Brown920397d2017-12-13 16:27:50 -08004803 /* Fw will take care incase of concurrency */
4804 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004805}
4806
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004807/**
4808 * hdd_close_all_adapters - Close all open adapters
4809 * @hdd_ctx: Hdd context
4810 * rtnl_held: True if RTNL lock held
4811 *
4812 * Close all open adapters.
4813 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304814 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004815 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004816QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004817{
Dustin Brown920397d2017-12-13 16:27:50 -08004818 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304819 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004820
Dustin Brown491d54b2018-03-14 12:39:11 -07004821 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004822
4823 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004824 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4825 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304826 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004827 adapter->mac_addr.bytes);
4828 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4829
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304830 /* Adapter removed. Decrement vdev count */
4831 if (hdd_ctx->current_intf_count != 0)
4832 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004833 }
Dustin Brown920397d2017-12-13 16:27:50 -08004834 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004835
Dustin Browne74003f2018-03-14 12:51:58 -07004836 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004837
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304838 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839}
4840
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004841void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004842{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304843 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004844 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004845
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004846 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004847 case QDF_STA_MODE:
4848 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004849 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004850 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004851 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004852 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004853 break;
4854 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004855 case QDF_SAP_MODE:
4856 case QDF_P2P_GO_MODE:
4857 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004858 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004859 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004860 break;
4861 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004862 case QDF_FTM_MODE:
4863 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004864 default:
4865 /*
4866 * wlan_hdd_reset_prob_rspies should not have been called
4867 * for these kind of devices
4868 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004869 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004870 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871 return;
4872 }
4873
Anurag Chouhanc5548422016-02-24 18:33:27 +05304874 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004875 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004876 updateIE.ieBufferlength = 0;
4877 updateIE.pAdditionIEBuffer = NULL;
4878 updateIE.append = true;
4879 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004880 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004881 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304882 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004883 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004884 }
4885}
4886
Dustin Browndb2a8be2017-12-20 11:49:56 -08004887QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4888 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304890 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07004891 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004892 union iwreq_data wrqu;
4893 tSirUpdateIE updateIE;
4894 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304895 tsap_Config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004896
Dustin Brown491d54b2018-03-14 12:39:11 -07004897 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004898
Alok Kumarb64650c2018-03-23 17:05:11 +05304899 hdd_nud_ignore_tracking(adapter, true);
4900 hdd_nud_reset_tracking(adapter);
4901
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004902 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304903 wlan_hdd_netif_queue_control(adapter,
4904 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4905 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004906 /*
4907 * if this is the last active connection check & stop the
4908 * opportunistic timer first
4909 */
4910 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4911 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4912 policy_mgr_convert_device_mode_to_qdf_type(
4913 adapter->device_mode), NULL) == 1)) ||
4914 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4915 policy_mgr_check_and_stop_opportunistic_timer(
4916 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004917 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004918 case QDF_STA_MODE:
4919 case QDF_P2P_CLIENT_MODE:
4920 case QDF_IBSS_MODE:
4921 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004922 case QDF_NDI_MODE:
4923 if ((QDF_NDI_MODE == adapter->device_mode) ||
4924 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004925 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4926 hdd_is_connecting(
4927 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004928 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07004929 roam_profile = hdd_roam_profile(adapter);
4930 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004931 if (QDF_NDI_MODE == adapter->device_mode)
4932 qdf_ret_status = sme_roam_disconnect(
4933 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004934 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004935 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07004936 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004937 eCSR_BSS_TYPE_START_IBSS)
4938 qdf_ret_status = sme_roam_disconnect(
4939 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004940 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004941 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004942 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004943 qdf_ret_status =
4944 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004945 hdd_debug("Send disconnected event to userspace");
4946 wlan_hdd_cfg80211_indicate_disconnect(
4947 adapter->dev, true,
4948 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08004949 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004950 qdf_ret_status = sme_roam_disconnect(
4951 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004952 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004953 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004954 /* success implies disconnect command got
4955 * queued up successfully
4956 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004957 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4958 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004959 rc = wait_for_completion_timeout(
4960 &adapter->disconnect_comp_var,
4961 msecs_to_jiffies
4962 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004963 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004964 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004965 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004966 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4967 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004968 memset(&wrqu, '\0', sizeof(wrqu));
4969 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4970 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4971 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4972 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304973 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004974 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004975
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304976 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304977 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004978
4979#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004980 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004981#endif
4982
4983 hdd_deregister_tx_flow_control(adapter);
4984
4985#ifdef WLAN_NS_OFFLOAD
4986#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004987 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004988#endif
4989#endif
4990
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304991 if (adapter->device_mode == QDF_STA_MODE)
4992 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4993 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004994
4995 if (wlan_hdd_try_disconnect(adapter)) {
4996 hdd_err("Error: Can't disconnect adapter");
4997 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004998 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004999
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305000 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005001 break;
5002
Rajeev Kumar3b906202018-02-01 10:55:14 -08005003 case QDF_MONITOR_MODE:
5004 wlan_hdd_scan_abort(adapter);
5005 hdd_deregister_tx_flow_control(adapter);
5006 hdd_vdev_destroy(adapter);
5007 break;
5008
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005009 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08005010 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305011 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305012 sap_config = &adapter->session.ap.sap_config;
5013 if (sap_config)
5014 wlansap_reset_sap_config_add_ie(sap_config,
5015 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305016 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08005017 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005018
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005019 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07005020 if (QDF_SAP_MODE == adapter->device_mode) {
5021 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5022 cds_flush_delayed_work(
5023 &adapter->acs_pending_work);
5024 clear_bit(ACS_PENDING, &adapter->event_flags);
5025 }
5026 }
Krunal Soni22208392017-09-29 18:10:34 -07005027 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005029 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305030 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005031 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005032 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005033 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5034
5035 hdd_deregister_tx_flow_control(adapter);
5036
Kapil Guptac1224bf2017-06-22 21:22:40 +05305037 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038 mutex_lock(&hdd_ctx->sap_lock);
5039 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305040 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305041 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042
5043 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005044 status = wlansap_stop_bss(
5045 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005046
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305047 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005048 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305050 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305051 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305052 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305053 qdf_wait_for_event_completion(
5054 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005055 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056
Anurag Chouhance0dc992016-02-16 18:18:03 +05305057 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005058 hdd_err("failure waiting for wlansap_stop_bss %d",
5059 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005060 }
5061 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005062 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005063 }
5064 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005065 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5066 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005067 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005068 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305069 adapter->device_mode,
5070 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005071
Anurag Chouhanc5548422016-02-24 18:33:27 +05305072 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005073 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005074 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005075 updateIE.ieBufferlength = 0;
5076 updateIE.pAdditionIEBuffer = NULL;
5077 updateIE.append = false;
5078 updateIE.notify = false;
5079 /* Probe bcn reset */
5080 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5081 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305082 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005083 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084 }
5085 /* Assoc resp reset */
5086 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5087 &updateIE,
5088 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305089 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005090 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005091 }
5092 /* Reset WNI_CFG_PROBE_RSP Flags */
5093 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005094 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07005095 qdf_mem_free(adapter->session.ap.beacon);
5096 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305097 /*
5098 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5099 */
5100 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5101 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5102
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305103#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005104 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305105#endif
5106
5107#ifdef WLAN_NS_OFFLOAD
5108#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005109 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305110#endif
5111#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005112
5113 hdd_vdev_destroy(adapter);
5114
Krunal Sonib51eec72017-11-20 21:53:01 -08005115 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005117 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005118 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005119 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005120 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005121 hdd_deregister_tx_flow_control(adapter);
5122 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005123 break;
5124 default:
5125 break;
5126 }
5127
Dustin Brown04348372017-12-14 16:13:39 -08005128 if (adapter->scan_info.default_scan_ies) {
5129 qdf_mem_free(adapter->scan_info.default_scan_ies);
5130 adapter->scan_info.default_scan_ies = NULL;
5131 }
5132
Dustin Browne74003f2018-03-14 12:51:58 -07005133 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005134
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305135 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005136}
5137
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305138/**
5139 * hdd_deinit_all_adapters - deinit all adapters
5140 * @hdd_ctx: HDD context
5141 * @rtnl_held: True if RTNL lock held
5142 *
5143 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005144void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305145{
Jeff Johnson9d295242017-08-29 14:39:48 -07005146 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305147
Dustin Brown491d54b2018-03-14 12:39:11 -07005148 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305149
Dustin Brown920397d2017-12-13 16:27:50 -08005150 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305151 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305152
Dustin Browne74003f2018-03-14 12:51:58 -07005153 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305154}
5155
Dustin Browndb2a8be2017-12-20 11:49:56 -08005156QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157{
Jeff Johnson9d295242017-08-29 14:39:48 -07005158 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159
Dustin Brown491d54b2018-03-14 12:39:11 -07005160 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005161
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305162 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5163
Dustin Brown920397d2017-12-13 16:27:50 -08005164 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005165 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005166
Dustin Browne74003f2018-03-14 12:51:58 -07005167 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005168
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305169 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170}
5171
Paul Zhang84fa9382017-11-10 21:18:21 +08005172static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5173 struct hdd_adapter *adapter)
5174{
5175 switch (adapter->device_mode) {
5176 case QDF_STA_MODE:
5177 case QDF_P2P_CLIENT_MODE:
5178 case QDF_IBSS_MODE:
5179 case QDF_P2P_DEVICE_MODE:
5180 case QDF_NDI_MODE:
5181 wlan_hdd_scan_abort(adapter);
5182 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5183 if (adapter->device_mode == QDF_STA_MODE)
5184 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5185 adapter->dev);
5186 break;
5187 case QDF_P2P_GO_MODE:
5188 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5189 break;
5190 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305191 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005192 wlan_hdd_undo_acs(adapter);
5193 break;
5194 default:
5195 break;
5196 }
5197}
5198
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005199QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005200{
Jeff Johnson9d295242017-08-29 14:39:48 -07005201 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005202 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005203 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005204 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205
Dustin Brown491d54b2018-03-14 12:39:11 -07005206 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305208 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5209
Dustin Brown920397d2017-12-13 16:27:50 -08005210 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005211 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5212 hdd_device_mode_to_string(adapter->device_mode),
5213 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305214
5215 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005216 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305217 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005218 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005219 adapter->session.station.hdd_reassoc_scenario = false;
5220 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305221
Arun Khandavallicc544b32017-01-30 19:52:16 +05305222 if (hdd_ctx->config->sap_internal_restart &&
5223 adapter->device_mode == QDF_SAP_MODE) {
5224 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305225 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305226 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005227 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005228 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005229 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005230 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5231 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305232 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305233 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005235 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236
Paul Zhang84fa9382017-11-10 21:18:21 +08005237 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005238
5239 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005240 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005241 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005242 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305243 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5245 hdd_wmm_adapter_close(adapter);
5246 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5247 }
5248
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305249 if (adapter->device_mode == QDF_STA_MODE)
5250 hdd_clear_fils_connection_info(adapter);
5251
Wu Gao3545e642017-07-14 19:24:41 +08005252 if (adapter->device_mode == QDF_SAP_MODE) {
5253 /*
5254 * If adapter is SAP, set session ID to invalid
5255 * since SAP session will be cleanup during SSR.
5256 */
Wu Gao36717432016-11-21 15:09:48 +08005257 wlansap_set_invalid_session(
5258 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5259
Wu Gao3545e642017-07-14 19:24:41 +08005260 wlansap_cleanup_cac_timer(
5261 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5262 }
5263
Yue Ma42654682018-01-11 16:55:24 -08005264 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005265 if (adapter->device_mode == QDF_STA_MODE ||
5266 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005267 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005268 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005269 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005270
5271 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5272 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005273 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5274 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5275 if (adapter->sta_info[sta_id].in_use) {
5276 hdd_debug("[SSR] deregister STA with ID %d",
5277 sta_id);
5278 hdd_softap_deregister_sta(adapter,
5279 sta_id);
5280 adapter->sta_info[sta_id].in_use = 0;
5281 }
5282 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005283 }
5284
Alok Kumarb64650c2018-03-23 17:05:11 +05305285 hdd_nud_reset_tracking(adapter);
5286 hdd_nud_ignore_tracking(adapter, true);
5287 hdd_set_disconnect_status(adapter, false);
5288
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005289 hdd_softap_deinit_tx_rx(adapter);
5290
Yue Maf9782842017-05-08 12:49:49 -07005291 /* Destroy vdev which will be recreated during reinit. */
5292 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005293 }
5294
Dustin Browne74003f2018-03-14 12:51:58 -07005295 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005296
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305297 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005298}
5299
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005300bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305301{
Dustin Brown920397d2017-12-13 16:27:50 -08005302 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305303 bool close_modules = true;
5304
Arun Khandavalliba479c42017-07-26 21:29:40 +05305305 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5306 hdd_info("FTM mode, don't close the module");
5307 return false;
5308 }
5309
Dustin Brown920397d2017-12-13 16:27:50 -08005310 hdd_for_each_adapter(hdd_ctx, adapter) {
5311 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5312 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005313 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305314 close_modules = false;
5315 break;
5316 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305317 }
5318
5319 return close_modules;
5320}
5321
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305322bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305323{
5324 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5325 return true;
5326 else
5327 return false;
5328}
5329
Anurag Chouhanc4092922016-09-08 15:56:11 +05305330#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005331 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305332struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5333 struct ieee80211_channel *channel,
5334 const u8 *bssid, const u8 *ssid,
5335 size_t ssid_len)
5336{
5337 return cfg80211_get_bss(wiphy, channel, bssid,
5338 ssid, ssid_len,
5339 WLAN_CAPABILITY_ESS,
5340 WLAN_CAPABILITY_ESS);
5341}
5342#else
5343struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5344 struct ieee80211_channel *channel,
5345 const u8 *bssid, const u8 *ssid,
5346 size_t ssid_len)
5347{
5348 return cfg80211_get_bss(wiphy, channel, bssid,
5349 ssid, ssid_len,
5350 IEEE80211_BSS_TYPE_ESS,
5351 IEEE80211_PRIVACY_ANY);
5352}
5353#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305354
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305355#if defined CFG80211_CONNECT_BSS || \
5356 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305357#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305358 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305359/**
5360 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5361 * @timeout_reason: reason for connect timeout
5362 *
5363 * This function is used to convert host timeout
5364 * reason enum to kernel specific enum.
5365 *
5366 * Return: nl timeout enum
5367 */
5368static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5369 tSirResultCodes timeout_reason)
5370{
5371 switch (timeout_reason) {
5372 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5373 return NL80211_TIMEOUT_SCAN;
5374 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5375 return NL80211_TIMEOUT_AUTH;
5376 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5377 return NL80211_TIMEOUT_ASSOC;
5378 default:
5379 return NL80211_TIMEOUT_UNSPECIFIED;
5380 }
5381}
5382
5383/**
5384 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5385 * @dev: network device
5386 * @bssid: bssid to which we want to associate
5387 * @timeout_reason: reason for connect timeout
5388 *
5389 * This API is used to send connection timeout reason to supplicant
5390 *
5391 * Return: void
5392 */
5393static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5394 const u8 *bssid,
5395 tSirResultCodes timeout_reason)
5396{
5397 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005398
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305399 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5400
5401 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5402 nl_timeout_reason);
5403}
5404
5405/**
5406 * __hdd_connect_bss() - API to send connection status to supplicant
5407 * @dev: network device
5408 * @bssid: bssid to which we want to associate
5409 * @req_ie: Request Information Element
5410 * @req_ie_len: len of the req IE
5411 * @resp_ie: Response IE
5412 * @resp_ie_len: len of ht response IE
5413 * @status: status
5414 * @gfp: Kernel Flag
5415 * @timeout_reason: reason for connect timeout
5416 *
5417 * Return: void
5418 */
5419static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5420 struct cfg80211_bss *bss, const u8 *req_ie,
5421 size_t req_ie_len, const u8 *resp_ie,
5422 size_t resp_ie_len, int status, gfp_t gfp,
5423 tSirResultCodes timeout_reason)
5424{
5425 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005426
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305427 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5428
5429 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5430 resp_ie, resp_ie_len, status, gfp,
5431 nl_timeout_reason);
5432}
5433#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305434#if defined CFG80211_CONNECT_TIMEOUT || \
5435 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305436static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5437 const u8 *bssid,
5438 tSirResultCodes timeout_reason)
5439{
5440 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5441}
5442#endif
5443
5444static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5445 struct cfg80211_bss *bss, const u8 *req_ie,
5446 size_t req_ie_len, const u8 *resp_ie,
5447 size_t resp_ie_len, int status, gfp_t gfp,
5448 tSirResultCodes timeout_reason)
5449{
5450 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5451 resp_ie, resp_ie_len, status, gfp);
5452}
5453#endif
5454
Abhishek Singha84d3952016-09-13 13:45:05 +05305455/**
5456 * hdd_connect_bss() - API to send connection status to supplicant
5457 * @dev: network device
5458 * @bssid: bssid to which we want to associate
5459 * @req_ie: Request Information Element
5460 * @req_ie_len: len of the req IE
5461 * @resp_ie: Response IE
5462 * @resp_ie_len: len of ht response IE
5463 * @status: status
5464 * @gfp: Kernel Flag
5465 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305466 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305467 *
5468 * The API is a wrapper to send connection status to supplicant
5469 *
5470 * Return: Void
5471 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305472#if defined CFG80211_CONNECT_TIMEOUT || \
5473 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305474static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5475 struct cfg80211_bss *bss, const u8 *req_ie,
5476 size_t req_ie_len, const u8 *resp_ie,
5477 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305478 bool connect_timeout,
5479 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305480{
5481 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305482 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305483 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305484 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5485 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305486}
5487#else
5488static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5489 struct cfg80211_bss *bss, const u8 *req_ie,
5490 size_t req_ie_len, const u8 *resp_ie,
5491 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305492 bool connect_timeout,
5493 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305494{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305495 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5496 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305497}
5498#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305499
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305500#if defined(WLAN_FEATURE_FILS_SK)
5501#if defined(CFG80211_CONNECT_DONE) || \
5502 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5503#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5504 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305505/**
5506 * hdd_populate_fils_params() - Populate FILS keys to connect response
5507 * @fils_params: connect response to supplicant
5508 * @fils_kek: FILS kek
5509 * @fils_kek_len: FILS kek length
5510 * @pmk: FILS PMK
5511 * @pmk_len: FILS PMK length
5512 * @pmkid: PMKID
5513 * @fils_seq_num: FILS Seq number
5514 *
5515 * Return: None
5516 */
5517static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5518 *fils_params, const uint8_t *fils_kek,
5519 size_t fils_kek_len, const uint8_t *pmk,
5520 size_t pmk_len, const uint8_t *pmkid,
5521 uint16_t fils_seq_num)
5522{
5523 /* Increament seq number to be used for next FILS */
5524 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5525 fils_params->update_erp_next_seq_num = true;
5526 fils_params->fils_kek = fils_kek;
5527 fils_params->fils_kek_len = fils_kek_len;
5528 fils_params->pmk = pmk;
5529 fils_params->pmk_len = pmk_len;
5530 fils_params->pmkid = pmkid;
5531}
5532#else
5533static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5534 *fils_params, const uint8_t
5535 *fils_kek, size_t fils_kek_len,
5536 const uint8_t *pmk, size_t pmk_len,
5537 const uint8_t *pmkid,
5538 uint16_t fils_seq_num)
5539{ }
5540#endif
5541
Jeff Johnson172237b2017-11-07 15:32:59 -08005542void hdd_update_hlp_info(struct net_device *dev,
5543 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305544{
5545 struct sk_buff *skb;
5546 uint16_t skb_len;
5547 struct llc_snap_hdr_t *llc_hdr;
5548 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305549 uint8_t *hlp_data;
5550 uint16_t hlp_data_len;
5551 struct fils_join_rsp_params *roam_fils_params
5552 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305553 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5554
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305555 if (!roam_fils_params) {
5556 hdd_err("FILS Roam Param NULL");
5557 return;
5558 }
5559
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005560 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305561 hdd_err("FILS HLP Data NULL, len %d",
5562 roam_fils_params->hlp_data_len);
5563 return;
5564 }
5565
5566 hlp_data = roam_fils_params->hlp_data;
5567 hlp_data_len = roam_fils_params->hlp_data_len;
5568
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305569 /* Calculate skb length */
5570 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5571 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5572 if (skb == NULL) {
5573 hdd_err("HLP packet nbuf alloc fails");
5574 return;
5575 }
5576
5577 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5578 QDF_MAC_ADDR_SIZE);
5579 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5580 QDF_MAC_ADDR_SIZE);
5581
5582 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5583 if (IS_SNAP(llc_hdr)) {
5584 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5585 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5586 }
5587
5588 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5589
5590 /*
5591 * This HLP packet is formed from HLP info encapsulated
5592 * in assoc response frame which is AEAD encrypted.
5593 * Hence, this checksum validation can be set unnecessary.
5594 * i.e. network layer need not worry about checksum.
5595 */
5596 skb->ip_summed = CHECKSUM_UNNECESSARY;
5597
5598 status = hdd_rx_packet_cbk(padapter, skb);
5599 if (QDF_IS_STATUS_ERROR(status)) {
5600 hdd_err("Sending HLP packet fails");
5601 return;
5602 }
5603 hdd_debug("send HLP packet to netif successfully");
5604}
5605
5606/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305607 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5608 * @dev: network device
5609 * @bssid: bssid to which we want to associate
5610 * @bss: cfg80211 bss info
5611 * @roam_info: information about connected bss
5612 * @req_ie: Request Information Element
5613 * @req_ie_len: len of the req IE
5614 * @resp_ie: Response IE
5615 * @resp_ie_len: len of ht response IE
5616 * @status: status
5617 * @gfp: allocation flags
5618 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5619 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305620 *
5621 * This API is used as wrapper to send FILS key/sequence number
5622 * params etc. to supplicant in case of FILS connection
5623 *
5624 * Return: None
5625 */
5626static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005627 struct cfg80211_bss *bss,
5628 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305629 const u8 *req_ie, size_t req_ie_len,
5630 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005631 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305632 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305633{
5634 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305635 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5636 struct fils_join_rsp_params *roam_fils_params =
5637 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005638
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305639 qdf_mem_zero(&fils_params, sizeof(fils_params));
5640
5641 if (!roam_fils_params) {
5642 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5643 } else {
5644 fils_params.status = status;
5645 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005646 fils_params.timeout_reason =
5647 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305648 fils_params.req_ie = req_ie;
5649 fils_params.req_ie_len = req_ie_len;
5650 fils_params.resp_ie = resp_ie;
5651 fils_params.resp_ie_len = resp_ie_len;
5652 fils_params.bss = bss;
5653 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5654 roam_fils_params->kek_len,
5655 roam_fils_params->fils_pmk,
5656 roam_fils_params->fils_pmk_len,
5657 roam_fils_params->fils_pmkid,
5658 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305659 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305660 }
5661 hdd_debug("FILS indicate connect status %d seq no %d",
5662 fils_params.status,
5663 fils_params.fils_erp_next_seq_num);
5664
5665 cfg80211_connect_done(dev, &fils_params, gfp);
5666
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305667 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305668 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305669
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305670 /* Clear all the FILS key info */
5671 if (roam_fils_params && roam_fils_params->fils_pmk)
5672 qdf_mem_free(roam_fils_params->fils_pmk);
5673 if (roam_fils_params)
5674 qdf_mem_free(roam_fils_params);
5675 roam_info->fils_join_rsp = NULL;
5676}
5677#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005678static inline void
5679hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005680 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005681 const u8 *req_ie, size_t req_ie_len,
5682 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5683 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305684 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305685{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305686#endif
5687#endif
5688
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305689#if defined(WLAN_FEATURE_FILS_SK) && \
5690 (defined(CFG80211_CONNECT_DONE) || \
5691 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305692/**
5693 * hdd_fils_update_connect_results() - API to send fils connection status to
5694 * supplicant.
5695 * @dev: network device
5696 * @bssid: bssid to which we want to associate
5697 * @bss: cfg80211 bss info
5698 * @roam_info: information about connected bss
5699 * @req_ie: Request Information Element
5700 * @req_ie_len: len of the req IE
5701 * @resp_ie: Response IE
5702 * @resp_ie_len: len of ht response IE
5703 * @status: status
5704 * @gfp: allocation flags
5705 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5706 * @timeout_reason: reason for connect timeout
5707 *
5708 * The API is a wrapper to send connection status to supplicant
5709 *
5710 * Return: 0 if success else failure
5711 */
5712static int hdd_fils_update_connect_results(struct net_device *dev,
5713 const u8 *bssid,
5714 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005715 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305716 size_t req_ie_len, const u8 *resp_ie,
5717 size_t resp_ie_len, u16 status, gfp_t gfp,
5718 bool connect_timeout,
5719 tSirResultCodes timeout_reason)
5720{
Dustin Brown491d54b2018-03-14 12:39:11 -07005721 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305722 if (!roam_info || !roam_info->is_fils_connection)
5723 return -EINVAL;
5724
5725 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5726 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305727 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305728 return 0;
5729}
5730#else
5731static inline int hdd_fils_update_connect_results(struct net_device *dev,
5732 const u8 *bssid,
5733 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005734 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305735 size_t req_ie_len, const u8 *resp_ie,
5736 size_t resp_ie_len, u16 status, gfp_t gfp,
5737 bool connect_timeout,
5738 tSirResultCodes timeout_reason)
5739{
5740 return -EINVAL;
5741}
5742#endif
5743
Anurag Chouhanc4092922016-09-08 15:56:11 +05305744/**
5745 * hdd_connect_result() - API to send connection status to supplicant
5746 * @dev: network device
5747 * @bssid: bssid to which we want to associate
5748 * @roam_info: information about connected bss
5749 * @req_ie: Request Information Element
5750 * @req_ie_len: len of the req IE
5751 * @resp_ie: Response IE
5752 * @resp_ie_len: len of ht response IE
5753 * @status: status
5754 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305755 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305756 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305757 *
5758 * The API is a wrapper to send connection status to supplicant
5759 * and allow runtime suspend
5760 *
5761 * Return: Void
5762 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305763void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005764 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305765 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305766 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305767 bool connect_timeout,
5768 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305769{
Jeff Johnson9d295242017-08-29 14:39:48 -07005770 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305771 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005772 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305773
5774 if (WLAN_STATUS_SUCCESS == status) {
5775 struct ieee80211_channel *chan;
5776 int freq;
5777 int chan_no = roam_info->pBssDesc->channelId;
5778
5779 if (chan_no <= 14)
5780 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005781 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305782 else
5783 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005784 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305785
5786 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5787 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5788 roam_info->u.pConnectedProfile->SSID.ssId,
5789 roam_info->u.pConnectedProfile->SSID.length);
5790 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305791
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305792 if (hdd_fils_update_connect_results(dev, bssid, bss,
5793 roam_info, req_ie, req_ie_len, resp_ie,
5794 resp_ie_len, status, gfp, connect_timeout,
5795 timeout_reason) != 0) {
5796 hdd_connect_bss(dev, bssid, bss, req_ie,
5797 req_ie_len, resp_ie, resp_ie_len,
5798 status, gfp, connect_timeout, timeout_reason);
5799 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305800
Jingxiang Geb49aa302018-01-17 20:54:15 +08005801 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005802 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305803}
5804#else
5805void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005806 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305807 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305808 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305809 bool connect_timeout,
5810 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305811{
Jeff Johnson9d295242017-08-29 14:39:48 -07005812 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005813 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305814
Anurag Chouhanc4092922016-09-08 15:56:11 +05305815 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5816 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005817
Jingxiang Geb49aa302018-01-17 20:54:15 +08005818 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005819 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305820}
5821#endif
5822
Jeff Johnsond9952752018-04-18 12:15:35 -07005823int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
5824 uint32_t bandwidth)
5825{
5826 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5827 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5828 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
5829 QDF_STATUS status;
5830 tHalHandle hal_hdl = hdd_ctx->hHal;
5831 struct qdf_mac_addr bssid;
5832 struct csr_roam_profile roam_profile;
5833 struct ch_params ch_params;
5834
5835 if (QDF_GLOBAL_MONITOR_MODE != hdd_get_conparam()) {
5836 hdd_err("Not supported, device is not in monitor mode");
5837 return -EINVAL;
5838 }
5839
5840 hdd_debug("Set monitor mode Channel %d", chan);
5841 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
5842 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
5843 roam_profile.ChannelInfo.numOfChannels = 1;
5844 roam_profile.phyMode = ch_info->phy_mode;
5845 roam_profile.ch_params.ch_width = bandwidth;
5846 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
5847
5848 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
5849 QDF_MAC_ADDR_SIZE);
5850
5851 ch_params.ch_width = bandwidth;
5852 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
5853 if (ch_params.ch_width == CH_WIDTH_INVALID) {
5854 hdd_err("Invalid capture channel or bandwidth for a country");
5855 return -EINVAL;
5856 }
5857 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
5858 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
5859 hdd_err("Failed to change hw mode");
5860 return -EINVAL;
5861 }
5862
5863 status = sme_roam_channel_change_req(hal_hdl, bssid, &ch_params,
5864 &roam_profile);
5865 if (status) {
5866 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
5867 status);
5868 }
5869
5870 adapter->mon_chan = chan;
5871 adapter->mon_bandwidth = bandwidth;
5872 return qdf_status_to_os_return(status);
5873}
Anurag Chouhanc4092922016-09-08 15:56:11 +05305874
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005875QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005876{
Jeff Johnson9d295242017-08-29 14:39:48 -07005877 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005878#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005879 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005880#endif
5881 eConnectionState connState;
5882
Dustin Brown491d54b2018-03-14 12:39:11 -07005883 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005884
Dustin Brown920397d2017-12-13 16:27:50 -08005885 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305886 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005887 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305888
Yue Ma42654682018-01-11 16:55:24 -08005889 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5890 hdd_device_mode_to_string(adapter->device_mode),
5891 adapter->device_mode);
5892
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005893 hdd_wmm_init(adapter);
5894
5895 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005896 case QDF_STA_MODE:
5897 case QDF_P2P_CLIENT_MODE:
5898 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005899
5900 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5901 ->conn_info.connState;
5902
Krunal Sonib51eec72017-11-20 21:53:01 -08005903 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005904 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005905 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005906
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005907 /* Indicate disconnect event to supplicant
5908 * if associated previously
5909 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005910 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005911 eConnectionState_IbssConnected == connState ||
5912 eConnectionState_NotConnected == connState ||
5913 eConnectionState_IbssDisconnected == connState ||
5914 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005915 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005916
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005917 memset(&wrqu, '\0', sizeof(wrqu));
5918 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5919 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5920 wireless_send_event(adapter->dev, SIOCGIWAP,
5921 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005922 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005923 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005924
5925 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305926 wlan_hdd_cfg80211_indicate_disconnect(
5927 adapter->dev, false,
5928 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005929 } else if (eConnectionState_Connecting == connState) {
5930 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005931 * Indicate connect failure to supplicant if we
5932 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005933 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305934 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305935 NULL, 0, NULL, 0,
5936 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005937 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005938 }
5939
5940 hdd_register_tx_flow_control(adapter,
5941 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005942 hdd_tx_resume_cb,
5943 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005944
Alok Kumarb64650c2018-03-23 17:05:11 +05305945 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005946 break;
5947
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005948 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005949 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005950 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005952 break;
5953
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005954 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005955#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005956 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005957 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5958#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005959 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005960 /* event supplicant to restart */
5961 cfg80211_del_sta(adapter->dev,
5962 (const u8 *)&bcastMac.bytes[0],
5963 GFP_KERNEL);
5964#endif
5965 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305966 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005967 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305968 hdd_set_mon_rx_cb(adapter->dev);
5969 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5970 adapter->mon_bandwidth);
5971 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005972 default:
5973 break;
5974 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005975 /*
5976 * Action frame registered in one adapter which will
5977 * applicable to all interfaces
5978 */
5979 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980 }
5981
Dustin Browne74003f2018-03-14 12:51:58 -07005982 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005983
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305984 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005985}
5986
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005987QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005988 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005989{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305990 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005991 qdf_list_node_t *node;
5992
5993 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005994
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005995 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005996 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005997 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005998
5999 if (QDF_IS_STATUS_ERROR(status))
6000 return status;
6001
6002 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6003
6004 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006005}
6006
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006007QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006008 struct hdd_adapter *current_adapter,
6009 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006010{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306011 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006012 qdf_list_node_t *node;
6013
6014 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006015
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006016 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006017 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006018 &current_adapter->node,
6019 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006020 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006021
6022 if (QDF_IS_STATUS_ERROR(status))
6023 return status;
6024
6025 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6026
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006027 return status;
6028}
6029
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006030QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006031 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006032{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306033 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006034
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006035 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006036 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006037 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006038
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006039 return status;
6040}
6041
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006042QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006043 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306045 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006046 qdf_list_node_t *node;
6047
6048 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006049
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006050 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006051 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006052 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006053
6054 if (QDF_IS_STATUS_ERROR(status))
6055 return status;
6056
6057 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6058
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006059 return status;
6060}
6061
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006062QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006063 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006064{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306065 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006066
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006067 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006068 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006069 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006070
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006071 return status;
6072}
6073
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006074QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006075 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006076{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306077 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006078
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006079 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006080 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006081 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006082
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006083 return status;
6084}
6085
Jeff Johnson9d295242017-08-29 14:39:48 -07006086struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006087 tSirMacAddr macAddr)
6088{
Jeff Johnson9d295242017-08-29 14:39:48 -07006089 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006090
Dustin Brown920397d2017-12-13 16:27:50 -08006091 hdd_for_each_adapter(hdd_ctx, adapter) {
6092 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6093 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006094 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006095 }
6096
6097 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006098}
6099
Jeff Johnson9d295242017-08-29 14:39:48 -07006100struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006101 uint32_t vdev_id)
6102{
Jeff Johnson9d295242017-08-29 14:39:48 -07006103 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006104
Dustin Brown920397d2017-12-13 16:27:50 -08006105 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006106 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006107 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006108 }
6109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006110 return NULL;
6111}
6112
Abhishek Singh7996eb72015-12-30 17:24:02 +05306113/**
6114 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6115 * the sessionid
6116 * @hdd_ctx: hdd context.
6117 * @sme_session_id: sme session is for the adapter to get.
6118 *
6119 * This function is used to get the adapter with provided session id
6120 *
6121 * Return: adapter pointer if found
6122 *
6123 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006124struct hdd_adapter *
6125hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6126 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306127{
Jeff Johnson9d295242017-08-29 14:39:48 -07006128 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306129
Dustin Brown920397d2017-12-13 16:27:50 -08006130 hdd_for_each_adapter(hdd_ctx, adapter) {
6131 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306132 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306133 }
Dustin Brown920397d2017-12-13 16:27:50 -08006134
Abhishek Singh7996eb72015-12-30 17:24:02 +05306135 return NULL;
6136}
6137
Jeff Johnson9d295242017-08-29 14:39:48 -07006138struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006139 const char *iface_name)
6140{
Jeff Johnson9d295242017-08-29 14:39:48 -07006141 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006142
Dustin Brown920397d2017-12-13 16:27:50 -08006143 hdd_for_each_adapter(hdd_ctx, adapter) {
6144 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006145 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006146 }
Dustin Brown920397d2017-12-13 16:27:50 -08006147
Naveen Rawat4edb6822017-04-12 10:09:17 -07006148 return NULL;
6149}
6150
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006151/**
6152 * hdd_get_adapter() - to get adapter matching the mode
6153 * @hdd_ctx: hdd context
6154 * @mode: adapter mode
6155 *
6156 * This routine will return the pointer to adapter matching
6157 * with the passed mode.
6158 *
6159 * Return: pointer to adapter or null
6160 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006161struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006162 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006163{
Jeff Johnson9d295242017-08-29 14:39:48 -07006164 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006165
Dustin Brown920397d2017-12-13 16:27:50 -08006166 hdd_for_each_adapter(hdd_ctx, adapter) {
6167 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006169 }
6170
6171 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006172}
6173
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306174enum tQDF_ADAPTER_MODE hdd_get_device_mode(uint32_t session_id)
6175{
6176 struct hdd_context *hdd_ctx;
6177 struct hdd_adapter *adapter;
6178
6179 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6180 if (!hdd_ctx) {
6181 hdd_err("Invalid HDD context");
6182 return QDF_MAX_NO_OF_MODE;
6183 }
6184
6185 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6186 if (!adapter) {
6187 hdd_err("Invalid HDD adapter");
6188 return QDF_MAX_NO_OF_MODE;
6189 }
6190
6191 return adapter->device_mode;
6192}
6193
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006194/**
6195 * hdd_get_operating_channel() - return operating channel of the device mode
6196 * @hdd_ctx: Pointer to the HDD context.
6197 * @mode: Device mode for which operating channel is required.
6198 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006199 * QDF_STA_MODE,
6200 * QDF_P2P_CLIENT_MODE,
6201 * QDF_SAP_MODE,
6202 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006203 *
6204 * This API returns the operating channel of the requested device mode
6205 *
6206 * Return: channel number. "0" id the requested device is not found OR it is
6207 * not connected.
6208 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006209uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006210 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211{
Jeff Johnson9d295242017-08-29 14:39:48 -07006212 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006213 uint8_t operatingChannel = 0;
6214
Dustin Brown920397d2017-12-13 16:27:50 -08006215 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006216 if (mode == adapter->device_mode) {
6217 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006218 case QDF_STA_MODE:
6219 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220 if (hdd_conn_is_connected
6221 (WLAN_HDD_GET_STATION_CTX_PTR
6222 (adapter))) {
6223 operatingChannel =
6224 (WLAN_HDD_GET_STATION_CTX_PTR
6225 (adapter))->conn_info.
6226 operationChannel;
6227 }
6228 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006229 case QDF_SAP_MODE:
6230 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006231 /* softap connection info */
6232 if (test_bit
6233 (SOFTAP_BSS_STARTED,
6234 &adapter->event_flags))
6235 operatingChannel =
6236 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006237 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006238 break;
6239 default:
6240 break;
6241 }
6242
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006243 /* Found the device of interest. break the loop */
6244 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246 }
Dustin Brown920397d2017-12-13 16:27:50 -08006247
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006248 return operatingChannel;
6249}
6250
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006251static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006252 hdd_ctx)
6253{
Jeff Johnson9d295242017-08-29 14:39:48 -07006254 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006255
Dustin Brown491d54b2018-03-14 12:39:11 -07006256 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006257
Dustin Brown920397d2017-12-13 16:27:50 -08006258 hdd_for_each_adapter(hdd_ctx, adapter) {
6259 if (adapter->device_mode == QDF_STA_MODE ||
6260 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6261 adapter->device_mode == QDF_IBSS_MODE ||
6262 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6263 adapter->device_mode == QDF_SAP_MODE ||
6264 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265 wlan_hdd_cfg80211_deregister_frames(adapter);
6266 hdd_unregister_wext(adapter->dev);
6267 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006268 }
6269
Dustin Browne74003f2018-03-14 12:51:58 -07006270 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006271
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306272 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006273}
6274
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006275QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006276{
Jeff Johnson9d295242017-08-29 14:39:48 -07006277 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006278
Dustin Brown491d54b2018-03-14 12:39:11 -07006279 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006280
Dustin Brown920397d2017-12-13 16:27:50 -08006281 hdd_for_each_adapter(hdd_ctx, adapter) {
6282 if (adapter->device_mode == QDF_STA_MODE ||
6283 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6284 adapter->device_mode == QDF_IBSS_MODE ||
6285 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6286 adapter->device_mode == QDF_SAP_MODE ||
6287 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006288 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006289 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306290 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006291 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006292 }
6293
Dustin Browne74003f2018-03-14 12:51:58 -07006294 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006295
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306296 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006297}
6298
Dustin Brownf27bce82016-11-03 12:52:27 -07006299/**
6300 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6301 * adapters
6302 * @hdd_ctx: The HDD context containing the adapters to operate on
6303 *
6304 * return: QDF_STATUS_SUCCESS
6305 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006306static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006307{
Jeff Johnson9d295242017-08-29 14:39:48 -07006308 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006309 int err;
6310
Dustin Brown491d54b2018-03-14 12:39:11 -07006311 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006312
Dustin Brown920397d2017-12-13 16:27:50 -08006313 hdd_for_each_adapter(hdd_ctx, adapter) {
6314 if (adapter->device_mode == QDF_STA_MODE ||
6315 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6316 adapter->device_mode == QDF_IBSS_MODE ||
6317 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6318 adapter->device_mode == QDF_SAP_MODE ||
6319 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006320 err = wlan_hdd_sched_scan_stop(adapter->dev);
6321 if (err)
6322 hdd_err("Unable to stop scheduled scan");
6323 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006324 }
6325
Dustin Browne74003f2018-03-14 12:51:58 -07006326 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006327
6328 return QDF_STATUS_SUCCESS;
6329}
6330
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006331#ifdef WLAN_NS_OFFLOAD
6332/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006333 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006334 * @hdd_ctx: Pointer to hdd context
6335 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006336 * Unregister for IPv6 address change notifications.
6337 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006338 * Return: None
6339 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006340static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006341{
6342 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006343}
6344
6345/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006346 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006347 * @hdd_ctx: Pointer to hdd context
6348 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006349 * Register for IPv6 address change notifications.
6350 *
6351 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006352 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006353static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354{
6355 int ret;
6356
6357 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6358 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006359 if (ret) {
6360 hdd_err("Failed to register IPv6 notifier: %d", ret);
6361 goto out;
6362 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006363
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006364 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006365out:
6366 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006367}
6368#else
6369/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006370 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006371 * @hdd_ctx: Pointer to hdd context
6372 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006373 * Unregister for IPv6 address change notifications.
6374 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006375 * Return: None
6376 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006377static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378{
6379}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006380
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006381/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006382 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006383 * @hdd_ctx: Pointer to hdd context
6384 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006385 * Register for IPv6 address change notifications.
6386 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006387 * Return: None
6388 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006389static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006390{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006391 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006392}
6393#endif
6394
Alok Kumarb64650c2018-03-23 17:05:11 +05306395void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6396{
6397 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6398 adapter->disconnection_in_progress = status;
6399 qdf_mutex_release(&adapter->disconnection_status_lock);
6400 hdd_debug("setting disconnection status: %d", status);
6401}
6402
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006403/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006404 * hdd_register_notifiers - Register netdev notifiers.
6405 * @hdd_ctx: HDD context
6406 *
6407 * Register netdev notifiers like IPv4 and IPv6.
6408 *
6409 * Return: 0 on success and errno on failure
6410 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006411static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006412{
6413 int ret;
6414
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006415 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6416 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306417 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006418
6419 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6420 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6421 if (ret) {
6422 hdd_err("Failed to register IPv4 notifier: %d", ret);
6423 goto unregister_ip6_notifier;
6424 }
6425
Alok Kumarb64650c2018-03-23 17:05:11 +05306426 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6427 if (ret) {
6428 hdd_err("Failed to register netevent notifier: %d",
6429 ret);
6430 goto unregister_inetaddr_notifier;
6431 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006432 return 0;
6433
Alok Kumarb64650c2018-03-23 17:05:11 +05306434unregister_inetaddr_notifier:
6435 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006436unregister_ip6_notifier:
6437 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006438out:
6439 return ret;
6440
6441}
6442
6443/**
6444 * hdd_unregister_notifiers - Unregister netdev notifiers.
6445 * @hdd_ctx: HDD context
6446 *
6447 * Unregister netdev notifiers like IPv4 and IPv6.
6448 *
6449 * Return: None.
6450 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006451void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006452{
Alok Kumarb64650c2018-03-23 17:05:11 +05306453 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006454 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6455
6456 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006457}
6458
6459/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006460 * hdd_exit_netlink_services - Exit netlink services
6461 * @hdd_ctx: HDD context
6462 *
6463 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6464 * nl service.
6465 *
6466 * Return: None.
6467 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006468static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006469{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006470 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006471 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006472 ptt_sock_deactivate_svc();
6473
6474 nl_srv_exit();
6475}
6476
6477/**
6478 * hdd_init_netlink_services- Init netlink services
6479 * @hdd_ctx: HDD context
6480 *
6481 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6482 * nl service.
6483 *
6484 * Return: 0 on success and errno on failure.
6485 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006486static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006487{
6488 int ret;
6489
Ryan Hsuceddceb2016-04-28 10:20:14 -07006490 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006491 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006492 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006493 goto out;
6494 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006495 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006496
Naveen Rawat910726a2017-03-06 11:42:51 -08006497 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006498 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006499 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006500 goto err_nl_srv;
6501 }
6502
6503 ret = ptt_sock_activate_svc();
6504 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006505 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006506 goto err_nl_srv;
6507 }
6508
6509 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006510 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006511 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006512
6513 ret = cnss_diag_activate_service();
6514 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006515 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006516 goto err_close_cesium;
6517 }
6518
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006519 ret = spectral_scan_activate_service();
6520 if (ret) {
6521 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6522 goto err_close_cesium;
6523 }
6524
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006525 return 0;
6526
6527err_close_cesium:
6528 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006529 ptt_sock_deactivate_svc();
6530err_nl_srv:
6531 nl_srv_exit();
6532out:
6533 return ret;
6534}
6535
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006536/**
6537 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6538 * @hdd_ctx: HDD context.
6539 *
6540 * Destroy RX wakelock.
6541 *
6542 * Return: None.
6543 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006544static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006545{
6546 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6547}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006548
6549/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006550 * hdd_rx_wake_lock_create() - Create RX wakelock
6551 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006552 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006553 * Create RX wakelock.
6554 *
6555 * Return: None.
6556 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006557static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006558{
6559 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6560}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006561
6562/**
Houston Hoffman160db392016-10-10 17:37:51 -07006563 * hdd_context_deinit() - Deinitialize HDD context
6564 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006565 *
Houston Hoffman160db392016-10-10 17:37:51 -07006566 * Deinitialize HDD context along with all the feature specific contexts but
6567 * do not free hdd context itself. Caller of this API is supposed to free
6568 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006569 *
Houston Hoffman160db392016-10-10 17:37:51 -07006570 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006571 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006572static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006573{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306574 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6575
Houston Hoffman160db392016-10-10 17:37:51 -07006576 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006577
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006578 hdd_sap_context_destroy(hdd_ctx);
6579
6580 hdd_rx_wake_lock_destroy(hdd_ctx);
6581
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006582 hdd_scan_context_destroy(hdd_ctx);
6583
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006584 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006585
Houston Hoffman160db392016-10-10 17:37:51 -07006586 return 0;
6587}
6588
6589/**
6590 * hdd_context_destroy() - Destroy HDD context
6591 * @hdd_ctx: HDD context to be destroyed.
6592 *
6593 * Free config and HDD context as well as destroy all the resources.
6594 *
6595 * Return: None
6596 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006597static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006598{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006599 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306600
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306601 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6602
Houston Hoffman160db392016-10-10 17:37:51 -07006603 hdd_context_deinit(hdd_ctx);
6604
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306605 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006606 hdd_ctx->config = NULL;
6607
6608 wiphy_free(hdd_ctx->wiphy);
6609}
6610
6611/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306612 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6613 *
6614 * This function is used to destroy bug report lock
6615 *
6616 * Return: None
6617 */
6618static void wlan_destroy_bug_report_lock(void)
6619{
6620 p_cds_contextType p_cds_context;
6621
6622 p_cds_context = cds_get_global_context();
6623 if (!p_cds_context) {
6624 hdd_err("cds context is NULL");
6625 return;
6626 }
6627
6628 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6629}
6630
6631/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632 * hdd_wlan_exit() - HDD WLAN exit function
6633 * @hdd_ctx: Pointer to the HDD Context
6634 *
6635 * This is the driver exit point (invoked during rmmod)
6636 *
6637 * Return: None
6638 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006639static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006640{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006641 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306642 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006643
Dustin Brown491d54b2018-03-14 12:39:11 -07006644 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006645
Arun Khandavallifae92942016-08-01 13:31:08 +05306646 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006647
Prashanth Bhattaab004382016-10-11 16:08:11 -07006648 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006649
6650#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306651 if (QDF_TIMER_STATE_RUNNING ==
6652 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6653 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006654 }
6655
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306656 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306657 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006658 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006659 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006660 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6661 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6662 hdd_ctx->last_acs_channel_list = NULL;
6663 hdd_ctx->num_of_channels = 0;
6664 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006665#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666
Arun Khandavallifae92942016-08-01 13:31:08 +05306667 mutex_lock(&hdd_ctx->iface_change_lock);
6668 driver_status = hdd_ctx->driver_status;
6669 mutex_unlock(&hdd_ctx->iface_change_lock);
6670
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006671 /*
6672 * Powersave Offload Case
6673 * Disable Idle Power Save Mode
6674 */
6675 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006676 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306677 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006678
Arun Khandavallifae92942016-08-01 13:31:08 +05306679 if (driver_status != DRIVER_MODULES_CLOSED) {
6680 hdd_unregister_wext_all_adapters(hdd_ctx);
6681 /*
6682 * Cancel any outstanding scan requests. We are about to close
6683 * all of our adapters, but an adapter structure is what SME
6684 * passes back to our callback function. Hence if there
6685 * are any outstanding scan requests then there is a
6686 * race condition between when the adapter is closed and
6687 * when the callback is invoked. We try to resolve that
6688 * race condition here by canceling any outstanding scans
6689 * before we close the adapters.
6690 * Note that the scans may be cancelled in an asynchronous
6691 * manner, so ideally there needs to be some kind of
6692 * synchronization. Rather than introduce a new
6693 * synchronization here, we will utilize the fact that we are
6694 * about to Request Full Power, and since that is synchronized,
6695 * the expectation is that by the time Request Full Power has
6696 * completed, all scans will be cancelled
6697 */
6698 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006699 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006700 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006701 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006702 }
6703
Arunk Khandavalli830c9692018-03-22 12:17:40 +05306704 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306705 unregister_netdevice_notifier(&hdd_netdev_notifier);
6706
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006707 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306708
Dustin Brown021cecd2017-12-11 13:56:43 -08006709 hdd_driver_memdump_deinit();
6710
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306711 qdf_nbuf_deinit_replenish_timer();
6712
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306713 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6714 hdd_info("Release wakelock for monitor mode!");
6715 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6716 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6717 }
6718
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306719 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6720 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6721 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6722
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006723 /*
6724 * Close CDS
6725 * This frees pMac(HAL) context. There should not be any call
6726 * that requires pMac access after this.
6727 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006728
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006729 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -07006730 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731
Dustin Brownd005ad82018-01-19 10:32:13 -08006732 hdd_close_all_adapters(hdd_ctx, false);
6733
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306734 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306735 /*
6736 * If there is re_init failure wiphy would have already de-registered
6737 * check the wiphy status before un-registering again
6738 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306739 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306740 wiphy_unregister(wiphy);
6741 wlan_hdd_cfg80211_deinit(wiphy);
6742 hdd_lpass_notify_stop(hdd_ctx);
6743 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006744
Arun Khandavallifae92942016-08-01 13:31:08 +05306745 hdd_exit_netlink_services(hdd_ctx);
6746 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306747#ifdef FEATURE_WLAN_CH_AVOID
6748 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6749#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306750
Abhishek Singhe9068f12017-03-31 14:14:52 +05306751 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6752 if (driver_status)
6753 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006754
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006755 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006756}
6757
6758void __hdd_wlan_exit(void)
6759{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006760 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006761
Dustin Brown491d54b2018-03-14 12:39:11 -07006762 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006763
Anurag Chouhan6d760662016-02-20 16:05:43 +05306764 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006765 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006766 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07006767 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006768 return;
6769 }
6770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006771 /* Do all the cleanup before deregistering the driver */
6772 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006773
Dustin Browne74003f2018-03-14 12:51:58 -07006774 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775}
6776
6777#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006778/**
6779 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006780 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006781 *
6782 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6783 * Then new ACS request will do a fresh scan without reusing the cached
6784 * scan information.
6785 *
6786 * Return: void
6787 */
Tang Yingying523322d2017-01-17 23:28:43 +08006788static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006789{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006790 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006791
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006792 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006793 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006794 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6795 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6796 hdd_ctx->last_acs_channel_list = NULL;
6797 hdd_ctx->num_of_channels = 0;
6798 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006799
6800 if (!hdd_ctx->hHal)
6801 return;
6802 sme_scan_flush_result(hdd_ctx->hHal);
6803}
6804#endif
6805
6806#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006807int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6808 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006809{
6810 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306811 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006812 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006813
6814 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6815
6816 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306817 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006818 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306819
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006820 if (!hdd_ctx->hHal)
6821 return -EINVAL;
6822
Jeff Johnsone7672e72017-10-21 15:10:04 -07006823 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006824 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306825 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006826 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006827 return -EINVAL;
6828 }
6829
6830 return 0;
6831}
6832#endif
6833
6834/**
6835 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6836 * @state: state
6837 *
6838 * This function notifies FW with modem power status
6839 *
6840 * Return: 0 if successful, error number otherwise
6841 */
6842int hdd_wlan_notify_modem_power_state(int state)
6843{
6844 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306845 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006846 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006847
Anurag Chouhan6d760662016-02-20 16:05:43 +05306848 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006849 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306850 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006851 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306852
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006853 if (!hdd_ctx->hHal)
6854 return -EINVAL;
6855
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306856 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6857 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006858 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006859 state);
6860 return -EINVAL;
6861 }
6862 return 0;
6863}
6864
6865/**
6866 *
6867 * hdd_post_cds_enable_config() - HDD post cds start config helper
6868 * @adapter - Pointer to the HDD
6869 *
6870 * Return: None
6871 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006872QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006873{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306874 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875
6876 /*
6877 * Send ready indication to the HDD. This will kick off the MAC
6878 * into a 'running' state and should kick off an initial scan.
6879 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306880 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6881 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006882 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6883 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306884 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006885 }
6886
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306887 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888}
6889
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05306890struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
6891{
6892 struct hdd_adapter *adapter;
6893
6894 hdd_for_each_adapter(hdd_ctx, adapter) {
6895 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
6896 return adapter;
6897 }
6898
6899 return NULL;
6900}
6901
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006902/* wake lock APIs for HDD */
6903void hdd_prevent_suspend(uint32_t reason)
6904{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306905 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006906}
6907
6908void hdd_allow_suspend(uint32_t reason)
6909{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306910 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006911}
6912
6913void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6914{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306915 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6916 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006917}
6918
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006919/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006920QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006921{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006922
Amar Singhal6f8592b2017-04-26 14:31:58 -07006923 return sme_init_chan_list(hdd_ctx->hHal,
6924 hdd_ctx->reg.alpha2,
6925 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006926}
6927
6928/**
6929 * hdd_is_5g_supported() - check if hardware supports 5GHz
6930 * @hdd_ctx: Pointer to the hdd context
6931 *
6932 * HDD function to know if hardware supports 5GHz
6933 *
6934 * Return: true if hardware supports 5GHz
6935 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006936bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006937{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006938 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006939 return true;
6940
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006941 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006942 return true;
6943 else
6944 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006945}
6946
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006947static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006948{
6949 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006950 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951
6952 wiphy = hdd_ctx->wiphy;
6953
6954 /*
6955 * The channel information in
6956 * wiphy needs to be initialized before wiphy registration
6957 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006958 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6959 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006960 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006961 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006962 }
6963
6964#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6965 wiphy->wowlan = &wowlan_support_reg_init;
6966#else
6967 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6968 WIPHY_WOWLAN_MAGIC_PKT |
6969 WIPHY_WOWLAN_DISCONNECT |
6970 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6971 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6972 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6973 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6974 WIPHY_WOWLAN_RFKILL_RELEASE;
6975
6976 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6977 WOW_MAX_FILTERS_PER_LIST);
6978 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6979 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6980#endif
6981
6982 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006983 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306984 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006985 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306986 return ret_val;
6987 }
6988
Amar Singhal2d812012018-02-03 15:06:47 +08006989 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006990
Amar Singhale4f28ee2015-10-21 14:36:56 -07006991 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006992}
6993
Mohit Khannaca4173b2017-09-12 21:52:19 -07006994#ifdef MSM_PLATFORM
6995/**
6996 * hdd_display_periodic_stats() - Function to display periodic stats
6997 * @hdd_ctx - handle to hdd context
6998 * @bool data_in_interval - true, if data detected in bw time interval
6999 *
7000 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7001 * Stats show up in wlan driver logs.
7002 *
7003 * Returns: None
7004 */
7005static inline
7006void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7007 bool data_in_interval)
7008{
7009 static u32 counter;
7010 static bool data_in_time_period;
7011 ol_txrx_pdev_handle pdev;
7012
7013 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7014 return;
7015
7016 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7017 if (!pdev) {
7018 hdd_err("pdev is NULL");
7019 return;
7020 }
7021
7022 counter++;
7023 if (data_in_interval)
7024 data_in_time_period = data_in_interval;
7025
7026 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7027 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7028 if (data_in_time_period) {
7029 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7030 CDP_TXRX_PATH_STATS,
7031 QDF_STATS_VERBOSITY_LEVEL_LOW);
7032 wlan_hdd_display_netif_queue_history
7033 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7034 qdf_dp_trace_dump_stats();
7035 }
7036 counter = 0;
7037 data_in_time_period = false;
7038 }
7039}
7040
Ravi Joshie2331e82015-07-01 18:18:54 -07007041/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007042 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007043 * @hdd_ctx - handle to hdd context
7044 * @tx_packets - transmit packet count
7045 * @rx_packets - receive packet count
7046 *
7047 * The function controls the bus bandwidth and dynamic control of
7048 * tcp delayed ack configuration
7049 *
7050 * Returns: None
7051 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007052
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007053static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007054 const uint64_t tx_packets,
7055 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007056{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007057 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08007058 uint64_t temp_rx = 0;
7059 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007060 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007061 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007062 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007063 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007064 uint16_t index = 0;
7065 bool vote_level_change = false;
7066 bool rx_level_change = false;
7067 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007068
Mohit Khannaca4173b2017-09-12 21:52:19 -07007069 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007070 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007071 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007072 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007073 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007074 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007075 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007076 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007078 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007079 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7080 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007081 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007082 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007083 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05307084 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307085 if (hdd_ctx->hbw_requested) {
7086 pld_remove_pm_qos(hdd_ctx->parent_dev);
7087 hdd_ctx->hbw_requested = false;
7088 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05307089 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007090 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007091 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307092 if (!hdd_ctx->hbw_requested) {
7093 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7094 hdd_ctx->hbw_requested = true;
7095 }
7096
Nirav Shah3bbfa512016-05-12 16:43:49 +05307097 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007098 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007099 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07007100 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007101 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007102
Mohit Khannaf8f96822017-05-17 17:11:59 -07007103 qdf_dp_trace_throttle_live_mode(
7104 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
7105
Mohit Khannae71e2262015-11-10 09:37:24 -08007106 /* fine-tuning parameters for RX Flows */
7107 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
7108
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007109 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007110
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307111 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
7112 hdd_disable_lro_for_low_tput(hdd_ctx, true);
7113 else
7114 hdd_disable_lro_for_low_tput(hdd_ctx, false);
7115
Ravi Joshifed83572016-10-07 16:20:37 -07007116 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
7117 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7118 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7119 next_rx_level = WLAN_SVC_TP_HIGH;
7120 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007121 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007122 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007123 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007124 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007125
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007126 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007127 struct wlan_rx_tp_data rx_tp_data = {0};
7128
Ravi Joshie2331e82015-07-01 18:18:54 -07007129 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130 next_rx_level, temp_rx);
7131 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007132 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007133 /* Send throughput indication only if it is enabled.
7134 * Disabling tcp_del_ack will revert the tcp stack behavior
7135 * to default delayed ack. Note that this will disable the
7136 * dynamic delayed ack mechanism across the system
7137 */
7138 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007139 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7140
Mohit Khanna6272fb682017-04-13 09:34:36 -07007141 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7142 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7143
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007144 rx_tp_data.level = next_rx_level;
7145 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7146 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7147 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007148 }
7149
Mohit Khannae71e2262015-11-10 09:37:24 -08007150 /* fine-tuning parameters for TX Flows */
7151 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7152 hdd_ctx->prev_tx = tx_packets;
7153 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7154 next_tx_level = WLAN_SVC_TP_HIGH;
7155 else
7156 next_tx_level = WLAN_SVC_TP_LOW;
7157
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007158 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7159 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007160 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7161 next_tx_level, temp_tx);
7162 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007163 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307164 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7165 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007166 &next_tx_level,
7167 sizeof(next_tx_level));
7168 }
7169
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007170 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007171 if (vote_level_change || tx_level_change || rx_level_change) {
7172 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7173 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7174 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7175 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7176 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7177 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7178 hdd_ctx->hdd_txrx_hist_idx++;
7179 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7180 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007181
7182 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007183}
7184
7185#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307186static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007187{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007188 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307189 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07007190 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307191 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307192 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7193 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007194 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307195 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007196 bool connected = false;
7197 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7198
Prashanth Bhattaab004382016-10-11 16:08:11 -07007199 if (wlan_hdd_validate_context(hdd_ctx))
7200 return;
7201
Jeff Johnson214671b2017-10-30 19:45:23 -07007202 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007203 goto restart_timer;
7204
Dustin Brown920397d2017-12-13 16:27:50 -08007205 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307206 /*
7207 * Validate magic so we don't end up accessing
7208 * an invalid adapter.
7209 */
7210 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7211 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007212
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007213 if ((adapter->device_mode == QDF_STA_MODE ||
7214 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007215 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7216 != eConnectionState_Associated) {
7217
7218 continue;
7219 }
7220
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007221 if ((adapter->device_mode == QDF_SAP_MODE ||
7222 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007223 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007224
7225 continue;
7226 }
7227
7228 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7229 adapter->prev_tx_packets);
7230 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7231 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307232
7233 if (adapter->device_mode == QDF_SAP_MODE ||
7234 adapter->device_mode == QDF_P2P_GO_MODE ||
7235 adapter->device_mode == QDF_IBSS_MODE) {
7236
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007237 ret = cdp_get_intra_bss_fwd_pkts_count(
7238 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007239 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307240 &fwd_tx_packets, &fwd_rx_packets);
7241 if (ret == A_OK) {
7242 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7243 fwd_tx_packets,
7244 adapter->prev_fwd_tx_packets);
7245 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7246 fwd_tx_packets,
7247 adapter->prev_fwd_rx_packets);
7248 }
7249 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007250
7251 total_rx += adapter->stats.rx_packets;
7252 total_tx += adapter->stats.tx_packets;
7253
7254 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7255 adapter->prev_tx_packets = adapter->stats.tx_packets;
7256 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307257 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7258 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007259 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7260 connected = true;
7261 }
7262
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307263 /* add intra bss forwarded tx and rx packets */
7264 tx_packets += fwd_tx_packets_diff;
7265 rx_packets += fwd_rx_packets_diff;
7266
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05307267 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7268 &ipa_rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007269 tx_packets += (uint64_t)ipa_tx_packets;
7270 rx_packets += (uint64_t)ipa_rx_packets;
7271
7272 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007273 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007274 return;
7275 }
7276
Yuanyuan Liu13738502016-04-06 17:41:37 -07007277 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007278
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +05307279 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05307280 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007281
Jingxiang Gec64e1932017-08-22 14:38:59 +08007282restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007283 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007284 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007285 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307286 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007287 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007288 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007289}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007290
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307291/**
7292 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7293 * @arg: Argument of timer function
7294 *
7295 * Schedule a workqueue in this function where all the processing is done.
7296 *
7297 * Return: None.
7298 */
7299static void __hdd_bus_bw_cbk(void *arg)
7300{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007301 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307302
7303 if (wlan_hdd_validate_context(hdd_ctx))
7304 return;
7305
7306 schedule_work(&hdd_ctx->bus_bw_work);
7307}
7308
7309/**
7310 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7311 * @arg: Argument of timer function
7312 *
7313 * Return: None.
7314 */
7315static void hdd_bus_bw_cbk(void *arg)
7316{
7317 cds_ssr_protect(__func__);
7318 __hdd_bus_bw_cbk(arg);
7319 cds_ssr_unprotect(__func__);
7320}
7321
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007322int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007323{
7324 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307325 INIT_WORK(&hdd_ctx->bus_bw_work,
7326 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007327 hdd_ctx->bus_bw_timer_running = false;
7328 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307329 qdf_timer_init(NULL,
7330 &hdd_ctx->bus_bw_timer,
7331 hdd_bus_bw_cbk, (void *)hdd_ctx,
7332 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007333
7334 return 0;
7335}
7336
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007337void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007338{
Dustin Brownfce08d12017-01-17 16:29:38 -08007339 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007340 hdd_reset_tcp_delack(hdd_ctx);
7341
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007342 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307343 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307344 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007345 hdd_ctx->bus_bw_timer_running = false;
7346 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007347}
Lin Baic5c06882017-09-21 13:58:43 +08007348
7349void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7350{
7351 if (hdd_ctx)
7352 cancel_work_sync(&hdd_ctx->bus_bw_work);
7353}
jiadcdaf9bd2017-10-26 12:20:21 +08007354
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007355#endif
7356
7357/**
Nirav Shahed34b212016-04-25 10:59:16 +05307358 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7359 * @hdd_ctx: hdd context
7360 *
7361 * Return: 0 for success or error code
7362 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007363static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307364{
7365 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7366 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7367 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007368 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307369 return -ENOMEM;
7370 }
7371 return 0;
7372}
7373
7374/**
7375 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7376 * @hdd_ctx: hdd context
7377 *
7378 * Return: none
7379 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007380void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307381{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307382 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7383 return;
7384
7385 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7386 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307387}
7388
Nirav Shahda008342016-05-17 18:50:40 +05307389static uint8_t *convert_level_to_string(uint32_t level)
7390{
7391 switch (level) {
7392 /* initialize the wlan sub system */
7393 case WLAN_SVC_TP_NONE:
7394 return "NONE";
7395 case WLAN_SVC_TP_LOW:
7396 return "LOW";
7397 case WLAN_SVC_TP_MEDIUM:
7398 return "MED";
7399 case WLAN_SVC_TP_HIGH:
7400 return "HIGH";
7401 default:
7402 return "INVAL";
7403 }
7404}
7405
Nirav Shahed34b212016-04-25 10:59:16 +05307406
7407/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007408 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7409 * @hdd_ctx: hdd context
7410 *
7411 * Return: none
7412 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007413void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007414{
7415 int i;
7416
7417#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007418 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307419 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007420 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007421 hdd_ctx->config->busBandwidthHighThreshold,
7422 hdd_ctx->config->busBandwidthMediumThreshold,
7423 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007424 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307425 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007426 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007427 hdd_ctx->config->tcpDelackThresholdHigh,
7428 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007429 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307430 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007431#endif
7432
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007433 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307434 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7435
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007436 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007437
7438 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007439 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007440 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007441 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7442 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7443 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7444 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7445 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007446 hdd_ctx->hdd_txrx_hist[i].
7447 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007448 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007449 hdd_ctx->hdd_txrx_hist[i].
7450 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007451 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007452 hdd_ctx->hdd_txrx_hist[i].
7453 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007454 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007455}
7456
7457/**
7458 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7459 * @hdd_ctx: hdd context
7460 *
7461 * Return: none
7462 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007463void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007464{
7465 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307466 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7467 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007468}
7469
Mohit Khannaca4173b2017-09-12 21:52:19 -07007470/* length of the netif queue log needed per adapter */
7471#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7472
7473/**
7474 *
7475 * hdd_display_netif_queue_history_compact() - display compact netifq history
7476 * @hdd_ctx: hdd context
7477 *
7478 * Return: none
7479 */
7480static void
7481hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7482{
7483 int adapter_num = 0;
7484 int i;
7485 int bytes_written;
7486 u32 tbytes;
7487 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007488 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007489 char *comb_log_str;
7490 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007491 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007492
jiadbdefb252018-01-03 14:27:06 +08007493 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7494 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7495 if (!comb_log_str) {
7496 hdd_err("failed to alloc comb_log_str");
7497 return;
7498 }
7499
Mohit Khannaca4173b2017-09-12 21:52:19 -07007500 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007501
Dustin Brown920397d2017-12-13 16:27:50 -08007502 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007503 curr_time = qdf_system_ticks();
7504 total = curr_time - adapter->start_time;
7505 delta = curr_time - adapter->last_time;
7506
7507 if (adapter->pause_map) {
7508 pause = adapter->total_pause_time + delta;
7509 unpause = adapter->total_unpause_time;
7510 } else {
7511 unpause = adapter->total_unpause_time + delta;
7512 pause = adapter->total_pause_time;
7513 }
7514
7515 tbytes = 0;
7516 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7517 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7518 if (adapter->queue_oper_stats[i].pause_count == 0)
7519 continue;
7520 tbytes +=
7521 snprintf(
7522 &temp_str[tbytes],
7523 (tbytes >= sizeof(temp_str) ?
7524 0 : sizeof(temp_str) - tbytes),
7525 "%d(%d,%d) ",
7526 i,
7527 adapter->queue_oper_stats[i].
7528 pause_count,
7529 adapter->queue_oper_stats[i].
7530 unpause_count);
7531 }
7532 if (tbytes >= sizeof(temp_str))
7533 hdd_warn("log truncated");
7534
7535 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007536 bytes_written >= comb_log_str_size ? 0 :
7537 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007538 "[%d %d] (%d) %u/%ums %s|",
7539 adapter->session_id, adapter->device_mode,
7540 adapter->pause_map,
7541 qdf_system_ticks_to_msecs(pause),
7542 qdf_system_ticks_to_msecs(total),
7543 temp_str);
7544
Mohit Khannaca4173b2017-09-12 21:52:19 -07007545 adapter_num++;
7546 }
7547
7548 /* using QDF_TRACE to avoid printing function name */
7549 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7550 "STATS |%s", comb_log_str);
7551
jiadbdefb252018-01-03 14:27:06 +08007552 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007553 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007554
7555 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007556}
7557
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007558/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007559 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007560 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007561 *
7562 * Return: none
7563 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007564void
7565wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7566 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007567{
7568
Jeff Johnson9d295242017-08-29 14:39:48 -07007569 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007570 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307571 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007572
Mohit Khannaca4173b2017-09-12 21:52:19 -07007573 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7574 hdd_display_netif_queue_history_compact(hdd_ctx);
7575 return;
7576 }
7577
Dustin Brown920397d2017-12-13 16:27:50 -08007578 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007579 hdd_debug("Netif queue operation statistics:");
7580 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007581 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007582 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307583 curr_time = qdf_system_ticks();
7584 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307585 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307586 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307587 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307588 unpause = adapter->total_unpause_time;
7589 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307590 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307591 pause = adapter->total_pause_time;
7592 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007593 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307594 qdf_system_ticks_to_msecs(total),
7595 qdf_system_ticks_to_msecs(pause),
7596 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007597 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007598
Nirav Shahda008342016-05-17 18:50:40 +05307599 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7600 qdf_time_t pause_delta = 0;
7601
7602 if (adapter->pause_map & (1 << i))
7603 pause_delta = delta;
7604
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007605 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007606 hdd_debug("%s: %d: %d: %ums",
7607 hdd_reason_type_to_string(i),
7608 adapter->queue_oper_stats[i].pause_count,
7609 adapter->queue_oper_stats[i].unpause_count,
7610 qdf_system_ticks_to_msecs(
7611 adapter->queue_oper_stats[i].total_pause_time +
7612 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007613 }
7614
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007615 hdd_debug("Netif queue operation history:");
7616 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307617 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7618
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007619 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007620
7621 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007622 /* using hdd_log to avoid printing function name */
7623 if (adapter->queue_oper_history[i].time == 0)
7624 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007625 hdd_debug("%d: %u: %s: %s: %x",
7626 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007628 hdd_action_type_to_string(
7629 adapter->queue_oper_history[i].netif_action),
7630 hdd_reason_type_to_string(
7631 adapter->queue_oper_history[i].netif_reason),
7632 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007633 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007634 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007635}
7636
7637/**
7638 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7639 * @hdd_ctx: hdd context
7640 *
7641 * Return: none
7642 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007643void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007644{
Jeff Johnson9d295242017-08-29 14:39:48 -07007645 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007646
Dustin Brown920397d2017-12-13 16:27:50 -08007647 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307648 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007649 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307650 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007651 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307652 adapter->history_index = 0;
7653 adapter->start_time = adapter->last_time = qdf_system_ticks();
7654 adapter->total_pause_time = 0;
7655 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007656 }
7657}
7658
7659/**
7660 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7661 * @halHandle: Hal handle
7662 * @pContext: Pointer to the context
7663 * @sessionId: Session ID
7664 * @scanId: Scan ID
7665 * @status: Status
7666 *
7667 * This is the callback to be executed when 11d scan is completed to flush out
7668 * the scan results
7669 *
7670 * 11d scan is done during driver load and is a passive scan on all
7671 * channels supported by the device, 11d scans may find some APs on
7672 * frequencies which are forbidden to be used in the regulatory domain
7673 * the device is operating in. If these APs are notified to the supplicant
7674 * it may try to connect to these APs, thus flush out all the scan results
7675 * which are present in SME after 11d scan is done.
7676 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307677 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007678 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307679static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007680 uint8_t sessionId, uint32_t scanId,
7681 eCsrScanStatus status)
7682{
Dustin Brown491d54b2018-03-14 12:39:11 -07007683 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007684
7685 sme_scan_flush_result(halHandle);
7686
Dustin Browne74003f2018-03-14 12:51:58 -07007687 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007688
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307689 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007690}
7691
7692#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7693/**
7694 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7695 * @hdd_ctx: hdd global context
7696 *
7697 * Return: none
7698 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007699static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007700{
7701 uint8_t i;
7702
7703 mutex_init(&hdd_ctx->op_ctx.op_lock);
7704 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7705 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7706 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7707 }
7708}
7709#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007710static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007711{
7712}
7713#endif
7714
Yingying Tang95409972016-10-20 15:16:15 +08007715#ifdef WLAN_FEATURE_WOW_PULSE
7716/**
7717 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007718 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007719 * @enable: enable or disable this behaviour
7720 *
7721 * Return: int
7722 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007723static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007724{
7725 struct hdd_config *pcfg_ini = phddctx->config;
7726 struct wow_pulse_mode wow_pulse_set_info;
7727 QDF_STATUS status;
7728
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007729 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007730
7731 if (false == phddctx->config->wow_pulse_support)
7732 return 0;
7733
7734 /* prepare the request to send to SME */
7735 if (enable == true) {
7736 wow_pulse_set_info.wow_pulse_enable = true;
7737 wow_pulse_set_info.wow_pulse_pin =
7738 pcfg_ini->wow_pulse_pin;
7739 wow_pulse_set_info.wow_pulse_interval_low =
7740 pcfg_ini->wow_pulse_interval_low;
7741 wow_pulse_set_info.wow_pulse_interval_high =
7742 pcfg_ini->wow_pulse_interval_high;
7743 } else {
7744 wow_pulse_set_info.wow_pulse_enable = false;
7745 wow_pulse_set_info.wow_pulse_pin = 0;
7746 wow_pulse_set_info.wow_pulse_interval_low = 0;
7747 wow_pulse_set_info.wow_pulse_interval_high = 0;
7748 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007749 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007750 wow_pulse_set_info.wow_pulse_enable,
7751 wow_pulse_set_info.wow_pulse_pin,
7752 wow_pulse_set_info.wow_pulse_interval_low,
7753 wow_pulse_set_info.wow_pulse_interval_high);
7754
7755 status = sme_set_wow_pulse(&wow_pulse_set_info);
7756 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007757 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007758 return -EIO;
7759 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007760 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007761 return 0;
7762}
7763#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007764static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007765{
7766 return 0;
7767}
7768#endif
7769
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007770#ifdef WLAN_FEATURE_FASTPATH
7771/**
7772 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7773 * @hdd_cfg: hdd config
7774 * @context: lower layer context
7775 *
7776 * Return: none
7777 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307778void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007779 void *context)
7780{
7781 if (hdd_cfg->fastpath_enable)
7782 hif_enable_fastpath(context);
7783}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007784#endif
7785
Yuanyuan Liu13738502016-04-06 17:41:37 -07007786#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007787/**
7788 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007789 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007790 * @level: thermal level
7791 *
7792 * Change IPA data path to SW path when the thermal throttle level greater
7793 * than 0, and restore the original data path when throttle level is 0
7794 *
7795 * Return: none
7796 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007797static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007798{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007799 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007800
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007801 /* Change IPA to SW path when throttle level greater than 0 */
7802 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307803 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007804 else
7805 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307806 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007807}
7808
7809/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307810 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7811 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307812 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007813 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307814 * Get a safe channel to restart SAP. PCL already takes into account the
7815 * unsafe channels. So, the PCL is validated with the ACS range to provide
7816 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007817 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307818 * Return: Channel number to restart SAP in case of success. In case of any
7819 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007820 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307821static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007822 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007823{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307824 struct sir_pcl_list pcl;
7825 QDF_STATUS status;
7826 uint32_t i, j;
7827 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007828 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307829 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007830 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007831
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307832 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7833 if (!hdd_ctx) {
7834 hdd_err("invalid HDD context");
7835 return INVALID_CHANNEL_ID;
7836 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007837
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307838 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7839 if (!hal_handle) {
7840 hdd_err("invalid HAL handle");
7841 return INVALID_CHANNEL_ID;
7842 }
7843
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007844 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7845 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007846 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7847 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307848 if (QDF_IS_STATUS_ERROR(status)) {
7849 hdd_err("Get PCL failed");
7850 return INVALID_CHANNEL_ID;
7851 }
7852
Frank Liudc2cefb2017-06-21 15:38:18 +08007853 /*
7854 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7855 * channel is unsafe channel, the pcl may be empty, instead of return,
7856 * try to choose a safe channel from acs range.
7857 */
7858 if (!pcl.pcl_len)
7859 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307860
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007861 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007862 adapter->session.ap.sap_config.acs_cfg.start_ch,
7863 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307864
7865 /* PCL already takes unsafe channel into account */
7866 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007867 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307868 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007869 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307870 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007871 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007872 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307873 return pcl.pcl_list[i];
7874 }
7875 }
7876
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007877 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307878
7879 /* Try for safe channel from all valid channel */
7880 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007881 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7882 &pcl.pcl_len);
7883 if (ret) {
7884 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307885 return INVALID_CHANNEL_ID;
7886 }
7887
7888 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007889 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307890 found = false;
7891 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007892 if (pcl.pcl_list[i] ==
7893 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007894 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307895 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007896 break;
7897 }
7898 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307899
7900 if (found)
7901 continue;
7902
7903 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007904 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307905 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007906 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007907 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307908 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007909 }
7910 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307911
7912 return INVALID_CHANNEL_ID;
7913}
Nirav Shaheb017be2018-02-15 11:20:58 +05307914#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307915
7916/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007917 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307918 * @adapter: AP adapter
7919 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007920 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307921 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007922 * Moves the SAP interface by invoking the function which
7923 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307924 *
7925 * Return: None
7926 */
Min Liu2fef5792018-01-19 17:59:42 +08007927void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7928 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307929{
Jeff Johnson87251032017-08-29 13:31:11 -07007930 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307931 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007932 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307933
7934 if (!adapter) {
7935 hdd_err("invalid adapter");
7936 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007937 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307938
7939 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7940
7941 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7942 if (!hal_handle) {
7943 hdd_err("invalid HAL handle");
7944 return;
7945 }
7946
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007947 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7948
Jeff Johnson91df29d2017-10-27 19:29:50 -07007949 hdd_ap_ctx->sap_config.channel = channel;
7950 hdd_ap_ctx->sap_config.ch_params.ch_width =
7951 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307952
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007953 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007954 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307955
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007956 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007957 hdd_ap_ctx->sap_config.channel,
7958 hdd_ap_ctx->sap_config.sec_ch,
7959 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307960
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007961 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007962 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007963 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007964}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307965
Jeff Johnson9d295242017-08-29 14:39:48 -07007966int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307967{
7968 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307969 int status;
7970 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307971
7972 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7973
7974 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007975 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307976 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007977 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307978 }
7979 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007980 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307981 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307982 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007983 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307984 WLAN_VENDOR_ACS_WAIT_TIME);
7985 if (qdf_status != QDF_STATUS_SUCCESS) {
7986 hdd_err("failed to start external acs timer");
7987 return -ENOSPC;
7988 }
7989 /* Update config to application */
7990 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07007991 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307992
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307993 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307994}
7995
Nirav Shaheb017be2018-02-15 11:20:58 +05307996#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307997/**
7998 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7999 * @hdd_ctx: hdd context pointer
8000 *
8001 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8002 * and if ACS is enabled, driver will ask userspace to restart the
8003 * sap. User space on LTE coex indication restart driver.
8004 *
8005 * Return - none
8006 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008007void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308008{
Dustin Brown920397d2017-12-13 16:27:50 -08008009 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308010 uint32_t i;
8011 bool found = false;
8012 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008013
Dustin Brown920397d2017-12-13 16:27:50 -08008014 hdd_for_each_adapter(hdd_ctxt, adapter) {
8015 if (!(adapter->device_mode == QDF_SAP_MODE &&
8016 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008017 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008018 adapter->device_mode,
8019 adapter->session.ap.sap_config.
8020 acs_cfg.acs_mode);
8021 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308022 }
8023
8024 found = false;
8025 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08008026 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05308027 hdd_ctxt->unsafe_channel_list[i]) {
8028 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008029 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08008030 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308031 break;
8032 }
8033 }
8034
8035 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008036 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008037 adapter->session.ap.operating_channel);
8038 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308039 }
8040
Kapil Gupta8878ad92017-02-13 11:56:04 +05308041 if (hdd_ctxt->config->vendor_acs_support &&
8042 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008043 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308044 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008045 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308046 } else
8047 restart_chan =
8048 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008049 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308050 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008051 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308052 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008053 /*
8054 * SAP restart due to unsafe channel. While
8055 * restarting the SAP, make sure to clear
8056 * acs_channel, channel to reset to
8057 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308058 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008059 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308060 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008061 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308062 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008063 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308064 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8065 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008066 hdd_debug("driver to start sap: %d",
8067 hdd_ctxt->config->sap_internal_restart);
8068 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008069 hdd_switch_sap_channel(adapter, restart_chan,
8070 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008071 else
8072 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308073 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308074 }
8075}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308076
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008077/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008078 * hdd_init_channel_avoidance() - Initialize channel avoidance
8079 * @hdd_ctx: HDD global context
8080 *
8081 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008082 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008083 * down to the lower layers. Then subscribe to subsequent channel
8084 * avoidance events.
8085 *
8086 * Return: None
8087 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008088static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008089{
8090 uint16_t unsafe_channel_count;
8091 int index;
8092
Yuanyuan Liu13738502016-04-06 17:41:37 -07008093 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8094 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008095 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008096 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008097
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008098 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008099 hdd_ctx->unsafe_channel_count);
8100
Anurag Chouhan6d760662016-02-20 16:05:43 +05308101 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008102 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008103
8104 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008105 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008106 hdd_ctx->unsafe_channel_list[index]);
8107
8108 }
8109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008110}
Dustin Brown676a2322017-08-15 13:16:13 -07008111
Jeff Johnson9d295242017-08-29 14:39:48 -07008112static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008113 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008114{
8115 uint8_t restart_chan;
8116
8117 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8118 if (!restart_chan) {
8119 hdd_alert("fail to restart SAP");
8120 return;
8121 }
8122
8123 /* SAP restart due to unsafe channel. While restarting
8124 * the SAP, make sure to clear acs_channel, channel to
8125 * reset to 0. Otherwise these settings will override
8126 * the ACS while restart.
8127 */
8128 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008129 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008130
8131 hdd_debug("sending coex indication");
8132
8133 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8134 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008135 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008136}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008137
8138int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8139 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8140{
8141 uint32_t size;
8142 uint16_t *unsafe_list;
8143 uint16_t chan_count;
8144
8145 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8146 return -EINVAL;
8147
8148 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8149 NUM_CHANNELS);
8150 if (chan_count) {
8151 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8152 unsafe_list = qdf_mem_malloc(size);
8153 if (!unsafe_list) {
8154 hdd_err("No memory for unsafe chan list size%d",
8155 size);
8156 return -ENOMEM;
8157 }
8158 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8159 } else {
8160 unsafe_list = NULL;
8161 }
8162
8163 *local_unsafe_list = unsafe_list;
8164 *local_unsafe_list_count = chan_count;
8165
8166 return 0;
8167}
8168
8169bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8170 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8171{
8172 int i, j;
8173
8174 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8175 return true;
8176 if (local_unsafe_list_count == 0)
8177 return false;
8178 for (i = 0; i < local_unsafe_list_count; i++) {
8179 for (j = 0; j < local_unsafe_list_count; j++)
8180 if (local_unsafe_list[i] ==
8181 hdd_ctx->unsafe_channel_list[j])
8182 break;
8183 if (j >= local_unsafe_list_count)
8184 break;
8185 }
8186 if (i >= local_unsafe_list_count) {
8187 hdd_info("unsafe chan list same");
8188 return false;
8189 }
8190
8191 return true;
8192}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008193#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008194static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008195{
8196}
Dustin Brown676a2322017-08-15 13:16:13 -07008197
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008198static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008199{
8200}
Dustin Brown676a2322017-08-15 13:16:13 -07008201
Jeff Johnson9d295242017-08-29 14:39:48 -07008202static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008203 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008204{
8205 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8206}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008207#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008208
8209/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008210 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8211 * user space
8212 * @frame_ind: Management frame data to be informed.
8213 *
8214 * This function is used to indicate management frame to
8215 * user space
8216 *
8217 * Return: None
8218 *
8219 */
8220void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8221{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008222 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008223 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008224 int i;
8225
Rajeev Kumard004abc2016-02-17 12:09:56 -08008226 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008227 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008228
8229 if (0 != wlan_hdd_validate_context(hdd_ctx))
8230 return;
8231
8232 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8233 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8234 adapter =
8235 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8236 if (adapter)
8237 break;
8238 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008239 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8240 hdd_for_each_adapter(hdd_ctx, adapter) {
8241 if ((NULL != adapter) &&
8242 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8243 __hdd_indicate_mgmt_frame(adapter,
8244 frame_ind->frame_len,
8245 frame_ind->frameBuf,
8246 frame_ind->frameType,
8247 frame_ind->rxChan,
8248 frame_ind->rxRssi);
8249 }
8250 }
8251 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008252 } else {
8253 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8254 frame_ind->sessionId);
8255 }
8256
8257 if ((NULL != adapter) &&
8258 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8259 __hdd_indicate_mgmt_frame(adapter,
8260 frame_ind->frame_len,
8261 frame_ind->frameBuf,
8262 frame_ind->frameType,
8263 frame_ind->rxChan,
8264 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008265}
8266
Kapil Gupta8878ad92017-02-13 11:56:04 +05308267void hdd_acs_response_timeout_handler(void *context)
8268{
8269 struct hdd_external_acs_timer_context *timer_context =
8270 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008271 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008272 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308273 uint8_t reason;
8274
Dustin Brown491d54b2018-03-14 12:39:11 -07008275 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308276 if (!timer_context) {
8277 hdd_err("invlaid timer context");
8278 return;
8279 }
8280 adapter = timer_context->adapter;
8281 reason = timer_context->reason;
8282
8283
8284 if ((!adapter) ||
8285 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8286 hdd_err("invalid adapter or adapter has invalid magic");
8287 return;
8288 }
8289 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8290 if (wlan_hdd_validate_context(hdd_ctx))
8291 return;
8292
8293 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8294 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8295 else
8296 return;
8297
8298 hdd_err("ACS timeout happened for %s reason %d",
8299 adapter->dev->name, reason);
8300 switch (reason) {
8301 /* SAP init case */
8302 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8303 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8304 false);
8305 wlan_hdd_cfg80211_start_acs(adapter);
8306 break;
8307 /* DFS detected on current channel */
8308 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8309 wlan_sap_update_next_channel(
8310 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8311 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008312 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308313 break;
8314 /* LTE coex event on current channel */
8315 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8316 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8317 break;
8318 default:
8319 hdd_info("invalid reason for timer invoke");
8320
8321 }
8322}
8323
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008324/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008325 * hdd_override_ini_config - Override INI config
8326 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008327 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008328 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008329 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008330 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008331 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008332static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008333{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008334
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008335 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8336 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008337 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008338 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008339 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008340 if (0 == enable_11d || 1 == enable_11d) {
8341 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008342 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008343 }
Leo Chang11545d62016-10-17 14:53:50 -07008344
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308345 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008346 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008347 hdd_debug("IpaConfig override to %d",
8348 hdd_ctx->config->IpaConfig);
8349 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308350
8351 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8352 !hdd_ctx->config->enable_bcast_probe_rsp) {
8353 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8354 hdd_ctx->config->rssi_assoc_reject_enabled,
8355 hdd_ctx->config->enable_bcast_probe_rsp);
8356 hdd_ctx->config->oce_sta_enabled = 0;
8357 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008358}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008359
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008360/**
8361 * hdd_set_trace_level_for_each - Set trace level for each INI config
8362 * @hdd_ctx - HDD context
8363 *
8364 * Set trace level for each module based on INI config.
8365 *
8366 * Return: None
8367 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008368static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008369{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308370 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8371 hdd_ctx->config->qdf_trace_enable_wdi);
8372 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8373 hdd_ctx->config->qdf_trace_enable_hdd);
8374 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8375 hdd_ctx->config->qdf_trace_enable_sme);
8376 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8377 hdd_ctx->config->qdf_trace_enable_pe);
8378 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8379 hdd_ctx->config->qdf_trace_enable_wma);
8380 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8381 hdd_ctx->config->qdf_trace_enable_sys);
8382 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8383 hdd_ctx->config->qdf_trace_enable_qdf);
8384 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8385 hdd_ctx->config->qdf_trace_enable_sap);
8386 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8387 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8388 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8389 hdd_ctx->config->qdf_trace_enable_bmi);
8390 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8391 hdd_ctx->config->qdf_trace_enable_cfg);
8392 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8393 hdd_ctx->config->qdf_trace_enable_epping);
8394 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8395 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8396 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008397 hdd_ctx->config->qdf_trace_enable_txrx);
8398 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8399 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308400 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8401 hdd_ctx->config->qdf_trace_enable_htc);
8402 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8403 hdd_ctx->config->qdf_trace_enable_hif);
8404 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8405 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8406 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8407 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008408 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8409 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008410 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8411 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008412 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8413 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008414 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8415 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008417 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008418}
8419
8420/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008421 * hdd_context_init() - Initialize HDD context
8422 * @hdd_ctx: HDD context.
8423 *
8424 * Initialize HDD context along with all the feature specific contexts.
8425 *
8426 * return: 0 on success and errno on failure.
8427 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008428static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008429{
8430 int ret;
8431
8432 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8433 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8434
8435 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308436 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008437
8438 init_completion(&hdd_ctx->mc_sus_event_var);
8439 init_completion(&hdd_ctx->ready_to_suspend);
8440
8441 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308442 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008443 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308444
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008445 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008446
8447 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8448
8449 ret = hdd_scan_context_init(hdd_ctx);
8450 if (ret)
8451 goto list_destroy;
8452
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008453 hdd_rx_wake_lock_create(hdd_ctx);
8454
8455 ret = hdd_sap_context_init(hdd_ctx);
8456 if (ret)
8457 goto scan_destroy;
8458
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008459 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8460
8461 hdd_init_offloaded_packets_ctx(hdd_ctx);
8462
8463 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8464 hdd_ctx->config);
8465 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008466 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008467
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308468 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8469 "monitor_mode_wakelock");
8470
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008471 return 0;
8472
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008473sap_destroy:
8474 hdd_sap_context_destroy(hdd_ctx);
8475
8476scan_destroy:
8477 hdd_scan_context_destroy(hdd_ctx);
8478 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008479list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008480 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008481
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008482 return ret;
8483}
8484
8485/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308486 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8487 * @hdd_ctx: pointer to hdd context
8488 *
8489 * Return: status of initialization
8490 * 0 - success
8491 * negative value - failure
8492 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008493static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308494{
8495 int ret;
8496
8497 if (!hdd_ctx->config->probe_req_ie_whitelist)
8498 return 0;
8499
8500 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8501 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8502 hdd_ctx->config->probe_req_ie_whitelist = false;
8503 return -EINVAL;
8504 }
8505
8506 /* parse ini string probe req oui */
8507 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8508 if (ret) {
8509 hdd_err("parsing error: disable ie whitelisting");
8510 hdd_ctx->config->probe_req_ie_whitelist = false;
8511 }
8512
8513 return ret;
8514}
8515
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308516/**
8517 * hdd_iface_change_callback() - Function invoked when stop modules expires
8518 * @priv: pointer to hdd context
8519 *
8520 * This function is invoked when the timer waiting for the interface change
8521 * expires, it shall cut-down the power to wlan and stop all the modules.
8522 *
8523 * Return: void
8524 */
8525static void hdd_iface_change_callback(void *priv)
8526{
8527 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8528 int ret;
8529 int status = wlan_hdd_validate_context(hdd_ctx);
8530
8531 if (status)
8532 return;
8533
Dustin Brown491d54b2018-03-14 12:39:11 -07008534 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308535 hdd_debug("Interface change timer expired close the modules!");
8536 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8537 if (ret)
8538 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008539 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308540}
8541
Nirav Shaheb017be2018-02-15 11:20:58 +05308542#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8543static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8544{
8545 wlan_logging_set_log_to_console(hdd_ctx->config->
8546 wlan_logging_to_console);
8547 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8548}
8549#else
8550static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8551{ }
8552#endif
8553
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308554/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008555 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308556 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008557 *
8558 * Allocate and initialize HDD context. HDD context is allocated as part of
8559 * wiphy allocation and then context is initialized.
8560 *
8561 * Return: HDD context on success and ERR_PTR on failure
8562 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008563static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008564{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308565 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008566 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008567 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008568
Dustin Brown491d54b2018-03-14 12:39:11 -07008569 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008570
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008571 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008572 if (hdd_ctx == NULL) {
8573 ret = -ENOMEM;
8574 goto err_out;
8575 }
8576
Dustin Brown6f427922017-09-19 12:19:00 -07008577 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8578 hdd_iface_change_callback,
8579 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308580
8581 mutex_init(&hdd_ctx->iface_change_lock);
8582
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008583 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308584 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008585
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308586 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008587 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008588 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008589 ret = -ENOMEM;
8590 goto err_free_hdd_context;
8591 }
8592
8593 /* Read and parse the qcom_cfg.ini file */
8594 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308595 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308596 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008597 WLAN_INI_FILE);
8598 ret = -EINVAL;
8599 goto err_free_config;
8600 }
8601
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308602 ie_whitelist_attrs_init(hdd_ctx);
8603
Dustin Brown7f939932017-05-18 15:02:17 -07008604 hdd_debug("setting timer multiplier: %u",
8605 hdd_ctx->config->timer_multiplier);
8606 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8607
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008608
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308609 if (hdd_ctx->config->fhostNSOffload)
8610 hdd_ctx->ns_offload_enable = true;
8611
Abhishek Singh5ea86532016-04-27 14:10:53 +05308612 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8613
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008614 hdd_override_ini_config(hdd_ctx);
8615
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008616 ret = hdd_context_init(hdd_ctx);
8617
8618 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008619 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008620
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008621 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308622 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008623
Anurag Chouhan6d760662016-02-20 16:05:43 +05308624 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008625 goto skip_multicast_logging;
8626
8627 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8628
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008629 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8630 if (ret)
8631 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308632
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008633 ret = hdd_init_netlink_services(hdd_ctx);
8634 if (ret)
8635 goto err_deinit_txrx_histogram;
8636
Nirav Shaheb017be2018-02-15 11:20:58 +05308637 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308638
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008639skip_multicast_logging:
8640 hdd_set_trace_level_for_each(hdd_ctx);
8641
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008642 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8643
Dustin Browne74003f2018-03-14 12:51:58 -07008644 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008645
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008646 return hdd_ctx;
8647
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008648err_deinit_txrx_histogram:
8649 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8650
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008651err_deinit_hdd_context:
8652 hdd_context_deinit(hdd_ctx);
8653
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008654err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308655 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008656
8657err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308658 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008659 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008660
8661err_out:
8662 return ERR_PTR(ret);
8663}
8664
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008665#ifdef WLAN_OPEN_P2P_INTERFACE
8666/**
8667 * hdd_open_p2p_interface - Open P2P interface
8668 * @hdd_ctx: HDD context
8669 * @rtnl_held: True if RTNL lock held
8670 *
8671 * Open P2P interface during probe. This function called to open the P2P
8672 * interface at probe along with STA interface.
8673 *
8674 * Return: 0 on success and errno on failure
8675 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008676static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008677{
Jeff Johnson9d295242017-08-29 14:39:48 -07008678 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008679 uint8_t *p2p_dev_addr;
8680
8681 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8682 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008683 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008684 hdd_ctx->config->intfMacAddr[0].bytes,
8685 sizeof(tSirMacAddr));
8686
8687 /*
8688 * Generate the P2P Device Address. This consists of
8689 * the device's primary MAC address with the locally
8690 * administered bit set.
8691 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008692 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008693 } else {
8694 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8695 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008696 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008697 return -ENOSPC;
8698 }
8699
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008700 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8701 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008702 }
8703
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008704 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008705 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008706 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008707
8708 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008709 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008710 return -ENOSPC;
8711 }
8712
8713 return 0;
8714}
8715#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008716static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008717 bool rtnl_held)
8718{
8719 return 0;
8720}
8721#endif
8722
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008723static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008724{
Jeff Johnson9d295242017-08-29 14:39:48 -07008725 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008726 int ret = 0;
8727
8728 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8729 wlan_hdd_get_intf_addr(hdd_ctx),
8730 NET_NAME_UNKNOWN, rtnl_held);
8731 if (adapter == NULL) {
8732 hdd_err("Failed to open 802.11p interface");
8733 ret = -ENOSPC;
8734 }
8735
8736 return ret;
8737}
8738
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008739/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308740 * hdd_start_station_adapter()- Start the Station Adapter
8741 * @adapter: HDD adapter
8742 *
8743 * This function initializes the adapter for the station mode.
8744 *
8745 * Return: 0 on success or errno on failure.
8746 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008747int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308748{
8749 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008750 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308751
Dustin Brownfdf17c12018-03-14 12:55:34 -07008752 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008753 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8754 hdd_err("session is already opened, %d",
8755 adapter->session_id);
8756 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8757 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308758
Krunal Sonib51eec72017-11-20 21:53:01 -08008759 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8760 if (ret) {
8761 hdd_err("failed to create vdev: %d", ret);
8762 return ret;
8763 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308764 status = hdd_init_station_mode(adapter);
8765
8766 if (QDF_STATUS_SUCCESS != status) {
8767 hdd_err("Error Initializing station mode: %d", status);
8768 return qdf_status_to_os_return(status);
8769 }
8770
Arun Khandavallifae92942016-08-01 13:31:08 +05308771 hdd_register_tx_flow_control(adapter,
8772 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008773 hdd_tx_resume_cb,
8774 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308775
Dustin Browne74003f2018-03-14 12:51:58 -07008776 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308777 return 0;
8778}
8779
8780/**
8781 * hdd_start_ap_adapter()- Start AP Adapter
8782 * @adapter: HDD adapter
8783 *
8784 * This function initializes the adapter for the AP mode.
8785 *
8786 * Return: 0 on success errno on failure.
8787 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008788int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308789{
8790 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008791 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008792 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008793 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308794
Dustin Brown491d54b2018-03-14 12:39:11 -07008795 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308796
Krunal Sonib51eec72017-11-20 21:53:01 -08008797 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8798 hdd_err("session is already opened, %d",
8799 adapter->session_id);
8800 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8801 }
8802 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008803 * In SSR case no need to create new sap context.
8804 * Otherwise create sap context first and then create
8805 * vdev as while creating the vdev, driver needs to
8806 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008807 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008808 if (adapter->session.ap.sap_context) {
8809 is_ssr = true;
8810 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008811 hdd_err("sap creation failed");
8812 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8813 }
8814
8815 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8816 adapter->session.ap.sap_context);
8817 if (ret) {
8818 hdd_err("failed to create vdev, status:%d", ret);
8819 hdd_sap_destroy_ctx(adapter);
8820 return ret;
8821 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008822
8823 if (adapter->device_mode == QDF_SAP_MODE)
8824 sme_cli_set_command(adapter->session_id,
8825 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8826 (bool)(hdd_ctx->config->fine_time_meas_cap &
8827 WMI_FW_AP_RTT_RESPR),
8828 VDEV_CMD);
8829
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008830 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308831
8832 if (QDF_STATUS_SUCCESS != status) {
8833 hdd_err("Error Initializing the AP mode: %d", status);
8834 return qdf_status_to_os_return(status);
8835 }
8836
Arun Khandavallifae92942016-08-01 13:31:08 +05308837 hdd_register_tx_flow_control(adapter,
8838 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008839 hdd_softap_tx_resume_cb,
8840 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308841
Dustin Browne74003f2018-03-14 12:51:58 -07008842 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308843 return 0;
8844}
8845
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308846static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8847 bool rtnl_held)
8848{
8849 struct hdd_adapter *adapter;
8850
8851 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8852 hdd_ctx->config->enableConcurrentSTA,
8853 wlan_hdd_get_intf_addr(hdd_ctx),
8854 NET_NAME_UNKNOWN, rtnl_held);
8855
8856 if (!adapter)
8857 return -ENOSPC;
8858
8859 return 0;
8860}
8861
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308862/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008863 * hdd_open_interfaces - Open all required interfaces
8864 * hdd_ctx: HDD context
8865 * rtnl_held: True if RTNL lock is held
8866 *
8867 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8868 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008869 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008870 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008871static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008872{
Jeff Johnson9d295242017-08-29 14:39:48 -07008873 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008874 int ret;
8875
Ravi Joshia307f632017-07-17 23:41:41 -07008876 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008877 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8878 con_mode == QDF_GLOBAL_FTM_MODE) {
8879 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8880 QDF_MONITOR_MODE : QDF_FTM_MODE;
8881
8882 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8883 wlan_hdd_get_intf_addr(hdd_ctx),
8884 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008885 if (!adapter) {
8886 hdd_err("open adapter failed");
8887 return -ENOSPC;
8888 }
Lin Bai1c678482017-12-18 18:29:11 +08008889
Ravi Joshia307f632017-07-17 23:41:41 -07008890 return 0;
8891 }
8892
Jeff Johnson957bc272017-02-02 08:54:48 -08008893 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308894 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008895 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008896
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008897 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008898 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008899 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008900
8901 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008902 return -ENOSPC;
8903
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308904 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8905 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8906 if (ret)
8907 hdd_err("Cannot create concurrent STA interface");
8908 }
8909
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008910 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8911 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008912 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008913
8914 /* Open 802.11p Interface */
8915 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008916 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8917 if (ret)
8918 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008919 }
8920
Jeff Johnson957bc272017-02-02 08:54:48 -08008921 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008922
Jeff Johnson957bc272017-02-02 08:54:48 -08008923err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008924 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008925 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008926}
8927
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008928
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308929#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8930/**
8931 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8932 * @cds_cfg: CDS Configuration
8933 * @hdd_ctx: Pointer to hdd context
8934 *
8935 * Return: none
8936 */
8937static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8938 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008939 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308940{
8941 cds_cfg->tx_flow_stop_queue_th =
8942 hdd_ctx->config->TxFlowStopQueueThreshold;
8943 cds_cfg->tx_flow_start_queue_offset =
8944 hdd_ctx->config->TxFlowStartQueueOffset;
8945}
8946#else
8947static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8948 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008949 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308950{
8951}
8952#endif
8953
8954#ifdef FEATURE_WLAN_RA_FILTERING
8955/**
8956 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8957 * @cds_cfg: CDS Configuration
8958 * @hdd_ctx: Pointer to hdd context
8959 *
8960 * Return: none
8961 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308962static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008963 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308964{
8965 cds_cfg->ra_ratelimit_interval =
8966 hdd_ctx->config->RArateLimitInterval;
8967 cds_cfg->is_ra_ratelimit_enabled =
8968 hdd_ctx->config->IsRArateLimitEnabled;
8969}
8970#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308971static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008972 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308973{
8974}
8975#endif
8976
8977/**
8978 * hdd_update_cds_config() - API to update cds configuration parameters
8979 * @hdd_ctx: HDD Context
8980 *
8981 * Return: 0 for Success, errno on failure
8982 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008983static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308984{
8985 struct cds_config_info *cds_cfg;
8986
8987 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8988 if (!cds_cfg) {
8989 hdd_err("failed to allocate cds config");
8990 return -ENOMEM;
8991 }
8992
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008993 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008994 if (!hdd_ctx->config->nMaxPsPoll ||
8995 !hdd_ctx->config->enablePowersaveOffload) {
8996 cds_cfg->powersave_offload_enabled =
8997 hdd_ctx->config->enablePowersaveOffload;
8998 } else {
8999 if ((hdd_ctx->config->enablePowersaveOffload ==
9000 PS_QPOWER_NODEEPSLEEP) ||
9001 (hdd_ctx->config->enablePowersaveOffload ==
9002 PS_LEGACY_NODEEPSLEEP))
9003 cds_cfg->powersave_offload_enabled =
9004 PS_LEGACY_NODEEPSLEEP;
9005 else
9006 cds_cfg->powersave_offload_enabled =
9007 PS_LEGACY_DEEPSLEEP;
9008 hdd_info("Qpower disabled in cds config, %d",
9009 cds_cfg->powersave_offload_enabled);
9010 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309011 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9012 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9013 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9014 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309015
9016 /*
9017 * Copy the DFS Phyerr Filtering Offload status.
9018 * This parameter reflects the value of the
9019 * dfs_phyerr_filter_offload flag as set in the ini.
9020 */
9021 cds_cfg->dfs_phyerr_filter_offload =
9022 hdd_ctx->config->fDfsPhyerrFilterOffload;
9023 if (hdd_ctx->config->ssdp)
9024 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9025
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309026 cds_cfg->force_target_assert_enabled =
9027 hdd_ctx->config->crash_inject_enabled;
9028
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309029 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9030 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9031
9032 cds_cfg->ap_maxoffload_reorderbuffs =
9033 hdd_ctx->config->apMaxOffloadReorderBuffs;
9034
9035 cds_cfg->ap_disable_intrabss_fwd =
9036 hdd_ctx->config->apDisableIntraBssFwd;
9037
9038 cds_cfg->dfs_pri_multiplier =
9039 hdd_ctx->config->dfsRadarPriMultiplier;
9040 cds_cfg->reorder_offload =
9041 hdd_ctx->config->reorderOffloadSupport;
9042
9043 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309044 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009045 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9046 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009047 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009048 hdd_ctx->config->IpaUcTxBufCount);
9049 hdd_ctx->config->IpaUcTxBufCount =
9050 rounddown_pow_of_two(
9051 hdd_ctx->config->IpaUcTxBufCount);
9052 if (!hdd_ctx->config->IpaUcTxBufCount) {
9053 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309054 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009055 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009056 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009057 hdd_ctx->config->IpaUcTxBufCount);
9058 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309059 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9060 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009061 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9062 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009063 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009064 hdd_ctx->config->IpaUcRxIndRingCount);
9065 hdd_ctx->config->IpaUcRxIndRingCount =
9066 rounddown_pow_of_two(
9067 hdd_ctx->config->IpaUcRxIndRingCount);
9068 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9069 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309070 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009071 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009072 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009073 hdd_ctx->config->IpaUcRxIndRingCount);
9074 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309075 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009076 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309077 cds_cfg->uc_tx_partition_base =
9078 hdd_ctx->config->IpaUcTxPartitionBase;
9079 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9080
9081 cds_cfg->ip_tcp_udp_checksum_offload =
9082 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009083 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309084 cds_cfg->ce_classify_enabled =
9085 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07009086 cds_cfg->bpf_packet_filter_enable =
9087 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309088 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9089 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9090 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009091 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009092 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009093 cds_cfg->max_msdus_per_rxinorderind =
9094 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009095 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009096 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05309097 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
9098 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309099 cds_cfg->auto_power_save_fail_mode =
9100 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309101
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309102 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009103 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009104 cds_cfg->delay_before_vdev_stop =
9105 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309106
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309107 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9108 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9109 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009110 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309111 cds_init_ini_config(cds_cfg);
9112 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309113
9114exit:
9115 qdf_mem_free(cds_cfg);
9116 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309117}
9118
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009119/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009120 * hdd_update_user_config() - API to update user configuration
9121 * parameters to obj mgr which are used by multiple components
9122 * @hdd_ctx: HDD Context
9123 *
9124 * Return: 0 for Success, errno on failure
9125 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009126static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009127{
9128 struct wlan_objmgr_psoc_user_config *user_config;
9129
9130 user_config = qdf_mem_malloc(sizeof(*user_config));
9131 if (user_config == NULL) {
9132 hdd_alert("Failed to alloc memory for user_config!");
9133 return -ENOMEM;
9134 }
9135
9136 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9137 user_config->dual_mac_feature_disable =
9138 hdd_ctx->config->dual_mac_feature_disable;
9139 user_config->indoor_channel_support =
9140 hdd_ctx->config->indoor_channel_support;
9141 user_config->is_11d_support_enabled =
9142 hdd_ctx->config->Is11dSupportEnabled;
9143 user_config->is_11h_support_enabled =
9144 hdd_ctx->config->Is11hSupportEnabled;
9145 user_config->optimize_chan_avoid_event =
9146 hdd_ctx->config->goptimize_chan_avoid_event;
9147 user_config->skip_dfs_chnl_in_p2p_search =
9148 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009149 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009150 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9151
9152 qdf_mem_free(user_config);
9153 return 0;
9154}
9155
9156/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009157 * hdd_init_thermal_info - Initialize thermal level
9158 * @hdd_ctx: HDD context
9159 *
9160 * Initialize thermal level at SME layer and set the thermal level callback
9161 * which would be called when a configured thermal threshold is hit.
9162 *
9163 * Return: 0 on success and errno on failure
9164 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009165static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009166{
9167 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309168 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009169
9170 thermal_param.smeThermalMgmtEnabled =
9171 hdd_ctx->config->thermalMitigationEnable;
9172 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9173
Poddar, Siddarth83905022016-04-16 17:56:08 -07009174 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9175 hdd_ctx->config->throttle_dutycycle_level0;
9176 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9177 hdd_ctx->config->throttle_dutycycle_level1;
9178 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9179 hdd_ctx->config->throttle_dutycycle_level2;
9180 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9181 hdd_ctx->config->throttle_dutycycle_level3;
9182
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009183 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9184 hdd_ctx->config->thermalTempMinLevel0;
9185 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9186 hdd_ctx->config->thermalTempMaxLevel0;
9187 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9188 hdd_ctx->config->thermalTempMinLevel1;
9189 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9190 hdd_ctx->config->thermalTempMaxLevel1;
9191 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9192 hdd_ctx->config->thermalTempMinLevel2;
9193 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9194 hdd_ctx->config->thermalTempMaxLevel2;
9195 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9196 hdd_ctx->config->thermalTempMinLevel3;
9197 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9198 hdd_ctx->config->thermalTempMaxLevel3;
9199
9200 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9201
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309202 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309203 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009204
9205 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9206 hdd_set_thermal_level_cb);
9207
9208 return 0;
9209
9210}
9211
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009212#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9213/**
9214 * hdd_hold_rtnl_lock - Hold RTNL lock
9215 *
9216 * Hold RTNL lock
9217 *
9218 * Return: True if held and false otherwise
9219 */
9220static inline bool hdd_hold_rtnl_lock(void)
9221{
9222 rtnl_lock();
9223 return true;
9224}
9225
9226/**
9227 * hdd_release_rtnl_lock - Release RTNL lock
9228 *
9229 * Release RTNL lock
9230 *
9231 * Return: None
9232 */
9233static inline void hdd_release_rtnl_lock(void)
9234{
9235 rtnl_unlock();
9236}
9237#else
9238static inline bool hdd_hold_rtnl_lock(void) { return false; }
9239static inline void hdd_release_rtnl_lock(void) { }
9240#endif
9241
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009242#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009243
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309244/* MAX iwpriv command support */
9245#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309246#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309247#define MAX_PKTLOG_SIZE 16
9248
9249/**
9250 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9251 * @hdd_ctx: hdd context
9252 * @set_value2: pktlog buffer size value
9253 *
9254 *
9255 * Return: 0 for success or error.
9256 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009257static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309258{
9259 struct sir_wifi_start_log start_log = { 0 };
9260 QDF_STATUS status;
9261
9262 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9263 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9264 start_log.ini_triggered = cds_is_packet_log_enabled();
9265 start_log.user_triggered = 1;
9266 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309267 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309268
9269 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9270 if (!QDF_IS_STATUS_SUCCESS(status)) {
9271 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009272 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309273 return -EINVAL;
9274 }
9275
9276 return 0;
9277}
9278
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009279/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309280 * hdd_pktlog_clear_buff() - clear pktlog buffer
9281 * @hdd_ctx: hdd context
9282 *
9283 * Return: 0 for success or error.
9284 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009285static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309286{
9287 struct sir_wifi_start_log start_log;
9288 QDF_STATUS status;
9289
9290 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9291 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9292 start_log.ini_triggered = cds_is_packet_log_enabled();
9293 start_log.user_triggered = 1;
9294 start_log.size = 0;
9295 start_log.is_pktlog_buff_clear = true;
9296
9297 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9298 if (!QDF_IS_STATUS_SUCCESS(status)) {
9299 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009300 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309301 return -EINVAL;
9302 }
9303
9304 return 0;
9305}
9306
9307
9308/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009309 * hdd_process_pktlog_command() - process pktlog command
9310 * @hdd_ctx: hdd context
9311 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309312 * @set_value2: pktlog buffer size value
9313 *
9314 * This function process pktlog command.
9315 * set_value2 only matters when set_value is 3 (set buff size)
9316 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009317 *
9318 * Return: 0 for success or error.
9319 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009320int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309321 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009322{
9323 int ret;
9324 bool enable;
9325 uint8_t user_triggered = 0;
9326
9327 ret = wlan_hdd_validate_context(hdd_ctx);
9328 if (0 != ret)
9329 return ret;
9330
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009331 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009332
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309333 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009334 hdd_err("invalid pktlog value %d", set_value);
9335 return -EINVAL;
9336 }
9337
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309338 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9339 if (set_value2 <= 0) {
9340 hdd_err("invalid pktlog size %d", set_value2);
9341 return -EINVAL;
9342 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9343 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9344 return -EINVAL;
9345 }
9346 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309347 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9348 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309349 }
9350
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009351 /*
9352 * set_value = 0 then disable packetlog
9353 * set_value = 1 enable packetlog forcefully
9354 * set_vlaue = 2 then disable packetlog if disabled through ini or
9355 * enable packetlog with AUTO type.
9356 */
9357 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9358 true : false;
9359
9360 if (1 == set_value) {
9361 enable = true;
9362 user_triggered = 1;
9363 }
9364
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309365 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009366}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009367
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009368/**
9369 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9370 * @hdd_ctx: HDD context
9371 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309372 * @user_triggered: triggered through iwpriv
9373 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009374 *
9375 * Return: 0 on success; error number otherwise
9376 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009377int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309378 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009379{
9380 struct sir_wifi_start_log start_log;
9381 QDF_STATUS status;
9382
9383 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9384 start_log.verbose_level =
9385 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009386 start_log.ini_triggered = cds_is_packet_log_enabled();
9387 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309388 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309389 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309390 /*
9391 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9392 * commands. Host uses this flag to decide whether to send pktlog
9393 * disable command to fw without sending pktlog enable command
9394 * previously. For eg, If vendor sends pktlog disable command without
9395 * sending pktlog enable command, then host discards the packet
9396 * but for iwpriv command, host will send it to fw.
9397 */
9398 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009399 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9400 if (!QDF_IS_STATUS_SUCCESS(status)) {
9401 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009402 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009403 return -EINVAL;
9404 }
9405
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309406 if (enable == true)
9407 hdd_ctx->is_pktlog_enabled = 1;
9408 else
9409 hdd_ctx->is_pktlog_enabled = 0;
9410
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009411 return 0;
9412}
9413#endif /* REMOVE_PKT_LOG */
9414
Komal Seelam92fff912016-03-24 11:51:41 +05309415/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009416 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9417 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309418 * @dev: Device Pointer
9419 * @num: Number of Valid Mac address
9420 *
9421 * Return: Pointer to MAC address buffer
9422 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009423static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9424 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309425{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009426 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309427}
Komal Seelam92fff912016-03-24 11:51:41 +05309428
9429/**
9430 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9431 * @hdd_ctx: HDD Context
9432 * @num: Number of random mac addresses needed
9433 *
9434 * Generate random addresses using bit manipulation on the base mac address
9435 *
9436 * Return: None
9437 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009438void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309439{
9440 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9441 uint32_t iter;
9442 struct hdd_config *ini = hdd_ctx->config;
9443 uint8_t *buf = NULL;
9444 uint8_t macaddr_b3, tmp_br3;
9445 uint8_t *src = ini->intfMacAddr[0].bytes;
9446
9447 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9448 buf = ini->intfMacAddr[iter].bytes;
9449 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9450 macaddr_b3 = buf[3];
9451 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9452 INTF_MACADDR_MASK;
9453 macaddr_b3 += tmp_br3;
9454 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9455 buf[0] |= 0x02;
9456 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009457 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309458 }
9459}
9460
9461/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009462 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309463 * @hdd_ctx: HDD Context
9464 *
9465 * API to get mac addresses from platform driver and update the driver
9466 * structures and configure FW with the base mac address.
9467 * Return: int
9468 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009469static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309470{
9471 uint32_t no_of_mac_addr, iter;
9472 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9473 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9474 uint8_t *addr, *buf;
9475 struct device *dev = hdd_ctx->parent_dev;
9476 struct hdd_config *ini = hdd_ctx->config;
9477 tSirMacAddr mac_addr;
9478 QDF_STATUS status;
9479
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009480 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309481
9482 if (no_of_mac_addr == 0 || !addr) {
9483 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9484 return -EINVAL;
9485 }
9486
9487 if (no_of_mac_addr > max_mac_addr)
9488 no_of_mac_addr = max_mac_addr;
9489
9490 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9491
9492 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9493 buf = ini->intfMacAddr[iter].bytes;
9494 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009495 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309496 }
9497
9498 status = sme_set_custom_mac_addr(mac_addr);
9499
9500 if (!QDF_IS_STATUS_SUCCESS(status))
9501 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009502
Komal Seelam92fff912016-03-24 11:51:41 +05309503 if (no_of_mac_addr < max_mac_addr)
9504 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9505 no_of_mac_addr);
9506 return 0;
9507}
9508
9509/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009510 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9511 * @hdd_ctx: HDD Context
9512 *
9513 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9514 * will generate its own MAC and update it to FW.
9515 *
9516 * Return: 0 for success
9517 * Non-zero error code for failure
9518 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009519static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009520{
9521 tSirMacAddr customMacAddr;
9522 QDF_STATUS status;
9523
9524 qdf_mem_copy(&customMacAddr,
9525 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9526 sizeof(tSirMacAddr));
9527 status = sme_set_custom_mac_addr(customMacAddr);
9528 if (!QDF_IS_STATUS_SUCCESS(status))
9529 return -EAGAIN;
9530 return 0;
9531}
9532
9533/**
Komal Seelam92fff912016-03-24 11:51:41 +05309534 * hdd_initialize_mac_address() - API to get wlan mac addresses
9535 * @hdd_ctx: HDD Context
9536 *
9537 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9538 * is provisioned with mac addresses, driver uses it, else it will use
9539 * wlan_mac.bin to update HW MAC addresses.
9540 *
9541 * Return: None
9542 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009543static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309544{
9545 QDF_STATUS status;
9546 int ret;
9547
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009548 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309549 if (ret == 0)
9550 return;
9551
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009552 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9553 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309554
9555 status = hdd_update_mac_config(hdd_ctx);
9556
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009557 if (QDF_IS_STATUS_SUCCESS(status))
9558 return;
9559
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009560 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9561 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009562
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009563 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009564 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009565 if (ret != 0) {
9566 hdd_err("MAC address out-of-sync, ret:%d", ret);
9567 QDF_ASSERT(ret);
9568 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009569 }
Komal Seelam92fff912016-03-24 11:51:41 +05309570}
9571
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009572static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009573{
9574 int vdev_id = 0;
9575 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9576 int value = hdd_ctx->config->smart_chainmask_enabled;
9577 int vpdev = PDEV_CMD;
9578 int ret;
9579
Naveen Rawat247a8682017-06-05 15:00:31 -07009580 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009581 if (ret)
9582 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9583
9584 return ret;
9585}
9586
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009587static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009588{
9589 int vdev_id = 0;
9590 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9591 int value = hdd_ctx->config->alternative_chainmask_enabled;
9592 int vpdev = PDEV_CMD;
9593 int ret;
9594
Naveen Rawat247a8682017-06-05 15:00:31 -07009595 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009596 if (ret)
9597 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9598 ret);
9599
9600 return ret;
9601}
9602
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009603static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009604{
9605 int vdev_id = 0;
9606 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9607 int value = hdd_ctx->config->ani_enabled;
9608 int vpdev = PDEV_CMD;
9609 int ret;
9610
Naveen Rawat247a8682017-06-05 15:00:31 -07009611 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009612 if (ret)
9613 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9614
9615 return ret;
9616}
9617
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009618/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009619 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9620 * @hdd_ctx: HDD context
9621 *
9622 * Pre configurations to be done at lower layer before calling cds enable.
9623 *
9624 * Return: 0 on success and errno on failure.
9625 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009626static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009627{
9628 int ret;
9629 QDF_STATUS status;
9630 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009631 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009632
Leo Changfdb45c32016-10-28 11:09:23 -07009633 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009634 /*
9635 * Set 802.11p config
9636 * TODO-OCB: This has been temporarily added here to ensure this
9637 * parameter is set in CSR when we init the channel list. This should
9638 * be removed once the 5.9 GHz channels are added to the regulatory
9639 * domain.
9640 */
9641 hdd_set_dot11p_config(hdd_ctx);
9642
9643 /*
9644 * Note that the cds_pre_enable() sequence triggers the cfg download.
9645 * The cfg download must occur before we update the SME config
9646 * since the SME config operation must access the cfg database
9647 */
9648 status = hdd_set_sme_config(hdd_ctx);
9649
9650 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009651 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009652 ret = qdf_status_to_os_return(status);
9653 goto out;
9654 }
9655
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009656 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9657 if (QDF_STATUS_SUCCESS != status) {
9658 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9659 ret = qdf_status_to_os_return(status);
9660 goto out;
9661 }
9662
Naveen Rawat247a8682017-06-05 15:00:31 -07009663 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009664 hdd_ctx->config->tx_chain_mask_1ss,
9665 PDEV_CMD);
9666 if (0 != ret) {
9667 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9668 goto out;
9669 }
9670
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009671 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9672 if (ret)
9673 goto out;
9674
9675 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9676 if (ret)
9677 goto out;
9678
Jeff Johnson12a744b2017-04-04 08:19:37 -07009679 ret = hdd_set_ani_enabled(hdd_ctx);
9680 if (ret)
9681 goto out;
9682
Naveen Rawat247a8682017-06-05 15:00:31 -07009683 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009684 hdd_ctx->config->arp_ac_category,
9685 PDEV_CMD);
9686 if (0 != ret) {
9687 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9688 hdd_ctx->config->arp_ac_category, ret);
9689 goto out;
9690 }
9691
Prashanth Bhatta07998752016-04-28 12:35:33 -07009692 status = hdd_set_sme_chan_list(hdd_ctx);
9693 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009694 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009695 ret = qdf_status_to_os_return(status);
9696 goto out;
9697 }
9698
9699 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009700 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009701 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009702 ret = -EINVAL;
9703 goto out;
9704 }
9705
Prashanth Bhatta07998752016-04-28 12:35:33 -07009706 /*
9707 * Set the MAC Address Currently this is used by HAL to add self sta.
9708 * Remove this once self sta is added as part of session open.
9709 */
9710 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9711 hdd_ctx->config->intfMacAddr[0].bytes,
9712 sizeof(hdd_ctx->config->intfMacAddr[0]));
9713
9714 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9715 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9716 hal_status, hal_status);
9717 ret = -EINVAL;
9718 goto out;
9719 }
9720
9721 hdd_init_channel_avoidance(hdd_ctx);
9722
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309723 /* update enable sap mandatory chan list */
9724 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9725 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009726out:
9727 return ret;
9728}
9729
9730/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009731 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9732 * @context_ptr - hdd context pointer
9733 * @event_ptr - event structure pointer
9734 *
9735 * This is the p2p listen offload stop event handler, it sends vendor
9736 * event back to supplicant to notify the stop reason.
9737 *
9738 * Return: None
9739 */
9740static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9741 void *event_ptr)
9742{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009743 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009744 struct sir_p2p_lo_event *evt = event_ptr;
9745 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009746 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009747
Dustin Brown491d54b2018-03-14 12:39:11 -07009748 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009749
9750 if (hdd_ctx == NULL) {
9751 hdd_err("Invalid HDD context pointer");
9752 return;
9753 }
9754
Peng Xu5c682812017-08-06 07:39:13 -07009755 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9756 if (!adapter) {
9757 hdd_err("Cannot find adapter by vdev_id = %d",
9758 evt->vdev_id);
9759 return;
9760 }
9761
Peng Xu8fdaa492016-06-22 10:20:47 -07009762 vendor_event =
9763 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009764 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009765 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9766 GFP_KERNEL);
9767
9768 if (!vendor_event) {
9769 hdd_err("cfg80211_vendor_event_alloc failed");
9770 return;
9771 }
9772
9773 if (nla_put_u32(vendor_event,
9774 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9775 evt->reason_code)) {
9776 hdd_err("nla put failed");
9777 kfree_skb(vendor_event);
9778 return;
9779 }
9780
9781 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009782 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9783 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009784}
9785
9786/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309787 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9788 * @hdd_ctx: HDD context
9789 *
9790 * This function sends the adaptive dwell time config configuration to the
9791 * firmware via WMA
9792 *
9793 * Return: 0 - success, < 0 - failure
9794 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009795static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309796{
9797 QDF_STATUS status;
9798 struct adaptive_dwelltime_params dwelltime_params;
9799
9800 dwelltime_params.is_enabled =
9801 hdd_ctx->config->adaptive_dwell_mode_enabled;
9802 dwelltime_params.dwelltime_mode =
9803 hdd_ctx->config->global_adapt_dwelltime_mode;
9804 dwelltime_params.lpf_weight =
9805 hdd_ctx->config->adapt_dwell_lpf_weight;
9806 dwelltime_params.passive_mon_intval =
9807 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9808 dwelltime_params.wifi_act_threshold =
9809 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9810
9811 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9812 &dwelltime_params);
9813
9814 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9815 if (!QDF_IS_STATUS_SUCCESS(status)) {
9816 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9817 return -EAGAIN;
9818 }
9819 return 0;
9820}
9821
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009822int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309823{
9824 QDF_STATUS status;
9825 struct wmi_dbs_scan_sel_params dbs_scan_params;
9826 uint32_t i = 0;
9827 uint8_t count = 0, numentries = 0;
9828 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9829 * CDS_DBS_SCAN_CLIENTS_MAX];
9830
9831 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +05309832 if ((hdd_ctx->config->dual_mac_feature_disable ==
9833 DISABLE_DBS_CXN_AND_SCAN) ||
9834 (hdd_ctx->config->dual_mac_feature_disable ==
9835 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309836 return -EINVAL;
9837
9838 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9839 dbs_scan_config, &numentries,
9840 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9841 * CDS_DBS_SCAN_CLIENTS_MAX));
9842
9843 hdd_info("numentries %hu", numentries);
9844 if (!numentries) {
9845 hdd_info("Donot send scan_selection_config");
9846 return 0;
9847 }
9848
9849 /* hdd_set_fw_log_params */
9850 dbs_scan_params.num_clients = 0;
9851 while (count < (numentries - 2)) {
9852 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9853 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9854 dbs_scan_params.num_non_dbs_scans[i] =
9855 dbs_scan_config[count + 2];
9856 dbs_scan_params.num_clients++;
9857 hdd_debug("module:%d NDS:%d NNDS:%d",
9858 dbs_scan_params.module_id[i],
9859 dbs_scan_params.num_dbs_scans[i],
9860 dbs_scan_params.num_non_dbs_scans[i]);
9861 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9862 i++;
9863 }
9864
9865 dbs_scan_params.pdev_id = 0;
9866
9867 hdd_debug("clients:%d pdev:%d",
9868 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9869
9870 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9871 &dbs_scan_params);
9872 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9873 if (!QDF_IS_STATUS_SUCCESS(status)) {
9874 hdd_err("Failed to send DBS Scan selection configuration!");
9875 return -EAGAIN;
9876 }
9877 return 0;
9878}
9879
Arun Khandavallid4349a92016-07-25 11:10:43 +05309880#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9881/**
9882 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9883 * @hdd_ctx: HDD context
9884 *
9885 * Set auto shutdown callback to get indications from firmware to indicate
9886 * userspace to shutdown WLAN after a configured amount of inactivity.
9887 *
9888 * Return: 0 on success and errno on failure.
9889 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009890static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309891{
9892 QDF_STATUS status;
9893
9894 if (!hdd_ctx->config->WlanAutoShutdown)
9895 return 0;
9896
9897 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9898 wlan_hdd_auto_shutdown_cb);
9899 if (status != QDF_STATUS_SUCCESS)
9900 hdd_err("Auto shutdown feature could not be enabled: %d",
9901 status);
9902
9903 return qdf_status_to_os_return(status);
9904}
9905#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009906static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309907{
9908 return 0;
9909}
9910#endif
9911
9912/**
9913 * hdd_features_init() - Init features
9914 * @hdd_ctx: HDD context
9915 * @adapter: Primary adapter context
9916 *
9917 * Initialize features and their feature context after WLAN firmware is up.
9918 *
9919 * Return: 0 on success and errno on failure.
9920 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009921static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309922{
9923 tSirTxPowerLimit hddtxlimit;
9924 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309925 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309926 int ret;
9927
Dustin Brown491d54b2018-03-14 12:39:11 -07009928 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309929
Arun Khandavallid4349a92016-07-25 11:10:43 +05309930 /* FW capabilities received, Set the Dot11 mode */
9931 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009932 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9933 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309934
Arun Khandavallid4349a92016-07-25 11:10:43 +05309935
9936 if (hdd_ctx->config->fIsImpsEnabled)
9937 hdd_set_idle_ps_config(hdd_ctx, true);
9938 else
9939 hdd_set_idle_ps_config(hdd_ctx, false);
9940
Poddar, Siddarth37033032017-10-11 15:47:40 +05309941 /* Send Enable/Disable data stall detection cmd to FW */
9942 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9943 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9944
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309945 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009946 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309947
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309948 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9949 hdd_warn("Error in setting Voltage Corner mode config to FW");
9950
Arun Khandavallid4349a92016-07-25 11:10:43 +05309951 if (hdd_lro_init(hdd_ctx))
9952 hdd_err("Unable to initialize LRO in fw");
9953
9954 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9955 hdd_err("Unable to send adaptive dwelltime setting to FW");
9956
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309957 if (hdd_dbs_scan_selection_init(hdd_ctx))
9958 hdd_err("Unable to send DBS scan selection setting to FW");
9959
Arun Khandavallid4349a92016-07-25 11:10:43 +05309960 ret = hdd_init_thermal_info(hdd_ctx);
9961 if (ret) {
9962 hdd_err("Error while initializing thermal information");
9963 goto deregister_frames;
9964 }
9965
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309966 /**
9967 * In case of SSR/PDR, if pktlog was enabled manually before
9968 * SSR/PDR, Then enabled it again automatically after Wlan
9969 * device up.
9970 */
9971 if (cds_is_driver_recovering()) {
9972 if (hdd_ctx->is_pktlog_enabled)
9973 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +08009974 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309975
Arun Khandavallid4349a92016-07-25 11:10:43 +05309976 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9977 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9978 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9979 if (!QDF_IS_STATUS_SUCCESS(status))
9980 hdd_err("Error setting txlimit in sme: %d", status);
9981
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009982 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309983
Arun Khandavallid4349a92016-07-25 11:10:43 +05309984 ret = hdd_register_cb(hdd_ctx);
9985 if (ret) {
9986 hdd_err("Failed to register HDD callbacks!");
9987 goto deregister_frames;
9988 }
9989
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309990 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9991 status = sme_enable_disable_chanavoidind_event(
9992 hdd_ctx->hHal, 0);
9993 if (!QDF_IS_STATUS_SUCCESS(status)) {
9994 hdd_err("Failed to disable Chan Avoidance Indication");
9995 goto deregister_cb;
9996 }
9997 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309998
Manjeet Singha9cae432017-02-28 11:58:22 +05309999 if (hdd_ctx->config->enable_5g_band_pref) {
10000 band_pref_params.rssi_boost_threshold_5g =
10001 hdd_ctx->config->rssi_boost_threshold_5g;
10002 band_pref_params.rssi_boost_factor_5g =
10003 hdd_ctx->config->rssi_boost_factor_5g;
10004 band_pref_params.max_rssi_boost_5g =
10005 hdd_ctx->config->max_rssi_boost_5g;
10006 band_pref_params.rssi_penalize_threshold_5g =
10007 hdd_ctx->config->rssi_penalize_threshold_5g;
10008 band_pref_params.rssi_penalize_factor_5g =
10009 hdd_ctx->config->rssi_penalize_factor_5g;
10010 band_pref_params.max_rssi_penalize_5g =
10011 hdd_ctx->config->max_rssi_penalize_5g;
10012 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
10013 }
10014
Arun Khandavallid4349a92016-07-25 11:10:43 +053010015 /* register P2P Listen Offload event callback */
10016 if (wma_is_p2p_lo_capable())
10017 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
10018 wlan_hdd_p2p_lo_event_callback);
10019
10020 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10021
10022 if (ret)
10023 goto deregister_cb;
10024
Dustin Brown11638b72018-01-25 17:37:25 +053010025 wlan_hdd_init_chan_info(hdd_ctx);
10026
Dustin Browne74003f2018-03-14 12:51:58 -070010027 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010028 return 0;
10029
10030deregister_cb:
10031 hdd_deregister_cb(hdd_ctx);
10032deregister_frames:
10033 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010034 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010035}
10036
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010037/**
10038 * hdd_features_deinit() - Deinit features
10039 * @hdd_ctx: HDD context
10040 *
10041 * De-Initialize features and their feature context.
10042 *
10043 * Return: none.
10044 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010045static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010046{
Dustin Brown11638b72018-01-25 17:37:25 +053010047 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010048 wlan_hdd_tsf_deinit(hdd_ctx);
10049}
10050
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010051/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010052 * hdd_register_bcn_cb() - register scan beacon callback
10053 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010054 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010055 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010056 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010057static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010058{
10059 QDF_STATUS status;
10060
10061 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10062 wlan_cfg80211_inform_bss_frame,
10063 SCAN_CB_TYPE_INFORM_BCN);
10064 if (!QDF_IS_STATUS_SUCCESS(status)) {
10065 hdd_err("failed with status code %08d [x%08x]",
10066 status, status);
10067 return status;
10068 }
10069
10070 return QDF_STATUS_SUCCESS;
10071}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010072
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010073/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010074 * hdd_configure_cds() - Configure cds modules
10075 * @hdd_ctx: HDD context
10076 * @adapter: Primary adapter context
10077 *
10078 * Enable Cds modules after WLAN firmware is up.
10079 *
10080 * Return: 0 on success and errno on failure.
10081 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010082int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +053010083{
10084 int ret;
10085 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010086 int set_value;
10087 uint32_t num_abg_tx_chains = 0;
10088 uint32_t num_11b_tx_chains = 0;
10089 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -070010090 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010091
10092 if (hdd_ctx->config->sifs_burst_duration) {
10093 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
10094 hdd_ctx->config->sifs_burst_duration;
10095
10096 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
10097 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
10098 set_value, PDEV_CMD);
10099 }
10100
10101 if (hdd_ctx->config->is_force_1x1)
10102 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10103 1, PDEV_CMD);
10104 /* set chip power save failure detected callback */
10105 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
10106 hdd_chip_pwr_save_fail_detected_cb);
10107
10108 if (hdd_ctx->config->max_mpdus_inampdu) {
10109 set_value = hdd_ctx->config->max_mpdus_inampdu;
10110 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10111 set_value, PDEV_CMD);
10112 }
10113
10114 if (hdd_ctx->config->enable_rts_sifsbursting) {
10115 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10116 sme_cli_set_command(0,
10117 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10118 set_value, PDEV_CMD);
10119 }
10120
10121 if (hdd_ctx->config->sap_get_peer_info) {
10122 set_value = hdd_ctx->config->sap_get_peer_info;
10123 sme_cli_set_command(0,
10124 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10125 set_value, PDEV_CMD);
10126 }
10127
10128 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10129 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10130 if (!hdd_ctx->config->enable2x2) {
10131 if (num_11b_tx_chains > 1)
10132 num_11b_tx_chains = 1;
10133 if (num_11ag_tx_chains > 1)
10134 num_11ag_tx_chains = 1;
10135 }
10136 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10137 num_11b_tx_chains);
10138 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10139 num_11ag_tx_chains);
10140 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10141 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010142
10143 ret = hdd_pre_enable_configure(hdd_ctx);
10144 if (ret) {
10145 hdd_err("Failed to pre-configure cds");
10146 goto out;
10147 }
10148
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010149 /* Always get latest IPA resources allocated from cds_open and configure
10150 * IPA module before configuring them to FW. Sequence required as crash
10151 * observed otherwise.
10152 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010153 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10154 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010155 hdd_err("Failed to setup pipes");
10156 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010157 }
10158
Arun Khandavallifae92942016-08-01 13:31:08 +053010159 /*
10160 * Start CDS which starts up the SME/MAC/HAL modules and everything
10161 * else
10162 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010163 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010164
10165 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010166 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010167 goto out;
10168 }
10169
10170 status = hdd_post_cds_enable_config(hdd_ctx);
10171 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010172 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010173 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010174 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010175 status = hdd_register_bcn_cb(hdd_ctx);
10176 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010177 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010178 goto cds_disable;
10179 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010180
10181 ret = hdd_features_init(hdd_ctx, adapter);
10182 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010183 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010184
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010185 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010186 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010187 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010188 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10189 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010190 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010191 goto cds_disable;
10192 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010193 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10194 wlan_hdd_send_mode_change_event);
10195 if (!QDF_IS_STATUS_SUCCESS(status)) {
10196 hdd_debug("Failed to register mode change cb with Policy Manager");
10197 goto cds_disable;
10198 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010199
Jeff Johnson8bb61112018-03-31 13:33:54 -070010200 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010201 hdd_debug("enhance green ap is not enabled");
10202
Nachiket Kukadedd302662017-07-13 17:31:44 +053010203 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10204 hdd_debug("Failed to set wow pulse");
10205
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010206 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10207 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010208 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10209 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10210
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010211
10212 if (hdd_ctx->config->enable_phy_reg_retention)
10213 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10214 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10215
Arun Khandavallifae92942016-08-01 13:31:08 +053010216 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010217
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010218cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010219 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010220
Arun Khandavallifae92942016-08-01 13:31:08 +053010221out:
10222 return -EINVAL;
10223}
10224
10225/**
10226 * hdd_deconfigure_cds() -De-Configure cds
10227 * @hdd_ctx: HDD context
10228 *
10229 * Deconfigure Cds modules before WLAN firmware is down.
10230 *
10231 * Return: 0 on success and errno on failure.
10232 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010233static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010234{
10235 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010236 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010237
Dustin Brown491d54b2018-03-14 12:39:11 -070010238 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010239
10240 /* De-init features */
10241 hdd_features_deinit(hdd_ctx);
10242
Arun Khandavallifae92942016-08-01 13:31:08 +053010243 /* De-register the SME callbacks */
10244 hdd_deregister_cb(hdd_ctx);
10245
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010246 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10247 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10248 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10249 }
10250
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010251 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010252 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10253 hdd_err("Failed to Disable the CDS Modules! :%d",
10254 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010255 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010256 }
10257
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010258 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010259 hdd_err("Failed to disconnect pipes");
10260 ret = -EINVAL;
10261 }
10262
Dustin Browne74003f2018-03-14 12:51:58 -070010263 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010264 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010265}
10266
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010267#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10268static void hdd_deregister_policy_manager_callback(
10269 struct wlan_objmgr_psoc *psoc)
10270{
10271 if (QDF_STATUS_SUCCESS !=
10272 policy_mgr_deregister_hdd_cb(psoc)) {
10273 hdd_err("HDD callback deregister with policy manager failed");
10274 }
10275}
10276#else
10277static void hdd_deregister_policy_manager_callback(
10278 struct wlan_objmgr_psoc *psoc)
10279{
10280}
10281#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010282
10283/**
10284 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10285 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010286 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010287 *
10288 * This function maintains the driver state machine it will be invoked from
10289 * exit, shutdown and con_mode change handler. Depending on the driver state
10290 * shall perform the stopping/closing of the modules.
10291 *
10292 * Return: 0 for success; non-zero for failure
10293 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010294int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010295{
10296 void *hif_ctx;
10297 qdf_device_t qdf_ctx;
10298 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010299 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010300 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010301 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10302 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010303 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010304 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010305
Dustin Brown491d54b2018-03-14 12:39:11 -070010306 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010307 hdd_alert("stop WLAN module: entering driver status=%d",
10308 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010309
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010310 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10311
Arun Khandavallifae92942016-08-01 13:31:08 +053010312 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10313 if (!qdf_ctx) {
10314 hdd_err("QDF device context NULL");
10315 return -EINVAL;
10316 }
10317
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010318 mutex_lock(&hdd_ctx->iface_change_lock);
10319 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010320 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010321
Dustin Brown70111822017-03-30 15:31:40 -070010322 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010323 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010324 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010325 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010326
10327 cds_print_external_threads();
10328
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010329 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010330 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010331 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10332 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010333 hdd_prevent_suspend_timeout(
10334 hdd_ctx->config->iface_change_wait_time,
10335 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010336 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010337 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010338 return 0;
10339 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010340 }
10341
Arun Khandavallifae92942016-08-01 13:31:08 +053010342 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10343
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010344 /* free user wowl patterns */
10345 hdd_free_user_wowl_ptrns();
10346
Arun Khandavallifae92942016-08-01 13:31:08 +053010347 switch (hdd_ctx->driver_status) {
10348 case DRIVER_MODULES_UNINITIALIZED:
10349 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010350 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010351 case DRIVER_MODULES_CLOSED:
10352 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010353 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010354 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010355 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10356
Komal Seelamf2136bb2016-09-28 18:30:44 +053010357 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010358 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010359 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010360 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010361 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010362 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010363 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010364
Arun Khandavallifae92942016-08-01 13:31:08 +053010365 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010366 hdd_info("Wlan transitioned (now OPENED)");
10367
10368 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010369 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010370 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010371 break;
10372 default:
10373 hdd_err("Trying to stop wlan in a wrong state: %d",
10374 hdd_ctx->driver_status);
10375 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010376 ret = -EINVAL;
10377 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010378 }
10379
Amar Singhal18081642018-01-26 16:04:13 -080010380 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010381 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010382
Rajeev Kumarbe021242017-02-16 16:12:23 -080010383 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010384 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10385 hdd_err("Failed to process post CDS disable Modules! :%d",
10386 qdf_status);
10387 ret = -EINVAL;
10388 QDF_ASSERT(0);
10389 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010390
psimhadeea0a12017-12-18 14:50:02 -080010391 hdd_runtime_suspend_context_deinit(hdd_ctx);
10392
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010393 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10394 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10395 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10396 ret = -EINVAL;
10397 QDF_ASSERT(0);
10398 }
10399
Jeff Johnsone4b14592017-09-13 14:23:33 -070010400 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010401 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010402 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010403 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010404 QDF_ASSERT(0);
10405 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010406
Amar Singhal410675c2018-01-10 12:14:21 -080010407 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010408 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10409 if (ret) {
10410 hdd_err("Failed to destroy pdev; errno:%d", ret);
10411 QDF_ASSERT(0);
10412 }
10413
10414 /*
10415 * Reset total mac phy during module stop such that during
10416 * next module start same psoc is used to populate new service
10417 * ready data
10418 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010419 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10420 if (tgt_hdl)
10421 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10422
Liangwei Dong50a64a72018-01-11 01:17:00 -050010423
Arun Khandavallifae92942016-08-01 13:31:08 +053010424 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10425 if (!hif_ctx) {
10426 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010427 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010428 }
10429
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010430 if (hdd_ctx->target_hw_name) {
10431 qdf_mem_free(hdd_ctx->target_hw_name);
10432 hdd_ctx->target_hw_name = NULL;
10433 }
10434
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010435 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010436
10437 ol_cds_free();
10438
Dustin Brown70111822017-03-30 15:31:40 -070010439 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010440 ret = pld_power_off(qdf_ctx->dev);
10441 if (ret)
10442 hdd_err("CNSS power down failed put device into Low power mode:%d",
10443 ret);
10444 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010445
Dustin Brown4bc0a622017-12-06 15:56:50 -080010446 /* many adapter resources are not freed by design in SSR case */
10447 if (!is_recovery_stop)
10448 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010449 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010450
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010451 /* Once the firmware sequence is completed reset this flag */
10452 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010453 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010454 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010455
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010456done:
10457 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010458 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010459 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010460 hdd_alert("stop WLAN module: exit driver status=%d",
10461 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010462
Dustin Browne74003f2018-03-14 12:51:58 -070010463 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010464
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010465 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010466}
10467
Arun Khandavallifae92942016-08-01 13:31:08 +053010468
10469/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010470 * hdd_state_info_dump() - prints state information of hdd layer
10471 * @buf: buffer pointer
10472 * @size: size of buffer to be filled
10473 *
10474 * This function is used to dump state information of hdd layer
10475 *
10476 * Return: None
10477 */
10478static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10479{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010480 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010481 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010482 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010483 uint16_t len = 0;
10484 char *buf = *buf_ptr;
10485
10486 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10487 if (!hdd_ctx) {
10488 hdd_err("Failed to get hdd context ");
10489 return;
10490 }
10491
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010492 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010493
10494 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010495 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010496 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010497 "\n is_scheduler_suspended %d",
10498 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010499
Dustin Brown920397d2017-12-13 16:27:50 -080010500 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010501 if (adapter->dev)
10502 len += scnprintf(buf + len, *size - len,
10503 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010504 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010505 "\n device_mode: %d", adapter->device_mode);
10506 switch (adapter->device_mode) {
10507 case QDF_STA_MODE:
10508 case QDF_P2P_CLIENT_MODE:
10509 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10510 len += scnprintf(buf + len, *size - len,
10511 "\n connState: %d",
10512 hdd_sta_ctx->conn_info.connState);
10513 break;
10514
10515 default:
10516 break;
10517 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010518 }
10519
10520 *size -= len;
10521 *buf_ptr += len;
10522}
10523
10524/**
10525 * hdd_register_debug_callback() - registration function for hdd layer
10526 * to print hdd state information
10527 *
10528 * Return: None
10529 */
10530static void hdd_register_debug_callback(void)
10531{
10532 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10533}
10534
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010535/*
10536 * wlan_init_bug_report_lock() - Initialize bug report lock
10537 *
10538 * This function is used to create bug report lock
10539 *
10540 * Return: None
10541 */
10542static void wlan_init_bug_report_lock(void)
10543{
10544 p_cds_contextType p_cds_context;
10545
10546 p_cds_context = cds_get_global_context();
10547 if (!p_cds_context) {
10548 hdd_err("cds context is NULL");
10549 return;
10550 }
10551
10552 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10553}
10554
Mohit Khannaf8f96822017-05-17 17:11:59 -070010555void hdd_dp_trace_init(struct hdd_config *config)
10556{
10557
10558 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10559 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10560 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10561 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10562 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10563 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10564 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010565 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010566
10567 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10568 &num_entries, sizeof(config_params));
10569
10570 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010571 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010572 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010573 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010574 else if (bw_compute_interval > 1000) {
10575 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10576 thresh_time_limit = 1;
10577 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010578 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10579
10580 switch (num_entries) {
10581 case 4:
10582 proto_bitmap = config_params[3];
10583 case 3:
10584 verbosity = config_params[2];
10585 case 2:
10586 thresh = config_params[1];
10587 case 1:
10588 live_mode = config_params[0];
10589 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010590 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010591 live_mode, thresh, thresh_time_limit,
10592 verbosity, proto_bitmap);
10593 };
10594
10595 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10596 verbosity, proto_bitmap);
10597
10598}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010599/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010600 * hdd_wlan_startup() - HDD init function
10601 * @dev: Pointer to the underlying device
10602 *
10603 * This is the driver startup code executed once a WLAN device has been detected
10604 *
10605 * Return: 0 for success, < 0 for failure
10606 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010607int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010608{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010609 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010610 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010611 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010612 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010613
Dustin Brown491d54b2018-03-14 12:39:11 -070010614 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010615
Arun Khandavallifae92942016-08-01 13:31:08 +053010616 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010617
10618 if (IS_ERR(hdd_ctx))
10619 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010620
Abhishek Singhe9068f12017-03-31 14:14:52 +053010621 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10622 DEFAULT_PSOC_ID);
10623 if (ret) {
10624 hdd_err("Psoc creation fails!");
10625 QDF_BUG(0);
10626 goto err_hdd_free_context;
10627 }
10628
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010629 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010630#ifdef FEATURE_WLAN_CH_AVOID
10631 mutex_init(&hdd_ctx->avoid_freq_lock);
10632#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010633
Naveen Rawate02f8f52018-04-05 11:58:04 -070010634 osif_request_manager_init();
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010635 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010636 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010637
Dustin Brown021cecd2017-12-11 13:56:43 -080010638 hdd_driver_memdump_init();
10639
Jeff Johnson957bc272017-02-02 08:54:48 -080010640 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010641 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010642 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010643 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010644 }
10645
Yingying Tang80e15f32016-09-27 18:23:01 +080010646 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010647
Anurag Chouhan6d760662016-02-20 16:05:43 +053010648 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010649
10650 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010651 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010652 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010653 }
10654
Prashanth Bhatta07998752016-04-28 12:35:33 -070010655 ret = hdd_wiphy_init(hdd_ctx);
10656 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010657 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010658 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010659 }
10660
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010661 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010662 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010663
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010664 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010665
Paul Zhangfb02f452017-12-22 11:58:43 +080010666 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10667 if (ret) {
10668 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010669 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080010670 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010671
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010672 ret = register_reboot_notifier(&system_reboot_notifier);
10673 if (ret) {
10674 hdd_err("Failed to register reboot notifier: %d", ret);
10675 goto err_unregister_netdev;
10676 }
10677
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010678 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010679
Jeff Johnson957bc272017-02-02 08:54:48 -080010680 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10681 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010682 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010683 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010684 }
10685
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010686 hdd_release_rtnl_lock();
10687 rtnl_held = false;
10688
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010689 wlan_hdd_update_11n_mode(hdd_ctx->config);
10690
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010691#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010692 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010693 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010694 hdd_skip_acs_scan_timer_handler,
10695 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010696 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010697 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010698 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010699#endif
10700
Prashanth Bhattaab004382016-10-11 16:08:11 -070010701 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010702
Jeff Johnson9afc5012016-09-23 13:56:27 -070010703 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010704
Nirav Shahbd36b062016-07-18 11:12:59 +053010705 if (hdd_ctx->rps)
10706 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010707
Paul Zhangfb02f452017-12-22 11:58:43 +080010708 ret = hdd_register_notifiers(hdd_ctx);
10709 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010710 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010711
Paul Zhangfb02f452017-12-22 11:58:43 +080010712 status = wlansap_global_init();
10713 if (QDF_IS_STATUS_ERROR(status)) {
10714 hdd_unregister_notifiers(hdd_ctx);
10715 goto err_close_adapters;
10716 }
10717
Arun Khandavallifae92942016-08-01 13:31:08 +053010718 if (hdd_ctx->config->fIsImpsEnabled)
10719 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010720 else
10721 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010722
Mukul Sharma07bd8752017-10-10 16:58:14 +053010723 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010724 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10725 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010726 hdd_prevent_suspend_timeout(
10727 hdd_ctx->config->iface_change_wait_time,
10728 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10729 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010730
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010731 goto success;
10732
Jeff Johnson957bc272017-02-02 08:54:48 -080010733err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010734 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010735
Jeff Johnson46bde382017-02-01 15:31:16 -080010736err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010737 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010738 if (rtnl_held)
10739 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010741err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010742 unregister_netdevice_notifier(&hdd_netdev_notifier);
10743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010744err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010745 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010746
Arun Khandavallifae92942016-08-01 13:31:08 +053010747err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010748 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010749
Dustin Brown021cecd2017-12-11 13:56:43 -080010750err_memdump_deinit:
10751 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010752
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010753 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070010754 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010755 hdd_exit_netlink_services(hdd_ctx);
10756
Dustin Brown20912462017-06-07 13:48:25 -070010757 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10758
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010759err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010760 if (cds_is_fw_down())
10761 hdd_err("Not setting the complete event as fw is down");
10762 else
10763 hdd_start_complete(ret);
10764
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010765 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010766 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010767 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010768
10769success:
Dustin Browne74003f2018-03-14 12:51:58 -070010770 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010771 return 0;
10772}
10773
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010774/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010775 * hdd_wlan_update_target_info() - update target type info
10776 * @hdd_ctx: HDD context
10777 * @context: hif context
10778 *
10779 * Update target info received from firmware in hdd context
10780 * Return:None
10781 */
10782
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010783void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010784{
10785 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10786
10787 if (!tgt_info) {
10788 hdd_err("Target info is Null");
10789 return;
10790 }
10791
10792 hdd_ctx->target_type = tgt_info->target_type;
10793}
10794
10795/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010796 * hdd_get_nud_stats_cb() - callback api to update the stats
10797 * received from the firmware
10798 * @data: pointer to adapter.
10799 * @rsp: pointer to data received from FW.
10800 *
10801 * This is called when wlan driver received response event for
10802 * get arp stats to firmware.
10803 *
10804 * Return: None
10805 */
10806static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10807{
10808 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10809 struct hdd_nud_stats_context *context;
10810 int status;
10811 struct hdd_adapter *adapter = NULL;
10812
Dustin Brown491d54b2018-03-14 12:39:11 -070010813 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010814
10815 if (!rsp) {
10816 hdd_err("data is null");
10817 return;
10818 }
10819
10820 status = wlan_hdd_validate_context(hdd_ctx);
10821 if (0 != status)
10822 return;
10823
10824 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10825 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10826 hdd_err("Invalid adapter or adapter has invalid magic");
10827 return;
10828 }
10829
Dustin Brown5e89ef82018-03-14 11:50:23 -070010830 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10831 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10832 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10833 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10834 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10835 rsp->out_of_order_arp_rsp_drop_cnt);
10836 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
10837 hdd_info("rsp->connect_status :%x", rsp->connect_status);
10838 hdd_info("rsp->ba_session_establishment_status :%x",
10839 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010840
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010841 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010842 adapter->dad |= rsp->dad_detected;
10843 adapter->con_status = rsp->connect_status;
10844
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053010845 /* Flag true indicates connectivity check stats present. */
10846 if (rsp->connect_stats_present) {
10847 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
10848 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
10849 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
10850 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
10851 rsp->icmpv4_rsp_recvd;
10852 }
10853
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010854 spin_lock(&hdd_context_lock);
10855 context = &hdd_ctx->nud_stats_context;
10856 complete(&context->response_event);
10857 spin_unlock(&hdd_context_lock);
10858
Dustin Browne74003f2018-03-14 12:51:58 -070010859 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010860}
10861
10862/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010863 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010864 * @hdd_ctx: HDD context
10865 *
10866 * Register the HDD callbacks to CDS/SME.
10867 *
10868 * Return: 0 for success or Error code for failure
10869 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010870int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010871{
10872 QDF_STATUS status;
10873 int ret = 0;
10874
Dustin Brown491d54b2018-03-14 12:39:11 -070010875 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010876
10877 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10878
10879 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10880 hdd_send_oem_data_rsp_msg);
10881
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010882 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10883 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010884 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10885 sme_nan_register_callback(hdd_ctx->hHal,
10886 wlan_hdd_cfg80211_nan_callback);
10887 sme_stats_ext_register_callback(hdd_ctx->hHal,
10888 wlan_hdd_cfg80211_stats_ext_callback);
10889
10890 sme_ext_scan_register_callback(hdd_ctx->hHal,
10891 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010892 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10893 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010894
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010895 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10896 hdd_rssi_threshold_breached);
10897
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010898 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10899
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010900 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10901 wlan_hdd_cfg80211_link_layer_stats_callback);
10902
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010903 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10904
Zhang Qianca38fb12016-12-23 11:10:48 +080010905 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10906 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10907
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010908 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10909 hdd_lost_link_info_cb);
10910 /* print error and not block the startup process */
10911 if (!QDF_IS_STATUS_SUCCESS(status))
10912 hdd_err("set lost link info callback failed");
10913
Poddar, Siddarth34872782017-08-10 14:08:51 +053010914 ret = hdd_register_data_stall_detect_cb();
10915 if (ret) {
10916 hdd_err("Register data stall detect detect callback failed.");
10917 return ret;
10918 }
10919
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010920 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10921
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010922 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010923 hdd_set_connection_in_progress,
10924 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010925
10926 status = sme_congestion_register_callback(hdd_ctx->hHal,
10927 hdd_update_cca_info_cb);
10928 if (!QDF_IS_STATUS_SUCCESS(status))
10929 hdd_err("set congestion callback failed");
10930
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010931 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10932 hdd_bt_activity_cb);
10933 if (!QDF_IS_STATUS_SUCCESS(status))
10934 hdd_err("set bt activity info callback failed");
10935
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010936 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10937 hdd_tx_queue_cb);
10938 if (!QDF_IS_STATUS_SUCCESS(status))
10939 hdd_err("Register tx queue callback failed");
10940
Dustin Browne74003f2018-03-14 12:51:58 -070010941 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010942
10943 return ret;
10944}
10945
10946/**
10947 * hdd_deregister_cb() - De-Register HDD callbacks.
10948 * @hdd_ctx: HDD context
10949 *
10950 * De-Register the HDD callbacks to CDS/SME.
10951 *
10952 * Return: void
10953 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010954void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010955{
10956 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010957 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010958
Dustin Brown491d54b2018-03-14 12:39:11 -070010959 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010960
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010961 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010962 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10963 if (!QDF_IS_STATUS_SUCCESS(status))
10964 hdd_err("De-register of dcc stats callback failed: %d",
10965 status);
10966
10967 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010968 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10969
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010970 sme_stats_ext_register_callback(hdd_ctx->hHal,
10971 wlan_hdd_cfg80211_stats_ext_callback);
10972
10973 sme_nan_deregister_callback(hdd_ctx->hHal);
10974 status = sme_reset_tsfcb(hdd_ctx->hHal);
10975 if (!QDF_IS_STATUS_SUCCESS(status))
10976 hdd_err("Failed to de-register tsfcb the callback:%d",
10977 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010978
Poddar, Siddarth34872782017-08-10 14:08:51 +053010979 ret = hdd_deregister_data_stall_detect_cb();
10980 if (ret)
10981 hdd_err("Failed to de-register data stall detect event callback");
10982
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010983 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10984 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10985
Dustin Browne74003f2018-03-14 12:51:58 -070010986 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010987}
10988
10989/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010990 * hdd_softap_sta_deauth() - handle deauth req from HDD
10991 * @adapter: Pointer to the HDD
10992 * @enable: bool value
10993 *
10994 * This to take counter measure to handle deauth req from HDD
10995 *
10996 * Return: None
10997 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010998QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010999 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011000{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011001 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011002
Dustin Brown491d54b2018-03-14 12:39:11 -070011003 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011004
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011005 /* Ignore request to deauth bcmc station */
11006 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011007 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011008
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011009 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011010 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11011 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011012
Dustin Browne74003f2018-03-14 12:51:58 -070011013 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011014 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011015}
11016
11017/**
11018 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11019 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011020 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011021 *
11022 * This to take counter measure to handle deauth req from HDD
11023 *
11024 * Return: None
11025 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011026void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011027 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011028{
Dustin Brown491d54b2018-03-14 12:39:11 -070011029 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011031 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011032 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011033 return;
11034
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011035 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011036 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011037}
11038
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011039/**
11040 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11041 * @hdd_ctx: HDD Context
11042 *
11043 * API to find if there is any STA or P2P-Client is connected
11044 *
11045 * Return: true if connected; false otherwise
11046 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011047QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011048{
11049 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
11050}
11051
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011052/**
11053 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
11054 * @adapter: HDD adapter pointer
11055 *
11056 * This function loop through each adapter and disable roaming on each STA
11057 * device mode except the input adapter.
11058 *
11059 * Note: On the input adapter roaming is not enabled yet hence no need to
11060 * disable.
11061 *
11062 * Return: None
11063 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011064void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011065{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011066 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011067 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011068
11069 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011070 hdd_ctx->config->isRoamOffloadScanEnabled &&
11071 QDF_STA_MODE == adapter->device_mode &&
11072 policy_mgr_is_sta_active_connection_exists(
11073 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011074 hdd_debug("Connect received on STA session Id(%d)",
11075 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011076 /*
11077 * Loop through adapter and disable roaming for each STA device
11078 * mode except the input adapter.
11079 */
Dustin Brown920397d2017-12-13 16:27:50 -080011080 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011081 if (QDF_STA_MODE == adapterIdx->device_mode &&
11082 adapter->session_id != adapterIdx->session_id) {
11083 hdd_debug("Disable Roaming on session Id(%d)",
11084 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011085 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
11086 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011087 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011088 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011089 }
11090 }
11091}
11092
11093/**
11094 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
11095 * @adapter: HDD adapter pointer
11096 *
11097 * This function loop through each adapter and enable roaming on each STA
11098 * device mode except the input adapter.
11099 * Note: On the input adapter no need to enable roaming because link got
11100 * disconnected on this.
11101 *
11102 * Return: None
11103 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011104void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011105{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011106 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011107 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011108
11109 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011110 hdd_ctx->config->isRoamOffloadScanEnabled &&
11111 QDF_STA_MODE == adapter->device_mode &&
11112 policy_mgr_is_sta_active_connection_exists(
11113 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011114 hdd_debug("Disconnect received on STA session Id(%d)",
11115 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011116 /*
11117 * Loop through adapter and enable roaming for each STA device
11118 * mode except the input adapter.
11119 */
Dustin Brown920397d2017-12-13 16:27:50 -080011120 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011121 if (QDF_STA_MODE == adapterIdx->device_mode &&
11122 adapter->session_id != adapterIdx->session_id) {
11123 hdd_debug("Enabling Roaming on session Id(%d)",
11124 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011125 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
11126 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011127 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011128 REASON_CONNECT);
11129 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011130 }
11131 }
11132}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011133
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011134/**
11135 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11136 * @skb: sk buffer pointer
11137 *
11138 * Sends the bcast message to SVC multicast group with generic nl socket
11139 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11140 *
11141 * Return: None
11142 */
11143static void nl_srv_bcast_svc(struct sk_buff *skb)
11144{
11145#ifdef CNSS_GENL
11146 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11147#else
11148 nl_srv_bcast(skb);
11149#endif
11150}
11151
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011152void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011153{
11154 struct sk_buff *skb;
11155 struct nlmsghdr *nlh;
11156 tAniMsgHdr *ani_hdr;
11157 void *nl_data = NULL;
11158 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011159 struct radio_index_tlv *radio_info;
11160 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011161
11162 if (in_interrupt() || irqs_disabled() || in_atomic())
11163 flags = GFP_ATOMIC;
11164
11165 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11166
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011167 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011168 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011169
11170 nlh = (struct nlmsghdr *)skb->data;
11171 nlh->nlmsg_pid = 0; /* from kernel */
11172 nlh->nlmsg_flags = 0;
11173 nlh->nlmsg_seq = 0;
11174 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11175
11176 ani_hdr = NLMSG_DATA(nlh);
11177 ani_hdr->type = type;
11178
11179 switch (type) {
11180 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011181 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011182 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011183 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011184 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011185 ani_hdr->length = 0;
11186 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011187 break;
11188 case WLAN_SVC_WLAN_STATUS_IND:
11189 case WLAN_SVC_WLAN_VERSION_IND:
11190 case WLAN_SVC_DFS_CAC_START_IND:
11191 case WLAN_SVC_DFS_CAC_END_IND:
11192 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11193 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11194 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011195 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011196 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011197 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011198 ani_hdr->length = len;
11199 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11200 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11201 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011202 break;
11203
11204 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011205 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011206 type);
11207 kfree_skb(skb);
11208 return;
11209 }
11210
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011211 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011212 * Add radio index at the end of the svc event in TLV format
11213 * to maintain the backward compatibility with userspace
11214 * applications.
11215 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011216
11217 tlv_len = 0;
11218
11219 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11220 < WLAN_NL_MAX_PAYLOAD) {
11221 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11222 sizeof(*ani_hdr) + len);
11223 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11224 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11225 radio_info->radio = radio;
11226 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011227 hdd_debug("Added radio index tlv - radio index %d",
11228 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011229 }
11230
11231 nlh->nlmsg_len += tlv_len;
11232 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11233
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011234 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011235}
11236
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011237#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11238void wlan_hdd_auto_shutdown_cb(void)
11239{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011240 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011241
11242 if (!hdd_ctx)
11243 return;
11244
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011245 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011246 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11247 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011248}
11249
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011250void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011251{
Jeff Johnson9d295242017-08-29 14:39:48 -070011252 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011253 bool ap_connected = false, sta_connected = false;
11254 tHalHandle hal_handle;
11255
11256 hal_handle = hdd_ctx->hHal;
11257 if (hal_handle == NULL)
11258 return;
11259
11260 if (hdd_ctx->config->WlanAutoShutdown == 0)
11261 return;
11262
11263 if (enable == false) {
11264 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011265 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011266 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011267 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011268 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011269 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011270 return;
11271 }
11272
11273 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011274 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11275 hdd_for_each_adapter(hdd_ctx, adapter) {
11276 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011277 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11278 conn_info.connState ==
11279 eConnectionState_Associated) {
11280 sta_connected = true;
11281 break;
11282 }
11283 }
Dustin Brown920397d2017-12-13 16:27:50 -080011284
11285 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011286 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011287 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011288 ap_connected = true;
11289 break;
11290 }
11291 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011292 }
11293 }
11294
11295 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011296 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011297 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011298 }
Jeff Johnson68755312017-02-10 11:46:55 -080011299
11300 if (sme_set_auto_shutdown_timer(hal_handle,
11301 hdd_ctx->config->WlanAutoShutdown)
11302 != QDF_STATUS_SUCCESS)
11303 hdd_err("Failed to start wlan auto shutdown timer");
11304 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011305 hdd_info("Auto Shutdown timer for %d seconds enabled",
11306 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011307}
11308#endif
11309
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011310struct hdd_adapter *
11311hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11312 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011313{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011314 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011315 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011316
11317 con_sap_adapter = NULL;
11318
Dustin Brown920397d2017-12-13 16:27:50 -080011319 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011320 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11321 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011322 adapter != this_sap_adapter) {
11323 if (check_start_bss) {
11324 if (test_bit(SOFTAP_BSS_STARTED,
11325 &adapter->event_flags)) {
11326 con_sap_adapter = adapter;
11327 break;
11328 }
11329 } else {
11330 con_sap_adapter = adapter;
11331 break;
11332 }
11333 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011334 }
11335
11336 return con_sap_adapter;
11337}
11338
11339#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011340static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011341{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011342 return adapter->device_mode == QDF_STA_MODE ||
11343 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011344}
11345
Jeff Johnson9d295242017-08-29 14:39:48 -070011346static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011347{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011348 return adapter->device_mode == QDF_SAP_MODE ||
11349 adapter->device_mode == QDF_P2P_GO_MODE;
11350}
11351
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011352static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011353{
Dustin Brown920397d2017-12-13 16:27:50 -080011354 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011355
Dustin Brown920397d2017-12-13 16:27:50 -080011356 hdd_for_each_adapter(hdd_ctx, adapter) {
11357 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011358 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11359 conn_info.connState == eConnectionState_Associated) {
11360 return true;
11361 }
11362
Dustin Brown920397d2017-12-13 16:27:50 -080011363 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011364 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011365 return true;
11366 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011367 }
11368
11369 return false;
11370}
11371
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011372static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011373{
11374 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011375
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011376 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011377 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011378 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011379
Dustin Brown5ec6b552017-03-31 12:11:40 -070011380 return is_running;
11381}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011382
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011383static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011384{
11385 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11386 hdd_ctx->bus_bw_timer_running = true;
11387 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11388 hdd_ctx->config->busBandwidthComputeInterval);
11389 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11390}
11391
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011392void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011393{
Dustin Brown491d54b2018-03-14 12:39:11 -070011394 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011395
11396 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11397 hdd_debug("Bandwidth compute timer already started");
11398 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011399 }
11400
Dustin Brown5ec6b552017-03-31 12:11:40 -070011401 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11402
Dustin Browne74003f2018-03-14 12:51:58 -070011403 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011404}
11405
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011406void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011407{
Dustin Brown491d54b2018-03-14 12:39:11 -070011408 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011409
11410 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11411 hdd_debug("Bandwidth compute timer already started");
11412 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011413 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011414
11415 if (hdd_any_adapter_is_assoc(hdd_ctx))
11416 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11417
Dustin Browne74003f2018-03-14 12:51:58 -070011418 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011419}
11420
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011421static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011422{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011423 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011424
11425 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11426 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11427 hdd_ctx->bus_bw_timer_running = false;
11428 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11429
11430 hdd_reset_tcp_delack(hdd_ctx);
11431}
11432
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011433void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011434{
Dustin Brown491d54b2018-03-14 12:39:11 -070011435 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011436
11437 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11438 hdd_debug("Bandwidth compute timer already stopped");
11439 return;
11440 }
11441
11442 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11443
Dustin Browne74003f2018-03-14 12:51:58 -070011444 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011445}
11446
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011447void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011448{
Dustin Brown491d54b2018-03-14 12:39:11 -070011449 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011450
11451 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11452 hdd_debug("Bandwidth compute timer already stopped");
11453 return;
11454 }
11455
11456 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11457 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11458
Dustin Browne74003f2018-03-14 12:51:58 -070011459 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011460}
11461#endif
11462
11463/**
11464 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11465 * and sta's operating channel.
11466 * @sta_adapter: Describe the first argument to foobar.
11467 * @ap_adapter: Describe the second argument to foobar.
11468 * @roam_profile: Roam profile of AP to which STA wants to connect.
11469 * @concurrent_chnl_same: If both SAP and STA channels are same then
11470 * set this flag to true else false.
11471 *
11472 * This function checks the sap's operating channel and sta's operating channel.
11473 * if both are same then it will return false else it will restart the sap in
11474 * sta's channel and return true.
11475 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011476 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011477 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011478QDF_STATUS
11479wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11480 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011481 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011482 tScanResultHandle *scan_cache,
11483 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011484{
Jeff Johnson87251032017-08-29 13:31:11 -070011485 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011486 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011487 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011488 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011489 *concurrent_chnl_same = true;
11490
11491 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11492 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011493 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011494 scan_cache,
11495 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011496 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011497 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011498 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011499 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011500 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011501 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011502 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011503 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011504 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011505 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011506 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011507 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011508 }
11509 }
11510 } else {
11511 /*
11512 * Lets handle worst case scenario here, Scan cache lookup is
11513 * failed so we have to stop the SAP to avoid any channel
11514 * discrepancy between SAP's channel and STA's channel.
11515 * Return the status as failure so caller function could know
11516 * that scan look up is failed.
11517 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011518 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011519 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011520 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011521 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011522}
11523
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011524/**
11525 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11526 * @ap_adapter: SAP adapter
11527 *
11528 * This function will process the stopping of sap adapter.
11529 *
11530 * Return: None
11531 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011532void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011533{
Jeff Johnson87251032017-08-29 13:31:11 -070011534 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011535 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011536 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011537 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011538
11539 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011540 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011541 return;
11542 }
11543
11544 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11545 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011546 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011547 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011548
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011549 mutex_lock(&hdd_ctx->sap_lock);
11550 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011551 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011552 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011553 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011554 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011555 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011556 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011557 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011558 qdf_stop_bss_event,
11559 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011560 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011561 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011562 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011563 return;
11564 }
11565 }
11566 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011567 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11568 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011569 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011570 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011571 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011572 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011573 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011574 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011575 }
11576 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011577}
11578
11579/**
11580 * wlan_hdd_start_sap() - this function starts bss of SAP.
11581 * @ap_adapter: SAP adapter
11582 *
11583 * This function will process the starting of sap adapter.
11584 *
11585 * Return: None
11586 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011587void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011588{
Jeff Johnson87251032017-08-29 13:31:11 -070011589 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011590 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011591 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011592 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011593 tsap_Config_t *sap_config;
11594
11595 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011596 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011597 return;
11598 }
11599
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011600 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011601 hdd_err("SoftAp role has not been enabled");
11602 return;
11603 }
11604
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011605 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11606 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11607 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011608 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011610 mutex_lock(&hdd_ctx->sap_lock);
11611 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11612 goto end;
11613
11614 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011615 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011616 goto end;
11617 }
11618
Wei Song2f76f642016-11-18 16:32:53 +080011619 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011620 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011621 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011622 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011623 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011624 goto end;
11625
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011626 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011627 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011628 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011629 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011630 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011631 goto end;
11632 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011633 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011634 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011635 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011636 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011637 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11638 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011639 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011640 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011641 true);
11642 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011643 mutex_unlock(&hdd_ctx->sap_lock);
11644
11645 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011646end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011647 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011648 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011649 /* SAP context and beacon cleanup will happen during driver unload
11650 * in hdd_stop_adapter
11651 */
11652 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11653
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011654}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011655
11656/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011657 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11658 * mac scan config
11659 * @status: Status of set antenna mode
11660 *
11661 * Callback on setting the dual mac configuration
11662 *
11663 * Return: None
11664 */
11665void wlan_hdd_soc_set_antenna_mode_cb(
11666 enum set_antenna_mode_status status)
11667{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011668 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011669
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011670 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011671
11672 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11673 if (0 != wlan_hdd_validate_context(hdd_ctx))
11674 return;
11675
11676 /* Signal the completion of set dual mac config */
11677 complete(&hdd_ctx->set_antenna_mode_cmpl);
11678}
11679
11680/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011681 * hdd_get_fw_version() - Get FW version
11682 * @hdd_ctx: pointer to HDD context.
11683 * @major_spid: FW version - major spid.
11684 * @minor_spid: FW version - minor spid
11685 * @ssid: FW version - ssid
11686 * @crmid: FW version - crmid
11687 *
11688 * This function is called to get the firmware build version stored
11689 * as part of the HDD context
11690 *
11691 * Return: None
11692 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011693void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011694 uint32_t *major_spid, uint32_t *minor_spid,
11695 uint32_t *siid, uint32_t *crmid)
11696{
11697 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11698 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11699 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11700 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11701}
11702
11703#ifdef QCA_CONFIG_SMP
11704/**
11705 * wlan_hdd_get_cpu() - get cpu_index
11706 *
11707 * Return: cpu_index
11708 */
11709int wlan_hdd_get_cpu(void)
11710{
11711 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011712
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011713 put_cpu();
11714 return cpu_index;
11715}
11716#endif
11717
11718/**
11719 * hdd_get_fwpath() - get framework path
11720 *
11721 * This function is used to get the string written by
11722 * userspace to start the wlan driver
11723 *
11724 * Return: string
11725 */
11726const char *hdd_get_fwpath(void)
11727{
11728 return fwpath.string;
11729}
11730
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011731static int hdd_qdf_print_init(void)
11732{
11733 int qdf_print_idx;
11734 QDF_STATUS status;
11735
11736 status = qdf_print_setup();
11737 if (status != QDF_STATUS_SUCCESS) {
11738 pr_err("qdf_print_setup failed\n");
11739 return -EINVAL;
11740 }
11741
11742 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11743
11744 if (qdf_print_idx < 0) {
11745 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11746 qdf_print_idx);
11747 return -EINVAL;
11748 }
11749
11750 qdf_set_pidx(qdf_print_idx);
11751
11752 return 0;
11753}
11754
11755static void hdd_qdf_print_deinit(void)
11756{
11757 int qdf_print_idx;
11758
11759 qdf_print_idx = qdf_get_pidx();
11760 qdf_print_ctrl_cleanup(qdf_print_idx);
11761}
11762
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011763/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011764 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011765 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011766 * This function initilizes CDS global context with the help of cds_init. This
11767 * has to be the first function called after probe to get a valid global
11768 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011769 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011770 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011771 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011772int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011773{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011774 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011775 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011776
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011777 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011778 if (QDF_IS_STATUS_ERROR(status)) {
11779 hdd_err("Failed to allocate CDS context");
11780 ret = -ENOMEM;
11781 goto err_out;
11782 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011783
11784 wlan_init_bug_report_lock();
11785
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011786#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11787 wlan_logging_sock_init_svc();
11788#endif
11789
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011790 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11791 (void *)hdd_drv_ops_inactivity_handler, NULL,
11792 QDF_TIMER_TYPE_SW);
11793
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011794 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011795 hdd_qdf_print_init();
11796
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011797 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011798
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011799err_out:
11800 return ret;
11801}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011802
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011803/**
11804 * hdd_deinit() - Deinitialize Driver
11805 *
11806 * This function frees CDS global context with the help of cds_deinit. This
11807 * has to be the last function call in remove callback to free the global
11808 * context.
11809 */
11810void hdd_deinit(void)
11811{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011812 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011813
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011814 wlan_destroy_bug_report_lock();
11815 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011816
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011817 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011818#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11819 wlan_logging_sock_deinit_svc();
11820#endif
11821}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011822
Yue Ma6e7b1a02017-04-03 14:17:46 -070011823#ifdef QCA_WIFI_NAPIER_EMULATION
11824#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11825#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011826#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011827#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011828
Sachin Ahujadddd2632017-03-07 19:07:24 +053011829static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11830 struct file *file)
11831{
11832 return 0;
11833}
11834
11835static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11836 const char __user *user_buf,
11837 size_t count,
11838 loff_t *f_pos)
11839{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011840 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011841 static const char wlan_off_str[] = "OFF";
11842 static const char wlan_on_str[] = "ON";
11843 int ret;
11844 unsigned long rc;
11845
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011846 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011847 pr_err("Failed to read buffer\n");
11848 return -EINVAL;
11849 }
11850
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011851 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011852 pr_debug("Wifi turning off from UI\n");
11853 goto exit;
11854 }
11855
Sachin Ahuja16904db2017-12-13 19:56:57 +053011856 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
11857 pr_info("Wifi Turning On from UI\n");
11858 }
11859
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011860 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011861 pr_err("Invalid value received from framework");
11862 goto exit;
11863 }
11864
11865 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011866 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011867 rc = wait_for_completion_timeout(&wlan_start_comp,
11868 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11869 if (!rc) {
11870 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11871 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053011872 return ret;
11873 }
11874
11875 hdd_start_complete(0);
11876 }
11877
11878exit:
11879 return count;
11880}
11881
11882
11883const struct file_operations wlan_hdd_state_fops = {
11884 .owner = THIS_MODULE,
11885 .open = wlan_hdd_state_ctrl_param_open,
11886 .write = wlan_hdd_state_ctrl_param_write,
11887};
11888
11889static int wlan_hdd_state_ctrl_param_create(void)
11890{
11891 unsigned int wlan_hdd_state_major = 0;
11892 int ret;
11893 struct device *dev;
11894
11895 device = MKDEV(wlan_hdd_state_major, 0);
11896
11897 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11898 if (ret) {
11899 pr_err("Failed to register qcwlanstate");
11900 goto dev_alloc_err;
11901 }
11902 wlan_hdd_state_major = MAJOR(device);
11903
11904 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11905 if (IS_ERR(class)) {
11906 pr_err("wlan_hdd_state class_create error");
11907 goto class_err;
11908 }
11909
11910 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11911 if (IS_ERR(dev)) {
11912 pr_err("wlan_hdd_statedevice_create error");
11913 goto err_class_destroy;
11914 }
11915
11916 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11917 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11918 if (ret) {
11919 pr_err("Failed to add cdev error");
11920 goto cdev_add_err;
11921 }
11922
11923 pr_info("wlan_hdd_state %s major(%d) initialized",
11924 WLAN_MODULE_NAME, wlan_hdd_state_major);
11925
11926 return 0;
11927
11928cdev_add_err:
11929 device_destroy(class, device);
11930err_class_destroy:
11931 class_destroy(class);
11932class_err:
11933 unregister_chrdev_region(device, dev_num);
11934dev_alloc_err:
11935 return -ENODEV;
11936}
11937
11938static void wlan_hdd_state_ctrl_param_destroy(void)
11939{
11940 cdev_del(&wlan_hdd_state_cdev);
11941 device_destroy(class, device);
11942 class_destroy(class);
11943 unregister_chrdev_region(device, dev_num);
11944
11945 pr_info("Device node unregistered");
11946}
11947
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011948/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011949 * component_init - API to init cld component's
11950 *
11951 * Return: None
11952 */
11953static void component_init(void)
11954{
11955 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011956 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011957 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011958 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011959}
11960
11961/**
11962 * component_deinit - API to deinit cld component's
11963 *
11964 * Return: None
11965 */
11966static void component_deinit(void)
11967{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011968 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011969 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011970 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011971 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011972}
11973
11974void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11975{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011976 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011977 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011978}
11979
11980void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11981{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011982 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011983 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011984}
11985
11986/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011987 * __hdd_module_init - Module init helper
11988 *
11989 * Module init helper function used by both module and static driver.
11990 *
11991 * Return: 0 for success, errno on failure
11992 */
11993static int __hdd_module_init(void)
11994{
11995 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011996
Dustin Brown96cd9632017-11-13 12:45:04 -080011997 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011998 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011999 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012000 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012001
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012002 pld_init();
12003
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012004 ret = hdd_init();
12005 if (ret) {
12006 pr_err("hdd_init failed %x\n", ret);
12007 goto err_hdd_init;
12008 }
12009
Rajeev Kumar97767a02016-11-30 11:20:40 -080012010 dispatcher_init();
12011
Mukul Sharmad75a6672017-06-22 15:40:53 +053012012 /* Ensure to call post objmgr init */
12013 component_init();
12014
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012015 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012016
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012017 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012018
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012019 ret = wlan_hdd_register_driver();
12020 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012021 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12022 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012023 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012024 }
12025
Sachin Ahuja16904db2017-12-13 19:56:57 +053012026 ret = wlan_hdd_state_ctrl_param_create();
12027 if (ret) {
12028 pr_err("wlan_hdd_state_create:%x\n", ret);
12029 goto out;
12030 }
12031
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012032 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012033
12034 return 0;
12035out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012036 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012037 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012038 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012039 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012040
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012041err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012042 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012043 return ret;
12044}
12045
12046/**
12047 * __hdd_module_exit - Module exit helper
12048 *
12049 * Module exit helper function used by both module and static driver.
12050 */
12051static void __hdd_module_exit(void)
12052{
Will Huang36049722018-04-13 11:48:51 +080012053 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012054
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012055 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12056 QWLAN_VERSIONSTR);
12057
Will Huang36049722018-04-13 11:48:51 +080012058 if (!hdd_ctx) {
12059 hdd_err("hdd context is NULL return!!");
12060 return;
12061 }
12062
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012063 if (!hdd_wait_for_recovery_completion())
12064 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012065
Will Huang36049722018-04-13 11:48:51 +080012066 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
12067
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012068 wlan_hdd_unregister_driver();
12069
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012070 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012071
Mukul Sharmad75a6672017-06-22 15:40:53 +053012072 /* Ensure to call prior to objmgr deinit */
12073 component_deinit();
12074
Rajeev Kumar97767a02016-11-30 11:20:40 -080012075 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012076
12077 hdd_sysfs_destroy_version_interface();
12078
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012079 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012080 pld_deinit();
12081
Sachin Ahujadddd2632017-03-07 19:07:24 +053012082 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012083}
12084
Arun Khandavallifae92942016-08-01 13:31:08 +053012085#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012086/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012087 * wlan_boot_cb() - Wlan boot callback
12088 * @kobj: object whose directory we're creating the link in.
12089 * @attr: attribute the user is interacting with
12090 * @buff: the buffer containing the user data
12091 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012092 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012093 * This callback is invoked when the fs is ready to start the
12094 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012095 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012096 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012097 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012098static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012099 struct kobj_attribute *attr,
12100 const char *buf,
12101 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012102{
Arun Khandavallifae92942016-08-01 13:31:08 +053012103
Arun Khandavallifae92942016-08-01 13:31:08 +053012104 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012105 pr_err("%s: wlan driver already initialized\n", __func__);
12106 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012107 }
12108
Arun Khandavallifae92942016-08-01 13:31:08 +053012109 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012110 pr_err("%s: wlan driver initialization failed\n", __func__);
12111 return -EIO;
12112 }
12113
12114 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012115
12116 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012117}
Arun Khandavallifae92942016-08-01 13:31:08 +053012118
12119/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012120 * hdd_sysfs_cleanup() - cleanup sysfs
12121 *
12122 * Return: None
12123 *
12124 */
12125static void hdd_sysfs_cleanup(void)
12126{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012127 /* remove from group */
12128 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12129 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12130 wlan_loader->attr_group);
12131
12132 /* unlink the object from parent */
12133 kobject_del(wlan_loader->boot_wlan_obj);
12134
12135 /* free the object */
12136 kobject_put(wlan_loader->boot_wlan_obj);
12137
12138 kfree(wlan_loader->attr_group);
12139 kfree(wlan_loader);
12140
12141 wlan_loader = NULL;
12142}
12143
12144/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012145 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12146 * ready
12147 *
12148 * This is creates the syfs entry boot_wlan. Which shall be invoked
12149 * when the filesystem is ready.
12150 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012151 * QDF API cannot be used here since this function is called even before
12152 * initializing WLAN driver.
12153 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012154 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012155 */
12156static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012157{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012158 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012159
12160 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012161 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012162 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012163
12164 wlan_loader->boot_wlan_obj = NULL;
12165 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12166 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012167 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012168 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012169
12170 wlan_loader->loaded_state = 0;
12171 wlan_loader->attr_group->attrs = attrs;
12172
12173 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12174 kernel_kobj);
12175 if (!wlan_loader->boot_wlan_obj) {
12176 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012177 goto error_return;
12178 }
12179
12180 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12181 wlan_loader->attr_group);
12182 if (ret) {
12183 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12184 goto error_return;
12185 }
12186
12187 return 0;
12188
12189error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012190 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012191
12192 return ret;
12193}
12194
12195/**
12196 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12197 *
12198 * Return: 0 on success or errno on failure
12199 */
12200static int wlan_deinit_sysfs(void)
12201{
Arun Khandavallifae92942016-08-01 13:31:08 +053012202 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012203 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012204 return -EINVAL;
12205 }
12206
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012207 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012208 return 0;
12209}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012210
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012211#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012212
12213#ifdef MODULE
12214/**
12215 * __hdd_module_init - Module init helper
12216 *
12217 * Module init helper function used by both module and static driver.
12218 *
12219 * Return: 0 for success, errno on failure
12220 */
12221static int hdd_module_init(void)
12222{
Arun Khandavallifae92942016-08-01 13:31:08 +053012223 if (__hdd_module_init()) {
12224 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012225 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012226 }
12227
Dustin Brownab482ac2017-06-09 17:00:44 -070012228 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012229}
12230#else
12231static int __init hdd_module_init(void)
12232{
12233 int ret = -EINVAL;
12234
12235 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012236 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012237 pr_err("Failed to create sysfs entry for loading wlan");
12238
12239 return ret;
12240}
12241#endif
12242
12243
12244#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012245/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012246 * hdd_module_exit() - Exit function
12247 *
12248 * This is the driver exit point (invoked when module is unloaded using rmmod)
12249 *
12250 * Return: None
12251 */
12252static void __exit hdd_module_exit(void)
12253{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012254 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012255}
Arun Khandavallifae92942016-08-01 13:31:08 +053012256#else
12257static void __exit hdd_module_exit(void)
12258{
12259 __hdd_module_exit();
12260 wlan_deinit_sysfs();
12261}
12262#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012263
Srinivas Girigowda841da292018-02-21 16:33:00 -080012264static int fwpath_changed_handler(const char *kmessage,
12265 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012266{
12267 return param_set_copystring(kmessage, kp);
12268}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012269
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012270/**
12271 * is_con_mode_valid() check con mode is valid or not
12272 * @mode: global con mode
12273 *
12274 * Return: TRUE on success FALSE on failure
12275 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012276static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012277{
12278 switch (mode) {
12279 case QDF_GLOBAL_MONITOR_MODE:
12280 case QDF_GLOBAL_FTM_MODE:
12281 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012282 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012283 return true;
12284 default:
12285 return false;
12286 }
12287}
12288
12289/**
12290 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12291 * @mode: global con mode
12292 *
12293 * Return: adapter mode
12294 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012295static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012296 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012297{
12298
12299 switch (mode) {
12300 case QDF_GLOBAL_MISSION_MODE:
12301 return QDF_STA_MODE;
12302 case QDF_GLOBAL_MONITOR_MODE:
12303 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012304 case QDF_GLOBAL_EPPING_MODE:
12305 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012306 case QDF_GLOBAL_FTM_MODE:
12307 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012308 case QDF_GLOBAL_QVIT_MODE:
12309 return QDF_QVIT_MODE;
12310 default:
12311 return QDF_MAX_NO_OF_MODE;
12312 }
12313}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012314
Dustin Brown27cd9942017-09-27 16:11:44 -070012315static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012316 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012317{
12318 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12319 return;
12320
12321 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012322 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012323 hdd_info("Release wakelock for monitor mode!");
12324 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12325 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12326 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012327 case QDF_GLOBAL_FTM_MODE:
12328 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012329 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012330 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012331
Dustin Brown27cd9942017-09-27 16:11:44 -070012332 break;
12333 default:
12334 break;
12335 }
12336}
12337
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012338static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012339 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012340{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012341 int driver_status;
12342
12343 driver_status = hdd_ctx->driver_status;
12344
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012345 switch (curr_mode) {
12346 case QDF_GLOBAL_MISSION_MODE:
12347 case QDF_GLOBAL_MONITOR_MODE:
12348 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012349 hdd_deinit_all_adapters(hdd_ctx, false);
12350 hdd_close_all_adapters(hdd_ctx, false);
12351 break;
12352 case QDF_GLOBAL_EPPING_MODE:
12353 epping_disable();
12354 epping_close();
12355 break;
12356 default:
12357 return;
12358 }
12359}
12360
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012361static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012362 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012363{
Jeff Johnson9d295242017-08-29 14:39:48 -070012364 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012365 int ret = 0;
12366 bool rtnl_held;
12367 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12368 QDF_STATUS status;
12369
12370 if (!qdf_dev) {
12371 hdd_err("qdf device context is Null return!");
12372 return -EINVAL;
12373 }
12374
12375 rtnl_held = hdd_hold_rtnl_lock();
12376 switch (mode) {
12377 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012378 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12379 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012380 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012381 break;
12382 case QDF_GLOBAL_FTM_MODE:
12383 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12384 wlan_hdd_get_intf_addr(hdd_ctx),
12385 NET_NAME_UNKNOWN, rtnl_held);
12386 if (adapter == NULL)
12387 ret = -EINVAL;
12388 break;
12389 case QDF_GLOBAL_MONITOR_MODE:
12390 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12391 wlan_hdd_get_intf_addr(hdd_ctx),
12392 NET_NAME_UNKNOWN, rtnl_held);
12393 if (adapter == NULL)
12394 ret = -EINVAL;
12395 break;
12396 case QDF_GLOBAL_EPPING_MODE:
12397 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012398 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012399 hdd_err("Failed to open in eeping mode: %d", status);
12400 ret = -EINVAL;
12401 break;
12402 }
12403 ret = epping_enable(qdf_dev->dev);
12404 if (ret) {
12405 hdd_err("Failed to enable in epping mode : %d", ret);
12406 epping_close();
12407 }
12408 break;
12409 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012410 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012411 ret = -ENOTSUPP;
12412 break;
12413 }
12414 hdd_release_rtnl_lock();
12415 rtnl_held = false;
12416 return ret;
12417}
12418
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012419/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012420 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012421 * @kmessage: con mode name on which driver to be bring up
12422 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012423 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012424 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012425 * This function is invoked when user updates con mode using sys entry,
12426 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012427 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012428 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012429 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012430static int __con_mode_handler(const char *kmessage,
12431 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012432 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012433{
12434 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012435 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012436 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012437 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012438 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012439
Dustin Brownab6029b2017-05-24 13:04:19 -070012440 hdd_info("con_mode handler: %s", kmessage);
12441
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012442 ret = wlan_hdd_validate_context(hdd_ctx);
12443 if (ret)
12444 return ret;
12445
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012446 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012447 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012448
Dustin Brown20024e32018-01-03 12:34:58 -080012449 ret = kstrtoint(kmessage, 0, &new_con_mode);
12450 if (ret) {
12451 hdd_err("Failed to parse con_mode '%s'", kmessage);
12452 goto reset_flags;
12453 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012454 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012455
Dustin Brown20024e32018-01-03 12:34:58 -080012456 if (!is_con_mode_valid(new_con_mode)) {
12457 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012458 ret = -EINVAL;
12459 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012460 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012461
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012462 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012463 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012464 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012465 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012466 ret = 0;
12467 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012468 }
12469
Dustin Brown27cd9942017-09-27 16:11:44 -070012470 /* ensure adapters are stopped */
12471 hdd_stop_present_mode(hdd_ctx, curr_mode);
12472
Frank Liu6666f832018-01-04 10:06:05 +080012473 /* Cleanup present mode before switching to new mode */
12474 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12475
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012476 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012477 if (ret) {
12478 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012479 goto reset_flags;
12480 }
12481
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012482
Dustin Brown20024e32018-01-03 12:34:58 -080012483 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012484
Frank Liu6666f832018-01-04 10:06:05 +080012485 /*
12486 * Set ACTIVE domain before adapters created, otherwise check domain
12487 * match will fail when cleanup adapters.
12488 */
12489 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012490 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012491 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012492 if (ret) {
12493 hdd_err("Failed to register for new mode");
12494 goto reset_flags;
12495 }
12496
Dustin Brown20024e32018-01-03 12:34:58 -080012497 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012498 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12499 hdd_err("invalid adapter");
12500 ret = -EINVAL;
12501 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012502 }
12503
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012504 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012505 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012506 hdd_err("Failed to get adapter:%d", adapter_mode);
12507 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012508 }
12509
12510 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12511 if (ret) {
12512 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012513 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012514 }
12515
Dustin Brown20024e32018-01-03 12:34:58 -080012516 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012517 if (hdd_start_adapter(adapter)) {
12518 hdd_err("Failed to start %s adapter", kmessage);
12519 ret = -EINVAL;
12520 goto reset_flags;
12521 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012522
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012523 hdd_info("Acquire wakelock for monitor mode!");
12524 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12525 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12526 }
12527
Dustin Brown20024e32018-01-03 12:34:58 -080012528 /* con_mode is a global module parameter */
12529 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012530 hdd_info("Mode successfully changed to %s", kmessage);
12531 ret = 0;
12532
12533reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012534 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012535 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012536 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012537 return ret;
12538}
12539
12540
Srinivas Girigowda841da292018-02-21 16:33:00 -080012541static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012542{
12543 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012544 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012545
12546 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12547 ret = wlan_hdd_validate_context(hdd_ctx);
12548 if (ret)
12549 return ret;
12550
12551 cds_ssr_protect(__func__);
12552 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12553 cds_ssr_unprotect(__func__);
12554
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012555 return ret;
12556}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012557
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012558static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012559 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012560{
12561 int ret;
12562
12563 ret = param_set_int(kmessage, kp);
12564
12565 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12566 pr_err("Only FTM mode supported!");
12567 return -ENOTSUPP;
12568 }
12569
12570 hdd_set_conparam(con_mode_ftm);
12571 con_mode = con_mode_ftm;
12572
12573 return ret;
12574}
12575
Ravi Joshia307f632017-07-17 23:41:41 -070012576static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012577 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012578{
12579 int ret;
12580
12581 ret = param_set_int(kmessage, kp);
12582
12583 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12584 pr_err("Only Monitor mode supported!");
12585 return -ENOTSUPP;
12586 }
12587
12588 hdd_set_conparam(con_mode_monitor);
12589 con_mode = con_mode_monitor;
12590
12591 return ret;
12592}
12593
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012594/**
12595 * hdd_get_conparam() - driver exit point
12596 *
12597 * This is the driver exit point (invoked when module is unloaded using rmmod)
12598 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012599 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012600 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012601enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012602{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012603 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012604}
12605
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012606void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012607{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012608 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012609}
12610
Komal Seelamc11bb222016-01-27 18:57:10 +053012611/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012612 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12613 * @hdd_ctx: HDD context
12614 *
12615 * Cleans up the pre cac interface, if it exists
12616 *
12617 * Return: None
12618 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012619void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012620{
12621 uint8_t session_id;
12622 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012623 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012624
12625 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12626 if (QDF_IS_STATUS_ERROR(status)) {
12627 hdd_err("failed to get pre cac vdev id");
12628 return;
12629 }
12630
12631 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12632 if (!precac_adapter) {
12633 hdd_err("invalid pre cac adapater");
12634 return;
12635 }
12636
12637 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12638 wlan_hdd_sap_pre_cac_failure,
12639 (void *)precac_adapter);
12640 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12641
12642}
12643
12644/**
Komal Seelamec702b02016-02-24 18:42:16 +053012645 * hdd_update_ol_config - API to update ol configuration parameters
12646 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012647 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012648 * Return: void
12649 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012650static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012651{
Komal Seelamec702b02016-02-24 18:42:16 +053012652 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012653 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012654
Komal Seelamec702b02016-02-24 18:42:16 +053012655 if (!ol_ctx)
12656 return;
12657
12658 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12659 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12660 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12661 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012662 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012663
12664 ol_init_ini_config(ol_ctx, &cfg);
12665}
12666
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012667#ifdef FEATURE_RUNTIME_PM
12668/**
12669 * hdd_populate_runtime_cfg() - populate runtime configuration
12670 * @hdd_ctx: hdd context
12671 * @cfg: pointer to the configuration memory being populated
12672 *
12673 * Return: void
12674 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012675static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012676 struct hif_config_info *cfg)
12677{
12678 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12679 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12680}
12681#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012682static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012683 struct hif_config_info *cfg)
12684{
12685}
12686#endif
12687
Komal Seelamec702b02016-02-24 18:42:16 +053012688/**
12689 * hdd_update_hif_config - API to update HIF configuration parameters
12690 * @hdd_ctx: HDD Context
12691 *
12692 * Return: void
12693 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012694static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012695{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012696 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012697 struct hif_config_info cfg;
12698
12699 if (!scn)
12700 return;
12701
12702 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012703 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012704 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012705
12706 if (hdd_ctx->config->prevent_link_down)
12707 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012708}
12709
12710/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012711 * hdd_update_dp_config() - Propagate config parameters to Lithium
12712 * datapath
12713 * @hdd_ctx: HDD Context
12714 *
12715 * Return: 0 for success/errno for failure
12716 */
12717static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12718{
12719 struct cdp_config_params params;
12720 QDF_STATUS status;
12721
12722 params.tso_enable = hdd_ctx->config->tso_enable;
12723 params.lro_enable = hdd_ctx->config->lro_enable;
12724#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12725 params.tx_flow_stop_queue_threshold =
12726 hdd_ctx->config->TxFlowStopQueueThreshold;
12727 params.tx_flow_start_queue_offset =
12728 hdd_ctx->config->TxFlowStartQueueOffset;
12729#endif
12730 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12731 params.napi_enable = hdd_ctx->napi_enable;
12732 params.tcp_udp_checksumoffload =
12733 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12734
12735 status = cdp_update_config_parameters(
12736 cds_get_context(QDF_MODULE_ID_SOC),
12737 &params);
12738 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012739 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012740 return status;
12741 }
12742
12743 return 0;
12744}
12745
12746/**
Komal Seelamec702b02016-02-24 18:42:16 +053012747 * hdd_update_config() - Initialize driver per module ini parameters
12748 * @hdd_ctx: HDD Context
12749 *
12750 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012751 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012752 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012753int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012754{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012755 int ret;
12756
Komal Seelamec702b02016-02-24 18:42:16 +053012757 hdd_update_ol_config(hdd_ctx);
12758 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012759 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12760 ret = hdd_update_cds_config_ftm(hdd_ctx);
12761 else
12762 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012763 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012764
12765 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012766}
12767
Mukul Sharma9d797a02017-01-05 20:26:03 +053012768#ifdef FEATURE_WLAN_RA_FILTERING
12769/**
12770 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12771 * @psoc_cfg: pmo psoc Configuration
12772 * @hdd_ctx: Pointer to hdd context
12773 *
12774 * Return: none
12775 */
12776static inline void hdd_ra_populate_pmo_config(
12777 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012778 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012779{
12780 psoc_cfg->ra_ratelimit_interval =
12781 hdd_ctx->config->RArateLimitInterval;
12782 psoc_cfg->ra_ratelimit_enable =
12783 hdd_ctx->config->IsRArateLimitEnabled;
12784}
12785#else
12786static inline void hdd_ra_populate_pmo_config(
12787 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012788 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012789{
12790}
12791#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012792
Mukul Sharma9d797a02017-01-05 20:26:03 +053012793/**
12794 * hdd_update_pmo_config - API to update pmo configuration parameters
12795 * @hdd_ctx: HDD context
12796 *
12797 * Return: void
12798 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012799static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012800{
Mukul Sharma9d797a02017-01-05 20:26:03 +053012801 struct pmo_psoc_cfg psoc_cfg;
12802 QDF_STATUS status;
12803
12804 /*
12805 * Value of hdd_ctx->wowEnable can be,
12806 * 0 - Disable both magic pattern match and pattern byte match.
12807 * 1 - Enable magic pattern match on all interfaces.
12808 * 2 - Enable pattern byte match on all interfaces.
12809 * 3 - Enable both magic patter and pattern byte match on
12810 * all interfaces.
12811 */
12812 psoc_cfg.magic_ptrn_enable =
12813 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12814 psoc_cfg.ptrn_match_enable_all_vdev =
12815 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080012816 psoc_cfg.ptrn_id_per_vdev =
12817 wma_is_service_enabled(wmi_service_unified_wow_capability);
12818 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012819 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012820 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080012821 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012822 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080012823 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012824 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12825 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080012826 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012827 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012828 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053012829 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12830 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12831 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080012832 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012833 psoc_cfg.auto_power_save_fail_mode =
12834 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012835
12836 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012837 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12838 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012839
Dustin Brownb9987af2018-03-01 17:15:11 -080012840 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
12841 if (QDF_IS_STATUS_ERROR(status))
12842 hdd_err("failed pmo psoc configuration; status:%d", status);
12843
12844 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012845}
12846
Abhishek Singhb20db962017-03-03 21:28:46 +053012847#ifdef FEATURE_WLAN_SCAN_PNO
12848static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12849 struct hdd_config *cfg)
12850{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012851 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12852
Abhishek Singhb20db962017-03-03 21:28:46 +053012853 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12854 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12855 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12856 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12857 pno_cfg->channel_prediction_full_scan =
12858 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012859 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12860 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12861 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12862 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012863}
12864#else
12865static inline void
12866hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012867 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012868{
Abhishek Singhb20db962017-03-03 21:28:46 +053012869}
12870#endif
12871
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012872void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12873 struct hdd_config *cfg)
12874{
12875 uint8_t i = 0;
12876
12877 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12878 if (!ie_whitelist->white_list)
12879 return;
12880
12881 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12882 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12883 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12884 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12885 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12886 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12887 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12888 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12889
12890 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12891 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12892 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12893}
12894
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012895uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12896{
12897 uint8_t i, score;
12898
12899 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12900 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12901 if (score > MAX_INDEX_SCORE)
12902 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12903 MAX_INDEX_SCORE, i);
12904 }
12905
12906 return per_index_score;
12907}
12908
12909/**
12910 * hdd_update_score_config - API to update candidate scoring related params
12911 * configuration parameters
12912 * @score_config: score config to update
12913 * @cfg: config params
12914 *
12915 * Return: 0 if success else err
12916 */
12917static void hdd_update_score_config(
12918 struct scoring_config *score_config, struct hdd_config *cfg)
12919{
12920 int total_weight;
12921
12922 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12923 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12924 score_config->weight_cfg.vht_caps_weightage =
12925 cfg->vht_caps_weightage;
12926 score_config->weight_cfg.he_caps_weightage =
12927 cfg->he_caps_weightage;
12928 score_config->weight_cfg.chan_width_weightage =
12929 cfg->chan_width_weightage;
12930 score_config->weight_cfg.chan_band_weightage =
12931 cfg->chan_band_weightage;
12932 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12933 score_config->weight_cfg.beamforming_cap_weightage =
12934 cfg->beamforming_cap_weightage;
12935 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12936 score_config->weight_cfg.channel_congestion_weightage =
12937 cfg->channel_congestion_weightage;
12938 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12939
12940 total_weight = score_config->weight_cfg.rssi_weightage +
12941 score_config->weight_cfg.ht_caps_weightage +
12942 score_config->weight_cfg.vht_caps_weightage +
12943 score_config->weight_cfg.he_caps_weightage +
12944 score_config->weight_cfg.chan_width_weightage +
12945 score_config->weight_cfg.chan_band_weightage +
12946 score_config->weight_cfg.nss_weightage +
12947 score_config->weight_cfg.beamforming_cap_weightage +
12948 score_config->weight_cfg.pcl_weightage +
12949 score_config->weight_cfg.channel_congestion_weightage +
12950 score_config->weight_cfg.oce_wan_weightage;
12951
12952 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12953 hdd_err("total weight is greater than %d fallback to default values",
12954 BEST_CANDIDATE_MAX_WEIGHT);
12955
12956 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12957 score_config->weight_cfg.ht_caps_weightage =
12958 HT_CAPABILITY_WEIGHTAGE;
12959 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12960 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12961 score_config->weight_cfg.chan_width_weightage =
12962 CHAN_WIDTH_WEIGHTAGE;
12963 score_config->weight_cfg.chan_band_weightage =
12964 CHAN_BAND_WEIGHTAGE;
12965 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12966 score_config->weight_cfg.beamforming_cap_weightage =
12967 BEAMFORMING_CAP_WEIGHTAGE;
12968 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12969 score_config->weight_cfg.channel_congestion_weightage =
12970 CHANNEL_CONGESTION_WEIGHTAGE;
12971 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12972 }
12973
12974 score_config->bandwidth_weight_per_index =
12975 hdd_limit_max_per_index_score(
12976 cfg->bandwidth_weight_per_index);
12977 score_config->nss_weight_per_index =
12978 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12979 score_config->band_weight_per_index =
12980 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12981
12982 score_config->rssi_score.best_rssi_threshold =
12983 cfg->best_rssi_threshold;
12984 score_config->rssi_score.good_rssi_threshold =
12985 cfg->good_rssi_threshold;
12986 score_config->rssi_score.bad_rssi_threshold =
12987 cfg->bad_rssi_threshold;
12988 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12989 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12990 score_config->rssi_score.good_rssi_bucket_size =
12991 cfg->good_rssi_bucket_size;
12992 score_config->rssi_score.bad_rssi_bucket_size =
12993 cfg->bad_rssi_bucket_size;
12994 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12995 cfg->rssi_pref_5g_rssi_thresh;
12996
12997 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12998 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12999 hdd_limit_max_per_index_score(
13000 cfg->esp_qbss_score_slots3_to_0);
13001 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13002 hdd_limit_max_per_index_score(
13003 cfg->esp_qbss_score_slots7_to_4);
13004 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13005 hdd_limit_max_per_index_score(
13006 cfg->esp_qbss_score_slots11_to_8);
13007 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13008 hdd_limit_max_per_index_score(
13009 cfg->esp_qbss_score_slots15_to_12);
13010
13011 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13012 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13013 hdd_limit_max_per_index_score(
13014 cfg->oce_wan_score_slots3_to_0);
13015 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13016 hdd_limit_max_per_index_score(
13017 cfg->oce_wan_score_slots7_to_4);
13018 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13019 hdd_limit_max_per_index_score(
13020 cfg->oce_wan_score_slots11_to_8);
13021 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13022 hdd_limit_max_per_index_score(
13023 cfg->oce_wan_score_slots15_to_12);
13024
13025
13026 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13027 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13028 score_config->nss = cfg->enable2x2 ? 2 : 1;
13029
13030 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13031 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13032 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13033 score_config->he_cap = 1;
13034
13035 if (score_config->he_cap ||
13036 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13037 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13038 score_config->vht_cap = 1;
13039
13040 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13041 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13042 score_config->ht_cap = 1;
13043
13044 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13045 score_config->vht_24G_cap = 1;
13046
13047 if (cfg->enableTxBF)
13048 score_config->beamformee_cap = 1;
13049
13050}
13051
Abhishek Singh257a9482017-03-06 16:52:39 +053013052/**
bings81fe50a2017-11-27 14:33:26 +080013053 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13054 * @hdd_ctx: HDD context
13055 *
13056 * Return: 0 if success else err
13057 */
13058static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13059{
13060 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13061 struct hdd_config *cfg = hdd_ctx->config;
13062 struct dfs_user_config dfs_cfg;
13063 QDF_STATUS status;
13064
13065 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13066 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13067 if (QDF_IS_STATUS_ERROR(status)) {
13068 hdd_err("failed dfs psoc configuration");
13069 return -EINVAL;
13070 }
13071
13072 return 0;
13073}
13074
13075/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013076 * hdd_update_scan_config - API to update scan configuration parameters
13077 * @hdd_ctx: HDD context
13078 *
13079 * Return: 0 if success else err
13080 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013081static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013082{
13083 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13084 struct scan_user_cfg scan_cfg;
13085 struct hdd_config *cfg = hdd_ctx->config;
13086 QDF_STATUS status;
13087
13088 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13089 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13090 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13091 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13092 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13093 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13094 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013095 /* convert to ms */
13096 scan_cfg.scan_cache_aging_time =
13097 cfg->scanAgingTimeout * 1000;
13098 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13099 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13100 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13101 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013102 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013103 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013104 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13105 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013106 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013107 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013108 scan_cfg.sta_miracast_mcc_rest_time =
13109 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013110
Abhishek Singhb20db962017-03-03 21:28:46 +053013111 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013112 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013113 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013114
Abhishek Singh257a9482017-03-06 16:52:39 +053013115 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13116 if (status != QDF_STATUS_SUCCESS) {
13117 hdd_err("failed pmo psoc configuration");
13118 return -EINVAL;
13119 }
13120
13121 return 0;
13122}
Abhishek Singh257a9482017-03-06 16:52:39 +053013123
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013124int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013125{
13126 int ret;
13127
13128 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013129 if (ret)
13130 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013131
Abhishek Singh257a9482017-03-06 16:52:39 +053013132 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013133 if (ret)
13134 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013135
Frank Liud4b2fa02017-03-29 11:46:48 +080013136 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013137 if (ret)
13138 return ret;
13139
13140 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013141 if (ret)
13142 return ret;
13143
13144 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013145
13146 return ret;
13147}
13148
Agrawal Ashish65634612016-08-18 13:24:32 +053013149/**
13150 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13151 * @mode : cfg80211 DFS mode
13152 *
13153 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13154 */
13155enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13156{
13157 switch (mode) {
13158 case DFS_MODE_ENABLE:
13159 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013160 case DFS_MODE_DISABLE:
13161 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013162 case DFS_MODE_DEPRIORITIZE:
13163 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013164 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013165 hdd_debug("ACS dfs mode is NONE");
13166 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013167 }
13168}
13169
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013170/**
13171 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13172 * @hddctx: pointer to hdd context
13173 * @set_value: enable/disable
13174 *
13175 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13176 * Host(even though it is duplicate). When Host send vendor command
13177 * disable,FW doesn't perform any action. Whenever any change in
13178 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13179 *
13180 * return - 0 on success, appropriate error values on failure.
13181 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013182int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013183{
13184 QDF_STATUS status;
13185
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013186 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013187 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013188
13189 if (!hddctx->config->goptimize_chan_avoid_event) {
13190 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13191 return -EINVAL;
13192 }
13193
13194 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13195 if (!QDF_IS_STATUS_SUCCESS(status)) {
13196 hdd_err("Failed to send chan avoid command to SME");
13197 return -EINVAL;
13198 }
13199 return 0;
13200}
Agrawal Ashish65634612016-08-18 13:24:32 +053013201
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013202/**
13203 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13204 * @value: value to set
13205 *
13206 * This function will set the passed value to roaming in progress flag.
13207 *
13208 * Return: None
13209 */
13210void hdd_set_roaming_in_progress(bool value)
13211{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013212 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013213
13214 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13215 if (!hdd_ctx) {
13216 hdd_err("HDD context is NULL");
13217 return;
13218 }
13219
13220 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013221 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013222}
13223
13224/**
13225 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013226 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013227 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013228 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013229 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013230bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013231{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013232 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013233 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013234
13235 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13236 if (!hdd_ctx) {
13237 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013238 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013239 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013240 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13241 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013242 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13243 hdd_ctx->roaming_in_progress);
13244
13245 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013246}
13247
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013248/**
13249 * hdd_is_connection_in_progress() - check if connection is in
13250 * progress
13251 * @session_id: session id
13252 * @reason: scan reject reason
13253 *
13254 * Go through each adapter and check if Connection is in progress
13255 *
13256 * Return: true if connection is in progress else false
13257 */
13258bool hdd_is_connection_in_progress(uint8_t *session_id,
13259 enum scan_reject_states *reason)
13260{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013261 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013262 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013263 uint8_t sta_id = 0;
13264 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013265 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013266
13267 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13268 if (!hdd_ctx) {
13269 hdd_err("HDD context is NULL");
13270 return false;
13271 }
13272
Dustin Brown920397d2017-12-13 16:27:50 -080013273 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013274 hdd_info("Adapter with device mode %s(%d) exists",
13275 hdd_device_mode_to_string(adapter->device_mode),
13276 adapter->device_mode);
13277 if (((QDF_STA_MODE == adapter->device_mode)
13278 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13279 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13280 && (eConnectionState_Connecting ==
13281 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13282 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013283 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013284 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013285 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013286 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013287 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013288 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013289 }
13290 return true;
13291 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013292 /*
13293 * sme_neighbor_middle_of_roaming is for LFR2
13294 * hdd_is_roaming_in_progress is for LFR3
13295 */
13296 if (((QDF_STA_MODE == adapter->device_mode) &&
13297 sme_neighbor_middle_of_roaming(
13298 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013299 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013300 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013301 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013302 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013303 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013304 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013305 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013306 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013307 }
13308 return true;
13309 }
13310 if ((QDF_STA_MODE == adapter->device_mode) ||
13311 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13312 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13313 hdd_sta_ctx =
13314 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13315 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013316 hdd_sta_ctx->conn_info.connState)
13317 && sme_is_sta_key_exchange_in_progress(
13318 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013319 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013320 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013321 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013322 " is in middle of WPS/EAPOL exchange.",
13323 MAC_ADDR_ARRAY(sta_mac));
13324 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013325 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013326 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013327 }
13328 return true;
13329 }
13330 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13331 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13332 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13333 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013334 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013335 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013336 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013337 continue;
13338
13339 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013340 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013341 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013342 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013343 " of SAP/GO is in middle of WPS/EAPOL exchange",
13344 MAC_ADDR_ARRAY(sta_mac));
13345 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013346 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013347 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013348 }
13349 return true;
13350 }
13351 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013352 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013353 return true;
13354 }
13355 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013356 }
Dustin Brown920397d2017-12-13 16:27:50 -080013357
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013358 return false;
13359}
13360
13361/**
13362 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013363 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013364 *
13365 * Return: None
13366 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013367void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013368{
Jeff Johnson87251032017-08-29 13:31:11 -070013369 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013370 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013371 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013372 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013373 tsap_Config_t *sap_config;
13374 void *sap_ctx;
13375
13376 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013377 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013378 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013379
13380 mutex_lock(&hdd_ctx->sap_lock);
13381 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13382 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013383 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13384 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13385 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13386 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013387 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013388 qdf_stop_bss_event,
13389 SME_CMD_TIMEOUT_VALUE);
13390
13391 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013392 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013393 goto end;
13394 }
13395 }
13396 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013397 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013398 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013399 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013400 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013401 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013402
13403 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013404 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013405 wlansap_reset_sap_config_add_ie(sap_config,
13406 eUPDATE_IE_ALL);
13407 goto end;
13408 }
13409
13410 qdf_event_reset(&hostapd_state->qdf_event);
13411 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13412 sap_config,
13413 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013414 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013415 wlansap_reset_sap_config_add_ie(sap_config,
13416 eUPDATE_IE_ALL);
13417 goto end;
13418 }
13419
Jeff Johnson6867ec32017-09-29 20:30:20 -070013420 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013421 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013422 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013423 SME_CMD_TIMEOUT_VALUE);
13424 wlansap_reset_sap_config_add_ie(sap_config,
13425 eUPDATE_IE_ALL);
13426 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013427 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013428 goto end;
13429 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013430 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013431 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013432 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013433 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13434 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013435 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013436 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013437 ap_adapter->device_mode,
13438 true);
13439 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013440 }
13441end:
13442 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013443}
13444
13445/**
13446 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13447 * with non dfs acs
13448 *
13449 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13450 *
13451 * Return: None
13452 */
13453void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13454{
Jeff Johnson9d295242017-08-29 14:39:48 -070013455 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013456 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013457 cds_context_type *cds_ctx;
13458
13459 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13460 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013461 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013462 return;
13463 }
13464
13465 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13466 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013467 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013468 return;
13469 }
13470
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013471 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13472 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013473 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013474 return;
13475 }
13476
13477 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013478 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13479 &ap_adapter->event_flags) &&
13480 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013481 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013482
Jeff Johnson6867ec32017-09-29 20:30:20 -070013483 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013484 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013485 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013486 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013487 acs_cfg.acs_mode = true;
13488
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013489 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013490 }
13491}
13492
13493/**
13494 * hdd_set_connection_in_progress() - to set the connection in
13495 * progress flag
13496 * @value: value to set
13497 *
13498 * This function will set the passed value to connection in progress flag.
13499 * If value is previously being set to true then no need to set it again.
13500 *
13501 * Return: true if value is being set correctly and false otherwise.
13502 */
13503bool hdd_set_connection_in_progress(bool value)
13504{
13505 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013506 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013507
13508 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13509 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013510 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013511 return false;
13512 }
13513
13514 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13515 /*
13516 * if the value is set to true previously and if someone is
13517 * trying to make it true again then it could be some race
13518 * condition being triggered. Avoid this situation by returning
13519 * false
13520 */
13521 if (hdd_ctx->connection_in_progress && value)
13522 status = false;
13523 else
13524 hdd_ctx->connection_in_progress = value;
13525 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13526 return status;
13527}
13528
Jeff Johnson9d295242017-08-29 14:39:48 -070013529int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013530{
13531 if (!adapter) {
13532 hdd_err("Invalid adapter");
13533 return -EINVAL;
13534 }
13535 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013536 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013537 WMA_VDEV_MCC_SET_TIME_QUOTA,
13538 set_value, VDEV_CMD);
13539 return 0;
13540
13541}
13542
Jeff Johnson9d295242017-08-29 14:39:48 -070013543int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013544{
13545 if (!adapter) {
13546 hdd_err("Invalid adapter");
13547 return -EINVAL;
13548 }
13549
13550 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013551 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013552 WMA_VDEV_MCC_SET_TIME_LATENCY,
13553 set_value, VDEV_CMD);
13554 return 0;
13555}
13556
Jeff Johnson9d295242017-08-29 14:39:48 -070013557struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013558 *psoc, uint8_t vdev_id)
13559{
Jeff Johnson9d295242017-08-29 14:39:48 -070013560 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013561 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013562
13563 /*
13564 * Currently PSOC is not being used. But this logic will
13565 * change once we have the converged implementation of
13566 * HDD context per PSOC in place. This would break if
13567 * multiple vdev objects reuse the vdev id.
13568 */
13569 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13570 if (!adapter)
13571 hdd_err("Get adapter by vdev id failed");
13572
13573 return adapter;
13574}
13575
Jeff Johnson9d295242017-08-29 14:39:48 -070013576int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013577 int8_t *rssi, int8_t *snr)
13578{
13579 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013580 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013581
Jeff Johnson025618c2018-03-18 14:41:00 -070013582 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013583 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013584 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013585 if (QDF_STATUS_SUCCESS != status) {
13586 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13587 return -EINVAL;
13588 }
13589
13590 return 0;
13591}
13592
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013593/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013594 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13595 * @adapter - HDD adapter
13596 * @tos - type of service
13597 * @status - status of the traffic
13598 *
13599 * Return: 0 on success and non zero value on failure
13600 */
13601
13602int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13603 bool is_tos_active)
13604{
13605 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013606 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013607 uint32_t max_off_chan_time = 0;
13608 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013609 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013610 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013611
13612 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13613 ret = wlan_hdd_validate_context(hdd_ctx);
13614
13615 if (ret < 0) {
13616 hdd_err("failed to set limit off chan params");
13617 return ret;
13618 }
13619
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013620 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13621
13622 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013623 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013624 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013625 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013626
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013627 if (adapter->active_ac) {
13628 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013629 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013630 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13631 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13632 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013633 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013634 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013635 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13636 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13637 PM_LATENCY);
13638 } else {
13639 /*ignore this command if only BE/BK is active */
13640 is_tos_active = false;
13641 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13642 hdd_ctx->config->conc_system_pref);
13643 }
13644 } else {
13645 /* No active tos */
13646 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13647 hdd_ctx->config->conc_system_pref);
13648 }
13649
Jeff Johnson1b780e42017-10-31 14:11:45 -070013650 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013651 is_tos_active, max_off_chan_time,
13652 hdd_ctx->config->nRestTimeConc, true);
13653 if (!QDF_IS_STATUS_SUCCESS(status)) {
13654 hdd_err("failed to set limit off chan params");
13655 ret = -EINVAL;
13656 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013657
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013658 return ret;
13659}
13660
13661/**
13662 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13663 * @adapter - HDD adapter
13664 *
13665 * Return: 0 on success and non zero value on failure
13666 */
13667int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13668{
13669 struct hdd_context *hdd_ctx;
13670 int ret;
13671 QDF_STATUS status;
13672 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13673
13674 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13675 ret = wlan_hdd_validate_context(hdd_ctx);
13676 if (ret < 0)
13677 return ret;
13678
13679 /* set the system preferece to default */
13680 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13681 hdd_ctx->config->conc_system_pref);
13682
13683 /* clear the bitmap */
13684 adapter->active_ac = 0;
13685
13686 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013687 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013688
Jeff Johnson1b780e42017-10-31 14:11:45 -070013689 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013690 false, 0, 0, false);
13691 if (!QDF_IS_STATUS_SUCCESS(status)) {
13692 hdd_err("failed to reset limit off chan params");
13693 ret = -EINVAL;
13694 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013695
13696 return ret;
13697}
13698
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013699/**
13700 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13701 * @drv_op: Enum indicating driver op
13702 *
13703 * Return: none
13704 */
13705void hdd_start_driver_ops_timer(int drv_op)
13706{
13707 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13708 switch (drv_op) {
13709 case eHDD_DRV_OP_PROBE:
13710 memcpy(drv_ops_string, "probe", sizeof("probe"));
13711 break;
13712 case eHDD_DRV_OP_REMOVE:
13713 memcpy(drv_ops_string, "remove", sizeof("remove"));
13714 break;
13715 case eHDD_DRV_OP_SHUTDOWN:
13716 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13717 break;
13718 case eHDD_DRV_OP_REINIT:
13719 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13720 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013721 case eHDD_DRV_OP_IFF_UP:
13722 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13723 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013724 }
13725
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013726 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013727 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13728 HDD_OPS_INACTIVITY_TIMEOUT);
13729}
13730
13731/**
13732 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13733 *
13734 * Return: none
13735 */
13736void hdd_stop_driver_ops_timer(void)
13737{
13738 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13739}
13740
13741/**
13742 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13743 * inactivity timer
13744 *
13745 * Return: None
13746 */
13747void hdd_drv_ops_inactivity_handler(void)
13748{
13749 hdd_err("%s: %d Sec timer expired while in .%s",
13750 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13751
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013752 if (hdd_drv_ops_task) {
13753 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13754 qdf_print_thread_trace(hdd_drv_ops_task);
13755 } else {
13756 hdd_err("hdd_drv_ops_task is null");
13757 }
13758
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013759 /* Driver shutdown is stuck, no recovery possible at this point */
13760 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13761 sizeof("shutdown")))
13762 QDF_BUG(0);
13763
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013764 if (cds_is_fw_down()) {
13765 hdd_err("FW is down");
13766 return;
13767 }
13768
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013769 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013770 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013771 else
13772 QDF_BUG(0);
13773}
13774
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013775void hdd_pld_ipa_uc_shutdown_pipes(void)
13776{
13777 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13778
13779 if (!hdd_ctx)
13780 return;
13781
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053013782 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013783}
13784
Yun Parkff6a16a2017-09-26 16:38:18 -070013785/**
13786 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13787 * @struct hdd_context *hdd_ctx
13788 * @struct hdd_adapter *padapter
13789 * @bool enble
13790 *
13791 * Return: none
13792 */
13793void hdd_set_rx_mode_rps(bool enable)
13794{
13795 struct cds_config_info *cds_cfg = cds_get_ini_config();
13796 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13797 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13798
13799 if (adapter && hdd_ctx &&
13800 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13801 if (enable && !cds_cfg->rps_enabled)
13802 hdd_send_rps_ind(adapter);
13803 else if (!enable && cds_cfg->rps_enabled)
13804 hdd_send_rps_disable_ind(adapter);
13805 }
13806}
13807
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053013808bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
13809{
13810 struct hdd_adapter *adapter = NULL;
13811
13812 hdd_for_each_adapter(hdd_ctx, adapter) {
13813 if ((adapter->device_mode == QDF_STA_MODE ||
13814 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
13815 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
13816 &adapter->event_flags)){
13817 return true;
13818 }
13819 }
13820
13821 return false;
13822}
13823
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013824/* Register the module init/exit functions */
13825module_init(hdd_module_init);
13826module_exit(hdd_module_exit);
13827
13828MODULE_LICENSE("Dual BSD/GPL");
13829MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13830MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13831
Srinivas Girigowda841da292018-02-21 16:33:00 -080013832static const struct kernel_param_ops con_mode_ops = {
13833 .set = con_mode_handler,
13834 .get = param_get_int,
13835};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013836
Srinivas Girigowda841da292018-02-21 16:33:00 -080013837static const struct kernel_param_ops con_mode_ftm_ops = {
13838 .set = con_mode_handler_ftm,
13839 .get = param_get_int,
13840};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013841
Srinivas Girigowda841da292018-02-21 16:33:00 -080013842static const struct kernel_param_ops con_mode_monitor_ops = {
13843 .set = con_mode_handler_monitor,
13844 .get = param_get_int,
13845};
Ravi Joshia307f632017-07-17 23:41:41 -070013846
Srinivas Girigowda841da292018-02-21 16:33:00 -080013847static const struct kernel_param_ops fwpath_ops = {
13848 .set = fwpath_changed_handler,
13849 .get = param_get_string,
13850};
13851
13852module_param_cb(con_mode, &con_mode_ops, &con_mode,
13853 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13854
13855module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
13856 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13857
13858module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
13859 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13860
13861module_param_cb(fwpath, &fwpath_ops, &fwpath,
13862 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013863
13864module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13865
13866module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13867
13868module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);