blob: 15feba8f9cc20952c931bc3b3fbb8492188aa0da [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Dustin Browndb2a8be2017-12-20 11:49:56 -08002 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_main.c
30 *
31 * WLAN Host Device Driver implementation
32 *
33 */
34
35/* Include Files */
36#include <wlan_hdd_includes.h>
37#include <cds_api.h>
38#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053039#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <linux/etherdevice.h>
41#include <linux/firmware.h>
42#include <wlan_hdd_tx_rx.h>
43#include <wni_api.h>
44#include <wlan_hdd_cfg.h>
45#include <wlan_ptt_sock_svc.h>
46#include <dbglog_host.h>
47#include <wlan_logging_sock_svc.h>
48#include <wlan_hdd_wowl.h>
49#include <wlan_hdd_misc.h>
50#include <wlan_hdd_wext.h>
51#include "wlan_hdd_trace.h"
52#include "wlan_hdd_ioctl.h"
53#include "wlan_hdd_ftm.h"
54#include "wlan_hdd_power.h"
55#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070056#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080057#include "wlan_hdd_request_manager.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053058#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053059#include "qdf_trace.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080060#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080061#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080062#endif
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070063#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080064#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070065#include <cdp_txrx_stats.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066
67#include <net/addrconf.h>
68#include <linux/wireless.h>
69#include <net/cfg80211.h>
70#include <linux/inetdevice.h>
71#include <net/addrconf.h>
72#include "wlan_hdd_cfg80211.h"
73#include "wlan_hdd_ext_scan.h"
74#include "wlan_hdd_p2p.h"
75#include <linux/rtnetlink.h>
76#include "sap_api.h"
77#include <linux/semaphore.h>
78#include <linux/ctype.h>
79#include <linux/compat.h>
80#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#include <soc/qcom/subsystem_restart.h>
82#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083#include <wlan_hdd_hostapd.h>
84#include <wlan_hdd_softap_tx_rx.h>
85#include "cfg_api.h"
86#include "qwlan_version.h"
87#include "wma_types.h"
88#include "wlan_hdd_tdls.h"
89#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053090#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070092#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070093#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080094#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095#include "wlan_hdd_nan.h"
96#include "wlan_hdd_debugfs.h"
97#include "wlan_hdd_driver_ops.h"
98#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053099#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800100
101#include <wlan_hdd_ipa.h>
102#include "hif.h"
103#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800104#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700105#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530106#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700107#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700108#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530109#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700110#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530111#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800112#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800113#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530114#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800115#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800116#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530117#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530118#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800119#include "os_if_wifi_pos.h"
120#include "wifi_pos_api.h"
121#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800122#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700123#include "os_if_nan.h"
124#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700125#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800126#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700127#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530128#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530129#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700130#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800131#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530132#include "wlan_disa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530133#include <target_if.h>
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530134
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530135#ifdef CNSS_GENL
136#include <net/cnss_nl.h>
137#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800138#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800139#include "wlan_ocb_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530140
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530141#include <wlan_green_ap_ucfg_api.h>
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800142#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800143#ifdef MODULE
144#define WLAN_MODULE_NAME module_name(THIS_MODULE)
145#else
146#define WLAN_MODULE_NAME "wlan"
147#endif
148
149#ifdef TIMER_MANAGER
150#define TIMER_MANAGER_STR " +TIMER_MANAGER"
151#else
152#define TIMER_MANAGER_STR ""
153#endif
154
155#ifdef MEMORY_DEBUG
156#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
157#else
158#define MEMORY_DEBUG_STR ""
159#endif
160
Dustin Brownc1034df2018-02-07 14:51:32 -0800161#ifdef PANIC_ON_BUG
162#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
163#else
164#define PANIC_ON_BUG_STR ""
165#endif
166
Sachin Ahujadddd2632017-03-07 19:07:24 +0530167int wlan_start_ret_val;
168static DECLARE_COMPLETION(wlan_start_comp);
169static unsigned int dev_num = 1;
170static struct cdev wlan_hdd_state_cdev;
171static struct class *class;
172static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530173#ifndef MODULE
174static struct gwlan_loader *wlan_loader;
175static ssize_t wlan_boot_cb(struct kobject *kobj,
176 struct kobj_attribute *attr,
177 const char *buf, size_t count);
178struct gwlan_loader {
179 bool loaded_state;
180 struct kobject *boot_wlan_obj;
181 struct attribute_group *attr_group;
182};
183
184static struct kobj_attribute wlan_boot_attribute =
185 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
186
187static struct attribute *attrs[] = {
188 &wlan_boot_attribute.attr,
189 NULL,
190};
191
192#define MODULE_INITIALIZED 1
193#endif
194
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530195#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
196#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800197#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530198
199static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800200static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530201static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
202
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800203/* the Android framework expects this param even though we don't use it */
204#define BUF_LEN 20
205static char fwpath_buffer[BUF_LEN];
206static struct kparam_string fwpath = {
207 .string = fwpath_buffer,
208 .maxlen = BUF_LEN,
209};
210
211static char *country_code;
212static int enable_11d = -1;
213static int enable_dfs_chan_scan = -1;
214
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800215/*
216 * spinlock for synchronizing asynchronous request/response
217 * (full description of use in wlan_hdd_main.h)
218 */
219DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530220DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800221
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800222#define WLAN_NLINK_CESIUM 30
223
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530224static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800225
226#define WOW_MAX_FILTER_LISTS 1
227#define WOW_MAX_FILTERS_PER_LIST 4
228#define WOW_MIN_PATTERN_SIZE 6
229#define WOW_MAX_PATTERN_SIZE 64
230
231#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
232static const struct wiphy_wowlan_support wowlan_support_reg_init = {
233 .flags = WIPHY_WOWLAN_ANY |
234 WIPHY_WOWLAN_MAGIC_PKT |
235 WIPHY_WOWLAN_DISCONNECT |
236 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
237 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
238 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
239 WIPHY_WOWLAN_4WAY_HANDSHAKE |
240 WIPHY_WOWLAN_RFKILL_RELEASE,
241 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
242 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
243 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
244};
245#endif
246
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700247static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
248 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
260 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
261 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
262 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
263 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
264 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700282 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700283 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700284 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530285 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800286 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700287};
288
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530289int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
290 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
291 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
292 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
293 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
294};
295
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800296/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530297struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800298
299struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800300#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700301static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800302#endif
303
Sachin Ahujadddd2632017-03-07 19:07:24 +0530304void hdd_start_complete(int ret)
305{
306 wlan_start_ret_val = ret;
307
308 complete(&wlan_start_comp);
309}
310
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800311/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530312 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700313 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530314 *
315 * Return: none
316 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700317static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530318{
Jeff Johnson9d295242017-08-29 14:39:48 -0700319 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530320
Dustin Brown920397d2017-12-13 16:27:50 -0800321 hdd_for_each_adapter(hdd_ctx, adapter)
322 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530323}
324
325/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800326 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
327 * @vdev_id: vdev_id
328 * @action: action type
329 * @reason: reason type
330 *
331 * Return: none
332 */
333void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
334 enum netif_action_type action, enum netif_reason_type reason)
335{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700336 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700337 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800338
339 if (!hdd_ctx) {
340 hdd_err("hdd ctx is NULL");
341 return;
342 }
343 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
344
345 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800346}
347
348/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700349 * Store WLAN driver version and timestamp info in global variables such that
350 * crash debugger can extract them from driver debug symbol and crashdump for
351 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800352 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800353#ifdef BUILD_TAG
354uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
355#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800356uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700357#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800358
359/**
360 * hdd_device_mode_to_string() - return string conversion of device mode
361 * @device_mode: device mode
362 *
363 * This utility function helps log string conversion of device mode.
364 *
365 * Return: string conversion of device mode, if match found;
366 * "Unknown" otherwise.
367 */
368const char *hdd_device_mode_to_string(uint8_t device_mode)
369{
370 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800371 CASE_RETURN_STRING(QDF_STA_MODE);
372 CASE_RETURN_STRING(QDF_SAP_MODE);
373 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
374 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
375 CASE_RETURN_STRING(QDF_FTM_MODE);
376 CASE_RETURN_STRING(QDF_IBSS_MODE);
377 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
378 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700379 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800380 default:
381 return "Unknown";
382 }
383}
384
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530385/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500386 * hdd_get_valid_chan() - return current chan list from regulatory.
387 * @hdd_ctx: HDD context
388 * @chan_list: buf hold returned chan list
389 * @chan_num: input buf size and output returned chan num
390 *
391 * This function helps get current available chan list from regulatory
392 * module. It excludes the "disabled" and "invalid" channels.
393 *
394 * Return: 0 for success.
395 */
396static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
397 uint8_t *chan_list,
398 uint32_t *chan_num)
399{
400 int i = 0, j = 0;
401 struct regulatory_channel *cur_chan_list;
402 struct wlan_objmgr_pdev *pdev;
403
404 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
405 return -EINVAL;
406
407 pdev = hdd_ctx->hdd_pdev;
408 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
409 sizeof(struct regulatory_channel));
410 if (!cur_chan_list)
411 return -ENOMEM;
412
413 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
414 QDF_STATUS_SUCCESS) {
415 qdf_mem_free(cur_chan_list);
416 return -EINVAL;
417 }
418
419 for (i = 0; i < NUM_CHANNELS; i++) {
420 uint32_t ch = cur_chan_list[i].chan_num;
421 enum channel_state state = wlan_reg_get_channel_state(pdev,
422 ch);
423
424 if (state != CHANNEL_STATE_DISABLE &&
425 state != CHANNEL_STATE_INVALID &&
426 j < *chan_num) {
427 chan_list[j] = (uint8_t)ch;
428 j++;
429 }
430 }
431 *chan_num = j;
432 qdf_mem_free(cur_chan_list);
433 return 0;
434}
435
436/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530437 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
438 * @adapter: HDD adapter
439 * @chan_number: Channel number
440 * @chan_bw: Bandwidth
441 *
442 * Checks if the given bandwidth is valid for the given channel number.
443 *
444 * Return: 0 for success, non-zero for failure
445 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700446int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530447 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800448 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530449{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500450 uint8_t chan[NUM_CHANNELS];
451 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530452 bool found = false;
453 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500454 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530455
456 hal = WLAN_HDD_GET_HAL_CTX(adapter);
457 if (!hal) {
458 hdd_err("Invalid HAL context");
459 return -EINVAL;
460 }
461
Liangwei Dong17bf2662018-01-05 02:02:05 -0500462 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
463 &len);
464 if (ret) {
465 hdd_err("error %d in getting valid channel list", ret);
466 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530467 }
468
469 for (i = 0; i < len; i++) {
470 if (chan[i] == chan_number) {
471 found = true;
472 break;
473 }
474 }
475
476 if (found == false) {
477 hdd_err("Channel not in driver's valid channel list");
478 return -EOPNOTSUPP;
479 }
480
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700481 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
482 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530483 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
484 return -EINVAL;
485 }
486
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700487 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530488 if (chan_bw == CH_WIDTH_80MHZ) {
489 hdd_err("BW80 not possible in 2.4GHz band");
490 return -EINVAL;
491 }
492 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
493 (chan_bw != CH_WIDTH_MAX)) {
494 hdd_err("Only BW20 possible on channel 14");
495 return -EINVAL;
496 }
497 }
498
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700499 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530500 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
501 (chan_bw != CH_WIDTH_MAX)) {
502 hdd_err("Only BW20 possible on channel 165");
503 return -EINVAL;
504 }
505 }
506
507 return 0;
508}
509
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530510/**
511 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
512 *
513 * Block the unloading of the driver (or) interface up until the
514 * cds recovery is completed
515 *
516 * Return: true for recovery completion else false
517 */
518static bool hdd_wait_for_recovery_completion(void)
519{
520 int retry = 0;
521
522 /* Wait for recovery to complete */
523 while (cds_is_driver_recovering()) {
524 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
525 hdd_err("Recovery in progress; wait here!!!");
526 msleep(1000);
527 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
528 hdd_err("SSR never completed, error");
529 /*
530 * Trigger the bug_on in the internal builds, in the
531 * customer builds self-recovery will be enabled
532 * in those cases just return error.
533 */
534 if (cds_is_self_recovery_enabled())
535 return false;
536 QDF_BUG(0);
537 }
538 }
539
540 hdd_info("Recovery completed successfully!");
541 return true;
542}
543
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800544static int __hdd_netdev_notifier_call(struct notifier_block *nb,
545 unsigned long state, void *data)
546{
547#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
548 struct netdev_notifier_info *dev_notif_info = data;
549 struct net_device *dev = dev_notif_info->dev;
550#else
551 struct net_device *dev = data;
552#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700553 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700554 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800555
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800556 ENTER_DEV(dev);
557
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558 /* Make sure that this callback corresponds to our device. */
559 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
560 return NOTIFY_DONE;
561
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530562 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800563 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700564 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800565 return NOTIFY_DONE;
566 }
567
568 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700569 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800570 return NOTIFY_DONE;
571 }
572
573 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
574 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800575 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530576 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800577 return NOTIFY_DONE;
578 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800579
580 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
581 hdd_err("%s: Driver module is closed", __func__);
582 return NOTIFY_DONE;
583 }
584
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530585 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800586 return NOTIFY_DONE;
587
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800588 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800589 dev->name, state);
590
591 switch (state) {
592 case NETDEV_REGISTER:
593 break;
594
595 case NETDEV_UNREGISTER:
596 break;
597
598 case NETDEV_UP:
599 sme_ch_avoid_update_req(hdd_ctx->hHal);
600 break;
601
602 case NETDEV_DOWN:
603 break;
604
605 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700606 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800607 complete(&adapter->linkup_event_var);
608 break;
609
610 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700611 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
612 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530613 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700614 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800615 } else {
hqueaa33ee2017-05-04 17:56:35 +0800616 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800617 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800618 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530619 /*
620 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
621 * of return status of hdd_stop call, kernel resets the IFF_UP
622 * flag after which driver does not send the cfg80211_scan_done.
623 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
624 */
625 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626 break;
627
628 default:
629 break;
630 }
631
632 return NOTIFY_DONE;
633}
634
635/**
636 * hdd_netdev_notifier_call() - netdev notifier callback function
637 * @nb: pointer to notifier block
638 * @state: state
639 * @ndev: ndev pointer
640 *
641 * Return: 0 on success, error number otherwise.
642 */
643static int hdd_netdev_notifier_call(struct notifier_block *nb,
644 unsigned long state,
645 void *ndev)
646{
647 int ret;
648
649 cds_ssr_protect(__func__);
650 ret = __hdd_netdev_notifier_call(nb, state, ndev);
651 cds_ssr_unprotect(__func__);
652
653 return ret;
654}
655
656struct notifier_block hdd_netdev_notifier = {
657 .notifier_call = hdd_netdev_notifier_call,
658};
659
660/* variable to hold the insmod parameters */
661static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800662
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530663static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700664int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530665
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800666/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800667static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800668
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530669/**
670 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
671 * @ch_width: NL channel width
672 *
673 * Converts the NL channel width to the driver's internal representation
674 *
675 * Return: Converted channel width. In case of non matching NL channel width,
676 * CH_WIDTH_MAX will be returned.
677 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800678enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530679{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800680 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700681
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800682 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530683 switch (ch_width) {
684 case NL80211_CHAN_WIDTH_20_NOHT:
685 case NL80211_CHAN_WIDTH_20:
686 return CH_WIDTH_20MHZ;
687 case NL80211_CHAN_WIDTH_40:
688 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530689 case NL80211_CHAN_WIDTH_80:
690 return CH_WIDTH_80MHZ;
691 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800692 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
693 return CH_WIDTH_80P80MHZ;
694 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
695 return CH_WIDTH_160MHZ;
696 else
697 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530698 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800699 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
700 return CH_WIDTH_160MHZ;
701 else
702 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530703 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800704 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530705 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800706 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530707 default:
708 hdd_err("Invalid channel width %d, setting to default",
709 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800710 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530711 }
712}
713
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530714/* wlan_hdd_find_opclass() - Find operating class for a channel
715 * @hal: handler to HAL
716 * @channel: channel id
717 * @bw_offset: bandwidth offset
718 *
719 * Function invokes sme api to find the operating class
720 *
721 * Return: operating class
722 */
723uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
724 uint8_t bw_offset)
725{
726 uint8_t opclass = 0;
727
728 sme_get_opclass(hal, channel, bw_offset, &opclass);
729 return opclass;
730}
731
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800732/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530733 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530734 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735 * @bitmask: Bitmask of log levels to be enabled
736 *
737 * Called immediately after the cfg.ini is read in order to configure
738 * the desired trace levels.
739 *
740 * Return: None
741 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530742int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530744 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530745 int qdf_print_idx = -1;
746 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747 /*
748 * if the bitmask is the default value, then a bitmask was not
749 * specified in cfg.ini, so leave the logging level alone (it
750 * will remain at the "compiled in" default value)
751 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700752 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530753 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800754
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530755 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800756
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530757 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530758 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530759 QDF_TRACE_LEVEL_NONE, 0);
760
761 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530762 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800763 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530764 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 while (0 != bitmask) {
766 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530767 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530768 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530769 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530770 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800773 level++;
774 bitmask >>= 1;
775 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530776 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800777}
778
779/**
Chris Guo1751acf2017-07-03 14:09:01 +0800780 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
781 * @hdd_ctx: HDD context pointer
782 *
783 * Return: 0 if the context is valid. Error code otherwise
784 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700785int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800786{
787 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
788 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
789 return -ENODEV;
790 }
791
792 if (cds_is_driver_recovering()) {
793 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
794 (void *)_RET_IP_, cds_get_driver_state());
795 return -EAGAIN;
796 }
797
798 if (hdd_ctx->start_modules_in_progress ||
799 hdd_ctx->stop_modules_in_progress) {
800 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
801 (void *)_RET_IP_);
802 return -EAGAIN;
803 }
804
805 return 0;
806}
807
808
809/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810 * wlan_hdd_validate_context() - check the HDD context
811 * @hdd_ctx: HDD context pointer
812 *
813 * Return: 0 if the context is valid. Error code otherwise
814 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700815int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800816{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800817 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530818 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800819 return -ENODEV;
820 }
821
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800822 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800823 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530824 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800825 return -EAGAIN;
826 }
827
Yue Ma9f275d92017-09-14 16:58:41 -0700828 if (cds_is_load_or_unload_in_progress()) {
829 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
830 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700832 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530833
834 if (hdd_ctx->start_modules_in_progress ||
835 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800836 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530837 (void *)_RET_IP_);
838 return -EAGAIN;
839 }
840
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530841 if (cds_is_driver_in_bad_state()) {
842 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
843 (void *)_RET_IP_, cds_get_driver_state());
844 return -ENODEV;
845 }
846
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 return 0;
848}
849
Jeff Johnson9d295242017-08-29 14:39:48 -0700850int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700851{
852 if (!adapter) {
853 hdd_err("adapter is null");
854 return -EINVAL;
855 }
856
857 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
858 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
859 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
860 return -EINVAL;
861 }
862
863 if (!adapter->dev) {
864 hdd_err("adapter net_device is null");
865 return -EINVAL;
866 }
867
868 if (!(adapter->dev->flags & IFF_UP)) {
869 hdd_info("adapter net_device is not up");
870 return -EAGAIN;
871 }
872
Jeff Johnson1b780e42017-10-31 14:11:45 -0700873 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700874 hdd_info("adapter session is not open");
875 return -EAGAIN;
876 }
877
Jeff Johnson1b780e42017-10-31 14:11:45 -0700878 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
879 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700880 return -EINVAL;
881 }
882
883 return 0;
884}
885
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530887 * wlan_hdd_validate_modules_state() - Check modules status
888 * @hdd_ctx: HDD context pointer
889 *
890 * Check's the driver module's state and returns true if the
891 * modules are enabled returns false if modules are closed.
892 *
893 * Return: True if modules are enabled or false.
894 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700895bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530896{
897 mutex_lock(&hdd_ctx->iface_change_lock);
898 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
899 mutex_unlock(&hdd_ctx->iface_change_lock);
900 hdd_notice("Modules not enabled, Present status: %d",
901 hdd_ctx->driver_status);
902 return false;
903 }
904 mutex_unlock(&hdd_ctx->iface_change_lock);
905 return true;
906}
907
908/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800909 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700910 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 *
912 * This function sets the IBSS power save config parameters to WMA
913 * which will send it to firmware if FW supports IBSS power save
914 * before vdev start.
915 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530916 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 * on failure.
918 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700919QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920{
921 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700922 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923
924 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700925 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530926 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927 }
928
Jeff Johnson1b780e42017-10-31 14:11:45 -0700929 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800930 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
931 hdd_ctx->config->ibssATIMWinSize,
932 VDEV_CMD);
933 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700934 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530935 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800936 }
937
Jeff Johnson1b780e42017-10-31 14:11:45 -0700938 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800939 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
940 hdd_ctx->config->isIbssPowerSaveAllowed,
941 VDEV_CMD);
942 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700943 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
944 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530945 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800946 }
947
Jeff Johnson1b780e42017-10-31 14:11:45 -0700948 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
950 hdd_ctx->config->
951 isIbssPowerCollapseAllowed, VDEV_CMD);
952 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700953 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
954 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530955 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 }
957
Jeff Johnson1b780e42017-10-31 14:11:45 -0700958 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
960 hdd_ctx->config->isIbssAwakeOnTxRx,
961 VDEV_CMD);
962 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700963 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530964 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800965 }
966
Jeff Johnson1b780e42017-10-31 14:11:45 -0700967 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
969 hdd_ctx->config->ibssInactivityCount,
970 VDEV_CMD);
971 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700972 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530973 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974 }
975
Jeff Johnson1b780e42017-10-31 14:11:45 -0700976 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
978 hdd_ctx->config->ibssTxSpEndInactivityTime,
979 VDEV_CMD);
980 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700981 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
982 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530983 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 }
985
Jeff Johnson1b780e42017-10-31 14:11:45 -0700986 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
988 hdd_ctx->config->ibssPsWarmupTime,
989 VDEV_CMD);
990 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700991 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
992 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530993 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994 }
995
Jeff Johnson1b780e42017-10-31 14:11:45 -0700996 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
998 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
999 VDEV_CMD);
1000 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001001 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1002 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301003 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001004 }
1005
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301006 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001007}
1008
Yue Macd359b72017-10-03 15:21:00 -07001009#ifdef FEATURE_RUNTIME_PM
1010/**
1011 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1012 * @hdd_ctx: HDD context
1013 *
1014 * Return: None
1015 */
1016static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1017{
1018 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1019
Yue Macd359b72017-10-03 15:21:00 -07001020 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001021 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001022
1023 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1024}
1025
1026/**
1027 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1028 * @hdd_ctx: HDD Context
1029 *
1030 * Return: None
1031 */
1032static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1033{
1034 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1035
Yue Macd359b72017-10-03 15:21:00 -07001036 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001037 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001038
1039 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1040}
1041
Yue Macd359b72017-10-03 15:21:00 -07001042#else /* FEATURE_RUNTIME_PM */
1043static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1044static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001045#endif /* FEATURE_RUNTIME_PM */
1046
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047#define INTF_MACADDR_MASK 0x7
1048
1049/**
1050 * hdd_update_macaddr() - update mac address
1051 * @config: hdd configuration
1052 * @hw_macaddr: mac address
1053 *
1054 * Mac address for multiple virtual interface is found as following
1055 * i) The mac address of the first interface is just the actual hw mac address.
1056 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1057 * define the mac address for the remaining interfaces and locally
1058 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1059 * supported virtual interfaces, right now this is 0x07 (meaning 8
1060 * interface).
1061 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1062 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1063 *
1064 * Return: None
1065 */
1066void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301067 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068{
1069 int8_t i;
1070 uint8_t macaddr_b3, tmp_br3;
1071
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301072 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301073 QDF_MAC_ADDR_SIZE);
1074 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301075 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301076 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001077 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1078 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1079 INTF_MACADDR_MASK;
1080 macaddr_b3 += tmp_br3;
1081
1082 /* XOR-ing bit-24 of the mac address. This will give enough
1083 * mac address range before collision
1084 */
1085 macaddr_b3 ^= (1 << 7);
1086
1087 /* Set locally administered bit */
1088 config->intfMacAddr[i].bytes[0] |= 0x02;
1089 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001090 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091 MAC_ADDRESS_STR, i,
1092 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1093 }
1094}
1095
Kabilan Kannan44a58372017-12-06 18:16:11 -08001096static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1097{
1098 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1099 struct tdls_start_params tdls_cfg;
1100 struct tdls_user_config *config = &tdls_cfg.config;
1101 struct hdd_config *cfg = hdd_ctx->config;
1102 QDF_STATUS status;
1103
1104 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1105 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1106 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1107 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1108 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1109 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1110 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1111 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1112 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1113 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1114 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1115 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1116 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1117 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1118 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1119 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1120 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1121 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1122 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1123 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1124 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1125 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1126 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1127 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1128 (cfg->fEnableTDLSImplicitTrigger ?
1129 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1130 (cfg->fTDLSExternalControl ?
1131 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1132 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1133 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1134
1135 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1136 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1137 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1138 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1139 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1140 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1141 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1142 tdls_cfg.tdls_evt_cb_data = psoc;
1143 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
1144 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
1145 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
1146 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1147 tdls_cfg.tdls_wmm_cb_data = psoc;
1148 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1149 tdls_cfg.tdls_rx_cb_data = psoc;
1150 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1151
1152 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1153 if (status != QDF_STATUS_SUCCESS) {
1154 hdd_err("failed pmo psoc configuration");
1155 return -EINVAL;
1156 }
1157
1158 hdd_ctx->tdls_umac_comp_active = true;
1159 /* enable napier specific tdls data path */
1160 hdd_ctx->tdls_nap_active = true;
1161
1162 return 0;
1163}
1164
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001165static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001166 struct wma_tgt_services *cfg)
1167{
1168 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001169
1170 /* Set up UAPSD */
1171 config->apUapsdEnabled &= cfg->uapsd;
1172
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001173 /* 11AX mode support */
1174 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1175 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1176 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1177
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 /* 11AC mode support */
1179 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1180 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1181 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001182
1183 /* ARP offload: override user setting if invalid */
1184 config->fhostArpOffload &= cfg->arp_offload;
1185
1186#ifdef FEATURE_WLAN_SCAN_PNO
1187 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001188 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001189 if (cfg->pno_offload)
1190 config->PnoOffload = true;
1191#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192#ifdef FEATURE_WLAN_TDLS
1193 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301194 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1195 cfg->en_tdls_offchan;
1196 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1197 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001198 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001200 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001201 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001203#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1204 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1205#endif
Will Huang496b36c2017-07-11 16:38:50 +08001206 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001207 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001208 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001209 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001210
1211}
1212
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001213/**
1214 * hdd_update_vdev_nss() - sets the vdev nss
1215 * @hdd_ctx: HDD context
1216 *
1217 * Sets the Nss per vdev type based on INI
1218 *
1219 * Return: None
1220 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001221static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001222{
1223 struct hdd_config *cfg_ini = hdd_ctx->config;
1224 uint8_t max_supp_nss = 1;
1225
Naveen Rawat10b1c152017-01-18 11:16:06 -08001226 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001227 max_supp_nss = 2;
1228
1229 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001230 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001231
1232 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001233 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001234}
1235
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301236/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301237 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1238 * @hdd_ctx: HDD context
1239 *
1240 * Updates wiphy vhtcap fields
1241 *
1242 * Return: None
1243 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001244static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301245{
1246 struct ieee80211_supported_band *band_5g =
1247 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1248 uint32_t val;
1249
1250 if (!band_5g) {
1251 hdd_debug("5GHz band disabled, skipping capability population");
1252 return;
1253 }
1254
1255 val = hdd_ctx->config->txBFCsnValue;
1256 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1257
1258 val = NUM_OF_SOUNDING_DIMENSIONS;
1259 band_5g->vht_cap.cap |=
1260 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1261
1262 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1263 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1264}
1265
1266/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301267 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1268 * @hdd_ctx: HDD context
1269 *
1270 * Sets the DBS capability as per INI and firmware capability
1271 *
1272 * Return: None
1273 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001274static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301275{
1276 struct hdd_config *cfg_ini = hdd_ctx->config;
1277 uint8_t hw_dbs_capable = 0;
1278
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001279 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1280 ((cfg_ini->dual_mac_feature_disable ==
1281 ENABLE_DBS_CXN_AND_SCAN) ||
1282 (cfg_ini->dual_mac_feature_disable ==
1283 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301284 hw_dbs_capable = 1;
1285
1286 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1287}
1288
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001289static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001290 struct wma_tgt_ht_cap *cfg)
1291{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301292 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001293 uint32_t value, val32;
1294 uint16_t val16;
1295 struct hdd_config *pconfig = hdd_ctx->config;
1296 tSirMacHTCapabilityInfo *phtCapInfo;
1297 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1298 uint8_t enable_tx_stbc;
1299
1300 /* check and update RX STBC */
1301 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1302 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1303
1304 /* get the MPDU density */
1305 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1306
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301307 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001308 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001309 value = 0;
1310 }
1311
1312 /*
1313 * MPDU density:
1314 * override user's setting if value is larger
1315 * than the one supported by target
1316 */
1317 if (value > cfg->mpdu_density) {
1318 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1319 cfg->mpdu_density);
1320
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301321 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001322 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 }
1324
1325 /* get the HT capability info */
1326 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301327 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001328 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329 return;
1330 }
1331 val16 = (uint16_t) val32;
1332 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1333
1334 /* Set the LDPC capability */
1335 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1336
1337 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1338 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1339
1340 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1341 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1342
1343 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1344 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1345
1346 enable_tx_stbc = pconfig->enableTxSTBC;
1347
1348 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1349 pconfig->enable2x2 = 1;
1350 } else {
1351 pconfig->enable2x2 = 0;
1352 enable_tx_stbc = 0;
1353
1354 /* 1x1 */
1355 /* Update Rx Highest Long GI data Rate */
1356 if (sme_cfg_set_int(hdd_ctx->hHal,
1357 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001358 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301359 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001360 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 }
1362
1363 /* Update Tx Highest Long GI data Rate */
1364 if (sme_cfg_set_int
1365 (hdd_ctx->hHal,
1366 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001367 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301368 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001369 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370 }
1371 }
1372 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1373 enable_tx_stbc = 0;
1374 phtCapInfo->txSTBC = enable_tx_stbc;
1375
1376 val32 = val16;
1377 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301378 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001379 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001380#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1381 value = SIZE_OF_SUPPORTED_MCS_SET;
1382 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301383 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001384 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385
1386 if (pconfig->enable2x2) {
1387 for (value = 0; value < cfg->num_rf_chains; value++)
1388 mcs_set[value] =
1389 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1390
1391 status =
1392 sme_cfg_set_str(hdd_ctx->hHal,
1393 WNI_CFG_SUPPORTED_MCS_SET,
1394 mcs_set,
1395 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301396 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001397 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001398 }
1399 }
1400#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1401}
1402
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001403static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 struct wma_tgt_vht_cap *cfg)
1405{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301406 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001407 uint32_t value = 0;
1408 struct hdd_config *pconfig = hdd_ctx->config;
1409 struct wiphy *wiphy = hdd_ctx->wiphy;
1410 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001411 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001412 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001413 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001414 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001415
Dustin Brown5e06bd32016-10-04 12:49:10 -07001416 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001417 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001418 return;
1419 }
1420
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001421 /* Get the current MPDU length */
1422 status =
1423 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1424 &value);
1425
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301426 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001427 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 value = 0;
1429 }
1430
1431 /*
1432 * VHT max MPDU length:
1433 * override if user configured value is too high
1434 * that the target cannot support
1435 */
1436 if (value > cfg->vht_max_mpdu) {
1437 status = sme_cfg_set_int(hdd_ctx->hHal,
1438 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1439 cfg->vht_max_mpdu);
1440
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001441 if (status == QDF_STATUS_E_FAILURE)
1442 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001443 }
1444
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001445 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1446 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1447
1448 if (pconfig->enable2x2)
1449 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1450
1451 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1452 QDF_STATUS_E_FAILURE) {
1453 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1454 }
1455
1456 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1457 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1458 if (pconfig->enable2x2)
1459 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1460
1461 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1462 QDF_STATUS_E_FAILURE) {
1463 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1464 }
1465
1466 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1467 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1468 if (pconfig->enable2x2)
1469 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1470
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001471 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001472 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1473
1474 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1475 QDF_STATUS_E_FAILURE) {
1476 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1477 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001478 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001479 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001480 &value);
1481
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301482 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001483 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001484 value = 0;
1485 }
1486
jiad4a7a33c2017-08-08 15:32:24 +08001487 /* Set HW RX LDPC capability */
1488 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1489 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 status = sme_cfg_set_int(hdd_ctx->hHal,
1491 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001492 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001494 if (status == QDF_STATUS_E_FAILURE)
1495 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 }
1497
1498 /* Get current GI 80 value */
1499 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1500 &value);
1501
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301502 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001503 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001504 value = 0;
1505 }
1506
1507 /* set the Guard interval 80MHz */
1508 if (value && !cfg->vht_short_gi_80) {
1509 status = sme_cfg_set_int(hdd_ctx->hHal,
1510 WNI_CFG_VHT_SHORT_GI_80MHZ,
1511 cfg->vht_short_gi_80);
1512
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001513 if (status == QDF_STATUS_E_FAILURE)
1514 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001515 }
1516
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001517 /* Get VHT TX STBC cap */
1518 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1519
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301520 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001521 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001522 value = 0;
1523 }
1524
1525 /* VHT TX STBC cap */
1526 if (value && !cfg->vht_tx_stbc) {
1527 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1528 cfg->vht_tx_stbc);
1529
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001530 if (status == QDF_STATUS_E_FAILURE)
1531 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001532 }
1533
1534 /* Get VHT RX STBC cap */
1535 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1536
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301537 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001538 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001539 value = 0;
1540 }
1541
1542 /* VHT RX STBC cap */
1543 if (value && !cfg->vht_rx_stbc) {
1544 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1545 cfg->vht_rx_stbc);
1546
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001547 if (status == QDF_STATUS_E_FAILURE)
1548 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549 }
1550
1551 /* Get VHT SU Beamformer cap */
1552 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1553 &value);
1554
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301555 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001556 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001557 value = 0;
1558 }
1559
1560 /* set VHT SU Beamformer cap */
1561 if (value && !cfg->vht_su_bformer) {
1562 status = sme_cfg_set_int(hdd_ctx->hHal,
1563 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1564 cfg->vht_su_bformer);
1565
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001566 if (status == QDF_STATUS_E_FAILURE)
1567 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001568 }
1569
1570 /* check and update SU BEAMFORMEE capabality */
1571 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1572 pconfig->enableTxBF = cfg->vht_su_bformee;
1573
1574 status = sme_cfg_set_int(hdd_ctx->hHal,
1575 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1576 pconfig->enableTxBF);
1577
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001578 if (status == QDF_STATUS_E_FAILURE)
1579 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001580
1581 /* Get VHT MU Beamformer cap */
1582 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1583 &value);
1584
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301585 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001586 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001587 value = 0;
1588 }
1589
1590 /* set VHT MU Beamformer cap */
1591 if (value && !cfg->vht_mu_bformer) {
1592 status = sme_cfg_set_int(hdd_ctx->hHal,
1593 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1594 cfg->vht_mu_bformer);
1595
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001596 if (status == QDF_STATUS_E_FAILURE)
1597 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001598 }
1599
1600 /* Get VHT MU Beamformee cap */
1601 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1602 &value);
1603
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301604 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001605 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606 value = 0;
1607 }
1608
1609 /* set VHT MU Beamformee cap */
1610 if (value && !cfg->vht_mu_bformee) {
1611 status = sme_cfg_set_int(hdd_ctx->hHal,
1612 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1613 cfg->vht_mu_bformee);
1614
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001615 if (status == QDF_STATUS_E_FAILURE)
1616 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001617 }
1618
1619 /* Get VHT MAX AMPDU Len exp */
1620 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1621 &value);
1622
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301623 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001624 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625 value = 0;
1626 }
1627
1628 /*
1629 * VHT max AMPDU len exp:
1630 * override if user configured value is too high
1631 * that the target cannot support.
1632 * Even though Rome publish ampdu_len=7, it can
1633 * only support 4 because of some h/w bug.
1634 */
1635
1636 if (value > cfg->vht_max_ampdu_len_exp) {
1637 status = sme_cfg_set_int(hdd_ctx->hHal,
1638 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1639 cfg->vht_max_ampdu_len_exp);
1640
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001641 if (status == QDF_STATUS_E_FAILURE)
1642 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643 }
1644
1645 /* Get VHT TXOP PS CAP */
1646 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1647
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301648 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001649 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001650 value = 0;
1651 }
1652
1653 /* set VHT TXOP PS cap */
1654 if (value && !cfg->vht_txop_ps) {
1655 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1656 cfg->vht_txop_ps);
1657
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001658 if (status == QDF_STATUS_E_FAILURE)
1659 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001660 }
1661
1662 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1663 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1664 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1665 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1666 else
1667 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1668
1669
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001670 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1671 status = sme_cfg_set_int(hdd_ctx->hHal,
1672 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1673 VHT_CAP_160_AND_80P80_SUPP);
1674 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001675 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676 band_5g->vht_cap.cap |=
1677 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001678 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1679 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1680 status = sme_cfg_set_int(hdd_ctx->hHal,
1681 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1682 VHT_CAP_160_SUPP);
1683 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001684 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001685 band_5g->vht_cap.cap |=
1686 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001687 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1688 }
1689 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1690 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301691 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001692 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301693 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001694 &value);
1695 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301696 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001697 value = 0;
1698 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301699 /* set the Guard interval 160MHz */
1700 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001701 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301702 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1703 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001704
1705 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301706 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001707 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708
1709 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1710 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1711
1712 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1713 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1714 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1715 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1716
1717 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1718 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1719
1720 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1721 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1722 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1723 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1724 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1725 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1726
1727 band_5g->vht_cap.cap |=
1728 (cfg->vht_max_ampdu_len_exp <<
1729 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1730
1731 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1732 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1733 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1734 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1735 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1736 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1737 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1738 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1739
1740 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1741 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1742
1743}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001744
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001745/**
1746 * hdd_generate_macaddr_auto() - Auto-generate mac address
1747 * @hdd_ctx: Pointer to the HDD context
1748 *
1749 * Auto-generate mac address using device serial number.
1750 * Keep the first 3 bytes of OUI as before and replace
1751 * the last 3 bytes with the lower 3 bytes of serial number.
1752 *
1753 * Return: 0 for success
1754 * Non zero failure code for errors
1755 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001756static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001757{
1758 unsigned int serialno = 0;
1759 struct qdf_mac_addr mac_addr = {
1760 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1761 };
1762
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001763 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001764 if (serialno == 0)
1765 return -EINVAL;
1766
1767 serialno &= 0x00ffffff;
1768
1769 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1770 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1771 mac_addr.bytes[5] = serialno & 0xff;
1772
1773 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1774 return 0;
1775}
1776
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301777/**
1778 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1779 * configuration to cfg_ini in HDD
1780 * @hdd_ctx: Pointer to hdd_ctx
1781 * @cfg: target configuration
1782 *
1783 * Return: None
1784 */
1785#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001786static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301787 struct wma_tgt_cfg *cfg)
1788{
1789 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1790}
1791#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001792static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301793 struct wma_tgt_cfg *cfg)
1794{
1795}
1796#endif
1797
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301798uint8_t hdd_check_green_ap_enable(struct hdd_context *hdd_ctx,
1799 bool *is_enabled)
1800{
1801 struct hdd_config *cfg;
1802 uint32_t concurrency_mode;
1803
1804 cfg = hdd_ctx->config;
1805 if (!cfg) {
1806 hdd_err("NULL hdd config");
1807 return -EINVAL;
1808 }
1809
1810 concurrency_mode = policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc);
1811
1812 if (cfg->enable2x2 && cfg->enableGreenAP) {
1813 if ((concurrency_mode & (1 << QDF_SAP_MODE)) &&
1814 !(concurrency_mode & (~(1 << QDF_SAP_MODE))))
1815 *is_enabled = true;
1816 }
1817 return 0;
1818}
1819
1820static int hdd_update_green_ap_config(struct hdd_context *hdd_ctx)
1821{
1822 struct green_ap_user_cfg green_ap_cfg;
1823 struct hdd_config *cfg = hdd_ctx->config;
1824 QDF_STATUS status;
1825
1826 green_ap_cfg.host_enable_egap = cfg->enable_egap;
1827 green_ap_cfg.egap_inactivity_time = cfg->egap_inact_time;
1828 green_ap_cfg.egap_wait_time = cfg->egap_wait_time;
1829 green_ap_cfg.egap_feature_flags = cfg->egap_feature_flag;
1830
1831 status = ucfg_green_ap_update_user_config(hdd_ctx->hdd_pdev,
1832 &green_ap_cfg);
1833 if (status != QDF_STATUS_SUCCESS) {
1834 hdd_err("failed to update green ap user configuration");
1835 return -EINVAL;
1836 }
1837
1838 return 0;
1839}
1840
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001841void hdd_update_tgt_cfg(void *context, void *param)
1842{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001843 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001844 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001845 struct wma_tgt_cfg *cfg = param;
1846 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001847 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301848 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001849 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301850
Dustin Brownbd68fe12017-11-21 15:28:52 -08001851 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1852 if (ret) {
1853 hdd_err("Failed to create pdev; errno:%d", ret);
1854 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001855 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001856 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001857 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001858 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1859 hdd_err("dispatcher pdev open failed");
1860 QDF_BUG(0);
1861 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301862 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001863
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301864 ret = hdd_update_green_ap_config(hdd_ctx);
1865
Naveen Rawat64e477e2016-05-20 10:34:56 -07001866 if (cds_cfg) {
1867 if (hdd_ctx->config->enable_sub_20_channel_width !=
1868 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1869 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1870 cds_cfg->sub_20_channel_width =
1871 WLAN_SUB_20_CH_WIDTH_NONE;
1872 } else {
1873 cds_cfg->sub_20_channel_width =
1874 hdd_ctx->config->enable_sub_20_channel_width;
1875 }
1876 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877
1878 /* first store the INI band capability */
1879 temp_band_cap = hdd_ctx->config->nBandCapability;
1880
1881 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301882 hdd_ctx->is_fils_roaming_supported =
1883 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001884
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301885 hdd_ctx->config->is_11k_offload_supported =
1886 cfg->services.is_11k_offload_supported;
1887
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001888 /*
1889 * now overwrite the target band capability with INI
1890 * setting if INI setting is a subset
1891 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001892
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001893 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1894 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001895 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001896 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1897 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001898 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001899 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900 }
1901
Amar Singhal58b45ef2017-08-01 13:43:54 -07001902 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1903
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301904 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001905 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1906 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1907 }
1908
1909 /* This can be extended to other configurations like ht, vht cap... */
1910
Anurag Chouhanc5548422016-02-24 18:33:27 +05301911 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001912 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001913 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001914 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001915 static struct qdf_mac_addr default_mac_addr = {
1916 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1917 };
1918 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1919 &default_mac_addr)) {
1920 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1921 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1922 MAC_ADDRESS_STR,
1923 MAC_ADDR_ARRAY(hdd_ctx->config->
1924 intfMacAddr[0].bytes));
1925 } else {
1926 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1927 MAC_ADDRESS_STR,
1928 MAC_ADDR_ARRAY(hdd_ctx->config->
1929 intfMacAddr[0].bytes));
1930 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001931 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001932 }
1933
1934 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001935 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001936
1937 hdd_ctx->max_intf_count = cfg->max_intf_count;
1938
Jeff Johnsonc875e242016-09-23 18:12:34 -07001939 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001940
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001941 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1942 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1943
1944 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1945
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001946 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001947 if (cfg->services.en_11ax) {
1948 hdd_info("11AX: 11ax is enabled - update HDD config");
1949 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1950 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001951
1952 hdd_update_vdev_nss(hdd_ctx);
1953
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301954 hdd_update_hw_dbs_capable(hdd_ctx);
1955
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001956 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001957 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001958 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001959 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001960
Nitesh Shahe50711f2017-04-26 16:30:45 +05301961 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1962 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1963 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001964 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001965 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001966
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001967 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1968 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301969 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301970 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301971
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301972 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001973 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1974 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301975 hdd_ctx->config->txBFCsnValue =
1976 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1977
Arif Hussainee10f902017-12-27 16:30:17 -08001978 status = sme_cfg_set_int(hdd_ctx->hHal,
1979 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1980 hdd_ctx->config->txBFCsnValue);
1981 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301982 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1983
1984
1985 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001986 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1987 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301988
1989 /*
1990 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1991 */
1992 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301993
Arun Khandavallid454d422016-08-17 12:47:05 +05301994 /*
1995 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1996 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1997 * configure the STA mode wow pattern.
1998 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301999 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05302000 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302001
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302002 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2003
Yue Macd359b72017-10-03 15:21:00 -07002004 /*
2005 * This needs to be done after HDD pdev is created and stored since
2006 * it will access the HDD pdev object lock.
2007 */
2008 hdd_runtime_suspend_context_init(hdd_ctx);
2009
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002010 /* Configure NAN datapath features */
2011 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002012 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002013 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002014 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2015 cfg->obss_detection_offloaded);
2016 if (QDF_IS_STATUS_ERROR(status))
2017 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002018
2019 status = sme_cfg_set_int(hdd_ctx->hHal,
2020 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2021 cfg->obss_color_collision_offloaded);
2022 if (QDF_IS_STATUS_ERROR(status))
2023 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002024}
2025
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002026bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002027{
Jeff Johnson9d295242017-08-29 14:39:48 -07002028 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002029 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002030
Jiachao Wuf610d912018-01-23 17:47:32 +08002031 if (!hdd_ctx) {
2032 hdd_info("Couldn't get hdd_ctx");
2033 return true;
2034 }
2035
2036 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002037 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002038 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302039 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002040 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002041
Dustin Brown920397d2017-12-13 16:27:50 -08002042 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002043 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2044
2045 if ((QDF_SAP_MODE == adapter->device_mode ||
2046 QDF_P2P_GO_MODE == adapter->device_mode) &&
2047 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002048 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002049 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2050 true;
2051 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002052 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302053 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002054 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302055
2056 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002057}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002058
2059/**
2060 * hdd_is_valid_mac_address() - validate MAC address
2061 * @pMacAddr: Pointer to the input MAC address
2062 *
2063 * This function validates whether the given MAC address is valid or not
2064 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2065 * where X is the hexa decimal digit character and separated by ':'
2066 * This algorithm works even if MAC address is not separated by ':'
2067 *
2068 * This code checks given input string mac contains exactly 12 hexadecimal
2069 * digits and a separator colon : appears in the input string only after
2070 * an even number of hex digits.
2071 *
2072 * Return: 1 for valid and 0 for invalid
2073 */
2074bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2075{
2076 int xdigit = 0;
2077 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002078
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002079 while (*pMacAddr) {
2080 if (isxdigit(*pMacAddr)) {
2081 xdigit++;
2082 } else if (':' == *pMacAddr) {
2083 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2084 break;
2085
2086 ++separator;
2087 } else {
2088 /* Invalid MAC found */
2089 return 0;
2090 }
2091 ++pMacAddr;
2092 }
2093 return xdigit == 12 && (separator == 5 || separator == 0);
2094}
2095
2096/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302097 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2098 * @dev: Handle to struct net_device to be updated.
2099 *
2100 * Return: None
2101 */
2102static void hdd_mon_mode_ether_setup(struct net_device *dev)
2103{
2104 dev->header_ops = NULL;
2105 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2106 dev->hard_header_len = ETH_HLEN;
2107 dev->mtu = ETH_DATA_LEN;
2108 dev->addr_len = ETH_ALEN;
2109 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2110 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2111 dev->priv_flags |= IFF_TX_SKB_SHARING;
2112
2113 memset(dev->broadcast, 0xFF, ETH_ALEN);
2114}
2115
2116/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002117 * __hdd__mon_open() - HDD Open function
2118 * @dev: Pointer to net_device structure
2119 *
2120 * This is called in response to ifconfig up
2121 *
2122 * Return: 0 for success; non-zero for failure
2123 */
2124static int __hdd_mon_open(struct net_device *dev)
2125{
2126 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002127 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2128 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002129
2130 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002131
2132 ret = wlan_hdd_validate_context(hdd_ctx);
2133 if (ret)
2134 return ret;
2135
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302136 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002137
2138 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2139 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2140 if (ret) {
2141 hdd_err("Failed to start WLAN modules return");
2142 return ret;
2143 }
2144 hdd_err("hdd_wlan_start_modules() successful !");
2145
2146 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2147 ret = hdd_start_adapter(adapter);
2148 if (ret) {
2149 hdd_err("Failed to start adapter :%d",
2150 adapter->device_mode);
2151 return ret;
2152 }
2153 hdd_err("hdd_start_adapters() successful !");
2154 }
2155 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2156 }
2157
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002158 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002159
2160 if (!ret)
2161 ret = hdd_enable_monitor_mode(dev);
2162
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002163 return ret;
2164}
2165
2166/**
2167 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2168 * @dev: Pointer to net_device structure
2169 *
2170 * This is called in response to ifconfig up
2171 *
2172 * Return: 0 for success; non-zero for failure
2173 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002174static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002175{
2176 int ret;
2177
2178 cds_ssr_protect(__func__);
2179 ret = __hdd_mon_open(dev);
2180 cds_ssr_unprotect(__func__);
2181
2182 return ret;
2183}
2184
2185/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302186 * hdd_start_adapter() - Wrapper function for device specific adapter
2187 * @adapter: pointer to HDD adapter
2188 *
2189 * This function is called to start the device specific adapter for
2190 * the mode passed in the adapter's device_mode.
2191 *
2192 * Return: 0 for success; non-zero for failure
2193 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002194int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302195{
2196
2197 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002198 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302199
2200 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002201 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302202
2203 switch (device_mode) {
2204 case QDF_P2P_CLIENT_MODE:
2205 case QDF_P2P_DEVICE_MODE:
2206 case QDF_OCB_MODE:
2207 case QDF_STA_MODE:
2208 case QDF_MONITOR_MODE:
2209 ret = hdd_start_station_adapter(adapter);
2210 if (ret)
2211 goto err_start_adapter;
2212 break;
2213 case QDF_P2P_GO_MODE:
2214 case QDF_SAP_MODE:
2215 ret = hdd_start_ap_adapter(adapter);
2216 if (ret)
2217 goto err_start_adapter;
2218 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302219 case QDF_IBSS_MODE:
2220 /*
2221 * For IBSS interface is initialized as part of
2222 * hdd_init_station_mode()
2223 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002224 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302225 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002226 /* vdevs are dynamically managed by firmware in FTM */
2227 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302228 default:
2229 hdd_err("Invalid session type %d", device_mode);
2230 QDF_ASSERT(0);
2231 goto err_start_adapter;
2232 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002233
Arun Khandavallifae92942016-08-01 13:31:08 +05302234 if (hdd_set_fw_params(adapter))
2235 hdd_err("Failed to set the FW params for the adapter!");
2236
2237 /*
2238 * Action frame registered in one adapter which will
2239 * applicable to all interfaces
2240 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302241 ret = wlan_hdd_cfg80211_register_frames(adapter);
2242 if (ret < 0) {
2243 hdd_err("Failed to register frames - ret %d", ret);
2244 goto err_start_adapter;
2245 }
2246
Dustin Browndb2a8be2017-12-20 11:49:56 -08002247exit_with_success:
Arun Khandavallifae92942016-08-01 13:31:08 +05302248 EXIT();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002249
Arun Khandavallifae92942016-08-01 13:31:08 +05302250 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002251
Arun Khandavallifae92942016-08-01 13:31:08 +05302252err_start_adapter:
2253 return -EINVAL;
2254}
2255
2256/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302257 * hdd_enable_power_management() - API to Enable Power Management
2258 *
2259 * API invokes Bus Interface Layer power management functionality
2260 *
2261 * Return: None
2262 */
2263static void hdd_enable_power_management(void)
2264{
2265 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2266
2267 if (!hif_ctx) {
2268 hdd_err("Bus Interface Context is Invalid");
2269 return;
2270 }
2271
2272 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2273}
2274
2275/**
2276 * hdd_disable_power_management() - API to disable Power Management
2277 *
2278 * API disable Bus Interface Layer Power management functionality
2279 *
2280 * Return: None
2281 */
2282static void hdd_disable_power_management(void)
2283{
2284 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2285
2286 if (!hif_ctx) {
2287 hdd_err("Bus Interface Context is Invalid");
2288 return;
2289 }
2290
2291 hif_disable_power_management(hif_ctx);
2292}
2293
2294/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302295 * hdd_update_hw_sw_info() - API to update the HW/SW information
2296 *
2297 * API to update the HW and SW information in the driver
2298 *
2299 * Return: None
2300 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002301static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302302{
2303 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002304 size_t target_hw_name_len;
2305 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302306
2307 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2308 if (!hif_sc) {
2309 hdd_err("HIF context is NULL");
2310 return;
2311 }
2312
2313 /*
2314 * target hw version/revision would only be retrieved after firmware
2315 * download
2316 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002317 hif_get_hw_info(hif_sc,
2318 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302319 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002320 &target_hw_name);
2321
2322 if (hdd_ctx->target_hw_name)
2323 qdf_mem_free(hdd_ctx->target_hw_name);
2324
2325 target_hw_name_len = strlen(target_hw_name) + 1;
2326 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2327 if (hdd_ctx->target_hw_name)
2328 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2329 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302330
2331 /* Get the wlan hw/fw version */
2332 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302333}
2334
2335/**
gbian62edd7e2017-03-07 13:12:13 +08002336 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2337 * @hdd_ctx: Pointer to hdd context
2338 *
2339 * Return: none
2340 */
2341static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002342hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002343{
2344 uint8_t num_entries = 0;
2345 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2346 uint8_t *tx_sched_wrr_ac;
2347 int i;
2348 cds_context_type *cds_ctx;
2349
2350 if (NULL == hdd_ctx)
2351 return;
2352
2353 if (NULL == hdd_ctx->config) {
2354 /* Do nothing if hdd_ctx is invalid */
2355 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2356 return;
2357 }
2358
2359 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2360
2361 if (!cds_ctx) {
2362 hdd_err("Invalid CDS Context");
2363 return;
2364 }
2365
2366 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2367 switch (i) {
2368 case OL_TX_WMM_AC_BE:
2369 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2370 break;
2371 case OL_TX_WMM_AC_BK:
2372 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2373 break;
2374 case OL_TX_WMM_AC_VI:
2375 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2376 break;
2377 case OL_TX_WMM_AC_VO:
2378 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2379 break;
2380 default:
2381 tx_sched_wrr_ac = NULL;
2382 break;
2383 }
2384
2385 hdd_string_to_u8_array(tx_sched_wrr_ac,
2386 tx_sched_wrr_param,
2387 &num_entries,
2388 sizeof(tx_sched_wrr_param));
2389
2390 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2391 cds_ctx->ac_specs[i].wrr_skip_weight =
2392 tx_sched_wrr_param[0];
2393 cds_ctx->ac_specs[i].credit_threshold =
2394 tx_sched_wrr_param[1];
2395 cds_ctx->ac_specs[i].send_limit =
2396 tx_sched_wrr_param[2];
2397 cds_ctx->ac_specs[i].credit_reserve =
2398 tx_sched_wrr_param[3];
2399 cds_ctx->ac_specs[i].discard_weight =
2400 tx_sched_wrr_param[4];
2401 }
2402
2403 num_entries = 0;
2404 }
2405}
2406
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002407#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002408static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2409 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2410{
Jeff Johnson9d295242017-08-29 14:39:48 -07002411 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002412 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002413
2414 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2415 if (!adapter) {
2416 hdd_err("Adapter is NULL");
2417 return PM_MAX_NUM_OF_MODE;
2418 }
2419
2420 return policy_mgr_convert_device_mode_to_qdf_type(
2421 adapter->device_mode);
2422}
2423
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002424static void hdd_register_policy_manager_callback(
2425 struct wlan_objmgr_psoc *psoc)
2426{
2427 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002428
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002429 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002430 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002431 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2432 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002433 hdd_cbacks.get_mode_for_non_connected_vdev =
2434 wlan_hdd_get_mode_for_non_connected_vdev;
2435
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002436 if (QDF_STATUS_SUCCESS !=
2437 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2438 hdd_err("HDD callback registration with policy manager failed");
2439 }
2440}
2441#else
2442static void hdd_register_policy_manager_callback(
2443 struct wlan_objmgr_psoc *psoc)
2444{
2445}
2446#endif
2447
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002448static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002449{
2450 struct nan_callbacks cb_obj = {0};
2451
2452 cb_obj.ndi_open = hdd_ndi_open;
2453 cb_obj.ndi_close = hdd_ndi_close;
2454 cb_obj.ndi_start = hdd_ndi_start;
2455 cb_obj.ndi_delete = hdd_ndi_delete;
2456 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2457 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2458
Naveen Rawat37f62c82017-03-26 22:24:43 -07002459 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2460 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002461 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002462
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002463 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2464}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002465
Dustin Brown26b3d042017-12-21 11:13:27 -08002466#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002467/**
2468 * hdd_check_for_leaks() - Perform runtime memory leak checks
2469 *
2470 * This API triggers runtime memory leak detection. This feature enforces the
2471 * policy that any memory allocated at runtime must also be released at runtime.
2472 *
2473 * Allocating memory at runtime and releasing it at unload is effectively a
2474 * memory leak for configurations which never unload (e.g. LONU, statically
2475 * compiled driver). Such memory leaks are NOT false positives, and must be
2476 * fixed.
2477 *
2478 * Return: None
2479 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002480static void hdd_check_for_leaks(void)
2481{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002482 /* DO NOT REMOVE these checks; for false positives, read above first */
2483
Dustin Brown677e0862017-10-10 16:30:09 -07002484 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002485 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002486 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002487}
2488
Dustin Brown26b3d042017-12-21 11:13:27 -08002489#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2490#else
2491static inline void hdd_check_for_leaks(void) {}
2492
2493#define hdd_debug_domain_set(domain)
2494#endif /* CONFIG_LEAK_DETECTION */
2495
gbian62edd7e2017-03-07 13:12:13 +08002496/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002497 * hdd_update_country_code - Update country code
2498 * @hdd_ctx: HDD context
2499 *
2500 * Update country code based on module parameter country_code
2501 *
2502 * Return: 0 on success and errno on failure
2503 */
2504static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2505{
2506 if (!country_code)
2507 return 0;
2508
2509 return hdd_reg_set_country(hdd_ctx, country_code);
2510}
2511
2512/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302513 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2514 * @hdd_ctx: HDD context
2515 * @adapter: HDD adapter
2516 * @reinit: flag to indicate from SSR or normal path
2517 *
2518 * This function maintains the driver state machine it will be invoked from
2519 * startup, reinit and change interface. Depending on the driver state shall
2520 * perform the opening of the modules.
2521 *
2522 * Return: 0 for success; non-zero for failure
2523 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002524int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2525 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302526 bool reinit)
2527{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002528 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302529 qdf_device_t qdf_dev;
2530 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302531 bool unint = false;
2532 void *hif_ctx;
2533
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002534 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302535
2536 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2537 if (!qdf_dev) {
2538 hdd_err("QDF Device Context is Invalid return");
2539 return -EINVAL;
2540 }
2541
Dustin Brown6f427922017-09-19 12:19:00 -07002542 hdd_set_idle_ps_config(hdd_ctx, false);
2543 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302544
Dustin Brown1fe30a82017-10-03 16:13:36 -07002545 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302546 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2547 mutex_unlock(&hdd_ctx->iface_change_lock);
2548 hdd_info("Driver modules already Enabled");
2549 EXIT();
2550 return 0;
2551 }
2552
Dustin Brown1fe30a82017-10-03 16:13:36 -07002553 hdd_ctx->start_modules_in_progress = true;
2554
Arun Khandavallifae92942016-08-01 13:31:08 +05302555 switch (hdd_ctx->driver_status) {
2556 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002557 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302558 unint = true;
2559 /* Fall through dont add break here */
2560 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002561 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2562
Dustin Brown26b3d042017-12-21 11:13:27 -08002563 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002564
Arun Khandavallifae92942016-08-01 13:31:08 +05302565 if (!reinit && !unint) {
2566 ret = pld_power_on(qdf_dev->dev);
2567 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002568 hdd_err("Failed to Powerup the device; errno: %d",
2569 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302570 goto release_lock;
2571 }
2572 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002573
2574 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2575 hdd_ctx->config->enable_fw_log);
2576
Arun Khandavallifae92942016-08-01 13:31:08 +05302577 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2578 qdf_dev->bus_type,
2579 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2580 HIF_ENABLE_TYPE_PROBE);
2581 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002582 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302583 goto power_down;
2584 }
2585
2586 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302587 if (!hif_ctx) {
2588 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002589 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302590 goto power_down;
2591 }
2592
Arun Khandavallifae92942016-08-01 13:31:08 +05302593 status = ol_cds_init(qdf_dev, hif_ctx);
2594 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002595 hdd_err("No Memory to Create BMI Context; status: %d",
2596 status);
2597 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302598 goto hif_close;
2599 }
2600
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002601 ret = hdd_update_config(hdd_ctx);
2602 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002603 hdd_err("Failed to update configuration; errno: %d",
2604 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002605 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002606 }
2607
gbian62edd7e2017-03-07 13:12:13 +08002608 hdd_update_cds_ac_specs_params(hdd_ctx);
2609
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302610 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002611 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002612 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002613 ret = qdf_status_to_os_return(status);
2614 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302615 }
2616
Mukul Sharma9d797a02017-01-05 20:26:03 +05302617 /* initalize components configurations after psoc open */
2618 ret = hdd_update_components_config(hdd_ctx);
2619 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002620 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302621 ret);
2622 goto close;
2623 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002624 status = cds_dp_open(hdd_ctx->hdd_psoc);
2625 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002626 hdd_err("Failed to Open cds post open; status: %d",
2627 status);
2628 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002629 goto close;
2630 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302631
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002632 /*
2633 * NAN compoenet requires certian operations like, open adapter,
2634 * close adapter, etc. to be initiated by HDD, for those
2635 * register HDD callbacks with UMAC's NAN componenet.
2636 */
2637 hdd_nan_register_callbacks(hdd_ctx);
2638
Arun Khandavallifae92942016-08-01 13:31:08 +05302639 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2640
Jeff Johnson3a280122017-09-13 07:42:00 -07002641 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302642 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002643 hdd_err("Failed to pre-enable CDS; status: %d", status);
2644 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002645 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302646 }
2647
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002648 hdd_register_policy_manager_callback(
2649 hdd_ctx->hdd_psoc);
2650
Amar Singhal0928b192017-12-01 10:50:54 -08002651 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2652
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302653 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302654 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002655 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302656
Arun Khandavallifae92942016-08-01 13:31:08 +05302657 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002658 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302659 break;
2660 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302661
2662 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002663 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2664 if (ret) {
2665 hdd_err("HDD IPA UC reinit failed; errno: %d",
2666 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002667 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002668 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302669 }
2670
Arun Khandavallifae92942016-08-01 13:31:08 +05302671 /* Fall through dont add break here */
2672 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002673 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2674
Arun Khandavallifae92942016-08-01 13:31:08 +05302675 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002676 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002677 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002678 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302679 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302680 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2681 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002682 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302683 break;
2684 }
Dustin Browndca39692017-11-09 15:30:25 -08002685
2686 ret = hdd_configure_cds(hdd_ctx, adapter);
2687 if (ret) {
2688 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002689 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302690 }
Dustin Browndca39692017-11-09 15:30:25 -08002691
Komal Seelamf2136bb2016-09-28 18:30:44 +05302692 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002693
Arun Khandavallifae92942016-08-01 13:31:08 +05302694 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002695 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302696 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002697
Arun Khandavallifae92942016-08-01 13:31:08 +05302698 default:
2699 hdd_err("WLAN start invoked in wrong state! :%d\n",
2700 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002701 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302702 goto release_lock;
2703 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002704
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302705 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002706 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2707 ret = hdd_update_country_code(hdd_ctx);
2708 if (ret)
2709 hdd_err("Failed to update command line country code!");
2710 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302711 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002712
Arun Khandavallifae92942016-08-01 13:31:08 +05302713 EXIT();
Dustin Brown550f6d22017-12-14 15:44:01 -08002714
Arun Khandavallifae92942016-08-01 13:31:08 +05302715 return 0;
2716
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002717post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002718 cds_post_disable();
Amar Singhal410675c2018-01-10 12:14:21 -08002719 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Dustin Brownbd68fe12017-11-21 15:28:52 -08002720 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002721
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002722cds_txrx_free:
2723 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002724
Arun Khandavallifae92942016-08-01 13:31:08 +05302725close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002726 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002727 hdd_info("Wlan transition aborted (now CLOSED)");
2728
Jeff Johnsone4b14592017-09-13 14:23:33 -07002729 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302730
Dustin Brown28b17892017-10-10 13:29:38 -07002731deinit_config:
2732 cds_deinit_ini_config();
2733
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002734cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302735 ol_cds_free();
2736
2737hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002738 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2739 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302740power_down:
2741 if (!reinit && !unint)
2742 pld_power_off(qdf_dev->dev);
2743release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302744 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302745 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002746
2747 /* many adapter resources are not freed by design in SSR case */
2748 if (!reinit)
2749 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002750 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002751
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302752 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002753
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002754 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302755}
2756
Naveen Rawat910726a2017-03-06 11:42:51 -08002757#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002758static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002759{
2760 int ret = os_if_wifi_pos_register_nl();
2761
2762 if (ret)
2763 hdd_err("os_if_wifi_pos_register_nl failed");
2764
2765 return ret;
2766}
2767
2768static int hdd_deactivate_wifi_pos(void)
2769{
2770 int ret = os_if_wifi_pos_deregister_nl();
2771
2772 if (ret)
2773 hdd_err("os_if_wifi_pos_deregister_nl failed");
2774
2775 return ret;
2776}
2777
2778/**
2779 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2780 * @hdd_ctx: hdd context
2781 *
2782 * Return: status of operation
2783 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002784static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002785{
2786 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2787 struct hdd_config *cfg = hdd_ctx->config;
2788
2789 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2790 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2791 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2792 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2793 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2794 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2795 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2796 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2797}
2798#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002799static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002800{
2801 return oem_activate_service(hdd_ctx);
2802}
2803
2804static int hdd_deactivate_wifi_pos(void)
2805{
2806 return 0;
2807}
2808
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002809static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002810{
2811}
2812#endif
2813
Arun Khandavallifae92942016-08-01 13:31:08 +05302814/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002815 * __hdd_open() - HDD Open function
2816 * @dev: Pointer to net_device structure
2817 *
2818 * This is called in response to ifconfig up
2819 *
2820 * Return: 0 for success; non-zero for failure
2821 */
2822static int __hdd_open(struct net_device *dev)
2823{
Jeff Johnson9d295242017-08-29 14:39:48 -07002824 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002825 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002826 int ret;
2827
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002828 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302829 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002830 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002831
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302832 /* Nothing to be done if device is unloading */
2833 if (cds_is_driver_unloading()) {
2834 hdd_err("Driver is unloading can not open the hdd");
2835 return -EBUSY;
2836 }
2837
Dustin Brown01847752017-10-25 13:56:27 -07002838 if (cds_is_driver_recovering()) {
2839 hdd_err("WLAN is currently recovering; Please try again.");
2840 return -EBUSY;
2841 }
2842
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302843 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2844 hdd_err("con_mode_handler is in progress; Please try again.");
2845 return -EBUSY;
2846 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302847
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302848 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302849 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2850
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302851 /*
2852 * This scenario can be hit in cases where in the wlan driver after
2853 * registering the netdevices and there is a failure in driver
2854 * initialization. So return error gracefully because the netdevices
2855 * will be de-registered as part of the load failure.
2856 */
2857
2858 if (!cds_is_driver_loaded()) {
2859 hdd_err("Failed to start the wlan driver!!");
2860 ret = -EIO;
2861 goto err_hdd_hdd_init_deinit_lock;
2862 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302863
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002864
Arun Khandavallifae92942016-08-01 13:31:08 +05302865 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2866 if (ret) {
2867 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302868 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302869 }
2870
2871
2872 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2873 ret = hdd_start_adapter(adapter);
2874 if (ret) {
2875 hdd_err("Failed to start adapter :%d",
2876 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302877 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302878 }
2879 }
2880
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002881 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2882 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002883 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002884 /* Enable TX queues only when we are connected */
2885 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302886 WLAN_START_ALL_NETIF_QUEUE,
2887 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002888 }
2889
Naveen Rawat286def52016-09-23 15:38:02 -07002890 /* Enable carrier and transmit queues for NDI */
2891 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002892 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002893 wlan_hdd_netif_queue_control(adapter,
2894 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2895 WLAN_CONTROL_PATH);
2896 }
2897
Naveen Rawat910726a2017-03-06 11:42:51 -08002898 hdd_populate_wifi_pos_cfg(hdd_ctx);
2899
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302900err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302901 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302902 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903 return ret;
2904}
2905
Arun Khandavallifae92942016-08-01 13:31:08 +05302906
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002907/**
2908 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2909 * @dev: Pointer to net_device structure
2910 *
2911 * This is called in response to ifconfig up
2912 *
2913 * Return: 0 for success; non-zero for failure
2914 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002915static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002916{
2917 int ret;
2918
2919 cds_ssr_protect(__func__);
2920 ret = __hdd_open(dev);
2921 cds_ssr_unprotect(__func__);
2922
2923 return ret;
2924}
2925
2926/**
2927 * __hdd_stop() - HDD stop function
2928 * @dev: Pointer to net_device structure
2929 *
2930 * This is called in response to ifconfig down
2931 *
2932 * Return: 0 for success; non-zero for failure
2933 */
2934static int __hdd_stop(struct net_device *dev)
2935{
Jeff Johnson9d295242017-08-29 14:39:48 -07002936 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002937 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002938 int ret;
2939
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002940 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002941
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302942 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002943 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002944
2945 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302946 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002948
2949 /* Nothing to be done if the interface is not opened */
2950 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002951 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002952 return -ENODEV;
2953 }
2954
2955 /* Make sure the interface is marked as closed */
2956 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302957
2958 hdd_debug("Disabling Auto Power save timer");
2959 sme_ps_disable_auto_ps_timer(
2960 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002961 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302962
2963 /*
2964 * Disable TX on the interface, after this hard_start_xmit() will not
2965 * be called on that interface
2966 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002967 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2968 hdd_device_mode_to_string(adapter->device_mode),
2969 adapter->device_mode);
2970
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302971 wlan_hdd_netif_queue_control(adapter,
2972 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2973 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002974
2975 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002976 * NAN data interface is different in some sense. The traffic on NDI is
2977 * bursty in nature and depends on the need to transfer. The service
2978 * layer may down the interface after the usage and up again when
2979 * required. In some sense, the NDI is expected to be available
2980 * (like SAP) iface until NDI delete request is issued by the service
2981 * layer. Skip BSS termination and adapter deletion for NAN Data
2982 * interface (NDI).
2983 */
2984 if (WLAN_HDD_IS_NDI(adapter))
2985 return 0;
2986
2987 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002988 * The interface is marked as down for outside world (aka kernel)
2989 * But the driver is pretty much alive inside. The driver needs to
2990 * tear down the existing connection on the netdev (session)
2991 * cleanup the data pipes and wait until the control plane is stabilized
2992 * for this interface. The call also needs to wait until the above
2993 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002994 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002995 * That is intentional to be able to scan if it is a STA/P2P interface
2996 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002997 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002998
2999 /* DeInit the adapter. This ensures datapath cleanup as well */
3000 hdd_deinit_adapter(hdd_ctx, adapter, true);
3001
Arun Khandavallifae92942016-08-01 13:31:08 +05303002
3003 /*
3004 * Find if any iface is up. If any iface is up then can't put device to
3005 * sleep/power save mode
3006 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303007 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003008 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003009 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3010 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303011 hdd_prevent_suspend_timeout(
3012 hdd_ctx->config->iface_change_wait_time,
3013 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303014 }
3015
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003016 EXIT();
3017 return 0;
3018}
3019
3020/**
3021 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3022 * @dev: pointer to net_device structure
3023 *
3024 * This is called in response to ifconfig down
3025 *
3026 * Return: 0 for success and error number for failure
3027 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003028static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029{
3030 int ret;
3031
3032 cds_ssr_protect(__func__);
3033 ret = __hdd_stop(dev);
3034 cds_ssr_unprotect(__func__);
3035
3036 return ret;
3037}
3038
3039/**
3040 * __hdd_uninit() - HDD uninit function
3041 * @dev: Pointer to net_device structure
3042 *
3043 * This is called during the netdev unregister to uninitialize all data
3044 * associated with the device
3045 *
3046 * Return: None
3047 */
3048static void __hdd_uninit(struct net_device *dev)
3049{
Jeff Johnson9d295242017-08-29 14:39:48 -07003050 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003051 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003052
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003053 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003054
3055 do {
3056 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003057 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003058 break;
3059 }
3060
Jeff Johnson399c6272017-08-30 10:51:00 -07003061 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3062 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003063 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003064 break;
3065 }
3066
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003067 if (dev != adapter->dev)
3068 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003069
Jeff Johnson399c6272017-08-30 10:51:00 -07003070 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003071
3072 /* after uninit our adapter structure will no longer be valid */
3073 adapter->dev = NULL;
3074 adapter->magic = 0;
3075 } while (0);
3076
3077 EXIT();
3078}
3079
3080/**
3081 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3082 * @dev: pointer to net_device structure
3083 *
3084 * This is called during the netdev unregister to uninitialize all data
3085 * associated with the device
3086 *
3087 * Return: none
3088 */
3089static void hdd_uninit(struct net_device *dev)
3090{
3091 cds_ssr_protect(__func__);
3092 __hdd_uninit(dev);
3093 cds_ssr_unprotect(__func__);
3094}
3095
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003096static int hdd_open_cesium_nl_sock(void)
3097{
3098#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3099 struct netlink_kernel_cfg cfg = {
3100 .groups = WLAN_NLINK_MCAST_GRP_ID,
3101 .input = NULL
3102 };
3103#endif
3104 int ret = 0;
3105
3106#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3107 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3108#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3109 THIS_MODULE,
3110#endif
3111 &cfg);
3112#else
3113 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3114 WLAN_NLINK_MCAST_GRP_ID,
3115 NULL, NULL, THIS_MODULE);
3116#endif
3117
3118 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003119 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003120 ret = -ECONNREFUSED;
3121 }
3122
3123 return ret;
3124}
3125
3126static void hdd_close_cesium_nl_sock(void)
3127{
3128 if (NULL != cesium_nl_srv_sock) {
3129 netlink_kernel_release(cesium_nl_srv_sock);
3130 cesium_nl_srv_sock = NULL;
3131 }
3132}
3133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003134/**
3135 * __hdd_set_mac_address() - set the user specified mac address
3136 * @dev: Pointer to the net device.
3137 * @addr: Pointer to the sockaddr.
3138 *
3139 * This function sets the user specified mac address using
3140 * the command ifconfig wlanX hw ether <mac adress>.
3141 *
3142 * Return: 0 for success, non zero for failure
3143 */
3144static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3145{
Jeff Johnson9d295242017-08-29 14:39:48 -07003146 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003147 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303149 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150 int ret;
3151
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003152 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153
3154 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3155 ret = wlan_hdd_validate_context(hdd_ctx);
3156 if (0 != ret)
3157 return ret;
3158
Jeff Johnson1e851a12017-10-28 14:36:12 -07003159 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003160 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3161
3162 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303163 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164}
3165
3166/**
3167 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3168 * function from SSR
3169 * @dev: pointer to net_device structure
3170 * @addr: Pointer to the sockaddr
3171 *
3172 * This function sets the user specified mac address using
3173 * the command ifconfig wlanX hw ether <mac adress>.
3174 *
3175 * Return: 0 for success.
3176 */
3177static int hdd_set_mac_address(struct net_device *dev, void *addr)
3178{
3179 int ret;
3180
3181 cds_ssr_protect(__func__);
3182 ret = __hdd_set_mac_address(dev, addr);
3183 cds_ssr_unprotect(__func__);
3184
3185 return ret;
3186}
3187
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003188uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003189{
3190 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003191
Anurag Chouhan6d760662016-02-20 16:05:43 +05303192 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003193 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3194 break;
3195 }
3196
Anurag Chouhan6d760662016-02-20 16:05:43 +05303197 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198 return NULL;
3199
3200 hdd_ctx->config->intfAddrMask |= (1 << i);
3201 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3202}
3203
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003204void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3205 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206{
3207 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003208
Anurag Chouhan6d760662016-02-20 16:05:43 +05303209 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003210 if (!memcmp(releaseAddr,
3211 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3212 6)) {
3213 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3214 break;
3215 }
3216 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217}
3218
3219#ifdef WLAN_FEATURE_PACKET_FILTERING
3220/**
3221 * __hdd_set_multicast_list() - set the multicast address list
3222 * @dev: Pointer to the WLAN device.
3223 * @skb: Pointer to OS packet (sk_buff).
3224 *
3225 * This funciton sets the multicast address list.
3226 *
3227 * Return: None
3228 */
3229static void __hdd_set_multicast_list(struct net_device *dev)
3230{
Jeff Johnson9d295242017-08-29 14:39:48 -07003231 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003232 int i = 0, status;
3233 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003234 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303235 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3236 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3237 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003239 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303240 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303241 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303242
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303244 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303245 goto out;
3246
Dustin Brownc788acb2017-08-01 17:43:51 -07003247 status = hdd_validate_adapter(adapter);
3248 if (status)
3249 goto out;
3250
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303251 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3252 hdd_err("%s: Driver module is closed", __func__);
3253 return;
3254 }
3255
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303256 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3257 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003258 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303259 goto out;
3260 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303262 /* Delete already configured multicast address list */
3263 if (adapter->mc_addr_list.mc_cnt > 0) {
3264 hdd_info("clear previously configured MC address list");
3265 hdd_disable_and_flush_mc_addr_list(adapter,
3266 pmo_mc_list_change_notify);
3267 }
3268
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003270 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303271 hdd_disable_and_flush_mc_addr_list(adapter,
3272 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273 } else {
3274 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303275 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003276 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303277 pmo_ucfg_max_mc_addr_supported(psoc));
3278 hdd_disable_and_flush_mc_addr_list(adapter,
3279 pmo_mc_list_change_notify);
3280 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003282 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003283 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303284 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003285 if (i == mc_count)
3286 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303287 memset(&(mc_list_request->mc_addr[i].bytes),
3288 0, ETH_ALEN);
3289 memcpy(&(mc_list_request->mc_addr[i].bytes),
3290 ha->addr, ETH_ALEN);
3291 hdd_info("mlist[%d] = %pM", i,
3292 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003293 i++;
3294 }
3295 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303296
3297 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003298 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303299 mc_list_request->count = mc_count;
3300 status = hdd_cache_mc_addr_list(mc_list_request);
3301 if (status == 0) {
3302 hdd_enable_mc_addr_filtering(adapter,
3303 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003304 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303305 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003306 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303307out:
3308 if (mc_list_request)
3309 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303310 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003311}
3312
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303313
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003314/**
3315 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3316 * @dev: pointer to net_device
3317 *
3318 * Return: none
3319 */
3320static void hdd_set_multicast_list(struct net_device *dev)
3321{
3322 cds_ssr_protect(__func__);
3323 __hdd_set_multicast_list(dev);
3324 cds_ssr_unprotect(__func__);
3325}
3326#endif
3327
3328/**
3329 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3330 * @dev: Pointer to the WLAN device.
3331 * @skb: Pointer to OS packet (sk_buff).
3332 *
3333 * This function is registered with the Linux OS for network
3334 * core to decide which queue to use first.
3335 *
3336 * Return: ac, Queue Index/access category corresponding to UP in IP header
3337 */
3338static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3339#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3340 , void *accel_priv
3341#endif
3342#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3343 , select_queue_fallback_t fallback
3344#endif
3345)
3346{
3347 return hdd_wmm_select_queue(dev, skb);
3348}
3349
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003350static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003351 .ndo_open = hdd_open,
3352 .ndo_stop = hdd_stop,
3353 .ndo_uninit = hdd_uninit,
3354 .ndo_start_xmit = hdd_hard_start_xmit,
3355 .ndo_tx_timeout = hdd_tx_timeout,
3356 .ndo_get_stats = hdd_get_stats,
3357 .ndo_do_ioctl = hdd_ioctl,
3358 .ndo_set_mac_address = hdd_set_mac_address,
3359 .ndo_select_queue = hdd_select_queue,
3360#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003362#endif
3363};
3364
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003365/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003366static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003367 .ndo_open = hdd_mon_open,
3368 .ndo_stop = hdd_stop,
3369 .ndo_get_stats = hdd_get_stats,
3370};
3371
3372/**
3373 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003374 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003375 * Return: None
3376 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003377void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003379 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003380 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003381 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003382 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003383}
3384
3385/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003386 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3387 * @hdd_ctx: global hdd context
3388 * @macAddr: mac address to assign to the interface
3389 * @name: User-visible name of the interface
3390 *
3391 * hdd adapter pointer would point to the netdev->priv space, this function
3392 * would retrive the pointer, and setup the hdd adapter configuration.
3393 *
3394 * Return: the pointer to hdd adapter, otherwise NULL
3395 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003396static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003397 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003398 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003399 const char *name)
3400{
Jeff Johnson5505db82017-11-02 21:19:23 -07003401 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003402 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003403 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303404 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405 /*
3406 * cfg80211 initialization and registration....
3407 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003408 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003409#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3410 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003411#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003412 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3413 hdd_mon_mode_ether_setup : ether_setup),
3414 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003415
Jeff Johnson5505db82017-11-02 21:19:23 -07003416 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417
3418 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003419 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003420
Jeff Johnson9d295242017-08-29 14:39:48 -07003421 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003422 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303423 qdf_mem_set(sta_ctx->conn_info.staId,
3424 sizeof(sta_ctx->conn_info.staId),
3425 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003426 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003427 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003428 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003429 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303431 qdf_status = qdf_event_create(
3432 &adapter->qdf_session_open_event);
3433 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3434 hdd_err("Session open QDF event init failed!");
3435 free_netdev(adapter->dev);
3436 return NULL;
3437 }
3438
3439 qdf_status = qdf_event_create(
3440 &adapter->qdf_session_close_event);
3441 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3442 hdd_err("Session close QDF event init failed!");
3443 free_netdev(adapter->dev);
3444 return NULL;
3445 }
3446
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003447 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303448 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 init_completion(&adapter->linkup_event_var);
3450 init_completion(&adapter->cancel_rem_on_chan_var);
3451 init_completion(&adapter->rem_on_chan_ready_event);
3452 init_completion(&adapter->sta_authorized_event);
3453 init_completion(&adapter->offchannel_tx_event);
3454 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003455 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003456 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303457 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458
3459 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003460 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003462 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463
Jeff Johnson5505db82017-11-02 21:19:23 -07003464 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003466 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003467 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003468 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469
3470 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003471 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003473 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474
Jeff Johnson5505db82017-11-02 21:19:23 -07003475 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003476
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 hdd_set_station_ops(adapter->dev);
3478
Jeff Johnson5505db82017-11-02 21:19:23 -07003479 hdd_dev_setup_destructor(dev);
3480 dev->ieee80211_ptr = &adapter->wdev;
3481 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003482 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003483 adapter->wdev.netdev = dev;
3484 /* set dev's parent to underlying device */
3485 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003486 hdd_wmm_init(adapter);
3487 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303488 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489 }
3490
3491 return adapter;
3492}
3493
Jeff Johnson9d295242017-08-29 14:39:48 -07003494static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003495{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003496 struct net_device *dev = adapter->dev;
3497 int ret;
3498
3499 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003501 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003502 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3503
3504 ret = dev_alloc_name(dev, dev->name);
3505 if (ret < 0) {
3506 hdd_err(
3507 "unable to get dev name: %s, err = 0x%x",
3508 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303509 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003510 }
3511 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003512
3513 ret = register_netdevice(dev);
3514 if (ret) {
3515 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3516 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303517 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 }
3519 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003520 ret = register_netdev(dev);
3521 if (ret) {
3522 hdd_err("register_netdev(%s) failed, err = 0x%x",
3523 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303524 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003525 }
3526 }
3527 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3528
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003529 EXIT();
3530
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303531 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003532}
3533
Krunal Sonib51eec72017-11-20 21:53:01 -08003534QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003535{
Krunal Sonib51eec72017-11-20 21:53:01 -08003536 struct hdd_adapter *adapter;
3537 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538
Krunal Sonib51eec72017-11-20 21:53:01 -08003539 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3540 if (!hdd_ctx) {
3541 hdd_err("Invalid HDD_CTX");
3542 return QDF_STATUS_E_FAILURE;
3543 }
3544
3545 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3546 if (NULL == adapter) {
3547 hdd_err("NULL adapter");
3548 return QDF_STATUS_E_INVAL;
3549 }
3550 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303551 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003552 hdd_debug("session %d opened", adapter->session_id);
3553
3554 return QDF_STATUS_SUCCESS;
3555}
3556
3557QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3558{
3559 struct hdd_adapter *adapter;
3560 struct hdd_context *hdd_ctx;
3561
3562 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3563 if (!hdd_ctx) {
3564 hdd_err("Invalid HDD_CTX");
3565 return QDF_STATUS_E_FAILURE;
3566 }
3567
3568 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003569 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003570 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303571 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003572 }
3573
3574 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003575 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303576 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003577 }
3578
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003579 /*
3580 * For NAN Data interface, the close session results in the final
3581 * indication to the userspace
3582 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003583 if (adapter->device_mode == QDF_NDI_MODE)
3584 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003585
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003586 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3587
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588 /*
3589 * We can be blocked while waiting for scheduled work to be
3590 * flushed, and the adapter structure can potentially be freed, in
3591 * which case the magic will have been reset. So make sure the
3592 * magic is still good, and hence the adapter structure is still
3593 * valid, before signaling completion
3594 */
3595 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303596 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003597
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303598 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599}
3600
Jeff Johnson9d295242017-08-29 14:39:48 -07003601int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602{
Dustin Brownd28772b2017-03-17 14:16:07 -07003603 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604
Dustin Brownd28772b2017-03-17 14:16:07 -07003605 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003606 if (QDF_IS_STATUS_ERROR(status))
3607 return qdf_status_to_os_return(status);
3608
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003609 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003610 if (QDF_IS_STATUS_ERROR(status))
3611 return qdf_status_to_os_return(status);
3612
3613 if (wma_capability_enhanced_mcast_filter())
3614 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3615 else
3616 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003617
3618 return qdf_status_to_os_return(status);
3619}
3620
Jeff Johnson9d295242017-08-29 14:39:48 -07003621int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003622{
3623 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003624 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003625 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003626 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003627
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003628 vdev_id = adapter->session_id;
3629 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003630
3631 /* vdev created sanity check */
3632 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003633 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003634 return -EINVAL;
3635 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003636 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003637
Dustin Brownd28772b2017-03-17 14:16:07 -07003638 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303639 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003640 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003641 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003642 if (QDF_IS_STATUS_ERROR(status)) {
3643 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003644 errno = qdf_status_to_os_return(status);
3645 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003646 }
3647
3648 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303649 status = qdf_wait_for_event_completion(
3650 &adapter->qdf_session_close_event,
3651 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3652 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003653 if (adapter->device_mode == QDF_NDI_MODE)
3654 hdd_ndp_session_end_handler(adapter);
3655 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303656 adapter->session_id = HDD_SESSION_ID_INVALID;
3657 if (QDF_STATUS_E_TIMEOUT != status) {
3658 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003659 errno = -ETIMEDOUT;
3660 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303661 } else if (adapter->qdf_session_close_event.force_set) {
3662 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003663 errno = -EINVAL;
3664 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303665 } else {
3666 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003667 errno = -EINVAL;
3668 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303669 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003670 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003671
Yue Maf9782842017-05-08 12:49:49 -07003672release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003673 /*
3674 * In SSR or driver unloading case, directly exit may cause objects
3675 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003676 */
Frank Liuc66d4bf2018-01-26 16:18:18 +08003677 if (errno && !(cds_is_driver_recovering() || cds_is_driver_unloading()))
Jiachao Wu2c42c222018-01-15 18:13:19 +08003678 return errno;
3679
Sandeep Puligillaef415362017-08-30 16:37:13 -07003680 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003681 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003682 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003683 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003684 return errno;
3685 }
3686
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003687 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003688
3689 return 0;
3690}
3691
Krunal Sonib51eec72017-11-20 21:53:01 -08003692static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3693 struct sme_session_params *session_param,
3694 csr_roam_completeCallback callback,
3695 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003696{
Dustin Brownd28772b2017-03-17 14:16:07 -07003697 uint32_t type;
3698 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003699 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003700
3701 /* determine vdev (sub)type */
3702 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303703 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003704 hdd_err("failed to get vdev type: %d", status);
3705 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003707 session_param->sme_session_id = adapter->session_id;
3708 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3709 session_param->type_of_persona = type;
3710 session_param->subtype_of_persona = sub_type;
3711 session_param->session_open_cb = hdd_sme_open_session_callback;
3712 session_param->session_close_cb = hdd_sme_close_session_callback;
3713 session_param->callback = callback;
3714 session_param->callback_ctx = callback_ctx;
3715
3716 return 0;
3717}
3718
3719int hdd_vdev_create(struct hdd_adapter *adapter,
3720 csr_roam_completeCallback callback, void *ctx)
3721{
3722 QDF_STATUS status;
3723 int errno;
3724 struct hdd_context *hdd_ctx;
3725 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003726
3727 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003728
3729 /* do vdev create via objmgr */
3730 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003731 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003732 if (errno) {
3733 hdd_err("failed to create objmgr vdev: %d", errno);
3734 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003735 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003736
3737 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303738 status = qdf_event_reset(&adapter->qdf_session_open_event);
3739 if (QDF_STATUS_SUCCESS != status) {
3740 hdd_err("failed to reinit session open event");
3741 return -EINVAL;
3742 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003743 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3744 callback, ctx);
3745 if (errno) {
3746 hdd_err("failed to populating SME params");
3747 goto objmgr_vdev_destroy_procedure;
3748 }
3749
3750 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003751 if (QDF_IS_STATUS_ERROR(status)) {
3752 hdd_err("failed to open sme session: %d", status);
3753 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003754 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003755 }
3756
3757 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303758 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3759 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3760 if (QDF_STATUS_SUCCESS != status) {
3761 if (adapter->qdf_session_open_event.force_set) {
3762 /*
3763 * SSR/PDR has caused shutdown, which has forcefully
3764 * set the event. Return without the closing session.
3765 */
3766 adapter->session_id = HDD_SESSION_ID_INVALID;
3767 hdd_err("Session open event forcefully set");
3768 return -EINVAL;
3769 } else {
3770 if (QDF_STATUS_E_TIMEOUT == status)
3771 hdd_err("Session failed to open within timeout period");
3772 else
3773 hdd_err("Failed to wait for session open event(status-%d)",
3774 status);
3775 errno = -ETIMEDOUT;
3776 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3777 goto hdd_vdev_destroy_procedure;
3778 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003779 }
3780
3781 /* firmware ready for component communication, raise vdev_ready event */
3782 errno = hdd_vdev_ready(adapter);
3783 if (errno) {
3784 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003785 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003786 }
3787
Jeff Johnson1b780e42017-10-31 14:11:45 -07003788 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003789
3790 return 0;
3791
3792 /*
3793 * Due to legacy constraints, we need to destroy in the same order as
3794 * create. So, split error handling into 2 cases to accommodate.
3795 */
3796
Krunal Soni4a020c72017-10-30 20:58:40 -07003797objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003798 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003799
3800 return errno;
3801
Krunal Soni4a020c72017-10-30 20:58:40 -07003802hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003803 QDF_BUG(!hdd_vdev_destroy(adapter));
3804
3805 return errno;
3806}
3807
Jeff Johnson9d295242017-08-29 14:39:48 -07003808QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003809{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003810 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003811 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003812 QDF_STATUS status;
3813 int ret_val;
3814
Dustin Brownd28772b2017-03-17 14:16:07 -07003815 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3816 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3817 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003818 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003819
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003820 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003821 status = hdd_register_wext(adapter->dev);
3822 if (QDF_IS_STATUS_ERROR(status)) {
3823 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003824 goto error_register_wext;
3825 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003826 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003827
Himanshu Agarwalb229a142017-12-21 10:16:45 +05303828 hdd_debug("Disabling Green AP");
3829 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev, false);
3830 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
3831
Jeff Johnsond377dce2017-10-04 10:32:42 -07003832 qdf_mem_set(sta_ctx->conn_info.staId,
3833 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303834
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003835 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003836 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303837 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003838 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003839 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003840 hdd_ctx->config->OperatingChannel;
3841
3842 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003843 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844
3845 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303846 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003847 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003848 status, status);
3849 goto error_init_txrx;
3850 }
3851
3852 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3853
3854 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303855 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003856 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857 status, status);
3858 goto error_wmm_init;
3859 }
3860
3861 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3862
Jeff Johnson1b780e42017-10-31 14:11:45 -07003863 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003864 WMI_PDEV_PARAM_BURST_ENABLE,
3865 hdd_ctx->config->enableSifsBurst,
3866 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003867 if (ret_val)
3868 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303870 /*
3871 * In case of USB tethering, LRO is disabled. If SSR happened
3872 * during that time, then as part of SSR init, do not enable
3873 * the LRO again. Keep the LRO state same as before SSR.
3874 */
3875 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003876 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303877
3878 /* rcpi info initialization */
3879 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3880
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303881 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003882
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883error_wmm_init:
3884 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3885 hdd_deinit_tx_rx(adapter);
3886error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003887 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003888error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003889 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003890
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891 return status;
3892}
3893
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303894/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003895 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303896 * @hdd_ctx: global hdd context
3897 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003898 * @rtnl_held: Used to indicate whether or not the caller is holding
3899 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303900 *
3901 * This function De-initializes the STA/P2P/OCB adapter.
3902 *
3903 * Return: None.
3904 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003905static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003906 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003907 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303908{
3909 ENTER_DEV(adapter->dev);
3910
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303911 if (adapter->dev) {
3912 if (rtnl_held)
3913 adapter->dev->wireless_handlers = NULL;
3914 else {
3915 rtnl_lock();
3916 adapter->dev->wireless_handlers = NULL;
3917 rtnl_unlock();
3918 }
3919 }
3920
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303921 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3922 hdd_deinit_tx_rx(adapter);
3923 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3924 }
3925
3926 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3927 hdd_wmm_adapter_close(adapter);
3928 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3929 }
3930
Krunal Sonib51eec72017-11-20 21:53:01 -08003931
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303932 EXIT();
3933}
3934
Krunal Sonib51eec72017-11-20 21:53:01 -08003935void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3936 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 bool rtnl_held)
3938{
3939 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303940
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003941 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003942 case QDF_STA_MODE:
3943 case QDF_P2P_CLIENT_MODE:
3944 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003945 case QDF_IBSS_MODE:
3946 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003948 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 break;
3950 }
3951
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003952 case QDF_SAP_MODE:
3953 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003955 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 break;
3957 }
3958
3959 default:
3960 break;
3961 }
3962
3963 EXIT();
3964}
3965
Jeff Johnson9d295242017-08-29 14:39:48 -07003966static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003967 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968{
Jeff Johnson5505db82017-11-02 21:19:23 -07003969 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970
3971 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003972 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003973 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003974 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 return;
3976 }
3977
Rajeev Kumardca5f812016-02-04 17:28:06 -08003978 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303979
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 /*
3981 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3982 * the driver is almost closed and cannot handle either control
3983 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003984 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3985 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986 * is not right. Setting this flag helps hdd_stop() to recognize that
3987 * the interface is closed and restricts any operations on that
3988 */
3989 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3990
3991 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003992 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003993 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003994 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003995 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 /*
3997 * Note that the adapter is no longer valid at this point
3998 * since the memory has been reclaimed
3999 */
4000 }
4001}
4002
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004003static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004004 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005{
Jeff Johnson9d295242017-08-29 14:39:48 -07004006 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004007
Dustin Brown920397d2017-12-13 16:27:50 -08004008 hdd_for_each_adapter(hdd_ctx, adapter) {
4009 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4010 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304011 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 }
Dustin Brown920397d2017-12-13 16:27:50 -08004014
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304015 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004017
Arun Khandavalli2358d522016-05-16 18:05:37 +05304018#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4019/**
4020 * hdd_set_fw_log_params() - Set log parameters to FW
4021 * @hdd_ctx: HDD Context
4022 * @adapter: HDD Adapter
4023 *
4024 * This function set the FW Debug log level based on the INI.
4025 *
4026 * Return: None
4027 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004028static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004029 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304030{
4031 uint8_t count = 0, numentries = 0,
4032 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4033 uint32_t value = 0;
4034 int ret;
4035
Arun Khandavallifae92942016-08-01 13:31:08 +05304036 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4037 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004038 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304039 return;
4040 }
4041
Arun Khandavallifae92942016-08-01 13:31:08 +05304042 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304043 hdd_ctx->fw_log_settings.dl_type =
4044 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004045 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304046 WMI_DBGLOG_TYPE,
4047 hdd_ctx->config->enableFwLogType,
4048 DBG_CMD);
4049 if (ret != 0)
4050 hdd_err("Failed to enable FW log type ret %d",
4051 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304052
4053 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304054 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004055 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304056 WMI_DBGLOG_LOG_LEVEL,
4057 hdd_ctx->config->enableFwLogLevel,
4058 DBG_CMD);
4059 if (ret != 0)
4060 hdd_err("Failed to enable FW log level ret %d",
4061 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304062
4063 hdd_string_to_u8_array(
4064 hdd_ctx->config->enableFwModuleLogLevel,
4065 moduleloglevel,
4066 &numentries,
4067 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4068
4069 while (count < numentries) {
4070 /*
4071 * FW module log level input string looks like
4072 * below:
4073 * gFwDebugModuleLoglevel=<FW Module ID>,
4074 * <Log Level>,...
4075 * For example:
4076 * gFwDebugModuleLoglevel=
4077 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4078 * Above input string means :
4079 * For FW module ID 1 enable log level 0
4080 * For FW module ID 2 enable log level 1
4081 * For FW module ID 3 enable log level 2
4082 * For FW module ID 4 enable log level 3
4083 * For FW module ID 5 enable log level 4
4084 * For FW module ID 6 enable log level 5
4085 * For FW module ID 7 enable log level 6
4086 */
4087
Nishank Aggarwale239d962017-03-03 12:26:02 +05304088 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4089 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4090 hdd_err("Module id %d and dbglog level %d input length is more than max",
4091 moduleloglevel[count],
4092 moduleloglevel[count + 1]);
4093 return;
4094 }
4095
4096 value = moduleloglevel[count] << 16;
4097 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004098 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304099 WMI_DBGLOG_MOD_LOG_LEVEL,
4100 value, DBG_CMD);
4101 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304102 hdd_err("Failed to enable FW module log level %d ret %d",
4103 value, ret);
4104
4105 count += 2;
4106 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304107
Arun Khandavalli2358d522016-05-16 18:05:37 +05304108}
4109#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004110static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004111 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304112{
4113}
4114
4115#endif
4116
4117/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004118 * hdd_configure_chain_mask() - programs chain mask to firmware
4119 * @adapter: HDD adapter
4120 *
4121 * Return: 0 on success or errno on failure
4122 */
4123static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4124{
4125 int ret_val;
4126 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4127
4128 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4129 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4130 hdd_ctx->config->txchainmask1x1,
4131 hdd_ctx->config->rxchainmask1x1);
4132 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4133 hdd_ctx->config->dual_mac_feature_disable,
4134 hdd_ctx->config->tx_chain_mask_2g,
4135 hdd_ctx->config->rx_chain_mask_2g);
4136 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4137 hdd_ctx->config->tx_chain_mask_5g,
4138 hdd_ctx->config->rx_chain_mask_5g);
4139
4140 if (hdd_ctx->config->enable2x2) {
4141 hdd_info("2x2 enabled. skip chain mask programming");
4142 return 0;
4143 }
4144
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004145 if (hdd_ctx->config->dual_mac_feature_disable !=
4146 DISABLE_DBS_CXN_AND_SCAN) {
4147 hdd_info("DBS enabled(%d). skip chain mask programming",
4148 hdd_ctx->config->dual_mac_feature_disable);
4149 return 0;
4150 }
4151
Naveen Rawatdacb5032018-02-08 15:23:24 -08004152 if (hdd_ctx->lte_coex_ant_share) {
4153 hdd_info("lte ant sharing enabled. skip chainmask programming");
4154 return 0;
4155 }
4156
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004157 if (hdd_ctx->config->txchainmask1x1) {
4158 ret_val = sme_cli_set_command(adapter->session_id,
4159 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4160 hdd_ctx->config->txchainmask1x1,
4161 PDEV_CMD);
4162 if (ret_val)
4163 goto error;
4164 }
4165
4166 if (hdd_ctx->config->rxchainmask1x1) {
4167 ret_val = sme_cli_set_command(adapter->session_id,
4168 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4169 hdd_ctx->config->rxchainmask1x1,
4170 PDEV_CMD);
4171 if (ret_val)
4172 goto error;
4173 }
4174
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004175 if (hdd_ctx->config->txchainmask1x1 ||
4176 hdd_ctx->config->rxchainmask1x1) {
4177 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4178 return 0;
4179 }
4180
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004181 if (hdd_ctx->config->tx_chain_mask_2g) {
4182 ret_val = sme_cli_set_command(adapter->session_id,
4183 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4184 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4185 if (0 != ret_val)
4186 goto error;
4187 }
4188
4189 if (hdd_ctx->config->rx_chain_mask_2g) {
4190 ret_val = sme_cli_set_command(adapter->session_id,
4191 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4192 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4193 if (0 != ret_val)
4194 goto error;
4195 }
4196
4197 if (hdd_ctx->config->tx_chain_mask_5g) {
4198 ret_val = sme_cli_set_command(adapter->session_id,
4199 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4200 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4201 if (0 != ret_val)
4202 goto error;
4203 }
4204
4205 if (hdd_ctx->config->rx_chain_mask_5g) {
4206 ret_val = sme_cli_set_command(adapter->session_id,
4207 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4208 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4209 if (0 != ret_val)
4210 goto error;
4211 }
4212
4213 return 0;
4214
4215error:
4216 hdd_err("WMI PDEV set param failed %d", ret_val);
4217 return -EINVAL;
4218}
4219
4220/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304221 * hdd_set_fw_params() - Set parameters to firmware
4222 * @adapter: HDD adapter
4223 *
4224 * This function Sets various parameters to fw once the
4225 * adapter is started.
4226 *
4227 * Return: 0 on success or errno on failure
4228 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004229int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304230{
4231 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004232 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304233
4234 ENTER_DEV(adapter->dev);
4235
4236 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4237 if (!hdd_ctx)
4238 return -EINVAL;
4239
Dustin Brown732ab9c2017-06-15 13:24:09 -07004240 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4241 hdd_debug("FTM Mode is active; nothing to do");
4242 return 0;
4243 }
4244
Jeff Johnson1b780e42017-10-31 14:11:45 -07004245 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304246 WMI_PDEV_PARAM_DTIM_SYNTH,
4247 hdd_ctx->config->enable_lprx, PDEV_CMD);
4248 if (ret) {
4249 hdd_err("Failed to set LPRx");
4250 goto error;
4251 }
4252
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304253 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004254 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304255 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4256 hdd_ctx->config->upper_brssi_thresh);
4257
Jeff Johnson1b780e42017-10-31 14:11:45 -07004258 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304259 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4260 hdd_ctx->config->lower_brssi_thresh);
4261
Jeff Johnson1b780e42017-10-31 14:11:45 -07004262 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304263 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4264 hdd_ctx->config->enable_dtim_1chrx);
4265 }
4266
Dustin Brown732ab9c2017-06-15 13:24:09 -07004267 if (hdd_ctx->config->enable2x2) {
4268 hdd_debug("configuring 2x2 mode fw params");
4269
Jeff Johnson1b780e42017-10-31 14:11:45 -07004270 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004271 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4272 hdd_ctx->config->enable_cck_tx_fir_override,
4273 PDEV_CMD);
4274 if (ret) {
4275 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4276 ret);
4277 goto error;
4278 }
4279 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304280#define HDD_DTIM_1CHAIN_RX_ID 0x5
4281#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004282 hdd_debug("configuring 1x1 mode fw params");
4283
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004284 /*
4285 * Disable DTIM 1 chain Rx when in 1x1,
4286 * we are passing two value
4287 * as param_id << 29 | param_value.
4288 * Below param_value = 0(disable)
4289 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004290 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004291 WMI_STA_SMPS_PARAM_CMDID,
4292 HDD_DTIM_1CHAIN_RX_ID <<
4293 HDD_SMPS_PARAM_VALUE_S,
4294 VDEV_CMD);
4295 if (ret) {
4296 hdd_err("DTIM 1 chain set failed %d", ret);
4297 goto error;
4298 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304299
Arun Khandavalli2358d522016-05-16 18:05:37 +05304300#undef HDD_DTIM_1CHAIN_RX_ID
4301#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004302
4303 if (hdd_configure_chain_mask(adapter))
4304 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004305 }
4306
Jeff Johnson1b780e42017-10-31 14:11:45 -07004307 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004308 WMI_PDEV_PARAM_HYST_EN,
4309 hdd_ctx->config->enableMemDeepSleep,
4310 PDEV_CMD);
4311 if (ret) {
4312 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4313 goto error;
4314 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304315
Jeff Johnson1b780e42017-10-31 14:11:45 -07004316 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004317 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4318 hdd_ctx->config->rts_profile,
4319 VDEV_CMD);
4320 if (ret) {
4321 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4322 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304323 }
4324
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004325 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4326
Jeff Johnson1b780e42017-10-31 14:11:45 -07004327 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004328 GEN_VDEV_PARAM_AMSDU,
4329 hdd_ctx->config->max_amsdu_num,
4330 GEN_CMD);
4331 if (ret != 0) {
4332 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4333 goto error;
4334 }
4335
Arun Khandavalli2358d522016-05-16 18:05:37 +05304336 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304337 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004338
Arun Khandavalli2358d522016-05-16 18:05:37 +05304339 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304340
Arun Khandavalli2358d522016-05-16 18:05:37 +05304341error:
4342 return -EINVAL;
4343}
4344
Ryan Hsu07495ea2016-01-21 15:25:39 -08004345/**
4346 * hdd_open_adapter() - open and setup the hdd adatper
4347 * @hdd_ctx: global hdd context
4348 * @session_type: type of the interface to be created
4349 * @iface_name: User-visible name of the interface
4350 * @macAddr: MAC address to assign to the interface
4351 * @name_assign_type: the name of assign type of the netdev
4352 * @rtnl_held: the rtnl lock hold flag
4353 *
4354 * This function open and setup the hdd adpater according to the device
4355 * type request, assign the name, the mac address assigned, and then prepared
4356 * the hdd related parameters, queue, lock and ready to start.
4357 *
4358 * Return: the pointer of hdd adapter, otherwise NULL.
4359 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004360struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004361 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004362 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004363 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364{
Jeff Johnson9d295242017-08-29 14:39:48 -07004365 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304366 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367
4368 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4369 /*
4370 * Max limit reached on the number of vdevs configured by the
4371 * host. Return error
4372 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304373 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4374 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375 return NULL;
4376 }
4377
4378 if (macAddr == NULL) {
4379 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304380 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 return NULL;
4382 }
4383 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304384 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304385 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4386 " already exists",
4387 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004388 return NULL;
4389 }
4390
4391 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004392 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393 /* Reset locally administered bit if the device mode is STA */
4394 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304395 hdd_info("locally administered bit reset in sta mode: "
4396 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004397 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004398 case QDF_P2P_CLIENT_MODE:
4399 case QDF_P2P_DEVICE_MODE:
4400 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004401 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304402 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004403 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4404 name_assign_type,
4405 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004406
4407 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304408 hdd_err("failed to allocate adapter for session %d",
4409 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410 return NULL;
4411 }
4412
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004413 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004414 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004415 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304417 else if (QDF_MONITOR_MODE == session_type)
4418 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004419 else
4420 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4421
4422 adapter->device_mode = session_type;
4423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425 /*
4426 * Workqueue which gets scheduled in IPv4 notification
4427 * callback
4428 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004429 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004430 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431
4432#ifdef WLAN_NS_OFFLOAD
4433 /*
4434 * Workqueue which gets scheduled in IPv6
4435 * notification callback.
4436 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004437 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438 hdd_ipv6_notifier_work_queue);
4439#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004440 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004441 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004442 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443
4444 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004445 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304447 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4448 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304449
Ravi Joshi1a292562017-05-18 16:28:54 -07004450 /* Initialize NAN Data Interface */
4451 if (QDF_NDI_MODE == session_type) {
4452 status = hdd_init_nan_data_mode(adapter);
4453 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004454 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004455 }
4456
4457 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004459 case QDF_P2P_GO_MODE:
4460 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004461 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4462 name_assign_type,
4463 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004465 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304466 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004467 return NULL;
4468 }
4469
4470 adapter->wdev.iftype =
4471 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004472 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004473 NL80211_IFTYPE_P2P_GO;
4474 adapter->device_mode = session_type;
4475
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004476 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004477 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004478 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004479
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004480 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304482 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4483 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304484
4485 /*
4486 * Workqueue which gets scheduled in IPv4 notification
4487 * callback
4488 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004489 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304490 hdd_ipv4_notifier_work_queue);
4491
4492#ifdef WLAN_NS_OFFLOAD
4493 /*
4494 * Workqueue which gets scheduled in IPv6
4495 * notification callback.
4496 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004497 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304498 hdd_ipv6_notifier_work_queue);
4499#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304501 case QDF_FTM_MODE:
4502 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4503 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004504 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304505 if (NULL == adapter) {
4506 hdd_err("Failed to allocate adapter for FTM mode");
4507 return NULL;
4508 }
4509 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4510 adapter->device_mode = session_type;
4511 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004512 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004513 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004514
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304515 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004516 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304517 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304518 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4519 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304520 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004521 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004522 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304523 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004524 return NULL;
4525 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004526
hqueaa33ee2017-05-04 17:56:35 +08004527 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4528
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304529 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004530 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004531 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004532 }
4533
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304534 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004535 if (NULL != adapter) {
4536 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4537 adapter = NULL;
4538 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004539
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004540 return NULL;
4541 }
4542
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304543 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004544 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4545 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004546
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004547 /* Adapter successfully added. Increment the vdev count */
4548 hdd_ctx->current_intf_count++;
4549
Jeff Johnson5880d792016-08-15 13:32:30 -07004550 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004551 hdd_ctx->current_intf_count);
4552
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004553 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004554 }
4555
Rajeev Kumardca5f812016-02-04 17:28:06 -08004556 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004557 hdd_err("Interface %s wow debug_fs init failed",
4558 netdev_name(adapter->dev));
4559
4560 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4561 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004562
4563 return adapter;
4564
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004565err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004566 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304567 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568
4569 return NULL;
4570}
4571
Jeff Johnson9d295242017-08-29 14:39:48 -07004572QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004573 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574{
Dustin Brown920397d2017-12-13 16:27:50 -08004575 /*
4576 * Here we are stopping global bus_bw timer & work per adapter.
4577 *
4578 * The reason is to fix one race condition between
4579 * bus bandwidth work and cleaning up an adapter.
4580 * Under some conditions, it is possible for the bus bandwidth
4581 * work to access a particularly destroyed adapter, leading to
4582 * use-after-free.
4583 */
4584 hdd_debug("wait for bus bw work to flush");
4585 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4586 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004587
Dustin Brown920397d2017-12-13 16:27:50 -08004588 /* cleanup adapter */
4589 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4590 adapter->device_mode);
4591 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4592 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004593
Dustin Brown920397d2017-12-13 16:27:50 -08004594 /* conditionally restart the bw timer */
4595 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004596
Dustin Brown920397d2017-12-13 16:27:50 -08004597 /* Adapter removed. Decrement vdev count */
4598 if (hdd_ctx->current_intf_count != 0)
4599 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004600
Dustin Brown920397d2017-12-13 16:27:50 -08004601 /* Fw will take care incase of concurrency */
4602 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004603}
4604
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004605/**
4606 * hdd_close_all_adapters - Close all open adapters
4607 * @hdd_ctx: Hdd context
4608 * rtnl_held: True if RTNL lock held
4609 *
4610 * Close all open adapters.
4611 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304612 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004613 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004614QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004615{
Dustin Brown920397d2017-12-13 16:27:50 -08004616 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304617 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618
4619 ENTER();
4620
4621 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004622 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4623 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304624 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004625 adapter->mac_addr.bytes);
4626 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4627
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304628 /* Adapter removed. Decrement vdev count */
4629 if (hdd_ctx->current_intf_count != 0)
4630 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004631 }
Dustin Brown920397d2017-12-13 16:27:50 -08004632 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004633
4634 EXIT();
4635
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304636 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004637}
4638
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004639void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004640{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304641 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004642 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004643
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004644 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004645 case QDF_STA_MODE:
4646 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004647 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004648 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004649 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004650 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651 break;
4652 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004653 case QDF_SAP_MODE:
4654 case QDF_P2P_GO_MODE:
4655 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004656 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004657 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004658 break;
4659 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004660 case QDF_FTM_MODE:
4661 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 default:
4663 /*
4664 * wlan_hdd_reset_prob_rspies should not have been called
4665 * for these kind of devices
4666 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004667 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004668 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004669 return;
4670 }
4671
Anurag Chouhanc5548422016-02-24 18:33:27 +05304672 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004673 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004674 updateIE.ieBufferlength = 0;
4675 updateIE.pAdditionIEBuffer = NULL;
4676 updateIE.append = true;
4677 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004678 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004679 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304680 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004681 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004682 }
4683}
4684
Dustin Browndb2a8be2017-12-20 11:49:56 -08004685QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4686 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004687{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304688 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004689 struct hdd_wext_state *pWextState =
4690 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004691 union iwreq_data wrqu;
4692 tSirUpdateIE updateIE;
4693 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304694 tsap_Config_t *sap_config;
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304695 bool is_enabled = false;
4696 uint8_t ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004697
4698 ENTER();
4699
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004700 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304701 wlan_hdd_netif_queue_control(adapter,
4702 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4703 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004704 /*
4705 * if this is the last active connection check & stop the
4706 * opportunistic timer first
4707 */
4708 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4709 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4710 policy_mgr_convert_device_mode_to_qdf_type(
4711 adapter->device_mode), NULL) == 1)) ||
4712 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4713 policy_mgr_check_and_stop_opportunistic_timer(
4714 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004715 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004716 case QDF_STA_MODE:
4717 case QDF_P2P_CLIENT_MODE:
4718 case QDF_IBSS_MODE:
4719 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004720 case QDF_NDI_MODE:
4721 if ((QDF_NDI_MODE == adapter->device_mode) ||
4722 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004723 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4724 hdd_is_connecting(
4725 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004726 INIT_COMPLETION(adapter->disconnect_comp_var);
4727 /*
4728 * For NDI do not use pWextState from sta_ctx, if needed
4729 * extract from ndi_ctx.
4730 */
4731 if (QDF_NDI_MODE == adapter->device_mode)
4732 qdf_ret_status = sme_roam_disconnect(
4733 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004734 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004735 eCSR_DISCONNECT_REASON_NDI_DELETE);
4736 else if (pWextState->roamProfile.BSSType ==
4737 eCSR_BSS_TYPE_START_IBSS)
4738 qdf_ret_status = sme_roam_disconnect(
4739 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004740 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004741 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004742 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004743 qdf_ret_status =
4744 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004745 hdd_debug("Send disconnected event to userspace");
4746 wlan_hdd_cfg80211_indicate_disconnect(
4747 adapter->dev, true,
4748 WLAN_REASON_UNSPECIFIED);
4749 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004750 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004751 qdf_ret_status = sme_roam_disconnect(
4752 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004753 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004754 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004755 /* success implies disconnect command got
4756 * queued up successfully
4757 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004758 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4759 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004760 rc = wait_for_completion_timeout(
4761 &adapter->disconnect_comp_var,
4762 msecs_to_jiffies
4763 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004764 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004765 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004767 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4768 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769 memset(&wrqu, '\0', sizeof(wrqu));
4770 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4771 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4772 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4773 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304774 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004775 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004776
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304777 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304778 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004779
4780#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004781 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004782#endif
4783
4784 hdd_deregister_tx_flow_control(adapter);
4785
4786#ifdef WLAN_NS_OFFLOAD
4787#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004788 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004789#endif
4790#endif
4791
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304792 if (adapter->device_mode == QDF_STA_MODE)
4793 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4794 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004795
4796 if (wlan_hdd_try_disconnect(adapter)) {
4797 hdd_err("Error: Can't disconnect adapter");
4798 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004799 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004800
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304801 ret = hdd_check_green_ap_enable(hdd_ctx, &is_enabled);
4802 if (!ret) {
4803 hdd_debug("Green AP enable status: %d", is_enabled);
4804 if (is_enabled) {
4805 hdd_debug("Enabling Green AP");
4806 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
4807 true);
4808 wlan_green_ap_start(hdd_ctx->hdd_pdev);
4809 }
4810 } else {
4811 hdd_err("Failed to check if Green AP should be enabled or not");
4812 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004813
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304814 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004815 break;
4816
Rajeev Kumar3b906202018-02-01 10:55:14 -08004817 case QDF_MONITOR_MODE:
4818 wlan_hdd_scan_abort(adapter);
4819 hdd_deregister_tx_flow_control(adapter);
4820 hdd_vdev_destroy(adapter);
4821 break;
4822
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004823 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004824 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304825 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304826 sap_config = &adapter->session.ap.sap_config;
4827 if (sap_config)
4828 wlansap_reset_sap_config_add_ie(sap_config,
4829 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304830 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004831 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004832
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004833 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004834 if (QDF_SAP_MODE == adapter->device_mode) {
4835 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4836 cds_flush_delayed_work(
4837 &adapter->acs_pending_work);
4838 clear_bit(ACS_PENDING, &adapter->event_flags);
4839 }
4840 }
Krunal Soni22208392017-09-29 18:10:34 -07004841 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004842
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004843 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004844 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004845 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4847
4848 hdd_deregister_tx_flow_control(adapter);
4849
Kapil Guptac1224bf2017-06-22 21:22:40 +05304850 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004851 mutex_lock(&hdd_ctx->sap_lock);
4852 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304853 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304854 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004855
4856 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857 status = wlansap_stop_bss(
4858 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004859
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304860 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004861 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004862 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304863 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304864 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304865 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304866 qdf_wait_for_event_completion(
4867 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004868 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004869
Anurag Chouhance0dc992016-02-16 18:18:03 +05304870 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004871 hdd_err("failure waiting for wlansap_stop_bss %d",
4872 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873 }
4874 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004875 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004876 }
4877 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004878 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4879 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004880 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004881
Anurag Chouhanc5548422016-02-24 18:33:27 +05304882 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004883 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004884 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 updateIE.ieBufferlength = 0;
4886 updateIE.pAdditionIEBuffer = NULL;
4887 updateIE.append = false;
4888 updateIE.notify = false;
4889 /* Probe bcn reset */
4890 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4891 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304892 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004893 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004894 }
4895 /* Assoc resp reset */
4896 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4897 &updateIE,
4898 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304899 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004900 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004901 }
4902 /* Reset WNI_CFG_PROBE_RSP Flags */
4903 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004904 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004905 qdf_mem_free(adapter->session.ap.beacon);
4906 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304907 /*
4908 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4909 */
4910 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4911 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4912
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304913#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004914 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304915#endif
4916
4917#ifdef WLAN_NS_OFFLOAD
4918#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004919 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304920#endif
4921#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08004922
4923 hdd_vdev_destroy(adapter);
4924
Krunal Sonib51eec72017-11-20 21:53:01 -08004925 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004926 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004927 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004928 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004929 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004930 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08004931 hdd_deregister_tx_flow_control(adapter);
4932 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004933 break;
4934 default:
4935 break;
4936 }
4937
Dustin Brown04348372017-12-14 16:13:39 -08004938 if (adapter->scan_info.default_scan_ies) {
4939 qdf_mem_free(adapter->scan_info.default_scan_ies);
4940 adapter->scan_info.default_scan_ies = NULL;
4941 }
4942
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004943 EXIT();
Dustin Brown04348372017-12-14 16:13:39 -08004944
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304945 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004946}
4947
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304948/**
4949 * hdd_deinit_all_adapters - deinit all adapters
4950 * @hdd_ctx: HDD context
4951 * @rtnl_held: True if RTNL lock held
4952 *
4953 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004954void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304955{
Jeff Johnson9d295242017-08-29 14:39:48 -07004956 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304957
4958 ENTER();
4959
Dustin Brown920397d2017-12-13 16:27:50 -08004960 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304961 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304962
4963 EXIT();
4964}
4965
Dustin Browndb2a8be2017-12-20 11:49:56 -08004966QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004967{
Jeff Johnson9d295242017-08-29 14:39:48 -07004968 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004969
4970 ENTER();
4971
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304972 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4973
Dustin Brown920397d2017-12-13 16:27:50 -08004974 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08004975 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004976
4977 EXIT();
4978
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304979 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004980}
4981
Paul Zhang84fa9382017-11-10 21:18:21 +08004982static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4983 struct hdd_adapter *adapter)
4984{
4985 switch (adapter->device_mode) {
4986 case QDF_STA_MODE:
4987 case QDF_P2P_CLIENT_MODE:
4988 case QDF_IBSS_MODE:
4989 case QDF_P2P_DEVICE_MODE:
4990 case QDF_NDI_MODE:
4991 wlan_hdd_scan_abort(adapter);
4992 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4993 if (adapter->device_mode == QDF_STA_MODE)
4994 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4995 adapter->dev);
4996 break;
4997 case QDF_P2P_GO_MODE:
4998 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4999 break;
5000 case QDF_SAP_MODE:
5001 wlan_hdd_undo_acs(adapter);
5002 break;
5003 default:
5004 break;
5005 }
5006}
5007
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005008QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005009{
Jeff Johnson9d295242017-08-29 14:39:48 -07005010 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005011 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005012 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005013 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005014
5015 ENTER();
5016
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305017 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5018
Dustin Brown920397d2017-12-13 16:27:50 -08005019 hdd_for_each_adapter(hdd_ctx, adapter) {
Yue Ma42654682018-01-11 16:55:24 -08005020 hdd_notice("[SSR] reset adapter with device mode %s(%d)",
5021 hdd_device_mode_to_string(adapter->device_mode),
Yue Mad5b4b9f2017-05-26 16:23:40 -07005022 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305023
5024 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07005025 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305026 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005027 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305028
Arun Khandavallicc544b32017-01-30 19:52:16 +05305029 if (hdd_ctx->config->sap_internal_restart &&
5030 adapter->device_mode == QDF_SAP_MODE) {
5031 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305032 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305033 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005034 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005035 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005036 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005037 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5038 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305039 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305040 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005041 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005042 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005043
Paul Zhang84fa9382017-11-10 21:18:21 +08005044 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005045 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005046
5047 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005048 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005049 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5051 hdd_wmm_adapter_close(adapter);
5052 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5053 }
5054
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305055 if (adapter->device_mode == QDF_STA_MODE)
5056 hdd_clear_fils_connection_info(adapter);
5057
Wu Gao3545e642017-07-14 19:24:41 +08005058 if (adapter->device_mode == QDF_SAP_MODE) {
5059 /*
5060 * If adapter is SAP, set session ID to invalid
5061 * since SAP session will be cleanup during SSR.
5062 */
Wu Gao36717432016-11-21 15:09:48 +08005063 wlansap_set_invalid_session(
5064 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5065
Wu Gao3545e642017-07-14 19:24:41 +08005066 wlansap_cleanup_cac_timer(
5067 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5068 }
5069
Yue Ma42654682018-01-11 16:55:24 -08005070 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005071 if (adapter->device_mode == QDF_STA_MODE ||
5072 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005073 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005074 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005075 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005076
5077 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5078 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005079 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5080 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5081 if (adapter->sta_info[sta_id].in_use) {
5082 hdd_debug("[SSR] deregister STA with ID %d",
5083 sta_id);
5084 hdd_softap_deregister_sta(adapter,
5085 sta_id);
5086 adapter->sta_info[sta_id].in_use = 0;
5087 }
5088 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005089 }
5090
Yue Maf9782842017-05-08 12:49:49 -07005091 /* Destroy vdev which will be recreated during reinit. */
5092 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 }
5094
5095 EXIT();
5096
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305097 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098}
5099
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005100bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305101{
Dustin Brown920397d2017-12-13 16:27:50 -08005102 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305103 bool close_modules = true;
5104
Arun Khandavalliba479c42017-07-26 21:29:40 +05305105 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5106 hdd_info("FTM mode, don't close the module");
5107 return false;
5108 }
5109
Dustin Brown920397d2017-12-13 16:27:50 -08005110 hdd_for_each_adapter(hdd_ctx, adapter) {
5111 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5112 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005113 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305114 close_modules = false;
5115 break;
5116 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305117 }
5118
5119 return close_modules;
5120}
5121
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305122bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305123{
5124 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5125 return true;
5126 else
5127 return false;
5128}
5129
Anurag Chouhanc4092922016-09-08 15:56:11 +05305130#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005131 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305132struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5133 struct ieee80211_channel *channel,
5134 const u8 *bssid, const u8 *ssid,
5135 size_t ssid_len)
5136{
5137 return cfg80211_get_bss(wiphy, channel, bssid,
5138 ssid, ssid_len,
5139 WLAN_CAPABILITY_ESS,
5140 WLAN_CAPABILITY_ESS);
5141}
5142#else
5143struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5144 struct ieee80211_channel *channel,
5145 const u8 *bssid, const u8 *ssid,
5146 size_t ssid_len)
5147{
5148 return cfg80211_get_bss(wiphy, channel, bssid,
5149 ssid, ssid_len,
5150 IEEE80211_BSS_TYPE_ESS,
5151 IEEE80211_PRIVACY_ANY);
5152}
5153#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305154
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305155#if defined CFG80211_CONNECT_BSS || \
5156 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305157#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305158 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305159/**
5160 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5161 * @timeout_reason: reason for connect timeout
5162 *
5163 * This function is used to convert host timeout
5164 * reason enum to kernel specific enum.
5165 *
5166 * Return: nl timeout enum
5167 */
5168static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5169 tSirResultCodes timeout_reason)
5170{
5171 switch (timeout_reason) {
5172 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5173 return NL80211_TIMEOUT_SCAN;
5174 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5175 return NL80211_TIMEOUT_AUTH;
5176 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5177 return NL80211_TIMEOUT_ASSOC;
5178 default:
5179 return NL80211_TIMEOUT_UNSPECIFIED;
5180 }
5181}
5182
5183/**
5184 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5185 * @dev: network device
5186 * @bssid: bssid to which we want to associate
5187 * @timeout_reason: reason for connect timeout
5188 *
5189 * This API is used to send connection timeout reason to supplicant
5190 *
5191 * Return: void
5192 */
5193static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5194 const u8 *bssid,
5195 tSirResultCodes timeout_reason)
5196{
5197 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005198
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305199 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5200
5201 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5202 nl_timeout_reason);
5203}
5204
5205/**
5206 * __hdd_connect_bss() - API to send connection status to supplicant
5207 * @dev: network device
5208 * @bssid: bssid to which we want to associate
5209 * @req_ie: Request Information Element
5210 * @req_ie_len: len of the req IE
5211 * @resp_ie: Response IE
5212 * @resp_ie_len: len of ht response IE
5213 * @status: status
5214 * @gfp: Kernel Flag
5215 * @timeout_reason: reason for connect timeout
5216 *
5217 * Return: void
5218 */
5219static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5220 struct cfg80211_bss *bss, const u8 *req_ie,
5221 size_t req_ie_len, const u8 *resp_ie,
5222 size_t resp_ie_len, int status, gfp_t gfp,
5223 tSirResultCodes timeout_reason)
5224{
5225 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005226
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305227 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5228
5229 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5230 resp_ie, resp_ie_len, status, gfp,
5231 nl_timeout_reason);
5232}
5233#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305234#if defined CFG80211_CONNECT_TIMEOUT || \
5235 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305236static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5237 const u8 *bssid,
5238 tSirResultCodes timeout_reason)
5239{
5240 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5241}
5242#endif
5243
5244static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5245 struct cfg80211_bss *bss, const u8 *req_ie,
5246 size_t req_ie_len, const u8 *resp_ie,
5247 size_t resp_ie_len, int status, gfp_t gfp,
5248 tSirResultCodes timeout_reason)
5249{
5250 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5251 resp_ie, resp_ie_len, status, gfp);
5252}
5253#endif
5254
Abhishek Singha84d3952016-09-13 13:45:05 +05305255/**
5256 * hdd_connect_bss() - API to send connection status to supplicant
5257 * @dev: network device
5258 * @bssid: bssid to which we want to associate
5259 * @req_ie: Request Information Element
5260 * @req_ie_len: len of the req IE
5261 * @resp_ie: Response IE
5262 * @resp_ie_len: len of ht response IE
5263 * @status: status
5264 * @gfp: Kernel Flag
5265 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305266 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305267 *
5268 * The API is a wrapper to send connection status to supplicant
5269 *
5270 * Return: Void
5271 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305272#if defined CFG80211_CONNECT_TIMEOUT || \
5273 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305274static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5275 struct cfg80211_bss *bss, const u8 *req_ie,
5276 size_t req_ie_len, const u8 *resp_ie,
5277 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305278 bool connect_timeout,
5279 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305280{
5281 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305282 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305283 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305284 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5285 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305286}
5287#else
5288static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5289 struct cfg80211_bss *bss, const u8 *req_ie,
5290 size_t req_ie_len, const u8 *resp_ie,
5291 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305292 bool connect_timeout,
5293 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305294{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305295 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5296 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305297}
5298#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305299
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305300#if defined(WLAN_FEATURE_FILS_SK)
5301#if defined(CFG80211_CONNECT_DONE) || \
5302 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5303#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5304 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305305/**
5306 * hdd_populate_fils_params() - Populate FILS keys to connect response
5307 * @fils_params: connect response to supplicant
5308 * @fils_kek: FILS kek
5309 * @fils_kek_len: FILS kek length
5310 * @pmk: FILS PMK
5311 * @pmk_len: FILS PMK length
5312 * @pmkid: PMKID
5313 * @fils_seq_num: FILS Seq number
5314 *
5315 * Return: None
5316 */
5317static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5318 *fils_params, const uint8_t *fils_kek,
5319 size_t fils_kek_len, const uint8_t *pmk,
5320 size_t pmk_len, const uint8_t *pmkid,
5321 uint16_t fils_seq_num)
5322{
5323 /* Increament seq number to be used for next FILS */
5324 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5325 fils_params->update_erp_next_seq_num = true;
5326 fils_params->fils_kek = fils_kek;
5327 fils_params->fils_kek_len = fils_kek_len;
5328 fils_params->pmk = pmk;
5329 fils_params->pmk_len = pmk_len;
5330 fils_params->pmkid = pmkid;
5331}
5332#else
5333static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5334 *fils_params, const uint8_t
5335 *fils_kek, size_t fils_kek_len,
5336 const uint8_t *pmk, size_t pmk_len,
5337 const uint8_t *pmkid,
5338 uint16_t fils_seq_num)
5339{ }
5340#endif
5341
Jeff Johnson172237b2017-11-07 15:32:59 -08005342void hdd_update_hlp_info(struct net_device *dev,
5343 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305344{
5345 struct sk_buff *skb;
5346 uint16_t skb_len;
5347 struct llc_snap_hdr_t *llc_hdr;
5348 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305349 uint8_t *hlp_data;
5350 uint16_t hlp_data_len;
5351 struct fils_join_rsp_params *roam_fils_params
5352 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305353 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5354
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305355 if (!roam_fils_params) {
5356 hdd_err("FILS Roam Param NULL");
5357 return;
5358 }
5359
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005360 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305361 hdd_err("FILS HLP Data NULL, len %d",
5362 roam_fils_params->hlp_data_len);
5363 return;
5364 }
5365
5366 hlp_data = roam_fils_params->hlp_data;
5367 hlp_data_len = roam_fils_params->hlp_data_len;
5368
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305369 /* Calculate skb length */
5370 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5371 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5372 if (skb == NULL) {
5373 hdd_err("HLP packet nbuf alloc fails");
5374 return;
5375 }
5376
5377 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5378 QDF_MAC_ADDR_SIZE);
5379 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5380 QDF_MAC_ADDR_SIZE);
5381
5382 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5383 if (IS_SNAP(llc_hdr)) {
5384 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5385 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5386 }
5387
5388 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5389
5390 /*
5391 * This HLP packet is formed from HLP info encapsulated
5392 * in assoc response frame which is AEAD encrypted.
5393 * Hence, this checksum validation can be set unnecessary.
5394 * i.e. network layer need not worry about checksum.
5395 */
5396 skb->ip_summed = CHECKSUM_UNNECESSARY;
5397
5398 status = hdd_rx_packet_cbk(padapter, skb);
5399 if (QDF_IS_STATUS_ERROR(status)) {
5400 hdd_err("Sending HLP packet fails");
5401 return;
5402 }
5403 hdd_debug("send HLP packet to netif successfully");
5404}
5405
5406/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305407 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5408 * @dev: network device
5409 * @bssid: bssid to which we want to associate
5410 * @bss: cfg80211 bss info
5411 * @roam_info: information about connected bss
5412 * @req_ie: Request Information Element
5413 * @req_ie_len: len of the req IE
5414 * @resp_ie: Response IE
5415 * @resp_ie_len: len of ht response IE
5416 * @status: status
5417 * @gfp: allocation flags
5418 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5419 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305420 *
5421 * This API is used as wrapper to send FILS key/sequence number
5422 * params etc. to supplicant in case of FILS connection
5423 *
5424 * Return: None
5425 */
5426static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005427 struct cfg80211_bss *bss,
5428 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305429 const u8 *req_ie, size_t req_ie_len,
5430 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005431 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305432 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305433{
5434 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305435 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5436 struct fils_join_rsp_params *roam_fils_params =
5437 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005438
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305439 qdf_mem_zero(&fils_params, sizeof(fils_params));
5440
5441 if (!roam_fils_params) {
5442 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5443 } else {
5444 fils_params.status = status;
5445 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005446 fils_params.timeout_reason =
5447 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305448 fils_params.req_ie = req_ie;
5449 fils_params.req_ie_len = req_ie_len;
5450 fils_params.resp_ie = resp_ie;
5451 fils_params.resp_ie_len = resp_ie_len;
5452 fils_params.bss = bss;
5453 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5454 roam_fils_params->kek_len,
5455 roam_fils_params->fils_pmk,
5456 roam_fils_params->fils_pmk_len,
5457 roam_fils_params->fils_pmkid,
5458 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305459 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305460 }
5461 hdd_debug("FILS indicate connect status %d seq no %d",
5462 fils_params.status,
5463 fils_params.fils_erp_next_seq_num);
5464
5465 cfg80211_connect_done(dev, &fils_params, gfp);
5466
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305467 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305468 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305469
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305470 /* Clear all the FILS key info */
5471 if (roam_fils_params && roam_fils_params->fils_pmk)
5472 qdf_mem_free(roam_fils_params->fils_pmk);
5473 if (roam_fils_params)
5474 qdf_mem_free(roam_fils_params);
5475 roam_info->fils_join_rsp = NULL;
5476}
5477#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005478static inline void
5479hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005480 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005481 const u8 *req_ie, size_t req_ie_len,
5482 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5483 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305484 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305485{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305486#endif
5487#endif
5488
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305489#if defined(WLAN_FEATURE_FILS_SK) && \
5490 (defined(CFG80211_CONNECT_DONE) || \
5491 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305492/**
5493 * hdd_fils_update_connect_results() - API to send fils connection status to
5494 * supplicant.
5495 * @dev: network device
5496 * @bssid: bssid to which we want to associate
5497 * @bss: cfg80211 bss info
5498 * @roam_info: information about connected bss
5499 * @req_ie: Request Information Element
5500 * @req_ie_len: len of the req IE
5501 * @resp_ie: Response IE
5502 * @resp_ie_len: len of ht response IE
5503 * @status: status
5504 * @gfp: allocation flags
5505 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5506 * @timeout_reason: reason for connect timeout
5507 *
5508 * The API is a wrapper to send connection status to supplicant
5509 *
5510 * Return: 0 if success else failure
5511 */
5512static int hdd_fils_update_connect_results(struct net_device *dev,
5513 const u8 *bssid,
5514 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005515 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305516 size_t req_ie_len, const u8 *resp_ie,
5517 size_t resp_ie_len, u16 status, gfp_t gfp,
5518 bool connect_timeout,
5519 tSirResultCodes timeout_reason)
5520{
5521 ENTER();
5522 if (!roam_info || !roam_info->is_fils_connection)
5523 return -EINVAL;
5524
5525 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5526 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305527 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305528 return 0;
5529}
5530#else
5531static inline int hdd_fils_update_connect_results(struct net_device *dev,
5532 const u8 *bssid,
5533 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005534 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305535 size_t req_ie_len, const u8 *resp_ie,
5536 size_t resp_ie_len, u16 status, gfp_t gfp,
5537 bool connect_timeout,
5538 tSirResultCodes timeout_reason)
5539{
5540 return -EINVAL;
5541}
5542#endif
5543
Anurag Chouhanc4092922016-09-08 15:56:11 +05305544/**
5545 * hdd_connect_result() - API to send connection status to supplicant
5546 * @dev: network device
5547 * @bssid: bssid to which we want to associate
5548 * @roam_info: information about connected bss
5549 * @req_ie: Request Information Element
5550 * @req_ie_len: len of the req IE
5551 * @resp_ie: Response IE
5552 * @resp_ie_len: len of ht response IE
5553 * @status: status
5554 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305555 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305556 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305557 *
5558 * The API is a wrapper to send connection status to supplicant
5559 * and allow runtime suspend
5560 *
5561 * Return: Void
5562 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305563void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005564 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305565 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305566 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305567 bool connect_timeout,
5568 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305569{
Jeff Johnson9d295242017-08-29 14:39:48 -07005570 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305571 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005572 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305573
5574 if (WLAN_STATUS_SUCCESS == status) {
5575 struct ieee80211_channel *chan;
5576 int freq;
5577 int chan_no = roam_info->pBssDesc->channelId;
5578
5579 if (chan_no <= 14)
5580 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005581 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305582 else
5583 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005584 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305585
5586 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5587 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5588 roam_info->u.pConnectedProfile->SSID.ssId,
5589 roam_info->u.pConnectedProfile->SSID.length);
5590 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305591
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305592 if (hdd_fils_update_connect_results(dev, bssid, bss,
5593 roam_info, req_ie, req_ie_len, resp_ie,
5594 resp_ie_len, status, gfp, connect_timeout,
5595 timeout_reason) != 0) {
5596 hdd_connect_bss(dev, bssid, bss, req_ie,
5597 req_ie_len, resp_ie, resp_ie_len,
5598 status, gfp, connect_timeout, timeout_reason);
5599 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305600
Jingxiang Geb49aa302018-01-17 20:54:15 +08005601 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005602 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305603}
5604#else
5605void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005606 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305607 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305608 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305609 bool connect_timeout,
5610 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305611{
Jeff Johnson9d295242017-08-29 14:39:48 -07005612 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005613 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305614
Anurag Chouhanc4092922016-09-08 15:56:11 +05305615 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5616 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005617
Jingxiang Geb49aa302018-01-17 20:54:15 +08005618 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005619 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305620}
5621#endif
5622
5623
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005624QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005625{
Jeff Johnson9d295242017-08-29 14:39:48 -07005626 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005627#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005628 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005629#endif
5630 eConnectionState connState;
5631
5632 ENTER();
5633
Dustin Brown920397d2017-12-13 16:27:50 -08005634 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305635 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005636 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305637
Yue Ma42654682018-01-11 16:55:24 -08005638 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5639 hdd_device_mode_to_string(adapter->device_mode),
5640 adapter->device_mode);
5641
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005642 hdd_wmm_init(adapter);
5643
5644 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005645 case QDF_STA_MODE:
5646 case QDF_P2P_CLIENT_MODE:
5647 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005648
5649 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5650 ->conn_info.connState;
5651
Krunal Sonib51eec72017-11-20 21:53:01 -08005652 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005653 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005654 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005655
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005656 /* Indicate disconnect event to supplicant
5657 * if associated previously
5658 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005660 eConnectionState_IbssConnected == connState ||
5661 eConnectionState_NotConnected == connState ||
5662 eConnectionState_IbssDisconnected == connState ||
5663 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005664 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005665
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005666 memset(&wrqu, '\0', sizeof(wrqu));
5667 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5668 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5669 wireless_send_event(adapter->dev, SIOCGIWAP,
5670 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005671 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005672 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673
5674 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305675 wlan_hdd_cfg80211_indicate_disconnect(
5676 adapter->dev, false,
5677 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005678 } else if (eConnectionState_Connecting == connState) {
5679 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005680 * Indicate connect failure to supplicant if we
5681 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005682 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305683 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305684 NULL, 0, NULL, 0,
5685 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005686 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005687 }
5688
5689 hdd_register_tx_flow_control(adapter,
5690 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005691 hdd_tx_resume_cb,
5692 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005693
5694 break;
5695
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005696 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005697 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005698 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305699
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005700 break;
5701
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005702 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005704 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005705 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5706#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005707 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005708 /* event supplicant to restart */
5709 cfg80211_del_sta(adapter->dev,
5710 (const u8 *)&bcastMac.bytes[0],
5711 GFP_KERNEL);
5712#endif
5713 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305714 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005715 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305716 hdd_set_mon_rx_cb(adapter->dev);
5717 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5718 adapter->mon_bandwidth);
5719 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720 default:
5721 break;
5722 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005723 /*
5724 * Action frame registered in one adapter which will
5725 * applicable to all interfaces
5726 */
5727 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005728 }
5729
5730 EXIT();
5731
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305732 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005733}
5734
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005735QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005736 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005737{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305738 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005739 qdf_list_node_t *node;
5740
5741 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005742
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005743 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005744 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005745 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005746
5747 if (QDF_IS_STATUS_ERROR(status))
5748 return status;
5749
5750 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5751
5752 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005753}
5754
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005755QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005756 struct hdd_adapter *current_adapter,
5757 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005758{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305759 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005760 qdf_list_node_t *node;
5761
5762 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005763
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005764 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005765 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005766 &current_adapter->node,
5767 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005768 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005769
5770 if (QDF_IS_STATUS_ERROR(status))
5771 return status;
5772
5773 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5774
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005775 return status;
5776}
5777
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005778QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005779 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005780{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305781 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005782
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005783 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005784 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005785 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005786
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005787 return status;
5788}
5789
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005790QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005791 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005792{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305793 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005794 qdf_list_node_t *node;
5795
5796 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005797
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005798 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005799 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005800 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005801
5802 if (QDF_IS_STATUS_ERROR(status))
5803 return status;
5804
5805 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005807 return status;
5808}
5809
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005810QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005811 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005812{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305813 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005814
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005815 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005816 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005817 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005818
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005819 return status;
5820}
5821
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005822QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005823 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005824{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305825 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005826
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005827 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005828 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005829 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005830
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005831 return status;
5832}
5833
Jeff Johnson9d295242017-08-29 14:39:48 -07005834struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005835 tSirMacAddr macAddr)
5836{
Jeff Johnson9d295242017-08-29 14:39:48 -07005837 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005838
Dustin Brown920397d2017-12-13 16:27:50 -08005839 hdd_for_each_adapter(hdd_ctx, adapter) {
5840 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5841 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005842 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005843 }
5844
5845 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005846}
5847
Jeff Johnson9d295242017-08-29 14:39:48 -07005848struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005849 uint32_t vdev_id)
5850{
Jeff Johnson9d295242017-08-29 14:39:48 -07005851 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005852
Dustin Brown920397d2017-12-13 16:27:50 -08005853 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005854 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005855 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005856 }
5857
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005858 return NULL;
5859}
5860
Abhishek Singh7996eb72015-12-30 17:24:02 +05305861/**
5862 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5863 * the sessionid
5864 * @hdd_ctx: hdd context.
5865 * @sme_session_id: sme session is for the adapter to get.
5866 *
5867 * This function is used to get the adapter with provided session id
5868 *
5869 * Return: adapter pointer if found
5870 *
5871 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005872struct hdd_adapter *
5873hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5874 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305875{
Jeff Johnson9d295242017-08-29 14:39:48 -07005876 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305877
Dustin Brown920397d2017-12-13 16:27:50 -08005878 hdd_for_each_adapter(hdd_ctx, adapter) {
5879 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305880 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305881 }
Dustin Brown920397d2017-12-13 16:27:50 -08005882
Abhishek Singh7996eb72015-12-30 17:24:02 +05305883 return NULL;
5884}
5885
Jeff Johnson9d295242017-08-29 14:39:48 -07005886struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005887 const char *iface_name)
5888{
Jeff Johnson9d295242017-08-29 14:39:48 -07005889 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005890
Dustin Brown920397d2017-12-13 16:27:50 -08005891 hdd_for_each_adapter(hdd_ctx, adapter) {
5892 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07005893 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005894 }
Dustin Brown920397d2017-12-13 16:27:50 -08005895
Naveen Rawat4edb6822017-04-12 10:09:17 -07005896 return NULL;
5897}
5898
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005899/**
5900 * hdd_get_adapter() - to get adapter matching the mode
5901 * @hdd_ctx: hdd context
5902 * @mode: adapter mode
5903 *
5904 * This routine will return the pointer to adapter matching
5905 * with the passed mode.
5906 *
5907 * Return: pointer to adapter or null
5908 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005909struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005910 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005911{
Jeff Johnson9d295242017-08-29 14:39:48 -07005912 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005913
Dustin Brown920397d2017-12-13 16:27:50 -08005914 hdd_for_each_adapter(hdd_ctx, adapter) {
5915 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005916 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005917 }
5918
5919 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005920}
5921
5922/**
5923 * hdd_get_operating_channel() - return operating channel of the device mode
5924 * @hdd_ctx: Pointer to the HDD context.
5925 * @mode: Device mode for which operating channel is required.
5926 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005927 * QDF_STA_MODE,
5928 * QDF_P2P_CLIENT_MODE,
5929 * QDF_SAP_MODE,
5930 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005931 *
5932 * This API returns the operating channel of the requested device mode
5933 *
5934 * Return: channel number. "0" id the requested device is not found OR it is
5935 * not connected.
5936 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005937uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005938 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005939{
Jeff Johnson9d295242017-08-29 14:39:48 -07005940 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005941 uint8_t operatingChannel = 0;
5942
Dustin Brown920397d2017-12-13 16:27:50 -08005943 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005944 if (mode == adapter->device_mode) {
5945 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005946 case QDF_STA_MODE:
5947 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005948 if (hdd_conn_is_connected
5949 (WLAN_HDD_GET_STATION_CTX_PTR
5950 (adapter))) {
5951 operatingChannel =
5952 (WLAN_HDD_GET_STATION_CTX_PTR
5953 (adapter))->conn_info.
5954 operationChannel;
5955 }
5956 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005957 case QDF_SAP_MODE:
5958 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005959 /* softap connection info */
5960 if (test_bit
5961 (SOFTAP_BSS_STARTED,
5962 &adapter->event_flags))
5963 operatingChannel =
5964 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005965 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005966 break;
5967 default:
5968 break;
5969 }
5970
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005971 /* Found the device of interest. break the loop */
5972 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005973 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005974 }
Dustin Brown920397d2017-12-13 16:27:50 -08005975
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005976 return operatingChannel;
5977}
5978
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005979static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980 hdd_ctx)
5981{
Jeff Johnson9d295242017-08-29 14:39:48 -07005982 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005983
5984 ENTER();
5985
Dustin Brown920397d2017-12-13 16:27:50 -08005986 hdd_for_each_adapter(hdd_ctx, adapter) {
5987 if (adapter->device_mode == QDF_STA_MODE ||
5988 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5989 adapter->device_mode == QDF_IBSS_MODE ||
5990 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5991 adapter->device_mode == QDF_SAP_MODE ||
5992 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005993 wlan_hdd_cfg80211_deregister_frames(adapter);
5994 hdd_unregister_wext(adapter->dev);
5995 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005996 }
5997
5998 EXIT();
5999
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306000 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006001}
6002
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006003QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006004{
Jeff Johnson9d295242017-08-29 14:39:48 -07006005 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006006
6007 ENTER();
6008
Dustin Brown920397d2017-12-13 16:27:50 -08006009 hdd_for_each_adapter(hdd_ctx, adapter) {
6010 if (adapter->device_mode == QDF_STA_MODE ||
6011 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6012 adapter->device_mode == QDF_IBSS_MODE ||
6013 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6014 adapter->device_mode == QDF_SAP_MODE ||
6015 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006016 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006017 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306018 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006019 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006020 }
6021
6022 EXIT();
6023
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306024 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006025}
6026
Dustin Brownf27bce82016-11-03 12:52:27 -07006027/**
6028 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6029 * adapters
6030 * @hdd_ctx: The HDD context containing the adapters to operate on
6031 *
6032 * return: QDF_STATUS_SUCCESS
6033 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006034static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006035{
Jeff Johnson9d295242017-08-29 14:39:48 -07006036 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006037 int err;
6038
6039 ENTER();
6040
Dustin Brown920397d2017-12-13 16:27:50 -08006041 hdd_for_each_adapter(hdd_ctx, adapter) {
6042 if (adapter->device_mode == QDF_STA_MODE ||
6043 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6044 adapter->device_mode == QDF_IBSS_MODE ||
6045 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6046 adapter->device_mode == QDF_SAP_MODE ||
6047 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006048 err = wlan_hdd_sched_scan_stop(adapter->dev);
6049 if (err)
6050 hdd_err("Unable to stop scheduled scan");
6051 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006052 }
6053
6054 EXIT();
6055
6056 return QDF_STATUS_SUCCESS;
6057}
6058
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006059#ifdef WLAN_NS_OFFLOAD
6060/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006061 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062 * @hdd_ctx: Pointer to hdd context
6063 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006064 * Unregister for IPv6 address change notifications.
6065 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006066 * Return: None
6067 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006068static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006069{
6070 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006071}
6072
6073/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006074 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075 * @hdd_ctx: Pointer to hdd context
6076 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006077 * Register for IPv6 address change notifications.
6078 *
6079 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006080 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006081static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006082{
6083 int ret;
6084
6085 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6086 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006087 if (ret) {
6088 hdd_err("Failed to register IPv6 notifier: %d", ret);
6089 goto out;
6090 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006091
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006092 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006093out:
6094 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006095}
6096#else
6097/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006098 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006099 * @hdd_ctx: Pointer to hdd context
6100 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006101 * Unregister for IPv6 address change notifications.
6102 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006103 * Return: None
6104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006105static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006106{
6107}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006108
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006109/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006110 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006111 * @hdd_ctx: Pointer to hdd context
6112 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006113 * Register for IPv6 address change notifications.
6114 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006115 * Return: None
6116 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006117static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006118{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006119 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006120}
6121#endif
6122
6123/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006124 * hdd_register_notifiers - Register netdev notifiers.
6125 * @hdd_ctx: HDD context
6126 *
6127 * Register netdev notifiers like IPv4 and IPv6.
6128 *
6129 * Return: 0 on success and errno on failure
6130 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006131static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006132{
6133 int ret;
6134
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006135 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6136 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306137 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006138
6139 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6140 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6141 if (ret) {
6142 hdd_err("Failed to register IPv4 notifier: %d", ret);
6143 goto unregister_ip6_notifier;
6144 }
6145
6146 return 0;
6147
6148unregister_ip6_notifier:
6149 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006150out:
6151 return ret;
6152
6153}
6154
6155/**
6156 * hdd_unregister_notifiers - Unregister netdev notifiers.
6157 * @hdd_ctx: HDD context
6158 *
6159 * Unregister netdev notifiers like IPv4 and IPv6.
6160 *
6161 * Return: None.
6162 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006163void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006164{
6165 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6166
6167 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006168}
6169
6170/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006171 * hdd_exit_netlink_services - Exit netlink services
6172 * @hdd_ctx: HDD context
6173 *
6174 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6175 * nl service.
6176 *
6177 * Return: None.
6178 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006179static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006180{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006181 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006182 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006183 ptt_sock_deactivate_svc();
6184
6185 nl_srv_exit();
6186}
6187
6188/**
6189 * hdd_init_netlink_services- Init netlink services
6190 * @hdd_ctx: HDD context
6191 *
6192 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6193 * nl service.
6194 *
6195 * Return: 0 on success and errno on failure.
6196 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006197static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006198{
6199 int ret;
6200
Ryan Hsuceddceb2016-04-28 10:20:14 -07006201 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006202 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006203 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006204 goto out;
6205 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006206 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006207
Naveen Rawat910726a2017-03-06 11:42:51 -08006208 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006209 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006210 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006211 goto err_nl_srv;
6212 }
6213
6214 ret = ptt_sock_activate_svc();
6215 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006216 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006217 goto err_nl_srv;
6218 }
6219
6220 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006221 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006222 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006223
6224 ret = cnss_diag_activate_service();
6225 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006226 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006227 goto err_close_cesium;
6228 }
6229
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006230 ret = spectral_scan_activate_service();
6231 if (ret) {
6232 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6233 goto err_close_cesium;
6234 }
6235
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006236 return 0;
6237
6238err_close_cesium:
6239 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006240 ptt_sock_deactivate_svc();
6241err_nl_srv:
6242 nl_srv_exit();
6243out:
6244 return ret;
6245}
6246
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006247/**
6248 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6249 * @hdd_ctx: HDD context.
6250 *
6251 * Destroy RX wakelock.
6252 *
6253 * Return: None.
6254 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006255static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006256{
6257 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6258}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006259
6260/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006261 * hdd_rx_wake_lock_create() - Create RX wakelock
6262 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006263 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006264 * Create RX wakelock.
6265 *
6266 * Return: None.
6267 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006268static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006269{
6270 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6271}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006272
6273/**
Houston Hoffman160db392016-10-10 17:37:51 -07006274 * hdd_context_deinit() - Deinitialize HDD context
6275 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006276 *
Houston Hoffman160db392016-10-10 17:37:51 -07006277 * Deinitialize HDD context along with all the feature specific contexts but
6278 * do not free hdd context itself. Caller of this API is supposed to free
6279 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006280 *
Houston Hoffman160db392016-10-10 17:37:51 -07006281 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006282 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006283static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006284{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306285 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6286
Houston Hoffman160db392016-10-10 17:37:51 -07006287 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006288
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006289 hdd_sap_context_destroy(hdd_ctx);
6290
6291 hdd_rx_wake_lock_destroy(hdd_ctx);
6292
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006293 hdd_scan_context_destroy(hdd_ctx);
6294
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006295 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006296
Houston Hoffman160db392016-10-10 17:37:51 -07006297 return 0;
6298}
6299
6300/**
6301 * hdd_context_destroy() - Destroy HDD context
6302 * @hdd_ctx: HDD context to be destroyed.
6303 *
6304 * Free config and HDD context as well as destroy all the resources.
6305 *
6306 * Return: None
6307 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006308static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006309{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006310 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306311
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306312 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6313
Houston Hoffman160db392016-10-10 17:37:51 -07006314 hdd_context_deinit(hdd_ctx);
6315
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306316 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006317 hdd_ctx->config = NULL;
6318
6319 wiphy_free(hdd_ctx->wiphy);
6320}
6321
6322/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306323 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6324 *
6325 * This function is used to destroy bug report lock
6326 *
6327 * Return: None
6328 */
6329static void wlan_destroy_bug_report_lock(void)
6330{
6331 p_cds_contextType p_cds_context;
6332
6333 p_cds_context = cds_get_global_context();
6334 if (!p_cds_context) {
6335 hdd_err("cds context is NULL");
6336 return;
6337 }
6338
6339 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6340}
6341
6342/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006343 * hdd_wlan_exit() - HDD WLAN exit function
6344 * @hdd_ctx: Pointer to the HDD Context
6345 *
6346 * This is the driver exit point (invoked during rmmod)
6347 *
6348 * Return: None
6349 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006350static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006351{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006352 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306353 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354
6355 ENTER();
6356
Dustin Brown6f427922017-09-19 12:19:00 -07006357 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306358
6359 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006360
Prashanth Bhattaab004382016-10-11 16:08:11 -07006361 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006362
6363#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306364 if (QDF_TIMER_STATE_RUNNING ==
6365 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6366 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006367 }
6368
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306369 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306370 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006371 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006373 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6374 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6375 hdd_ctx->last_acs_channel_list = NULL;
6376 hdd_ctx->num_of_channels = 0;
6377 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006379
Arun Khandavallifae92942016-08-01 13:31:08 +05306380 mutex_lock(&hdd_ctx->iface_change_lock);
6381 driver_status = hdd_ctx->driver_status;
6382 mutex_unlock(&hdd_ctx->iface_change_lock);
6383
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006384 /*
6385 * Powersave Offload Case
6386 * Disable Idle Power Save Mode
6387 */
6388 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006389 /* clear the scan queue in all the scenarios */
6390 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006391
Arun Khandavallifae92942016-08-01 13:31:08 +05306392 if (driver_status != DRIVER_MODULES_CLOSED) {
6393 hdd_unregister_wext_all_adapters(hdd_ctx);
6394 /*
6395 * Cancel any outstanding scan requests. We are about to close
6396 * all of our adapters, but an adapter structure is what SME
6397 * passes back to our callback function. Hence if there
6398 * are any outstanding scan requests then there is a
6399 * race condition between when the adapter is closed and
6400 * when the callback is invoked. We try to resolve that
6401 * race condition here by canceling any outstanding scans
6402 * before we close the adapters.
6403 * Note that the scans may be cancelled in an asynchronous
6404 * manner, so ideally there needs to be some kind of
6405 * synchronization. Rather than introduce a new
6406 * synchronization here, we will utilize the fact that we are
6407 * about to Request Full Power, and since that is synchronized,
6408 * the expectation is that by the time Request Full Power has
6409 * completed, all scans will be cancelled
6410 */
6411 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006412 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006413 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006414 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006415 }
6416
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306417 unregister_netdevice_notifier(&hdd_netdev_notifier);
6418
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006419 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306420
Dustin Brown021cecd2017-12-11 13:56:43 -08006421 hdd_driver_memdump_deinit();
6422
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306423 qdf_nbuf_deinit_replenish_timer();
6424
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306425 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6426 hdd_info("Release wakelock for monitor mode!");
6427 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6428 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6429 }
6430
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306431 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6432 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6433 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6434
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006435 /*
6436 * Close CDS
6437 * This frees pMac(HAL) context. There should not be any call
6438 * that requires pMac access after this.
6439 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006440
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006441 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006442
Dustin Brownd005ad82018-01-19 10:32:13 -08006443 hdd_close_all_adapters(hdd_ctx, false);
6444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006445 hdd_ipa_cleanup(hdd_ctx);
6446
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306447 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306448 /*
6449 * If there is re_init failure wiphy would have already de-registered
6450 * check the wiphy status before un-registering again
6451 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306452 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306453 wiphy_unregister(wiphy);
6454 wlan_hdd_cfg80211_deinit(wiphy);
6455 hdd_lpass_notify_stop(hdd_ctx);
6456 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006457
Arun Khandavallifae92942016-08-01 13:31:08 +05306458 hdd_exit_netlink_services(hdd_ctx);
6459 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306460#ifdef FEATURE_WLAN_CH_AVOID
6461 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6462#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306463
Abhishek Singhe9068f12017-03-31 14:14:52 +05306464 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6465 if (driver_status)
6466 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006467
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006468 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006469}
6470
6471void __hdd_wlan_exit(void)
6472{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006473 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006474
6475 ENTER();
6476
Anurag Chouhan6d760662016-02-20 16:05:43 +05306477 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006478 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006479 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480 EXIT();
6481 return;
6482 }
6483
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006484 /* Do all the cleanup before deregistering the driver */
6485 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006486
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006487 EXIT();
6488}
6489
6490#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006491/**
6492 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006493 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006494 *
6495 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6496 * Then new ACS request will do a fresh scan without reusing the cached
6497 * scan information.
6498 *
6499 * Return: void
6500 */
Tang Yingying523322d2017-01-17 23:28:43 +08006501static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006502{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006503 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006504
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006505 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006507 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6508 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6509 hdd_ctx->last_acs_channel_list = NULL;
6510 hdd_ctx->num_of_channels = 0;
6511 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006512
6513 if (!hdd_ctx->hHal)
6514 return;
6515 sme_scan_flush_result(hdd_ctx->hHal);
6516}
6517#endif
6518
6519#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006520int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6521 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522{
6523 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306524 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006525 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006526
6527 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6528
6529 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306530 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006531 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306532
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006533 if (!hdd_ctx->hHal)
6534 return -EINVAL;
6535
Jeff Johnsone7672e72017-10-21 15:10:04 -07006536 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006537 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306538 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006539 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540 return -EINVAL;
6541 }
6542
6543 return 0;
6544}
6545#endif
6546
6547/**
6548 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6549 * @state: state
6550 *
6551 * This function notifies FW with modem power status
6552 *
6553 * Return: 0 if successful, error number otherwise
6554 */
6555int hdd_wlan_notify_modem_power_state(int state)
6556{
6557 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306558 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006559 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006560
Anurag Chouhan6d760662016-02-20 16:05:43 +05306561 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006562 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306563 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006564 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306565
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006566 if (!hdd_ctx->hHal)
6567 return -EINVAL;
6568
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306569 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6570 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006571 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006572 state);
6573 return -EINVAL;
6574 }
6575 return 0;
6576}
6577
6578/**
6579 *
6580 * hdd_post_cds_enable_config() - HDD post cds start config helper
6581 * @adapter - Pointer to the HDD
6582 *
6583 * Return: None
6584 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006585QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006586{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306587 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006588
6589 /*
6590 * Send ready indication to the HDD. This will kick off the MAC
6591 * into a 'running' state and should kick off an initial scan.
6592 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306593 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6594 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006595 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6596 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306597 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006598 }
6599
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306600 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006601}
6602
6603/* wake lock APIs for HDD */
6604void hdd_prevent_suspend(uint32_t reason)
6605{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306606 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006607}
6608
6609void hdd_allow_suspend(uint32_t reason)
6610{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306611 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006612}
6613
6614void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6615{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306616 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6617 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006618}
6619
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006620/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006621QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006622{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006623
Amar Singhal6f8592b2017-04-26 14:31:58 -07006624 return sme_init_chan_list(hdd_ctx->hHal,
6625 hdd_ctx->reg.alpha2,
6626 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006627}
6628
6629/**
6630 * hdd_is_5g_supported() - check if hardware supports 5GHz
6631 * @hdd_ctx: Pointer to the hdd context
6632 *
6633 * HDD function to know if hardware supports 5GHz
6634 *
6635 * Return: true if hardware supports 5GHz
6636 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006637bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006638{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006639 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006640 return true;
6641
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006642 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006643 return true;
6644 else
6645 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006646}
6647
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006648static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006649{
6650 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006651 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006652
6653 wiphy = hdd_ctx->wiphy;
6654
6655 /*
6656 * The channel information in
6657 * wiphy needs to be initialized before wiphy registration
6658 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006659 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6660 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006661 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006662 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006663 }
6664
6665#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6666 wiphy->wowlan = &wowlan_support_reg_init;
6667#else
6668 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6669 WIPHY_WOWLAN_MAGIC_PKT |
6670 WIPHY_WOWLAN_DISCONNECT |
6671 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6672 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6673 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6674 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6675 WIPHY_WOWLAN_RFKILL_RELEASE;
6676
6677 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6678 WOW_MAX_FILTERS_PER_LIST);
6679 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6680 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6681#endif
6682
6683 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006684 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306685 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006686 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306687 return ret_val;
6688 }
6689
Amar Singhal2d812012018-02-03 15:06:47 +08006690 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006691
Amar Singhale4f28ee2015-10-21 14:36:56 -07006692 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006693}
6694
Mohit Khannaca4173b2017-09-12 21:52:19 -07006695#ifdef MSM_PLATFORM
6696/**
6697 * hdd_display_periodic_stats() - Function to display periodic stats
6698 * @hdd_ctx - handle to hdd context
6699 * @bool data_in_interval - true, if data detected in bw time interval
6700 *
6701 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6702 * Stats show up in wlan driver logs.
6703 *
6704 * Returns: None
6705 */
6706static inline
6707void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6708 bool data_in_interval)
6709{
6710 static u32 counter;
6711 static bool data_in_time_period;
6712 ol_txrx_pdev_handle pdev;
6713
6714 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6715 return;
6716
6717 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6718 if (!pdev) {
6719 hdd_err("pdev is NULL");
6720 return;
6721 }
6722
6723 counter++;
6724 if (data_in_interval)
6725 data_in_time_period = data_in_interval;
6726
6727 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6728 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6729 if (data_in_time_period) {
6730 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6731 CDP_TXRX_PATH_STATS,
6732 QDF_STATS_VERBOSITY_LEVEL_LOW);
6733 wlan_hdd_display_netif_queue_history
6734 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6735 qdf_dp_trace_dump_stats();
6736 }
6737 counter = 0;
6738 data_in_time_period = false;
6739 }
6740}
6741
Ravi Joshie2331e82015-07-01 18:18:54 -07006742/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006743 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006744 * @hdd_ctx - handle to hdd context
6745 * @tx_packets - transmit packet count
6746 * @rx_packets - receive packet count
6747 *
6748 * The function controls the bus bandwidth and dynamic control of
6749 * tcp delayed ack configuration
6750 *
6751 * Returns: None
6752 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006753
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006754static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006755 const uint64_t tx_packets,
6756 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006757{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006758 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006759 uint64_t temp_rx = 0;
6760 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006761 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006762 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006763 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006764 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006765 uint16_t index = 0;
6766 bool vote_level_change = false;
6767 bool rx_level_change = false;
6768 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006769
Mohit Khannaca4173b2017-09-12 21:52:19 -07006770 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006771 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006772 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006773 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006774 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006775 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006776 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006777 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006780 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6781 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006782 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006783 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006784 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306785 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306786 if (hdd_ctx->hbw_requested) {
6787 pld_remove_pm_qos(hdd_ctx->parent_dev);
6788 hdd_ctx->hbw_requested = false;
6789 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306790 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006791 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006792 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306793 if (!hdd_ctx->hbw_requested) {
6794 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6795 hdd_ctx->hbw_requested = true;
6796 }
6797
Nirav Shah3bbfa512016-05-12 16:43:49 +05306798 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006799 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006800 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006801 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006802 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006803
Mohit Khannaf8f96822017-05-17 17:11:59 -07006804 qdf_dp_trace_throttle_live_mode(
6805 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6806
Mohit Khannae71e2262015-11-10 09:37:24 -08006807 /* fine-tuning parameters for RX Flows */
6808 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6809
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006810 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006811
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306812 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6813 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6814 else
6815 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6816
Ravi Joshifed83572016-10-07 16:20:37 -07006817 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6818 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6819 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6820 next_rx_level = WLAN_SVC_TP_HIGH;
6821 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006822 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006823 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006824 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006825 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006826
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006827 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006828 struct wlan_rx_tp_data rx_tp_data = {0};
6829
Ravi Joshie2331e82015-07-01 18:18:54 -07006830 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006831 next_rx_level, temp_rx);
6832 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006833 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006834 /* Send throughput indication only if it is enabled.
6835 * Disabling tcp_del_ack will revert the tcp stack behavior
6836 * to default delayed ack. Note that this will disable the
6837 * dynamic delayed ack mechanism across the system
6838 */
6839 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006840 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6841
Mohit Khanna6272fb682017-04-13 09:34:36 -07006842 if (hdd_ctx->config->enable_tcp_adv_win_scale)
6843 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6844
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006845 rx_tp_data.level = next_rx_level;
6846 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6847 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6848 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006849 }
6850
Mohit Khannae71e2262015-11-10 09:37:24 -08006851 /* fine-tuning parameters for TX Flows */
6852 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6853 hdd_ctx->prev_tx = tx_packets;
6854 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6855 next_tx_level = WLAN_SVC_TP_HIGH;
6856 else
6857 next_tx_level = WLAN_SVC_TP_LOW;
6858
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006859 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006860 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6861 next_tx_level, temp_tx);
6862 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006863 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306864 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6865 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006866 &next_tx_level,
6867 sizeof(next_tx_level));
6868 }
6869
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006870 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006871 if (vote_level_change || tx_level_change || rx_level_change) {
6872 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6873 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6874 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6875 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6876 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6877 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6878 hdd_ctx->hdd_txrx_hist_idx++;
6879 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6880 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07006881
6882 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006883}
6884
6885#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306886static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006887{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006888 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306889 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006890 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306891 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306892 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6893 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006894 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306895 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006896 bool connected = false;
6897 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6898
Prashanth Bhattaab004382016-10-11 16:08:11 -07006899 if (wlan_hdd_validate_context(hdd_ctx))
6900 return;
6901
Jeff Johnson214671b2017-10-30 19:45:23 -07006902 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006903 goto restart_timer;
6904
Dustin Brown920397d2017-12-13 16:27:50 -08006905 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05306906 /*
6907 * Validate magic so we don't end up accessing
6908 * an invalid adapter.
6909 */
6910 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6911 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006912
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006913 if ((adapter->device_mode == QDF_STA_MODE ||
6914 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006915 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6916 != eConnectionState_Associated) {
6917
6918 continue;
6919 }
6920
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006921 if ((adapter->device_mode == QDF_SAP_MODE ||
6922 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006923 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006924
6925 continue;
6926 }
6927
6928 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6929 adapter->prev_tx_packets);
6930 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6931 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306932
6933 if (adapter->device_mode == QDF_SAP_MODE ||
6934 adapter->device_mode == QDF_P2P_GO_MODE ||
6935 adapter->device_mode == QDF_IBSS_MODE) {
6936
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006937 ret = cdp_get_intra_bss_fwd_pkts_count(
6938 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006939 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306940 &fwd_tx_packets, &fwd_rx_packets);
6941 if (ret == A_OK) {
6942 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6943 fwd_tx_packets,
6944 adapter->prev_fwd_tx_packets);
6945 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6946 fwd_tx_packets,
6947 adapter->prev_fwd_rx_packets);
6948 }
6949 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006950
6951 total_rx += adapter->stats.rx_packets;
6952 total_tx += adapter->stats.tx_packets;
6953
6954 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6955 adapter->prev_tx_packets = adapter->stats.tx_packets;
6956 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306957 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6958 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006959 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6960 connected = true;
6961 }
6962
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306963 /* add intra bss forwarded tx and rx packets */
6964 tx_packets += fwd_tx_packets_diff;
6965 rx_packets += fwd_rx_packets_diff;
6966
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006967 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6968 tx_packets += (uint64_t)ipa_tx_packets;
6969 rx_packets += (uint64_t)ipa_rx_packets;
6970
Yun Park2aa880c2017-08-22 10:58:10 -07006971 if (adapter) {
6972 adapter->stats.tx_packets += ipa_tx_packets;
6973 adapter->stats.rx_packets += ipa_rx_packets;
6974 }
6975
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006976 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006977 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006978 return;
6979 }
6980
Yuanyuan Liu13738502016-04-06 17:41:37 -07006981 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006982
6983 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6984 hdd_ipa_uc_stat_request(adapter, 2);
6985
Jingxiang Gec64e1932017-08-22 14:38:59 +08006986restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006987 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006988 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006989 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306990 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006991 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006992 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006993}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006994
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306995/**
6996 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6997 * @arg: Argument of timer function
6998 *
6999 * Schedule a workqueue in this function where all the processing is done.
7000 *
7001 * Return: None.
7002 */
7003static void __hdd_bus_bw_cbk(void *arg)
7004{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007005 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307006
7007 if (wlan_hdd_validate_context(hdd_ctx))
7008 return;
7009
7010 schedule_work(&hdd_ctx->bus_bw_work);
7011}
7012
7013/**
7014 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7015 * @arg: Argument of timer function
7016 *
7017 * Return: None.
7018 */
7019static void hdd_bus_bw_cbk(void *arg)
7020{
7021 cds_ssr_protect(__func__);
7022 __hdd_bus_bw_cbk(arg);
7023 cds_ssr_unprotect(__func__);
7024}
7025
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007026int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007027{
7028 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307029 INIT_WORK(&hdd_ctx->bus_bw_work,
7030 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007031 hdd_ctx->bus_bw_timer_running = false;
7032 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307033 qdf_timer_init(NULL,
7034 &hdd_ctx->bus_bw_timer,
7035 hdd_bus_bw_cbk, (void *)hdd_ctx,
7036 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007037
7038 return 0;
7039}
7040
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007041void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007042{
Dustin Brownfce08d12017-01-17 16:29:38 -08007043 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007044 hdd_reset_tcp_delack(hdd_ctx);
7045
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007046 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307047 cancel_work_sync(&hdd_ctx->bus_bw_work);
7048 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007049 hdd_ctx->bus_bw_timer_running = false;
7050 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007051}
Lin Baic5c06882017-09-21 13:58:43 +08007052
7053void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7054{
7055 if (hdd_ctx)
7056 cancel_work_sync(&hdd_ctx->bus_bw_work);
7057}
jiadcdaf9bd2017-10-26 12:20:21 +08007058
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007059#endif
7060
7061/**
Nirav Shahed34b212016-04-25 10:59:16 +05307062 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7063 * @hdd_ctx: hdd context
7064 *
7065 * Return: 0 for success or error code
7066 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007067static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307068{
7069 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7070 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7071 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007072 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307073 return -ENOMEM;
7074 }
7075 return 0;
7076}
7077
7078/**
7079 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7080 * @hdd_ctx: hdd context
7081 *
7082 * Return: none
7083 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007084void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307085{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307086 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7087 return;
7088
7089 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7090 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307091}
7092
Nirav Shahda008342016-05-17 18:50:40 +05307093static uint8_t *convert_level_to_string(uint32_t level)
7094{
7095 switch (level) {
7096 /* initialize the wlan sub system */
7097 case WLAN_SVC_TP_NONE:
7098 return "NONE";
7099 case WLAN_SVC_TP_LOW:
7100 return "LOW";
7101 case WLAN_SVC_TP_MEDIUM:
7102 return "MED";
7103 case WLAN_SVC_TP_HIGH:
7104 return "HIGH";
7105 default:
7106 return "INVAL";
7107 }
7108}
7109
Nirav Shahed34b212016-04-25 10:59:16 +05307110
7111/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007112 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7113 * @hdd_ctx: hdd context
7114 *
7115 * Return: none
7116 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007117void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007118{
7119 int i;
7120
7121#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007122 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307123 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007124 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007125 hdd_ctx->config->busBandwidthHighThreshold,
7126 hdd_ctx->config->busBandwidthMediumThreshold,
7127 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007128 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307129 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007130 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007131 hdd_ctx->config->tcpDelackThresholdHigh,
7132 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007133 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307134 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007135#endif
7136
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007137 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307138 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7139
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007140 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007141
7142 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007143 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007144 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07007145 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007146 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7147 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007148 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007149 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7150 convert_level_to_string(
7151 hdd_ctx->hdd_txrx_hist[i].
7152 next_vote_level),
7153 convert_level_to_string(
7154 hdd_ctx->hdd_txrx_hist[i].
7155 next_rx_level),
7156 convert_level_to_string(
7157 hdd_ctx->hdd_txrx_hist[i].
7158 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007159 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007160}
7161
7162/**
7163 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7164 * @hdd_ctx: hdd context
7165 *
7166 * Return: none
7167 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007168void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007169{
7170 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307171 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7172 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007173}
7174
Mohit Khannaca4173b2017-09-12 21:52:19 -07007175/* length of the netif queue log needed per adapter */
7176#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7177
7178/**
7179 *
7180 * hdd_display_netif_queue_history_compact() - display compact netifq history
7181 * @hdd_ctx: hdd context
7182 *
7183 * Return: none
7184 */
7185static void
7186hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7187{
7188 int adapter_num = 0;
7189 int i;
7190 int bytes_written;
7191 u32 tbytes;
7192 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007193 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007194 char *comb_log_str;
7195 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007196 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007197
jiadbdefb252018-01-03 14:27:06 +08007198 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7199 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7200 if (!comb_log_str) {
7201 hdd_err("failed to alloc comb_log_str");
7202 return;
7203 }
7204
Mohit Khannaca4173b2017-09-12 21:52:19 -07007205 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007206
Dustin Brown920397d2017-12-13 16:27:50 -08007207 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007208 curr_time = qdf_system_ticks();
7209 total = curr_time - adapter->start_time;
7210 delta = curr_time - adapter->last_time;
7211
7212 if (adapter->pause_map) {
7213 pause = adapter->total_pause_time + delta;
7214 unpause = adapter->total_unpause_time;
7215 } else {
7216 unpause = adapter->total_unpause_time + delta;
7217 pause = adapter->total_pause_time;
7218 }
7219
7220 tbytes = 0;
7221 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7222 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7223 if (adapter->queue_oper_stats[i].pause_count == 0)
7224 continue;
7225 tbytes +=
7226 snprintf(
7227 &temp_str[tbytes],
7228 (tbytes >= sizeof(temp_str) ?
7229 0 : sizeof(temp_str) - tbytes),
7230 "%d(%d,%d) ",
7231 i,
7232 adapter->queue_oper_stats[i].
7233 pause_count,
7234 adapter->queue_oper_stats[i].
7235 unpause_count);
7236 }
7237 if (tbytes >= sizeof(temp_str))
7238 hdd_warn("log truncated");
7239
7240 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007241 bytes_written >= comb_log_str_size ? 0 :
7242 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007243 "[%d %d] (%d) %u/%ums %s|",
7244 adapter->session_id, adapter->device_mode,
7245 adapter->pause_map,
7246 qdf_system_ticks_to_msecs(pause),
7247 qdf_system_ticks_to_msecs(total),
7248 temp_str);
7249
Mohit Khannaca4173b2017-09-12 21:52:19 -07007250 adapter_num++;
7251 }
7252
7253 /* using QDF_TRACE to avoid printing function name */
7254 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7255 "STATS |%s", comb_log_str);
7256
jiadbdefb252018-01-03 14:27:06 +08007257 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007258 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007259
7260 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007261}
7262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007263/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007264 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007265 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007266 *
7267 * Return: none
7268 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007269void
7270wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7271 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007272{
7273
Jeff Johnson9d295242017-08-29 14:39:48 -07007274 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007275 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307276 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007277
Mohit Khannaca4173b2017-09-12 21:52:19 -07007278 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7279 hdd_display_netif_queue_history_compact(hdd_ctx);
7280 return;
7281 }
7282
Dustin Brown920397d2017-12-13 16:27:50 -08007283 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007284 hdd_debug("Netif queue operation statistics:");
7285 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007286 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007287 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307288 curr_time = qdf_system_ticks();
7289 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307290 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307291 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307292 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307293 unpause = adapter->total_unpause_time;
7294 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307295 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307296 pause = adapter->total_pause_time;
7297 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007298 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307299 qdf_system_ticks_to_msecs(total),
7300 qdf_system_ticks_to_msecs(pause),
7301 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007302 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007303
Nirav Shahda008342016-05-17 18:50:40 +05307304 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7305 qdf_time_t pause_delta = 0;
7306
7307 if (adapter->pause_map & (1 << i))
7308 pause_delta = delta;
7309
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007310 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07007311 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007312 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007313 hdd_reason_type_to_string(i),
7314 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05307315 adapter->queue_oper_stats[i].unpause_count,
7316 qdf_system_ticks_to_msecs(
7317 adapter->queue_oper_stats[i].total_pause_time +
7318 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007319 }
7320
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007321 hdd_debug("Netif queue operation history:");
7322 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307323 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7324
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007325 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007326
7327 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007328 /* using hdd_log to avoid printing function name */
7329 if (adapter->queue_oper_history[i].time == 0)
7330 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07007331 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007332 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05307333 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007334 adapter->queue_oper_history[i].time),
7335 hdd_action_type_to_string(
7336 adapter->queue_oper_history[i].netif_action),
7337 hdd_reason_type_to_string(
7338 adapter->queue_oper_history[i].netif_reason),
7339 adapter->queue_oper_history[i].pause_map);
7340 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007341 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342}
7343
7344/**
7345 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7346 * @hdd_ctx: hdd context
7347 *
7348 * Return: none
7349 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007350void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351{
Jeff Johnson9d295242017-08-29 14:39:48 -07007352 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007353
Dustin Brown920397d2017-12-13 16:27:50 -08007354 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307355 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007356 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307357 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007358 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307359 adapter->history_index = 0;
7360 adapter->start_time = adapter->last_time = qdf_system_ticks();
7361 adapter->total_pause_time = 0;
7362 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007363 }
7364}
7365
7366/**
7367 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7368 * @halHandle: Hal handle
7369 * @pContext: Pointer to the context
7370 * @sessionId: Session ID
7371 * @scanId: Scan ID
7372 * @status: Status
7373 *
7374 * This is the callback to be executed when 11d scan is completed to flush out
7375 * the scan results
7376 *
7377 * 11d scan is done during driver load and is a passive scan on all
7378 * channels supported by the device, 11d scans may find some APs on
7379 * frequencies which are forbidden to be used in the regulatory domain
7380 * the device is operating in. If these APs are notified to the supplicant
7381 * it may try to connect to these APs, thus flush out all the scan results
7382 * which are present in SME after 11d scan is done.
7383 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307384 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007385 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307386static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007387 uint8_t sessionId, uint32_t scanId,
7388 eCsrScanStatus status)
7389{
7390 ENTER();
7391
7392 sme_scan_flush_result(halHandle);
7393
7394 EXIT();
7395
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307396 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007397}
7398
7399#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7400/**
7401 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7402 * @hdd_ctx: hdd global context
7403 *
7404 * Return: none
7405 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007406static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007407{
7408 uint8_t i;
7409
7410 mutex_init(&hdd_ctx->op_ctx.op_lock);
7411 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7412 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7413 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7414 }
7415}
7416#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007417static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007418{
7419}
7420#endif
7421
Yingying Tang95409972016-10-20 15:16:15 +08007422#ifdef WLAN_FEATURE_WOW_PULSE
7423/**
7424 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007425 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007426 * @enable: enable or disable this behaviour
7427 *
7428 * Return: int
7429 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007430static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007431{
7432 struct hdd_config *pcfg_ini = phddctx->config;
7433 struct wow_pulse_mode wow_pulse_set_info;
7434 QDF_STATUS status;
7435
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007436 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007437
7438 if (false == phddctx->config->wow_pulse_support)
7439 return 0;
7440
7441 /* prepare the request to send to SME */
7442 if (enable == true) {
7443 wow_pulse_set_info.wow_pulse_enable = true;
7444 wow_pulse_set_info.wow_pulse_pin =
7445 pcfg_ini->wow_pulse_pin;
7446 wow_pulse_set_info.wow_pulse_interval_low =
7447 pcfg_ini->wow_pulse_interval_low;
7448 wow_pulse_set_info.wow_pulse_interval_high =
7449 pcfg_ini->wow_pulse_interval_high;
7450 } else {
7451 wow_pulse_set_info.wow_pulse_enable = false;
7452 wow_pulse_set_info.wow_pulse_pin = 0;
7453 wow_pulse_set_info.wow_pulse_interval_low = 0;
7454 wow_pulse_set_info.wow_pulse_interval_high = 0;
7455 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007456 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007457 wow_pulse_set_info.wow_pulse_enable,
7458 wow_pulse_set_info.wow_pulse_pin,
7459 wow_pulse_set_info.wow_pulse_interval_low,
7460 wow_pulse_set_info.wow_pulse_interval_high);
7461
7462 status = sme_set_wow_pulse(&wow_pulse_set_info);
7463 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007464 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007465 return -EIO;
7466 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007467 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007468 return 0;
7469}
7470#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007471static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007472{
7473 return 0;
7474}
7475#endif
7476
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007477#ifdef WLAN_FEATURE_FASTPATH
7478/**
7479 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7480 * @hdd_cfg: hdd config
7481 * @context: lower layer context
7482 *
7483 * Return: none
7484 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307485void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007486 void *context)
7487{
7488 if (hdd_cfg->fastpath_enable)
7489 hif_enable_fastpath(context);
7490}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007491#endif
7492
Yuanyuan Liu13738502016-04-06 17:41:37 -07007493#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007494/**
7495 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007496 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007497 * @level: thermal level
7498 *
7499 * Change IPA data path to SW path when the thermal throttle level greater
7500 * than 0, and restore the original data path when throttle level is 0
7501 *
7502 * Return: none
7503 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007504static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007505{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007506 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007507
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007508 /* Change IPA to SW path when throttle level greater than 0 */
7509 if (level > THROTTLE_LEVEL_0)
7510 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7511 else
7512 /* restore original concurrency mode */
7513 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7514}
7515
7516/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307517 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7518 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307519 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007520 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307521 * Get a safe channel to restart SAP. PCL already takes into account the
7522 * unsafe channels. So, the PCL is validated with the ACS range to provide
7523 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007524 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307525 * Return: Channel number to restart SAP in case of success. In case of any
7526 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007527 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307528static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007529 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007530{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307531 struct sir_pcl_list pcl;
7532 QDF_STATUS status;
7533 uint32_t i, j;
7534 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007535 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307536 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007537 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007538
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307539 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7540 if (!hdd_ctx) {
7541 hdd_err("invalid HDD context");
7542 return INVALID_CHANNEL_ID;
7543 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007544
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307545 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7546 if (!hal_handle) {
7547 hdd_err("invalid HAL handle");
7548 return INVALID_CHANNEL_ID;
7549 }
7550
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007551 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7552 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007553 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7554 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307555 if (QDF_IS_STATUS_ERROR(status)) {
7556 hdd_err("Get PCL failed");
7557 return INVALID_CHANNEL_ID;
7558 }
7559
Frank Liudc2cefb2017-06-21 15:38:18 +08007560 /*
7561 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7562 * channel is unsafe channel, the pcl may be empty, instead of return,
7563 * try to choose a safe channel from acs range.
7564 */
7565 if (!pcl.pcl_len)
7566 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307567
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007568 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007569 adapter->session.ap.sap_config.acs_cfg.start_ch,
7570 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307571
7572 /* PCL already takes unsafe channel into account */
7573 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007574 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307575 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007576 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307577 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007578 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007579 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307580 return pcl.pcl_list[i];
7581 }
7582 }
7583
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007584 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307585
7586 /* Try for safe channel from all valid channel */
7587 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007588 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7589 &pcl.pcl_len);
7590 if (ret) {
7591 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307592 return INVALID_CHANNEL_ID;
7593 }
7594
7595 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007596 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307597 found = false;
7598 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007599 if (pcl.pcl_list[i] ==
7600 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007601 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307602 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007603 break;
7604 }
7605 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307606
7607 if (found)
7608 continue;
7609
7610 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007611 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307612 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007613 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007614 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307615 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007616 }
7617 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307618
7619 return INVALID_CHANNEL_ID;
7620}
7621
7622/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007623 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307624 * @adapter: AP adapter
7625 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007626 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307627 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007628 * Moves the SAP interface by invoking the function which
7629 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307630 *
7631 * Return: None
7632 */
Min Liu2fef5792018-01-19 17:59:42 +08007633void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7634 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307635{
Jeff Johnson87251032017-08-29 13:31:11 -07007636 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307637 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007638 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307639
7640 if (!adapter) {
7641 hdd_err("invalid adapter");
7642 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007643 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307644
7645 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7646
7647 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7648 if (!hal_handle) {
7649 hdd_err("invalid HAL handle");
7650 return;
7651 }
7652
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007653 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7654
Jeff Johnson91df29d2017-10-27 19:29:50 -07007655 hdd_ap_ctx->sap_config.channel = channel;
7656 hdd_ap_ctx->sap_config.ch_params.ch_width =
7657 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307658
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007659 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007660 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307661
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007662 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007663 hdd_ap_ctx->sap_config.channel,
7664 hdd_ap_ctx->sap_config.sec_ch,
7665 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307666
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007667 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007668 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007669 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007670}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307671
Jeff Johnson9d295242017-08-29 14:39:48 -07007672int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307673{
7674 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307675 int status;
7676 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307677
7678 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7679
7680 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007681 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307682 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007683 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307684 }
7685 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007686 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307687 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307688 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007689 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307690 WLAN_VENDOR_ACS_WAIT_TIME);
7691 if (qdf_status != QDF_STATUS_SUCCESS) {
7692 hdd_err("failed to start external acs timer");
7693 return -ENOSPC;
7694 }
7695 /* Update config to application */
7696 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307697 hdd_notice("Updated ACS config to nl with reason %d", reason);
7698
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307699 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307700}
7701
Agrawal Ashish467dde42016-09-08 18:44:22 +05307702/**
7703 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7704 * @hdd_ctx: hdd context pointer
7705 *
7706 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7707 * and if ACS is enabled, driver will ask userspace to restart the
7708 * sap. User space on LTE coex indication restart driver.
7709 *
7710 * Return - none
7711 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007712void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307713{
Dustin Brown920397d2017-12-13 16:27:50 -08007714 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307715 uint32_t i;
7716 bool found = false;
7717 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007718
Dustin Brown920397d2017-12-13 16:27:50 -08007719 hdd_for_each_adapter(hdd_ctxt, adapter) {
7720 if (!(adapter->device_mode == QDF_SAP_MODE &&
7721 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007722 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007723 adapter->device_mode,
7724 adapter->session.ap.sap_config.
7725 acs_cfg.acs_mode);
7726 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307727 }
7728
7729 found = false;
7730 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007731 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307732 hdd_ctxt->unsafe_channel_list[i]) {
7733 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007734 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007735 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307736 break;
7737 }
7738 }
7739
7740 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007741 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007742 adapter->session.ap.operating_channel);
7743 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307744 }
7745
Kapil Gupta8878ad92017-02-13 11:56:04 +05307746 if (hdd_ctxt->config->vendor_acs_support &&
7747 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007748 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307749 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007750 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307751 } else
7752 restart_chan =
7753 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007754 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307755 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007756 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307757 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007758 /*
7759 * SAP restart due to unsafe channel. While
7760 * restarting the SAP, make sure to clear
7761 * acs_channel, channel to reset to
7762 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307763 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007764 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307765 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007766 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307767 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007768 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307769 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7770 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007771 hdd_debug("driver to start sap: %d",
7772 hdd_ctxt->config->sap_internal_restart);
7773 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08007774 hdd_switch_sap_channel(adapter, restart_chan,
7775 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04007776 else
7777 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307778 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307779 }
7780}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307781
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007782/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007783 * hdd_init_channel_avoidance() - Initialize channel avoidance
7784 * @hdd_ctx: HDD global context
7785 *
7786 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007787 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007788 * down to the lower layers. Then subscribe to subsequent channel
7789 * avoidance events.
7790 *
7791 * Return: None
7792 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007793static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007794{
7795 uint16_t unsafe_channel_count;
7796 int index;
7797
Yuanyuan Liu13738502016-04-06 17:41:37 -07007798 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7799 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007800 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007801 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007802
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007803 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007804 hdd_ctx->unsafe_channel_count);
7805
Anurag Chouhan6d760662016-02-20 16:05:43 +05307806 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007807 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007808
7809 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007810 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007811 hdd_ctx->unsafe_channel_list[index]);
7812
7813 }
7814
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007815}
Dustin Brown676a2322017-08-15 13:16:13 -07007816
Jeff Johnson9d295242017-08-29 14:39:48 -07007817static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007818 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007819{
7820 uint8_t restart_chan;
7821
7822 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7823 if (!restart_chan) {
7824 hdd_alert("fail to restart SAP");
7825 return;
7826 }
7827
7828 /* SAP restart due to unsafe channel. While restarting
7829 * the SAP, make sure to clear acs_channel, channel to
7830 * reset to 0. Otherwise these settings will override
7831 * the ACS while restart.
7832 */
7833 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007834 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007835
7836 hdd_debug("sending coex indication");
7837
7838 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7839 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08007840 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07007841}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007842
7843int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7844 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7845{
7846 uint32_t size;
7847 uint16_t *unsafe_list;
7848 uint16_t chan_count;
7849
7850 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7851 return -EINVAL;
7852
7853 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7854 NUM_CHANNELS);
7855 if (chan_count) {
7856 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7857 unsafe_list = qdf_mem_malloc(size);
7858 if (!unsafe_list) {
7859 hdd_err("No memory for unsafe chan list size%d",
7860 size);
7861 return -ENOMEM;
7862 }
7863 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7864 } else {
7865 unsafe_list = NULL;
7866 }
7867
7868 *local_unsafe_list = unsafe_list;
7869 *local_unsafe_list_count = chan_count;
7870
7871 return 0;
7872}
7873
7874bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7875 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7876{
7877 int i, j;
7878
7879 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7880 return true;
7881 if (local_unsafe_list_count == 0)
7882 return false;
7883 for (i = 0; i < local_unsafe_list_count; i++) {
7884 for (j = 0; j < local_unsafe_list_count; j++)
7885 if (local_unsafe_list[i] ==
7886 hdd_ctx->unsafe_channel_list[j])
7887 break;
7888 if (j >= local_unsafe_list_count)
7889 break;
7890 }
7891 if (i >= local_unsafe_list_count) {
7892 hdd_info("unsafe chan list same");
7893 return false;
7894 }
7895
7896 return true;
7897}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007898#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007899static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007900{
7901}
Dustin Brown676a2322017-08-15 13:16:13 -07007902
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007903static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007904{
7905}
Dustin Brown676a2322017-08-15 13:16:13 -07007906
Jeff Johnson9d295242017-08-29 14:39:48 -07007907static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007908 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007909{
7910 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7911}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007912#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007913
7914/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007915 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7916 * user space
7917 * @frame_ind: Management frame data to be informed.
7918 *
7919 * This function is used to indicate management frame to
7920 * user space
7921 *
7922 * Return: None
7923 *
7924 */
7925void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7926{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007927 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007928 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007929 int i;
7930
Rajeev Kumard004abc2016-02-17 12:09:56 -08007931 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007932 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007933
7934 if (0 != wlan_hdd_validate_context(hdd_ctx))
7935 return;
7936
7937 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7938 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7939 adapter =
7940 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7941 if (adapter)
7942 break;
7943 }
Wu Gaoa0230a62018-01-04 20:56:57 +08007944 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
7945 hdd_for_each_adapter(hdd_ctx, adapter) {
7946 if ((NULL != adapter) &&
7947 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
7948 __hdd_indicate_mgmt_frame(adapter,
7949 frame_ind->frame_len,
7950 frame_ind->frameBuf,
7951 frame_ind->frameType,
7952 frame_ind->rxChan,
7953 frame_ind->rxRssi);
7954 }
7955 }
7956 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007957 } else {
7958 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7959 frame_ind->sessionId);
7960 }
7961
7962 if ((NULL != adapter) &&
7963 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7964 __hdd_indicate_mgmt_frame(adapter,
7965 frame_ind->frame_len,
7966 frame_ind->frameBuf,
7967 frame_ind->frameType,
7968 frame_ind->rxChan,
7969 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007970}
7971
Kapil Gupta8878ad92017-02-13 11:56:04 +05307972void hdd_acs_response_timeout_handler(void *context)
7973{
7974 struct hdd_external_acs_timer_context *timer_context =
7975 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007976 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007977 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307978 uint8_t reason;
7979
7980 ENTER();
7981 if (!timer_context) {
7982 hdd_err("invlaid timer context");
7983 return;
7984 }
7985 adapter = timer_context->adapter;
7986 reason = timer_context->reason;
7987
7988
7989 if ((!adapter) ||
7990 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7991 hdd_err("invalid adapter or adapter has invalid magic");
7992 return;
7993 }
7994 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7995 if (wlan_hdd_validate_context(hdd_ctx))
7996 return;
7997
7998 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7999 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8000 else
8001 return;
8002
8003 hdd_err("ACS timeout happened for %s reason %d",
8004 adapter->dev->name, reason);
8005 switch (reason) {
8006 /* SAP init case */
8007 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8008 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8009 false);
8010 wlan_hdd_cfg80211_start_acs(adapter);
8011 break;
8012 /* DFS detected on current channel */
8013 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8014 wlan_sap_update_next_channel(
8015 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8016 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008017 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308018 break;
8019 /* LTE coex event on current channel */
8020 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8021 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8022 break;
8023 default:
8024 hdd_info("invalid reason for timer invoke");
8025
8026 }
8027}
8028
Rajeev Kumard004abc2016-02-17 12:09:56 -08008029/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008030 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
8031 * @hdd_ctx: HDD context
8032 *
8033 * Disables all the dual mac features like DBS, Agile DFS etc.
8034 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308035 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008036 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008037static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008038{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008039 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308040 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008041
8042 if (!hdd_ctx) {
8043 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308044 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008045 }
8046
8047 cfg.scan_config = 0;
8048 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008049 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008050
8051 hdd_debug("Disabling all dual mac features...");
8052
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008053 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308054 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008055 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8056 return status;
8057 }
8058
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308059 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008060}
8061
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008062static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008063wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008064{
8065 struct policy_mgr_dual_mac_config cfg = {0};
8066 QDF_STATUS status;
8067
8068 if (!hdd_ctx) {
8069 hdd_err("HDD context is NULL");
8070 return QDF_STATUS_E_FAILURE;
8071 }
8072
8073 cfg.scan_config = 0;
8074 cfg.fw_mode_config = 0;
8075 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
8076 status = policy_mgr_get_updated_scan_and_fw_mode_config(
8077 hdd_ctx->hdd_psoc, &cfg.scan_config,
8078 &cfg.fw_mode_config,
8079 hdd_ctx->config->dual_mac_feature_disable);
8080
8081 if (status != QDF_STATUS_SUCCESS) {
8082 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
8083 status);
8084 return status;
8085 }
8086
8087 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
8088 cfg.scan_config, cfg.fw_mode_config);
8089
8090 status = sme_soc_set_dual_mac_config(cfg);
8091 if (status != QDF_STATUS_SUCCESS) {
8092 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8093 return status;
8094 }
8095
8096 return QDF_STATUS_SUCCESS;
8097}
8098
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008099/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008100 * hdd_override_ini_config - Override INI config
8101 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008102 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008103 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008104 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008105 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008106 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008107static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008108{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008109
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008110 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8111 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008112 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008113 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008114 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008115 if (0 == enable_11d || 1 == enable_11d) {
8116 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008117 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008118 }
Leo Chang11545d62016-10-17 14:53:50 -07008119
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008120 if (!hdd_ipa_is_present(hdd_ctx)) {
Leo Chang11545d62016-10-17 14:53:50 -07008121 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008122 hdd_debug("IpaConfig override to %d",
8123 hdd_ctx->config->IpaConfig);
8124 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308125
8126 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8127 !hdd_ctx->config->enable_bcast_probe_rsp) {
8128 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8129 hdd_ctx->config->rssi_assoc_reject_enabled,
8130 hdd_ctx->config->enable_bcast_probe_rsp);
8131 hdd_ctx->config->oce_sta_enabled = 0;
8132 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008133}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008134
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008135/**
8136 * hdd_set_trace_level_for_each - Set trace level for each INI config
8137 * @hdd_ctx - HDD context
8138 *
8139 * Set trace level for each module based on INI config.
8140 *
8141 * Return: None
8142 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008143static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008144{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308145 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8146 hdd_ctx->config->qdf_trace_enable_wdi);
8147 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8148 hdd_ctx->config->qdf_trace_enable_hdd);
8149 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8150 hdd_ctx->config->qdf_trace_enable_sme);
8151 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8152 hdd_ctx->config->qdf_trace_enable_pe);
8153 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8154 hdd_ctx->config->qdf_trace_enable_wma);
8155 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8156 hdd_ctx->config->qdf_trace_enable_sys);
8157 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8158 hdd_ctx->config->qdf_trace_enable_qdf);
8159 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8160 hdd_ctx->config->qdf_trace_enable_sap);
8161 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8162 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8163 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8164 hdd_ctx->config->qdf_trace_enable_bmi);
8165 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8166 hdd_ctx->config->qdf_trace_enable_cfg);
8167 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8168 hdd_ctx->config->qdf_trace_enable_epping);
8169 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8170 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8171 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008172 hdd_ctx->config->qdf_trace_enable_txrx);
8173 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8174 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308175 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8176 hdd_ctx->config->qdf_trace_enable_htc);
8177 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8178 hdd_ctx->config->qdf_trace_enable_hif);
8179 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8180 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8181 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8182 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008183 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8184 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008185 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8186 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008187 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8188 hdd_ctx->config->qdf_trace_enable_regulatory);
8189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008190 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008191}
8192
8193/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008194 * hdd_context_init() - Initialize HDD context
8195 * @hdd_ctx: HDD context.
8196 *
8197 * Initialize HDD context along with all the feature specific contexts.
8198 *
8199 * return: 0 on success and errno on failure.
8200 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008201static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008202{
8203 int ret;
8204
8205 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8206 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8207
8208 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308209 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008210
8211 init_completion(&hdd_ctx->mc_sus_event_var);
8212 init_completion(&hdd_ctx->ready_to_suspend);
8213
8214 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308215 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008216 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308217
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008218 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008219
8220 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8221
8222 ret = hdd_scan_context_init(hdd_ctx);
8223 if (ret)
8224 goto list_destroy;
8225
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008226 hdd_rx_wake_lock_create(hdd_ctx);
8227
8228 ret = hdd_sap_context_init(hdd_ctx);
8229 if (ret)
8230 goto scan_destroy;
8231
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008232 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8233
8234 hdd_init_offloaded_packets_ctx(hdd_ctx);
8235
8236 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8237 hdd_ctx->config);
8238 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008239 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008240
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308241 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8242 "monitor_mode_wakelock");
8243
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008244 return 0;
8245
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008246sap_destroy:
8247 hdd_sap_context_destroy(hdd_ctx);
8248
8249scan_destroy:
8250 hdd_scan_context_destroy(hdd_ctx);
8251 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008252list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008253 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008254
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008255 return ret;
8256}
8257
8258/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308259 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8260 * @hdd_ctx: pointer to hdd context
8261 *
8262 * Return: status of initialization
8263 * 0 - success
8264 * negative value - failure
8265 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008266static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308267{
8268 int ret;
8269
8270 if (!hdd_ctx->config->probe_req_ie_whitelist)
8271 return 0;
8272
8273 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8274 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8275 hdd_ctx->config->probe_req_ie_whitelist = false;
8276 return -EINVAL;
8277 }
8278
8279 /* parse ini string probe req oui */
8280 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8281 if (ret) {
8282 hdd_err("parsing error: disable ie whitelisting");
8283 hdd_ctx->config->probe_req_ie_whitelist = false;
8284 }
8285
8286 return ret;
8287}
8288
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308289
8290/**
8291 * hdd_iface_change_callback() - Function invoked when stop modules expires
8292 * @priv: pointer to hdd context
8293 *
8294 * This function is invoked when the timer waiting for the interface change
8295 * expires, it shall cut-down the power to wlan and stop all the modules.
8296 *
8297 * Return: void
8298 */
8299static void hdd_iface_change_callback(void *priv)
8300{
8301 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8302 int ret;
8303 int status = wlan_hdd_validate_context(hdd_ctx);
8304
8305 if (status)
8306 return;
8307
8308 ENTER();
8309 hdd_debug("Interface change timer expired close the modules!");
8310 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8311 if (ret)
8312 hdd_err("Failed to stop modules");
8313 EXIT();
8314}
8315
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308316/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008317 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308318 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008319 *
8320 * Allocate and initialize HDD context. HDD context is allocated as part of
8321 * wiphy allocation and then context is initialized.
8322 *
8323 * Return: HDD context on success and ERR_PTR on failure
8324 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008325static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008326{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308327 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008328 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008329 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008330
8331 ENTER();
8332
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008333 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008334 if (hdd_ctx == NULL) {
8335 ret = -ENOMEM;
8336 goto err_out;
8337 }
8338
Dustin Brown6f427922017-09-19 12:19:00 -07008339 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8340 hdd_iface_change_callback,
8341 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308342
8343 mutex_init(&hdd_ctx->iface_change_lock);
8344
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008345 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308346 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008347
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308348 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008349 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008350 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008351 ret = -ENOMEM;
8352 goto err_free_hdd_context;
8353 }
8354
8355 /* Read and parse the qcom_cfg.ini file */
8356 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308357 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308358 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008359 WLAN_INI_FILE);
8360 ret = -EINVAL;
8361 goto err_free_config;
8362 }
8363
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308364 ie_whitelist_attrs_init(hdd_ctx);
8365
Dustin Brown7f939932017-05-18 15:02:17 -07008366 hdd_debug("setting timer multiplier: %u",
8367 hdd_ctx->config->timer_multiplier);
8368 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8369
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008370
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308371 if (hdd_ctx->config->fhostNSOffload)
8372 hdd_ctx->ns_offload_enable = true;
8373
Abhishek Singh5ea86532016-04-27 14:10:53 +05308374 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8375
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008376 hdd_override_ini_config(hdd_ctx);
8377
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008378 ret = hdd_context_init(hdd_ctx);
8379
8380 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008381 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008382
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008383 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308384 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008385
Anurag Chouhan6d760662016-02-20 16:05:43 +05308386 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008387 goto skip_multicast_logging;
8388
8389 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8390
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008391 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8392 if (ret)
8393 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308394
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008395 ret = hdd_init_netlink_services(hdd_ctx);
8396 if (ret)
8397 goto err_deinit_txrx_histogram;
8398
Dustin Brown7b3dea22017-07-10 13:02:47 -07008399 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
8400 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05308401
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008402skip_multicast_logging:
8403 hdd_set_trace_level_for_each(hdd_ctx);
8404
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008405 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8406
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008407 EXIT();
8408
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008409 return hdd_ctx;
8410
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008411err_deinit_txrx_histogram:
8412 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8413
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008414err_deinit_hdd_context:
8415 hdd_context_deinit(hdd_ctx);
8416
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008417err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308418 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008419
8420err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308421 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008422 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008423
8424err_out:
8425 return ERR_PTR(ret);
8426}
8427
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008428#ifdef WLAN_OPEN_P2P_INTERFACE
8429/**
8430 * hdd_open_p2p_interface - Open P2P interface
8431 * @hdd_ctx: HDD context
8432 * @rtnl_held: True if RTNL lock held
8433 *
8434 * Open P2P interface during probe. This function called to open the P2P
8435 * interface at probe along with STA interface.
8436 *
8437 * Return: 0 on success and errno on failure
8438 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008439static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008440{
Jeff Johnson9d295242017-08-29 14:39:48 -07008441 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008442 uint8_t *p2p_dev_addr;
8443
8444 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8445 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008446 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008447 hdd_ctx->config->intfMacAddr[0].bytes,
8448 sizeof(tSirMacAddr));
8449
8450 /*
8451 * Generate the P2P Device Address. This consists of
8452 * the device's primary MAC address with the locally
8453 * administered bit set.
8454 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008455 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008456 } else {
8457 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8458 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008459 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008460 return -ENOSPC;
8461 }
8462
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008463 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8464 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008465 }
8466
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008467 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008468 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008469 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008470
8471 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008472 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008473 return -ENOSPC;
8474 }
8475
8476 return 0;
8477}
8478#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008479static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008480 bool rtnl_held)
8481{
8482 return 0;
8483}
8484#endif
8485
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008486static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008487{
Jeff Johnson9d295242017-08-29 14:39:48 -07008488 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008489 int ret = 0;
8490
8491 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8492 wlan_hdd_get_intf_addr(hdd_ctx),
8493 NET_NAME_UNKNOWN, rtnl_held);
8494 if (adapter == NULL) {
8495 hdd_err("Failed to open 802.11p interface");
8496 ret = -ENOSPC;
8497 }
8498
8499 return ret;
8500}
8501
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008502/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308503 * hdd_start_station_adapter()- Start the Station Adapter
8504 * @adapter: HDD adapter
8505 *
8506 * This function initializes the adapter for the station mode.
8507 *
8508 * Return: 0 on success or errno on failure.
8509 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008510int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308511{
8512 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008513 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308514
8515 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008516 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8517 hdd_err("session is already opened, %d",
8518 adapter->session_id);
8519 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8520 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308521
Krunal Sonib51eec72017-11-20 21:53:01 -08008522 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8523 if (ret) {
8524 hdd_err("failed to create vdev: %d", ret);
8525 return ret;
8526 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308527 status = hdd_init_station_mode(adapter);
8528
8529 if (QDF_STATUS_SUCCESS != status) {
8530 hdd_err("Error Initializing station mode: %d", status);
8531 return qdf_status_to_os_return(status);
8532 }
8533
Arun Khandavallifae92942016-08-01 13:31:08 +05308534 hdd_register_tx_flow_control(adapter,
8535 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008536 hdd_tx_resume_cb,
8537 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308538
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308539 EXIT();
8540 return 0;
8541}
8542
8543/**
8544 * hdd_start_ap_adapter()- Start AP Adapter
8545 * @adapter: HDD adapter
8546 *
8547 * This function initializes the adapter for the AP mode.
8548 *
8549 * Return: 0 on success errno on failure.
8550 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008551int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308552{
8553 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008554 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008555 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008556 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308557
8558 ENTER();
8559
Krunal Sonib51eec72017-11-20 21:53:01 -08008560 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8561 hdd_err("session is already opened, %d",
8562 adapter->session_id);
8563 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8564 }
8565 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008566 * In SSR case no need to create new sap context.
8567 * Otherwise create sap context first and then create
8568 * vdev as while creating the vdev, driver needs to
8569 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008570 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008571 if (adapter->session.ap.sap_context) {
8572 is_ssr = true;
8573 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008574 hdd_err("sap creation failed");
8575 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8576 }
8577
8578 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8579 adapter->session.ap.sap_context);
8580 if (ret) {
8581 hdd_err("failed to create vdev, status:%d", ret);
8582 hdd_sap_destroy_ctx(adapter);
8583 return ret;
8584 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008585
8586 if (adapter->device_mode == QDF_SAP_MODE)
8587 sme_cli_set_command(adapter->session_id,
8588 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8589 (bool)(hdd_ctx->config->fine_time_meas_cap &
8590 WMI_FW_AP_RTT_RESPR),
8591 VDEV_CMD);
8592
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008593 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308594
8595 if (QDF_STATUS_SUCCESS != status) {
8596 hdd_err("Error Initializing the AP mode: %d", status);
8597 return qdf_status_to_os_return(status);
8598 }
8599
Arun Khandavallifae92942016-08-01 13:31:08 +05308600 hdd_register_tx_flow_control(adapter,
8601 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008602 hdd_softap_tx_resume_cb,
8603 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308604
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308605 EXIT();
8606 return 0;
8607}
8608
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308609static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8610 bool rtnl_held)
8611{
8612 struct hdd_adapter *adapter;
8613
8614 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8615 hdd_ctx->config->enableConcurrentSTA,
8616 wlan_hdd_get_intf_addr(hdd_ctx),
8617 NET_NAME_UNKNOWN, rtnl_held);
8618
8619 if (!adapter)
8620 return -ENOSPC;
8621
8622 return 0;
8623}
8624
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308625/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008626 * hdd_open_interfaces - Open all required interfaces
8627 * hdd_ctx: HDD context
8628 * rtnl_held: True if RTNL lock is held
8629 *
8630 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8631 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008632 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008633 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008634static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008635{
Jeff Johnson9d295242017-08-29 14:39:48 -07008636 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008637 int ret;
8638
Ravi Joshia307f632017-07-17 23:41:41 -07008639 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008640 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8641 con_mode == QDF_GLOBAL_FTM_MODE) {
8642 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8643 QDF_MONITOR_MODE : QDF_FTM_MODE;
8644
8645 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8646 wlan_hdd_get_intf_addr(hdd_ctx),
8647 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008648 if (!adapter) {
8649 hdd_err("open adapter failed");
8650 return -ENOSPC;
8651 }
Lin Bai1c678482017-12-18 18:29:11 +08008652
Ravi Joshia307f632017-07-17 23:41:41 -07008653 return 0;
8654 }
8655
Jeff Johnson957bc272017-02-02 08:54:48 -08008656 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308657 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008658 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008659
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008660 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008661 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008662 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008663
8664 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008665 return -ENOSPC;
8666
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308667 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8668 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8669 if (ret)
8670 hdd_err("Cannot create concurrent STA interface");
8671 }
8672
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008673 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8674 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008675 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008676
8677 /* Open 802.11p Interface */
8678 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008679 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8680 if (ret)
8681 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008682 }
8683
Jeff Johnson957bc272017-02-02 08:54:48 -08008684 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008685
Jeff Johnson957bc272017-02-02 08:54:48 -08008686err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008687 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008688 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008689}
8690
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008691
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308692#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8693/**
8694 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8695 * @cds_cfg: CDS Configuration
8696 * @hdd_ctx: Pointer to hdd context
8697 *
8698 * Return: none
8699 */
8700static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8701 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008702 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308703{
8704 cds_cfg->tx_flow_stop_queue_th =
8705 hdd_ctx->config->TxFlowStopQueueThreshold;
8706 cds_cfg->tx_flow_start_queue_offset =
8707 hdd_ctx->config->TxFlowStartQueueOffset;
8708}
8709#else
8710static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8711 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008712 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308713{
8714}
8715#endif
8716
8717#ifdef FEATURE_WLAN_RA_FILTERING
8718/**
8719 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8720 * @cds_cfg: CDS Configuration
8721 * @hdd_ctx: Pointer to hdd context
8722 *
8723 * Return: none
8724 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308725static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008726 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308727{
8728 cds_cfg->ra_ratelimit_interval =
8729 hdd_ctx->config->RArateLimitInterval;
8730 cds_cfg->is_ra_ratelimit_enabled =
8731 hdd_ctx->config->IsRArateLimitEnabled;
8732}
8733#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308734static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008735 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308736{
8737}
8738#endif
8739
8740/**
8741 * hdd_update_cds_config() - API to update cds configuration parameters
8742 * @hdd_ctx: HDD Context
8743 *
8744 * Return: 0 for Success, errno on failure
8745 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008746static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308747{
8748 struct cds_config_info *cds_cfg;
8749
8750 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8751 if (!cds_cfg) {
8752 hdd_err("failed to allocate cds config");
8753 return -ENOMEM;
8754 }
8755
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008756 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008757 if (!hdd_ctx->config->nMaxPsPoll ||
8758 !hdd_ctx->config->enablePowersaveOffload) {
8759 cds_cfg->powersave_offload_enabled =
8760 hdd_ctx->config->enablePowersaveOffload;
8761 } else {
8762 if ((hdd_ctx->config->enablePowersaveOffload ==
8763 PS_QPOWER_NODEEPSLEEP) ||
8764 (hdd_ctx->config->enablePowersaveOffload ==
8765 PS_LEGACY_NODEEPSLEEP))
8766 cds_cfg->powersave_offload_enabled =
8767 PS_LEGACY_NODEEPSLEEP;
8768 else
8769 cds_cfg->powersave_offload_enabled =
8770 PS_LEGACY_DEEPSLEEP;
8771 hdd_info("Qpower disabled in cds config, %d",
8772 cds_cfg->powersave_offload_enabled);
8773 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308774 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8775 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8776 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8777 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8778 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8779
8780 /* Here ol_ini_info is used to store ini status of arp offload
8781 * ns offload and others. Currently 1st bit is used for arp
8782 * off load and 2nd bit for ns offload currently, rest bits are unused
8783 */
8784 if (hdd_ctx->config->fhostArpOffload)
8785 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8786 if (hdd_ctx->config->fhostNSOffload)
8787 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8788
8789 /*
8790 * Copy the DFS Phyerr Filtering Offload status.
8791 * This parameter reflects the value of the
8792 * dfs_phyerr_filter_offload flag as set in the ini.
8793 */
8794 cds_cfg->dfs_phyerr_filter_offload =
8795 hdd_ctx->config->fDfsPhyerrFilterOffload;
8796 if (hdd_ctx->config->ssdp)
8797 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8798
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308799 cds_cfg->force_target_assert_enabled =
8800 hdd_ctx->config->crash_inject_enabled;
8801
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308802 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8803 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8804
8805 cds_cfg->ap_maxoffload_reorderbuffs =
8806 hdd_ctx->config->apMaxOffloadReorderBuffs;
8807
8808 cds_cfg->ap_disable_intrabss_fwd =
8809 hdd_ctx->config->apDisableIntraBssFwd;
8810
8811 cds_cfg->dfs_pri_multiplier =
8812 hdd_ctx->config->dfsRadarPriMultiplier;
8813 cds_cfg->reorder_offload =
8814 hdd_ctx->config->reorderOffloadSupport;
8815
8816 /* IPA micro controller data path offload resource config item */
8817 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008818 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8819 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008820 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008821 hdd_ctx->config->IpaUcTxBufCount);
8822 hdd_ctx->config->IpaUcTxBufCount =
8823 rounddown_pow_of_two(
8824 hdd_ctx->config->IpaUcTxBufCount);
8825 if (!hdd_ctx->config->IpaUcTxBufCount) {
8826 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308827 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008828 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008829 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008830 hdd_ctx->config->IpaUcTxBufCount);
8831 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308832 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8833 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008834 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8835 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008836 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008837 hdd_ctx->config->IpaUcRxIndRingCount);
8838 hdd_ctx->config->IpaUcRxIndRingCount =
8839 rounddown_pow_of_two(
8840 hdd_ctx->config->IpaUcRxIndRingCount);
8841 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8842 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308843 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008844 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008845 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008846 hdd_ctx->config->IpaUcRxIndRingCount);
8847 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308848 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008849 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308850 cds_cfg->uc_tx_partition_base =
8851 hdd_ctx->config->IpaUcTxPartitionBase;
8852 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8853
8854 cds_cfg->ip_tcp_udp_checksum_offload =
8855 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008856 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308857 cds_cfg->ce_classify_enabled =
8858 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008859 cds_cfg->bpf_packet_filter_enable =
8860 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308861 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8862 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8863 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008864 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008865 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008866 cds_cfg->max_msdus_per_rxinorderind =
8867 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008868 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008869 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308870 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8871 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308872 cds_cfg->auto_power_save_fail_mode =
8873 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308874
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308875 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008876 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08008877 cds_cfg->delay_before_vdev_stop =
8878 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308879
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308880 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8881 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8882 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008883 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308884 cds_init_ini_config(cds_cfg);
8885 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308886
8887exit:
8888 qdf_mem_free(cds_cfg);
8889 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308890}
8891
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008892/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008893 * hdd_update_user_config() - API to update user configuration
8894 * parameters to obj mgr which are used by multiple components
8895 * @hdd_ctx: HDD Context
8896 *
8897 * Return: 0 for Success, errno on failure
8898 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008899static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008900{
8901 struct wlan_objmgr_psoc_user_config *user_config;
8902
8903 user_config = qdf_mem_malloc(sizeof(*user_config));
8904 if (user_config == NULL) {
8905 hdd_alert("Failed to alloc memory for user_config!");
8906 return -ENOMEM;
8907 }
8908
8909 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8910 user_config->dual_mac_feature_disable =
8911 hdd_ctx->config->dual_mac_feature_disable;
8912 user_config->indoor_channel_support =
8913 hdd_ctx->config->indoor_channel_support;
8914 user_config->is_11d_support_enabled =
8915 hdd_ctx->config->Is11dSupportEnabled;
8916 user_config->is_11h_support_enabled =
8917 hdd_ctx->config->Is11hSupportEnabled;
8918 user_config->optimize_chan_avoid_event =
8919 hdd_ctx->config->goptimize_chan_avoid_event;
8920 user_config->skip_dfs_chnl_in_p2p_search =
8921 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008922 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008923 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8924
8925 qdf_mem_free(user_config);
8926 return 0;
8927}
8928
8929/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008930 * hdd_init_thermal_info - Initialize thermal level
8931 * @hdd_ctx: HDD context
8932 *
8933 * Initialize thermal level at SME layer and set the thermal level callback
8934 * which would be called when a configured thermal threshold is hit.
8935 *
8936 * Return: 0 on success and errno on failure
8937 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008938static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008939{
8940 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308941 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008942
8943 thermal_param.smeThermalMgmtEnabled =
8944 hdd_ctx->config->thermalMitigationEnable;
8945 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8946
Poddar, Siddarth83905022016-04-16 17:56:08 -07008947 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8948 hdd_ctx->config->throttle_dutycycle_level0;
8949 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8950 hdd_ctx->config->throttle_dutycycle_level1;
8951 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8952 hdd_ctx->config->throttle_dutycycle_level2;
8953 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8954 hdd_ctx->config->throttle_dutycycle_level3;
8955
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008956 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8957 hdd_ctx->config->thermalTempMinLevel0;
8958 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8959 hdd_ctx->config->thermalTempMaxLevel0;
8960 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8961 hdd_ctx->config->thermalTempMinLevel1;
8962 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8963 hdd_ctx->config->thermalTempMaxLevel1;
8964 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8965 hdd_ctx->config->thermalTempMinLevel2;
8966 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8967 hdd_ctx->config->thermalTempMaxLevel2;
8968 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8969 hdd_ctx->config->thermalTempMinLevel3;
8970 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8971 hdd_ctx->config->thermalTempMaxLevel3;
8972
8973 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8974
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308975 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308976 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008977
8978 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8979 hdd_set_thermal_level_cb);
8980
8981 return 0;
8982
8983}
8984
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008985#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8986/**
8987 * hdd_hold_rtnl_lock - Hold RTNL lock
8988 *
8989 * Hold RTNL lock
8990 *
8991 * Return: True if held and false otherwise
8992 */
8993static inline bool hdd_hold_rtnl_lock(void)
8994{
8995 rtnl_lock();
8996 return true;
8997}
8998
8999/**
9000 * hdd_release_rtnl_lock - Release RTNL lock
9001 *
9002 * Release RTNL lock
9003 *
9004 * Return: None
9005 */
9006static inline void hdd_release_rtnl_lock(void)
9007{
9008 rtnl_unlock();
9009}
9010#else
9011static inline bool hdd_hold_rtnl_lock(void) { return false; }
9012static inline void hdd_release_rtnl_lock(void) { }
9013#endif
9014
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009015#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009016
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309017/* MAX iwpriv command support */
9018#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309019#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309020#define MAX_PKTLOG_SIZE 16
9021
9022/**
9023 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9024 * @hdd_ctx: hdd context
9025 * @set_value2: pktlog buffer size value
9026 *
9027 *
9028 * Return: 0 for success or error.
9029 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009030static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309031{
9032 struct sir_wifi_start_log start_log = { 0 };
9033 QDF_STATUS status;
9034
9035 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9036 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9037 start_log.ini_triggered = cds_is_packet_log_enabled();
9038 start_log.user_triggered = 1;
9039 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309040 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309041
9042 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9043 if (!QDF_IS_STATUS_SUCCESS(status)) {
9044 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9045 EXIT();
9046 return -EINVAL;
9047 }
9048
9049 return 0;
9050}
9051
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009052/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309053 * hdd_pktlog_clear_buff() - clear pktlog buffer
9054 * @hdd_ctx: hdd context
9055 *
9056 * Return: 0 for success or error.
9057 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009058static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309059{
9060 struct sir_wifi_start_log start_log;
9061 QDF_STATUS status;
9062
9063 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9064 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9065 start_log.ini_triggered = cds_is_packet_log_enabled();
9066 start_log.user_triggered = 1;
9067 start_log.size = 0;
9068 start_log.is_pktlog_buff_clear = true;
9069
9070 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9071 if (!QDF_IS_STATUS_SUCCESS(status)) {
9072 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9073 EXIT();
9074 return -EINVAL;
9075 }
9076
9077 return 0;
9078}
9079
9080
9081/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009082 * hdd_process_pktlog_command() - process pktlog command
9083 * @hdd_ctx: hdd context
9084 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309085 * @set_value2: pktlog buffer size value
9086 *
9087 * This function process pktlog command.
9088 * set_value2 only matters when set_value is 3 (set buff size)
9089 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009090 *
9091 * Return: 0 for success or error.
9092 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009093int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309094 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009095{
9096 int ret;
9097 bool enable;
9098 uint8_t user_triggered = 0;
9099
9100 ret = wlan_hdd_validate_context(hdd_ctx);
9101 if (0 != ret)
9102 return ret;
9103
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009104 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009105
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309106 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009107 hdd_err("invalid pktlog value %d", set_value);
9108 return -EINVAL;
9109 }
9110
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309111 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9112 if (set_value2 <= 0) {
9113 hdd_err("invalid pktlog size %d", set_value2);
9114 return -EINVAL;
9115 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9116 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9117 return -EINVAL;
9118 }
9119 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309120 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9121 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309122 }
9123
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009124 /*
9125 * set_value = 0 then disable packetlog
9126 * set_value = 1 enable packetlog forcefully
9127 * set_vlaue = 2 then disable packetlog if disabled through ini or
9128 * enable packetlog with AUTO type.
9129 */
9130 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9131 true : false;
9132
9133 if (1 == set_value) {
9134 enable = true;
9135 user_triggered = 1;
9136 }
9137
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309138 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009139}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009140
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009141/**
9142 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9143 * @hdd_ctx: HDD context
9144 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309145 * @user_triggered: triggered through iwpriv
9146 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009147 *
9148 * Return: 0 on success; error number otherwise
9149 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009150int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309151 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009152{
9153 struct sir_wifi_start_log start_log;
9154 QDF_STATUS status;
9155
9156 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9157 start_log.verbose_level =
9158 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009159 start_log.ini_triggered = cds_is_packet_log_enabled();
9160 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309161 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309162 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309163 /*
9164 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9165 * commands. Host uses this flag to decide whether to send pktlog
9166 * disable command to fw without sending pktlog enable command
9167 * previously. For eg, If vendor sends pktlog disable command without
9168 * sending pktlog enable command, then host discards the packet
9169 * but for iwpriv command, host will send it to fw.
9170 */
9171 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009172 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9173 if (!QDF_IS_STATUS_SUCCESS(status)) {
9174 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9175 EXIT();
9176 return -EINVAL;
9177 }
9178
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309179 if (enable == true)
9180 hdd_ctx->is_pktlog_enabled = 1;
9181 else
9182 hdd_ctx->is_pktlog_enabled = 0;
9183
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009184 return 0;
9185}
9186#endif /* REMOVE_PKT_LOG */
9187
Komal Seelam92fff912016-03-24 11:51:41 +05309188/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009189 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9190 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309191 * @dev: Device Pointer
9192 * @num: Number of Valid Mac address
9193 *
9194 * Return: Pointer to MAC address buffer
9195 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009196static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9197 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309198{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009199 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309200}
Komal Seelam92fff912016-03-24 11:51:41 +05309201
9202/**
9203 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9204 * @hdd_ctx: HDD Context
9205 * @num: Number of random mac addresses needed
9206 *
9207 * Generate random addresses using bit manipulation on the base mac address
9208 *
9209 * Return: None
9210 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009211void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309212{
9213 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9214 uint32_t iter;
9215 struct hdd_config *ini = hdd_ctx->config;
9216 uint8_t *buf = NULL;
9217 uint8_t macaddr_b3, tmp_br3;
9218 uint8_t *src = ini->intfMacAddr[0].bytes;
9219
9220 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9221 buf = ini->intfMacAddr[iter].bytes;
9222 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9223 macaddr_b3 = buf[3];
9224 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9225 INTF_MACADDR_MASK;
9226 macaddr_b3 += tmp_br3;
9227 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9228 buf[0] |= 0x02;
9229 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009230 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309231 }
9232}
9233
9234/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009235 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309236 * @hdd_ctx: HDD Context
9237 *
9238 * API to get mac addresses from platform driver and update the driver
9239 * structures and configure FW with the base mac address.
9240 * Return: int
9241 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009242static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309243{
9244 uint32_t no_of_mac_addr, iter;
9245 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9246 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9247 uint8_t *addr, *buf;
9248 struct device *dev = hdd_ctx->parent_dev;
9249 struct hdd_config *ini = hdd_ctx->config;
9250 tSirMacAddr mac_addr;
9251 QDF_STATUS status;
9252
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009253 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309254
9255 if (no_of_mac_addr == 0 || !addr) {
9256 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9257 return -EINVAL;
9258 }
9259
9260 if (no_of_mac_addr > max_mac_addr)
9261 no_of_mac_addr = max_mac_addr;
9262
9263 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9264
9265 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9266 buf = ini->intfMacAddr[iter].bytes;
9267 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009268 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309269 }
9270
9271 status = sme_set_custom_mac_addr(mac_addr);
9272
9273 if (!QDF_IS_STATUS_SUCCESS(status))
9274 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009275
Komal Seelam92fff912016-03-24 11:51:41 +05309276 if (no_of_mac_addr < max_mac_addr)
9277 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9278 no_of_mac_addr);
9279 return 0;
9280}
9281
9282/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009283 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9284 * @hdd_ctx: HDD Context
9285 *
9286 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9287 * will generate its own MAC and update it to FW.
9288 *
9289 * Return: 0 for success
9290 * Non-zero error code for failure
9291 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009292static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009293{
9294 tSirMacAddr customMacAddr;
9295 QDF_STATUS status;
9296
9297 qdf_mem_copy(&customMacAddr,
9298 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9299 sizeof(tSirMacAddr));
9300 status = sme_set_custom_mac_addr(customMacAddr);
9301 if (!QDF_IS_STATUS_SUCCESS(status))
9302 return -EAGAIN;
9303 return 0;
9304}
9305
9306/**
Komal Seelam92fff912016-03-24 11:51:41 +05309307 * hdd_initialize_mac_address() - API to get wlan mac addresses
9308 * @hdd_ctx: HDD Context
9309 *
9310 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9311 * is provisioned with mac addresses, driver uses it, else it will use
9312 * wlan_mac.bin to update HW MAC addresses.
9313 *
9314 * Return: None
9315 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009316static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309317{
9318 QDF_STATUS status;
9319 int ret;
9320
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009321 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309322 if (ret == 0)
9323 return;
9324
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009325 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9326 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309327
9328 status = hdd_update_mac_config(hdd_ctx);
9329
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009330 if (QDF_IS_STATUS_SUCCESS(status))
9331 return;
9332
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009333 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9334 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009335
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009336 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009337 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009338 if (ret != 0) {
9339 hdd_err("MAC address out-of-sync, ret:%d", ret);
9340 QDF_ASSERT(ret);
9341 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009342 }
Komal Seelam92fff912016-03-24 11:51:41 +05309343}
9344
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009345static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009346{
9347 int vdev_id = 0;
9348 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9349 int value = hdd_ctx->config->smart_chainmask_enabled;
9350 int vpdev = PDEV_CMD;
9351 int ret;
9352
Naveen Rawat247a8682017-06-05 15:00:31 -07009353 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009354 if (ret)
9355 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9356
9357 return ret;
9358}
9359
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009360static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009361{
9362 int vdev_id = 0;
9363 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9364 int value = hdd_ctx->config->alternative_chainmask_enabled;
9365 int vpdev = PDEV_CMD;
9366 int ret;
9367
Naveen Rawat247a8682017-06-05 15:00:31 -07009368 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009369 if (ret)
9370 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9371 ret);
9372
9373 return ret;
9374}
9375
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009376static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009377{
9378 int vdev_id = 0;
9379 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9380 int value = hdd_ctx->config->ani_enabled;
9381 int vpdev = PDEV_CMD;
9382 int ret;
9383
Naveen Rawat247a8682017-06-05 15:00:31 -07009384 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009385 if (ret)
9386 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9387
9388 return ret;
9389}
9390
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009391/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009392 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9393 * @hdd_ctx: HDD context
9394 *
9395 * Pre configurations to be done at lower layer before calling cds enable.
9396 *
9397 * Return: 0 on success and errno on failure.
9398 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009399static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009400{
9401 int ret;
9402 QDF_STATUS status;
9403 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009404 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009405
Leo Changfdb45c32016-10-28 11:09:23 -07009406 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009407 /*
9408 * Set 802.11p config
9409 * TODO-OCB: This has been temporarily added here to ensure this
9410 * parameter is set in CSR when we init the channel list. This should
9411 * be removed once the 5.9 GHz channels are added to the regulatory
9412 * domain.
9413 */
9414 hdd_set_dot11p_config(hdd_ctx);
9415
9416 /*
9417 * Note that the cds_pre_enable() sequence triggers the cfg download.
9418 * The cfg download must occur before we update the SME config
9419 * since the SME config operation must access the cfg database
9420 */
9421 status = hdd_set_sme_config(hdd_ctx);
9422
9423 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009424 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009425 ret = qdf_status_to_os_return(status);
9426 goto out;
9427 }
9428
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009429 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9430 if (QDF_STATUS_SUCCESS != status) {
9431 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9432 ret = qdf_status_to_os_return(status);
9433 goto out;
9434 }
9435
Naveen Rawat247a8682017-06-05 15:00:31 -07009436 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009437 hdd_ctx->config->tx_chain_mask_1ss,
9438 PDEV_CMD);
9439 if (0 != ret) {
9440 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9441 goto out;
9442 }
9443
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009444 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9445 if (ret)
9446 goto out;
9447
9448 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9449 if (ret)
9450 goto out;
9451
Jeff Johnson12a744b2017-04-04 08:19:37 -07009452 ret = hdd_set_ani_enabled(hdd_ctx);
9453 if (ret)
9454 goto out;
9455
Naveen Rawat247a8682017-06-05 15:00:31 -07009456 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009457 hdd_ctx->config->arp_ac_category,
9458 PDEV_CMD);
9459 if (0 != ret) {
9460 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9461 hdd_ctx->config->arp_ac_category, ret);
9462 goto out;
9463 }
9464
Prashanth Bhatta07998752016-04-28 12:35:33 -07009465 status = hdd_set_sme_chan_list(hdd_ctx);
9466 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009467 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009468 ret = qdf_status_to_os_return(status);
9469 goto out;
9470 }
9471
9472 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009473 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009474 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009475 ret = -EINVAL;
9476 goto out;
9477 }
9478
Prashanth Bhatta07998752016-04-28 12:35:33 -07009479 /*
9480 * Set the MAC Address Currently this is used by HAL to add self sta.
9481 * Remove this once self sta is added as part of session open.
9482 */
9483 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9484 hdd_ctx->config->intfMacAddr[0].bytes,
9485 sizeof(hdd_ctx->config->intfMacAddr[0]));
9486
9487 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9488 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9489 hal_status, hal_status);
9490 ret = -EINVAL;
9491 goto out;
9492 }
9493
9494 hdd_init_channel_avoidance(hdd_ctx);
9495
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309496 /* update enable sap mandatory chan list */
9497 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9498 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009499out:
9500 return ret;
9501}
9502
9503/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009504 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9505 * @context_ptr - hdd context pointer
9506 * @event_ptr - event structure pointer
9507 *
9508 * This is the p2p listen offload stop event handler, it sends vendor
9509 * event back to supplicant to notify the stop reason.
9510 *
9511 * Return: None
9512 */
9513static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9514 void *event_ptr)
9515{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009516 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009517 struct sir_p2p_lo_event *evt = event_ptr;
9518 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009519 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009520
9521 ENTER();
9522
9523 if (hdd_ctx == NULL) {
9524 hdd_err("Invalid HDD context pointer");
9525 return;
9526 }
9527
Peng Xu5c682812017-08-06 07:39:13 -07009528 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9529 if (!adapter) {
9530 hdd_err("Cannot find adapter by vdev_id = %d",
9531 evt->vdev_id);
9532 return;
9533 }
9534
Peng Xu8fdaa492016-06-22 10:20:47 -07009535 vendor_event =
9536 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009537 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009538 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9539 GFP_KERNEL);
9540
9541 if (!vendor_event) {
9542 hdd_err("cfg80211_vendor_event_alloc failed");
9543 return;
9544 }
9545
9546 if (nla_put_u32(vendor_event,
9547 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9548 evt->reason_code)) {
9549 hdd_err("nla put failed");
9550 kfree_skb(vendor_event);
9551 return;
9552 }
9553
9554 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009555 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9556 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009557}
9558
9559/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309560 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9561 * @hdd_ctx: HDD context
9562 *
9563 * This function sends the adaptive dwell time config configuration to the
9564 * firmware via WMA
9565 *
9566 * Return: 0 - success, < 0 - failure
9567 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009568static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309569{
9570 QDF_STATUS status;
9571 struct adaptive_dwelltime_params dwelltime_params;
9572
9573 dwelltime_params.is_enabled =
9574 hdd_ctx->config->adaptive_dwell_mode_enabled;
9575 dwelltime_params.dwelltime_mode =
9576 hdd_ctx->config->global_adapt_dwelltime_mode;
9577 dwelltime_params.lpf_weight =
9578 hdd_ctx->config->adapt_dwell_lpf_weight;
9579 dwelltime_params.passive_mon_intval =
9580 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9581 dwelltime_params.wifi_act_threshold =
9582 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9583
9584 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9585 &dwelltime_params);
9586
9587 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9588 if (!QDF_IS_STATUS_SUCCESS(status)) {
9589 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9590 return -EAGAIN;
9591 }
9592 return 0;
9593}
9594
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009595int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309596{
9597 QDF_STATUS status;
9598 struct wmi_dbs_scan_sel_params dbs_scan_params;
9599 uint32_t i = 0;
9600 uint8_t count = 0, numentries = 0;
9601 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9602 * CDS_DBS_SCAN_CLIENTS_MAX];
9603
9604 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009605 if (hdd_ctx->config->dual_mac_feature_disable ==
9606 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309607 return -EINVAL;
9608
9609 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9610 dbs_scan_config, &numentries,
9611 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9612 * CDS_DBS_SCAN_CLIENTS_MAX));
9613
9614 hdd_info("numentries %hu", numentries);
9615 if (!numentries) {
9616 hdd_info("Donot send scan_selection_config");
9617 return 0;
9618 }
9619
9620 /* hdd_set_fw_log_params */
9621 dbs_scan_params.num_clients = 0;
9622 while (count < (numentries - 2)) {
9623 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9624 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9625 dbs_scan_params.num_non_dbs_scans[i] =
9626 dbs_scan_config[count + 2];
9627 dbs_scan_params.num_clients++;
9628 hdd_debug("module:%d NDS:%d NNDS:%d",
9629 dbs_scan_params.module_id[i],
9630 dbs_scan_params.num_dbs_scans[i],
9631 dbs_scan_params.num_non_dbs_scans[i]);
9632 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9633 i++;
9634 }
9635
9636 dbs_scan_params.pdev_id = 0;
9637
9638 hdd_debug("clients:%d pdev:%d",
9639 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9640
9641 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9642 &dbs_scan_params);
9643 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9644 if (!QDF_IS_STATUS_SUCCESS(status)) {
9645 hdd_err("Failed to send DBS Scan selection configuration!");
9646 return -EAGAIN;
9647 }
9648 return 0;
9649}
9650
Arun Khandavallid4349a92016-07-25 11:10:43 +05309651#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9652/**
9653 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9654 * @hdd_ctx: HDD context
9655 *
9656 * Set auto shutdown callback to get indications from firmware to indicate
9657 * userspace to shutdown WLAN after a configured amount of inactivity.
9658 *
9659 * Return: 0 on success and errno on failure.
9660 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009661static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309662{
9663 QDF_STATUS status;
9664
9665 if (!hdd_ctx->config->WlanAutoShutdown)
9666 return 0;
9667
9668 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9669 wlan_hdd_auto_shutdown_cb);
9670 if (status != QDF_STATUS_SUCCESS)
9671 hdd_err("Auto shutdown feature could not be enabled: %d",
9672 status);
9673
9674 return qdf_status_to_os_return(status);
9675}
9676#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009677static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309678{
9679 return 0;
9680}
9681#endif
9682
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009683static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009684{
9685 QDF_STATUS status = QDF_STATUS_SUCCESS;
9686
9687 switch (hdd_ctx->config->dual_mac_feature_disable) {
9688 case DISABLE_DBS_CXN_AND_SCAN:
9689 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9690 if (status != QDF_STATUS_SUCCESS)
9691 hdd_err("Failed to disable dual mac features");
9692 break;
9693 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9694 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9695 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9696 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9697 if (status != QDF_STATUS_SUCCESS)
9698 hdd_err("Failed to set dbs scan and fw mode config");
9699 break;
9700 default:
9701 break;
9702 }
9703
9704 return status;
9705}
9706
Arun Khandavallid4349a92016-07-25 11:10:43 +05309707/**
9708 * hdd_features_init() - Init features
9709 * @hdd_ctx: HDD context
9710 * @adapter: Primary adapter context
9711 *
9712 * Initialize features and their feature context after WLAN firmware is up.
9713 *
9714 * Return: 0 on success and errno on failure.
9715 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009716static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309717{
9718 tSirTxPowerLimit hddtxlimit;
9719 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309720 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309721 int ret;
9722
9723 ENTER();
9724
Arun Khandavallid4349a92016-07-25 11:10:43 +05309725 /* FW capabilities received, Set the Dot11 mode */
9726 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009727 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9728 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309729
Arun Khandavallid4349a92016-07-25 11:10:43 +05309730
9731 if (hdd_ctx->config->fIsImpsEnabled)
9732 hdd_set_idle_ps_config(hdd_ctx, true);
9733 else
9734 hdd_set_idle_ps_config(hdd_ctx, false);
9735
Poddar, Siddarth37033032017-10-11 15:47:40 +05309736 /* Send Enable/Disable data stall detection cmd to FW */
9737 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9738 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9739
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309740 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009741 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309742
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309743 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9744 hdd_warn("Error in setting Voltage Corner mode config to FW");
9745
Arun Khandavallid4349a92016-07-25 11:10:43 +05309746 if (hdd_lro_init(hdd_ctx))
9747 hdd_err("Unable to initialize LRO in fw");
9748
9749 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9750 hdd_err("Unable to send adaptive dwelltime setting to FW");
9751
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309752 if (hdd_dbs_scan_selection_init(hdd_ctx))
9753 hdd_err("Unable to send DBS scan selection setting to FW");
9754
Arun Khandavallid4349a92016-07-25 11:10:43 +05309755 ret = hdd_init_thermal_info(hdd_ctx);
9756 if (ret) {
9757 hdd_err("Error while initializing thermal information");
9758 goto deregister_frames;
9759 }
9760
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309761 /**
9762 * In case of SSR/PDR, if pktlog was enabled manually before
9763 * SSR/PDR, Then enabled it again automatically after Wlan
9764 * device up.
9765 */
9766 if (cds_is_driver_recovering()) {
9767 if (hdd_ctx->is_pktlog_enabled)
9768 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9769 } else if (cds_is_packet_log_enabled())
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309770 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9771
Arun Khandavallid4349a92016-07-25 11:10:43 +05309772 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9773 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9774 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9775 if (!QDF_IS_STATUS_SUCCESS(status))
9776 hdd_err("Error setting txlimit in sme: %d", status);
9777
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009778 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309779
Arun Khandavallid4349a92016-07-25 11:10:43 +05309780 ret = hdd_register_cb(hdd_ctx);
9781 if (ret) {
9782 hdd_err("Failed to register HDD callbacks!");
9783 goto deregister_frames;
9784 }
9785
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009786 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9787 if (!QDF_IS_STATUS_SUCCESS(status)) {
9788 hdd_err("Failed to set dbs scan and fw mode cfg");
9789 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309790 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009791
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309792 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9793 status = sme_enable_disable_chanavoidind_event(
9794 hdd_ctx->hHal, 0);
9795 if (!QDF_IS_STATUS_SUCCESS(status)) {
9796 hdd_err("Failed to disable Chan Avoidance Indication");
9797 goto deregister_cb;
9798 }
9799 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309800
Manjeet Singha9cae432017-02-28 11:58:22 +05309801 if (hdd_ctx->config->enable_5g_band_pref) {
9802 band_pref_params.rssi_boost_threshold_5g =
9803 hdd_ctx->config->rssi_boost_threshold_5g;
9804 band_pref_params.rssi_boost_factor_5g =
9805 hdd_ctx->config->rssi_boost_factor_5g;
9806 band_pref_params.max_rssi_boost_5g =
9807 hdd_ctx->config->max_rssi_boost_5g;
9808 band_pref_params.rssi_penalize_threshold_5g =
9809 hdd_ctx->config->rssi_penalize_threshold_5g;
9810 band_pref_params.rssi_penalize_factor_5g =
9811 hdd_ctx->config->rssi_penalize_factor_5g;
9812 band_pref_params.max_rssi_penalize_5g =
9813 hdd_ctx->config->max_rssi_penalize_5g;
9814 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9815 }
9816
Arun Khandavallid4349a92016-07-25 11:10:43 +05309817 /* register P2P Listen Offload event callback */
9818 if (wma_is_p2p_lo_capable())
9819 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9820 wlan_hdd_p2p_lo_event_callback);
9821
9822 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9823
9824 if (ret)
9825 goto deregister_cb;
9826
Dustin Brown11638b72018-01-25 17:37:25 +05309827 wlan_hdd_init_chan_info(hdd_ctx);
9828
Arun Khandavallid4349a92016-07-25 11:10:43 +05309829 EXIT();
9830 return 0;
9831
9832deregister_cb:
9833 hdd_deregister_cb(hdd_ctx);
9834deregister_frames:
9835 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309836 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309837}
9838
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009839/**
9840 * hdd_features_deinit() - Deinit features
9841 * @hdd_ctx: HDD context
9842 *
9843 * De-Initialize features and their feature context.
9844 *
9845 * Return: none.
9846 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009847static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009848{
Dustin Brown11638b72018-01-25 17:37:25 +05309849 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009850 wlan_hdd_tsf_deinit(hdd_ctx);
9851}
9852
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309853/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009854 * hdd_register_bcn_cb() - register scan beacon callback
9855 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309856 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009857 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309858 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009859static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309860{
9861 QDF_STATUS status;
9862
9863 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9864 wlan_cfg80211_inform_bss_frame,
9865 SCAN_CB_TYPE_INFORM_BCN);
9866 if (!QDF_IS_STATUS_SUCCESS(status)) {
9867 hdd_err("failed with status code %08d [x%08x]",
9868 status, status);
9869 return status;
9870 }
9871
9872 return QDF_STATUS_SUCCESS;
9873}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309874
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309875/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309876 * hdd_configure_cds() - Configure cds modules
9877 * @hdd_ctx: HDD context
9878 * @adapter: Primary adapter context
9879 *
9880 * Enable Cds modules after WLAN firmware is up.
9881 *
9882 * Return: 0 on success and errno on failure.
9883 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009884int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309885{
9886 int ret;
9887 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309888 int set_value;
9889 uint32_t num_abg_tx_chains = 0;
9890 uint32_t num_11b_tx_chains = 0;
9891 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009892 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309893
9894 if (hdd_ctx->config->sifs_burst_duration) {
9895 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9896 hdd_ctx->config->sifs_burst_duration;
9897
9898 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9899 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9900 set_value, PDEV_CMD);
9901 }
9902
9903 if (hdd_ctx->config->is_force_1x1)
9904 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9905 1, PDEV_CMD);
9906 /* set chip power save failure detected callback */
9907 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9908 hdd_chip_pwr_save_fail_detected_cb);
9909
9910 if (hdd_ctx->config->max_mpdus_inampdu) {
9911 set_value = hdd_ctx->config->max_mpdus_inampdu;
9912 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9913 set_value, PDEV_CMD);
9914 }
9915
9916 if (hdd_ctx->config->enable_rts_sifsbursting) {
9917 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9918 sme_cli_set_command(0,
9919 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9920 set_value, PDEV_CMD);
9921 }
9922
9923 if (hdd_ctx->config->sap_get_peer_info) {
9924 set_value = hdd_ctx->config->sap_get_peer_info;
9925 sme_cli_set_command(0,
9926 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9927 set_value, PDEV_CMD);
9928 }
9929
9930 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9931 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9932 if (!hdd_ctx->config->enable2x2) {
9933 if (num_11b_tx_chains > 1)
9934 num_11b_tx_chains = 1;
9935 if (num_11ag_tx_chains > 1)
9936 num_11ag_tx_chains = 1;
9937 }
9938 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9939 num_11b_tx_chains);
9940 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9941 num_11ag_tx_chains);
9942 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9943 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309944
9945 ret = hdd_pre_enable_configure(hdd_ctx);
9946 if (ret) {
9947 hdd_err("Failed to pre-configure cds");
9948 goto out;
9949 }
9950
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009951 /* Always get latest IPA resources allocated from cds_open and configure
9952 * IPA module before configuring them to FW. Sequence required as crash
9953 * observed otherwise.
9954 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009955 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9956 hdd_err("Failed to setup pipes");
9957 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009958 }
9959
Arun Khandavallifae92942016-08-01 13:31:08 +05309960 /*
9961 * Start CDS which starts up the SME/MAC/HAL modules and everything
9962 * else
9963 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009964 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309965
9966 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009967 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309968 goto out;
9969 }
9970
9971 status = hdd_post_cds_enable_config(hdd_ctx);
9972 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009973 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009974 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309975 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309976 status = hdd_register_bcn_cb(hdd_ctx);
9977 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +08009978 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309979 goto cds_disable;
9980 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309981
9982 ret = hdd_features_init(hdd_ctx, adapter);
9983 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009984 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309985
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009986 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009987 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009988 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9989 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009990 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009991 goto cds_disable;
9992 }
9993
Himanshu Agarwalb229a142017-12-21 10:16:45 +05309994 if (ucfg_green_ap_enable_egap(hdd_ctx->hdd_pdev))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309995 hdd_debug("enhance green ap is not enabled");
9996
Nachiket Kukadedd302662017-07-13 17:31:44 +05309997 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9998 hdd_debug("Failed to set wow pulse");
9999
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010000 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10001 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010002 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10003 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10004
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010005
10006 if (hdd_ctx->config->enable_phy_reg_retention)
10007 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10008 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10009
Arun Khandavallifae92942016-08-01 13:31:08 +053010010 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010011
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010012cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010013 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010014
Arun Khandavallifae92942016-08-01 13:31:08 +053010015out:
10016 return -EINVAL;
10017}
10018
10019/**
10020 * hdd_deconfigure_cds() -De-Configure cds
10021 * @hdd_ctx: HDD context
10022 *
10023 * Deconfigure Cds modules before WLAN firmware is down.
10024 *
10025 * Return: 0 on success and errno on failure.
10026 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010027static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010028{
10029 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010030 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010031
10032 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010033
10034 /* De-init features */
10035 hdd_features_deinit(hdd_ctx);
10036
Arun Khandavallifae92942016-08-01 13:31:08 +053010037 /* De-register the SME callbacks */
10038 hdd_deregister_cb(hdd_ctx);
10039
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010040 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010041 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10042 hdd_err("Failed to Disable the CDS Modules! :%d",
10043 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010044 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010045 }
10046
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010047 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
10048 hdd_err("Failed to disconnect pipes");
10049 ret = -EINVAL;
10050 }
10051
Arun Khandavallifae92942016-08-01 13:31:08 +053010052 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010053 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010054}
10055
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010056#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10057static void hdd_deregister_policy_manager_callback(
10058 struct wlan_objmgr_psoc *psoc)
10059{
10060 if (QDF_STATUS_SUCCESS !=
10061 policy_mgr_deregister_hdd_cb(psoc)) {
10062 hdd_err("HDD callback deregister with policy manager failed");
10063 }
10064}
10065#else
10066static void hdd_deregister_policy_manager_callback(
10067 struct wlan_objmgr_psoc *psoc)
10068{
10069}
10070#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010071
10072/**
10073 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10074 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010075 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010076 *
10077 * This function maintains the driver state machine it will be invoked from
10078 * exit, shutdown and con_mode change handler. Depending on the driver state
10079 * shall perform the stopping/closing of the modules.
10080 *
10081 * Return: 0 for success; non-zero for failure
10082 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010083int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010084{
10085 void *hif_ctx;
10086 qdf_device_t qdf_ctx;
10087 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010088 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010089 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010090 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10091 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010092 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010093 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010094
10095 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -070010096 hdd_alert("stop WLAN module: entering driver status=%d",
10097 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010098
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010099 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10100
Arun Khandavallifae92942016-08-01 13:31:08 +053010101 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10102 if (!qdf_ctx) {
10103 hdd_err("QDF device context NULL");
10104 return -EINVAL;
10105 }
10106
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010107 mutex_lock(&hdd_ctx->iface_change_lock);
10108 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010109 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010110
Dustin Brown70111822017-03-30 15:31:40 -070010111 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010112 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010113 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010114 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010115
10116 cds_print_external_threads();
10117
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010118 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010119 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010120 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10121 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010122 hdd_prevent_suspend_timeout(
10123 hdd_ctx->config->iface_change_wait_time,
10124 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010125 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010126 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010127 return 0;
10128 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010129 }
10130
Arun Khandavallifae92942016-08-01 13:31:08 +053010131 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10132
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010133 /* free user wowl patterns */
10134 hdd_free_user_wowl_ptrns();
10135
Arun Khandavallifae92942016-08-01 13:31:08 +053010136 switch (hdd_ctx->driver_status) {
10137 case DRIVER_MODULES_UNINITIALIZED:
10138 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010139 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010140 case DRIVER_MODULES_CLOSED:
10141 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010142 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010143 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010144 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10145
Komal Seelamf2136bb2016-09-28 18:30:44 +053010146 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010147 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010148 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010149 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010150 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010151 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010152 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010153
Arun Khandavallifae92942016-08-01 13:31:08 +053010154 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010155 hdd_info("Wlan transitioned (now OPENED)");
10156
10157 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010158 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010159 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010160 break;
10161 default:
10162 hdd_err("Trying to stop wlan in a wrong state: %d",
10163 hdd_ctx->driver_status);
10164 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010165 ret = -EINVAL;
10166 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010167 }
10168
Amar Singhal18081642018-01-26 16:04:13 -080010169 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010170 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010171
Rajeev Kumarbe021242017-02-16 16:12:23 -080010172 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010173 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10174 hdd_err("Failed to process post CDS disable Modules! :%d",
10175 qdf_status);
10176 ret = -EINVAL;
10177 QDF_ASSERT(0);
10178 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010179
psimhadeea0a12017-12-18 14:50:02 -080010180 hdd_runtime_suspend_context_deinit(hdd_ctx);
10181
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010182 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10183 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10184 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10185 ret = -EINVAL;
10186 QDF_ASSERT(0);
10187 }
10188
Jeff Johnsone4b14592017-09-13 14:23:33 -070010189 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010190 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010191 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010192 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010193 QDF_ASSERT(0);
10194 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010195
Amar Singhal410675c2018-01-10 12:14:21 -080010196 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010197 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10198 if (ret) {
10199 hdd_err("Failed to destroy pdev; errno:%d", ret);
10200 QDF_ASSERT(0);
10201 }
10202
10203 /*
10204 * Reset total mac phy during module stop such that during
10205 * next module start same psoc is used to populate new service
10206 * ready data
10207 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010208 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10209 if (tgt_hdl)
10210 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10211
Liangwei Dong50a64a72018-01-11 01:17:00 -050010212
Arun Khandavallifae92942016-08-01 13:31:08 +053010213 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10214 if (!hif_ctx) {
10215 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010216 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010217 }
10218
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010219 if (hdd_ctx->target_hw_name) {
10220 qdf_mem_free(hdd_ctx->target_hw_name);
10221 hdd_ctx->target_hw_name = NULL;
10222 }
10223
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010224 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010225
10226 ol_cds_free();
10227
Dustin Brown70111822017-03-30 15:31:40 -070010228 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010229 ret = pld_power_off(qdf_ctx->dev);
10230 if (ret)
10231 hdd_err("CNSS power down failed put device into Low power mode:%d",
10232 ret);
10233 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010234
Dustin Brown4bc0a622017-12-06 15:56:50 -080010235 /* many adapter resources are not freed by design in SSR case */
10236 if (!is_recovery_stop)
10237 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010238 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010239
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010240 /* Once the firmware sequence is completed reset this flag */
10241 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010242 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010243 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010244
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010245done:
10246 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010247 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010248 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010249 hdd_alert("stop WLAN module: exit driver status=%d",
10250 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010251
Arun Khandavallifae92942016-08-01 13:31:08 +053010252 EXIT();
10253
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010254 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010255}
10256
Arun Khandavallifae92942016-08-01 13:31:08 +053010257
10258/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010259 * hdd_state_info_dump() - prints state information of hdd layer
10260 * @buf: buffer pointer
10261 * @size: size of buffer to be filled
10262 *
10263 * This function is used to dump state information of hdd layer
10264 *
10265 * Return: None
10266 */
10267static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10268{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010269 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010270 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010271 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010272 uint16_t len = 0;
10273 char *buf = *buf_ptr;
10274
10275 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10276 if (!hdd_ctx) {
10277 hdd_err("Failed to get hdd context ");
10278 return;
10279 }
10280
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010281 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010282
10283 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010284 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010285 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010286 "\n is_scheduler_suspended %d",
10287 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010288
Dustin Brown920397d2017-12-13 16:27:50 -080010289 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010290 if (adapter->dev)
10291 len += scnprintf(buf + len, *size - len,
10292 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010293 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010294 "\n device_mode: %d", adapter->device_mode);
10295 switch (adapter->device_mode) {
10296 case QDF_STA_MODE:
10297 case QDF_P2P_CLIENT_MODE:
10298 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10299 len += scnprintf(buf + len, *size - len,
10300 "\n connState: %d",
10301 hdd_sta_ctx->conn_info.connState);
10302 break;
10303
10304 default:
10305 break;
10306 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010307 }
10308
10309 *size -= len;
10310 *buf_ptr += len;
10311}
10312
10313/**
10314 * hdd_register_debug_callback() - registration function for hdd layer
10315 * to print hdd state information
10316 *
10317 * Return: None
10318 */
10319static void hdd_register_debug_callback(void)
10320{
10321 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10322}
10323
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010324/*
10325 * wlan_init_bug_report_lock() - Initialize bug report lock
10326 *
10327 * This function is used to create bug report lock
10328 *
10329 * Return: None
10330 */
10331static void wlan_init_bug_report_lock(void)
10332{
10333 p_cds_contextType p_cds_context;
10334
10335 p_cds_context = cds_get_global_context();
10336 if (!p_cds_context) {
10337 hdd_err("cds context is NULL");
10338 return;
10339 }
10340
10341 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10342}
10343
Mohit Khannaf8f96822017-05-17 17:11:59 -070010344void hdd_dp_trace_init(struct hdd_config *config)
10345{
10346
10347 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10348 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10349 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10350 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10351 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10352 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10353 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010354 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010355
10356 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10357 &num_entries, sizeof(config_params));
10358
10359 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010360 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010361 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010362 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010363 else if (bw_compute_interval > 1000) {
10364 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10365 thresh_time_limit = 1;
10366 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010367 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10368
10369 switch (num_entries) {
10370 case 4:
10371 proto_bitmap = config_params[3];
10372 case 3:
10373 verbosity = config_params[2];
10374 case 2:
10375 thresh = config_params[1];
10376 case 1:
10377 live_mode = config_params[0];
10378 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010379 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010380 live_mode, thresh, thresh_time_limit,
10381 verbosity, proto_bitmap);
10382 };
10383
10384 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10385 verbosity, proto_bitmap);
10386
10387}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010388/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010389 * hdd_wlan_startup() - HDD init function
10390 * @dev: Pointer to the underlying device
10391 *
10392 * This is the driver startup code executed once a WLAN device has been detected
10393 *
10394 * Return: 0 for success, < 0 for failure
10395 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010396int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010397{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010398 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010399 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010400 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010401 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010402
10403 ENTER();
10404
Arun Khandavallifae92942016-08-01 13:31:08 +053010405 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010406
10407 if (IS_ERR(hdd_ctx))
10408 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010409
Abhishek Singhe9068f12017-03-31 14:14:52 +053010410 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10411 DEFAULT_PSOC_ID);
10412 if (ret) {
10413 hdd_err("Psoc creation fails!");
10414 QDF_BUG(0);
10415 goto err_hdd_free_context;
10416 }
10417
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010418 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010419#ifdef FEATURE_WLAN_CH_AVOID
10420 mutex_init(&hdd_ctx->avoid_freq_lock);
10421#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010422
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010423 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010424 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010425
Dustin Brown021cecd2017-12-11 13:56:43 -080010426 hdd_driver_memdump_init();
10427
Jeff Johnson957bc272017-02-02 08:54:48 -080010428 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010429 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010430 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010431 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010432 }
10433
Yingying Tang80e15f32016-09-27 18:23:01 +080010434 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010435
Anurag Chouhan6d760662016-02-20 16:05:43 +053010436 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010437
10438 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010439 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010440 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010441 }
10442
Prashanth Bhatta07998752016-04-28 12:35:33 -070010443 ret = hdd_wiphy_init(hdd_ctx);
10444 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010445 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010446 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010447 }
10448
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010449 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010450 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010451
jiad195f7032018-01-31 15:18:09 +080010452 ret = hdd_ipa_init(hdd_ctx);
10453 if (ret == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010454 goto err_wiphy_unregister;
10455
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010456 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010457
Paul Zhangfb02f452017-12-22 11:58:43 +080010458 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10459 if (ret) {
10460 hdd_err("register_netdevice_notifier failed: %d", ret);
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010461 goto err_ipa_cleanup;
Paul Zhangfb02f452017-12-22 11:58:43 +080010462 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010463
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010464 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010465
Jeff Johnson957bc272017-02-02 08:54:48 -080010466 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10467 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010468 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010469 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010470 }
10471
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010472 hdd_release_rtnl_lock();
10473 rtnl_held = false;
10474
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010475 wlan_hdd_update_11n_mode(hdd_ctx->config);
10476
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010477#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010478 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010479 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010480 hdd_skip_acs_scan_timer_handler,
10481 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010482 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010483 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010484 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010485#endif
10486
Prashanth Bhattaab004382016-10-11 16:08:11 -070010487 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010488
Jeff Johnson9afc5012016-09-23 13:56:27 -070010489 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010490
Nirav Shahbd36b062016-07-18 11:12:59 +053010491 if (hdd_ctx->rps)
10492 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010493
Paul Zhangfb02f452017-12-22 11:58:43 +080010494 ret = hdd_register_notifiers(hdd_ctx);
10495 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010496 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010497
Paul Zhangfb02f452017-12-22 11:58:43 +080010498 status = wlansap_global_init();
10499 if (QDF_IS_STATUS_ERROR(status)) {
10500 hdd_unregister_notifiers(hdd_ctx);
10501 goto err_close_adapters;
10502 }
10503
Arun Khandavallifae92942016-08-01 13:31:08 +053010504 if (hdd_ctx->config->fIsImpsEnabled)
10505 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010506 else
10507 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010508
Mukul Sharma07bd8752017-10-10 16:58:14 +053010509 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010510 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10511 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010512 hdd_prevent_suspend_timeout(
10513 hdd_ctx->config->iface_change_wait_time,
10514 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10515 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010516
Sachin Ahujadddd2632017-03-07 19:07:24 +053010517 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010518 goto success;
10519
Jeff Johnson957bc272017-02-02 08:54:48 -080010520err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010521 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010522
Jeff Johnson46bde382017-02-01 15:31:16 -080010523err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010524 if (rtnl_held)
10525 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010526
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010527 unregister_netdevice_notifier(&hdd_netdev_notifier);
10528
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010529err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010530 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010531
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010532err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010533 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010534
Arun Khandavallifae92942016-08-01 13:31:08 +053010535err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010536 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010537
Dustin Brown021cecd2017-12-11 13:56:43 -080010538err_memdump_deinit:
10539 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010540
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010541 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010542 hdd_exit_netlink_services(hdd_ctx);
10543
Dustin Brown20912462017-06-07 13:48:25 -070010544 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10545
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010546err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010547 if (cds_is_fw_down())
10548 hdd_err("Not setting the complete event as fw is down");
10549 else
10550 hdd_start_complete(ret);
10551
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010552 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010553 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010554 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010555
10556success:
10557 EXIT();
10558 return 0;
10559}
10560
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010561/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010562 * hdd_wlan_update_target_info() - update target type info
10563 * @hdd_ctx: HDD context
10564 * @context: hif context
10565 *
10566 * Update target info received from firmware in hdd context
10567 * Return:None
10568 */
10569
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010570void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010571{
10572 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10573
10574 if (!tgt_info) {
10575 hdd_err("Target info is Null");
10576 return;
10577 }
10578
10579 hdd_ctx->target_type = tgt_info->target_type;
10580}
10581
10582/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010583 * hdd_get_nud_stats_cb() - callback api to update the stats
10584 * received from the firmware
10585 * @data: pointer to adapter.
10586 * @rsp: pointer to data received from FW.
10587 *
10588 * This is called when wlan driver received response event for
10589 * get arp stats to firmware.
10590 *
10591 * Return: None
10592 */
10593static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10594{
10595 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10596 struct hdd_nud_stats_context *context;
10597 int status;
10598 struct hdd_adapter *adapter = NULL;
10599
10600 ENTER();
10601
10602 if (!rsp) {
10603 hdd_err("data is null");
10604 return;
10605 }
10606
10607 status = wlan_hdd_validate_context(hdd_ctx);
10608 if (0 != status)
10609 return;
10610
10611 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10612 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10613 hdd_err("Invalid adapter or adapter has invalid magic");
10614 return;
10615 }
10616
10617 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10618 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10619 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10620 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10621 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10622 rsp->out_of_order_arp_rsp_drop_cnt);
10623 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10624 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10625 hdd_notice("rsp->ba_session_establishment_status :%x",
10626 rsp->ba_session_establishment_status);
10627
10628 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10629 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10630 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10631 adapter->dad |= rsp->dad_detected;
10632 adapter->con_status = rsp->connect_status;
10633
10634 spin_lock(&hdd_context_lock);
10635 context = &hdd_ctx->nud_stats_context;
10636 complete(&context->response_event);
10637 spin_unlock(&hdd_context_lock);
10638
10639 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010640}
10641
10642/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010643 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010644 * @hdd_ctx: HDD context
10645 *
10646 * Register the HDD callbacks to CDS/SME.
10647 *
10648 * Return: 0 for success or Error code for failure
10649 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010650int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010651{
10652 QDF_STATUS status;
10653 int ret = 0;
10654
10655 ENTER();
10656
10657 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10658
10659 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10660 hdd_send_oem_data_rsp_msg);
10661
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010662 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10663 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010664 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10665 sme_nan_register_callback(hdd_ctx->hHal,
10666 wlan_hdd_cfg80211_nan_callback);
10667 sme_stats_ext_register_callback(hdd_ctx->hHal,
10668 wlan_hdd_cfg80211_stats_ext_callback);
10669
10670 sme_ext_scan_register_callback(hdd_ctx->hHal,
10671 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010672 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10673 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010674
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010675 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10676 hdd_rssi_threshold_breached);
10677
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010678 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10679
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010680 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10681 wlan_hdd_cfg80211_link_layer_stats_callback);
10682
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010683 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10684
Zhang Qianca38fb12016-12-23 11:10:48 +080010685 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10686 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10687
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010688 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10689 hdd_lost_link_info_cb);
10690 /* print error and not block the startup process */
10691 if (!QDF_IS_STATUS_SUCCESS(status))
10692 hdd_err("set lost link info callback failed");
10693
Poddar, Siddarth34872782017-08-10 14:08:51 +053010694 ret = hdd_register_data_stall_detect_cb();
10695 if (ret) {
10696 hdd_err("Register data stall detect detect callback failed.");
10697 return ret;
10698 }
10699
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010700 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10701
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010702 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010703 hdd_set_connection_in_progress,
10704 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010705
10706 status = sme_congestion_register_callback(hdd_ctx->hHal,
10707 hdd_update_cca_info_cb);
10708 if (!QDF_IS_STATUS_SUCCESS(status))
10709 hdd_err("set congestion callback failed");
10710
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010711 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10712 hdd_bt_activity_cb);
10713 if (!QDF_IS_STATUS_SUCCESS(status))
10714 hdd_err("set bt activity info callback failed");
10715
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010716 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10717 hdd_tx_queue_cb);
10718 if (!QDF_IS_STATUS_SUCCESS(status))
10719 hdd_err("Register tx queue callback failed");
10720
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010721 EXIT();
10722
10723 return ret;
10724}
10725
10726/**
10727 * hdd_deregister_cb() - De-Register HDD callbacks.
10728 * @hdd_ctx: HDD context
10729 *
10730 * De-Register the HDD callbacks to CDS/SME.
10731 *
10732 * Return: void
10733 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010734void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010735{
10736 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010737 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010738
10739 ENTER();
10740
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010741 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010742 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10743 if (!QDF_IS_STATUS_SUCCESS(status))
10744 hdd_err("De-register of dcc stats callback failed: %d",
10745 status);
10746
10747 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010748 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10749
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010750 sme_stats_ext_register_callback(hdd_ctx->hHal,
10751 wlan_hdd_cfg80211_stats_ext_callback);
10752
10753 sme_nan_deregister_callback(hdd_ctx->hHal);
10754 status = sme_reset_tsfcb(hdd_ctx->hHal);
10755 if (!QDF_IS_STATUS_SUCCESS(status))
10756 hdd_err("Failed to de-register tsfcb the callback:%d",
10757 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010758
Poddar, Siddarth34872782017-08-10 14:08:51 +053010759 ret = hdd_deregister_data_stall_detect_cb();
10760 if (ret)
10761 hdd_err("Failed to de-register data stall detect event callback");
10762
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010763 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10764 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10765
10766 EXIT();
10767}
10768
10769/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010770 * hdd_softap_sta_deauth() - handle deauth req from HDD
10771 * @adapter: Pointer to the HDD
10772 * @enable: bool value
10773 *
10774 * This to take counter measure to handle deauth req from HDD
10775 *
10776 * Return: None
10777 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010778QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010779 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010781 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010782
10783 ENTER();
10784
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010785 /* Ignore request to deauth bcmc station */
10786 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010787 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010788
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010789 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010790 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10791 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010792
10793 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010794 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010795}
10796
10797/**
10798 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10799 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010800 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010801 *
10802 * This to take counter measure to handle deauth req from HDD
10803 *
10804 * Return: None
10805 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010806void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010807 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010808{
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010809 struct sir_peer_sta_info peer_sta_info;
10810 struct hdd_station_info *stainfo;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010811 ENTER();
10812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010813 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010814 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010815 return;
10816
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010817 wlan_hdd_get_peer_rssi(adapter, &pDelStaParams->peerMacAddr,
10818 &peer_sta_info);
10819 stainfo = hdd_get_stainfo(adapter->cache_sta_info,
10820 pDelStaParams->peerMacAddr);
10821 if (stainfo) {
10822 stainfo->rssi = peer_sta_info.info[0].rssi;
10823 stainfo->tx_rate = peer_sta_info.info[0].tx_rate;
10824 stainfo->rx_rate = peer_sta_info.info[0].rx_rate;
Jiachao Wuf610d912018-01-23 17:47:32 +080010825 stainfo->reason_code = pDelStaParams->reason_code;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010826 }
10827
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010828 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010829 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010830}
10831
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010832/**
10833 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10834 * @hdd_ctx: HDD Context
10835 *
10836 * API to find if there is any STA or P2P-Client is connected
10837 *
10838 * Return: true if connected; false otherwise
10839 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010840QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010841{
10842 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10843}
10844
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010845/**
10846 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10847 * @adapter: HDD adapter pointer
10848 *
10849 * This function loop through each adapter and disable roaming on each STA
10850 * device mode except the input adapter.
10851 *
10852 * Note: On the input adapter roaming is not enabled yet hence no need to
10853 * disable.
10854 *
10855 * Return: None
10856 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010857void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010858{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010859 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010860 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010861
10862 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010863 hdd_ctx->config->isRoamOffloadScanEnabled &&
10864 QDF_STA_MODE == adapter->device_mode &&
10865 policy_mgr_is_sta_active_connection_exists(
10866 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010867 hdd_debug("Connect received on STA session Id(%d)",
10868 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010869 /*
10870 * Loop through adapter and disable roaming for each STA device
10871 * mode except the input adapter.
10872 */
Dustin Brown920397d2017-12-13 16:27:50 -080010873 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010874 if (QDF_STA_MODE == adapterIdx->device_mode &&
10875 adapter->session_id != adapterIdx->session_id) {
10876 hdd_debug("Disable Roaming on session Id(%d)",
10877 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010878 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10879 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010880 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010881 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010882 }
10883 }
10884}
10885
10886/**
10887 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10888 * @adapter: HDD adapter pointer
10889 *
10890 * This function loop through each adapter and enable roaming on each STA
10891 * device mode except the input adapter.
10892 * Note: On the input adapter no need to enable roaming because link got
10893 * disconnected on this.
10894 *
10895 * Return: None
10896 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010897void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010898{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010899 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010900 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010901
10902 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010903 hdd_ctx->config->isRoamOffloadScanEnabled &&
10904 QDF_STA_MODE == adapter->device_mode &&
10905 policy_mgr_is_sta_active_connection_exists(
10906 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010907 hdd_debug("Disconnect received on STA session Id(%d)",
10908 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010909 /*
10910 * Loop through adapter and enable roaming for each STA device
10911 * mode except the input adapter.
10912 */
Dustin Brown920397d2017-12-13 16:27:50 -080010913 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010914 if (QDF_STA_MODE == adapterIdx->device_mode &&
10915 adapter->session_id != adapterIdx->session_id) {
10916 hdd_debug("Enabling Roaming on session Id(%d)",
10917 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010918 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10919 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010920 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010921 REASON_CONNECT);
10922 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010923 }
10924 }
10925}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010926
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010927/**
10928 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10929 * @skb: sk buffer pointer
10930 *
10931 * Sends the bcast message to SVC multicast group with generic nl socket
10932 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10933 *
10934 * Return: None
10935 */
10936static void nl_srv_bcast_svc(struct sk_buff *skb)
10937{
10938#ifdef CNSS_GENL
10939 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10940#else
10941 nl_srv_bcast(skb);
10942#endif
10943}
10944
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010945void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010946{
10947 struct sk_buff *skb;
10948 struct nlmsghdr *nlh;
10949 tAniMsgHdr *ani_hdr;
10950 void *nl_data = NULL;
10951 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010952 struct radio_index_tlv *radio_info;
10953 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010954
10955 if (in_interrupt() || irqs_disabled() || in_atomic())
10956 flags = GFP_ATOMIC;
10957
10958 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10959
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010960 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010961 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010962
10963 nlh = (struct nlmsghdr *)skb->data;
10964 nlh->nlmsg_pid = 0; /* from kernel */
10965 nlh->nlmsg_flags = 0;
10966 nlh->nlmsg_seq = 0;
10967 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10968
10969 ani_hdr = NLMSG_DATA(nlh);
10970 ani_hdr->type = type;
10971
10972 switch (type) {
10973 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010974 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010975 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010976 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010977 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010978 ani_hdr->length = 0;
10979 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010980 break;
10981 case WLAN_SVC_WLAN_STATUS_IND:
10982 case WLAN_SVC_WLAN_VERSION_IND:
10983 case WLAN_SVC_DFS_CAC_START_IND:
10984 case WLAN_SVC_DFS_CAC_END_IND:
10985 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10986 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10987 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010988 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010989 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010990 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010991 ani_hdr->length = len;
10992 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10993 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10994 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010995 break;
10996
10997 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010998 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010999 type);
11000 kfree_skb(skb);
11001 return;
11002 }
11003
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011004 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011005 * Add radio index at the end of the svc event in TLV format
11006 * to maintain the backward compatibility with userspace
11007 * applications.
11008 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011009
11010 tlv_len = 0;
11011
11012 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11013 < WLAN_NL_MAX_PAYLOAD) {
11014 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11015 sizeof(*ani_hdr) + len);
11016 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11017 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11018 radio_info->radio = radio;
11019 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080011020 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011021 "Added radio index tlv - radio index %d",
11022 radio_info->radio);
11023 }
11024
11025 nlh->nlmsg_len += tlv_len;
11026 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11027
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011028 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011029}
11030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011031#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11032void wlan_hdd_auto_shutdown_cb(void)
11033{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011034 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011035
11036 if (!hdd_ctx)
11037 return;
11038
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011039 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011040 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11041 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011042}
11043
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011044void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011045{
Jeff Johnson9d295242017-08-29 14:39:48 -070011046 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011047 bool ap_connected = false, sta_connected = false;
11048 tHalHandle hal_handle;
11049
11050 hal_handle = hdd_ctx->hHal;
11051 if (hal_handle == NULL)
11052 return;
11053
11054 if (hdd_ctx->config->WlanAutoShutdown == 0)
11055 return;
11056
11057 if (enable == false) {
11058 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011059 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011060 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011061 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011062 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011063 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011064 return;
11065 }
11066
11067 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011068 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11069 hdd_for_each_adapter(hdd_ctx, adapter) {
11070 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011071 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11072 conn_info.connState ==
11073 eConnectionState_Associated) {
11074 sta_connected = true;
11075 break;
11076 }
11077 }
Dustin Brown920397d2017-12-13 16:27:50 -080011078
11079 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011080 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011081 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011082 ap_connected = true;
11083 break;
11084 }
11085 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011086 }
11087 }
11088
11089 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011090 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011091 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011092 }
Jeff Johnson68755312017-02-10 11:46:55 -080011093
11094 if (sme_set_auto_shutdown_timer(hal_handle,
11095 hdd_ctx->config->WlanAutoShutdown)
11096 != QDF_STATUS_SUCCESS)
11097 hdd_err("Failed to start wlan auto shutdown timer");
11098 else
11099 hdd_notice("Auto Shutdown timer for %d seconds enabled",
11100 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011101}
11102#endif
11103
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011104struct hdd_adapter *
11105hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11106 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011107{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011108 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011109 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011110
11111 con_sap_adapter = NULL;
11112
Dustin Brown920397d2017-12-13 16:27:50 -080011113 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011114 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11115 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011116 adapter != this_sap_adapter) {
11117 if (check_start_bss) {
11118 if (test_bit(SOFTAP_BSS_STARTED,
11119 &adapter->event_flags)) {
11120 con_sap_adapter = adapter;
11121 break;
11122 }
11123 } else {
11124 con_sap_adapter = adapter;
11125 break;
11126 }
11127 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011128 }
11129
11130 return con_sap_adapter;
11131}
11132
11133#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011134static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011135{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011136 return adapter->device_mode == QDF_STA_MODE ||
11137 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011138}
11139
Jeff Johnson9d295242017-08-29 14:39:48 -070011140static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011141{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011142 return adapter->device_mode == QDF_SAP_MODE ||
11143 adapter->device_mode == QDF_P2P_GO_MODE;
11144}
11145
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011146static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011147{
Dustin Brown920397d2017-12-13 16:27:50 -080011148 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011149
Dustin Brown920397d2017-12-13 16:27:50 -080011150 hdd_for_each_adapter(hdd_ctx, adapter) {
11151 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011152 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11153 conn_info.connState == eConnectionState_Associated) {
11154 return true;
11155 }
11156
Dustin Brown920397d2017-12-13 16:27:50 -080011157 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011158 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011159 return true;
11160 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011161 }
11162
11163 return false;
11164}
11165
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011166static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011167{
11168 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011169
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011170 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011171 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011172 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011173
Dustin Brown5ec6b552017-03-31 12:11:40 -070011174 return is_running;
11175}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011176
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011177static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011178{
11179 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11180 hdd_ctx->bus_bw_timer_running = true;
11181 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11182 hdd_ctx->config->busBandwidthComputeInterval);
11183 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11184}
11185
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011186void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011187{
11188 ENTER();
11189
11190 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11191 hdd_debug("Bandwidth compute timer already started");
11192 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011193 }
11194
Dustin Brown5ec6b552017-03-31 12:11:40 -070011195 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11196
11197 EXIT();
11198}
11199
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011200void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011201{
11202 ENTER();
11203
11204 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11205 hdd_debug("Bandwidth compute timer already started");
11206 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011207 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011208
11209 if (hdd_any_adapter_is_assoc(hdd_ctx))
11210 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11211
11212 EXIT();
11213}
11214
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011215static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011216{
11217 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
11218
11219 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11220 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11221 hdd_ctx->bus_bw_timer_running = false;
11222 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11223
11224 hdd_reset_tcp_delack(hdd_ctx);
11225}
11226
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011227void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011228{
11229 ENTER();
11230
11231 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11232 hdd_debug("Bandwidth compute timer already stopped");
11233 return;
11234 }
11235
11236 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11237
11238 EXIT();
11239}
11240
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011241void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011242{
11243 ENTER();
11244
11245 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11246 hdd_debug("Bandwidth compute timer already stopped");
11247 return;
11248 }
11249
11250 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11251 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11252
11253 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011254}
11255#endif
11256
11257/**
11258 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11259 * and sta's operating channel.
11260 * @sta_adapter: Describe the first argument to foobar.
11261 * @ap_adapter: Describe the second argument to foobar.
11262 * @roam_profile: Roam profile of AP to which STA wants to connect.
11263 * @concurrent_chnl_same: If both SAP and STA channels are same then
11264 * set this flag to true else false.
11265 *
11266 * This function checks the sap's operating channel and sta's operating channel.
11267 * if both are same then it will return false else it will restart the sap in
11268 * sta's channel and return true.
11269 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011270 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011271 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011272QDF_STATUS
11273wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11274 struct hdd_adapter *ap_adapter,
11275 tCsrRoamProfile *roam_profile,
11276 tScanResultHandle *scan_cache,
11277 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011278{
Jeff Johnson87251032017-08-29 13:31:11 -070011279 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011280 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011281 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011282 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011283 *concurrent_chnl_same = true;
11284
11285 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11286 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011287 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011288 scan_cache,
11289 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011290 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011291 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011292 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011293 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011294 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011295 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011296 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011297 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011298 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011299 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011300 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011301 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011302 }
11303 }
11304 } else {
11305 /*
11306 * Lets handle worst case scenario here, Scan cache lookup is
11307 * failed so we have to stop the SAP to avoid any channel
11308 * discrepancy between SAP's channel and STA's channel.
11309 * Return the status as failure so caller function could know
11310 * that scan look up is failed.
11311 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011312 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011313 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011314 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011315 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011316}
11317
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011318/**
11319 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11320 * @ap_adapter: SAP adapter
11321 *
11322 * This function will process the stopping of sap adapter.
11323 *
11324 * Return: None
11325 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011326void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011327{
Jeff Johnson87251032017-08-29 13:31:11 -070011328 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011329 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011330 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011331 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011332
11333 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011334 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011335 return;
11336 }
11337
11338 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11339 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011340 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011341 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011342
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011343 mutex_lock(&hdd_ctx->sap_lock);
11344 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011345 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011346 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011347 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011348 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011349 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011350 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011351 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011352 qdf_stop_bss_event,
11353 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011354 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011355 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011356 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011357 return;
11358 }
11359 }
11360 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011361 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11362 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011363 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011364 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011365 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011366 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011367 }
11368 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011369}
11370
11371/**
11372 * wlan_hdd_start_sap() - this function starts bss of SAP.
11373 * @ap_adapter: SAP adapter
11374 *
11375 * This function will process the starting of sap adapter.
11376 *
11377 * Return: None
11378 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011379void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011380{
Jeff Johnson87251032017-08-29 13:31:11 -070011381 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011382 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011383 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011384 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011385 tsap_Config_t *sap_config;
11386
11387 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011388 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011389 return;
11390 }
11391
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011392 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011393 hdd_err("SoftAp role has not been enabled");
11394 return;
11395 }
11396
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011397 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11398 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11399 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011400 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011401
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011402 mutex_lock(&hdd_ctx->sap_lock);
11403 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11404 goto end;
11405
11406 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011407 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011408 goto end;
11409 }
11410
Wei Song2f76f642016-11-18 16:32:53 +080011411 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011412 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011413 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011414 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011415 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011416 goto end;
11417
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011418 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011419 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011420 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011421 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011422 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011423 goto end;
11424 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011425 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011426 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011427 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011428 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011429 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11430 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011431 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011432 mutex_unlock(&hdd_ctx->sap_lock);
11433
11434 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011435end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011436 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011437 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011438 /* SAP context and beacon cleanup will happen during driver unload
11439 * in hdd_stop_adapter
11440 */
11441 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11442
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011443}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011444
11445/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011446 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11447 * mac scan config
11448 * @status: Status of set antenna mode
11449 *
11450 * Callback on setting the dual mac configuration
11451 *
11452 * Return: None
11453 */
11454void wlan_hdd_soc_set_antenna_mode_cb(
11455 enum set_antenna_mode_status status)
11456{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011457 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011458
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011459 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011460
11461 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11462 if (0 != wlan_hdd_validate_context(hdd_ctx))
11463 return;
11464
11465 /* Signal the completion of set dual mac config */
11466 complete(&hdd_ctx->set_antenna_mode_cmpl);
11467}
11468
11469/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011470 * hdd_get_fw_version() - Get FW version
11471 * @hdd_ctx: pointer to HDD context.
11472 * @major_spid: FW version - major spid.
11473 * @minor_spid: FW version - minor spid
11474 * @ssid: FW version - ssid
11475 * @crmid: FW version - crmid
11476 *
11477 * This function is called to get the firmware build version stored
11478 * as part of the HDD context
11479 *
11480 * Return: None
11481 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011482void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011483 uint32_t *major_spid, uint32_t *minor_spid,
11484 uint32_t *siid, uint32_t *crmid)
11485{
11486 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11487 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11488 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11489 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11490}
11491
11492#ifdef QCA_CONFIG_SMP
11493/**
11494 * wlan_hdd_get_cpu() - get cpu_index
11495 *
11496 * Return: cpu_index
11497 */
11498int wlan_hdd_get_cpu(void)
11499{
11500 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011501
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011502 put_cpu();
11503 return cpu_index;
11504}
11505#endif
11506
11507/**
11508 * hdd_get_fwpath() - get framework path
11509 *
11510 * This function is used to get the string written by
11511 * userspace to start the wlan driver
11512 *
11513 * Return: string
11514 */
11515const char *hdd_get_fwpath(void)
11516{
11517 return fwpath.string;
11518}
11519
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011520static int hdd_qdf_print_init(void)
11521{
11522 int qdf_print_idx;
11523 QDF_STATUS status;
11524
11525 status = qdf_print_setup();
11526 if (status != QDF_STATUS_SUCCESS) {
11527 pr_err("qdf_print_setup failed\n");
11528 return -EINVAL;
11529 }
11530
11531 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11532
11533 if (qdf_print_idx < 0) {
11534 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11535 qdf_print_idx);
11536 return -EINVAL;
11537 }
11538
11539 qdf_set_pidx(qdf_print_idx);
11540
11541 return 0;
11542}
11543
11544static void hdd_qdf_print_deinit(void)
11545{
11546 int qdf_print_idx;
11547
11548 qdf_print_idx = qdf_get_pidx();
11549 qdf_print_ctrl_cleanup(qdf_print_idx);
11550}
11551
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011552/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011553 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011554 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011555 * This function initilizes CDS global context with the help of cds_init. This
11556 * has to be the first function called after probe to get a valid global
11557 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011558 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011559 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011560 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011561int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011562{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011563 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011564 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011565
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011566 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011567 if (QDF_IS_STATUS_ERROR(status)) {
11568 hdd_err("Failed to allocate CDS context");
11569 ret = -ENOMEM;
11570 goto err_out;
11571 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011572
11573 wlan_init_bug_report_lock();
11574
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011575#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11576 wlan_logging_sock_init_svc();
11577#endif
11578
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011579 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11580 (void *)hdd_drv_ops_inactivity_handler, NULL,
11581 QDF_TIMER_TYPE_SW);
11582
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011583 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011584 hdd_qdf_print_init();
11585
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011586 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011587
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011588err_out:
11589 return ret;
11590}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011591
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011592/**
11593 * hdd_deinit() - Deinitialize Driver
11594 *
11595 * This function frees CDS global context with the help of cds_deinit. This
11596 * has to be the last function call in remove callback to free the global
11597 * context.
11598 */
11599void hdd_deinit(void)
11600{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011601 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011602
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011603 wlan_destroy_bug_report_lock();
11604 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011605
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011606 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011607#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11608 wlan_logging_sock_deinit_svc();
11609#endif
11610}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011611
Yue Ma6e7b1a02017-04-03 14:17:46 -070011612#ifdef QCA_WIFI_NAPIER_EMULATION
11613#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11614#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011615#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011616#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011617
Sachin Ahujadddd2632017-03-07 19:07:24 +053011618static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11619 struct file *file)
11620{
11621 return 0;
11622}
11623
11624static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11625 const char __user *user_buf,
11626 size_t count,
11627 loff_t *f_pos)
11628{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011629 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011630 static const char wlan_off_str[] = "OFF";
11631 static const char wlan_on_str[] = "ON";
11632 int ret;
11633 unsigned long rc;
11634
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011635 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011636 pr_err("Failed to read buffer\n");
11637 return -EINVAL;
11638 }
11639
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011640 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011641 pr_debug("Wifi turning off from UI\n");
11642 goto exit;
11643 }
11644
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011645 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011646 pr_err("Invalid value received from framework");
11647 goto exit;
11648 }
11649
11650 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011651 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011652 rc = wait_for_completion_timeout(&wlan_start_comp,
11653 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11654 if (!rc) {
11655 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11656 ret = -EINVAL;
11657 hdd_start_complete(ret);
11658 return ret;
11659 }
11660
11661 hdd_start_complete(0);
11662 }
11663
11664exit:
11665 return count;
11666}
11667
11668
11669const struct file_operations wlan_hdd_state_fops = {
11670 .owner = THIS_MODULE,
11671 .open = wlan_hdd_state_ctrl_param_open,
11672 .write = wlan_hdd_state_ctrl_param_write,
11673};
11674
11675static int wlan_hdd_state_ctrl_param_create(void)
11676{
11677 unsigned int wlan_hdd_state_major = 0;
11678 int ret;
11679 struct device *dev;
11680
11681 device = MKDEV(wlan_hdd_state_major, 0);
11682
11683 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11684 if (ret) {
11685 pr_err("Failed to register qcwlanstate");
11686 goto dev_alloc_err;
11687 }
11688 wlan_hdd_state_major = MAJOR(device);
11689
11690 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11691 if (IS_ERR(class)) {
11692 pr_err("wlan_hdd_state class_create error");
11693 goto class_err;
11694 }
11695
11696 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11697 if (IS_ERR(dev)) {
11698 pr_err("wlan_hdd_statedevice_create error");
11699 goto err_class_destroy;
11700 }
11701
11702 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11703 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11704 if (ret) {
11705 pr_err("Failed to add cdev error");
11706 goto cdev_add_err;
11707 }
11708
11709 pr_info("wlan_hdd_state %s major(%d) initialized",
11710 WLAN_MODULE_NAME, wlan_hdd_state_major);
11711
11712 return 0;
11713
11714cdev_add_err:
11715 device_destroy(class, device);
11716err_class_destroy:
11717 class_destroy(class);
11718class_err:
11719 unregister_chrdev_region(device, dev_num);
11720dev_alloc_err:
11721 return -ENODEV;
11722}
11723
11724static void wlan_hdd_state_ctrl_param_destroy(void)
11725{
11726 cdev_del(&wlan_hdd_state_cdev);
11727 device_destroy(class, device);
11728 class_destroy(class);
11729 unregister_chrdev_region(device, dev_num);
11730
11731 pr_info("Device node unregistered");
11732}
11733
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011734/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011735 * component_init - API to init cld component's
11736 *
11737 * Return: None
11738 */
11739static void component_init(void)
11740{
11741 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011742 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011743 ucfg_ocb_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011744}
11745
11746/**
11747 * component_deinit - API to deinit cld component's
11748 *
11749 * Return: None
11750 */
11751static void component_deinit(void)
11752{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011753 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011754 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011755 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011756}
11757
11758void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11759{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011760 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011761 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011762}
11763
11764void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11765{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011766 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011767 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011768}
11769
11770/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011771 * __hdd_module_init - Module init helper
11772 *
11773 * Module init helper function used by both module and static driver.
11774 *
11775 * Return: 0 for success, errno on failure
11776 */
11777static int __hdd_module_init(void)
11778{
11779 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011780
Dustin Brown96cd9632017-11-13 12:45:04 -080011781 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011782 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011783 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080011784 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011785
Sachin Ahujadddd2632017-03-07 19:07:24 +053011786 ret = wlan_hdd_state_ctrl_param_create();
11787 if (ret) {
11788 pr_err("wlan_hdd_state_create:%x\n", ret);
11789 goto err_dev_state;
11790 }
11791
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011792 pld_init();
11793
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011794 ret = hdd_init();
11795 if (ret) {
11796 pr_err("hdd_init failed %x\n", ret);
11797 goto err_hdd_init;
11798 }
11799
Rajeev Kumar97767a02016-11-30 11:20:40 -080011800 dispatcher_init();
11801
Mukul Sharmad75a6672017-06-22 15:40:53 +053011802 /* Ensure to call post objmgr init */
11803 component_init();
11804
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011805 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011806
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011807 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011808
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011809 ret = wlan_hdd_register_driver();
11810 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011811 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11812 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011813 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011814 }
11815
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011816 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011817
11818 return 0;
11819out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011820 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011821 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011822 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011823 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011824
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011825err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011826 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011827 wlan_hdd_state_ctrl_param_destroy();
11828err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011829 return ret;
11830}
11831
11832/**
11833 * __hdd_module_exit - Module exit helper
11834 *
11835 * Module exit helper function used by both module and static driver.
11836 */
11837static void __hdd_module_exit(void)
11838{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011839
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011840 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11841 QWLAN_VERSIONSTR);
11842
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011843 hdd_wait_for_recovery_completion();
11844
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011845 wlan_hdd_unregister_driver();
11846
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011847 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011848
Mukul Sharmad75a6672017-06-22 15:40:53 +053011849 /* Ensure to call prior to objmgr deinit */
11850 component_deinit();
11851
Rajeev Kumar97767a02016-11-30 11:20:40 -080011852 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011853
11854 hdd_sysfs_destroy_version_interface();
11855
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011856 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011857 pld_deinit();
11858
Sachin Ahujadddd2632017-03-07 19:07:24 +053011859 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011860}
11861
Arun Khandavallifae92942016-08-01 13:31:08 +053011862#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011863/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011864 * wlan_boot_cb() - Wlan boot callback
11865 * @kobj: object whose directory we're creating the link in.
11866 * @attr: attribute the user is interacting with
11867 * @buff: the buffer containing the user data
11868 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011869 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011870 * This callback is invoked when the fs is ready to start the
11871 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011872 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011873 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011874 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011875static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011876 struct kobj_attribute *attr,
11877 const char *buf,
11878 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011879{
Arun Khandavallifae92942016-08-01 13:31:08 +053011880
Arun Khandavallifae92942016-08-01 13:31:08 +053011881 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011882 pr_err("%s: wlan driver already initialized\n", __func__);
11883 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011884 }
11885
Arun Khandavallifae92942016-08-01 13:31:08 +053011886 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011887 pr_err("%s: wlan driver initialization failed\n", __func__);
11888 return -EIO;
11889 }
11890
11891 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011892
11893 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011894}
Arun Khandavallifae92942016-08-01 13:31:08 +053011895
11896/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011897 * hdd_sysfs_cleanup() - cleanup sysfs
11898 *
11899 * Return: None
11900 *
11901 */
11902static void hdd_sysfs_cleanup(void)
11903{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011904 /* remove from group */
11905 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11906 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11907 wlan_loader->attr_group);
11908
11909 /* unlink the object from parent */
11910 kobject_del(wlan_loader->boot_wlan_obj);
11911
11912 /* free the object */
11913 kobject_put(wlan_loader->boot_wlan_obj);
11914
11915 kfree(wlan_loader->attr_group);
11916 kfree(wlan_loader);
11917
11918 wlan_loader = NULL;
11919}
11920
11921/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011922 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11923 * ready
11924 *
11925 * This is creates the syfs entry boot_wlan. Which shall be invoked
11926 * when the filesystem is ready.
11927 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011928 * QDF API cannot be used here since this function is called even before
11929 * initializing WLAN driver.
11930 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011931 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011932 */
11933static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011934{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011935 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011936
11937 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011938 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011939 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011940
11941 wlan_loader->boot_wlan_obj = NULL;
11942 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11943 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011944 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011945 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011946
11947 wlan_loader->loaded_state = 0;
11948 wlan_loader->attr_group->attrs = attrs;
11949
11950 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11951 kernel_kobj);
11952 if (!wlan_loader->boot_wlan_obj) {
11953 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011954 goto error_return;
11955 }
11956
11957 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11958 wlan_loader->attr_group);
11959 if (ret) {
11960 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11961 goto error_return;
11962 }
11963
11964 return 0;
11965
11966error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011967 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011968
11969 return ret;
11970}
11971
11972/**
11973 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11974 *
11975 * Return: 0 on success or errno on failure
11976 */
11977static int wlan_deinit_sysfs(void)
11978{
Arun Khandavallifae92942016-08-01 13:31:08 +053011979 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011980 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011981 return -EINVAL;
11982 }
11983
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011984 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011985 return 0;
11986}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011987
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011988#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011989
11990#ifdef MODULE
11991/**
11992 * __hdd_module_init - Module init helper
11993 *
11994 * Module init helper function used by both module and static driver.
11995 *
11996 * Return: 0 for success, errno on failure
11997 */
11998static int hdd_module_init(void)
11999{
Arun Khandavallifae92942016-08-01 13:31:08 +053012000 if (__hdd_module_init()) {
12001 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012002 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012003 }
12004
Dustin Brownab482ac2017-06-09 17:00:44 -070012005 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012006}
12007#else
12008static int __init hdd_module_init(void)
12009{
12010 int ret = -EINVAL;
12011
12012 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012013 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012014 pr_err("Failed to create sysfs entry for loading wlan");
12015
12016 return ret;
12017}
12018#endif
12019
12020
12021#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012022/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012023 * hdd_module_exit() - Exit function
12024 *
12025 * This is the driver exit point (invoked when module is unloaded using rmmod)
12026 *
12027 * Return: None
12028 */
12029static void __exit hdd_module_exit(void)
12030{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012031 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012032}
Arun Khandavallifae92942016-08-01 13:31:08 +053012033#else
12034static void __exit hdd_module_exit(void)
12035{
12036 __hdd_module_exit();
12037 wlan_deinit_sysfs();
12038}
12039#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012040
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012041static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
12042{
12043 return param_set_copystring(kmessage, kp);
12044}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012045
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012046/**
12047 * is_con_mode_valid() check con mode is valid or not
12048 * @mode: global con mode
12049 *
12050 * Return: TRUE on success FALSE on failure
12051 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012052static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012053{
12054 switch (mode) {
12055 case QDF_GLOBAL_MONITOR_MODE:
12056 case QDF_GLOBAL_FTM_MODE:
12057 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012058 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012059 return true;
12060 default:
12061 return false;
12062 }
12063}
12064
12065/**
12066 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12067 * @mode: global con mode
12068 *
12069 * Return: adapter mode
12070 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012071static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012072 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012073{
12074
12075 switch (mode) {
12076 case QDF_GLOBAL_MISSION_MODE:
12077 return QDF_STA_MODE;
12078 case QDF_GLOBAL_MONITOR_MODE:
12079 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012080 case QDF_GLOBAL_EPPING_MODE:
12081 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012082 case QDF_GLOBAL_FTM_MODE:
12083 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012084 case QDF_GLOBAL_QVIT_MODE:
12085 return QDF_QVIT_MODE;
12086 default:
12087 return QDF_MAX_NO_OF_MODE;
12088 }
12089}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012090
Dustin Brown27cd9942017-09-27 16:11:44 -070012091static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012092 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012093{
12094 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12095 return;
12096
12097 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012098 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012099 hdd_info("Release wakelock for monitor mode!");
12100 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12101 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12102 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012103 case QDF_GLOBAL_FTM_MODE:
12104 hdd_abort_mac_scan_all_adapters(hdd_ctx);
12105 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012106 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012107
Dustin Brown27cd9942017-09-27 16:11:44 -070012108 break;
12109 default:
12110 break;
12111 }
12112}
12113
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012114static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012115 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012116{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012117 int driver_status;
12118
12119 driver_status = hdd_ctx->driver_status;
12120
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012121 switch (curr_mode) {
12122 case QDF_GLOBAL_MISSION_MODE:
12123 case QDF_GLOBAL_MONITOR_MODE:
12124 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012125 hdd_deinit_all_adapters(hdd_ctx, false);
12126 hdd_close_all_adapters(hdd_ctx, false);
12127 break;
12128 case QDF_GLOBAL_EPPING_MODE:
12129 epping_disable();
12130 epping_close();
12131 break;
12132 default:
12133 return;
12134 }
12135}
12136
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012137static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012138 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012139{
Jeff Johnson9d295242017-08-29 14:39:48 -070012140 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012141 int ret = 0;
12142 bool rtnl_held;
12143 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12144 QDF_STATUS status;
12145
12146 if (!qdf_dev) {
12147 hdd_err("qdf device context is Null return!");
12148 return -EINVAL;
12149 }
12150
12151 rtnl_held = hdd_hold_rtnl_lock();
12152 switch (mode) {
12153 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012154 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12155 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012156 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012157 break;
12158 case QDF_GLOBAL_FTM_MODE:
12159 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12160 wlan_hdd_get_intf_addr(hdd_ctx),
12161 NET_NAME_UNKNOWN, rtnl_held);
12162 if (adapter == NULL)
12163 ret = -EINVAL;
12164 break;
12165 case QDF_GLOBAL_MONITOR_MODE:
12166 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12167 wlan_hdd_get_intf_addr(hdd_ctx),
12168 NET_NAME_UNKNOWN, rtnl_held);
12169 if (adapter == NULL)
12170 ret = -EINVAL;
12171 break;
12172 case QDF_GLOBAL_EPPING_MODE:
12173 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012174 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012175 hdd_err("Failed to open in eeping mode: %d", status);
12176 ret = -EINVAL;
12177 break;
12178 }
12179 ret = epping_enable(qdf_dev->dev);
12180 if (ret) {
12181 hdd_err("Failed to enable in epping mode : %d", ret);
12182 epping_close();
12183 }
12184 break;
12185 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012186 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012187 ret = -ENOTSUPP;
12188 break;
12189 }
12190 hdd_release_rtnl_lock();
12191 rtnl_held = false;
12192 return ret;
12193}
12194
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012195/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012196 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012197 * @kmessage: con mode name on which driver to be bring up
12198 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012199 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012200 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012201 * This function is invoked when user updates con mode using sys entry,
12202 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012203 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012204 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012205 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012206static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012207 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012208{
12209 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012210 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012211 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012212 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012213 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012214
Dustin Brownab6029b2017-05-24 13:04:19 -070012215 hdd_info("con_mode handler: %s", kmessage);
12216
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012217 ret = wlan_hdd_validate_context(hdd_ctx);
12218 if (ret)
12219 return ret;
12220
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012221 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012222 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012223
Dustin Brown20024e32018-01-03 12:34:58 -080012224 ret = kstrtoint(kmessage, 0, &new_con_mode);
12225 if (ret) {
12226 hdd_err("Failed to parse con_mode '%s'", kmessage);
12227 goto reset_flags;
12228 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012229 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012230
Dustin Brown20024e32018-01-03 12:34:58 -080012231 if (!is_con_mode_valid(new_con_mode)) {
12232 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012233 ret = -EINVAL;
12234 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012235 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012236
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012237 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012238 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012239 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012240 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012241 ret = 0;
12242 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012243 }
12244
Dustin Brown27cd9942017-09-27 16:11:44 -070012245 /* ensure adapters are stopped */
12246 hdd_stop_present_mode(hdd_ctx, curr_mode);
12247
Frank Liu6666f832018-01-04 10:06:05 +080012248 /* Cleanup present mode before switching to new mode */
12249 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12250
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012251 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012252 if (ret) {
12253 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012254 goto reset_flags;
12255 }
12256
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012257
Dustin Brown20024e32018-01-03 12:34:58 -080012258 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012259
Frank Liu6666f832018-01-04 10:06:05 +080012260 /*
12261 * Set ACTIVE domain before adapters created, otherwise check domain
12262 * match will fail when cleanup adapters.
12263 */
12264 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012265 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012266 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012267 if (ret) {
12268 hdd_err("Failed to register for new mode");
12269 goto reset_flags;
12270 }
12271
Dustin Brown20024e32018-01-03 12:34:58 -080012272 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012273 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12274 hdd_err("invalid adapter");
12275 ret = -EINVAL;
12276 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012277 }
12278
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012279 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012280 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012281 hdd_err("Failed to get adapter:%d", adapter_mode);
12282 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012283 }
12284
12285 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12286 if (ret) {
12287 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012288 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012289 }
12290
Dustin Brown20024e32018-01-03 12:34:58 -080012291 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012292 if (hdd_start_adapter(adapter)) {
12293 hdd_err("Failed to start %s adapter", kmessage);
12294 ret = -EINVAL;
12295 goto reset_flags;
12296 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012297
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012298 hdd_info("Acquire wakelock for monitor mode!");
12299 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12300 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12301 }
12302
Dustin Brown20024e32018-01-03 12:34:58 -080012303 /* con_mode is a global module parameter */
12304 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012305 hdd_info("Mode successfully changed to %s", kmessage);
12306 ret = 0;
12307
12308reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012309 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012310 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012311 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012312 return ret;
12313}
12314
12315
12316static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12317{
12318 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012319 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012320
12321 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12322 ret = wlan_hdd_validate_context(hdd_ctx);
12323 if (ret)
12324 return ret;
12325
12326 cds_ssr_protect(__func__);
12327 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12328 cds_ssr_unprotect(__func__);
12329
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012330 return ret;
12331}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012332
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012333static int con_mode_handler_ftm(const char *kmessage,
12334 struct kernel_param *kp)
12335{
12336 int ret;
12337
12338 ret = param_set_int(kmessage, kp);
12339
12340 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12341 pr_err("Only FTM mode supported!");
12342 return -ENOTSUPP;
12343 }
12344
12345 hdd_set_conparam(con_mode_ftm);
12346 con_mode = con_mode_ftm;
12347
12348 return ret;
12349}
12350
Ravi Joshia307f632017-07-17 23:41:41 -070012351static int con_mode_handler_monitor(const char *kmessage,
12352 struct kernel_param *kp)
12353{
12354 int ret;
12355
12356 ret = param_set_int(kmessage, kp);
12357
12358 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12359 pr_err("Only Monitor mode supported!");
12360 return -ENOTSUPP;
12361 }
12362
12363 hdd_set_conparam(con_mode_monitor);
12364 con_mode = con_mode_monitor;
12365
12366 return ret;
12367}
12368
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012369/**
12370 * hdd_get_conparam() - driver exit point
12371 *
12372 * This is the driver exit point (invoked when module is unloaded using rmmod)
12373 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012374 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012375 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012376enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012377{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012378 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012379}
12380
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012381void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012382{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012383 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012384}
12385
Komal Seelamc11bb222016-01-27 18:57:10 +053012386/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012387 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12388 * @hdd_ctx: HDD context
12389 *
12390 * Cleans up the pre cac interface, if it exists
12391 *
12392 * Return: None
12393 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012394void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012395{
12396 uint8_t session_id;
12397 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012398 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012399
12400 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12401 if (QDF_IS_STATUS_ERROR(status)) {
12402 hdd_err("failed to get pre cac vdev id");
12403 return;
12404 }
12405
12406 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12407 if (!precac_adapter) {
12408 hdd_err("invalid pre cac adapater");
12409 return;
12410 }
12411
12412 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12413 wlan_hdd_sap_pre_cac_failure,
12414 (void *)precac_adapter);
12415 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12416
12417}
12418
12419/**
Komal Seelamec702b02016-02-24 18:42:16 +053012420 * hdd_update_ol_config - API to update ol configuration parameters
12421 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012422 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012423 * Return: void
12424 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012425static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012426{
Komal Seelamec702b02016-02-24 18:42:16 +053012427 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012428 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012429
Komal Seelamec702b02016-02-24 18:42:16 +053012430 if (!ol_ctx)
12431 return;
12432
12433 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12434 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12435 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12436 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012437 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012438
12439 ol_init_ini_config(ol_ctx, &cfg);
12440}
12441
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012442#ifdef FEATURE_RUNTIME_PM
12443/**
12444 * hdd_populate_runtime_cfg() - populate runtime configuration
12445 * @hdd_ctx: hdd context
12446 * @cfg: pointer to the configuration memory being populated
12447 *
12448 * Return: void
12449 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012450static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012451 struct hif_config_info *cfg)
12452{
12453 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12454 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12455}
12456#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012457static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012458 struct hif_config_info *cfg)
12459{
12460}
12461#endif
12462
Komal Seelamec702b02016-02-24 18:42:16 +053012463/**
12464 * hdd_update_hif_config - API to update HIF configuration parameters
12465 * @hdd_ctx: HDD Context
12466 *
12467 * Return: void
12468 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012469static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012470{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012471 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012472 struct hif_config_info cfg;
12473
12474 if (!scn)
12475 return;
12476
12477 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012478 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012479 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012480
12481 if (hdd_ctx->config->prevent_link_down)
12482 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012483}
12484
12485/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012486 * hdd_update_dp_config() - Propagate config parameters to Lithium
12487 * datapath
12488 * @hdd_ctx: HDD Context
12489 *
12490 * Return: 0 for success/errno for failure
12491 */
12492static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12493{
12494 struct cdp_config_params params;
12495 QDF_STATUS status;
12496
12497 params.tso_enable = hdd_ctx->config->tso_enable;
12498 params.lro_enable = hdd_ctx->config->lro_enable;
12499#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12500 params.tx_flow_stop_queue_threshold =
12501 hdd_ctx->config->TxFlowStopQueueThreshold;
12502 params.tx_flow_start_queue_offset =
12503 hdd_ctx->config->TxFlowStartQueueOffset;
12504#endif
12505 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12506 params.napi_enable = hdd_ctx->napi_enable;
12507 params.tcp_udp_checksumoffload =
12508 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12509
12510 status = cdp_update_config_parameters(
12511 cds_get_context(QDF_MODULE_ID_SOC),
12512 &params);
12513 if (status) {
12514 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12515 "%s: Failed to attach config parameters", __func__);
12516 return status;
12517 }
12518
12519 return 0;
12520}
12521
12522/**
Komal Seelamec702b02016-02-24 18:42:16 +053012523 * hdd_update_config() - Initialize driver per module ini parameters
12524 * @hdd_ctx: HDD Context
12525 *
12526 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012527 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012528 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012529int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012530{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012531 int ret;
12532
Komal Seelamec702b02016-02-24 18:42:16 +053012533 hdd_update_ol_config(hdd_ctx);
12534 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012535 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12536 ret = hdd_update_cds_config_ftm(hdd_ctx);
12537 else
12538 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012539 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012540
12541 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012542}
12543
Mukul Sharma9d797a02017-01-05 20:26:03 +053012544#ifdef FEATURE_WLAN_RA_FILTERING
12545/**
12546 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12547 * @psoc_cfg: pmo psoc Configuration
12548 * @hdd_ctx: Pointer to hdd context
12549 *
12550 * Return: none
12551 */
12552static inline void hdd_ra_populate_pmo_config(
12553 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012554 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012555{
12556 psoc_cfg->ra_ratelimit_interval =
12557 hdd_ctx->config->RArateLimitInterval;
12558 psoc_cfg->ra_ratelimit_enable =
12559 hdd_ctx->config->IsRArateLimitEnabled;
12560}
12561#else
12562static inline void hdd_ra_populate_pmo_config(
12563 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012564 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012565{
12566}
12567#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012568
Mukul Sharma9d797a02017-01-05 20:26:03 +053012569/**
12570 * hdd_update_pmo_config - API to update pmo configuration parameters
12571 * @hdd_ctx: HDD context
12572 *
12573 * Return: void
12574 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012575static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012576{
12577 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12578 struct pmo_psoc_cfg psoc_cfg;
12579 QDF_STATUS status;
12580
12581 /*
12582 * Value of hdd_ctx->wowEnable can be,
12583 * 0 - Disable both magic pattern match and pattern byte match.
12584 * 1 - Enable magic pattern match on all interfaces.
12585 * 2 - Enable pattern byte match on all interfaces.
12586 * 3 - Enable both magic patter and pattern byte match on
12587 * all interfaces.
12588 */
12589 psoc_cfg.magic_ptrn_enable =
12590 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12591 psoc_cfg.ptrn_match_enable_all_vdev =
12592 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012593 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
Sourav Mohapatra89c85d12017-12-01 09:17:54 +053012594 wmi_service_unified_wow_capability);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012595 psoc_cfg.bpf_enable =
12596 hdd_ctx->config->bpf_packet_filter_enable;
12597 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012598 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012599 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12600 if (hdd_ctx->config->fhostNSOffload)
12601 psoc_cfg.ns_offload_enable_dynamic = true;
12602 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12603 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12604 psoc_cfg.active_mode_offload =
12605 hdd_ctx->config->active_mode_offload;
12606 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012607 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012608 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012609 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12610 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12611 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12612 psoc_cfg.power_save_mode =
12613 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012614 psoc_cfg.auto_power_save_fail_mode =
12615 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012616
12617 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012618 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12619 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012620 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012621 if (status != QDF_STATUS_SUCCESS) {
12622 hdd_err("failed pmo psoc configuration");
12623 return -EINVAL;
12624 }
12625
12626 return 0;
12627}
12628
Abhishek Singhb20db962017-03-03 21:28:46 +053012629#ifdef FEATURE_WLAN_SCAN_PNO
12630static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12631 struct hdd_config *cfg)
12632{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012633 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12634
Abhishek Singhb20db962017-03-03 21:28:46 +053012635 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12636 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12637 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12638 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12639 pno_cfg->channel_prediction_full_scan =
12640 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012641 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12642 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12643 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12644 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012645}
12646#else
12647static inline void
12648hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012649 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012650{
Abhishek Singhb20db962017-03-03 21:28:46 +053012651}
12652#endif
12653
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012654void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12655 struct hdd_config *cfg)
12656{
12657 uint8_t i = 0;
12658
12659 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12660 if (!ie_whitelist->white_list)
12661 return;
12662
12663 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12664 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12665 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12666 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12667 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12668 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12669 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12670 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12671
12672 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12673 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12674 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12675}
12676
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012677uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12678{
12679 uint8_t i, score;
12680
12681 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12682 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12683 if (score > MAX_INDEX_SCORE)
12684 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12685 MAX_INDEX_SCORE, i);
12686 }
12687
12688 return per_index_score;
12689}
12690
12691/**
12692 * hdd_update_score_config - API to update candidate scoring related params
12693 * configuration parameters
12694 * @score_config: score config to update
12695 * @cfg: config params
12696 *
12697 * Return: 0 if success else err
12698 */
12699static void hdd_update_score_config(
12700 struct scoring_config *score_config, struct hdd_config *cfg)
12701{
12702 int total_weight;
12703
12704 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12705 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12706 score_config->weight_cfg.vht_caps_weightage =
12707 cfg->vht_caps_weightage;
12708 score_config->weight_cfg.he_caps_weightage =
12709 cfg->he_caps_weightage;
12710 score_config->weight_cfg.chan_width_weightage =
12711 cfg->chan_width_weightage;
12712 score_config->weight_cfg.chan_band_weightage =
12713 cfg->chan_band_weightage;
12714 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12715 score_config->weight_cfg.beamforming_cap_weightage =
12716 cfg->beamforming_cap_weightage;
12717 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12718 score_config->weight_cfg.channel_congestion_weightage =
12719 cfg->channel_congestion_weightage;
12720 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12721
12722 total_weight = score_config->weight_cfg.rssi_weightage +
12723 score_config->weight_cfg.ht_caps_weightage +
12724 score_config->weight_cfg.vht_caps_weightage +
12725 score_config->weight_cfg.he_caps_weightage +
12726 score_config->weight_cfg.chan_width_weightage +
12727 score_config->weight_cfg.chan_band_weightage +
12728 score_config->weight_cfg.nss_weightage +
12729 score_config->weight_cfg.beamforming_cap_weightage +
12730 score_config->weight_cfg.pcl_weightage +
12731 score_config->weight_cfg.channel_congestion_weightage +
12732 score_config->weight_cfg.oce_wan_weightage;
12733
12734 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12735 hdd_err("total weight is greater than %d fallback to default values",
12736 BEST_CANDIDATE_MAX_WEIGHT);
12737
12738 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12739 score_config->weight_cfg.ht_caps_weightage =
12740 HT_CAPABILITY_WEIGHTAGE;
12741 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12742 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12743 score_config->weight_cfg.chan_width_weightage =
12744 CHAN_WIDTH_WEIGHTAGE;
12745 score_config->weight_cfg.chan_band_weightage =
12746 CHAN_BAND_WEIGHTAGE;
12747 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12748 score_config->weight_cfg.beamforming_cap_weightage =
12749 BEAMFORMING_CAP_WEIGHTAGE;
12750 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12751 score_config->weight_cfg.channel_congestion_weightage =
12752 CHANNEL_CONGESTION_WEIGHTAGE;
12753 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12754 }
12755
12756 score_config->bandwidth_weight_per_index =
12757 hdd_limit_max_per_index_score(
12758 cfg->bandwidth_weight_per_index);
12759 score_config->nss_weight_per_index =
12760 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12761 score_config->band_weight_per_index =
12762 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12763
12764 score_config->rssi_score.best_rssi_threshold =
12765 cfg->best_rssi_threshold;
12766 score_config->rssi_score.good_rssi_threshold =
12767 cfg->good_rssi_threshold;
12768 score_config->rssi_score.bad_rssi_threshold =
12769 cfg->bad_rssi_threshold;
12770 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12771 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12772 score_config->rssi_score.good_rssi_bucket_size =
12773 cfg->good_rssi_bucket_size;
12774 score_config->rssi_score.bad_rssi_bucket_size =
12775 cfg->bad_rssi_bucket_size;
12776 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12777 cfg->rssi_pref_5g_rssi_thresh;
12778
12779 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12780 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12781 hdd_limit_max_per_index_score(
12782 cfg->esp_qbss_score_slots3_to_0);
12783 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12784 hdd_limit_max_per_index_score(
12785 cfg->esp_qbss_score_slots7_to_4);
12786 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12787 hdd_limit_max_per_index_score(
12788 cfg->esp_qbss_score_slots11_to_8);
12789 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12790 hdd_limit_max_per_index_score(
12791 cfg->esp_qbss_score_slots15_to_12);
12792
12793 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12794 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12795 hdd_limit_max_per_index_score(
12796 cfg->oce_wan_score_slots3_to_0);
12797 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12798 hdd_limit_max_per_index_score(
12799 cfg->oce_wan_score_slots7_to_4);
12800 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12801 hdd_limit_max_per_index_score(
12802 cfg->oce_wan_score_slots11_to_8);
12803 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12804 hdd_limit_max_per_index_score(
12805 cfg->oce_wan_score_slots15_to_12);
12806
12807
12808 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12809 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12810 score_config->nss = cfg->enable2x2 ? 2 : 1;
12811
12812 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12813 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12814 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12815 score_config->he_cap = 1;
12816
12817 if (score_config->he_cap ||
12818 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12819 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12820 score_config->vht_cap = 1;
12821
12822 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12823 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12824 score_config->ht_cap = 1;
12825
12826 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12827 score_config->vht_24G_cap = 1;
12828
12829 if (cfg->enableTxBF)
12830 score_config->beamformee_cap = 1;
12831
12832}
12833
Abhishek Singh257a9482017-03-06 16:52:39 +053012834/**
bings81fe50a2017-11-27 14:33:26 +080012835 * hdd_update_dfs_config() - API to update dfs configuration parameters.
12836 * @hdd_ctx: HDD context
12837 *
12838 * Return: 0 if success else err
12839 */
12840static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
12841{
12842 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12843 struct hdd_config *cfg = hdd_ctx->config;
12844 struct dfs_user_config dfs_cfg;
12845 QDF_STATUS status;
12846
12847 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
12848 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
12849 if (QDF_IS_STATUS_ERROR(status)) {
12850 hdd_err("failed dfs psoc configuration");
12851 return -EINVAL;
12852 }
12853
12854 return 0;
12855}
12856
12857/**
Abhishek Singh257a9482017-03-06 16:52:39 +053012858 * hdd_update_scan_config - API to update scan configuration parameters
12859 * @hdd_ctx: HDD context
12860 *
12861 * Return: 0 if success else err
12862 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012863static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012864{
12865 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12866 struct scan_user_cfg scan_cfg;
12867 struct hdd_config *cfg = hdd_ctx->config;
12868 QDF_STATUS status;
12869
12870 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12871 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12872 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12873 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12874 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12875 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12876 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012877 /* convert to ms */
12878 scan_cfg.scan_cache_aging_time =
12879 cfg->scanAgingTimeout * 1000;
12880 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12881 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12882 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12883 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012884 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012885 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012886 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12887 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012888 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012889 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053012890 scan_cfg.sta_miracast_mcc_rest_time =
12891 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053012892
Abhishek Singhb20db962017-03-03 21:28:46 +053012893 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012894 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012895 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012896
Abhishek Singh257a9482017-03-06 16:52:39 +053012897 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12898 if (status != QDF_STATUS_SUCCESS) {
12899 hdd_err("failed pmo psoc configuration");
12900 return -EINVAL;
12901 }
12902
12903 return 0;
12904}
Abhishek Singh257a9482017-03-06 16:52:39 +053012905
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012906int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012907{
12908 int ret;
12909
12910 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012911 if (ret)
12912 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012913
Abhishek Singh257a9482017-03-06 16:52:39 +053012914 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012915 if (ret)
12916 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012917
Frank Liud4b2fa02017-03-29 11:46:48 +080012918 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012919 if (ret)
12920 return ret;
12921
12922 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080012923 if (ret)
12924 return ret;
12925
12926 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012927
12928 return ret;
12929}
12930
Agrawal Ashish65634612016-08-18 13:24:32 +053012931/**
12932 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12933 * @mode : cfg80211 DFS mode
12934 *
12935 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12936 */
12937enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12938{
12939 switch (mode) {
12940 case DFS_MODE_ENABLE:
12941 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012942 case DFS_MODE_DISABLE:
12943 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012944 case DFS_MODE_DEPRIORITIZE:
12945 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012946 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012947 hdd_debug("ACS dfs mode is NONE");
12948 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012949 }
12950}
12951
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012952/**
12953 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12954 * @hddctx: pointer to hdd context
12955 * @set_value: enable/disable
12956 *
12957 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12958 * Host(even though it is duplicate). When Host send vendor command
12959 * disable,FW doesn't perform any action. Whenever any change in
12960 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12961 *
12962 * return - 0 on success, appropriate error values on failure.
12963 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012964int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012965{
12966 QDF_STATUS status;
12967
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012968 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012969 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012970
12971 if (!hddctx->config->goptimize_chan_avoid_event) {
12972 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12973 return -EINVAL;
12974 }
12975
12976 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12977 if (!QDF_IS_STATUS_SUCCESS(status)) {
12978 hdd_err("Failed to send chan avoid command to SME");
12979 return -EINVAL;
12980 }
12981 return 0;
12982}
Agrawal Ashish65634612016-08-18 13:24:32 +053012983
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012984/**
12985 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12986 * @value: value to set
12987 *
12988 * This function will set the passed value to roaming in progress flag.
12989 *
12990 * Return: None
12991 */
12992void hdd_set_roaming_in_progress(bool value)
12993{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012994 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012995
12996 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12997 if (!hdd_ctx) {
12998 hdd_err("HDD context is NULL");
12999 return;
13000 }
13001
13002 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013003 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013004}
13005
13006/**
13007 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013008 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013009 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013010 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013011 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013012bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013013{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013014 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013015 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013016
13017 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13018 if (!hdd_ctx) {
13019 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013020 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013021 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013022 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13023 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013024 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13025 hdd_ctx->roaming_in_progress);
13026
13027 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013028}
13029
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013030/**
13031 * hdd_is_connection_in_progress() - check if connection is in
13032 * progress
13033 * @session_id: session id
13034 * @reason: scan reject reason
13035 *
13036 * Go through each adapter and check if Connection is in progress
13037 *
13038 * Return: true if connection is in progress else false
13039 */
13040bool hdd_is_connection_in_progress(uint8_t *session_id,
13041 enum scan_reject_states *reason)
13042{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013043 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013044 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013045 uint8_t sta_id = 0;
13046 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013047 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013048
13049 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13050 if (!hdd_ctx) {
13051 hdd_err("HDD context is NULL");
13052 return false;
13053 }
13054
Dustin Brown920397d2017-12-13 16:27:50 -080013055 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013056 hdd_info("Adapter with device mode %s(%d) exists",
13057 hdd_device_mode_to_string(adapter->device_mode),
13058 adapter->device_mode);
13059 if (((QDF_STA_MODE == adapter->device_mode)
13060 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13061 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13062 && (eConnectionState_Connecting ==
13063 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13064 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013065 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013066 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013067 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013068 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013069 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013070 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013071 }
13072 return true;
13073 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013074 /*
13075 * sme_neighbor_middle_of_roaming is for LFR2
13076 * hdd_is_roaming_in_progress is for LFR3
13077 */
13078 if (((QDF_STA_MODE == adapter->device_mode) &&
13079 sme_neighbor_middle_of_roaming(
13080 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013081 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013082 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013083 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013084 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013085 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013086 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013087 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013088 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013089 }
13090 return true;
13091 }
13092 if ((QDF_STA_MODE == adapter->device_mode) ||
13093 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13094 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13095 hdd_sta_ctx =
13096 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13097 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013098 hdd_sta_ctx->conn_info.connState)
13099 && sme_is_sta_key_exchange_in_progress(
13100 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013101 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013102 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013103 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013104 " is in middle of WPS/EAPOL exchange.",
13105 MAC_ADDR_ARRAY(sta_mac));
13106 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013107 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013108 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013109 }
13110 return true;
13111 }
13112 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13113 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13114 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13115 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013116 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013117 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013118 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013119 continue;
13120
13121 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013122 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013123 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013124 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013125 " of SAP/GO is in middle of WPS/EAPOL exchange",
13126 MAC_ADDR_ARRAY(sta_mac));
13127 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013128 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013129 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013130 }
13131 return true;
13132 }
13133 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013134 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013135 return true;
13136 }
13137 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013138 }
Dustin Brown920397d2017-12-13 16:27:50 -080013139
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013140 return false;
13141}
13142
13143/**
13144 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013145 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013146 *
13147 * Return: None
13148 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013149void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013150{
Jeff Johnson87251032017-08-29 13:31:11 -070013151 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013152 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013153 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013154 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013155 tsap_Config_t *sap_config;
13156 void *sap_ctx;
13157
13158 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013159 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013160 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013161
13162 mutex_lock(&hdd_ctx->sap_lock);
13163 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13164 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013165 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13166 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13167 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13168 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013169 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013170 qdf_stop_bss_event,
13171 SME_CMD_TIMEOUT_VALUE);
13172
13173 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013174 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013175 goto end;
13176 }
13177 }
13178 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013179 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013180 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013181 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013182
13183 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013184 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013185 wlansap_reset_sap_config_add_ie(sap_config,
13186 eUPDATE_IE_ALL);
13187 goto end;
13188 }
13189
13190 qdf_event_reset(&hostapd_state->qdf_event);
13191 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13192 sap_config,
13193 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013194 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013195 wlansap_reset_sap_config_add_ie(sap_config,
13196 eUPDATE_IE_ALL);
13197 goto end;
13198 }
13199
Jeff Johnson6867ec32017-09-29 20:30:20 -070013200 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013201 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013202 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013203 SME_CMD_TIMEOUT_VALUE);
13204 wlansap_reset_sap_config_add_ie(sap_config,
13205 eUPDATE_IE_ALL);
13206 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013207 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013208 goto end;
13209 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013210 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013211 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070013212 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013213 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13214 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013215 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013216 }
13217end:
13218 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013219}
13220
13221/**
13222 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13223 * with non dfs acs
13224 *
13225 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13226 *
13227 * Return: None
13228 */
13229void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13230{
Jeff Johnson9d295242017-08-29 14:39:48 -070013231 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013232 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013233 cds_context_type *cds_ctx;
13234
13235 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13236 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013237 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013238 return;
13239 }
13240
13241 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13242 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013243 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013244 return;
13245 }
13246
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013247 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13248 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013249 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013250 return;
13251 }
13252
13253 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013254 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13255 &ap_adapter->event_flags) &&
13256 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013257 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013258
Jeff Johnson6867ec32017-09-29 20:30:20 -070013259 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013260 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013261 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013262 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013263 acs_cfg.acs_mode = true;
13264
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013265 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013266 }
13267}
13268
13269/**
13270 * hdd_set_connection_in_progress() - to set the connection in
13271 * progress flag
13272 * @value: value to set
13273 *
13274 * This function will set the passed value to connection in progress flag.
13275 * If value is previously being set to true then no need to set it again.
13276 *
13277 * Return: true if value is being set correctly and false otherwise.
13278 */
13279bool hdd_set_connection_in_progress(bool value)
13280{
13281 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013282 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013283
13284 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13285 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013286 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013287 return false;
13288 }
13289
13290 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13291 /*
13292 * if the value is set to true previously and if someone is
13293 * trying to make it true again then it could be some race
13294 * condition being triggered. Avoid this situation by returning
13295 * false
13296 */
13297 if (hdd_ctx->connection_in_progress && value)
13298 status = false;
13299 else
13300 hdd_ctx->connection_in_progress = value;
13301 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13302 return status;
13303}
13304
Jeff Johnson9d295242017-08-29 14:39:48 -070013305int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013306{
13307 if (!adapter) {
13308 hdd_err("Invalid adapter");
13309 return -EINVAL;
13310 }
13311 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013312 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013313 WMA_VDEV_MCC_SET_TIME_QUOTA,
13314 set_value, VDEV_CMD);
13315 return 0;
13316
13317}
13318
Jeff Johnson9d295242017-08-29 14:39:48 -070013319int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013320{
13321 if (!adapter) {
13322 hdd_err("Invalid adapter");
13323 return -EINVAL;
13324 }
13325
13326 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013327 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013328 WMA_VDEV_MCC_SET_TIME_LATENCY,
13329 set_value, VDEV_CMD);
13330 return 0;
13331}
13332
Jeff Johnson9d295242017-08-29 14:39:48 -070013333struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013334 *psoc, uint8_t vdev_id)
13335{
Jeff Johnson9d295242017-08-29 14:39:48 -070013336 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013337 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013338
13339 /*
13340 * Currently PSOC is not being used. But this logic will
13341 * change once we have the converged implementation of
13342 * HDD context per PSOC in place. This would break if
13343 * multiple vdev objects reuse the vdev id.
13344 */
13345 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13346 if (!adapter)
13347 hdd_err("Get adapter by vdev id failed");
13348
13349 return adapter;
13350}
13351
Jeff Johnson9d295242017-08-29 14:39:48 -070013352int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013353 int8_t *rssi, int8_t *snr)
13354{
13355 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070013356 struct hdd_wext_state *wext_state =
13357 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013358 tCsrRoamProfile *profile = &wext_state->roamProfile;
13359
13360 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
13361 profile, bssid, rssi, snr);
13362 if (QDF_STATUS_SUCCESS != status) {
13363 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13364 return -EINVAL;
13365 }
13366
13367 return 0;
13368}
13369
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013370/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013371 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13372 * @adapter - HDD adapter
13373 * @tos - type of service
13374 * @status - status of the traffic
13375 *
13376 * Return: 0 on success and non zero value on failure
13377 */
13378
13379int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13380 bool is_tos_active)
13381{
13382 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013383 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013384 uint32_t max_off_chan_time = 0;
13385 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013386 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013387 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013388
13389 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13390 ret = wlan_hdd_validate_context(hdd_ctx);
13391
13392 if (ret < 0) {
13393 hdd_err("failed to set limit off chan params");
13394 return ret;
13395 }
13396
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013397 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13398
13399 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013400 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013401 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013402 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013403
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013404 if (adapter->active_ac) {
13405 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013406 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013407 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13408 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13409 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013410 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013411 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013412 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13413 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13414 PM_LATENCY);
13415 } else {
13416 /*ignore this command if only BE/BK is active */
13417 is_tos_active = false;
13418 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13419 hdd_ctx->config->conc_system_pref);
13420 }
13421 } else {
13422 /* No active tos */
13423 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13424 hdd_ctx->config->conc_system_pref);
13425 }
13426
Jeff Johnson1b780e42017-10-31 14:11:45 -070013427 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013428 is_tos_active, max_off_chan_time,
13429 hdd_ctx->config->nRestTimeConc, true);
13430 if (!QDF_IS_STATUS_SUCCESS(status)) {
13431 hdd_err("failed to set limit off chan params");
13432 ret = -EINVAL;
13433 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013434
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013435 return ret;
13436}
13437
13438/**
13439 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13440 * @adapter - HDD adapter
13441 *
13442 * Return: 0 on success and non zero value on failure
13443 */
13444int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13445{
13446 struct hdd_context *hdd_ctx;
13447 int ret;
13448 QDF_STATUS status;
13449 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13450
13451 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13452 ret = wlan_hdd_validate_context(hdd_ctx);
13453 if (ret < 0)
13454 return ret;
13455
13456 /* set the system preferece to default */
13457 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13458 hdd_ctx->config->conc_system_pref);
13459
13460 /* clear the bitmap */
13461 adapter->active_ac = 0;
13462
13463 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013464 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013465
Jeff Johnson1b780e42017-10-31 14:11:45 -070013466 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013467 false, 0, 0, false);
13468 if (!QDF_IS_STATUS_SUCCESS(status)) {
13469 hdd_err("failed to reset limit off chan params");
13470 ret = -EINVAL;
13471 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013472
13473 return ret;
13474}
13475
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013476/**
13477 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13478 * @drv_op: Enum indicating driver op
13479 *
13480 * Return: none
13481 */
13482void hdd_start_driver_ops_timer(int drv_op)
13483{
13484 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13485 switch (drv_op) {
13486 case eHDD_DRV_OP_PROBE:
13487 memcpy(drv_ops_string, "probe", sizeof("probe"));
13488 break;
13489 case eHDD_DRV_OP_REMOVE:
13490 memcpy(drv_ops_string, "remove", sizeof("remove"));
13491 break;
13492 case eHDD_DRV_OP_SHUTDOWN:
13493 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13494 break;
13495 case eHDD_DRV_OP_REINIT:
13496 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13497 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013498 case eHDD_DRV_OP_IFF_UP:
13499 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13500 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013501 }
13502
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013503 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013504 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13505 HDD_OPS_INACTIVITY_TIMEOUT);
13506}
13507
13508/**
13509 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13510 *
13511 * Return: none
13512 */
13513void hdd_stop_driver_ops_timer(void)
13514{
13515 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13516}
13517
13518/**
13519 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13520 * inactivity timer
13521 *
13522 * Return: None
13523 */
13524void hdd_drv_ops_inactivity_handler(void)
13525{
13526 hdd_err("%s: %d Sec timer expired while in .%s",
13527 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13528
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013529 if (hdd_drv_ops_task) {
13530 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13531 qdf_print_thread_trace(hdd_drv_ops_task);
13532 } else {
13533 hdd_err("hdd_drv_ops_task is null");
13534 }
13535
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013536 /* Driver shutdown is stuck, no recovery possible at this point */
13537 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13538 sizeof("shutdown")))
13539 QDF_BUG(0);
13540
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013541 if (cds_is_fw_down()) {
13542 hdd_err("FW is down");
13543 return;
13544 }
13545
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013546 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013547 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013548 else
13549 QDF_BUG(0);
13550}
13551
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013552void hdd_pld_ipa_uc_shutdown_pipes(void)
13553{
13554 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13555
13556 if (!hdd_ctx)
13557 return;
13558
13559 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13560}
13561
Yun Parkff6a16a2017-09-26 16:38:18 -070013562/**
13563 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13564 * @struct hdd_context *hdd_ctx
13565 * @struct hdd_adapter *padapter
13566 * @bool enble
13567 *
13568 * Return: none
13569 */
13570void hdd_set_rx_mode_rps(bool enable)
13571{
13572 struct cds_config_info *cds_cfg = cds_get_ini_config();
13573 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13574 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13575
13576 if (adapter && hdd_ctx &&
13577 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13578 if (enable && !cds_cfg->rps_enabled)
13579 hdd_send_rps_ind(adapter);
13580 else if (!enable && cds_cfg->rps_enabled)
13581 hdd_send_rps_disable_ind(adapter);
13582 }
13583}
13584
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013585/* Register the module init/exit functions */
13586module_init(hdd_module_init);
13587module_exit(hdd_module_exit);
13588
13589MODULE_LICENSE("Dual BSD/GPL");
13590MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13591MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13592
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013593module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13594 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013595
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013596module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13597 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13598
Ravi Joshia307f632017-07-17 23:41:41 -070013599module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13600 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13601
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013602module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13603 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13604
13605module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13606
13607module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13608
13609module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);