blob: 4ffff2675429eb6dc962a44da59af0c68c6da92a [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
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530847 if (cds_is_fw_down()) {
848 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
849 (void *)_RET_IP_, cds_get_driver_state());
850 return -ENODEV;
851 }
852
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 return 0;
854}
855
Jeff Johnson9d295242017-08-29 14:39:48 -0700856int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700857{
858 if (!adapter) {
859 hdd_err("adapter is null");
860 return -EINVAL;
861 }
862
863 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
864 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
865 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
866 return -EINVAL;
867 }
868
869 if (!adapter->dev) {
870 hdd_err("adapter net_device is null");
871 return -EINVAL;
872 }
873
874 if (!(adapter->dev->flags & IFF_UP)) {
875 hdd_info("adapter net_device is not up");
876 return -EAGAIN;
877 }
878
Jeff Johnson1b780e42017-10-31 14:11:45 -0700879 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700880 hdd_info("adapter session is not open");
881 return -EAGAIN;
882 }
883
Jeff Johnson1b780e42017-10-31 14:11:45 -0700884 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
885 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700886 return -EINVAL;
887 }
888
889 return 0;
890}
891
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530893 * wlan_hdd_validate_modules_state() - Check modules status
894 * @hdd_ctx: HDD context pointer
895 *
896 * Check's the driver module's state and returns true if the
897 * modules are enabled returns false if modules are closed.
898 *
899 * Return: True if modules are enabled or false.
900 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700901bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530902{
903 mutex_lock(&hdd_ctx->iface_change_lock);
904 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
905 mutex_unlock(&hdd_ctx->iface_change_lock);
906 hdd_notice("Modules not enabled, Present status: %d",
907 hdd_ctx->driver_status);
908 return false;
909 }
910 mutex_unlock(&hdd_ctx->iface_change_lock);
911 return true;
912}
913
914/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700916 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 *
918 * This function sets the IBSS power save config parameters to WMA
919 * which will send it to firmware if FW supports IBSS power save
920 * before vdev start.
921 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530922 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 * on failure.
924 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700925QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800926{
927 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700928 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800929
930 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700931 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530932 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933 }
934
Jeff Johnson1b780e42017-10-31 14:11:45 -0700935 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800936 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
937 hdd_ctx->config->ibssATIMWinSize,
938 VDEV_CMD);
939 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700940 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530941 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800942 }
943
Jeff Johnson1b780e42017-10-31 14:11:45 -0700944 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800945 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
946 hdd_ctx->config->isIbssPowerSaveAllowed,
947 VDEV_CMD);
948 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700949 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
950 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530951 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800952 }
953
Jeff Johnson1b780e42017-10-31 14:11:45 -0700954 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
956 hdd_ctx->config->
957 isIbssPowerCollapseAllowed, VDEV_CMD);
958 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700959 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
960 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530961 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800962 }
963
Jeff Johnson1b780e42017-10-31 14:11:45 -0700964 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800965 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
966 hdd_ctx->config->isIbssAwakeOnTxRx,
967 VDEV_CMD);
968 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700969 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530970 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971 }
972
Jeff Johnson1b780e42017-10-31 14:11:45 -0700973 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
975 hdd_ctx->config->ibssInactivityCount,
976 VDEV_CMD);
977 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700978 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530979 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800980 }
981
Jeff Johnson1b780e42017-10-31 14:11:45 -0700982 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800983 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
984 hdd_ctx->config->ibssTxSpEndInactivityTime,
985 VDEV_CMD);
986 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700987 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
988 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530989 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800990 }
991
Jeff Johnson1b780e42017-10-31 14:11:45 -0700992 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
994 hdd_ctx->config->ibssPsWarmupTime,
995 VDEV_CMD);
996 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700997 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
998 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530999 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000 }
1001
Jeff Johnson1b780e42017-10-31 14:11:45 -07001002 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1004 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1005 VDEV_CMD);
1006 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001007 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1008 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301009 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001010 }
1011
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301012 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013}
1014
Yue Macd359b72017-10-03 15:21:00 -07001015#ifdef FEATURE_RUNTIME_PM
1016/**
1017 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1018 * @hdd_ctx: HDD context
1019 *
1020 * Return: None
1021 */
1022static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1023{
1024 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1025
Yue Macd359b72017-10-03 15:21:00 -07001026 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001027 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001028
1029 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1030}
1031
1032/**
1033 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1034 * @hdd_ctx: HDD Context
1035 *
1036 * Return: None
1037 */
1038static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1039{
1040 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1041
Yue Macd359b72017-10-03 15:21:00 -07001042 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001043 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001044
1045 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1046}
1047
Yue Macd359b72017-10-03 15:21:00 -07001048#else /* FEATURE_RUNTIME_PM */
1049static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1050static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001051#endif /* FEATURE_RUNTIME_PM */
1052
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001053#define INTF_MACADDR_MASK 0x7
1054
1055/**
1056 * hdd_update_macaddr() - update mac address
1057 * @config: hdd configuration
1058 * @hw_macaddr: mac address
1059 *
1060 * Mac address for multiple virtual interface is found as following
1061 * i) The mac address of the first interface is just the actual hw mac address.
1062 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1063 * define the mac address for the remaining interfaces and locally
1064 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1065 * supported virtual interfaces, right now this is 0x07 (meaning 8
1066 * interface).
1067 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1068 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1069 *
1070 * Return: None
1071 */
1072void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301073 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074{
1075 int8_t i;
1076 uint8_t macaddr_b3, tmp_br3;
1077
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301078 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301079 QDF_MAC_ADDR_SIZE);
1080 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301081 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301082 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001083 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1084 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1085 INTF_MACADDR_MASK;
1086 macaddr_b3 += tmp_br3;
1087
1088 /* XOR-ing bit-24 of the mac address. This will give enough
1089 * mac address range before collision
1090 */
1091 macaddr_b3 ^= (1 << 7);
1092
1093 /* Set locally administered bit */
1094 config->intfMacAddr[i].bytes[0] |= 0x02;
1095 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001096 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001097 MAC_ADDRESS_STR, i,
1098 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1099 }
1100}
1101
Kabilan Kannan44a58372017-12-06 18:16:11 -08001102static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1103{
1104 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1105 struct tdls_start_params tdls_cfg;
1106 struct tdls_user_config *config = &tdls_cfg.config;
1107 struct hdd_config *cfg = hdd_ctx->config;
1108 QDF_STATUS status;
1109
1110 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1111 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1112 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1113 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1114 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1115 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1116 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1117 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1118 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1119 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1120 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1121 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1122 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1123 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1124 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1125 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1126 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1127 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1128 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1129 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1130 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1131 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1132 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1133 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1134 (cfg->fEnableTDLSImplicitTrigger ?
1135 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1136 (cfg->fTDLSExternalControl ?
1137 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1138 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1139 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1140
1141 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1142 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1143 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1144 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1145 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1146 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1147 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1148 tdls_cfg.tdls_evt_cb_data = psoc;
1149 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
1150 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
1151 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
1152 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1153 tdls_cfg.tdls_wmm_cb_data = psoc;
1154 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1155 tdls_cfg.tdls_rx_cb_data = psoc;
1156 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1157
1158 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1159 if (status != QDF_STATUS_SUCCESS) {
1160 hdd_err("failed pmo psoc configuration");
1161 return -EINVAL;
1162 }
1163
1164 hdd_ctx->tdls_umac_comp_active = true;
1165 /* enable napier specific tdls data path */
1166 hdd_ctx->tdls_nap_active = true;
1167
1168 return 0;
1169}
1170
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001171static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172 struct wma_tgt_services *cfg)
1173{
1174 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001175
1176 /* Set up UAPSD */
1177 config->apUapsdEnabled &= cfg->uapsd;
1178
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001179 /* 11AX mode support */
1180 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1181 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1182 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1183
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001184 /* 11AC mode support */
1185 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1186 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1187 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001188
1189 /* ARP offload: override user setting if invalid */
1190 config->fhostArpOffload &= cfg->arp_offload;
1191
1192#ifdef FEATURE_WLAN_SCAN_PNO
1193 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001194 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195 if (cfg->pno_offload)
1196 config->PnoOffload = true;
1197#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001198#ifdef FEATURE_WLAN_TDLS
1199 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301200 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1201 cfg->en_tdls_offchan;
1202 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1203 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001204 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001205 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001206 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001207 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001208#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001209#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1210 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1211#endif
Will Huang496b36c2017-07-11 16:38:50 +08001212 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001213 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001214 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001215 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001216
1217}
1218
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001219/**
1220 * hdd_update_vdev_nss() - sets the vdev nss
1221 * @hdd_ctx: HDD context
1222 *
1223 * Sets the Nss per vdev type based on INI
1224 *
1225 * Return: None
1226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001227static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001228{
1229 struct hdd_config *cfg_ini = hdd_ctx->config;
1230 uint8_t max_supp_nss = 1;
1231
Naveen Rawat10b1c152017-01-18 11:16:06 -08001232 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001233 max_supp_nss = 2;
1234
1235 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001236 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001237
1238 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001239 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001240}
1241
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301242/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301243 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1244 * @hdd_ctx: HDD context
1245 *
1246 * Updates wiphy vhtcap fields
1247 *
1248 * Return: None
1249 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001250static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301251{
1252 struct ieee80211_supported_band *band_5g =
1253 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1254 uint32_t val;
1255
1256 if (!band_5g) {
1257 hdd_debug("5GHz band disabled, skipping capability population");
1258 return;
1259 }
1260
1261 val = hdd_ctx->config->txBFCsnValue;
1262 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1263
1264 val = NUM_OF_SOUNDING_DIMENSIONS;
1265 band_5g->vht_cap.cap |=
1266 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1267
1268 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1269 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1270}
1271
1272/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301273 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1274 * @hdd_ctx: HDD context
1275 *
1276 * Sets the DBS capability as per INI and firmware capability
1277 *
1278 * Return: None
1279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001280static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301281{
1282 struct hdd_config *cfg_ini = hdd_ctx->config;
1283 uint8_t hw_dbs_capable = 0;
1284
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001285 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1286 ((cfg_ini->dual_mac_feature_disable ==
1287 ENABLE_DBS_CXN_AND_SCAN) ||
1288 (cfg_ini->dual_mac_feature_disable ==
1289 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301290 hw_dbs_capable = 1;
1291
1292 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1293}
1294
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001295static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296 struct wma_tgt_ht_cap *cfg)
1297{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301298 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 uint32_t value, val32;
1300 uint16_t val16;
1301 struct hdd_config *pconfig = hdd_ctx->config;
1302 tSirMacHTCapabilityInfo *phtCapInfo;
1303 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1304 uint8_t enable_tx_stbc;
1305
1306 /* check and update RX STBC */
1307 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1308 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1309
1310 /* get the MPDU density */
1311 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1312
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301313 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001314 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001315 value = 0;
1316 }
1317
1318 /*
1319 * MPDU density:
1320 * override user's setting if value is larger
1321 * than the one supported by target
1322 */
1323 if (value > cfg->mpdu_density) {
1324 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1325 cfg->mpdu_density);
1326
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301327 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001328 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329 }
1330
1331 /* get the HT capability info */
1332 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301333 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001334 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001335 return;
1336 }
1337 val16 = (uint16_t) val32;
1338 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1339
1340 /* Set the LDPC capability */
1341 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1342
1343 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1344 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1345
1346 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1347 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1348
1349 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1350 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1351
1352 enable_tx_stbc = pconfig->enableTxSTBC;
1353
1354 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1355 pconfig->enable2x2 = 1;
1356 } else {
1357 pconfig->enable2x2 = 0;
1358 enable_tx_stbc = 0;
1359
1360 /* 1x1 */
1361 /* Update Rx Highest Long GI data Rate */
1362 if (sme_cfg_set_int(hdd_ctx->hHal,
1363 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001364 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301365 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001366 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001367 }
1368
1369 /* Update Tx Highest Long GI data Rate */
1370 if (sme_cfg_set_int
1371 (hdd_ctx->hHal,
1372 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001373 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301374 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001375 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001376 }
1377 }
1378 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1379 enable_tx_stbc = 0;
1380 phtCapInfo->txSTBC = enable_tx_stbc;
1381
1382 val32 = val16;
1383 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301384 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001385 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1387 value = SIZE_OF_SUPPORTED_MCS_SET;
1388 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301389 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001390 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001391
1392 if (pconfig->enable2x2) {
1393 for (value = 0; value < cfg->num_rf_chains; value++)
1394 mcs_set[value] =
1395 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1396
1397 status =
1398 sme_cfg_set_str(hdd_ctx->hHal,
1399 WNI_CFG_SUPPORTED_MCS_SET,
1400 mcs_set,
1401 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301402 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001403 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 }
1405 }
1406#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1407}
1408
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001409static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001410 struct wma_tgt_vht_cap *cfg)
1411{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301412 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 uint32_t value = 0;
1414 struct hdd_config *pconfig = hdd_ctx->config;
1415 struct wiphy *wiphy = hdd_ctx->wiphy;
1416 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001417 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001418 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001419 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001420 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001421
Dustin Brown5e06bd32016-10-04 12:49:10 -07001422 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001423 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001424 return;
1425 }
1426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427 /* Get the current MPDU length */
1428 status =
1429 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1430 &value);
1431
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301432 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001433 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434 value = 0;
1435 }
1436
1437 /*
1438 * VHT max MPDU length:
1439 * override if user configured value is too high
1440 * that the target cannot support
1441 */
1442 if (value > cfg->vht_max_mpdu) {
1443 status = sme_cfg_set_int(hdd_ctx->hHal,
1444 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1445 cfg->vht_max_mpdu);
1446
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001447 if (status == QDF_STATUS_E_FAILURE)
1448 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001449 }
1450
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001451 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1452 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1453
1454 if (pconfig->enable2x2)
1455 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1456
1457 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1458 QDF_STATUS_E_FAILURE) {
1459 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1460 }
1461
1462 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1463 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1464 if (pconfig->enable2x2)
1465 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1466
1467 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1468 QDF_STATUS_E_FAILURE) {
1469 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1470 }
1471
1472 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1473 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1474 if (pconfig->enable2x2)
1475 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1476
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001477 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001478 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1479
1480 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1481 QDF_STATUS_E_FAILURE) {
1482 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1483 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001484 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001485 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001486 &value);
1487
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301488 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001489 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 value = 0;
1491 }
1492
jiad4a7a33c2017-08-08 15:32:24 +08001493 /* Set HW RX LDPC capability */
1494 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1495 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 status = sme_cfg_set_int(hdd_ctx->hHal,
1497 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001498 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001499
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001500 if (status == QDF_STATUS_E_FAILURE)
1501 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001502 }
1503
1504 /* Get current GI 80 value */
1505 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1506 &value);
1507
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301508 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001509 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001510 value = 0;
1511 }
1512
1513 /* set the Guard interval 80MHz */
1514 if (value && !cfg->vht_short_gi_80) {
1515 status = sme_cfg_set_int(hdd_ctx->hHal,
1516 WNI_CFG_VHT_SHORT_GI_80MHZ,
1517 cfg->vht_short_gi_80);
1518
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001519 if (status == QDF_STATUS_E_FAILURE)
1520 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001521 }
1522
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001523 /* Get VHT TX STBC cap */
1524 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1525
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301526 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001527 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001528 value = 0;
1529 }
1530
1531 /* VHT TX STBC cap */
1532 if (value && !cfg->vht_tx_stbc) {
1533 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1534 cfg->vht_tx_stbc);
1535
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001536 if (status == QDF_STATUS_E_FAILURE)
1537 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001538 }
1539
1540 /* Get VHT RX STBC cap */
1541 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1542
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301543 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001544 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001545 value = 0;
1546 }
1547
1548 /* VHT RX STBC cap */
1549 if (value && !cfg->vht_rx_stbc) {
1550 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1551 cfg->vht_rx_stbc);
1552
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001553 if (status == QDF_STATUS_E_FAILURE)
1554 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555 }
1556
1557 /* Get VHT SU Beamformer cap */
1558 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1559 &value);
1560
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301561 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001562 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001563 value = 0;
1564 }
1565
1566 /* set VHT SU Beamformer cap */
1567 if (value && !cfg->vht_su_bformer) {
1568 status = sme_cfg_set_int(hdd_ctx->hHal,
1569 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1570 cfg->vht_su_bformer);
1571
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001572 if (status == QDF_STATUS_E_FAILURE)
1573 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001574 }
1575
1576 /* check and update SU BEAMFORMEE capabality */
1577 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1578 pconfig->enableTxBF = cfg->vht_su_bformee;
1579
1580 status = sme_cfg_set_int(hdd_ctx->hHal,
1581 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1582 pconfig->enableTxBF);
1583
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001584 if (status == QDF_STATUS_E_FAILURE)
1585 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001586
1587 /* Get VHT MU Beamformer cap */
1588 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1589 &value);
1590
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301591 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001592 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593 value = 0;
1594 }
1595
1596 /* set VHT MU Beamformer cap */
1597 if (value && !cfg->vht_mu_bformer) {
1598 status = sme_cfg_set_int(hdd_ctx->hHal,
1599 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1600 cfg->vht_mu_bformer);
1601
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001602 if (status == QDF_STATUS_E_FAILURE)
1603 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 }
1605
1606 /* Get VHT MU Beamformee cap */
1607 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1608 &value);
1609
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301610 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001611 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 value = 0;
1613 }
1614
1615 /* set VHT MU Beamformee cap */
1616 if (value && !cfg->vht_mu_bformee) {
1617 status = sme_cfg_set_int(hdd_ctx->hHal,
1618 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1619 cfg->vht_mu_bformee);
1620
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001621 if (status == QDF_STATUS_E_FAILURE)
1622 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623 }
1624
1625 /* Get VHT MAX AMPDU Len exp */
1626 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1627 &value);
1628
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301629 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001630 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 value = 0;
1632 }
1633
1634 /*
1635 * VHT max AMPDU len exp:
1636 * override if user configured value is too high
1637 * that the target cannot support.
1638 * Even though Rome publish ampdu_len=7, it can
1639 * only support 4 because of some h/w bug.
1640 */
1641
1642 if (value > cfg->vht_max_ampdu_len_exp) {
1643 status = sme_cfg_set_int(hdd_ctx->hHal,
1644 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1645 cfg->vht_max_ampdu_len_exp);
1646
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001647 if (status == QDF_STATUS_E_FAILURE)
1648 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649 }
1650
1651 /* Get VHT TXOP PS CAP */
1652 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1653
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301654 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001655 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001656 value = 0;
1657 }
1658
1659 /* set VHT TXOP PS cap */
1660 if (value && !cfg->vht_txop_ps) {
1661 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1662 cfg->vht_txop_ps);
1663
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001664 if (status == QDF_STATUS_E_FAILURE)
1665 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 }
1667
1668 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1669 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1670 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1671 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1672 else
1673 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1674
1675
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001676 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1677 status = sme_cfg_set_int(hdd_ctx->hHal,
1678 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1679 VHT_CAP_160_AND_80P80_SUPP);
1680 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001681 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001682 band_5g->vht_cap.cap |=
1683 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001684 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1685 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1686 status = sme_cfg_set_int(hdd_ctx->hHal,
1687 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1688 VHT_CAP_160_SUPP);
1689 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001690 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001691 band_5g->vht_cap.cap |=
1692 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001693 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1694 }
1695 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1696 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301697 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001698 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301699 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001700 &value);
1701 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301702 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001703 value = 0;
1704 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301705 /* set the Guard interval 160MHz */
1706 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001707 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301708 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1709 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001710
1711 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301712 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001713 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714
1715 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1716 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1717
1718 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1719 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1720 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1721 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1722
1723 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1724 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1725
1726 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1727 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1728 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1729 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1730 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1731 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1732
1733 band_5g->vht_cap.cap |=
1734 (cfg->vht_max_ampdu_len_exp <<
1735 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1736
1737 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1738 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1739 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1740 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1741 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1742 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1743 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1744 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1745
1746 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1747 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1748
1749}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001750
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001751/**
1752 * hdd_generate_macaddr_auto() - Auto-generate mac address
1753 * @hdd_ctx: Pointer to the HDD context
1754 *
1755 * Auto-generate mac address using device serial number.
1756 * Keep the first 3 bytes of OUI as before and replace
1757 * the last 3 bytes with the lower 3 bytes of serial number.
1758 *
1759 * Return: 0 for success
1760 * Non zero failure code for errors
1761 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001762static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001763{
1764 unsigned int serialno = 0;
1765 struct qdf_mac_addr mac_addr = {
1766 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1767 };
1768
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001769 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001770 if (serialno == 0)
1771 return -EINVAL;
1772
1773 serialno &= 0x00ffffff;
1774
1775 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1776 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1777 mac_addr.bytes[5] = serialno & 0xff;
1778
1779 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1780 return 0;
1781}
1782
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301783/**
1784 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1785 * configuration to cfg_ini in HDD
1786 * @hdd_ctx: Pointer to hdd_ctx
1787 * @cfg: target configuration
1788 *
1789 * Return: None
1790 */
1791#ifdef FEATURE_WLAN_RA_FILTERING
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 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1796}
1797#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001798static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301799 struct wma_tgt_cfg *cfg)
1800{
1801}
1802#endif
1803
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301804uint8_t hdd_check_green_ap_enable(struct hdd_context *hdd_ctx,
1805 bool *is_enabled)
1806{
1807 struct hdd_config *cfg;
1808 uint32_t concurrency_mode;
1809
1810 cfg = hdd_ctx->config;
1811 if (!cfg) {
1812 hdd_err("NULL hdd config");
1813 return -EINVAL;
1814 }
1815
1816 concurrency_mode = policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc);
1817
1818 if (cfg->enable2x2 && cfg->enableGreenAP) {
1819 if ((concurrency_mode & (1 << QDF_SAP_MODE)) &&
1820 !(concurrency_mode & (~(1 << QDF_SAP_MODE))))
1821 *is_enabled = true;
1822 }
1823 return 0;
1824}
1825
1826static int hdd_update_green_ap_config(struct hdd_context *hdd_ctx)
1827{
1828 struct green_ap_user_cfg green_ap_cfg;
1829 struct hdd_config *cfg = hdd_ctx->config;
1830 QDF_STATUS status;
1831
1832 green_ap_cfg.host_enable_egap = cfg->enable_egap;
1833 green_ap_cfg.egap_inactivity_time = cfg->egap_inact_time;
1834 green_ap_cfg.egap_wait_time = cfg->egap_wait_time;
1835 green_ap_cfg.egap_feature_flags = cfg->egap_feature_flag;
1836
1837 status = ucfg_green_ap_update_user_config(hdd_ctx->hdd_pdev,
1838 &green_ap_cfg);
1839 if (status != QDF_STATUS_SUCCESS) {
1840 hdd_err("failed to update green ap user configuration");
1841 return -EINVAL;
1842 }
1843
1844 return 0;
1845}
1846
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001847void hdd_update_tgt_cfg(void *context, void *param)
1848{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001849 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001850 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001851 struct wma_tgt_cfg *cfg = param;
1852 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001853 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301854 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001855 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301856
Dustin Brownbd68fe12017-11-21 15:28:52 -08001857 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1858 if (ret) {
1859 hdd_err("Failed to create pdev; errno:%d", ret);
1860 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001861 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001862 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001863 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001864 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1865 hdd_err("dispatcher pdev open failed");
1866 QDF_BUG(0);
1867 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301868 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001869
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301870 ret = hdd_update_green_ap_config(hdd_ctx);
1871
Naveen Rawat64e477e2016-05-20 10:34:56 -07001872 if (cds_cfg) {
1873 if (hdd_ctx->config->enable_sub_20_channel_width !=
1874 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1875 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1876 cds_cfg->sub_20_channel_width =
1877 WLAN_SUB_20_CH_WIDTH_NONE;
1878 } else {
1879 cds_cfg->sub_20_channel_width =
1880 hdd_ctx->config->enable_sub_20_channel_width;
1881 }
1882 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001883
1884 /* first store the INI band capability */
1885 temp_band_cap = hdd_ctx->config->nBandCapability;
1886
1887 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301888 hdd_ctx->is_fils_roaming_supported =
1889 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001890
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301891 hdd_ctx->config->is_11k_offload_supported =
1892 cfg->services.is_11k_offload_supported;
1893
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001894 /*
1895 * now overwrite the target band capability with INI
1896 * setting if INI setting is a subset
1897 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001898
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001899 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1900 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001901 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001902 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1903 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001904 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001905 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001906 }
1907
Amar Singhal58b45ef2017-08-01 13:43:54 -07001908 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1909
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301910 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001911 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1912 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1913 }
1914
1915 /* This can be extended to other configurations like ht, vht cap... */
1916
Anurag Chouhanc5548422016-02-24 18:33:27 +05301917 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001918 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001919 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001920 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001921 static struct qdf_mac_addr default_mac_addr = {
1922 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1923 };
1924 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1925 &default_mac_addr)) {
1926 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1927 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1928 MAC_ADDRESS_STR,
1929 MAC_ADDR_ARRAY(hdd_ctx->config->
1930 intfMacAddr[0].bytes));
1931 } else {
1932 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1933 MAC_ADDRESS_STR,
1934 MAC_ADDR_ARRAY(hdd_ctx->config->
1935 intfMacAddr[0].bytes));
1936 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001937 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001938 }
1939
1940 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001941 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001942
1943 hdd_ctx->max_intf_count = cfg->max_intf_count;
1944
Jeff Johnsonc875e242016-09-23 18:12:34 -07001945 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001947 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1948 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1949
1950 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001952 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001953 if (cfg->services.en_11ax) {
1954 hdd_info("11AX: 11ax is enabled - update HDD config");
1955 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1956 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001957
1958 hdd_update_vdev_nss(hdd_ctx);
1959
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301960 hdd_update_hw_dbs_capable(hdd_ctx);
1961
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001962 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001963 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001964 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001965 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001966
Nitesh Shahe50711f2017-04-26 16:30:45 +05301967 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1968 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1969 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001970 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001971 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001972
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001973 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1974 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301975 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301976 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301977
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301978 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001979 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1980 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301981 hdd_ctx->config->txBFCsnValue =
1982 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1983
Arif Hussainee10f902017-12-27 16:30:17 -08001984 status = sme_cfg_set_int(hdd_ctx->hHal,
1985 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1986 hdd_ctx->config->txBFCsnValue);
1987 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301988 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1989
1990
1991 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001992 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1993 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301994
1995 /*
1996 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1997 */
1998 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301999
Arun Khandavallid454d422016-08-17 12:47:05 +05302000 /*
2001 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
2002 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
2003 * configure the STA mode wow pattern.
2004 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302005 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05302006 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302007
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302008 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2009
Yue Macd359b72017-10-03 15:21:00 -07002010 /*
2011 * This needs to be done after HDD pdev is created and stored since
2012 * it will access the HDD pdev object lock.
2013 */
2014 hdd_runtime_suspend_context_init(hdd_ctx);
2015
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002016 /* Configure NAN datapath features */
2017 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002018 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002019 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002020 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2021 cfg->obss_detection_offloaded);
2022 if (QDF_IS_STATUS_ERROR(status))
2023 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002024
2025 status = sme_cfg_set_int(hdd_ctx->hHal,
2026 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2027 cfg->obss_color_collision_offloaded);
2028 if (QDF_IS_STATUS_ERROR(status))
2029 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002030}
2031
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002032bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002033{
Jeff Johnson9d295242017-08-29 14:39:48 -07002034 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002035 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002036
Jiachao Wuf610d912018-01-23 17:47:32 +08002037 if (!hdd_ctx) {
2038 hdd_info("Couldn't get hdd_ctx");
2039 return true;
2040 }
2041
2042 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002043 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002044 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302045 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002046 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002047
Dustin Brown920397d2017-12-13 16:27:50 -08002048 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002049 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2050
2051 if ((QDF_SAP_MODE == adapter->device_mode ||
2052 QDF_P2P_GO_MODE == adapter->device_mode) &&
2053 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002054 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002055 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2056 true;
2057 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002058 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302059 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002060 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302061
2062 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002063}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002064
2065/**
2066 * hdd_is_valid_mac_address() - validate MAC address
2067 * @pMacAddr: Pointer to the input MAC address
2068 *
2069 * This function validates whether the given MAC address is valid or not
2070 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2071 * where X is the hexa decimal digit character and separated by ':'
2072 * This algorithm works even if MAC address is not separated by ':'
2073 *
2074 * This code checks given input string mac contains exactly 12 hexadecimal
2075 * digits and a separator colon : appears in the input string only after
2076 * an even number of hex digits.
2077 *
2078 * Return: 1 for valid and 0 for invalid
2079 */
2080bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2081{
2082 int xdigit = 0;
2083 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002084
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002085 while (*pMacAddr) {
2086 if (isxdigit(*pMacAddr)) {
2087 xdigit++;
2088 } else if (':' == *pMacAddr) {
2089 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2090 break;
2091
2092 ++separator;
2093 } else {
2094 /* Invalid MAC found */
2095 return 0;
2096 }
2097 ++pMacAddr;
2098 }
2099 return xdigit == 12 && (separator == 5 || separator == 0);
2100}
2101
2102/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302103 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2104 * @dev: Handle to struct net_device to be updated.
2105 *
2106 * Return: None
2107 */
2108static void hdd_mon_mode_ether_setup(struct net_device *dev)
2109{
2110 dev->header_ops = NULL;
2111 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2112 dev->hard_header_len = ETH_HLEN;
2113 dev->mtu = ETH_DATA_LEN;
2114 dev->addr_len = ETH_ALEN;
2115 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2116 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2117 dev->priv_flags |= IFF_TX_SKB_SHARING;
2118
2119 memset(dev->broadcast, 0xFF, ETH_ALEN);
2120}
2121
2122/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002123 * __hdd__mon_open() - HDD Open function
2124 * @dev: Pointer to net_device structure
2125 *
2126 * This is called in response to ifconfig up
2127 *
2128 * Return: 0 for success; non-zero for failure
2129 */
2130static int __hdd_mon_open(struct net_device *dev)
2131{
2132 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002133 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2134 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002135
2136 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002137
2138 ret = wlan_hdd_validate_context(hdd_ctx);
2139 if (ret)
2140 return ret;
2141
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302142 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002143
2144 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2145 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2146 if (ret) {
2147 hdd_err("Failed to start WLAN modules return");
2148 return ret;
2149 }
2150 hdd_err("hdd_wlan_start_modules() successful !");
2151
2152 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2153 ret = hdd_start_adapter(adapter);
2154 if (ret) {
2155 hdd_err("Failed to start adapter :%d",
2156 adapter->device_mode);
2157 return ret;
2158 }
2159 hdd_err("hdd_start_adapters() successful !");
2160 }
2161 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2162 }
2163
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002164 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002165
2166 if (!ret)
2167 ret = hdd_enable_monitor_mode(dev);
2168
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002169 return ret;
2170}
2171
2172/**
2173 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2174 * @dev: Pointer to net_device structure
2175 *
2176 * This is called in response to ifconfig up
2177 *
2178 * Return: 0 for success; non-zero for failure
2179 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002180static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002181{
2182 int ret;
2183
2184 cds_ssr_protect(__func__);
2185 ret = __hdd_mon_open(dev);
2186 cds_ssr_unprotect(__func__);
2187
2188 return ret;
2189}
2190
2191/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302192 * hdd_start_adapter() - Wrapper function for device specific adapter
2193 * @adapter: pointer to HDD adapter
2194 *
2195 * This function is called to start the device specific adapter for
2196 * the mode passed in the adapter's device_mode.
2197 *
2198 * Return: 0 for success; non-zero for failure
2199 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002200int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302201{
2202
2203 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002204 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302205
2206 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002207 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302208
2209 switch (device_mode) {
2210 case QDF_P2P_CLIENT_MODE:
2211 case QDF_P2P_DEVICE_MODE:
2212 case QDF_OCB_MODE:
2213 case QDF_STA_MODE:
2214 case QDF_MONITOR_MODE:
2215 ret = hdd_start_station_adapter(adapter);
2216 if (ret)
2217 goto err_start_adapter;
2218 break;
2219 case QDF_P2P_GO_MODE:
2220 case QDF_SAP_MODE:
2221 ret = hdd_start_ap_adapter(adapter);
2222 if (ret)
2223 goto err_start_adapter;
2224 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302225 case QDF_IBSS_MODE:
2226 /*
2227 * For IBSS interface is initialized as part of
2228 * hdd_init_station_mode()
2229 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002230 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302231 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002232 /* vdevs are dynamically managed by firmware in FTM */
2233 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302234 default:
2235 hdd_err("Invalid session type %d", device_mode);
2236 QDF_ASSERT(0);
2237 goto err_start_adapter;
2238 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002239
Arun Khandavallifae92942016-08-01 13:31:08 +05302240 if (hdd_set_fw_params(adapter))
2241 hdd_err("Failed to set the FW params for the adapter!");
2242
2243 /*
2244 * Action frame registered in one adapter which will
2245 * applicable to all interfaces
2246 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302247 ret = wlan_hdd_cfg80211_register_frames(adapter);
2248 if (ret < 0) {
2249 hdd_err("Failed to register frames - ret %d", ret);
2250 goto err_start_adapter;
2251 }
2252
Dustin Browndb2a8be2017-12-20 11:49:56 -08002253exit_with_success:
Arun Khandavallifae92942016-08-01 13:31:08 +05302254 EXIT();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002255
Arun Khandavallifae92942016-08-01 13:31:08 +05302256 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002257
Arun Khandavallifae92942016-08-01 13:31:08 +05302258err_start_adapter:
2259 return -EINVAL;
2260}
2261
2262/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302263 * hdd_enable_power_management() - API to Enable Power Management
2264 *
2265 * API invokes Bus Interface Layer power management functionality
2266 *
2267 * Return: None
2268 */
2269static void hdd_enable_power_management(void)
2270{
2271 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2272
2273 if (!hif_ctx) {
2274 hdd_err("Bus Interface Context is Invalid");
2275 return;
2276 }
2277
2278 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2279}
2280
2281/**
2282 * hdd_disable_power_management() - API to disable Power Management
2283 *
2284 * API disable Bus Interface Layer Power management functionality
2285 *
2286 * Return: None
2287 */
2288static void hdd_disable_power_management(void)
2289{
2290 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2291
2292 if (!hif_ctx) {
2293 hdd_err("Bus Interface Context is Invalid");
2294 return;
2295 }
2296
2297 hif_disable_power_management(hif_ctx);
2298}
2299
2300/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302301 * hdd_update_hw_sw_info() - API to update the HW/SW information
2302 *
2303 * API to update the HW and SW information in the driver
2304 *
2305 * Return: None
2306 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002307static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302308{
2309 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002310 size_t target_hw_name_len;
2311 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302312
2313 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2314 if (!hif_sc) {
2315 hdd_err("HIF context is NULL");
2316 return;
2317 }
2318
2319 /*
2320 * target hw version/revision would only be retrieved after firmware
2321 * download
2322 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002323 hif_get_hw_info(hif_sc,
2324 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302325 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002326 &target_hw_name);
2327
2328 if (hdd_ctx->target_hw_name)
2329 qdf_mem_free(hdd_ctx->target_hw_name);
2330
2331 target_hw_name_len = strlen(target_hw_name) + 1;
2332 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2333 if (hdd_ctx->target_hw_name)
2334 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2335 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302336
2337 /* Get the wlan hw/fw version */
2338 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302339}
2340
2341/**
gbian62edd7e2017-03-07 13:12:13 +08002342 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2343 * @hdd_ctx: Pointer to hdd context
2344 *
2345 * Return: none
2346 */
2347static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002348hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002349{
2350 uint8_t num_entries = 0;
2351 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2352 uint8_t *tx_sched_wrr_ac;
2353 int i;
2354 cds_context_type *cds_ctx;
2355
2356 if (NULL == hdd_ctx)
2357 return;
2358
2359 if (NULL == hdd_ctx->config) {
2360 /* Do nothing if hdd_ctx is invalid */
2361 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2362 return;
2363 }
2364
2365 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2366
2367 if (!cds_ctx) {
2368 hdd_err("Invalid CDS Context");
2369 return;
2370 }
2371
2372 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2373 switch (i) {
2374 case OL_TX_WMM_AC_BE:
2375 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2376 break;
2377 case OL_TX_WMM_AC_BK:
2378 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2379 break;
2380 case OL_TX_WMM_AC_VI:
2381 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2382 break;
2383 case OL_TX_WMM_AC_VO:
2384 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2385 break;
2386 default:
2387 tx_sched_wrr_ac = NULL;
2388 break;
2389 }
2390
2391 hdd_string_to_u8_array(tx_sched_wrr_ac,
2392 tx_sched_wrr_param,
2393 &num_entries,
2394 sizeof(tx_sched_wrr_param));
2395
2396 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2397 cds_ctx->ac_specs[i].wrr_skip_weight =
2398 tx_sched_wrr_param[0];
2399 cds_ctx->ac_specs[i].credit_threshold =
2400 tx_sched_wrr_param[1];
2401 cds_ctx->ac_specs[i].send_limit =
2402 tx_sched_wrr_param[2];
2403 cds_ctx->ac_specs[i].credit_reserve =
2404 tx_sched_wrr_param[3];
2405 cds_ctx->ac_specs[i].discard_weight =
2406 tx_sched_wrr_param[4];
2407 }
2408
2409 num_entries = 0;
2410 }
2411}
2412
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002413#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002414static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2415 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2416{
Jeff Johnson9d295242017-08-29 14:39:48 -07002417 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002418 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002419
2420 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2421 if (!adapter) {
2422 hdd_err("Adapter is NULL");
2423 return PM_MAX_NUM_OF_MODE;
2424 }
2425
2426 return policy_mgr_convert_device_mode_to_qdf_type(
2427 adapter->device_mode);
2428}
2429
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002430static void hdd_register_policy_manager_callback(
2431 struct wlan_objmgr_psoc *psoc)
2432{
2433 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002434
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002435 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002436 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002437 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2438 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002439 hdd_cbacks.get_mode_for_non_connected_vdev =
2440 wlan_hdd_get_mode_for_non_connected_vdev;
2441
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002442 if (QDF_STATUS_SUCCESS !=
2443 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2444 hdd_err("HDD callback registration with policy manager failed");
2445 }
2446}
2447#else
2448static void hdd_register_policy_manager_callback(
2449 struct wlan_objmgr_psoc *psoc)
2450{
2451}
2452#endif
2453
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002454static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002455{
2456 struct nan_callbacks cb_obj = {0};
2457
2458 cb_obj.ndi_open = hdd_ndi_open;
2459 cb_obj.ndi_close = hdd_ndi_close;
2460 cb_obj.ndi_start = hdd_ndi_start;
2461 cb_obj.ndi_delete = hdd_ndi_delete;
2462 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2463 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2464
Naveen Rawat37f62c82017-03-26 22:24:43 -07002465 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2466 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002467 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002468
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002469 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2470}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002471
Dustin Brown26b3d042017-12-21 11:13:27 -08002472#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002473/**
2474 * hdd_check_for_leaks() - Perform runtime memory leak checks
2475 *
2476 * This API triggers runtime memory leak detection. This feature enforces the
2477 * policy that any memory allocated at runtime must also be released at runtime.
2478 *
2479 * Allocating memory at runtime and releasing it at unload is effectively a
2480 * memory leak for configurations which never unload (e.g. LONU, statically
2481 * compiled driver). Such memory leaks are NOT false positives, and must be
2482 * fixed.
2483 *
2484 * Return: None
2485 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002486static void hdd_check_for_leaks(void)
2487{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002488 /* DO NOT REMOVE these checks; for false positives, read above first */
2489
Dustin Brown677e0862017-10-10 16:30:09 -07002490 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002491 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002492 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002493}
2494
Dustin Brown26b3d042017-12-21 11:13:27 -08002495#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2496#else
2497static inline void hdd_check_for_leaks(void) {}
2498
2499#define hdd_debug_domain_set(domain)
2500#endif /* CONFIG_LEAK_DETECTION */
2501
gbian62edd7e2017-03-07 13:12:13 +08002502/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002503 * hdd_update_country_code - Update country code
2504 * @hdd_ctx: HDD context
2505 *
2506 * Update country code based on module parameter country_code
2507 *
2508 * Return: 0 on success and errno on failure
2509 */
2510static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2511{
2512 if (!country_code)
2513 return 0;
2514
2515 return hdd_reg_set_country(hdd_ctx, country_code);
2516}
2517
2518/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302519 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2520 * @hdd_ctx: HDD context
2521 * @adapter: HDD adapter
2522 * @reinit: flag to indicate from SSR or normal path
2523 *
2524 * This function maintains the driver state machine it will be invoked from
2525 * startup, reinit and change interface. Depending on the driver state shall
2526 * perform the opening of the modules.
2527 *
2528 * Return: 0 for success; non-zero for failure
2529 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002530int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2531 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302532 bool reinit)
2533{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002534 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302535 qdf_device_t qdf_dev;
2536 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302537 bool unint = false;
2538 void *hif_ctx;
2539
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002540 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302541
2542 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2543 if (!qdf_dev) {
2544 hdd_err("QDF Device Context is Invalid return");
2545 return -EINVAL;
2546 }
2547
Dustin Brown6f427922017-09-19 12:19:00 -07002548 hdd_set_idle_ps_config(hdd_ctx, false);
2549 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302550
Dustin Brown1fe30a82017-10-03 16:13:36 -07002551 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302552 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2553 mutex_unlock(&hdd_ctx->iface_change_lock);
2554 hdd_info("Driver modules already Enabled");
2555 EXIT();
2556 return 0;
2557 }
2558
Dustin Brown1fe30a82017-10-03 16:13:36 -07002559 hdd_ctx->start_modules_in_progress = true;
2560
Arun Khandavallifae92942016-08-01 13:31:08 +05302561 switch (hdd_ctx->driver_status) {
2562 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002563 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302564 unint = true;
2565 /* Fall through dont add break here */
2566 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002567 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2568
Dustin Brown26b3d042017-12-21 11:13:27 -08002569 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002570
Arun Khandavallifae92942016-08-01 13:31:08 +05302571 if (!reinit && !unint) {
2572 ret = pld_power_on(qdf_dev->dev);
2573 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002574 hdd_err("Failed to Powerup the device; errno: %d",
2575 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302576 goto release_lock;
2577 }
2578 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002579
2580 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2581 hdd_ctx->config->enable_fw_log);
2582
Arun Khandavallifae92942016-08-01 13:31:08 +05302583 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2584 qdf_dev->bus_type,
2585 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2586 HIF_ENABLE_TYPE_PROBE);
2587 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002588 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302589 goto power_down;
2590 }
2591
2592 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302593 if (!hif_ctx) {
2594 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002595 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302596 goto power_down;
2597 }
2598
Arun Khandavallifae92942016-08-01 13:31:08 +05302599 status = ol_cds_init(qdf_dev, hif_ctx);
2600 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002601 hdd_err("No Memory to Create BMI Context; status: %d",
2602 status);
2603 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302604 goto hif_close;
2605 }
2606
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002607 ret = hdd_update_config(hdd_ctx);
2608 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002609 hdd_err("Failed to update configuration; errno: %d",
2610 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002611 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002612 }
2613
gbian62edd7e2017-03-07 13:12:13 +08002614 hdd_update_cds_ac_specs_params(hdd_ctx);
2615
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302616 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002617 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002618 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002619 ret = qdf_status_to_os_return(status);
2620 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302621 }
2622
Mukul Sharma9d797a02017-01-05 20:26:03 +05302623 /* initalize components configurations after psoc open */
2624 ret = hdd_update_components_config(hdd_ctx);
2625 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002626 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302627 ret);
2628 goto close;
2629 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002630 status = cds_dp_open(hdd_ctx->hdd_psoc);
2631 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002632 hdd_err("Failed to Open cds post open; status: %d",
2633 status);
2634 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002635 goto close;
2636 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302637
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002638 /*
2639 * NAN compoenet requires certian operations like, open adapter,
2640 * close adapter, etc. to be initiated by HDD, for those
2641 * register HDD callbacks with UMAC's NAN componenet.
2642 */
2643 hdd_nan_register_callbacks(hdd_ctx);
2644
Arun Khandavallifae92942016-08-01 13:31:08 +05302645 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2646
Jeff Johnson3a280122017-09-13 07:42:00 -07002647 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302648 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002649 hdd_err("Failed to pre-enable CDS; status: %d", status);
2650 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002651 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302652 }
2653
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002654 hdd_register_policy_manager_callback(
2655 hdd_ctx->hdd_psoc);
2656
Amar Singhal0928b192017-12-01 10:50:54 -08002657 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2658
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302659 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302660 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002661 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302662
Arun Khandavallifae92942016-08-01 13:31:08 +05302663 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002664 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302665 break;
2666 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302667
2668 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002669 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2670 if (ret) {
2671 hdd_err("HDD IPA UC reinit failed; errno: %d",
2672 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002673 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002674 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302675 }
2676
Arun Khandavallifae92942016-08-01 13:31:08 +05302677 /* Fall through dont add break here */
2678 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002679 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2680
Arun Khandavallifae92942016-08-01 13:31:08 +05302681 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002682 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002683 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002684 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302685 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302686 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2687 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002688 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302689 break;
2690 }
Dustin Browndca39692017-11-09 15:30:25 -08002691
2692 ret = hdd_configure_cds(hdd_ctx, adapter);
2693 if (ret) {
2694 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002695 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302696 }
Dustin Browndca39692017-11-09 15:30:25 -08002697
Komal Seelamf2136bb2016-09-28 18:30:44 +05302698 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002699
Arun Khandavallifae92942016-08-01 13:31:08 +05302700 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002701 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302702 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002703
Arun Khandavallifae92942016-08-01 13:31:08 +05302704 default:
2705 hdd_err("WLAN start invoked in wrong state! :%d\n",
2706 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002707 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302708 goto release_lock;
2709 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002710
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302711 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002712 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2713 ret = hdd_update_country_code(hdd_ctx);
2714 if (ret)
2715 hdd_err("Failed to update command line country code!");
2716 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302717 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002718
Arun Khandavallifae92942016-08-01 13:31:08 +05302719 EXIT();
Dustin Brown550f6d22017-12-14 15:44:01 -08002720
Arun Khandavallifae92942016-08-01 13:31:08 +05302721 return 0;
2722
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002723post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002724 cds_post_disable();
Amar Singhal410675c2018-01-10 12:14:21 -08002725 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Dustin Brownbd68fe12017-11-21 15:28:52 -08002726 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002727
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002728cds_txrx_free:
2729 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002730
Arun Khandavallifae92942016-08-01 13:31:08 +05302731close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002732 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002733 hdd_info("Wlan transition aborted (now CLOSED)");
2734
Jeff Johnsone4b14592017-09-13 14:23:33 -07002735 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302736
Dustin Brown28b17892017-10-10 13:29:38 -07002737deinit_config:
2738 cds_deinit_ini_config();
2739
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002740cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302741 ol_cds_free();
2742
2743hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002744 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2745 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302746power_down:
2747 if (!reinit && !unint)
2748 pld_power_off(qdf_dev->dev);
2749release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302750 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302751 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002752
2753 /* many adapter resources are not freed by design in SSR case */
2754 if (!reinit)
2755 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002756 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002757
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302758 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002759
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002760 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302761}
2762
Naveen Rawat910726a2017-03-06 11:42:51 -08002763#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002764static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002765{
2766 int ret = os_if_wifi_pos_register_nl();
2767
2768 if (ret)
2769 hdd_err("os_if_wifi_pos_register_nl failed");
2770
2771 return ret;
2772}
2773
2774static int hdd_deactivate_wifi_pos(void)
2775{
2776 int ret = os_if_wifi_pos_deregister_nl();
2777
2778 if (ret)
2779 hdd_err("os_if_wifi_pos_deregister_nl failed");
2780
2781 return ret;
2782}
2783
2784/**
2785 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2786 * @hdd_ctx: hdd context
2787 *
2788 * Return: status of operation
2789 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002790static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002791{
2792 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2793 struct hdd_config *cfg = hdd_ctx->config;
2794
2795 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2796 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2797 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2798 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2799 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2800 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2801 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2802 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2803}
2804#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002805static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002806{
2807 return oem_activate_service(hdd_ctx);
2808}
2809
2810static int hdd_deactivate_wifi_pos(void)
2811{
2812 return 0;
2813}
2814
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002815static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002816{
2817}
2818#endif
2819
Arun Khandavallifae92942016-08-01 13:31:08 +05302820/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002821 * __hdd_open() - HDD Open function
2822 * @dev: Pointer to net_device structure
2823 *
2824 * This is called in response to ifconfig up
2825 *
2826 * Return: 0 for success; non-zero for failure
2827 */
2828static int __hdd_open(struct net_device *dev)
2829{
Jeff Johnson9d295242017-08-29 14:39:48 -07002830 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002831 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002832 int ret;
2833
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002834 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302835 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002836 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002837
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302838 /* Nothing to be done if device is unloading */
2839 if (cds_is_driver_unloading()) {
2840 hdd_err("Driver is unloading can not open the hdd");
2841 return -EBUSY;
2842 }
2843
Dustin Brown01847752017-10-25 13:56:27 -07002844 if (cds_is_driver_recovering()) {
2845 hdd_err("WLAN is currently recovering; Please try again.");
2846 return -EBUSY;
2847 }
2848
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302849 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2850 hdd_err("con_mode_handler is in progress; Please try again.");
2851 return -EBUSY;
2852 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302853
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302854 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302855 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2856
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302857 /*
2858 * This scenario can be hit in cases where in the wlan driver after
2859 * registering the netdevices and there is a failure in driver
2860 * initialization. So return error gracefully because the netdevices
2861 * will be de-registered as part of the load failure.
2862 */
2863
2864 if (!cds_is_driver_loaded()) {
2865 hdd_err("Failed to start the wlan driver!!");
2866 ret = -EIO;
2867 goto err_hdd_hdd_init_deinit_lock;
2868 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302869
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002870
Arun Khandavallifae92942016-08-01 13:31:08 +05302871 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2872 if (ret) {
2873 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302874 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302875 }
2876
2877
2878 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2879 ret = hdd_start_adapter(adapter);
2880 if (ret) {
2881 hdd_err("Failed to start adapter :%d",
2882 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302883 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302884 }
2885 }
2886
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002887 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2888 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002889 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002890 /* Enable TX queues only when we are connected */
2891 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302892 WLAN_START_ALL_NETIF_QUEUE,
2893 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002894 }
2895
Naveen Rawat286def52016-09-23 15:38:02 -07002896 /* Enable carrier and transmit queues for NDI */
2897 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002898 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002899 wlan_hdd_netif_queue_control(adapter,
2900 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2901 WLAN_CONTROL_PATH);
2902 }
2903
Naveen Rawat910726a2017-03-06 11:42:51 -08002904 hdd_populate_wifi_pos_cfg(hdd_ctx);
2905
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302906err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302907 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302908 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002909 return ret;
2910}
2911
Arun Khandavallifae92942016-08-01 13:31:08 +05302912
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002913/**
2914 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2915 * @dev: Pointer to net_device structure
2916 *
2917 * This is called in response to ifconfig up
2918 *
2919 * Return: 0 for success; non-zero for failure
2920 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002921static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922{
2923 int ret;
2924
2925 cds_ssr_protect(__func__);
2926 ret = __hdd_open(dev);
2927 cds_ssr_unprotect(__func__);
2928
2929 return ret;
2930}
2931
2932/**
2933 * __hdd_stop() - HDD stop function
2934 * @dev: Pointer to net_device structure
2935 *
2936 * This is called in response to ifconfig down
2937 *
2938 * Return: 0 for success; non-zero for failure
2939 */
2940static int __hdd_stop(struct net_device *dev)
2941{
Jeff Johnson9d295242017-08-29 14:39:48 -07002942 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002943 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002944 int ret;
2945
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002946 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302948 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002949 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002950
2951 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302952 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002953 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002954
2955 /* Nothing to be done if the interface is not opened */
2956 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002957 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002958 return -ENODEV;
2959 }
2960
2961 /* Make sure the interface is marked as closed */
2962 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302963
2964 hdd_debug("Disabling Auto Power save timer");
2965 sme_ps_disable_auto_ps_timer(
2966 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002967 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302968
2969 /*
2970 * Disable TX on the interface, after this hard_start_xmit() will not
2971 * be called on that interface
2972 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002973 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2974 hdd_device_mode_to_string(adapter->device_mode),
2975 adapter->device_mode);
2976
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302977 wlan_hdd_netif_queue_control(adapter,
2978 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2979 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002980
2981 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002982 * NAN data interface is different in some sense. The traffic on NDI is
2983 * bursty in nature and depends on the need to transfer. The service
2984 * layer may down the interface after the usage and up again when
2985 * required. In some sense, the NDI is expected to be available
2986 * (like SAP) iface until NDI delete request is issued by the service
2987 * layer. Skip BSS termination and adapter deletion for NAN Data
2988 * interface (NDI).
2989 */
2990 if (WLAN_HDD_IS_NDI(adapter))
2991 return 0;
2992
2993 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002994 * The interface is marked as down for outside world (aka kernel)
2995 * But the driver is pretty much alive inside. The driver needs to
2996 * tear down the existing connection on the netdev (session)
2997 * cleanup the data pipes and wait until the control plane is stabilized
2998 * for this interface. The call also needs to wait until the above
2999 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003000 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003001 * That is intentional to be able to scan if it is a STA/P2P interface
3002 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003003 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004
3005 /* DeInit the adapter. This ensures datapath cleanup as well */
3006 hdd_deinit_adapter(hdd_ctx, adapter, true);
3007
Arun Khandavallifae92942016-08-01 13:31:08 +05303008
3009 /*
3010 * Find if any iface is up. If any iface is up then can't put device to
3011 * sleep/power save mode
3012 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303013 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003014 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003015 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3016 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303017 hdd_prevent_suspend_timeout(
3018 hdd_ctx->config->iface_change_wait_time,
3019 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303020 }
3021
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003022 EXIT();
3023 return 0;
3024}
3025
3026/**
3027 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3028 * @dev: pointer to net_device structure
3029 *
3030 * This is called in response to ifconfig down
3031 *
3032 * Return: 0 for success and error number for failure
3033 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003034static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003035{
3036 int ret;
3037
3038 cds_ssr_protect(__func__);
3039 ret = __hdd_stop(dev);
3040 cds_ssr_unprotect(__func__);
3041
3042 return ret;
3043}
3044
3045/**
3046 * __hdd_uninit() - HDD uninit function
3047 * @dev: Pointer to net_device structure
3048 *
3049 * This is called during the netdev unregister to uninitialize all data
3050 * associated with the device
3051 *
3052 * Return: None
3053 */
3054static void __hdd_uninit(struct net_device *dev)
3055{
Jeff Johnson9d295242017-08-29 14:39:48 -07003056 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003057 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003058
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003059 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003060
3061 do {
3062 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003063 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003064 break;
3065 }
3066
Jeff Johnson399c6272017-08-30 10:51:00 -07003067 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3068 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003069 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003070 break;
3071 }
3072
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003073 if (dev != adapter->dev)
3074 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003075
Jeff Johnson399c6272017-08-30 10:51:00 -07003076 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003077
3078 /* after uninit our adapter structure will no longer be valid */
3079 adapter->dev = NULL;
3080 adapter->magic = 0;
3081 } while (0);
3082
3083 EXIT();
3084}
3085
3086/**
3087 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3088 * @dev: pointer to net_device structure
3089 *
3090 * This is called during the netdev unregister to uninitialize all data
3091 * associated with the device
3092 *
3093 * Return: none
3094 */
3095static void hdd_uninit(struct net_device *dev)
3096{
3097 cds_ssr_protect(__func__);
3098 __hdd_uninit(dev);
3099 cds_ssr_unprotect(__func__);
3100}
3101
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003102static int hdd_open_cesium_nl_sock(void)
3103{
3104#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3105 struct netlink_kernel_cfg cfg = {
3106 .groups = WLAN_NLINK_MCAST_GRP_ID,
3107 .input = NULL
3108 };
3109#endif
3110 int ret = 0;
3111
3112#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3113 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3114#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3115 THIS_MODULE,
3116#endif
3117 &cfg);
3118#else
3119 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3120 WLAN_NLINK_MCAST_GRP_ID,
3121 NULL, NULL, THIS_MODULE);
3122#endif
3123
3124 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003125 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003126 ret = -ECONNREFUSED;
3127 }
3128
3129 return ret;
3130}
3131
3132static void hdd_close_cesium_nl_sock(void)
3133{
3134 if (NULL != cesium_nl_srv_sock) {
3135 netlink_kernel_release(cesium_nl_srv_sock);
3136 cesium_nl_srv_sock = NULL;
3137 }
3138}
3139
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003140/**
3141 * __hdd_set_mac_address() - set the user specified mac address
3142 * @dev: Pointer to the net device.
3143 * @addr: Pointer to the sockaddr.
3144 *
3145 * This function sets the user specified mac address using
3146 * the command ifconfig wlanX hw ether <mac adress>.
3147 *
3148 * Return: 0 for success, non zero for failure
3149 */
3150static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3151{
Jeff Johnson9d295242017-08-29 14:39:48 -07003152 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003153 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303155 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003156 int ret;
3157
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003158 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003159
3160 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3161 ret = wlan_hdd_validate_context(hdd_ctx);
3162 if (0 != ret)
3163 return ret;
3164
Jeff Johnson1e851a12017-10-28 14:36:12 -07003165 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3167
3168 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303169 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003170}
3171
3172/**
3173 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3174 * function from SSR
3175 * @dev: pointer to net_device structure
3176 * @addr: Pointer to the sockaddr
3177 *
3178 * This function sets the user specified mac address using
3179 * the command ifconfig wlanX hw ether <mac adress>.
3180 *
3181 * Return: 0 for success.
3182 */
3183static int hdd_set_mac_address(struct net_device *dev, void *addr)
3184{
3185 int ret;
3186
3187 cds_ssr_protect(__func__);
3188 ret = __hdd_set_mac_address(dev, addr);
3189 cds_ssr_unprotect(__func__);
3190
3191 return ret;
3192}
3193
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003194uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003195{
3196 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003197
Anurag Chouhan6d760662016-02-20 16:05:43 +05303198 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3200 break;
3201 }
3202
Anurag Chouhan6d760662016-02-20 16:05:43 +05303203 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204 return NULL;
3205
3206 hdd_ctx->config->intfAddrMask |= (1 << i);
3207 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3208}
3209
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003210void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3211 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212{
3213 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003214
Anurag Chouhan6d760662016-02-20 16:05:43 +05303215 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003216 if (!memcmp(releaseAddr,
3217 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3218 6)) {
3219 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3220 break;
3221 }
3222 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003223}
3224
3225#ifdef WLAN_FEATURE_PACKET_FILTERING
3226/**
3227 * __hdd_set_multicast_list() - set the multicast address list
3228 * @dev: Pointer to the WLAN device.
3229 * @skb: Pointer to OS packet (sk_buff).
3230 *
3231 * This funciton sets the multicast address list.
3232 *
3233 * Return: None
3234 */
3235static void __hdd_set_multicast_list(struct net_device *dev)
3236{
Jeff Johnson9d295242017-08-29 14:39:48 -07003237 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238 int i = 0, status;
3239 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003240 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303241 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3242 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3243 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003245 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303246 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303247 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303248
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303250 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303251 goto out;
3252
Dustin Brownc788acb2017-08-01 17:43:51 -07003253 status = hdd_validate_adapter(adapter);
3254 if (status)
3255 goto out;
3256
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303257 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3258 hdd_err("%s: Driver module is closed", __func__);
3259 return;
3260 }
3261
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303262 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3263 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003264 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303265 goto out;
3266 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303268 /* Delete already configured multicast address list */
3269 if (adapter->mc_addr_list.mc_cnt > 0) {
3270 hdd_info("clear previously configured MC address list");
3271 hdd_disable_and_flush_mc_addr_list(adapter,
3272 pmo_mc_list_change_notify);
3273 }
3274
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003275 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003276 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303277 hdd_disable_and_flush_mc_addr_list(adapter,
3278 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003279 } else {
3280 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303281 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003282 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303283 pmo_ucfg_max_mc_addr_supported(psoc));
3284 hdd_disable_and_flush_mc_addr_list(adapter,
3285 pmo_mc_list_change_notify);
3286 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003287 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003289 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303290 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003291 if (i == mc_count)
3292 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303293 memset(&(mc_list_request->mc_addr[i].bytes),
3294 0, ETH_ALEN);
3295 memcpy(&(mc_list_request->mc_addr[i].bytes),
3296 ha->addr, ETH_ALEN);
3297 hdd_info("mlist[%d] = %pM", i,
3298 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299 i++;
3300 }
3301 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303302
3303 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003304 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303305 mc_list_request->count = mc_count;
3306 status = hdd_cache_mc_addr_list(mc_list_request);
3307 if (status == 0) {
3308 hdd_enable_mc_addr_filtering(adapter,
3309 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003310 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303311 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303313out:
3314 if (mc_list_request)
3315 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303316 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003317}
3318
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303319
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320/**
3321 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3322 * @dev: pointer to net_device
3323 *
3324 * Return: none
3325 */
3326static void hdd_set_multicast_list(struct net_device *dev)
3327{
3328 cds_ssr_protect(__func__);
3329 __hdd_set_multicast_list(dev);
3330 cds_ssr_unprotect(__func__);
3331}
3332#endif
3333
3334/**
3335 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3336 * @dev: Pointer to the WLAN device.
3337 * @skb: Pointer to OS packet (sk_buff).
3338 *
3339 * This function is registered with the Linux OS for network
3340 * core to decide which queue to use first.
3341 *
3342 * Return: ac, Queue Index/access category corresponding to UP in IP header
3343 */
3344static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3345#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3346 , void *accel_priv
3347#endif
3348#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3349 , select_queue_fallback_t fallback
3350#endif
3351)
3352{
3353 return hdd_wmm_select_queue(dev, skb);
3354}
3355
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003356static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003357 .ndo_open = hdd_open,
3358 .ndo_stop = hdd_stop,
3359 .ndo_uninit = hdd_uninit,
3360 .ndo_start_xmit = hdd_hard_start_xmit,
3361 .ndo_tx_timeout = hdd_tx_timeout,
3362 .ndo_get_stats = hdd_get_stats,
3363 .ndo_do_ioctl = hdd_ioctl,
3364 .ndo_set_mac_address = hdd_set_mac_address,
3365 .ndo_select_queue = hdd_select_queue,
3366#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003367 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368#endif
3369};
3370
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003371/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003372static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003373 .ndo_open = hdd_mon_open,
3374 .ndo_stop = hdd_stop,
3375 .ndo_get_stats = hdd_get_stats,
3376};
3377
3378/**
3379 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003380 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003381 * Return: None
3382 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003383void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003384{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003385 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003386 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003387 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003388 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003389}
3390
3391/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003392 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3393 * @hdd_ctx: global hdd context
3394 * @macAddr: mac address to assign to the interface
3395 * @name: User-visible name of the interface
3396 *
3397 * hdd adapter pointer would point to the netdev->priv space, this function
3398 * would retrive the pointer, and setup the hdd adapter configuration.
3399 *
3400 * Return: the pointer to hdd adapter, otherwise NULL
3401 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003402static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003403 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003404 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405 const char *name)
3406{
Jeff Johnson5505db82017-11-02 21:19:23 -07003407 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003408 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003409 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303410 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003411 /*
3412 * cfg80211 initialization and registration....
3413 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003414 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003415#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3416 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003418 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3419 hdd_mon_mode_ether_setup : ether_setup),
3420 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421
Jeff Johnson5505db82017-11-02 21:19:23 -07003422 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423
3424 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003425 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003426
Jeff Johnson9d295242017-08-29 14:39:48 -07003427 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003428 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303429 qdf_mem_set(sta_ctx->conn_info.staId,
3430 sizeof(sta_ctx->conn_info.staId),
3431 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003432 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003433 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003435 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303437 qdf_status = qdf_event_create(
3438 &adapter->qdf_session_open_event);
3439 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3440 hdd_err("Session open QDF event init failed!");
3441 free_netdev(adapter->dev);
3442 return NULL;
3443 }
3444
3445 qdf_status = qdf_event_create(
3446 &adapter->qdf_session_close_event);
3447 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3448 hdd_err("Session close QDF event init failed!");
3449 free_netdev(adapter->dev);
3450 return NULL;
3451 }
3452
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303454 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003455 init_completion(&adapter->linkup_event_var);
3456 init_completion(&adapter->cancel_rem_on_chan_var);
3457 init_completion(&adapter->rem_on_chan_ready_event);
3458 init_completion(&adapter->sta_authorized_event);
3459 init_completion(&adapter->offchannel_tx_event);
3460 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003461 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303463 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464
3465 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003466 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003467 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003468 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469
Jeff Johnson5505db82017-11-02 21:19:23 -07003470 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003472 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003474 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475
3476 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003477 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003479 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003480
Jeff Johnson5505db82017-11-02 21:19:23 -07003481 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483 hdd_set_station_ops(adapter->dev);
3484
Jeff Johnson5505db82017-11-02 21:19:23 -07003485 hdd_dev_setup_destructor(dev);
3486 dev->ieee80211_ptr = &adapter->wdev;
3487 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003489 adapter->wdev.netdev = dev;
3490 /* set dev's parent to underlying device */
3491 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492 hdd_wmm_init(adapter);
3493 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303494 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003495 }
3496
3497 return adapter;
3498}
3499
Jeff Johnson9d295242017-08-29 14:39:48 -07003500static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003502 struct net_device *dev = adapter->dev;
3503 int ret;
3504
3505 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003506
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003507 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003508 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3509
3510 ret = dev_alloc_name(dev, dev->name);
3511 if (ret < 0) {
3512 hdd_err(
3513 "unable to get dev name: %s, err = 0x%x",
3514 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303515 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516 }
3517 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003518
3519 ret = register_netdevice(dev);
3520 if (ret) {
3521 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3522 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303523 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003524 }
3525 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003526 ret = register_netdev(dev);
3527 if (ret) {
3528 hdd_err("register_netdev(%s) failed, err = 0x%x",
3529 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303530 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003531 }
3532 }
3533 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3534
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003535 EXIT();
3536
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303537 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538}
3539
Krunal Sonib51eec72017-11-20 21:53:01 -08003540QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003541{
Krunal Sonib51eec72017-11-20 21:53:01 -08003542 struct hdd_adapter *adapter;
3543 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003544
Krunal Sonib51eec72017-11-20 21:53:01 -08003545 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3546 if (!hdd_ctx) {
3547 hdd_err("Invalid HDD_CTX");
3548 return QDF_STATUS_E_FAILURE;
3549 }
3550
3551 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3552 if (NULL == adapter) {
3553 hdd_err("NULL adapter");
3554 return QDF_STATUS_E_INVAL;
3555 }
3556 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303557 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003558 hdd_debug("session %d opened", adapter->session_id);
3559
3560 return QDF_STATUS_SUCCESS;
3561}
3562
3563QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3564{
3565 struct hdd_adapter *adapter;
3566 struct hdd_context *hdd_ctx;
3567
3568 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3569 if (!hdd_ctx) {
3570 hdd_err("Invalid HDD_CTX");
3571 return QDF_STATUS_E_FAILURE;
3572 }
3573
3574 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003575 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003576 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303577 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 }
3579
3580 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003581 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303582 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003583 }
3584
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003585 /*
3586 * For NAN Data interface, the close session results in the final
3587 * indication to the userspace
3588 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003589 if (adapter->device_mode == QDF_NDI_MODE)
3590 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003591
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3593
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594 /*
3595 * We can be blocked while waiting for scheduled work to be
3596 * flushed, and the adapter structure can potentially be freed, in
3597 * which case the magic will have been reset. So make sure the
3598 * magic is still good, and hence the adapter structure is still
3599 * valid, before signaling completion
3600 */
3601 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303602 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303604 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605}
3606
Jeff Johnson9d295242017-08-29 14:39:48 -07003607int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608{
Dustin Brownd28772b2017-03-17 14:16:07 -07003609 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610
Dustin Brownd28772b2017-03-17 14:16:07 -07003611 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003612 if (QDF_IS_STATUS_ERROR(status))
3613 return qdf_status_to_os_return(status);
3614
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003615 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003616 if (QDF_IS_STATUS_ERROR(status))
3617 return qdf_status_to_os_return(status);
3618
3619 if (wma_capability_enhanced_mcast_filter())
3620 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3621 else
3622 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003623
3624 return qdf_status_to_os_return(status);
3625}
3626
Jeff Johnson9d295242017-08-29 14:39:48 -07003627int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003628{
3629 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003630 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003631 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003632 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003633
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003634 vdev_id = adapter->session_id;
3635 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003636
3637 /* vdev created sanity check */
3638 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003639 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003640 return -EINVAL;
3641 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003642 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003643
Dustin Brownd28772b2017-03-17 14:16:07 -07003644 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303645 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003646 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003647 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003648 if (QDF_IS_STATUS_ERROR(status)) {
3649 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003650 errno = qdf_status_to_os_return(status);
3651 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003652 }
3653
3654 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303655 status = qdf_wait_for_event_completion(
3656 &adapter->qdf_session_close_event,
3657 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3658 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003659 if (adapter->device_mode == QDF_NDI_MODE)
3660 hdd_ndp_session_end_handler(adapter);
3661 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303662 adapter->session_id = HDD_SESSION_ID_INVALID;
3663 if (QDF_STATUS_E_TIMEOUT != status) {
3664 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003665 errno = -ETIMEDOUT;
3666 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303667 } else if (adapter->qdf_session_close_event.force_set) {
3668 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003669 errno = -EINVAL;
3670 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303671 } else {
3672 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003673 errno = -EINVAL;
3674 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303675 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003676 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003677
Yue Maf9782842017-05-08 12:49:49 -07003678release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003679 /*
3680 * In SSR or driver unloading case, directly exit may cause objects
3681 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003682 */
Frank Liuc66d4bf2018-01-26 16:18:18 +08003683 if (errno && !(cds_is_driver_recovering() || cds_is_driver_unloading()))
Jiachao Wu2c42c222018-01-15 18:13:19 +08003684 return errno;
3685
Sandeep Puligillaef415362017-08-30 16:37:13 -07003686 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003687 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003688 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003689 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003690 return errno;
3691 }
3692
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003693 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003694
3695 return 0;
3696}
3697
Krunal Sonib51eec72017-11-20 21:53:01 -08003698static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3699 struct sme_session_params *session_param,
3700 csr_roam_completeCallback callback,
3701 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003702{
Dustin Brownd28772b2017-03-17 14:16:07 -07003703 uint32_t type;
3704 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003705 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003706
3707 /* determine vdev (sub)type */
3708 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303709 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003710 hdd_err("failed to get vdev type: %d", status);
3711 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003713 session_param->sme_session_id = adapter->session_id;
3714 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3715 session_param->type_of_persona = type;
3716 session_param->subtype_of_persona = sub_type;
3717 session_param->session_open_cb = hdd_sme_open_session_callback;
3718 session_param->session_close_cb = hdd_sme_close_session_callback;
3719 session_param->callback = callback;
3720 session_param->callback_ctx = callback_ctx;
3721
3722 return 0;
3723}
3724
3725int hdd_vdev_create(struct hdd_adapter *adapter,
3726 csr_roam_completeCallback callback, void *ctx)
3727{
3728 QDF_STATUS status;
3729 int errno;
3730 struct hdd_context *hdd_ctx;
3731 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003732
3733 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003734
3735 /* do vdev create via objmgr */
3736 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003737 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003738 if (errno) {
3739 hdd_err("failed to create objmgr vdev: %d", errno);
3740 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003741 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003742
3743 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303744 status = qdf_event_reset(&adapter->qdf_session_open_event);
3745 if (QDF_STATUS_SUCCESS != status) {
3746 hdd_err("failed to reinit session open event");
3747 return -EINVAL;
3748 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003749 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3750 callback, ctx);
3751 if (errno) {
3752 hdd_err("failed to populating SME params");
3753 goto objmgr_vdev_destroy_procedure;
3754 }
3755
3756 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003757 if (QDF_IS_STATUS_ERROR(status)) {
3758 hdd_err("failed to open sme session: %d", status);
3759 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003760 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003761 }
3762
3763 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303764 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3765 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3766 if (QDF_STATUS_SUCCESS != status) {
3767 if (adapter->qdf_session_open_event.force_set) {
3768 /*
3769 * SSR/PDR has caused shutdown, which has forcefully
3770 * set the event. Return without the closing session.
3771 */
3772 adapter->session_id = HDD_SESSION_ID_INVALID;
3773 hdd_err("Session open event forcefully set");
3774 return -EINVAL;
3775 } else {
3776 if (QDF_STATUS_E_TIMEOUT == status)
3777 hdd_err("Session failed to open within timeout period");
3778 else
3779 hdd_err("Failed to wait for session open event(status-%d)",
3780 status);
3781 errno = -ETIMEDOUT;
3782 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3783 goto hdd_vdev_destroy_procedure;
3784 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003785 }
3786
3787 /* firmware ready for component communication, raise vdev_ready event */
3788 errno = hdd_vdev_ready(adapter);
3789 if (errno) {
3790 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003791 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003792 }
3793
Jeff Johnson1b780e42017-10-31 14:11:45 -07003794 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003795
3796 return 0;
3797
3798 /*
3799 * Due to legacy constraints, we need to destroy in the same order as
3800 * create. So, split error handling into 2 cases to accommodate.
3801 */
3802
Krunal Soni4a020c72017-10-30 20:58:40 -07003803objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003804 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003805
3806 return errno;
3807
Krunal Soni4a020c72017-10-30 20:58:40 -07003808hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003809 QDF_BUG(!hdd_vdev_destroy(adapter));
3810
3811 return errno;
3812}
3813
Jeff Johnson9d295242017-08-29 14:39:48 -07003814QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003815{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003816 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003817 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003818 QDF_STATUS status;
3819 int ret_val;
3820
Dustin Brownd28772b2017-03-17 14:16:07 -07003821 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3822 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3823 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003824 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003825
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003827 status = hdd_register_wext(adapter->dev);
3828 if (QDF_IS_STATUS_ERROR(status)) {
3829 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 goto error_register_wext;
3831 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003832 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833
Himanshu Agarwalb229a142017-12-21 10:16:45 +05303834 hdd_debug("Disabling Green AP");
3835 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev, false);
3836 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
3837
Jeff Johnsond377dce2017-10-04 10:32:42 -07003838 qdf_mem_set(sta_ctx->conn_info.staId,
3839 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303840
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003841 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003842 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303843 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003845 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003846 hdd_ctx->config->OperatingChannel;
3847
3848 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003849 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850
3851 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303852 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003853 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003854 status, status);
3855 goto error_init_txrx;
3856 }
3857
3858 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3859
3860 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303861 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003862 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003863 status, status);
3864 goto error_wmm_init;
3865 }
3866
3867 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3868
Jeff Johnson1b780e42017-10-31 14:11:45 -07003869 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870 WMI_PDEV_PARAM_BURST_ENABLE,
3871 hdd_ctx->config->enableSifsBurst,
3872 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003873 if (ret_val)
3874 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003875
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303876 /*
3877 * In case of USB tethering, LRO is disabled. If SSR happened
3878 * during that time, then as part of SSR init, do not enable
3879 * the LRO again. Keep the LRO state same as before SSR.
3880 */
3881 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003882 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303883
3884 /* rcpi info initialization */
3885 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3886
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303887 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003888
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889error_wmm_init:
3890 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3891 hdd_deinit_tx_rx(adapter);
3892error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003893 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003894error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003895 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003896
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 return status;
3898}
3899
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303900/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003901 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303902 * @hdd_ctx: global hdd context
3903 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003904 * @rtnl_held: Used to indicate whether or not the caller is holding
3905 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303906 *
3907 * This function De-initializes the STA/P2P/OCB adapter.
3908 *
3909 * Return: None.
3910 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003911static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003912 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003913 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303914{
3915 ENTER_DEV(adapter->dev);
3916
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303917 if (adapter->dev) {
3918 if (rtnl_held)
3919 adapter->dev->wireless_handlers = NULL;
3920 else {
3921 rtnl_lock();
3922 adapter->dev->wireless_handlers = NULL;
3923 rtnl_unlock();
3924 }
3925 }
3926
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303927 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3928 hdd_deinit_tx_rx(adapter);
3929 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3930 }
3931
3932 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3933 hdd_wmm_adapter_close(adapter);
3934 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3935 }
3936
Krunal Sonib51eec72017-11-20 21:53:01 -08003937
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303938 EXIT();
3939}
3940
Krunal Sonib51eec72017-11-20 21:53:01 -08003941void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3942 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943 bool rtnl_held)
3944{
3945 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003948 case QDF_STA_MODE:
3949 case QDF_P2P_CLIENT_MODE:
3950 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003951 case QDF_IBSS_MODE:
3952 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003954 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003955 break;
3956 }
3957
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003958 case QDF_SAP_MODE:
3959 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003960 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003961 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 break;
3963 }
3964
3965 default:
3966 break;
3967 }
3968
3969 EXIT();
3970}
3971
Jeff Johnson9d295242017-08-29 14:39:48 -07003972static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003973 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974{
Jeff Johnson5505db82017-11-02 21:19:23 -07003975 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976
3977 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003978 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003980 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 return;
3982 }
3983
Rajeev Kumardca5f812016-02-04 17:28:06 -08003984 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303985
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986 /*
3987 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3988 * the driver is almost closed and cannot handle either control
3989 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003990 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3991 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992 * is not right. Setting this flag helps hdd_stop() to recognize that
3993 * the interface is closed and restricts any operations on that
3994 */
3995 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3996
3997 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003998 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003999 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004000 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004001 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004002 /*
4003 * Note that the adapter is no longer valid at this point
4004 * since the memory has been reclaimed
4005 */
4006 }
4007}
4008
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004009static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004010 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004011{
Jeff Johnson9d295242017-08-29 14:39:48 -07004012 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004013
Dustin Brown920397d2017-12-13 16:27:50 -08004014 hdd_for_each_adapter(hdd_ctx, adapter) {
4015 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4016 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304017 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 }
Dustin Brown920397d2017-12-13 16:27:50 -08004020
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304021 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004023
Arun Khandavalli2358d522016-05-16 18:05:37 +05304024#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4025/**
4026 * hdd_set_fw_log_params() - Set log parameters to FW
4027 * @hdd_ctx: HDD Context
4028 * @adapter: HDD Adapter
4029 *
4030 * This function set the FW Debug log level based on the INI.
4031 *
4032 * Return: None
4033 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004034static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004035 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304036{
4037 uint8_t count = 0, numentries = 0,
4038 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4039 uint32_t value = 0;
4040 int ret;
4041
Arun Khandavallifae92942016-08-01 13:31:08 +05304042 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4043 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004044 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304045 return;
4046 }
4047
Arun Khandavallifae92942016-08-01 13:31:08 +05304048 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304049 hdd_ctx->fw_log_settings.dl_type =
4050 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004051 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304052 WMI_DBGLOG_TYPE,
4053 hdd_ctx->config->enableFwLogType,
4054 DBG_CMD);
4055 if (ret != 0)
4056 hdd_err("Failed to enable FW log type ret %d",
4057 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304058
4059 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304060 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004061 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304062 WMI_DBGLOG_LOG_LEVEL,
4063 hdd_ctx->config->enableFwLogLevel,
4064 DBG_CMD);
4065 if (ret != 0)
4066 hdd_err("Failed to enable FW log level ret %d",
4067 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304068
4069 hdd_string_to_u8_array(
4070 hdd_ctx->config->enableFwModuleLogLevel,
4071 moduleloglevel,
4072 &numentries,
4073 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4074
4075 while (count < numentries) {
4076 /*
4077 * FW module log level input string looks like
4078 * below:
4079 * gFwDebugModuleLoglevel=<FW Module ID>,
4080 * <Log Level>,...
4081 * For example:
4082 * gFwDebugModuleLoglevel=
4083 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4084 * Above input string means :
4085 * For FW module ID 1 enable log level 0
4086 * For FW module ID 2 enable log level 1
4087 * For FW module ID 3 enable log level 2
4088 * For FW module ID 4 enable log level 3
4089 * For FW module ID 5 enable log level 4
4090 * For FW module ID 6 enable log level 5
4091 * For FW module ID 7 enable log level 6
4092 */
4093
Nishank Aggarwale239d962017-03-03 12:26:02 +05304094 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4095 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4096 hdd_err("Module id %d and dbglog level %d input length is more than max",
4097 moduleloglevel[count],
4098 moduleloglevel[count + 1]);
4099 return;
4100 }
4101
4102 value = moduleloglevel[count] << 16;
4103 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004104 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304105 WMI_DBGLOG_MOD_LOG_LEVEL,
4106 value, DBG_CMD);
4107 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304108 hdd_err("Failed to enable FW module log level %d ret %d",
4109 value, ret);
4110
4111 count += 2;
4112 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304113
Arun Khandavalli2358d522016-05-16 18:05:37 +05304114}
4115#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004116static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004117 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304118{
4119}
4120
4121#endif
4122
4123/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004124 * hdd_configure_chain_mask() - programs chain mask to firmware
4125 * @adapter: HDD adapter
4126 *
4127 * Return: 0 on success or errno on failure
4128 */
4129static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4130{
4131 int ret_val;
4132 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4133
4134 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4135 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4136 hdd_ctx->config->txchainmask1x1,
4137 hdd_ctx->config->rxchainmask1x1);
4138 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4139 hdd_ctx->config->dual_mac_feature_disable,
4140 hdd_ctx->config->tx_chain_mask_2g,
4141 hdd_ctx->config->rx_chain_mask_2g);
4142 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4143 hdd_ctx->config->tx_chain_mask_5g,
4144 hdd_ctx->config->rx_chain_mask_5g);
4145
4146 if (hdd_ctx->config->enable2x2) {
4147 hdd_info("2x2 enabled. skip chain mask programming");
4148 return 0;
4149 }
4150
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004151 if (hdd_ctx->config->dual_mac_feature_disable !=
4152 DISABLE_DBS_CXN_AND_SCAN) {
4153 hdd_info("DBS enabled(%d). skip chain mask programming",
4154 hdd_ctx->config->dual_mac_feature_disable);
4155 return 0;
4156 }
4157
Naveen Rawatdacb5032018-02-08 15:23:24 -08004158 if (hdd_ctx->lte_coex_ant_share) {
4159 hdd_info("lte ant sharing enabled. skip chainmask programming");
4160 return 0;
4161 }
4162
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004163 if (hdd_ctx->config->txchainmask1x1) {
4164 ret_val = sme_cli_set_command(adapter->session_id,
4165 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4166 hdd_ctx->config->txchainmask1x1,
4167 PDEV_CMD);
4168 if (ret_val)
4169 goto error;
4170 }
4171
4172 if (hdd_ctx->config->rxchainmask1x1) {
4173 ret_val = sme_cli_set_command(adapter->session_id,
4174 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4175 hdd_ctx->config->rxchainmask1x1,
4176 PDEV_CMD);
4177 if (ret_val)
4178 goto error;
4179 }
4180
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004181 if (hdd_ctx->config->txchainmask1x1 ||
4182 hdd_ctx->config->rxchainmask1x1) {
4183 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4184 return 0;
4185 }
4186
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004187 if (hdd_ctx->config->tx_chain_mask_2g) {
4188 ret_val = sme_cli_set_command(adapter->session_id,
4189 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4190 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4191 if (0 != ret_val)
4192 goto error;
4193 }
4194
4195 if (hdd_ctx->config->rx_chain_mask_2g) {
4196 ret_val = sme_cli_set_command(adapter->session_id,
4197 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4198 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4199 if (0 != ret_val)
4200 goto error;
4201 }
4202
4203 if (hdd_ctx->config->tx_chain_mask_5g) {
4204 ret_val = sme_cli_set_command(adapter->session_id,
4205 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4206 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4207 if (0 != ret_val)
4208 goto error;
4209 }
4210
4211 if (hdd_ctx->config->rx_chain_mask_5g) {
4212 ret_val = sme_cli_set_command(adapter->session_id,
4213 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4214 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4215 if (0 != ret_val)
4216 goto error;
4217 }
4218
4219 return 0;
4220
4221error:
4222 hdd_err("WMI PDEV set param failed %d", ret_val);
4223 return -EINVAL;
4224}
4225
4226/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304227 * hdd_set_fw_params() - Set parameters to firmware
4228 * @adapter: HDD adapter
4229 *
4230 * This function Sets various parameters to fw once the
4231 * adapter is started.
4232 *
4233 * Return: 0 on success or errno on failure
4234 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004235int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304236{
4237 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004238 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304239
4240 ENTER_DEV(adapter->dev);
4241
4242 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4243 if (!hdd_ctx)
4244 return -EINVAL;
4245
Dustin Brown732ab9c2017-06-15 13:24:09 -07004246 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4247 hdd_debug("FTM Mode is active; nothing to do");
4248 return 0;
4249 }
4250
Jeff Johnson1b780e42017-10-31 14:11:45 -07004251 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304252 WMI_PDEV_PARAM_DTIM_SYNTH,
4253 hdd_ctx->config->enable_lprx, PDEV_CMD);
4254 if (ret) {
4255 hdd_err("Failed to set LPRx");
4256 goto error;
4257 }
4258
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304259 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004260 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304261 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4262 hdd_ctx->config->upper_brssi_thresh);
4263
Jeff Johnson1b780e42017-10-31 14:11:45 -07004264 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304265 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4266 hdd_ctx->config->lower_brssi_thresh);
4267
Jeff Johnson1b780e42017-10-31 14:11:45 -07004268 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304269 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4270 hdd_ctx->config->enable_dtim_1chrx);
4271 }
4272
Dustin Brown732ab9c2017-06-15 13:24:09 -07004273 if (hdd_ctx->config->enable2x2) {
4274 hdd_debug("configuring 2x2 mode fw params");
4275
Jeff Johnson1b780e42017-10-31 14:11:45 -07004276 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004277 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4278 hdd_ctx->config->enable_cck_tx_fir_override,
4279 PDEV_CMD);
4280 if (ret) {
4281 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4282 ret);
4283 goto error;
4284 }
4285 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304286#define HDD_DTIM_1CHAIN_RX_ID 0x5
4287#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004288 hdd_debug("configuring 1x1 mode fw params");
4289
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004290 /*
4291 * Disable DTIM 1 chain Rx when in 1x1,
4292 * we are passing two value
4293 * as param_id << 29 | param_value.
4294 * Below param_value = 0(disable)
4295 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004296 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004297 WMI_STA_SMPS_PARAM_CMDID,
4298 HDD_DTIM_1CHAIN_RX_ID <<
4299 HDD_SMPS_PARAM_VALUE_S,
4300 VDEV_CMD);
4301 if (ret) {
4302 hdd_err("DTIM 1 chain set failed %d", ret);
4303 goto error;
4304 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304305
Arun Khandavalli2358d522016-05-16 18:05:37 +05304306#undef HDD_DTIM_1CHAIN_RX_ID
4307#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004308
4309 if (hdd_configure_chain_mask(adapter))
4310 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004311 }
4312
Jeff Johnson1b780e42017-10-31 14:11:45 -07004313 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004314 WMI_PDEV_PARAM_HYST_EN,
4315 hdd_ctx->config->enableMemDeepSleep,
4316 PDEV_CMD);
4317 if (ret) {
4318 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4319 goto error;
4320 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304321
Jeff Johnson1b780e42017-10-31 14:11:45 -07004322 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004323 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4324 hdd_ctx->config->rts_profile,
4325 VDEV_CMD);
4326 if (ret) {
4327 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4328 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304329 }
4330
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004331 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4332
Jeff Johnson1b780e42017-10-31 14:11:45 -07004333 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004334 GEN_VDEV_PARAM_AMSDU,
4335 hdd_ctx->config->max_amsdu_num,
4336 GEN_CMD);
4337 if (ret != 0) {
4338 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4339 goto error;
4340 }
4341
Arun Khandavalli2358d522016-05-16 18:05:37 +05304342 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304343 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004344
Arun Khandavalli2358d522016-05-16 18:05:37 +05304345 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304346
Arun Khandavalli2358d522016-05-16 18:05:37 +05304347error:
4348 return -EINVAL;
4349}
4350
Ryan Hsu07495ea2016-01-21 15:25:39 -08004351/**
4352 * hdd_open_adapter() - open and setup the hdd adatper
4353 * @hdd_ctx: global hdd context
4354 * @session_type: type of the interface to be created
4355 * @iface_name: User-visible name of the interface
4356 * @macAddr: MAC address to assign to the interface
4357 * @name_assign_type: the name of assign type of the netdev
4358 * @rtnl_held: the rtnl lock hold flag
4359 *
4360 * This function open and setup the hdd adpater according to the device
4361 * type request, assign the name, the mac address assigned, and then prepared
4362 * the hdd related parameters, queue, lock and ready to start.
4363 *
4364 * Return: the pointer of hdd adapter, otherwise NULL.
4365 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004366struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004368 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004369 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004370{
Jeff Johnson9d295242017-08-29 14:39:48 -07004371 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304372 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004373
4374 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4375 /*
4376 * Max limit reached on the number of vdevs configured by the
4377 * host. Return error
4378 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304379 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4380 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 return NULL;
4382 }
4383
4384 if (macAddr == NULL) {
4385 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304386 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004387 return NULL;
4388 }
4389 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304390 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304391 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4392 " already exists",
4393 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394 return NULL;
4395 }
4396
4397 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004398 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399 /* Reset locally administered bit if the device mode is STA */
4400 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304401 hdd_info("locally administered bit reset in sta mode: "
4402 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004403 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004404 case QDF_P2P_CLIENT_MODE:
4405 case QDF_P2P_DEVICE_MODE:
4406 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004407 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304408 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004409 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4410 name_assign_type,
4411 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412
4413 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304414 hdd_err("failed to allocate adapter for session %d",
4415 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 return NULL;
4417 }
4418
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004419 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004421 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304423 else if (QDF_MONITOR_MODE == session_type)
4424 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425 else
4426 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4427
4428 adapter->device_mode = session_type;
4429
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004430
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431 /*
4432 * Workqueue which gets scheduled in IPv4 notification
4433 * callback
4434 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004435 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437
4438#ifdef WLAN_NS_OFFLOAD
4439 /*
4440 * Workqueue which gets scheduled in IPv6
4441 * notification callback.
4442 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004443 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004444 hdd_ipv6_notifier_work_queue);
4445#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004447 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004448 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004449
4450 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004451 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004452 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304453 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4454 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304455
Ravi Joshi1a292562017-05-18 16:28:54 -07004456 /* Initialize NAN Data Interface */
4457 if (QDF_NDI_MODE == session_type) {
4458 status = hdd_init_nan_data_mode(adapter);
4459 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004460 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004461 }
4462
4463 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004465 case QDF_P2P_GO_MODE:
4466 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004467 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4468 name_assign_type,
4469 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004470 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004471 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304472 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004473 return NULL;
4474 }
4475
4476 adapter->wdev.iftype =
4477 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004478 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004479 NL80211_IFTYPE_P2P_GO;
4480 adapter->device_mode = session_type;
4481
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004482 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004483 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004484 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004485
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004486 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004487 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304488 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4489 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304490
4491 /*
4492 * Workqueue which gets scheduled in IPv4 notification
4493 * callback
4494 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004495 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304496 hdd_ipv4_notifier_work_queue);
4497
4498#ifdef WLAN_NS_OFFLOAD
4499 /*
4500 * Workqueue which gets scheduled in IPv6
4501 * notification callback.
4502 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004503 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304504 hdd_ipv6_notifier_work_queue);
4505#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304507 case QDF_FTM_MODE:
4508 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4509 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004510 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304511 if (NULL == adapter) {
4512 hdd_err("Failed to allocate adapter for FTM mode");
4513 return NULL;
4514 }
4515 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4516 adapter->device_mode = session_type;
4517 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004518 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004519 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004520
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304521 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004522 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304523 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304524 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4525 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304526 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004528 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304529 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004530 return NULL;
4531 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004532
hqueaa33ee2017-05-04 17:56:35 +08004533 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4534
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304535 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004536 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004537 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004538 }
4539
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304540 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004541 if (NULL != adapter) {
4542 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4543 adapter = NULL;
4544 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004545
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004546 return NULL;
4547 }
4548
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304549 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004550 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4551 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004552
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004553 /* Adapter successfully added. Increment the vdev count */
4554 hdd_ctx->current_intf_count++;
4555
Jeff Johnson5880d792016-08-15 13:32:30 -07004556 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004557 hdd_ctx->current_intf_count);
4558
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004559 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004560 }
4561
Rajeev Kumardca5f812016-02-04 17:28:06 -08004562 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004563 hdd_err("Interface %s wow debug_fs init failed",
4564 netdev_name(adapter->dev));
4565
4566 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4567 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568
4569 return adapter;
4570
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004572 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304573 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574
4575 return NULL;
4576}
4577
Jeff Johnson9d295242017-08-29 14:39:48 -07004578QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004579 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004580{
Dustin Brown920397d2017-12-13 16:27:50 -08004581 /*
4582 * Here we are stopping global bus_bw timer & work per adapter.
4583 *
4584 * The reason is to fix one race condition between
4585 * bus bandwidth work and cleaning up an adapter.
4586 * Under some conditions, it is possible for the bus bandwidth
4587 * work to access a particularly destroyed adapter, leading to
4588 * use-after-free.
4589 */
4590 hdd_debug("wait for bus bw work to flush");
4591 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4592 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004593
Dustin Brown920397d2017-12-13 16:27:50 -08004594 /* cleanup adapter */
4595 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4596 adapter->device_mode);
4597 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4598 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004599
Dustin Brown920397d2017-12-13 16:27:50 -08004600 /* conditionally restart the bw timer */
4601 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004602
Dustin Brown920397d2017-12-13 16:27:50 -08004603 /* Adapter removed. Decrement vdev count */
4604 if (hdd_ctx->current_intf_count != 0)
4605 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004606
Dustin Brown920397d2017-12-13 16:27:50 -08004607 /* Fw will take care incase of concurrency */
4608 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004609}
4610
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004611/**
4612 * hdd_close_all_adapters - Close all open adapters
4613 * @hdd_ctx: Hdd context
4614 * rtnl_held: True if RTNL lock held
4615 *
4616 * Close all open adapters.
4617 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304618 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004619 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004620QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004621{
Dustin Brown920397d2017-12-13 16:27:50 -08004622 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304623 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624
4625 ENTER();
4626
4627 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004628 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4629 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304630 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004631 adapter->mac_addr.bytes);
4632 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4633
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304634 /* Adapter removed. Decrement vdev count */
4635 if (hdd_ctx->current_intf_count != 0)
4636 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004637 }
Dustin Brown920397d2017-12-13 16:27:50 -08004638 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004639
4640 EXIT();
4641
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304642 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004643}
4644
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004645void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004646{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304647 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004648 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004649
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004650 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004651 case QDF_STA_MODE:
4652 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004654 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004655 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004656 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004657 break;
4658 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004659 case QDF_SAP_MODE:
4660 case QDF_P2P_GO_MODE:
4661 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004663 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004664 break;
4665 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004666 case QDF_FTM_MODE:
4667 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004668 default:
4669 /*
4670 * wlan_hdd_reset_prob_rspies should not have been called
4671 * for these kind of devices
4672 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004673 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004674 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004675 return;
4676 }
4677
Anurag Chouhanc5548422016-02-24 18:33:27 +05304678 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004679 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004680 updateIE.ieBufferlength = 0;
4681 updateIE.pAdditionIEBuffer = NULL;
4682 updateIE.append = true;
4683 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004684 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004685 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304686 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004687 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004688 }
4689}
4690
Dustin Browndb2a8be2017-12-20 11:49:56 -08004691QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4692 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004693{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304694 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004695 struct hdd_wext_state *pWextState =
4696 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004697 union iwreq_data wrqu;
4698 tSirUpdateIE updateIE;
4699 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304700 tsap_Config_t *sap_config;
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304701 bool is_enabled = false;
4702 uint8_t ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004703
4704 ENTER();
4705
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004706 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304707 wlan_hdd_netif_queue_control(adapter,
4708 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4709 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004710 /*
4711 * if this is the last active connection check & stop the
4712 * opportunistic timer first
4713 */
4714 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4715 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4716 policy_mgr_convert_device_mode_to_qdf_type(
4717 adapter->device_mode), NULL) == 1)) ||
4718 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4719 policy_mgr_check_and_stop_opportunistic_timer(
4720 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004721 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004722 case QDF_STA_MODE:
4723 case QDF_P2P_CLIENT_MODE:
4724 case QDF_IBSS_MODE:
4725 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004726 case QDF_NDI_MODE:
4727 if ((QDF_NDI_MODE == adapter->device_mode) ||
4728 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4730 hdd_is_connecting(
4731 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004732 INIT_COMPLETION(adapter->disconnect_comp_var);
4733 /*
4734 * For NDI do not use pWextState from sta_ctx, if needed
4735 * extract from ndi_ctx.
4736 */
4737 if (QDF_NDI_MODE == adapter->device_mode)
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_NDI_DELETE);
4742 else if (pWextState->roamProfile.BSSType ==
4743 eCSR_BSS_TYPE_START_IBSS)
4744 qdf_ret_status = sme_roam_disconnect(
4745 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004746 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004747 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004748 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004749 qdf_ret_status =
4750 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004751 hdd_debug("Send disconnected event to userspace");
4752 wlan_hdd_cfg80211_indicate_disconnect(
4753 adapter->dev, true,
4754 WLAN_REASON_UNSPECIFIED);
4755 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004756 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004757 qdf_ret_status = sme_roam_disconnect(
4758 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004759 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004760 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004761 /* success implies disconnect command got
4762 * queued up successfully
4763 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004764 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4765 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766 rc = wait_for_completion_timeout(
4767 &adapter->disconnect_comp_var,
4768 msecs_to_jiffies
4769 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004770 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004771 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004772 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004773 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4774 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004775 memset(&wrqu, '\0', sizeof(wrqu));
4776 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4777 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4778 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4779 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304780 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004781 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004782
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304783 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304784 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004785
4786#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004787 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004788#endif
4789
4790 hdd_deregister_tx_flow_control(adapter);
4791
4792#ifdef WLAN_NS_OFFLOAD
4793#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004794 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004795#endif
4796#endif
4797
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304798 if (adapter->device_mode == QDF_STA_MODE)
4799 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4800 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004801
4802 if (wlan_hdd_try_disconnect(adapter)) {
4803 hdd_err("Error: Can't disconnect adapter");
4804 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004805 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004806
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304807 ret = hdd_check_green_ap_enable(hdd_ctx, &is_enabled);
4808 if (!ret) {
4809 hdd_debug("Green AP enable status: %d", is_enabled);
4810 if (is_enabled) {
4811 hdd_debug("Enabling Green AP");
4812 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
4813 true);
4814 wlan_green_ap_start(hdd_ctx->hdd_pdev);
4815 }
4816 } else {
4817 hdd_err("Failed to check if Green AP should be enabled or not");
4818 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004819
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304820 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004821 break;
4822
Rajeev Kumar3b906202018-02-01 10:55:14 -08004823 case QDF_MONITOR_MODE:
4824 wlan_hdd_scan_abort(adapter);
4825 hdd_deregister_tx_flow_control(adapter);
4826 hdd_vdev_destroy(adapter);
4827 break;
4828
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004829 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004830 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304831 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304832 sap_config = &adapter->session.ap.sap_config;
4833 if (sap_config)
4834 wlansap_reset_sap_config_add_ie(sap_config,
4835 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304836 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004837 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004838
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004839 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004840 if (QDF_SAP_MODE == adapter->device_mode) {
4841 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4842 cds_flush_delayed_work(
4843 &adapter->acs_pending_work);
4844 clear_bit(ACS_PENDING, &adapter->event_flags);
4845 }
4846 }
Krunal Soni22208392017-09-29 18:10:34 -07004847 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004848
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004849 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004850 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004851 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004852 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4853
4854 hdd_deregister_tx_flow_control(adapter);
4855
Kapil Guptac1224bf2017-06-22 21:22:40 +05304856 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857 mutex_lock(&hdd_ctx->sap_lock);
4858 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304859 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304860 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004861
4862 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004863 status = wlansap_stop_bss(
4864 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004865
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304866 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004867 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304869 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304870 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304871 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304872 qdf_wait_for_event_completion(
4873 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004874 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004875
Anurag Chouhance0dc992016-02-16 18:18:03 +05304876 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004877 hdd_err("failure waiting for wlansap_stop_bss %d",
4878 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004879 }
4880 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004881 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004882 }
4883 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004884 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4885 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004886 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004887
Anurag Chouhanc5548422016-02-24 18:33:27 +05304888 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004889 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004890 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004891 updateIE.ieBufferlength = 0;
4892 updateIE.pAdditionIEBuffer = NULL;
4893 updateIE.append = false;
4894 updateIE.notify = false;
4895 /* Probe bcn reset */
4896 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4897 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304898 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004899 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900 }
4901 /* Assoc resp reset */
4902 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4903 &updateIE,
4904 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304905 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004906 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004907 }
4908 /* Reset WNI_CFG_PROBE_RSP Flags */
4909 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004910 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004911 qdf_mem_free(adapter->session.ap.beacon);
4912 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304913 /*
4914 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4915 */
4916 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4917 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4918
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304919#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004920 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304921#endif
4922
4923#ifdef WLAN_NS_OFFLOAD
4924#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004925 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304926#endif
4927#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08004928
4929 hdd_vdev_destroy(adapter);
4930
Krunal Sonib51eec72017-11-20 21:53:01 -08004931 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004932 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004933 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004934 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004935 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004936 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08004937 hdd_deregister_tx_flow_control(adapter);
4938 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004939 break;
4940 default:
4941 break;
4942 }
4943
Dustin Brown04348372017-12-14 16:13:39 -08004944 if (adapter->scan_info.default_scan_ies) {
4945 qdf_mem_free(adapter->scan_info.default_scan_ies);
4946 adapter->scan_info.default_scan_ies = NULL;
4947 }
4948
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004949 EXIT();
Dustin Brown04348372017-12-14 16:13:39 -08004950
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304951 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004952}
4953
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304954/**
4955 * hdd_deinit_all_adapters - deinit all adapters
4956 * @hdd_ctx: HDD context
4957 * @rtnl_held: True if RTNL lock held
4958 *
4959 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004960void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304961{
Jeff Johnson9d295242017-08-29 14:39:48 -07004962 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304963
4964 ENTER();
4965
Dustin Brown920397d2017-12-13 16:27:50 -08004966 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304967 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304968
4969 EXIT();
4970}
4971
Dustin Browndb2a8be2017-12-20 11:49:56 -08004972QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004973{
Jeff Johnson9d295242017-08-29 14:39:48 -07004974 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004975
4976 ENTER();
4977
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304978 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4979
Dustin Brown920397d2017-12-13 16:27:50 -08004980 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08004981 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004982
4983 EXIT();
4984
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304985 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004986}
4987
Paul Zhang84fa9382017-11-10 21:18:21 +08004988static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4989 struct hdd_adapter *adapter)
4990{
4991 switch (adapter->device_mode) {
4992 case QDF_STA_MODE:
4993 case QDF_P2P_CLIENT_MODE:
4994 case QDF_IBSS_MODE:
4995 case QDF_P2P_DEVICE_MODE:
4996 case QDF_NDI_MODE:
4997 wlan_hdd_scan_abort(adapter);
4998 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4999 if (adapter->device_mode == QDF_STA_MODE)
5000 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5001 adapter->dev);
5002 break;
5003 case QDF_P2P_GO_MODE:
5004 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5005 break;
5006 case QDF_SAP_MODE:
5007 wlan_hdd_undo_acs(adapter);
5008 break;
5009 default:
5010 break;
5011 }
5012}
5013
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005014QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005015{
Jeff Johnson9d295242017-08-29 14:39:48 -07005016 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005017 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005018 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005019 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005020
5021 ENTER();
5022
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305023 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5024
Dustin Brown920397d2017-12-13 16:27:50 -08005025 hdd_for_each_adapter(hdd_ctx, adapter) {
Yue Ma42654682018-01-11 16:55:24 -08005026 hdd_notice("[SSR] reset adapter with device mode %s(%d)",
5027 hdd_device_mode_to_string(adapter->device_mode),
Yue Mad5b4b9f2017-05-26 16:23:40 -07005028 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305029
5030 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07005031 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305032 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005033 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305034
Arun Khandavallicc544b32017-01-30 19:52:16 +05305035 if (hdd_ctx->config->sap_internal_restart &&
5036 adapter->device_mode == QDF_SAP_MODE) {
5037 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305038 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305039 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005040 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005041 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005042 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005043 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5044 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305045 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305046 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005047 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005048 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049
Paul Zhang84fa9382017-11-10 21:18:21 +08005050 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005051 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005052
5053 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005054 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005055 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5057 hdd_wmm_adapter_close(adapter);
5058 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5059 }
5060
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305061 if (adapter->device_mode == QDF_STA_MODE)
5062 hdd_clear_fils_connection_info(adapter);
5063
Wu Gao3545e642017-07-14 19:24:41 +08005064 if (adapter->device_mode == QDF_SAP_MODE) {
5065 /*
5066 * If adapter is SAP, set session ID to invalid
5067 * since SAP session will be cleanup during SSR.
5068 */
Wu Gao36717432016-11-21 15:09:48 +08005069 wlansap_set_invalid_session(
5070 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5071
Wu Gao3545e642017-07-14 19:24:41 +08005072 wlansap_cleanup_cac_timer(
5073 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5074 }
5075
Yue Ma42654682018-01-11 16:55:24 -08005076 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005077 if (adapter->device_mode == QDF_STA_MODE ||
5078 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005079 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005080 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005081 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005082
5083 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5084 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005085 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5086 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5087 if (adapter->sta_info[sta_id].in_use) {
5088 hdd_debug("[SSR] deregister STA with ID %d",
5089 sta_id);
5090 hdd_softap_deregister_sta(adapter,
5091 sta_id);
5092 adapter->sta_info[sta_id].in_use = 0;
5093 }
5094 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005095 }
5096
Yue Maf9782842017-05-08 12:49:49 -07005097 /* Destroy vdev which will be recreated during reinit. */
5098 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005099 }
5100
5101 EXIT();
5102
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305103 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005104}
5105
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005106bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305107{
Dustin Brown920397d2017-12-13 16:27:50 -08005108 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305109 bool close_modules = true;
5110
Arun Khandavalliba479c42017-07-26 21:29:40 +05305111 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5112 hdd_info("FTM mode, don't close the module");
5113 return false;
5114 }
5115
Dustin Brown920397d2017-12-13 16:27:50 -08005116 hdd_for_each_adapter(hdd_ctx, adapter) {
5117 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5118 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005119 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305120 close_modules = false;
5121 break;
5122 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305123 }
5124
5125 return close_modules;
5126}
5127
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305128bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305129{
5130 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5131 return true;
5132 else
5133 return false;
5134}
5135
Anurag Chouhanc4092922016-09-08 15:56:11 +05305136#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005137 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305138struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5139 struct ieee80211_channel *channel,
5140 const u8 *bssid, const u8 *ssid,
5141 size_t ssid_len)
5142{
5143 return cfg80211_get_bss(wiphy, channel, bssid,
5144 ssid, ssid_len,
5145 WLAN_CAPABILITY_ESS,
5146 WLAN_CAPABILITY_ESS);
5147}
5148#else
5149struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5150 struct ieee80211_channel *channel,
5151 const u8 *bssid, const u8 *ssid,
5152 size_t ssid_len)
5153{
5154 return cfg80211_get_bss(wiphy, channel, bssid,
5155 ssid, ssid_len,
5156 IEEE80211_BSS_TYPE_ESS,
5157 IEEE80211_PRIVACY_ANY);
5158}
5159#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305160
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305161#if defined CFG80211_CONNECT_BSS || \
5162 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305163#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305164 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305165/**
5166 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5167 * @timeout_reason: reason for connect timeout
5168 *
5169 * This function is used to convert host timeout
5170 * reason enum to kernel specific enum.
5171 *
5172 * Return: nl timeout enum
5173 */
5174static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5175 tSirResultCodes timeout_reason)
5176{
5177 switch (timeout_reason) {
5178 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5179 return NL80211_TIMEOUT_SCAN;
5180 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5181 return NL80211_TIMEOUT_AUTH;
5182 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5183 return NL80211_TIMEOUT_ASSOC;
5184 default:
5185 return NL80211_TIMEOUT_UNSPECIFIED;
5186 }
5187}
5188
5189/**
5190 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5191 * @dev: network device
5192 * @bssid: bssid to which we want to associate
5193 * @timeout_reason: reason for connect timeout
5194 *
5195 * This API is used to send connection timeout reason to supplicant
5196 *
5197 * Return: void
5198 */
5199static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5200 const u8 *bssid,
5201 tSirResultCodes timeout_reason)
5202{
5203 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005204
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305205 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5206
5207 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5208 nl_timeout_reason);
5209}
5210
5211/**
5212 * __hdd_connect_bss() - API to send connection status to supplicant
5213 * @dev: network device
5214 * @bssid: bssid to which we want to associate
5215 * @req_ie: Request Information Element
5216 * @req_ie_len: len of the req IE
5217 * @resp_ie: Response IE
5218 * @resp_ie_len: len of ht response IE
5219 * @status: status
5220 * @gfp: Kernel Flag
5221 * @timeout_reason: reason for connect timeout
5222 *
5223 * Return: void
5224 */
5225static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5226 struct cfg80211_bss *bss, const u8 *req_ie,
5227 size_t req_ie_len, const u8 *resp_ie,
5228 size_t resp_ie_len, int status, gfp_t gfp,
5229 tSirResultCodes timeout_reason)
5230{
5231 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005232
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305233 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5234
5235 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5236 resp_ie, resp_ie_len, status, gfp,
5237 nl_timeout_reason);
5238}
5239#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305240#if defined CFG80211_CONNECT_TIMEOUT || \
5241 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305242static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5243 const u8 *bssid,
5244 tSirResultCodes timeout_reason)
5245{
5246 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5247}
5248#endif
5249
5250static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5251 struct cfg80211_bss *bss, const u8 *req_ie,
5252 size_t req_ie_len, const u8 *resp_ie,
5253 size_t resp_ie_len, int status, gfp_t gfp,
5254 tSirResultCodes timeout_reason)
5255{
5256 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5257 resp_ie, resp_ie_len, status, gfp);
5258}
5259#endif
5260
Abhishek Singha84d3952016-09-13 13:45:05 +05305261/**
5262 * hdd_connect_bss() - API to send connection status to supplicant
5263 * @dev: network device
5264 * @bssid: bssid to which we want to associate
5265 * @req_ie: Request Information Element
5266 * @req_ie_len: len of the req IE
5267 * @resp_ie: Response IE
5268 * @resp_ie_len: len of ht response IE
5269 * @status: status
5270 * @gfp: Kernel Flag
5271 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305272 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305273 *
5274 * The API is a wrapper to send connection status to supplicant
5275 *
5276 * Return: Void
5277 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305278#if defined CFG80211_CONNECT_TIMEOUT || \
5279 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305280static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5281 struct cfg80211_bss *bss, const u8 *req_ie,
5282 size_t req_ie_len, const u8 *resp_ie,
5283 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305284 bool connect_timeout,
5285 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305286{
5287 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305288 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305289 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305290 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5291 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305292}
5293#else
5294static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5295 struct cfg80211_bss *bss, const u8 *req_ie,
5296 size_t req_ie_len, const u8 *resp_ie,
5297 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305298 bool connect_timeout,
5299 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305300{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305301 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5302 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305303}
5304#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305305
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305306#if defined(WLAN_FEATURE_FILS_SK)
5307#if defined(CFG80211_CONNECT_DONE) || \
5308 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5309#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5310 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305311/**
5312 * hdd_populate_fils_params() - Populate FILS keys to connect response
5313 * @fils_params: connect response to supplicant
5314 * @fils_kek: FILS kek
5315 * @fils_kek_len: FILS kek length
5316 * @pmk: FILS PMK
5317 * @pmk_len: FILS PMK length
5318 * @pmkid: PMKID
5319 * @fils_seq_num: FILS Seq number
5320 *
5321 * Return: None
5322 */
5323static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5324 *fils_params, const uint8_t *fils_kek,
5325 size_t fils_kek_len, const uint8_t *pmk,
5326 size_t pmk_len, const uint8_t *pmkid,
5327 uint16_t fils_seq_num)
5328{
5329 /* Increament seq number to be used for next FILS */
5330 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5331 fils_params->update_erp_next_seq_num = true;
5332 fils_params->fils_kek = fils_kek;
5333 fils_params->fils_kek_len = fils_kek_len;
5334 fils_params->pmk = pmk;
5335 fils_params->pmk_len = pmk_len;
5336 fils_params->pmkid = pmkid;
5337}
5338#else
5339static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5340 *fils_params, const uint8_t
5341 *fils_kek, size_t fils_kek_len,
5342 const uint8_t *pmk, size_t pmk_len,
5343 const uint8_t *pmkid,
5344 uint16_t fils_seq_num)
5345{ }
5346#endif
5347
Jeff Johnson172237b2017-11-07 15:32:59 -08005348void hdd_update_hlp_info(struct net_device *dev,
5349 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305350{
5351 struct sk_buff *skb;
5352 uint16_t skb_len;
5353 struct llc_snap_hdr_t *llc_hdr;
5354 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305355 uint8_t *hlp_data;
5356 uint16_t hlp_data_len;
5357 struct fils_join_rsp_params *roam_fils_params
5358 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305359 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5360
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305361 if (!roam_fils_params) {
5362 hdd_err("FILS Roam Param NULL");
5363 return;
5364 }
5365
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005366 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305367 hdd_err("FILS HLP Data NULL, len %d",
5368 roam_fils_params->hlp_data_len);
5369 return;
5370 }
5371
5372 hlp_data = roam_fils_params->hlp_data;
5373 hlp_data_len = roam_fils_params->hlp_data_len;
5374
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305375 /* Calculate skb length */
5376 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5377 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5378 if (skb == NULL) {
5379 hdd_err("HLP packet nbuf alloc fails");
5380 return;
5381 }
5382
5383 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5384 QDF_MAC_ADDR_SIZE);
5385 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5386 QDF_MAC_ADDR_SIZE);
5387
5388 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5389 if (IS_SNAP(llc_hdr)) {
5390 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5391 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5392 }
5393
5394 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5395
5396 /*
5397 * This HLP packet is formed from HLP info encapsulated
5398 * in assoc response frame which is AEAD encrypted.
5399 * Hence, this checksum validation can be set unnecessary.
5400 * i.e. network layer need not worry about checksum.
5401 */
5402 skb->ip_summed = CHECKSUM_UNNECESSARY;
5403
5404 status = hdd_rx_packet_cbk(padapter, skb);
5405 if (QDF_IS_STATUS_ERROR(status)) {
5406 hdd_err("Sending HLP packet fails");
5407 return;
5408 }
5409 hdd_debug("send HLP packet to netif successfully");
5410}
5411
5412/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305413 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5414 * @dev: network device
5415 * @bssid: bssid to which we want to associate
5416 * @bss: cfg80211 bss info
5417 * @roam_info: information about connected bss
5418 * @req_ie: Request Information Element
5419 * @req_ie_len: len of the req IE
5420 * @resp_ie: Response IE
5421 * @resp_ie_len: len of ht response IE
5422 * @status: status
5423 * @gfp: allocation flags
5424 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5425 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305426 *
5427 * This API is used as wrapper to send FILS key/sequence number
5428 * params etc. to supplicant in case of FILS connection
5429 *
5430 * Return: None
5431 */
5432static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005433 struct cfg80211_bss *bss,
5434 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305435 const u8 *req_ie, size_t req_ie_len,
5436 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005437 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305438 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305439{
5440 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305441 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5442 struct fils_join_rsp_params *roam_fils_params =
5443 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005444
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305445 qdf_mem_zero(&fils_params, sizeof(fils_params));
5446
5447 if (!roam_fils_params) {
5448 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5449 } else {
5450 fils_params.status = status;
5451 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005452 fils_params.timeout_reason =
5453 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305454 fils_params.req_ie = req_ie;
5455 fils_params.req_ie_len = req_ie_len;
5456 fils_params.resp_ie = resp_ie;
5457 fils_params.resp_ie_len = resp_ie_len;
5458 fils_params.bss = bss;
5459 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5460 roam_fils_params->kek_len,
5461 roam_fils_params->fils_pmk,
5462 roam_fils_params->fils_pmk_len,
5463 roam_fils_params->fils_pmkid,
5464 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305465 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305466 }
5467 hdd_debug("FILS indicate connect status %d seq no %d",
5468 fils_params.status,
5469 fils_params.fils_erp_next_seq_num);
5470
5471 cfg80211_connect_done(dev, &fils_params, gfp);
5472
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305473 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305474 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305475
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305476 /* Clear all the FILS key info */
5477 if (roam_fils_params && roam_fils_params->fils_pmk)
5478 qdf_mem_free(roam_fils_params->fils_pmk);
5479 if (roam_fils_params)
5480 qdf_mem_free(roam_fils_params);
5481 roam_info->fils_join_rsp = NULL;
5482}
5483#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005484static inline void
5485hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005486 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005487 const u8 *req_ie, size_t req_ie_len,
5488 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5489 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305490 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305491{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305492#endif
5493#endif
5494
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305495#if defined(WLAN_FEATURE_FILS_SK) && \
5496 (defined(CFG80211_CONNECT_DONE) || \
5497 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305498/**
5499 * hdd_fils_update_connect_results() - API to send fils connection status to
5500 * supplicant.
5501 * @dev: network device
5502 * @bssid: bssid to which we want to associate
5503 * @bss: cfg80211 bss info
5504 * @roam_info: information about connected bss
5505 * @req_ie: Request Information Element
5506 * @req_ie_len: len of the req IE
5507 * @resp_ie: Response IE
5508 * @resp_ie_len: len of ht response IE
5509 * @status: status
5510 * @gfp: allocation flags
5511 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5512 * @timeout_reason: reason for connect timeout
5513 *
5514 * The API is a wrapper to send connection status to supplicant
5515 *
5516 * Return: 0 if success else failure
5517 */
5518static int hdd_fils_update_connect_results(struct net_device *dev,
5519 const u8 *bssid,
5520 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005521 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305522 size_t req_ie_len, const u8 *resp_ie,
5523 size_t resp_ie_len, u16 status, gfp_t gfp,
5524 bool connect_timeout,
5525 tSirResultCodes timeout_reason)
5526{
5527 ENTER();
5528 if (!roam_info || !roam_info->is_fils_connection)
5529 return -EINVAL;
5530
5531 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5532 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305533 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305534 return 0;
5535}
5536#else
5537static inline int hdd_fils_update_connect_results(struct net_device *dev,
5538 const u8 *bssid,
5539 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005540 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305541 size_t req_ie_len, const u8 *resp_ie,
5542 size_t resp_ie_len, u16 status, gfp_t gfp,
5543 bool connect_timeout,
5544 tSirResultCodes timeout_reason)
5545{
5546 return -EINVAL;
5547}
5548#endif
5549
Anurag Chouhanc4092922016-09-08 15:56:11 +05305550/**
5551 * hdd_connect_result() - API to send connection status to supplicant
5552 * @dev: network device
5553 * @bssid: bssid to which we want to associate
5554 * @roam_info: information about connected bss
5555 * @req_ie: Request Information Element
5556 * @req_ie_len: len of the req IE
5557 * @resp_ie: Response IE
5558 * @resp_ie_len: len of ht response IE
5559 * @status: status
5560 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305561 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305562 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305563 *
5564 * The API is a wrapper to send connection status to supplicant
5565 * and allow runtime suspend
5566 *
5567 * Return: Void
5568 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305569void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005570 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305571 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305572 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305573 bool connect_timeout,
5574 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305575{
Jeff Johnson9d295242017-08-29 14:39:48 -07005576 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305577 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005578 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305579
5580 if (WLAN_STATUS_SUCCESS == status) {
5581 struct ieee80211_channel *chan;
5582 int freq;
5583 int chan_no = roam_info->pBssDesc->channelId;
5584
5585 if (chan_no <= 14)
5586 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005587 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305588 else
5589 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005590 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305591
5592 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5593 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5594 roam_info->u.pConnectedProfile->SSID.ssId,
5595 roam_info->u.pConnectedProfile->SSID.length);
5596 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305597
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305598 if (hdd_fils_update_connect_results(dev, bssid, bss,
5599 roam_info, req_ie, req_ie_len, resp_ie,
5600 resp_ie_len, status, gfp, connect_timeout,
5601 timeout_reason) != 0) {
5602 hdd_connect_bss(dev, bssid, bss, req_ie,
5603 req_ie_len, resp_ie, resp_ie_len,
5604 status, gfp, connect_timeout, timeout_reason);
5605 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305606
Jingxiang Geb49aa302018-01-17 20:54:15 +08005607 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005608 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305609}
5610#else
5611void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005612 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305613 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305614 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305615 bool connect_timeout,
5616 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305617{
Jeff Johnson9d295242017-08-29 14:39:48 -07005618 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005619 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305620
Anurag Chouhanc4092922016-09-08 15:56:11 +05305621 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5622 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005623
Jingxiang Geb49aa302018-01-17 20:54:15 +08005624 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005625 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305626}
5627#endif
5628
5629
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005630QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631{
Jeff Johnson9d295242017-08-29 14:39:48 -07005632 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005633#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005634 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005635#endif
5636 eConnectionState connState;
5637
5638 ENTER();
5639
Dustin Brown920397d2017-12-13 16:27:50 -08005640 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305641 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005642 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305643
Yue Ma42654682018-01-11 16:55:24 -08005644 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5645 hdd_device_mode_to_string(adapter->device_mode),
5646 adapter->device_mode);
5647
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005648 hdd_wmm_init(adapter);
5649
5650 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005651 case QDF_STA_MODE:
5652 case QDF_P2P_CLIENT_MODE:
5653 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005654
5655 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5656 ->conn_info.connState;
5657
Krunal Sonib51eec72017-11-20 21:53:01 -08005658 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005660 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005661
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005662 /* Indicate disconnect event to supplicant
5663 * if associated previously
5664 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005665 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005666 eConnectionState_IbssConnected == connState ||
5667 eConnectionState_NotConnected == connState ||
5668 eConnectionState_IbssDisconnected == connState ||
5669 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005670 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005671
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005672 memset(&wrqu, '\0', sizeof(wrqu));
5673 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5674 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5675 wireless_send_event(adapter->dev, SIOCGIWAP,
5676 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005677 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005678 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005679
5680 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305681 wlan_hdd_cfg80211_indicate_disconnect(
5682 adapter->dev, false,
5683 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005684 } else if (eConnectionState_Connecting == connState) {
5685 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005686 * Indicate connect failure to supplicant if we
5687 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005688 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305689 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305690 NULL, 0, NULL, 0,
5691 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005692 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005693 }
5694
5695 hdd_register_tx_flow_control(adapter,
5696 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005697 hdd_tx_resume_cb,
5698 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699
5700 break;
5701
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005702 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005703 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005704 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305705
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005706 break;
5707
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005708 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005709#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005710 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005711 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5712#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005713 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005714 /* event supplicant to restart */
5715 cfg80211_del_sta(adapter->dev,
5716 (const u8 *)&bcastMac.bytes[0],
5717 GFP_KERNEL);
5718#endif
5719 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305720 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005721 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305722 hdd_set_mon_rx_cb(adapter->dev);
5723 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5724 adapter->mon_bandwidth);
5725 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005726 default:
5727 break;
5728 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005729 /*
5730 * Action frame registered in one adapter which will
5731 * applicable to all interfaces
5732 */
5733 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005734 }
5735
5736 EXIT();
5737
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305738 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005739}
5740
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005741QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005742 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005743{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305744 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005745 qdf_list_node_t *node;
5746
5747 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005748
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005749 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005750 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005751 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005752
5753 if (QDF_IS_STATUS_ERROR(status))
5754 return status;
5755
5756 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5757
5758 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005759}
5760
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005761QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005762 struct hdd_adapter *current_adapter,
5763 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005764{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305765 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005766 qdf_list_node_t *node;
5767
5768 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005769
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005770 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005771 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005772 &current_adapter->node,
5773 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005774 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005775
5776 if (QDF_IS_STATUS_ERROR(status))
5777 return status;
5778
5779 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5780
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005781 return status;
5782}
5783
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005784QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005785 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005786{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305787 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005788
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005789 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005790 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005791 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005792
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005793 return status;
5794}
5795
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005796QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005797 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005798{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305799 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005800 qdf_list_node_t *node;
5801
5802 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005803
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005804 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005805 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005806 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005807
5808 if (QDF_IS_STATUS_ERROR(status))
5809 return status;
5810
5811 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005813 return status;
5814}
5815
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005816QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005817 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005818{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305819 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005820
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005821 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005822 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005823 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005824
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005825 return status;
5826}
5827
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005828QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005829 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005830{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305831 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005832
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005833 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005834 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005835 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005836
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005837 return status;
5838}
5839
Jeff Johnson9d295242017-08-29 14:39:48 -07005840struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005841 tSirMacAddr macAddr)
5842{
Jeff Johnson9d295242017-08-29 14:39:48 -07005843 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005844
Dustin Brown920397d2017-12-13 16:27:50 -08005845 hdd_for_each_adapter(hdd_ctx, adapter) {
5846 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5847 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005848 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005849 }
5850
5851 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005852}
5853
Jeff Johnson9d295242017-08-29 14:39:48 -07005854struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005855 uint32_t vdev_id)
5856{
Jeff Johnson9d295242017-08-29 14:39:48 -07005857 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005858
Dustin Brown920397d2017-12-13 16:27:50 -08005859 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005860 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005861 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005862 }
5863
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005864 return NULL;
5865}
5866
Abhishek Singh7996eb72015-12-30 17:24:02 +05305867/**
5868 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5869 * the sessionid
5870 * @hdd_ctx: hdd context.
5871 * @sme_session_id: sme session is for the adapter to get.
5872 *
5873 * This function is used to get the adapter with provided session id
5874 *
5875 * Return: adapter pointer if found
5876 *
5877 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005878struct hdd_adapter *
5879hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5880 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305881{
Jeff Johnson9d295242017-08-29 14:39:48 -07005882 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305883
Dustin Brown920397d2017-12-13 16:27:50 -08005884 hdd_for_each_adapter(hdd_ctx, adapter) {
5885 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305886 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305887 }
Dustin Brown920397d2017-12-13 16:27:50 -08005888
Abhishek Singh7996eb72015-12-30 17:24:02 +05305889 return NULL;
5890}
5891
Jeff Johnson9d295242017-08-29 14:39:48 -07005892struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005893 const char *iface_name)
5894{
Jeff Johnson9d295242017-08-29 14:39:48 -07005895 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005896
Dustin Brown920397d2017-12-13 16:27:50 -08005897 hdd_for_each_adapter(hdd_ctx, adapter) {
5898 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07005899 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005900 }
Dustin Brown920397d2017-12-13 16:27:50 -08005901
Naveen Rawat4edb6822017-04-12 10:09:17 -07005902 return NULL;
5903}
5904
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005905/**
5906 * hdd_get_adapter() - to get adapter matching the mode
5907 * @hdd_ctx: hdd context
5908 * @mode: adapter mode
5909 *
5910 * This routine will return the pointer to adapter matching
5911 * with the passed mode.
5912 *
5913 * Return: pointer to adapter or null
5914 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005915struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005916 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005917{
Jeff Johnson9d295242017-08-29 14:39:48 -07005918 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005919
Dustin Brown920397d2017-12-13 16:27:50 -08005920 hdd_for_each_adapter(hdd_ctx, adapter) {
5921 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005922 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005923 }
5924
5925 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005926}
5927
5928/**
5929 * hdd_get_operating_channel() - return operating channel of the device mode
5930 * @hdd_ctx: Pointer to the HDD context.
5931 * @mode: Device mode for which operating channel is required.
5932 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005933 * QDF_STA_MODE,
5934 * QDF_P2P_CLIENT_MODE,
5935 * QDF_SAP_MODE,
5936 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005937 *
5938 * This API returns the operating channel of the requested device mode
5939 *
5940 * Return: channel number. "0" id the requested device is not found OR it is
5941 * not connected.
5942 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005943uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005944 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945{
Jeff Johnson9d295242017-08-29 14:39:48 -07005946 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005947 uint8_t operatingChannel = 0;
5948
Dustin Brown920397d2017-12-13 16:27:50 -08005949 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005950 if (mode == adapter->device_mode) {
5951 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005952 case QDF_STA_MODE:
5953 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954 if (hdd_conn_is_connected
5955 (WLAN_HDD_GET_STATION_CTX_PTR
5956 (adapter))) {
5957 operatingChannel =
5958 (WLAN_HDD_GET_STATION_CTX_PTR
5959 (adapter))->conn_info.
5960 operationChannel;
5961 }
5962 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005963 case QDF_SAP_MODE:
5964 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005965 /* softap connection info */
5966 if (test_bit
5967 (SOFTAP_BSS_STARTED,
5968 &adapter->event_flags))
5969 operatingChannel =
5970 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005971 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005972 break;
5973 default:
5974 break;
5975 }
5976
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005977 /* Found the device of interest. break the loop */
5978 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980 }
Dustin Brown920397d2017-12-13 16:27:50 -08005981
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005982 return operatingChannel;
5983}
5984
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005985static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005986 hdd_ctx)
5987{
Jeff Johnson9d295242017-08-29 14:39:48 -07005988 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005989
5990 ENTER();
5991
Dustin Brown920397d2017-12-13 16:27:50 -08005992 hdd_for_each_adapter(hdd_ctx, adapter) {
5993 if (adapter->device_mode == QDF_STA_MODE ||
5994 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5995 adapter->device_mode == QDF_IBSS_MODE ||
5996 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5997 adapter->device_mode == QDF_SAP_MODE ||
5998 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005999 wlan_hdd_cfg80211_deregister_frames(adapter);
6000 hdd_unregister_wext(adapter->dev);
6001 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006002 }
6003
6004 EXIT();
6005
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306006 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006007}
6008
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006009QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006010{
Jeff Johnson9d295242017-08-29 14:39:48 -07006011 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006012
6013 ENTER();
6014
Dustin Brown920397d2017-12-13 16:27:50 -08006015 hdd_for_each_adapter(hdd_ctx, adapter) {
6016 if (adapter->device_mode == QDF_STA_MODE ||
6017 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6018 adapter->device_mode == QDF_IBSS_MODE ||
6019 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6020 adapter->device_mode == QDF_SAP_MODE ||
6021 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006022 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006023 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306024 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006025 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006026 }
6027
6028 EXIT();
6029
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306030 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006031}
6032
Dustin Brownf27bce82016-11-03 12:52:27 -07006033/**
6034 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6035 * adapters
6036 * @hdd_ctx: The HDD context containing the adapters to operate on
6037 *
6038 * return: QDF_STATUS_SUCCESS
6039 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006040static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006041{
Jeff Johnson9d295242017-08-29 14:39:48 -07006042 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006043 int err;
6044
6045 ENTER();
6046
Dustin Brown920397d2017-12-13 16:27:50 -08006047 hdd_for_each_adapter(hdd_ctx, adapter) {
6048 if (adapter->device_mode == QDF_STA_MODE ||
6049 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6050 adapter->device_mode == QDF_IBSS_MODE ||
6051 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6052 adapter->device_mode == QDF_SAP_MODE ||
6053 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006054 err = wlan_hdd_sched_scan_stop(adapter->dev);
6055 if (err)
6056 hdd_err("Unable to stop scheduled scan");
6057 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006058 }
6059
6060 EXIT();
6061
6062 return QDF_STATUS_SUCCESS;
6063}
6064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006065#ifdef WLAN_NS_OFFLOAD
6066/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006067 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006068 * @hdd_ctx: Pointer to hdd context
6069 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006070 * Unregister for IPv6 address change notifications.
6071 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006072 * Return: None
6073 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006074static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075{
6076 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006077}
6078
6079/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006080 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006081 * @hdd_ctx: Pointer to hdd context
6082 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006083 * Register for IPv6 address change notifications.
6084 *
6085 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006086 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006087static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006088{
6089 int ret;
6090
6091 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6092 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006093 if (ret) {
6094 hdd_err("Failed to register IPv6 notifier: %d", ret);
6095 goto out;
6096 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006097
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006098 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006099out:
6100 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006101}
6102#else
6103/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006104 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006105 * @hdd_ctx: Pointer to hdd context
6106 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006107 * Unregister for IPv6 address change notifications.
6108 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006109 * Return: None
6110 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006111static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006112{
6113}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006114
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006115/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006116 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006117 * @hdd_ctx: Pointer to hdd context
6118 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006119 * Register for IPv6 address change notifications.
6120 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006121 * Return: None
6122 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006123static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006124{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006125 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006126}
6127#endif
6128
6129/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006130 * hdd_register_notifiers - Register netdev notifiers.
6131 * @hdd_ctx: HDD context
6132 *
6133 * Register netdev notifiers like IPv4 and IPv6.
6134 *
6135 * Return: 0 on success and errno on failure
6136 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006137static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006138{
6139 int ret;
6140
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006141 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6142 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306143 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006144
6145 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6146 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6147 if (ret) {
6148 hdd_err("Failed to register IPv4 notifier: %d", ret);
6149 goto unregister_ip6_notifier;
6150 }
6151
6152 return 0;
6153
6154unregister_ip6_notifier:
6155 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006156out:
6157 return ret;
6158
6159}
6160
6161/**
6162 * hdd_unregister_notifiers - Unregister netdev notifiers.
6163 * @hdd_ctx: HDD context
6164 *
6165 * Unregister netdev notifiers like IPv4 and IPv6.
6166 *
6167 * Return: None.
6168 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006169void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006170{
6171 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6172
6173 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006174}
6175
6176/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006177 * hdd_exit_netlink_services - Exit netlink services
6178 * @hdd_ctx: HDD context
6179 *
6180 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6181 * nl service.
6182 *
6183 * Return: None.
6184 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006185static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006186{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006187 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006188 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006189 ptt_sock_deactivate_svc();
6190
6191 nl_srv_exit();
6192}
6193
6194/**
6195 * hdd_init_netlink_services- Init netlink services
6196 * @hdd_ctx: HDD context
6197 *
6198 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6199 * nl service.
6200 *
6201 * Return: 0 on success and errno on failure.
6202 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006203static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006204{
6205 int ret;
6206
Ryan Hsuceddceb2016-04-28 10:20:14 -07006207 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006208 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006209 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006210 goto out;
6211 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006212 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006213
Naveen Rawat910726a2017-03-06 11:42:51 -08006214 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006215 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006216 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006217 goto err_nl_srv;
6218 }
6219
6220 ret = ptt_sock_activate_svc();
6221 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006222 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006223 goto err_nl_srv;
6224 }
6225
6226 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006227 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006228 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006229
6230 ret = cnss_diag_activate_service();
6231 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006232 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006233 goto err_close_cesium;
6234 }
6235
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006236 ret = spectral_scan_activate_service();
6237 if (ret) {
6238 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6239 goto err_close_cesium;
6240 }
6241
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006242 return 0;
6243
6244err_close_cesium:
6245 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006246 ptt_sock_deactivate_svc();
6247err_nl_srv:
6248 nl_srv_exit();
6249out:
6250 return ret;
6251}
6252
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006253/**
6254 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6255 * @hdd_ctx: HDD context.
6256 *
6257 * Destroy RX wakelock.
6258 *
6259 * Return: None.
6260 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006261static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006262{
6263 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6264}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006265
6266/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006267 * hdd_rx_wake_lock_create() - Create RX wakelock
6268 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006269 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006270 * Create RX wakelock.
6271 *
6272 * Return: None.
6273 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006274static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006275{
6276 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6277}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006278
6279/**
Houston Hoffman160db392016-10-10 17:37:51 -07006280 * hdd_context_deinit() - Deinitialize HDD context
6281 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006282 *
Houston Hoffman160db392016-10-10 17:37:51 -07006283 * Deinitialize HDD context along with all the feature specific contexts but
6284 * do not free hdd context itself. Caller of this API is supposed to free
6285 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006286 *
Houston Hoffman160db392016-10-10 17:37:51 -07006287 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006288 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006289static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006290{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306291 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6292
Houston Hoffman160db392016-10-10 17:37:51 -07006293 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006294
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006295 hdd_sap_context_destroy(hdd_ctx);
6296
6297 hdd_rx_wake_lock_destroy(hdd_ctx);
6298
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006299 hdd_scan_context_destroy(hdd_ctx);
6300
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006301 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006302
Houston Hoffman160db392016-10-10 17:37:51 -07006303 return 0;
6304}
6305
6306/**
6307 * hdd_context_destroy() - Destroy HDD context
6308 * @hdd_ctx: HDD context to be destroyed.
6309 *
6310 * Free config and HDD context as well as destroy all the resources.
6311 *
6312 * Return: None
6313 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006314static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006315{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006316 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306317
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306318 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6319
Houston Hoffman160db392016-10-10 17:37:51 -07006320 hdd_context_deinit(hdd_ctx);
6321
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306322 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006323 hdd_ctx->config = NULL;
6324
6325 wiphy_free(hdd_ctx->wiphy);
6326}
6327
6328/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306329 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6330 *
6331 * This function is used to destroy bug report lock
6332 *
6333 * Return: None
6334 */
6335static void wlan_destroy_bug_report_lock(void)
6336{
6337 p_cds_contextType p_cds_context;
6338
6339 p_cds_context = cds_get_global_context();
6340 if (!p_cds_context) {
6341 hdd_err("cds context is NULL");
6342 return;
6343 }
6344
6345 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6346}
6347
6348/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006349 * hdd_wlan_exit() - HDD WLAN exit function
6350 * @hdd_ctx: Pointer to the HDD Context
6351 *
6352 * This is the driver exit point (invoked during rmmod)
6353 *
6354 * Return: None
6355 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006356static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006357{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006358 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306359 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006360
6361 ENTER();
6362
Dustin Brown6f427922017-09-19 12:19:00 -07006363 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306364
6365 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366
Prashanth Bhattaab004382016-10-11 16:08:11 -07006367 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368
6369#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306370 if (QDF_TIMER_STATE_RUNNING ==
6371 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6372 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006373 }
6374
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306375 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306376 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006377 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006379 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6380 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6381 hdd_ctx->last_acs_channel_list = NULL;
6382 hdd_ctx->num_of_channels = 0;
6383 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006384#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006385
Arun Khandavallifae92942016-08-01 13:31:08 +05306386 mutex_lock(&hdd_ctx->iface_change_lock);
6387 driver_status = hdd_ctx->driver_status;
6388 mutex_unlock(&hdd_ctx->iface_change_lock);
6389
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006390 /*
6391 * Powersave Offload Case
6392 * Disable Idle Power Save Mode
6393 */
6394 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006395 /* clear the scan queue in all the scenarios */
6396 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006397
Arun Khandavallifae92942016-08-01 13:31:08 +05306398 if (driver_status != DRIVER_MODULES_CLOSED) {
6399 hdd_unregister_wext_all_adapters(hdd_ctx);
6400 /*
6401 * Cancel any outstanding scan requests. We are about to close
6402 * all of our adapters, but an adapter structure is what SME
6403 * passes back to our callback function. Hence if there
6404 * are any outstanding scan requests then there is a
6405 * race condition between when the adapter is closed and
6406 * when the callback is invoked. We try to resolve that
6407 * race condition here by canceling any outstanding scans
6408 * before we close the adapters.
6409 * Note that the scans may be cancelled in an asynchronous
6410 * manner, so ideally there needs to be some kind of
6411 * synchronization. Rather than introduce a new
6412 * synchronization here, we will utilize the fact that we are
6413 * about to Request Full Power, and since that is synchronized,
6414 * the expectation is that by the time Request Full Power has
6415 * completed, all scans will be cancelled
6416 */
6417 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006418 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006419 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006420 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006421 }
6422
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306423 unregister_netdevice_notifier(&hdd_netdev_notifier);
6424
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006425 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306426
Dustin Brown021cecd2017-12-11 13:56:43 -08006427 hdd_driver_memdump_deinit();
6428
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306429 qdf_nbuf_deinit_replenish_timer();
6430
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306431 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6432 hdd_info("Release wakelock for monitor mode!");
6433 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6434 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6435 }
6436
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306437 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6438 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6439 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6440
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006441 /*
6442 * Close CDS
6443 * This frees pMac(HAL) context. There should not be any call
6444 * that requires pMac access after this.
6445 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006446
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006447 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006448
Dustin Brownd005ad82018-01-19 10:32:13 -08006449 hdd_close_all_adapters(hdd_ctx, false);
6450
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006451 hdd_ipa_cleanup(hdd_ctx);
6452
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306453 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306454 /*
6455 * If there is re_init failure wiphy would have already de-registered
6456 * check the wiphy status before un-registering again
6457 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306458 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306459 wiphy_unregister(wiphy);
6460 wlan_hdd_cfg80211_deinit(wiphy);
6461 hdd_lpass_notify_stop(hdd_ctx);
6462 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006463
Arun Khandavallifae92942016-08-01 13:31:08 +05306464 hdd_exit_netlink_services(hdd_ctx);
6465 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306466#ifdef FEATURE_WLAN_CH_AVOID
6467 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6468#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306469
Abhishek Singhe9068f12017-03-31 14:14:52 +05306470 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6471 if (driver_status)
6472 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006473
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006474 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006475}
6476
6477void __hdd_wlan_exit(void)
6478{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006479 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480
6481 ENTER();
6482
Anurag Chouhan6d760662016-02-20 16:05:43 +05306483 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006484 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006485 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006486 EXIT();
6487 return;
6488 }
6489
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006490 /* Do all the cleanup before deregistering the driver */
6491 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006493 EXIT();
6494}
6495
6496#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006497/**
6498 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006499 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006500 *
6501 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6502 * Then new ACS request will do a fresh scan without reusing the cached
6503 * scan information.
6504 *
6505 * Return: void
6506 */
Tang Yingying523322d2017-01-17 23:28:43 +08006507static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006508{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006509 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006510
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006511 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006512 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006513 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6514 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6515 hdd_ctx->last_acs_channel_list = NULL;
6516 hdd_ctx->num_of_channels = 0;
6517 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006518
6519 if (!hdd_ctx->hHal)
6520 return;
6521 sme_scan_flush_result(hdd_ctx->hHal);
6522}
6523#endif
6524
6525#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006526int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6527 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006528{
6529 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306530 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006531 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006532
6533 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6534
6535 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306536 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006537 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306538
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006539 if (!hdd_ctx->hHal)
6540 return -EINVAL;
6541
Jeff Johnsone7672e72017-10-21 15:10:04 -07006542 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006543 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306544 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006545 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006546 return -EINVAL;
6547 }
6548
6549 return 0;
6550}
6551#endif
6552
6553/**
6554 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6555 * @state: state
6556 *
6557 * This function notifies FW with modem power status
6558 *
6559 * Return: 0 if successful, error number otherwise
6560 */
6561int hdd_wlan_notify_modem_power_state(int state)
6562{
6563 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306564 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006565 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006566
Anurag Chouhan6d760662016-02-20 16:05:43 +05306567 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006568 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306569 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006570 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006572 if (!hdd_ctx->hHal)
6573 return -EINVAL;
6574
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306575 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6576 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006577 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006578 state);
6579 return -EINVAL;
6580 }
6581 return 0;
6582}
6583
6584/**
6585 *
6586 * hdd_post_cds_enable_config() - HDD post cds start config helper
6587 * @adapter - Pointer to the HDD
6588 *
6589 * Return: None
6590 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006591QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006592{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306593 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594
6595 /*
6596 * Send ready indication to the HDD. This will kick off the MAC
6597 * into a 'running' state and should kick off an initial scan.
6598 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306599 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6600 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006601 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6602 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306603 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006604 }
6605
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306606 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006607}
6608
6609/* wake lock APIs for HDD */
6610void hdd_prevent_suspend(uint32_t reason)
6611{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306612 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006613}
6614
6615void hdd_allow_suspend(uint32_t reason)
6616{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306617 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006618}
6619
6620void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6621{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306622 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6623 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006624}
6625
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006626/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006627QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006628{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006629
Amar Singhal6f8592b2017-04-26 14:31:58 -07006630 return sme_init_chan_list(hdd_ctx->hHal,
6631 hdd_ctx->reg.alpha2,
6632 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006633}
6634
6635/**
6636 * hdd_is_5g_supported() - check if hardware supports 5GHz
6637 * @hdd_ctx: Pointer to the hdd context
6638 *
6639 * HDD function to know if hardware supports 5GHz
6640 *
6641 * Return: true if hardware supports 5GHz
6642 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006643bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006644{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006645 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006646 return true;
6647
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006648 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006649 return true;
6650 else
6651 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006652}
6653
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006654static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006655{
6656 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006657 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006658
6659 wiphy = hdd_ctx->wiphy;
6660
6661 /*
6662 * The channel information in
6663 * wiphy needs to be initialized before wiphy registration
6664 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006665 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6666 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006667 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006668 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006669 }
6670
6671#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6672 wiphy->wowlan = &wowlan_support_reg_init;
6673#else
6674 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6675 WIPHY_WOWLAN_MAGIC_PKT |
6676 WIPHY_WOWLAN_DISCONNECT |
6677 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6678 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6679 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6680 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6681 WIPHY_WOWLAN_RFKILL_RELEASE;
6682
6683 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6684 WOW_MAX_FILTERS_PER_LIST);
6685 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6686 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6687#endif
6688
6689 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006690 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306691 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006692 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306693 return ret_val;
6694 }
6695
Amar Singhal2d812012018-02-03 15:06:47 +08006696 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006697
Amar Singhale4f28ee2015-10-21 14:36:56 -07006698 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006699}
6700
Mohit Khannaca4173b2017-09-12 21:52:19 -07006701#ifdef MSM_PLATFORM
6702/**
6703 * hdd_display_periodic_stats() - Function to display periodic stats
6704 * @hdd_ctx - handle to hdd context
6705 * @bool data_in_interval - true, if data detected in bw time interval
6706 *
6707 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6708 * Stats show up in wlan driver logs.
6709 *
6710 * Returns: None
6711 */
6712static inline
6713void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6714 bool data_in_interval)
6715{
6716 static u32 counter;
6717 static bool data_in_time_period;
6718 ol_txrx_pdev_handle pdev;
6719
6720 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6721 return;
6722
6723 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6724 if (!pdev) {
6725 hdd_err("pdev is NULL");
6726 return;
6727 }
6728
6729 counter++;
6730 if (data_in_interval)
6731 data_in_time_period = data_in_interval;
6732
6733 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6734 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6735 if (data_in_time_period) {
6736 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6737 CDP_TXRX_PATH_STATS,
6738 QDF_STATS_VERBOSITY_LEVEL_LOW);
6739 wlan_hdd_display_netif_queue_history
6740 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6741 qdf_dp_trace_dump_stats();
6742 }
6743 counter = 0;
6744 data_in_time_period = false;
6745 }
6746}
6747
Ravi Joshie2331e82015-07-01 18:18:54 -07006748/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006749 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006750 * @hdd_ctx - handle to hdd context
6751 * @tx_packets - transmit packet count
6752 * @rx_packets - receive packet count
6753 *
6754 * The function controls the bus bandwidth and dynamic control of
6755 * tcp delayed ack configuration
6756 *
6757 * Returns: None
6758 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006759
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006760static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006761 const uint64_t tx_packets,
6762 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006763{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006764 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006765 uint64_t temp_rx = 0;
6766 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006767 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006768 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006769 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006770 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006771 uint16_t index = 0;
6772 bool vote_level_change = false;
6773 bool rx_level_change = false;
6774 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775
Mohit Khannaca4173b2017-09-12 21:52:19 -07006776 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006777 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006778 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006779 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006780 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006781 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006782 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006783 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006784
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006785 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006786 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6787 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006789 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006790 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306791 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306792 if (hdd_ctx->hbw_requested) {
6793 pld_remove_pm_qos(hdd_ctx->parent_dev);
6794 hdd_ctx->hbw_requested = false;
6795 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306796 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006797 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006798 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306799 if (!hdd_ctx->hbw_requested) {
6800 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6801 hdd_ctx->hbw_requested = true;
6802 }
6803
Nirav Shah3bbfa512016-05-12 16:43:49 +05306804 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006805 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006806 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006807 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006808 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006809
Mohit Khannaf8f96822017-05-17 17:11:59 -07006810 qdf_dp_trace_throttle_live_mode(
6811 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6812
Mohit Khannae71e2262015-11-10 09:37:24 -08006813 /* fine-tuning parameters for RX Flows */
6814 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6815
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006816 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006817
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306818 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6819 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6820 else
6821 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6822
Ravi Joshifed83572016-10-07 16:20:37 -07006823 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6824 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6825 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6826 next_rx_level = WLAN_SVC_TP_HIGH;
6827 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006828 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006829 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006830 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006831 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006832
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006833 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006834 struct wlan_rx_tp_data rx_tp_data = {0};
6835
Ravi Joshie2331e82015-07-01 18:18:54 -07006836 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006837 next_rx_level, temp_rx);
6838 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006839 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006840 /* Send throughput indication only if it is enabled.
6841 * Disabling tcp_del_ack will revert the tcp stack behavior
6842 * to default delayed ack. Note that this will disable the
6843 * dynamic delayed ack mechanism across the system
6844 */
6845 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006846 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6847
Mohit Khanna6272fb682017-04-13 09:34:36 -07006848 if (hdd_ctx->config->enable_tcp_adv_win_scale)
6849 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6850
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006851 rx_tp_data.level = next_rx_level;
6852 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6853 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6854 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006855 }
6856
Mohit Khannae71e2262015-11-10 09:37:24 -08006857 /* fine-tuning parameters for TX Flows */
6858 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6859 hdd_ctx->prev_tx = tx_packets;
6860 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6861 next_tx_level = WLAN_SVC_TP_HIGH;
6862 else
6863 next_tx_level = WLAN_SVC_TP_LOW;
6864
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006865 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006866 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6867 next_tx_level, temp_tx);
6868 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006869 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306870 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6871 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006872 &next_tx_level,
6873 sizeof(next_tx_level));
6874 }
6875
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006876 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006877 if (vote_level_change || tx_level_change || rx_level_change) {
6878 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6879 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6880 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6881 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6882 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6883 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6884 hdd_ctx->hdd_txrx_hist_idx++;
6885 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6886 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07006887
6888 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006889}
6890
6891#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306892static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006893{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006894 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306895 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006896 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306897 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306898 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6899 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006900 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306901 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006902 bool connected = false;
6903 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6904
Prashanth Bhattaab004382016-10-11 16:08:11 -07006905 if (wlan_hdd_validate_context(hdd_ctx))
6906 return;
6907
Jeff Johnson214671b2017-10-30 19:45:23 -07006908 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006909 goto restart_timer;
6910
Dustin Brown920397d2017-12-13 16:27:50 -08006911 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05306912 /*
6913 * Validate magic so we don't end up accessing
6914 * an invalid adapter.
6915 */
6916 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6917 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006918
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006919 if ((adapter->device_mode == QDF_STA_MODE ||
6920 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006921 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6922 != eConnectionState_Associated) {
6923
6924 continue;
6925 }
6926
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006927 if ((adapter->device_mode == QDF_SAP_MODE ||
6928 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006929 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006930
6931 continue;
6932 }
6933
6934 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6935 adapter->prev_tx_packets);
6936 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6937 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306938
6939 if (adapter->device_mode == QDF_SAP_MODE ||
6940 adapter->device_mode == QDF_P2P_GO_MODE ||
6941 adapter->device_mode == QDF_IBSS_MODE) {
6942
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006943 ret = cdp_get_intra_bss_fwd_pkts_count(
6944 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006945 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306946 &fwd_tx_packets, &fwd_rx_packets);
6947 if (ret == A_OK) {
6948 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6949 fwd_tx_packets,
6950 adapter->prev_fwd_tx_packets);
6951 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6952 fwd_tx_packets,
6953 adapter->prev_fwd_rx_packets);
6954 }
6955 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006956
6957 total_rx += adapter->stats.rx_packets;
6958 total_tx += adapter->stats.tx_packets;
6959
6960 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6961 adapter->prev_tx_packets = adapter->stats.tx_packets;
6962 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306963 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6964 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006965 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6966 connected = true;
6967 }
6968
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306969 /* add intra bss forwarded tx and rx packets */
6970 tx_packets += fwd_tx_packets_diff;
6971 rx_packets += fwd_rx_packets_diff;
6972
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006973 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6974 tx_packets += (uint64_t)ipa_tx_packets;
6975 rx_packets += (uint64_t)ipa_rx_packets;
6976
Yun Park2aa880c2017-08-22 10:58:10 -07006977 if (adapter) {
6978 adapter->stats.tx_packets += ipa_tx_packets;
6979 adapter->stats.rx_packets += ipa_rx_packets;
6980 }
6981
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006982 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006983 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006984 return;
6985 }
6986
Yuanyuan Liu13738502016-04-06 17:41:37 -07006987 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006988
6989 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6990 hdd_ipa_uc_stat_request(adapter, 2);
6991
Jingxiang Gec64e1932017-08-22 14:38:59 +08006992restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006993 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006994 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006995 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306996 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006997 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006998 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006999}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007000
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307001/**
7002 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7003 * @arg: Argument of timer function
7004 *
7005 * Schedule a workqueue in this function where all the processing is done.
7006 *
7007 * Return: None.
7008 */
7009static void __hdd_bus_bw_cbk(void *arg)
7010{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007011 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307012
7013 if (wlan_hdd_validate_context(hdd_ctx))
7014 return;
7015
7016 schedule_work(&hdd_ctx->bus_bw_work);
7017}
7018
7019/**
7020 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7021 * @arg: Argument of timer function
7022 *
7023 * Return: None.
7024 */
7025static void hdd_bus_bw_cbk(void *arg)
7026{
7027 cds_ssr_protect(__func__);
7028 __hdd_bus_bw_cbk(arg);
7029 cds_ssr_unprotect(__func__);
7030}
7031
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007032int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007033{
7034 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307035 INIT_WORK(&hdd_ctx->bus_bw_work,
7036 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007037 hdd_ctx->bus_bw_timer_running = false;
7038 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307039 qdf_timer_init(NULL,
7040 &hdd_ctx->bus_bw_timer,
7041 hdd_bus_bw_cbk, (void *)hdd_ctx,
7042 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007043
7044 return 0;
7045}
7046
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007047void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007048{
Dustin Brownfce08d12017-01-17 16:29:38 -08007049 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007050 hdd_reset_tcp_delack(hdd_ctx);
7051
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007052 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307053 cancel_work_sync(&hdd_ctx->bus_bw_work);
7054 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007055 hdd_ctx->bus_bw_timer_running = false;
7056 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007057}
Lin Baic5c06882017-09-21 13:58:43 +08007058
7059void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7060{
7061 if (hdd_ctx)
7062 cancel_work_sync(&hdd_ctx->bus_bw_work);
7063}
jiadcdaf9bd2017-10-26 12:20:21 +08007064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007065#endif
7066
7067/**
Nirav Shahed34b212016-04-25 10:59:16 +05307068 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7069 * @hdd_ctx: hdd context
7070 *
7071 * Return: 0 for success or error code
7072 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007073static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307074{
7075 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7076 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7077 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007078 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307079 return -ENOMEM;
7080 }
7081 return 0;
7082}
7083
7084/**
7085 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7086 * @hdd_ctx: hdd context
7087 *
7088 * Return: none
7089 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007090void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307091{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307092 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7093 return;
7094
7095 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7096 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307097}
7098
Nirav Shahda008342016-05-17 18:50:40 +05307099static uint8_t *convert_level_to_string(uint32_t level)
7100{
7101 switch (level) {
7102 /* initialize the wlan sub system */
7103 case WLAN_SVC_TP_NONE:
7104 return "NONE";
7105 case WLAN_SVC_TP_LOW:
7106 return "LOW";
7107 case WLAN_SVC_TP_MEDIUM:
7108 return "MED";
7109 case WLAN_SVC_TP_HIGH:
7110 return "HIGH";
7111 default:
7112 return "INVAL";
7113 }
7114}
7115
Nirav Shahed34b212016-04-25 10:59:16 +05307116
7117/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007118 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7119 * @hdd_ctx: hdd context
7120 *
7121 * Return: none
7122 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007123void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007124{
7125 int i;
7126
7127#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007128 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307129 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007130 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007131 hdd_ctx->config->busBandwidthHighThreshold,
7132 hdd_ctx->config->busBandwidthMediumThreshold,
7133 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007134 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307135 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007136 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007137 hdd_ctx->config->tcpDelackThresholdHigh,
7138 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007139 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307140 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007141#endif
7142
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007143 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307144 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7145
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007146 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007147
7148 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007149 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007150 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07007151 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007152 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7153 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007154 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007155 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7156 convert_level_to_string(
7157 hdd_ctx->hdd_txrx_hist[i].
7158 next_vote_level),
7159 convert_level_to_string(
7160 hdd_ctx->hdd_txrx_hist[i].
7161 next_rx_level),
7162 convert_level_to_string(
7163 hdd_ctx->hdd_txrx_hist[i].
7164 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007165 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007166}
7167
7168/**
7169 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7170 * @hdd_ctx: hdd context
7171 *
7172 * Return: none
7173 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007174void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007175{
7176 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307177 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7178 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007179}
7180
Mohit Khannaca4173b2017-09-12 21:52:19 -07007181/* length of the netif queue log needed per adapter */
7182#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7183
7184/**
7185 *
7186 * hdd_display_netif_queue_history_compact() - display compact netifq history
7187 * @hdd_ctx: hdd context
7188 *
7189 * Return: none
7190 */
7191static void
7192hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7193{
7194 int adapter_num = 0;
7195 int i;
7196 int bytes_written;
7197 u32 tbytes;
7198 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007199 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007200 char *comb_log_str;
7201 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007202 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007203
jiadbdefb252018-01-03 14:27:06 +08007204 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7205 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7206 if (!comb_log_str) {
7207 hdd_err("failed to alloc comb_log_str");
7208 return;
7209 }
7210
Mohit Khannaca4173b2017-09-12 21:52:19 -07007211 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007212
Dustin Brown920397d2017-12-13 16:27:50 -08007213 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007214 curr_time = qdf_system_ticks();
7215 total = curr_time - adapter->start_time;
7216 delta = curr_time - adapter->last_time;
7217
7218 if (adapter->pause_map) {
7219 pause = adapter->total_pause_time + delta;
7220 unpause = adapter->total_unpause_time;
7221 } else {
7222 unpause = adapter->total_unpause_time + delta;
7223 pause = adapter->total_pause_time;
7224 }
7225
7226 tbytes = 0;
7227 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7228 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7229 if (adapter->queue_oper_stats[i].pause_count == 0)
7230 continue;
7231 tbytes +=
7232 snprintf(
7233 &temp_str[tbytes],
7234 (tbytes >= sizeof(temp_str) ?
7235 0 : sizeof(temp_str) - tbytes),
7236 "%d(%d,%d) ",
7237 i,
7238 adapter->queue_oper_stats[i].
7239 pause_count,
7240 adapter->queue_oper_stats[i].
7241 unpause_count);
7242 }
7243 if (tbytes >= sizeof(temp_str))
7244 hdd_warn("log truncated");
7245
7246 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007247 bytes_written >= comb_log_str_size ? 0 :
7248 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007249 "[%d %d] (%d) %u/%ums %s|",
7250 adapter->session_id, adapter->device_mode,
7251 adapter->pause_map,
7252 qdf_system_ticks_to_msecs(pause),
7253 qdf_system_ticks_to_msecs(total),
7254 temp_str);
7255
Mohit Khannaca4173b2017-09-12 21:52:19 -07007256 adapter_num++;
7257 }
7258
7259 /* using QDF_TRACE to avoid printing function name */
7260 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7261 "STATS |%s", comb_log_str);
7262
jiadbdefb252018-01-03 14:27:06 +08007263 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007264 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007265
7266 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007267}
7268
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007269/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007270 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007271 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007272 *
7273 * Return: none
7274 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007275void
7276wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7277 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007278{
7279
Jeff Johnson9d295242017-08-29 14:39:48 -07007280 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007281 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307282 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007283
Mohit Khannaca4173b2017-09-12 21:52:19 -07007284 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7285 hdd_display_netif_queue_history_compact(hdd_ctx);
7286 return;
7287 }
7288
Dustin Brown920397d2017-12-13 16:27:50 -08007289 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007290 hdd_debug("Netif queue operation statistics:");
7291 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007292 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007293 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307294 curr_time = qdf_system_ticks();
7295 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307296 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307297 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307298 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307299 unpause = adapter->total_unpause_time;
7300 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307301 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307302 pause = adapter->total_pause_time;
7303 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007304 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307305 qdf_system_ticks_to_msecs(total),
7306 qdf_system_ticks_to_msecs(pause),
7307 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007308 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007309
Nirav Shahda008342016-05-17 18:50:40 +05307310 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7311 qdf_time_t pause_delta = 0;
7312
7313 if (adapter->pause_map & (1 << i))
7314 pause_delta = delta;
7315
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007316 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07007317 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007318 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007319 hdd_reason_type_to_string(i),
7320 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05307321 adapter->queue_oper_stats[i].unpause_count,
7322 qdf_system_ticks_to_msecs(
7323 adapter->queue_oper_stats[i].total_pause_time +
7324 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007325 }
7326
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007327 hdd_debug("Netif queue operation history:");
7328 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307329 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7330
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007331 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007332
7333 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007334 /* using hdd_log to avoid printing function name */
7335 if (adapter->queue_oper_history[i].time == 0)
7336 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07007337 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007338 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05307339 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007340 adapter->queue_oper_history[i].time),
7341 hdd_action_type_to_string(
7342 adapter->queue_oper_history[i].netif_action),
7343 hdd_reason_type_to_string(
7344 adapter->queue_oper_history[i].netif_reason),
7345 adapter->queue_oper_history[i].pause_map);
7346 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007347 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007348}
7349
7350/**
7351 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7352 * @hdd_ctx: hdd context
7353 *
7354 * Return: none
7355 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007356void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007357{
Jeff Johnson9d295242017-08-29 14:39:48 -07007358 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007359
Dustin Brown920397d2017-12-13 16:27:50 -08007360 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307361 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007362 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307363 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007364 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307365 adapter->history_index = 0;
7366 adapter->start_time = adapter->last_time = qdf_system_ticks();
7367 adapter->total_pause_time = 0;
7368 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007369 }
7370}
7371
7372/**
7373 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7374 * @halHandle: Hal handle
7375 * @pContext: Pointer to the context
7376 * @sessionId: Session ID
7377 * @scanId: Scan ID
7378 * @status: Status
7379 *
7380 * This is the callback to be executed when 11d scan is completed to flush out
7381 * the scan results
7382 *
7383 * 11d scan is done during driver load and is a passive scan on all
7384 * channels supported by the device, 11d scans may find some APs on
7385 * frequencies which are forbidden to be used in the regulatory domain
7386 * the device is operating in. If these APs are notified to the supplicant
7387 * it may try to connect to these APs, thus flush out all the scan results
7388 * which are present in SME after 11d scan is done.
7389 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307390 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007391 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307392static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007393 uint8_t sessionId, uint32_t scanId,
7394 eCsrScanStatus status)
7395{
7396 ENTER();
7397
7398 sme_scan_flush_result(halHandle);
7399
7400 EXIT();
7401
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307402 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007403}
7404
7405#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7406/**
7407 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7408 * @hdd_ctx: hdd global context
7409 *
7410 * Return: none
7411 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007412static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007413{
7414 uint8_t i;
7415
7416 mutex_init(&hdd_ctx->op_ctx.op_lock);
7417 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7418 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7419 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7420 }
7421}
7422#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007423static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007424{
7425}
7426#endif
7427
Yingying Tang95409972016-10-20 15:16:15 +08007428#ifdef WLAN_FEATURE_WOW_PULSE
7429/**
7430 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007431 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007432 * @enable: enable or disable this behaviour
7433 *
7434 * Return: int
7435 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007436static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007437{
7438 struct hdd_config *pcfg_ini = phddctx->config;
7439 struct wow_pulse_mode wow_pulse_set_info;
7440 QDF_STATUS status;
7441
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007442 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007443
7444 if (false == phddctx->config->wow_pulse_support)
7445 return 0;
7446
7447 /* prepare the request to send to SME */
7448 if (enable == true) {
7449 wow_pulse_set_info.wow_pulse_enable = true;
7450 wow_pulse_set_info.wow_pulse_pin =
7451 pcfg_ini->wow_pulse_pin;
7452 wow_pulse_set_info.wow_pulse_interval_low =
7453 pcfg_ini->wow_pulse_interval_low;
7454 wow_pulse_set_info.wow_pulse_interval_high =
7455 pcfg_ini->wow_pulse_interval_high;
7456 } else {
7457 wow_pulse_set_info.wow_pulse_enable = false;
7458 wow_pulse_set_info.wow_pulse_pin = 0;
7459 wow_pulse_set_info.wow_pulse_interval_low = 0;
7460 wow_pulse_set_info.wow_pulse_interval_high = 0;
7461 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007462 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007463 wow_pulse_set_info.wow_pulse_enable,
7464 wow_pulse_set_info.wow_pulse_pin,
7465 wow_pulse_set_info.wow_pulse_interval_low,
7466 wow_pulse_set_info.wow_pulse_interval_high);
7467
7468 status = sme_set_wow_pulse(&wow_pulse_set_info);
7469 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007470 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007471 return -EIO;
7472 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007473 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007474 return 0;
7475}
7476#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007477static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007478{
7479 return 0;
7480}
7481#endif
7482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007483#ifdef WLAN_FEATURE_FASTPATH
7484/**
7485 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7486 * @hdd_cfg: hdd config
7487 * @context: lower layer context
7488 *
7489 * Return: none
7490 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307491void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007492 void *context)
7493{
7494 if (hdd_cfg->fastpath_enable)
7495 hif_enable_fastpath(context);
7496}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007497#endif
7498
Yuanyuan Liu13738502016-04-06 17:41:37 -07007499#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007500/**
7501 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007502 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007503 * @level: thermal level
7504 *
7505 * Change IPA data path to SW path when the thermal throttle level greater
7506 * than 0, and restore the original data path when throttle level is 0
7507 *
7508 * Return: none
7509 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007510static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007511{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007512 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007513
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007514 /* Change IPA to SW path when throttle level greater than 0 */
7515 if (level > THROTTLE_LEVEL_0)
7516 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7517 else
7518 /* restore original concurrency mode */
7519 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7520}
7521
7522/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307523 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7524 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307525 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007526 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307527 * Get a safe channel to restart SAP. PCL already takes into account the
7528 * unsafe channels. So, the PCL is validated with the ACS range to provide
7529 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007530 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307531 * Return: Channel number to restart SAP in case of success. In case of any
7532 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007533 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307534static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007535 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007536{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307537 struct sir_pcl_list pcl;
7538 QDF_STATUS status;
7539 uint32_t i, j;
7540 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007541 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307542 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007543 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007544
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307545 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7546 if (!hdd_ctx) {
7547 hdd_err("invalid HDD context");
7548 return INVALID_CHANNEL_ID;
7549 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007550
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307551 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7552 if (!hal_handle) {
7553 hdd_err("invalid HAL handle");
7554 return INVALID_CHANNEL_ID;
7555 }
7556
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007557 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7558 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007559 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7560 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307561 if (QDF_IS_STATUS_ERROR(status)) {
7562 hdd_err("Get PCL failed");
7563 return INVALID_CHANNEL_ID;
7564 }
7565
Frank Liudc2cefb2017-06-21 15:38:18 +08007566 /*
7567 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7568 * channel is unsafe channel, the pcl may be empty, instead of return,
7569 * try to choose a safe channel from acs range.
7570 */
7571 if (!pcl.pcl_len)
7572 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307573
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007574 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007575 adapter->session.ap.sap_config.acs_cfg.start_ch,
7576 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307577
7578 /* PCL already takes unsafe channel into account */
7579 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007580 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307581 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007582 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307583 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007584 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007585 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307586 return pcl.pcl_list[i];
7587 }
7588 }
7589
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007590 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307591
7592 /* Try for safe channel from all valid channel */
7593 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007594 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7595 &pcl.pcl_len);
7596 if (ret) {
7597 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307598 return INVALID_CHANNEL_ID;
7599 }
7600
7601 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007602 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307603 found = false;
7604 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007605 if (pcl.pcl_list[i] ==
7606 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007607 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307608 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007609 break;
7610 }
7611 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307612
7613 if (found)
7614 continue;
7615
7616 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007617 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307618 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007619 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007620 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307621 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007622 }
7623 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307624
7625 return INVALID_CHANNEL_ID;
7626}
7627
7628/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007629 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307630 * @adapter: AP adapter
7631 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007632 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307633 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007634 * Moves the SAP interface by invoking the function which
7635 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307636 *
7637 * Return: None
7638 */
Min Liu2fef5792018-01-19 17:59:42 +08007639void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7640 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307641{
Jeff Johnson87251032017-08-29 13:31:11 -07007642 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307643 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007644 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307645
7646 if (!adapter) {
7647 hdd_err("invalid adapter");
7648 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007649 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307650
7651 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7652
7653 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7654 if (!hal_handle) {
7655 hdd_err("invalid HAL handle");
7656 return;
7657 }
7658
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007659 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7660
Jeff Johnson91df29d2017-10-27 19:29:50 -07007661 hdd_ap_ctx->sap_config.channel = channel;
7662 hdd_ap_ctx->sap_config.ch_params.ch_width =
7663 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307664
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007665 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007666 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307667
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007668 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007669 hdd_ap_ctx->sap_config.channel,
7670 hdd_ap_ctx->sap_config.sec_ch,
7671 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307672
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007673 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007674 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007675 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007676}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307677
Jeff Johnson9d295242017-08-29 14:39:48 -07007678int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307679{
7680 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307681 int status;
7682 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307683
7684 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7685
7686 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007687 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307688 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007689 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307690 }
7691 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007692 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307693 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307694 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007695 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307696 WLAN_VENDOR_ACS_WAIT_TIME);
7697 if (qdf_status != QDF_STATUS_SUCCESS) {
7698 hdd_err("failed to start external acs timer");
7699 return -ENOSPC;
7700 }
7701 /* Update config to application */
7702 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307703 hdd_notice("Updated ACS config to nl with reason %d", reason);
7704
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307705 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307706}
7707
Agrawal Ashish467dde42016-09-08 18:44:22 +05307708/**
7709 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7710 * @hdd_ctx: hdd context pointer
7711 *
7712 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7713 * and if ACS is enabled, driver will ask userspace to restart the
7714 * sap. User space on LTE coex indication restart driver.
7715 *
7716 * Return - none
7717 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007718void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307719{
Dustin Brown920397d2017-12-13 16:27:50 -08007720 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307721 uint32_t i;
7722 bool found = false;
7723 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007724
Dustin Brown920397d2017-12-13 16:27:50 -08007725 hdd_for_each_adapter(hdd_ctxt, adapter) {
7726 if (!(adapter->device_mode == QDF_SAP_MODE &&
7727 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007728 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007729 adapter->device_mode,
7730 adapter->session.ap.sap_config.
7731 acs_cfg.acs_mode);
7732 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307733 }
7734
7735 found = false;
7736 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007737 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307738 hdd_ctxt->unsafe_channel_list[i]) {
7739 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007740 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007741 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307742 break;
7743 }
7744 }
7745
7746 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007747 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007748 adapter->session.ap.operating_channel);
7749 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307750 }
7751
Kapil Gupta8878ad92017-02-13 11:56:04 +05307752 if (hdd_ctxt->config->vendor_acs_support &&
7753 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007754 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307755 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007756 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307757 } else
7758 restart_chan =
7759 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007760 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307761 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007762 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307763 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007764 /*
7765 * SAP restart due to unsafe channel. While
7766 * restarting the SAP, make sure to clear
7767 * acs_channel, channel to reset to
7768 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307769 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007770 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307771 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007772 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307773 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007774 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307775 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7776 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007777 hdd_debug("driver to start sap: %d",
7778 hdd_ctxt->config->sap_internal_restart);
7779 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08007780 hdd_switch_sap_channel(adapter, restart_chan,
7781 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04007782 else
7783 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307784 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307785 }
7786}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307787
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007788/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007789 * hdd_init_channel_avoidance() - Initialize channel avoidance
7790 * @hdd_ctx: HDD global context
7791 *
7792 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007793 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007794 * down to the lower layers. Then subscribe to subsequent channel
7795 * avoidance events.
7796 *
7797 * Return: None
7798 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007799static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007800{
7801 uint16_t unsafe_channel_count;
7802 int index;
7803
Yuanyuan Liu13738502016-04-06 17:41:37 -07007804 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7805 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007806 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007807 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007808
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007809 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007810 hdd_ctx->unsafe_channel_count);
7811
Anurag Chouhan6d760662016-02-20 16:05:43 +05307812 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007813 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007814
7815 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007816 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007817 hdd_ctx->unsafe_channel_list[index]);
7818
7819 }
7820
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007821}
Dustin Brown676a2322017-08-15 13:16:13 -07007822
Jeff Johnson9d295242017-08-29 14:39:48 -07007823static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007824 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007825{
7826 uint8_t restart_chan;
7827
7828 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7829 if (!restart_chan) {
7830 hdd_alert("fail to restart SAP");
7831 return;
7832 }
7833
7834 /* SAP restart due to unsafe channel. While restarting
7835 * the SAP, make sure to clear acs_channel, channel to
7836 * reset to 0. Otherwise these settings will override
7837 * the ACS while restart.
7838 */
7839 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007840 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007841
7842 hdd_debug("sending coex indication");
7843
7844 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7845 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08007846 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07007847}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007848
7849int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7850 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7851{
7852 uint32_t size;
7853 uint16_t *unsafe_list;
7854 uint16_t chan_count;
7855
7856 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7857 return -EINVAL;
7858
7859 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7860 NUM_CHANNELS);
7861 if (chan_count) {
7862 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7863 unsafe_list = qdf_mem_malloc(size);
7864 if (!unsafe_list) {
7865 hdd_err("No memory for unsafe chan list size%d",
7866 size);
7867 return -ENOMEM;
7868 }
7869 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7870 } else {
7871 unsafe_list = NULL;
7872 }
7873
7874 *local_unsafe_list = unsafe_list;
7875 *local_unsafe_list_count = chan_count;
7876
7877 return 0;
7878}
7879
7880bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7881 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7882{
7883 int i, j;
7884
7885 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7886 return true;
7887 if (local_unsafe_list_count == 0)
7888 return false;
7889 for (i = 0; i < local_unsafe_list_count; i++) {
7890 for (j = 0; j < local_unsafe_list_count; j++)
7891 if (local_unsafe_list[i] ==
7892 hdd_ctx->unsafe_channel_list[j])
7893 break;
7894 if (j >= local_unsafe_list_count)
7895 break;
7896 }
7897 if (i >= local_unsafe_list_count) {
7898 hdd_info("unsafe chan list same");
7899 return false;
7900 }
7901
7902 return true;
7903}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007904#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007905static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007906{
7907}
Dustin Brown676a2322017-08-15 13:16:13 -07007908
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007909static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007910{
7911}
Dustin Brown676a2322017-08-15 13:16:13 -07007912
Jeff Johnson9d295242017-08-29 14:39:48 -07007913static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007914 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007915{
7916 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7917}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007918#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007919
7920/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007921 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7922 * user space
7923 * @frame_ind: Management frame data to be informed.
7924 *
7925 * This function is used to indicate management frame to
7926 * user space
7927 *
7928 * Return: None
7929 *
7930 */
7931void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7932{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007933 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007934 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007935 int i;
7936
Rajeev Kumard004abc2016-02-17 12:09:56 -08007937 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007938 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007939
7940 if (0 != wlan_hdd_validate_context(hdd_ctx))
7941 return;
7942
7943 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7944 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7945 adapter =
7946 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7947 if (adapter)
7948 break;
7949 }
Wu Gaoa0230a62018-01-04 20:56:57 +08007950 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
7951 hdd_for_each_adapter(hdd_ctx, adapter) {
7952 if ((NULL != adapter) &&
7953 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
7954 __hdd_indicate_mgmt_frame(adapter,
7955 frame_ind->frame_len,
7956 frame_ind->frameBuf,
7957 frame_ind->frameType,
7958 frame_ind->rxChan,
7959 frame_ind->rxRssi);
7960 }
7961 }
7962 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007963 } else {
7964 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7965 frame_ind->sessionId);
7966 }
7967
7968 if ((NULL != adapter) &&
7969 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7970 __hdd_indicate_mgmt_frame(adapter,
7971 frame_ind->frame_len,
7972 frame_ind->frameBuf,
7973 frame_ind->frameType,
7974 frame_ind->rxChan,
7975 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007976}
7977
Kapil Gupta8878ad92017-02-13 11:56:04 +05307978void hdd_acs_response_timeout_handler(void *context)
7979{
7980 struct hdd_external_acs_timer_context *timer_context =
7981 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007982 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007983 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307984 uint8_t reason;
7985
7986 ENTER();
7987 if (!timer_context) {
7988 hdd_err("invlaid timer context");
7989 return;
7990 }
7991 adapter = timer_context->adapter;
7992 reason = timer_context->reason;
7993
7994
7995 if ((!adapter) ||
7996 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7997 hdd_err("invalid adapter or adapter has invalid magic");
7998 return;
7999 }
8000 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8001 if (wlan_hdd_validate_context(hdd_ctx))
8002 return;
8003
8004 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8005 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8006 else
8007 return;
8008
8009 hdd_err("ACS timeout happened for %s reason %d",
8010 adapter->dev->name, reason);
8011 switch (reason) {
8012 /* SAP init case */
8013 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8014 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8015 false);
8016 wlan_hdd_cfg80211_start_acs(adapter);
8017 break;
8018 /* DFS detected on current channel */
8019 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8020 wlan_sap_update_next_channel(
8021 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8022 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008023 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308024 break;
8025 /* LTE coex event on current channel */
8026 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8027 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8028 break;
8029 default:
8030 hdd_info("invalid reason for timer invoke");
8031
8032 }
8033}
8034
Rajeev Kumard004abc2016-02-17 12:09:56 -08008035/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008036 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
8037 * @hdd_ctx: HDD context
8038 *
8039 * Disables all the dual mac features like DBS, Agile DFS etc.
8040 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308041 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008042 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008043static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008044{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008045 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308046 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008047
8048 if (!hdd_ctx) {
8049 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308050 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008051 }
8052
8053 cfg.scan_config = 0;
8054 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008055 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008056
8057 hdd_debug("Disabling all dual mac features...");
8058
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008059 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308060 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008061 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8062 return status;
8063 }
8064
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308065 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008066}
8067
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008068static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008069wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008070{
8071 struct policy_mgr_dual_mac_config cfg = {0};
8072 QDF_STATUS status;
8073
8074 if (!hdd_ctx) {
8075 hdd_err("HDD context is NULL");
8076 return QDF_STATUS_E_FAILURE;
8077 }
8078
8079 cfg.scan_config = 0;
8080 cfg.fw_mode_config = 0;
8081 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
8082 status = policy_mgr_get_updated_scan_and_fw_mode_config(
8083 hdd_ctx->hdd_psoc, &cfg.scan_config,
8084 &cfg.fw_mode_config,
8085 hdd_ctx->config->dual_mac_feature_disable);
8086
8087 if (status != QDF_STATUS_SUCCESS) {
8088 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
8089 status);
8090 return status;
8091 }
8092
8093 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
8094 cfg.scan_config, cfg.fw_mode_config);
8095
8096 status = sme_soc_set_dual_mac_config(cfg);
8097 if (status != QDF_STATUS_SUCCESS) {
8098 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8099 return status;
8100 }
8101
8102 return QDF_STATUS_SUCCESS;
8103}
8104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008105/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008106 * hdd_override_ini_config - Override INI config
8107 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008108 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008109 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008110 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008111 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008112 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008113static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008114{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008115
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008116 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8117 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008118 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008119 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008120 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008121 if (0 == enable_11d || 1 == enable_11d) {
8122 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008123 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008124 }
Leo Chang11545d62016-10-17 14:53:50 -07008125
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008126 if (!hdd_ipa_is_present(hdd_ctx)) {
Leo Chang11545d62016-10-17 14:53:50 -07008127 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008128 hdd_debug("IpaConfig override to %d",
8129 hdd_ctx->config->IpaConfig);
8130 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308131
8132 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8133 !hdd_ctx->config->enable_bcast_probe_rsp) {
8134 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8135 hdd_ctx->config->rssi_assoc_reject_enabled,
8136 hdd_ctx->config->enable_bcast_probe_rsp);
8137 hdd_ctx->config->oce_sta_enabled = 0;
8138 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008139}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008140
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008141/**
8142 * hdd_set_trace_level_for_each - Set trace level for each INI config
8143 * @hdd_ctx - HDD context
8144 *
8145 * Set trace level for each module based on INI config.
8146 *
8147 * Return: None
8148 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008149static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008150{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308151 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8152 hdd_ctx->config->qdf_trace_enable_wdi);
8153 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8154 hdd_ctx->config->qdf_trace_enable_hdd);
8155 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8156 hdd_ctx->config->qdf_trace_enable_sme);
8157 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8158 hdd_ctx->config->qdf_trace_enable_pe);
8159 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8160 hdd_ctx->config->qdf_trace_enable_wma);
8161 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8162 hdd_ctx->config->qdf_trace_enable_sys);
8163 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8164 hdd_ctx->config->qdf_trace_enable_qdf);
8165 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8166 hdd_ctx->config->qdf_trace_enable_sap);
8167 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8168 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8169 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8170 hdd_ctx->config->qdf_trace_enable_bmi);
8171 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8172 hdd_ctx->config->qdf_trace_enable_cfg);
8173 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8174 hdd_ctx->config->qdf_trace_enable_epping);
8175 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8176 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8177 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008178 hdd_ctx->config->qdf_trace_enable_txrx);
8179 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8180 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308181 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8182 hdd_ctx->config->qdf_trace_enable_htc);
8183 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8184 hdd_ctx->config->qdf_trace_enable_hif);
8185 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8186 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8187 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8188 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008189 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8190 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008191 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8192 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008193 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8194 hdd_ctx->config->qdf_trace_enable_regulatory);
8195
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008196 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008197}
8198
8199/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008200 * hdd_context_init() - Initialize HDD context
8201 * @hdd_ctx: HDD context.
8202 *
8203 * Initialize HDD context along with all the feature specific contexts.
8204 *
8205 * return: 0 on success and errno on failure.
8206 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008207static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008208{
8209 int ret;
8210
8211 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8212 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8213
8214 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308215 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008216
8217 init_completion(&hdd_ctx->mc_sus_event_var);
8218 init_completion(&hdd_ctx->ready_to_suspend);
8219
8220 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308221 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008222 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308223
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008224 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008225
8226 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8227
8228 ret = hdd_scan_context_init(hdd_ctx);
8229 if (ret)
8230 goto list_destroy;
8231
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008232 hdd_rx_wake_lock_create(hdd_ctx);
8233
8234 ret = hdd_sap_context_init(hdd_ctx);
8235 if (ret)
8236 goto scan_destroy;
8237
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008238 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8239
8240 hdd_init_offloaded_packets_ctx(hdd_ctx);
8241
8242 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8243 hdd_ctx->config);
8244 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008245 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008246
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308247 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8248 "monitor_mode_wakelock");
8249
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008250 return 0;
8251
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008252sap_destroy:
8253 hdd_sap_context_destroy(hdd_ctx);
8254
8255scan_destroy:
8256 hdd_scan_context_destroy(hdd_ctx);
8257 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008258list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008259 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008260
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008261 return ret;
8262}
8263
8264/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308265 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8266 * @hdd_ctx: pointer to hdd context
8267 *
8268 * Return: status of initialization
8269 * 0 - success
8270 * negative value - failure
8271 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008272static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308273{
8274 int ret;
8275
8276 if (!hdd_ctx->config->probe_req_ie_whitelist)
8277 return 0;
8278
8279 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8280 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8281 hdd_ctx->config->probe_req_ie_whitelist = false;
8282 return -EINVAL;
8283 }
8284
8285 /* parse ini string probe req oui */
8286 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8287 if (ret) {
8288 hdd_err("parsing error: disable ie whitelisting");
8289 hdd_ctx->config->probe_req_ie_whitelist = false;
8290 }
8291
8292 return ret;
8293}
8294
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308295
8296/**
8297 * hdd_iface_change_callback() - Function invoked when stop modules expires
8298 * @priv: pointer to hdd context
8299 *
8300 * This function is invoked when the timer waiting for the interface change
8301 * expires, it shall cut-down the power to wlan and stop all the modules.
8302 *
8303 * Return: void
8304 */
8305static void hdd_iface_change_callback(void *priv)
8306{
8307 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8308 int ret;
8309 int status = wlan_hdd_validate_context(hdd_ctx);
8310
8311 if (status)
8312 return;
8313
8314 ENTER();
8315 hdd_debug("Interface change timer expired close the modules!");
8316 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8317 if (ret)
8318 hdd_err("Failed to stop modules");
8319 EXIT();
8320}
8321
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308322/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008323 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308324 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008325 *
8326 * Allocate and initialize HDD context. HDD context is allocated as part of
8327 * wiphy allocation and then context is initialized.
8328 *
8329 * Return: HDD context on success and ERR_PTR on failure
8330 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008331static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008332{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308333 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008334 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008335 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008336
8337 ENTER();
8338
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008339 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008340 if (hdd_ctx == NULL) {
8341 ret = -ENOMEM;
8342 goto err_out;
8343 }
8344
Dustin Brown6f427922017-09-19 12:19:00 -07008345 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8346 hdd_iface_change_callback,
8347 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308348
8349 mutex_init(&hdd_ctx->iface_change_lock);
8350
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008351 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308352 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008353
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308354 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008355 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008356 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008357 ret = -ENOMEM;
8358 goto err_free_hdd_context;
8359 }
8360
8361 /* Read and parse the qcom_cfg.ini file */
8362 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308363 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308364 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008365 WLAN_INI_FILE);
8366 ret = -EINVAL;
8367 goto err_free_config;
8368 }
8369
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308370 ie_whitelist_attrs_init(hdd_ctx);
8371
Dustin Brown7f939932017-05-18 15:02:17 -07008372 hdd_debug("setting timer multiplier: %u",
8373 hdd_ctx->config->timer_multiplier);
8374 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8375
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008376
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308377 if (hdd_ctx->config->fhostNSOffload)
8378 hdd_ctx->ns_offload_enable = true;
8379
Abhishek Singh5ea86532016-04-27 14:10:53 +05308380 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8381
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008382 hdd_override_ini_config(hdd_ctx);
8383
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008384 ret = hdd_context_init(hdd_ctx);
8385
8386 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008387 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008388
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008389 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308390 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008391
Anurag Chouhan6d760662016-02-20 16:05:43 +05308392 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008393 goto skip_multicast_logging;
8394
8395 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8396
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008397 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8398 if (ret)
8399 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308400
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008401 ret = hdd_init_netlink_services(hdd_ctx);
8402 if (ret)
8403 goto err_deinit_txrx_histogram;
8404
Dustin Brown7b3dea22017-07-10 13:02:47 -07008405 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
8406 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05308407
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008408skip_multicast_logging:
8409 hdd_set_trace_level_for_each(hdd_ctx);
8410
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008411 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8412
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008413 EXIT();
8414
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008415 return hdd_ctx;
8416
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008417err_deinit_txrx_histogram:
8418 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8419
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008420err_deinit_hdd_context:
8421 hdd_context_deinit(hdd_ctx);
8422
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008423err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308424 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008425
8426err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308427 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008428 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008429
8430err_out:
8431 return ERR_PTR(ret);
8432}
8433
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008434#ifdef WLAN_OPEN_P2P_INTERFACE
8435/**
8436 * hdd_open_p2p_interface - Open P2P interface
8437 * @hdd_ctx: HDD context
8438 * @rtnl_held: True if RTNL lock held
8439 *
8440 * Open P2P interface during probe. This function called to open the P2P
8441 * interface at probe along with STA interface.
8442 *
8443 * Return: 0 on success and errno on failure
8444 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008445static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008446{
Jeff Johnson9d295242017-08-29 14:39:48 -07008447 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008448 uint8_t *p2p_dev_addr;
8449
8450 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8451 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008452 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008453 hdd_ctx->config->intfMacAddr[0].bytes,
8454 sizeof(tSirMacAddr));
8455
8456 /*
8457 * Generate the P2P Device Address. This consists of
8458 * the device's primary MAC address with the locally
8459 * administered bit set.
8460 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008461 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008462 } else {
8463 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8464 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008465 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008466 return -ENOSPC;
8467 }
8468
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008469 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8470 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008471 }
8472
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008473 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008474 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008475 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008476
8477 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008478 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008479 return -ENOSPC;
8480 }
8481
8482 return 0;
8483}
8484#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008485static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008486 bool rtnl_held)
8487{
8488 return 0;
8489}
8490#endif
8491
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008492static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008493{
Jeff Johnson9d295242017-08-29 14:39:48 -07008494 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008495 int ret = 0;
8496
8497 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8498 wlan_hdd_get_intf_addr(hdd_ctx),
8499 NET_NAME_UNKNOWN, rtnl_held);
8500 if (adapter == NULL) {
8501 hdd_err("Failed to open 802.11p interface");
8502 ret = -ENOSPC;
8503 }
8504
8505 return ret;
8506}
8507
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008508/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308509 * hdd_start_station_adapter()- Start the Station Adapter
8510 * @adapter: HDD adapter
8511 *
8512 * This function initializes the adapter for the station mode.
8513 *
8514 * Return: 0 on success or errno on failure.
8515 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008516int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308517{
8518 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008519 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308520
8521 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008522 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8523 hdd_err("session is already opened, %d",
8524 adapter->session_id);
8525 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8526 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308527
Krunal Sonib51eec72017-11-20 21:53:01 -08008528 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8529 if (ret) {
8530 hdd_err("failed to create vdev: %d", ret);
8531 return ret;
8532 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308533 status = hdd_init_station_mode(adapter);
8534
8535 if (QDF_STATUS_SUCCESS != status) {
8536 hdd_err("Error Initializing station mode: %d", status);
8537 return qdf_status_to_os_return(status);
8538 }
8539
Arun Khandavallifae92942016-08-01 13:31:08 +05308540 hdd_register_tx_flow_control(adapter,
8541 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008542 hdd_tx_resume_cb,
8543 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308544
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308545 EXIT();
8546 return 0;
8547}
8548
8549/**
8550 * hdd_start_ap_adapter()- Start AP Adapter
8551 * @adapter: HDD adapter
8552 *
8553 * This function initializes the adapter for the AP mode.
8554 *
8555 * Return: 0 on success errno on failure.
8556 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008557int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308558{
8559 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008560 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008561 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008562 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308563
8564 ENTER();
8565
Krunal Sonib51eec72017-11-20 21:53:01 -08008566 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8567 hdd_err("session is already opened, %d",
8568 adapter->session_id);
8569 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8570 }
8571 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008572 * In SSR case no need to create new sap context.
8573 * Otherwise create sap context first and then create
8574 * vdev as while creating the vdev, driver needs to
8575 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008576 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008577 if (adapter->session.ap.sap_context) {
8578 is_ssr = true;
8579 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008580 hdd_err("sap creation failed");
8581 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8582 }
8583
8584 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8585 adapter->session.ap.sap_context);
8586 if (ret) {
8587 hdd_err("failed to create vdev, status:%d", ret);
8588 hdd_sap_destroy_ctx(adapter);
8589 return ret;
8590 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008591
8592 if (adapter->device_mode == QDF_SAP_MODE)
8593 sme_cli_set_command(adapter->session_id,
8594 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8595 (bool)(hdd_ctx->config->fine_time_meas_cap &
8596 WMI_FW_AP_RTT_RESPR),
8597 VDEV_CMD);
8598
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008599 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308600
8601 if (QDF_STATUS_SUCCESS != status) {
8602 hdd_err("Error Initializing the AP mode: %d", status);
8603 return qdf_status_to_os_return(status);
8604 }
8605
Arun Khandavallifae92942016-08-01 13:31:08 +05308606 hdd_register_tx_flow_control(adapter,
8607 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008608 hdd_softap_tx_resume_cb,
8609 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308610
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308611 EXIT();
8612 return 0;
8613}
8614
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308615static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8616 bool rtnl_held)
8617{
8618 struct hdd_adapter *adapter;
8619
8620 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8621 hdd_ctx->config->enableConcurrentSTA,
8622 wlan_hdd_get_intf_addr(hdd_ctx),
8623 NET_NAME_UNKNOWN, rtnl_held);
8624
8625 if (!adapter)
8626 return -ENOSPC;
8627
8628 return 0;
8629}
8630
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308631/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008632 * hdd_open_interfaces - Open all required interfaces
8633 * hdd_ctx: HDD context
8634 * rtnl_held: True if RTNL lock is held
8635 *
8636 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8637 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008638 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008639 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008640static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008641{
Jeff Johnson9d295242017-08-29 14:39:48 -07008642 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008643 int ret;
8644
Ravi Joshia307f632017-07-17 23:41:41 -07008645 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008646 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8647 con_mode == QDF_GLOBAL_FTM_MODE) {
8648 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8649 QDF_MONITOR_MODE : QDF_FTM_MODE;
8650
8651 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8652 wlan_hdd_get_intf_addr(hdd_ctx),
8653 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008654 if (!adapter) {
8655 hdd_err("open adapter failed");
8656 return -ENOSPC;
8657 }
Lin Bai1c678482017-12-18 18:29:11 +08008658
Ravi Joshia307f632017-07-17 23:41:41 -07008659 return 0;
8660 }
8661
Jeff Johnson957bc272017-02-02 08:54:48 -08008662 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308663 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008664 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008665
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008666 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008667 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008668 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008669
8670 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008671 return -ENOSPC;
8672
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308673 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8674 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8675 if (ret)
8676 hdd_err("Cannot create concurrent STA interface");
8677 }
8678
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008679 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8680 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008681 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008682
8683 /* Open 802.11p Interface */
8684 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008685 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8686 if (ret)
8687 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008688 }
8689
Jeff Johnson957bc272017-02-02 08:54:48 -08008690 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008691
Jeff Johnson957bc272017-02-02 08:54:48 -08008692err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008693 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008694 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008695}
8696
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008697
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308698#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8699/**
8700 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8701 * @cds_cfg: CDS Configuration
8702 * @hdd_ctx: Pointer to hdd context
8703 *
8704 * Return: none
8705 */
8706static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8707 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008708 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308709{
8710 cds_cfg->tx_flow_stop_queue_th =
8711 hdd_ctx->config->TxFlowStopQueueThreshold;
8712 cds_cfg->tx_flow_start_queue_offset =
8713 hdd_ctx->config->TxFlowStartQueueOffset;
8714}
8715#else
8716static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8717 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008718 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308719{
8720}
8721#endif
8722
8723#ifdef FEATURE_WLAN_RA_FILTERING
8724/**
8725 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8726 * @cds_cfg: CDS Configuration
8727 * @hdd_ctx: Pointer to hdd context
8728 *
8729 * Return: none
8730 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308731static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008732 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308733{
8734 cds_cfg->ra_ratelimit_interval =
8735 hdd_ctx->config->RArateLimitInterval;
8736 cds_cfg->is_ra_ratelimit_enabled =
8737 hdd_ctx->config->IsRArateLimitEnabled;
8738}
8739#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308740static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008741 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308742{
8743}
8744#endif
8745
8746/**
8747 * hdd_update_cds_config() - API to update cds configuration parameters
8748 * @hdd_ctx: HDD Context
8749 *
8750 * Return: 0 for Success, errno on failure
8751 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008752static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308753{
8754 struct cds_config_info *cds_cfg;
8755
8756 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8757 if (!cds_cfg) {
8758 hdd_err("failed to allocate cds config");
8759 return -ENOMEM;
8760 }
8761
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008762 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008763 if (!hdd_ctx->config->nMaxPsPoll ||
8764 !hdd_ctx->config->enablePowersaveOffload) {
8765 cds_cfg->powersave_offload_enabled =
8766 hdd_ctx->config->enablePowersaveOffload;
8767 } else {
8768 if ((hdd_ctx->config->enablePowersaveOffload ==
8769 PS_QPOWER_NODEEPSLEEP) ||
8770 (hdd_ctx->config->enablePowersaveOffload ==
8771 PS_LEGACY_NODEEPSLEEP))
8772 cds_cfg->powersave_offload_enabled =
8773 PS_LEGACY_NODEEPSLEEP;
8774 else
8775 cds_cfg->powersave_offload_enabled =
8776 PS_LEGACY_DEEPSLEEP;
8777 hdd_info("Qpower disabled in cds config, %d",
8778 cds_cfg->powersave_offload_enabled);
8779 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308780 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8781 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8782 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8783 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8784 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8785
8786 /* Here ol_ini_info is used to store ini status of arp offload
8787 * ns offload and others. Currently 1st bit is used for arp
8788 * off load and 2nd bit for ns offload currently, rest bits are unused
8789 */
8790 if (hdd_ctx->config->fhostArpOffload)
8791 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8792 if (hdd_ctx->config->fhostNSOffload)
8793 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8794
8795 /*
8796 * Copy the DFS Phyerr Filtering Offload status.
8797 * This parameter reflects the value of the
8798 * dfs_phyerr_filter_offload flag as set in the ini.
8799 */
8800 cds_cfg->dfs_phyerr_filter_offload =
8801 hdd_ctx->config->fDfsPhyerrFilterOffload;
8802 if (hdd_ctx->config->ssdp)
8803 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8804
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308805 cds_cfg->force_target_assert_enabled =
8806 hdd_ctx->config->crash_inject_enabled;
8807
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308808 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8809 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8810
8811 cds_cfg->ap_maxoffload_reorderbuffs =
8812 hdd_ctx->config->apMaxOffloadReorderBuffs;
8813
8814 cds_cfg->ap_disable_intrabss_fwd =
8815 hdd_ctx->config->apDisableIntraBssFwd;
8816
8817 cds_cfg->dfs_pri_multiplier =
8818 hdd_ctx->config->dfsRadarPriMultiplier;
8819 cds_cfg->reorder_offload =
8820 hdd_ctx->config->reorderOffloadSupport;
8821
8822 /* IPA micro controller data path offload resource config item */
8823 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008824 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8825 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008826 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008827 hdd_ctx->config->IpaUcTxBufCount);
8828 hdd_ctx->config->IpaUcTxBufCount =
8829 rounddown_pow_of_two(
8830 hdd_ctx->config->IpaUcTxBufCount);
8831 if (!hdd_ctx->config->IpaUcTxBufCount) {
8832 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308833 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008834 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008835 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008836 hdd_ctx->config->IpaUcTxBufCount);
8837 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308838 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8839 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008840 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8841 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008842 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008843 hdd_ctx->config->IpaUcRxIndRingCount);
8844 hdd_ctx->config->IpaUcRxIndRingCount =
8845 rounddown_pow_of_two(
8846 hdd_ctx->config->IpaUcRxIndRingCount);
8847 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8848 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308849 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008850 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008851 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008852 hdd_ctx->config->IpaUcRxIndRingCount);
8853 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308854 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008855 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308856 cds_cfg->uc_tx_partition_base =
8857 hdd_ctx->config->IpaUcTxPartitionBase;
8858 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8859
8860 cds_cfg->ip_tcp_udp_checksum_offload =
8861 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008862 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308863 cds_cfg->ce_classify_enabled =
8864 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008865 cds_cfg->bpf_packet_filter_enable =
8866 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308867 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8868 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8869 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008870 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008871 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008872 cds_cfg->max_msdus_per_rxinorderind =
8873 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008874 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008875 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308876 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8877 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308878 cds_cfg->auto_power_save_fail_mode =
8879 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308880
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308881 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008882 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08008883 cds_cfg->delay_before_vdev_stop =
8884 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308885
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308886 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8887 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8888 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008889 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308890 cds_init_ini_config(cds_cfg);
8891 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308892
8893exit:
8894 qdf_mem_free(cds_cfg);
8895 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308896}
8897
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008898/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008899 * hdd_update_user_config() - API to update user configuration
8900 * parameters to obj mgr which are used by multiple components
8901 * @hdd_ctx: HDD Context
8902 *
8903 * Return: 0 for Success, errno on failure
8904 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008905static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008906{
8907 struct wlan_objmgr_psoc_user_config *user_config;
8908
8909 user_config = qdf_mem_malloc(sizeof(*user_config));
8910 if (user_config == NULL) {
8911 hdd_alert("Failed to alloc memory for user_config!");
8912 return -ENOMEM;
8913 }
8914
8915 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8916 user_config->dual_mac_feature_disable =
8917 hdd_ctx->config->dual_mac_feature_disable;
8918 user_config->indoor_channel_support =
8919 hdd_ctx->config->indoor_channel_support;
8920 user_config->is_11d_support_enabled =
8921 hdd_ctx->config->Is11dSupportEnabled;
8922 user_config->is_11h_support_enabled =
8923 hdd_ctx->config->Is11hSupportEnabled;
8924 user_config->optimize_chan_avoid_event =
8925 hdd_ctx->config->goptimize_chan_avoid_event;
8926 user_config->skip_dfs_chnl_in_p2p_search =
8927 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008928 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008929 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8930
8931 qdf_mem_free(user_config);
8932 return 0;
8933}
8934
8935/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008936 * hdd_init_thermal_info - Initialize thermal level
8937 * @hdd_ctx: HDD context
8938 *
8939 * Initialize thermal level at SME layer and set the thermal level callback
8940 * which would be called when a configured thermal threshold is hit.
8941 *
8942 * Return: 0 on success and errno on failure
8943 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008944static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008945{
8946 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308947 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008948
8949 thermal_param.smeThermalMgmtEnabled =
8950 hdd_ctx->config->thermalMitigationEnable;
8951 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8952
Poddar, Siddarth83905022016-04-16 17:56:08 -07008953 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8954 hdd_ctx->config->throttle_dutycycle_level0;
8955 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8956 hdd_ctx->config->throttle_dutycycle_level1;
8957 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8958 hdd_ctx->config->throttle_dutycycle_level2;
8959 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8960 hdd_ctx->config->throttle_dutycycle_level3;
8961
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008962 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8963 hdd_ctx->config->thermalTempMinLevel0;
8964 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8965 hdd_ctx->config->thermalTempMaxLevel0;
8966 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8967 hdd_ctx->config->thermalTempMinLevel1;
8968 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8969 hdd_ctx->config->thermalTempMaxLevel1;
8970 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8971 hdd_ctx->config->thermalTempMinLevel2;
8972 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8973 hdd_ctx->config->thermalTempMaxLevel2;
8974 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8975 hdd_ctx->config->thermalTempMinLevel3;
8976 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8977 hdd_ctx->config->thermalTempMaxLevel3;
8978
8979 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8980
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308981 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308982 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008983
8984 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8985 hdd_set_thermal_level_cb);
8986
8987 return 0;
8988
8989}
8990
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008991#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8992/**
8993 * hdd_hold_rtnl_lock - Hold RTNL lock
8994 *
8995 * Hold RTNL lock
8996 *
8997 * Return: True if held and false otherwise
8998 */
8999static inline bool hdd_hold_rtnl_lock(void)
9000{
9001 rtnl_lock();
9002 return true;
9003}
9004
9005/**
9006 * hdd_release_rtnl_lock - Release RTNL lock
9007 *
9008 * Release RTNL lock
9009 *
9010 * Return: None
9011 */
9012static inline void hdd_release_rtnl_lock(void)
9013{
9014 rtnl_unlock();
9015}
9016#else
9017static inline bool hdd_hold_rtnl_lock(void) { return false; }
9018static inline void hdd_release_rtnl_lock(void) { }
9019#endif
9020
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009021#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009022
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309023/* MAX iwpriv command support */
9024#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309025#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309026#define MAX_PKTLOG_SIZE 16
9027
9028/**
9029 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9030 * @hdd_ctx: hdd context
9031 * @set_value2: pktlog buffer size value
9032 *
9033 *
9034 * Return: 0 for success or error.
9035 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009036static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309037{
9038 struct sir_wifi_start_log start_log = { 0 };
9039 QDF_STATUS status;
9040
9041 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9042 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9043 start_log.ini_triggered = cds_is_packet_log_enabled();
9044 start_log.user_triggered = 1;
9045 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309046 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309047
9048 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9049 if (!QDF_IS_STATUS_SUCCESS(status)) {
9050 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9051 EXIT();
9052 return -EINVAL;
9053 }
9054
9055 return 0;
9056}
9057
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009058/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309059 * hdd_pktlog_clear_buff() - clear pktlog buffer
9060 * @hdd_ctx: hdd context
9061 *
9062 * Return: 0 for success or error.
9063 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009064static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309065{
9066 struct sir_wifi_start_log start_log;
9067 QDF_STATUS status;
9068
9069 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9070 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9071 start_log.ini_triggered = cds_is_packet_log_enabled();
9072 start_log.user_triggered = 1;
9073 start_log.size = 0;
9074 start_log.is_pktlog_buff_clear = true;
9075
9076 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9077 if (!QDF_IS_STATUS_SUCCESS(status)) {
9078 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9079 EXIT();
9080 return -EINVAL;
9081 }
9082
9083 return 0;
9084}
9085
9086
9087/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009088 * hdd_process_pktlog_command() - process pktlog command
9089 * @hdd_ctx: hdd context
9090 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309091 * @set_value2: pktlog buffer size value
9092 *
9093 * This function process pktlog command.
9094 * set_value2 only matters when set_value is 3 (set buff size)
9095 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009096 *
9097 * Return: 0 for success or error.
9098 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009099int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309100 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009101{
9102 int ret;
9103 bool enable;
9104 uint8_t user_triggered = 0;
9105
9106 ret = wlan_hdd_validate_context(hdd_ctx);
9107 if (0 != ret)
9108 return ret;
9109
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009110 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009111
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309112 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009113 hdd_err("invalid pktlog value %d", set_value);
9114 return -EINVAL;
9115 }
9116
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309117 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9118 if (set_value2 <= 0) {
9119 hdd_err("invalid pktlog size %d", set_value2);
9120 return -EINVAL;
9121 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9122 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9123 return -EINVAL;
9124 }
9125 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309126 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9127 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309128 }
9129
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009130 /*
9131 * set_value = 0 then disable packetlog
9132 * set_value = 1 enable packetlog forcefully
9133 * set_vlaue = 2 then disable packetlog if disabled through ini or
9134 * enable packetlog with AUTO type.
9135 */
9136 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9137 true : false;
9138
9139 if (1 == set_value) {
9140 enable = true;
9141 user_triggered = 1;
9142 }
9143
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309144 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009145}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009146
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009147/**
9148 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9149 * @hdd_ctx: HDD context
9150 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309151 * @user_triggered: triggered through iwpriv
9152 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009153 *
9154 * Return: 0 on success; error number otherwise
9155 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009156int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309157 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009158{
9159 struct sir_wifi_start_log start_log;
9160 QDF_STATUS status;
9161
9162 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9163 start_log.verbose_level =
9164 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009165 start_log.ini_triggered = cds_is_packet_log_enabled();
9166 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309167 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309168 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309169 /*
9170 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9171 * commands. Host uses this flag to decide whether to send pktlog
9172 * disable command to fw without sending pktlog enable command
9173 * previously. For eg, If vendor sends pktlog disable command without
9174 * sending pktlog enable command, then host discards the packet
9175 * but for iwpriv command, host will send it to fw.
9176 */
9177 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009178 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9179 if (!QDF_IS_STATUS_SUCCESS(status)) {
9180 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9181 EXIT();
9182 return -EINVAL;
9183 }
9184
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309185 if (enable == true)
9186 hdd_ctx->is_pktlog_enabled = 1;
9187 else
9188 hdd_ctx->is_pktlog_enabled = 0;
9189
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009190 return 0;
9191}
9192#endif /* REMOVE_PKT_LOG */
9193
Komal Seelam92fff912016-03-24 11:51:41 +05309194/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009195 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9196 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309197 * @dev: Device Pointer
9198 * @num: Number of Valid Mac address
9199 *
9200 * Return: Pointer to MAC address buffer
9201 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009202static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9203 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309204{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009205 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309206}
Komal Seelam92fff912016-03-24 11:51:41 +05309207
9208/**
9209 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9210 * @hdd_ctx: HDD Context
9211 * @num: Number of random mac addresses needed
9212 *
9213 * Generate random addresses using bit manipulation on the base mac address
9214 *
9215 * Return: None
9216 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009217void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309218{
9219 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9220 uint32_t iter;
9221 struct hdd_config *ini = hdd_ctx->config;
9222 uint8_t *buf = NULL;
9223 uint8_t macaddr_b3, tmp_br3;
9224 uint8_t *src = ini->intfMacAddr[0].bytes;
9225
9226 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9227 buf = ini->intfMacAddr[iter].bytes;
9228 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9229 macaddr_b3 = buf[3];
9230 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9231 INTF_MACADDR_MASK;
9232 macaddr_b3 += tmp_br3;
9233 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9234 buf[0] |= 0x02;
9235 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009236 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309237 }
9238}
9239
9240/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009241 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309242 * @hdd_ctx: HDD Context
9243 *
9244 * API to get mac addresses from platform driver and update the driver
9245 * structures and configure FW with the base mac address.
9246 * Return: int
9247 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009248static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309249{
9250 uint32_t no_of_mac_addr, iter;
9251 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9252 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9253 uint8_t *addr, *buf;
9254 struct device *dev = hdd_ctx->parent_dev;
9255 struct hdd_config *ini = hdd_ctx->config;
9256 tSirMacAddr mac_addr;
9257 QDF_STATUS status;
9258
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009259 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309260
9261 if (no_of_mac_addr == 0 || !addr) {
9262 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9263 return -EINVAL;
9264 }
9265
9266 if (no_of_mac_addr > max_mac_addr)
9267 no_of_mac_addr = max_mac_addr;
9268
9269 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9270
9271 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9272 buf = ini->intfMacAddr[iter].bytes;
9273 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009274 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309275 }
9276
9277 status = sme_set_custom_mac_addr(mac_addr);
9278
9279 if (!QDF_IS_STATUS_SUCCESS(status))
9280 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009281
Komal Seelam92fff912016-03-24 11:51:41 +05309282 if (no_of_mac_addr < max_mac_addr)
9283 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9284 no_of_mac_addr);
9285 return 0;
9286}
9287
9288/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009289 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9290 * @hdd_ctx: HDD Context
9291 *
9292 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9293 * will generate its own MAC and update it to FW.
9294 *
9295 * Return: 0 for success
9296 * Non-zero error code for failure
9297 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009298static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009299{
9300 tSirMacAddr customMacAddr;
9301 QDF_STATUS status;
9302
9303 qdf_mem_copy(&customMacAddr,
9304 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9305 sizeof(tSirMacAddr));
9306 status = sme_set_custom_mac_addr(customMacAddr);
9307 if (!QDF_IS_STATUS_SUCCESS(status))
9308 return -EAGAIN;
9309 return 0;
9310}
9311
9312/**
Komal Seelam92fff912016-03-24 11:51:41 +05309313 * hdd_initialize_mac_address() - API to get wlan mac addresses
9314 * @hdd_ctx: HDD Context
9315 *
9316 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9317 * is provisioned with mac addresses, driver uses it, else it will use
9318 * wlan_mac.bin to update HW MAC addresses.
9319 *
9320 * Return: None
9321 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009322static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309323{
9324 QDF_STATUS status;
9325 int ret;
9326
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009327 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309328 if (ret == 0)
9329 return;
9330
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009331 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9332 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309333
9334 status = hdd_update_mac_config(hdd_ctx);
9335
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009336 if (QDF_IS_STATUS_SUCCESS(status))
9337 return;
9338
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009339 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9340 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009341
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009342 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009343 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009344 if (ret != 0) {
9345 hdd_err("MAC address out-of-sync, ret:%d", ret);
9346 QDF_ASSERT(ret);
9347 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009348 }
Komal Seelam92fff912016-03-24 11:51:41 +05309349}
9350
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009351static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009352{
9353 int vdev_id = 0;
9354 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9355 int value = hdd_ctx->config->smart_chainmask_enabled;
9356 int vpdev = PDEV_CMD;
9357 int ret;
9358
Naveen Rawat247a8682017-06-05 15:00:31 -07009359 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009360 if (ret)
9361 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9362
9363 return ret;
9364}
9365
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009366static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009367{
9368 int vdev_id = 0;
9369 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9370 int value = hdd_ctx->config->alternative_chainmask_enabled;
9371 int vpdev = PDEV_CMD;
9372 int ret;
9373
Naveen Rawat247a8682017-06-05 15:00:31 -07009374 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009375 if (ret)
9376 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9377 ret);
9378
9379 return ret;
9380}
9381
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009382static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009383{
9384 int vdev_id = 0;
9385 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9386 int value = hdd_ctx->config->ani_enabled;
9387 int vpdev = PDEV_CMD;
9388 int ret;
9389
Naveen Rawat247a8682017-06-05 15:00:31 -07009390 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009391 if (ret)
9392 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9393
9394 return ret;
9395}
9396
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009397/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009398 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9399 * @hdd_ctx: HDD context
9400 *
9401 * Pre configurations to be done at lower layer before calling cds enable.
9402 *
9403 * Return: 0 on success and errno on failure.
9404 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009405static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009406{
9407 int ret;
9408 QDF_STATUS status;
9409 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009410 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009411
Leo Changfdb45c32016-10-28 11:09:23 -07009412 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009413 /*
9414 * Set 802.11p config
9415 * TODO-OCB: This has been temporarily added here to ensure this
9416 * parameter is set in CSR when we init the channel list. This should
9417 * be removed once the 5.9 GHz channels are added to the regulatory
9418 * domain.
9419 */
9420 hdd_set_dot11p_config(hdd_ctx);
9421
9422 /*
9423 * Note that the cds_pre_enable() sequence triggers the cfg download.
9424 * The cfg download must occur before we update the SME config
9425 * since the SME config operation must access the cfg database
9426 */
9427 status = hdd_set_sme_config(hdd_ctx);
9428
9429 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009430 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009431 ret = qdf_status_to_os_return(status);
9432 goto out;
9433 }
9434
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009435 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9436 if (QDF_STATUS_SUCCESS != status) {
9437 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9438 ret = qdf_status_to_os_return(status);
9439 goto out;
9440 }
9441
Naveen Rawat247a8682017-06-05 15:00:31 -07009442 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009443 hdd_ctx->config->tx_chain_mask_1ss,
9444 PDEV_CMD);
9445 if (0 != ret) {
9446 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9447 goto out;
9448 }
9449
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009450 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9451 if (ret)
9452 goto out;
9453
9454 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9455 if (ret)
9456 goto out;
9457
Jeff Johnson12a744b2017-04-04 08:19:37 -07009458 ret = hdd_set_ani_enabled(hdd_ctx);
9459 if (ret)
9460 goto out;
9461
Naveen Rawat247a8682017-06-05 15:00:31 -07009462 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009463 hdd_ctx->config->arp_ac_category,
9464 PDEV_CMD);
9465 if (0 != ret) {
9466 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9467 hdd_ctx->config->arp_ac_category, ret);
9468 goto out;
9469 }
9470
Prashanth Bhatta07998752016-04-28 12:35:33 -07009471 status = hdd_set_sme_chan_list(hdd_ctx);
9472 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009473 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009474 ret = qdf_status_to_os_return(status);
9475 goto out;
9476 }
9477
9478 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009479 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009480 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009481 ret = -EINVAL;
9482 goto out;
9483 }
9484
Prashanth Bhatta07998752016-04-28 12:35:33 -07009485 /*
9486 * Set the MAC Address Currently this is used by HAL to add self sta.
9487 * Remove this once self sta is added as part of session open.
9488 */
9489 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9490 hdd_ctx->config->intfMacAddr[0].bytes,
9491 sizeof(hdd_ctx->config->intfMacAddr[0]));
9492
9493 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9494 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9495 hal_status, hal_status);
9496 ret = -EINVAL;
9497 goto out;
9498 }
9499
9500 hdd_init_channel_avoidance(hdd_ctx);
9501
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309502 /* update enable sap mandatory chan list */
9503 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9504 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009505out:
9506 return ret;
9507}
9508
9509/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009510 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9511 * @context_ptr - hdd context pointer
9512 * @event_ptr - event structure pointer
9513 *
9514 * This is the p2p listen offload stop event handler, it sends vendor
9515 * event back to supplicant to notify the stop reason.
9516 *
9517 * Return: None
9518 */
9519static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9520 void *event_ptr)
9521{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009522 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009523 struct sir_p2p_lo_event *evt = event_ptr;
9524 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009525 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009526
9527 ENTER();
9528
9529 if (hdd_ctx == NULL) {
9530 hdd_err("Invalid HDD context pointer");
9531 return;
9532 }
9533
Peng Xu5c682812017-08-06 07:39:13 -07009534 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9535 if (!adapter) {
9536 hdd_err("Cannot find adapter by vdev_id = %d",
9537 evt->vdev_id);
9538 return;
9539 }
9540
Peng Xu8fdaa492016-06-22 10:20:47 -07009541 vendor_event =
9542 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009543 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009544 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9545 GFP_KERNEL);
9546
9547 if (!vendor_event) {
9548 hdd_err("cfg80211_vendor_event_alloc failed");
9549 return;
9550 }
9551
9552 if (nla_put_u32(vendor_event,
9553 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9554 evt->reason_code)) {
9555 hdd_err("nla put failed");
9556 kfree_skb(vendor_event);
9557 return;
9558 }
9559
9560 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009561 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9562 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009563}
9564
9565/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309566 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9567 * @hdd_ctx: HDD context
9568 *
9569 * This function sends the adaptive dwell time config configuration to the
9570 * firmware via WMA
9571 *
9572 * Return: 0 - success, < 0 - failure
9573 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009574static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309575{
9576 QDF_STATUS status;
9577 struct adaptive_dwelltime_params dwelltime_params;
9578
9579 dwelltime_params.is_enabled =
9580 hdd_ctx->config->adaptive_dwell_mode_enabled;
9581 dwelltime_params.dwelltime_mode =
9582 hdd_ctx->config->global_adapt_dwelltime_mode;
9583 dwelltime_params.lpf_weight =
9584 hdd_ctx->config->adapt_dwell_lpf_weight;
9585 dwelltime_params.passive_mon_intval =
9586 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9587 dwelltime_params.wifi_act_threshold =
9588 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9589
9590 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9591 &dwelltime_params);
9592
9593 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9594 if (!QDF_IS_STATUS_SUCCESS(status)) {
9595 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9596 return -EAGAIN;
9597 }
9598 return 0;
9599}
9600
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009601int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309602{
9603 QDF_STATUS status;
9604 struct wmi_dbs_scan_sel_params dbs_scan_params;
9605 uint32_t i = 0;
9606 uint8_t count = 0, numentries = 0;
9607 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9608 * CDS_DBS_SCAN_CLIENTS_MAX];
9609
9610 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009611 if (hdd_ctx->config->dual_mac_feature_disable ==
9612 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309613 return -EINVAL;
9614
9615 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9616 dbs_scan_config, &numentries,
9617 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9618 * CDS_DBS_SCAN_CLIENTS_MAX));
9619
9620 hdd_info("numentries %hu", numentries);
9621 if (!numentries) {
9622 hdd_info("Donot send scan_selection_config");
9623 return 0;
9624 }
9625
9626 /* hdd_set_fw_log_params */
9627 dbs_scan_params.num_clients = 0;
9628 while (count < (numentries - 2)) {
9629 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9630 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9631 dbs_scan_params.num_non_dbs_scans[i] =
9632 dbs_scan_config[count + 2];
9633 dbs_scan_params.num_clients++;
9634 hdd_debug("module:%d NDS:%d NNDS:%d",
9635 dbs_scan_params.module_id[i],
9636 dbs_scan_params.num_dbs_scans[i],
9637 dbs_scan_params.num_non_dbs_scans[i]);
9638 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9639 i++;
9640 }
9641
9642 dbs_scan_params.pdev_id = 0;
9643
9644 hdd_debug("clients:%d pdev:%d",
9645 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9646
9647 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9648 &dbs_scan_params);
9649 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9650 if (!QDF_IS_STATUS_SUCCESS(status)) {
9651 hdd_err("Failed to send DBS Scan selection configuration!");
9652 return -EAGAIN;
9653 }
9654 return 0;
9655}
9656
Arun Khandavallid4349a92016-07-25 11:10:43 +05309657#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9658/**
9659 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9660 * @hdd_ctx: HDD context
9661 *
9662 * Set auto shutdown callback to get indications from firmware to indicate
9663 * userspace to shutdown WLAN after a configured amount of inactivity.
9664 *
9665 * Return: 0 on success and errno on failure.
9666 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009667static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309668{
9669 QDF_STATUS status;
9670
9671 if (!hdd_ctx->config->WlanAutoShutdown)
9672 return 0;
9673
9674 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9675 wlan_hdd_auto_shutdown_cb);
9676 if (status != QDF_STATUS_SUCCESS)
9677 hdd_err("Auto shutdown feature could not be enabled: %d",
9678 status);
9679
9680 return qdf_status_to_os_return(status);
9681}
9682#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009683static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309684{
9685 return 0;
9686}
9687#endif
9688
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009689static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009690{
9691 QDF_STATUS status = QDF_STATUS_SUCCESS;
9692
9693 switch (hdd_ctx->config->dual_mac_feature_disable) {
9694 case DISABLE_DBS_CXN_AND_SCAN:
9695 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9696 if (status != QDF_STATUS_SUCCESS)
9697 hdd_err("Failed to disable dual mac features");
9698 break;
9699 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9700 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9701 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9702 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9703 if (status != QDF_STATUS_SUCCESS)
9704 hdd_err("Failed to set dbs scan and fw mode config");
9705 break;
9706 default:
9707 break;
9708 }
9709
9710 return status;
9711}
9712
Arun Khandavallid4349a92016-07-25 11:10:43 +05309713/**
9714 * hdd_features_init() - Init features
9715 * @hdd_ctx: HDD context
9716 * @adapter: Primary adapter context
9717 *
9718 * Initialize features and their feature context after WLAN firmware is up.
9719 *
9720 * Return: 0 on success and errno on failure.
9721 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009722static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309723{
9724 tSirTxPowerLimit hddtxlimit;
9725 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309726 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309727 int ret;
9728
9729 ENTER();
9730
Arun Khandavallid4349a92016-07-25 11:10:43 +05309731 /* FW capabilities received, Set the Dot11 mode */
9732 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009733 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9734 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309735
Arun Khandavallid4349a92016-07-25 11:10:43 +05309736
9737 if (hdd_ctx->config->fIsImpsEnabled)
9738 hdd_set_idle_ps_config(hdd_ctx, true);
9739 else
9740 hdd_set_idle_ps_config(hdd_ctx, false);
9741
Poddar, Siddarth37033032017-10-11 15:47:40 +05309742 /* Send Enable/Disable data stall detection cmd to FW */
9743 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9744 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9745
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309746 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009747 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309748
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309749 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9750 hdd_warn("Error in setting Voltage Corner mode config to FW");
9751
Arun Khandavallid4349a92016-07-25 11:10:43 +05309752 if (hdd_lro_init(hdd_ctx))
9753 hdd_err("Unable to initialize LRO in fw");
9754
9755 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9756 hdd_err("Unable to send adaptive dwelltime setting to FW");
9757
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309758 if (hdd_dbs_scan_selection_init(hdd_ctx))
9759 hdd_err("Unable to send DBS scan selection setting to FW");
9760
Arun Khandavallid4349a92016-07-25 11:10:43 +05309761 ret = hdd_init_thermal_info(hdd_ctx);
9762 if (ret) {
9763 hdd_err("Error while initializing thermal information");
9764 goto deregister_frames;
9765 }
9766
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309767 /**
9768 * In case of SSR/PDR, if pktlog was enabled manually before
9769 * SSR/PDR, Then enabled it again automatically after Wlan
9770 * device up.
9771 */
9772 if (cds_is_driver_recovering()) {
9773 if (hdd_ctx->is_pktlog_enabled)
9774 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9775 } else if (cds_is_packet_log_enabled())
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309776 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9777
Arun Khandavallid4349a92016-07-25 11:10:43 +05309778 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9779 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9780 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9781 if (!QDF_IS_STATUS_SUCCESS(status))
9782 hdd_err("Error setting txlimit in sme: %d", status);
9783
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009784 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309785
Arun Khandavallid4349a92016-07-25 11:10:43 +05309786 ret = hdd_register_cb(hdd_ctx);
9787 if (ret) {
9788 hdd_err("Failed to register HDD callbacks!");
9789 goto deregister_frames;
9790 }
9791
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009792 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9793 if (!QDF_IS_STATUS_SUCCESS(status)) {
9794 hdd_err("Failed to set dbs scan and fw mode cfg");
9795 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309796 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009797
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309798 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9799 status = sme_enable_disable_chanavoidind_event(
9800 hdd_ctx->hHal, 0);
9801 if (!QDF_IS_STATUS_SUCCESS(status)) {
9802 hdd_err("Failed to disable Chan Avoidance Indication");
9803 goto deregister_cb;
9804 }
9805 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309806
Manjeet Singha9cae432017-02-28 11:58:22 +05309807 if (hdd_ctx->config->enable_5g_band_pref) {
9808 band_pref_params.rssi_boost_threshold_5g =
9809 hdd_ctx->config->rssi_boost_threshold_5g;
9810 band_pref_params.rssi_boost_factor_5g =
9811 hdd_ctx->config->rssi_boost_factor_5g;
9812 band_pref_params.max_rssi_boost_5g =
9813 hdd_ctx->config->max_rssi_boost_5g;
9814 band_pref_params.rssi_penalize_threshold_5g =
9815 hdd_ctx->config->rssi_penalize_threshold_5g;
9816 band_pref_params.rssi_penalize_factor_5g =
9817 hdd_ctx->config->rssi_penalize_factor_5g;
9818 band_pref_params.max_rssi_penalize_5g =
9819 hdd_ctx->config->max_rssi_penalize_5g;
9820 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9821 }
9822
Arun Khandavallid4349a92016-07-25 11:10:43 +05309823 /* register P2P Listen Offload event callback */
9824 if (wma_is_p2p_lo_capable())
9825 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9826 wlan_hdd_p2p_lo_event_callback);
9827
9828 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9829
9830 if (ret)
9831 goto deregister_cb;
9832
Dustin Brown11638b72018-01-25 17:37:25 +05309833 wlan_hdd_init_chan_info(hdd_ctx);
9834
Arun Khandavallid4349a92016-07-25 11:10:43 +05309835 EXIT();
9836 return 0;
9837
9838deregister_cb:
9839 hdd_deregister_cb(hdd_ctx);
9840deregister_frames:
9841 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309842 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309843}
9844
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009845/**
9846 * hdd_features_deinit() - Deinit features
9847 * @hdd_ctx: HDD context
9848 *
9849 * De-Initialize features and their feature context.
9850 *
9851 * Return: none.
9852 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009853static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009854{
Dustin Brown11638b72018-01-25 17:37:25 +05309855 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009856 wlan_hdd_tsf_deinit(hdd_ctx);
9857}
9858
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309859/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009860 * hdd_register_bcn_cb() - register scan beacon callback
9861 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309862 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009863 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309864 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009865static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309866{
9867 QDF_STATUS status;
9868
9869 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9870 wlan_cfg80211_inform_bss_frame,
9871 SCAN_CB_TYPE_INFORM_BCN);
9872 if (!QDF_IS_STATUS_SUCCESS(status)) {
9873 hdd_err("failed with status code %08d [x%08x]",
9874 status, status);
9875 return status;
9876 }
9877
9878 return QDF_STATUS_SUCCESS;
9879}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309880
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309881/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309882 * hdd_configure_cds() - Configure cds modules
9883 * @hdd_ctx: HDD context
9884 * @adapter: Primary adapter context
9885 *
9886 * Enable Cds modules after WLAN firmware is up.
9887 *
9888 * Return: 0 on success and errno on failure.
9889 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009890int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309891{
9892 int ret;
9893 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309894 int set_value;
9895 uint32_t num_abg_tx_chains = 0;
9896 uint32_t num_11b_tx_chains = 0;
9897 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009898 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309899
9900 if (hdd_ctx->config->sifs_burst_duration) {
9901 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9902 hdd_ctx->config->sifs_burst_duration;
9903
9904 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9905 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9906 set_value, PDEV_CMD);
9907 }
9908
9909 if (hdd_ctx->config->is_force_1x1)
9910 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9911 1, PDEV_CMD);
9912 /* set chip power save failure detected callback */
9913 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9914 hdd_chip_pwr_save_fail_detected_cb);
9915
9916 if (hdd_ctx->config->max_mpdus_inampdu) {
9917 set_value = hdd_ctx->config->max_mpdus_inampdu;
9918 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9919 set_value, PDEV_CMD);
9920 }
9921
9922 if (hdd_ctx->config->enable_rts_sifsbursting) {
9923 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9924 sme_cli_set_command(0,
9925 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9926 set_value, PDEV_CMD);
9927 }
9928
9929 if (hdd_ctx->config->sap_get_peer_info) {
9930 set_value = hdd_ctx->config->sap_get_peer_info;
9931 sme_cli_set_command(0,
9932 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9933 set_value, PDEV_CMD);
9934 }
9935
9936 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9937 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9938 if (!hdd_ctx->config->enable2x2) {
9939 if (num_11b_tx_chains > 1)
9940 num_11b_tx_chains = 1;
9941 if (num_11ag_tx_chains > 1)
9942 num_11ag_tx_chains = 1;
9943 }
9944 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9945 num_11b_tx_chains);
9946 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9947 num_11ag_tx_chains);
9948 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9949 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309950
9951 ret = hdd_pre_enable_configure(hdd_ctx);
9952 if (ret) {
9953 hdd_err("Failed to pre-configure cds");
9954 goto out;
9955 }
9956
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009957 /* Always get latest IPA resources allocated from cds_open and configure
9958 * IPA module before configuring them to FW. Sequence required as crash
9959 * observed otherwise.
9960 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009961 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9962 hdd_err("Failed to setup pipes");
9963 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009964 }
9965
Arun Khandavallifae92942016-08-01 13:31:08 +05309966 /*
9967 * Start CDS which starts up the SME/MAC/HAL modules and everything
9968 * else
9969 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009970 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309971
9972 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009973 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309974 goto out;
9975 }
9976
9977 status = hdd_post_cds_enable_config(hdd_ctx);
9978 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009979 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009980 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309981 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309982 status = hdd_register_bcn_cb(hdd_ctx);
9983 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +08009984 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309985 goto cds_disable;
9986 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309987
9988 ret = hdd_features_init(hdd_ctx, adapter);
9989 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009990 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309991
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009992 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009993 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009994 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9995 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009996 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009997 goto cds_disable;
9998 }
9999
Himanshu Agarwalb229a142017-12-21 10:16:45 +053010000 if (ucfg_green_ap_enable_egap(hdd_ctx->hdd_pdev))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010001 hdd_debug("enhance green ap is not enabled");
10002
Nachiket Kukadedd302662017-07-13 17:31:44 +053010003 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10004 hdd_debug("Failed to set wow pulse");
10005
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010006 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10007 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010008 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10009 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10010
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010011
10012 if (hdd_ctx->config->enable_phy_reg_retention)
10013 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10014 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10015
Arun Khandavallifae92942016-08-01 13:31:08 +053010016 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010017
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010018cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010019 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010020
Arun Khandavallifae92942016-08-01 13:31:08 +053010021out:
10022 return -EINVAL;
10023}
10024
10025/**
10026 * hdd_deconfigure_cds() -De-Configure cds
10027 * @hdd_ctx: HDD context
10028 *
10029 * Deconfigure Cds modules before WLAN firmware is down.
10030 *
10031 * Return: 0 on success and errno on failure.
10032 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010033static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010034{
10035 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010036 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010037
10038 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010039
10040 /* De-init features */
10041 hdd_features_deinit(hdd_ctx);
10042
Arun Khandavallifae92942016-08-01 13:31:08 +053010043 /* De-register the SME callbacks */
10044 hdd_deregister_cb(hdd_ctx);
10045
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010046 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010047 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10048 hdd_err("Failed to Disable the CDS Modules! :%d",
10049 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010050 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010051 }
10052
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010053 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
10054 hdd_err("Failed to disconnect pipes");
10055 ret = -EINVAL;
10056 }
10057
Arun Khandavallifae92942016-08-01 13:31:08 +053010058 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010059 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010060}
10061
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010062#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10063static void hdd_deregister_policy_manager_callback(
10064 struct wlan_objmgr_psoc *psoc)
10065{
10066 if (QDF_STATUS_SUCCESS !=
10067 policy_mgr_deregister_hdd_cb(psoc)) {
10068 hdd_err("HDD callback deregister with policy manager failed");
10069 }
10070}
10071#else
10072static void hdd_deregister_policy_manager_callback(
10073 struct wlan_objmgr_psoc *psoc)
10074{
10075}
10076#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010077
10078/**
10079 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10080 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010081 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010082 *
10083 * This function maintains the driver state machine it will be invoked from
10084 * exit, shutdown and con_mode change handler. Depending on the driver state
10085 * shall perform the stopping/closing of the modules.
10086 *
10087 * Return: 0 for success; non-zero for failure
10088 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010089int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010090{
10091 void *hif_ctx;
10092 qdf_device_t qdf_ctx;
10093 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010094 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010095 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010096 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10097 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010098 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010099 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010100
10101 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -070010102 hdd_alert("stop WLAN module: entering driver status=%d",
10103 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010104
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010105 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10106
Arun Khandavallifae92942016-08-01 13:31:08 +053010107 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10108 if (!qdf_ctx) {
10109 hdd_err("QDF device context NULL");
10110 return -EINVAL;
10111 }
10112
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010113 mutex_lock(&hdd_ctx->iface_change_lock);
10114 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010115 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010116
Dustin Brown70111822017-03-30 15:31:40 -070010117 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010118 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010119 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010120 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010121
10122 cds_print_external_threads();
10123
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010124 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010125 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010126 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10127 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010128 hdd_prevent_suspend_timeout(
10129 hdd_ctx->config->iface_change_wait_time,
10130 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010131 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010132 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010133 return 0;
10134 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010135 }
10136
Arun Khandavallifae92942016-08-01 13:31:08 +053010137 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10138
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010139 /* free user wowl patterns */
10140 hdd_free_user_wowl_ptrns();
10141
Arun Khandavallifae92942016-08-01 13:31:08 +053010142 switch (hdd_ctx->driver_status) {
10143 case DRIVER_MODULES_UNINITIALIZED:
10144 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010145 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010146 case DRIVER_MODULES_CLOSED:
10147 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010148 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010149 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010150 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10151
Komal Seelamf2136bb2016-09-28 18:30:44 +053010152 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010153 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010154 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010155 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010156 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010157 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010158 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010159
Arun Khandavallifae92942016-08-01 13:31:08 +053010160 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010161 hdd_info("Wlan transitioned (now OPENED)");
10162
10163 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010164 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010165 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010166 break;
10167 default:
10168 hdd_err("Trying to stop wlan in a wrong state: %d",
10169 hdd_ctx->driver_status);
10170 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010171 ret = -EINVAL;
10172 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010173 }
10174
Amar Singhal18081642018-01-26 16:04:13 -080010175 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010176 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010177
Rajeev Kumarbe021242017-02-16 16:12:23 -080010178 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010179 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10180 hdd_err("Failed to process post CDS disable Modules! :%d",
10181 qdf_status);
10182 ret = -EINVAL;
10183 QDF_ASSERT(0);
10184 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010185
psimhadeea0a12017-12-18 14:50:02 -080010186 hdd_runtime_suspend_context_deinit(hdd_ctx);
10187
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010188 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10189 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10190 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10191 ret = -EINVAL;
10192 QDF_ASSERT(0);
10193 }
10194
Jeff Johnsone4b14592017-09-13 14:23:33 -070010195 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010196 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010197 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010198 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010199 QDF_ASSERT(0);
10200 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010201
Amar Singhal410675c2018-01-10 12:14:21 -080010202 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010203 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10204 if (ret) {
10205 hdd_err("Failed to destroy pdev; errno:%d", ret);
10206 QDF_ASSERT(0);
10207 }
10208
10209 /*
10210 * Reset total mac phy during module stop such that during
10211 * next module start same psoc is used to populate new service
10212 * ready data
10213 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010214 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10215 if (tgt_hdl)
10216 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10217
Liangwei Dong50a64a72018-01-11 01:17:00 -050010218
Arun Khandavallifae92942016-08-01 13:31:08 +053010219 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10220 if (!hif_ctx) {
10221 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010222 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010223 }
10224
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010225 if (hdd_ctx->target_hw_name) {
10226 qdf_mem_free(hdd_ctx->target_hw_name);
10227 hdd_ctx->target_hw_name = NULL;
10228 }
10229
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010230 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010231
10232 ol_cds_free();
10233
Dustin Brown70111822017-03-30 15:31:40 -070010234 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010235 ret = pld_power_off(qdf_ctx->dev);
10236 if (ret)
10237 hdd_err("CNSS power down failed put device into Low power mode:%d",
10238 ret);
10239 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010240
Dustin Brown4bc0a622017-12-06 15:56:50 -080010241 /* many adapter resources are not freed by design in SSR case */
10242 if (!is_recovery_stop)
10243 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010244 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010245
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010246 /* Once the firmware sequence is completed reset this flag */
10247 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010248 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010249 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010250
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010251done:
10252 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010253 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010254 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010255 hdd_alert("stop WLAN module: exit driver status=%d",
10256 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010257
Arun Khandavallifae92942016-08-01 13:31:08 +053010258 EXIT();
10259
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010260 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010261}
10262
Arun Khandavallifae92942016-08-01 13:31:08 +053010263
10264/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010265 * hdd_state_info_dump() - prints state information of hdd layer
10266 * @buf: buffer pointer
10267 * @size: size of buffer to be filled
10268 *
10269 * This function is used to dump state information of hdd layer
10270 *
10271 * Return: None
10272 */
10273static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10274{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010275 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010276 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010277 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010278 uint16_t len = 0;
10279 char *buf = *buf_ptr;
10280
10281 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10282 if (!hdd_ctx) {
10283 hdd_err("Failed to get hdd context ");
10284 return;
10285 }
10286
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010287 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010288
10289 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010290 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010291 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010292 "\n is_scheduler_suspended %d",
10293 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010294
Dustin Brown920397d2017-12-13 16:27:50 -080010295 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010296 if (adapter->dev)
10297 len += scnprintf(buf + len, *size - len,
10298 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010299 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010300 "\n device_mode: %d", adapter->device_mode);
10301 switch (adapter->device_mode) {
10302 case QDF_STA_MODE:
10303 case QDF_P2P_CLIENT_MODE:
10304 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10305 len += scnprintf(buf + len, *size - len,
10306 "\n connState: %d",
10307 hdd_sta_ctx->conn_info.connState);
10308 break;
10309
10310 default:
10311 break;
10312 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010313 }
10314
10315 *size -= len;
10316 *buf_ptr += len;
10317}
10318
10319/**
10320 * hdd_register_debug_callback() - registration function for hdd layer
10321 * to print hdd state information
10322 *
10323 * Return: None
10324 */
10325static void hdd_register_debug_callback(void)
10326{
10327 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10328}
10329
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010330/*
10331 * wlan_init_bug_report_lock() - Initialize bug report lock
10332 *
10333 * This function is used to create bug report lock
10334 *
10335 * Return: None
10336 */
10337static void wlan_init_bug_report_lock(void)
10338{
10339 p_cds_contextType p_cds_context;
10340
10341 p_cds_context = cds_get_global_context();
10342 if (!p_cds_context) {
10343 hdd_err("cds context is NULL");
10344 return;
10345 }
10346
10347 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10348}
10349
Mohit Khannaf8f96822017-05-17 17:11:59 -070010350void hdd_dp_trace_init(struct hdd_config *config)
10351{
10352
10353 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10354 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10355 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10356 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10357 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10358 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10359 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010360 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010361
10362 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10363 &num_entries, sizeof(config_params));
10364
10365 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010366 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010367 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010368 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010369 else if (bw_compute_interval > 1000) {
10370 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10371 thresh_time_limit = 1;
10372 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010373 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10374
10375 switch (num_entries) {
10376 case 4:
10377 proto_bitmap = config_params[3];
10378 case 3:
10379 verbosity = config_params[2];
10380 case 2:
10381 thresh = config_params[1];
10382 case 1:
10383 live_mode = config_params[0];
10384 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010385 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010386 live_mode, thresh, thresh_time_limit,
10387 verbosity, proto_bitmap);
10388 };
10389
10390 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10391 verbosity, proto_bitmap);
10392
10393}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010394/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010395 * hdd_wlan_startup() - HDD init function
10396 * @dev: Pointer to the underlying device
10397 *
10398 * This is the driver startup code executed once a WLAN device has been detected
10399 *
10400 * Return: 0 for success, < 0 for failure
10401 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010402int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010403{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010404 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010405 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010406 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010407 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010408
10409 ENTER();
10410
Arun Khandavallifae92942016-08-01 13:31:08 +053010411 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010412
10413 if (IS_ERR(hdd_ctx))
10414 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010415
Abhishek Singhe9068f12017-03-31 14:14:52 +053010416 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10417 DEFAULT_PSOC_ID);
10418 if (ret) {
10419 hdd_err("Psoc creation fails!");
10420 QDF_BUG(0);
10421 goto err_hdd_free_context;
10422 }
10423
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010424 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010425#ifdef FEATURE_WLAN_CH_AVOID
10426 mutex_init(&hdd_ctx->avoid_freq_lock);
10427#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010428
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010429 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010430 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010431
Dustin Brown021cecd2017-12-11 13:56:43 -080010432 hdd_driver_memdump_init();
10433
Jeff Johnson957bc272017-02-02 08:54:48 -080010434 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010435 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010436 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010437 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010438 }
10439
Yingying Tang80e15f32016-09-27 18:23:01 +080010440 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010441
Anurag Chouhan6d760662016-02-20 16:05:43 +053010442 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010443
10444 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010445 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010446 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010447 }
10448
Prashanth Bhatta07998752016-04-28 12:35:33 -070010449 ret = hdd_wiphy_init(hdd_ctx);
10450 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010451 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010452 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010453 }
10454
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010455 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010456 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010457
jiad195f7032018-01-31 15:18:09 +080010458 ret = hdd_ipa_init(hdd_ctx);
10459 if (ret == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010460 goto err_wiphy_unregister;
10461
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010462 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010463
Paul Zhangfb02f452017-12-22 11:58:43 +080010464 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10465 if (ret) {
10466 hdd_err("register_netdevice_notifier failed: %d", ret);
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010467 goto err_ipa_cleanup;
Paul Zhangfb02f452017-12-22 11:58:43 +080010468 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010469
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010470 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010471
Jeff Johnson957bc272017-02-02 08:54:48 -080010472 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10473 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010474 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010475 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010476 }
10477
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010478 hdd_release_rtnl_lock();
10479 rtnl_held = false;
10480
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010481 wlan_hdd_update_11n_mode(hdd_ctx->config);
10482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010483#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010484 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010485 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010486 hdd_skip_acs_scan_timer_handler,
10487 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010488 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010489 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010490 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010491#endif
10492
Prashanth Bhattaab004382016-10-11 16:08:11 -070010493 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010494
Jeff Johnson9afc5012016-09-23 13:56:27 -070010495 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010496
Nirav Shahbd36b062016-07-18 11:12:59 +053010497 if (hdd_ctx->rps)
10498 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010499
Paul Zhangfb02f452017-12-22 11:58:43 +080010500 ret = hdd_register_notifiers(hdd_ctx);
10501 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010502 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010503
Paul Zhangfb02f452017-12-22 11:58:43 +080010504 status = wlansap_global_init();
10505 if (QDF_IS_STATUS_ERROR(status)) {
10506 hdd_unregister_notifiers(hdd_ctx);
10507 goto err_close_adapters;
10508 }
10509
Arun Khandavallifae92942016-08-01 13:31:08 +053010510 if (hdd_ctx->config->fIsImpsEnabled)
10511 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010512 else
10513 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010514
Mukul Sharma07bd8752017-10-10 16:58:14 +053010515 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010516 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10517 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010518 hdd_prevent_suspend_timeout(
10519 hdd_ctx->config->iface_change_wait_time,
10520 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10521 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010522
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010523 goto success;
10524
Jeff Johnson957bc272017-02-02 08:54:48 -080010525err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010526 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010527
Jeff Johnson46bde382017-02-01 15:31:16 -080010528err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010529 if (rtnl_held)
10530 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010531
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010532 unregister_netdevice_notifier(&hdd_netdev_notifier);
10533
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010534err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010535 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010536
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010537err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010538 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010539
Arun Khandavallifae92942016-08-01 13:31:08 +053010540err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010541 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010542
Dustin Brown021cecd2017-12-11 13:56:43 -080010543err_memdump_deinit:
10544 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010545
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010546 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010547 hdd_exit_netlink_services(hdd_ctx);
10548
Dustin Brown20912462017-06-07 13:48:25 -070010549 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10550
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010551err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010552 if (cds_is_fw_down())
10553 hdd_err("Not setting the complete event as fw is down");
10554 else
10555 hdd_start_complete(ret);
10556
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010557 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010558 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010559 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010560
10561success:
10562 EXIT();
10563 return 0;
10564}
10565
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010566/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010567 * hdd_wlan_update_target_info() - update target type info
10568 * @hdd_ctx: HDD context
10569 * @context: hif context
10570 *
10571 * Update target info received from firmware in hdd context
10572 * Return:None
10573 */
10574
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010575void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010576{
10577 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10578
10579 if (!tgt_info) {
10580 hdd_err("Target info is Null");
10581 return;
10582 }
10583
10584 hdd_ctx->target_type = tgt_info->target_type;
10585}
10586
10587/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010588 * hdd_get_nud_stats_cb() - callback api to update the stats
10589 * received from the firmware
10590 * @data: pointer to adapter.
10591 * @rsp: pointer to data received from FW.
10592 *
10593 * This is called when wlan driver received response event for
10594 * get arp stats to firmware.
10595 *
10596 * Return: None
10597 */
10598static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10599{
10600 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10601 struct hdd_nud_stats_context *context;
10602 int status;
10603 struct hdd_adapter *adapter = NULL;
10604
10605 ENTER();
10606
10607 if (!rsp) {
10608 hdd_err("data is null");
10609 return;
10610 }
10611
10612 status = wlan_hdd_validate_context(hdd_ctx);
10613 if (0 != status)
10614 return;
10615
10616 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10617 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10618 hdd_err("Invalid adapter or adapter has invalid magic");
10619 return;
10620 }
10621
10622 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10623 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10624 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10625 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10626 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10627 rsp->out_of_order_arp_rsp_drop_cnt);
10628 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10629 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10630 hdd_notice("rsp->ba_session_establishment_status :%x",
10631 rsp->ba_session_establishment_status);
10632
10633 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10634 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10635 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10636 adapter->dad |= rsp->dad_detected;
10637 adapter->con_status = rsp->connect_status;
10638
10639 spin_lock(&hdd_context_lock);
10640 context = &hdd_ctx->nud_stats_context;
10641 complete(&context->response_event);
10642 spin_unlock(&hdd_context_lock);
10643
10644 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010645}
10646
10647/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010648 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010649 * @hdd_ctx: HDD context
10650 *
10651 * Register the HDD callbacks to CDS/SME.
10652 *
10653 * Return: 0 for success or Error code for failure
10654 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010655int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010656{
10657 QDF_STATUS status;
10658 int ret = 0;
10659
10660 ENTER();
10661
10662 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10663
10664 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10665 hdd_send_oem_data_rsp_msg);
10666
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010667 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10668 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010669 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10670 sme_nan_register_callback(hdd_ctx->hHal,
10671 wlan_hdd_cfg80211_nan_callback);
10672 sme_stats_ext_register_callback(hdd_ctx->hHal,
10673 wlan_hdd_cfg80211_stats_ext_callback);
10674
10675 sme_ext_scan_register_callback(hdd_ctx->hHal,
10676 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010677 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10678 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010679
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010680 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10681 hdd_rssi_threshold_breached);
10682
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010683 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10684
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010685 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10686 wlan_hdd_cfg80211_link_layer_stats_callback);
10687
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010688 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10689
Zhang Qianca38fb12016-12-23 11:10:48 +080010690 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10691 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10692
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010693 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10694 hdd_lost_link_info_cb);
10695 /* print error and not block the startup process */
10696 if (!QDF_IS_STATUS_SUCCESS(status))
10697 hdd_err("set lost link info callback failed");
10698
Poddar, Siddarth34872782017-08-10 14:08:51 +053010699 ret = hdd_register_data_stall_detect_cb();
10700 if (ret) {
10701 hdd_err("Register data stall detect detect callback failed.");
10702 return ret;
10703 }
10704
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010705 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10706
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010707 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010708 hdd_set_connection_in_progress,
10709 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010710
10711 status = sme_congestion_register_callback(hdd_ctx->hHal,
10712 hdd_update_cca_info_cb);
10713 if (!QDF_IS_STATUS_SUCCESS(status))
10714 hdd_err("set congestion callback failed");
10715
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010716 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10717 hdd_bt_activity_cb);
10718 if (!QDF_IS_STATUS_SUCCESS(status))
10719 hdd_err("set bt activity info callback failed");
10720
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010721 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10722 hdd_tx_queue_cb);
10723 if (!QDF_IS_STATUS_SUCCESS(status))
10724 hdd_err("Register tx queue callback failed");
10725
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010726 EXIT();
10727
10728 return ret;
10729}
10730
10731/**
10732 * hdd_deregister_cb() - De-Register HDD callbacks.
10733 * @hdd_ctx: HDD context
10734 *
10735 * De-Register the HDD callbacks to CDS/SME.
10736 *
10737 * Return: void
10738 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010739void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010740{
10741 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010742 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010743
10744 ENTER();
10745
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010746 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010747 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10748 if (!QDF_IS_STATUS_SUCCESS(status))
10749 hdd_err("De-register of dcc stats callback failed: %d",
10750 status);
10751
10752 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010753 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10754
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010755 sme_stats_ext_register_callback(hdd_ctx->hHal,
10756 wlan_hdd_cfg80211_stats_ext_callback);
10757
10758 sme_nan_deregister_callback(hdd_ctx->hHal);
10759 status = sme_reset_tsfcb(hdd_ctx->hHal);
10760 if (!QDF_IS_STATUS_SUCCESS(status))
10761 hdd_err("Failed to de-register tsfcb the callback:%d",
10762 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010763
Poddar, Siddarth34872782017-08-10 14:08:51 +053010764 ret = hdd_deregister_data_stall_detect_cb();
10765 if (ret)
10766 hdd_err("Failed to de-register data stall detect event callback");
10767
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010768 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10769 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10770
10771 EXIT();
10772}
10773
10774/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010775 * hdd_softap_sta_deauth() - handle deauth req from HDD
10776 * @adapter: Pointer to the HDD
10777 * @enable: bool value
10778 *
10779 * This to take counter measure to handle deauth req from HDD
10780 *
10781 * Return: None
10782 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010783QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010784 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010785{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010786 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010787
10788 ENTER();
10789
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010790 /* Ignore request to deauth bcmc station */
10791 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010792 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010793
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010794 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010795 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10796 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010797
10798 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010799 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010800}
10801
10802/**
10803 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10804 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010805 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010806 *
10807 * This to take counter measure to handle deauth req from HDD
10808 *
10809 * Return: None
10810 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010811void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010812 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010813{
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010814 struct sir_peer_sta_info peer_sta_info;
10815 struct hdd_station_info *stainfo;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010816 ENTER();
10817
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010818 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010819 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010820 return;
10821
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010822 wlan_hdd_get_peer_rssi(adapter, &pDelStaParams->peerMacAddr,
10823 &peer_sta_info);
10824 stainfo = hdd_get_stainfo(adapter->cache_sta_info,
10825 pDelStaParams->peerMacAddr);
10826 if (stainfo) {
10827 stainfo->rssi = peer_sta_info.info[0].rssi;
10828 stainfo->tx_rate = peer_sta_info.info[0].tx_rate;
10829 stainfo->rx_rate = peer_sta_info.info[0].rx_rate;
Jiachao Wuf610d912018-01-23 17:47:32 +080010830 stainfo->reason_code = pDelStaParams->reason_code;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010831 }
10832
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010833 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010834 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010835}
10836
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010837/**
10838 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10839 * @hdd_ctx: HDD Context
10840 *
10841 * API to find if there is any STA or P2P-Client is connected
10842 *
10843 * Return: true if connected; false otherwise
10844 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010845QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010846{
10847 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10848}
10849
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010850/**
10851 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10852 * @adapter: HDD adapter pointer
10853 *
10854 * This function loop through each adapter and disable roaming on each STA
10855 * device mode except the input adapter.
10856 *
10857 * Note: On the input adapter roaming is not enabled yet hence no need to
10858 * disable.
10859 *
10860 * Return: None
10861 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010862void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010863{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010864 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010865 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010866
10867 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010868 hdd_ctx->config->isRoamOffloadScanEnabled &&
10869 QDF_STA_MODE == adapter->device_mode &&
10870 policy_mgr_is_sta_active_connection_exists(
10871 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010872 hdd_debug("Connect received on STA session Id(%d)",
10873 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010874 /*
10875 * Loop through adapter and disable roaming for each STA device
10876 * mode except the input adapter.
10877 */
Dustin Brown920397d2017-12-13 16:27:50 -080010878 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010879 if (QDF_STA_MODE == adapterIdx->device_mode &&
10880 adapter->session_id != adapterIdx->session_id) {
10881 hdd_debug("Disable Roaming on session Id(%d)",
10882 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010883 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10884 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010885 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010886 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010887 }
10888 }
10889}
10890
10891/**
10892 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10893 * @adapter: HDD adapter pointer
10894 *
10895 * This function loop through each adapter and enable roaming on each STA
10896 * device mode except the input adapter.
10897 * Note: On the input adapter no need to enable roaming because link got
10898 * disconnected on this.
10899 *
10900 * Return: None
10901 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010902void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010903{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010904 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010905 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010906
10907 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010908 hdd_ctx->config->isRoamOffloadScanEnabled &&
10909 QDF_STA_MODE == adapter->device_mode &&
10910 policy_mgr_is_sta_active_connection_exists(
10911 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010912 hdd_debug("Disconnect received on STA session Id(%d)",
10913 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010914 /*
10915 * Loop through adapter and enable roaming for each STA device
10916 * mode except the input adapter.
10917 */
Dustin Brown920397d2017-12-13 16:27:50 -080010918 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010919 if (QDF_STA_MODE == adapterIdx->device_mode &&
10920 adapter->session_id != adapterIdx->session_id) {
10921 hdd_debug("Enabling Roaming on session Id(%d)",
10922 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010923 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10924 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010925 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010926 REASON_CONNECT);
10927 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010928 }
10929 }
10930}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010931
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010932/**
10933 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10934 * @skb: sk buffer pointer
10935 *
10936 * Sends the bcast message to SVC multicast group with generic nl socket
10937 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10938 *
10939 * Return: None
10940 */
10941static void nl_srv_bcast_svc(struct sk_buff *skb)
10942{
10943#ifdef CNSS_GENL
10944 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10945#else
10946 nl_srv_bcast(skb);
10947#endif
10948}
10949
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010950void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010951{
10952 struct sk_buff *skb;
10953 struct nlmsghdr *nlh;
10954 tAniMsgHdr *ani_hdr;
10955 void *nl_data = NULL;
10956 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010957 struct radio_index_tlv *radio_info;
10958 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010959
10960 if (in_interrupt() || irqs_disabled() || in_atomic())
10961 flags = GFP_ATOMIC;
10962
10963 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10964
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010965 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010966 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010967
10968 nlh = (struct nlmsghdr *)skb->data;
10969 nlh->nlmsg_pid = 0; /* from kernel */
10970 nlh->nlmsg_flags = 0;
10971 nlh->nlmsg_seq = 0;
10972 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10973
10974 ani_hdr = NLMSG_DATA(nlh);
10975 ani_hdr->type = type;
10976
10977 switch (type) {
10978 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010979 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010980 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010981 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010982 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010983 ani_hdr->length = 0;
10984 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010985 break;
10986 case WLAN_SVC_WLAN_STATUS_IND:
10987 case WLAN_SVC_WLAN_VERSION_IND:
10988 case WLAN_SVC_DFS_CAC_START_IND:
10989 case WLAN_SVC_DFS_CAC_END_IND:
10990 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10991 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10992 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010993 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010994 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010995 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010996 ani_hdr->length = len;
10997 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10998 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10999 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011000 break;
11001
11002 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011003 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011004 type);
11005 kfree_skb(skb);
11006 return;
11007 }
11008
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011009 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011010 * Add radio index at the end of the svc event in TLV format
11011 * to maintain the backward compatibility with userspace
11012 * applications.
11013 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011014
11015 tlv_len = 0;
11016
11017 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11018 < WLAN_NL_MAX_PAYLOAD) {
11019 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11020 sizeof(*ani_hdr) + len);
11021 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11022 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11023 radio_info->radio = radio;
11024 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080011025 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011026 "Added radio index tlv - radio index %d",
11027 radio_info->radio);
11028 }
11029
11030 nlh->nlmsg_len += tlv_len;
11031 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11032
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011033 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011034}
11035
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011036#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11037void wlan_hdd_auto_shutdown_cb(void)
11038{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011039 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011040
11041 if (!hdd_ctx)
11042 return;
11043
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011044 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011045 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11046 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011047}
11048
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011049void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011050{
Jeff Johnson9d295242017-08-29 14:39:48 -070011051 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011052 bool ap_connected = false, sta_connected = false;
11053 tHalHandle hal_handle;
11054
11055 hal_handle = hdd_ctx->hHal;
11056 if (hal_handle == NULL)
11057 return;
11058
11059 if (hdd_ctx->config->WlanAutoShutdown == 0)
11060 return;
11061
11062 if (enable == false) {
11063 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011064 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011065 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011066 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011067 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011068 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011069 return;
11070 }
11071
11072 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011073 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11074 hdd_for_each_adapter(hdd_ctx, adapter) {
11075 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011076 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11077 conn_info.connState ==
11078 eConnectionState_Associated) {
11079 sta_connected = true;
11080 break;
11081 }
11082 }
Dustin Brown920397d2017-12-13 16:27:50 -080011083
11084 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011085 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011086 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011087 ap_connected = true;
11088 break;
11089 }
11090 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011091 }
11092 }
11093
11094 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011095 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011096 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011097 }
Jeff Johnson68755312017-02-10 11:46:55 -080011098
11099 if (sme_set_auto_shutdown_timer(hal_handle,
11100 hdd_ctx->config->WlanAutoShutdown)
11101 != QDF_STATUS_SUCCESS)
11102 hdd_err("Failed to start wlan auto shutdown timer");
11103 else
11104 hdd_notice("Auto Shutdown timer for %d seconds enabled",
11105 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011106}
11107#endif
11108
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011109struct hdd_adapter *
11110hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11111 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011112{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011113 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011114 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011115
11116 con_sap_adapter = NULL;
11117
Dustin Brown920397d2017-12-13 16:27:50 -080011118 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011119 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11120 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011121 adapter != this_sap_adapter) {
11122 if (check_start_bss) {
11123 if (test_bit(SOFTAP_BSS_STARTED,
11124 &adapter->event_flags)) {
11125 con_sap_adapter = adapter;
11126 break;
11127 }
11128 } else {
11129 con_sap_adapter = adapter;
11130 break;
11131 }
11132 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011133 }
11134
11135 return con_sap_adapter;
11136}
11137
11138#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011139static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011140{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011141 return adapter->device_mode == QDF_STA_MODE ||
11142 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011143}
11144
Jeff Johnson9d295242017-08-29 14:39:48 -070011145static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011146{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011147 return adapter->device_mode == QDF_SAP_MODE ||
11148 adapter->device_mode == QDF_P2P_GO_MODE;
11149}
11150
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011151static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011152{
Dustin Brown920397d2017-12-13 16:27:50 -080011153 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011154
Dustin Brown920397d2017-12-13 16:27:50 -080011155 hdd_for_each_adapter(hdd_ctx, adapter) {
11156 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011157 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11158 conn_info.connState == eConnectionState_Associated) {
11159 return true;
11160 }
11161
Dustin Brown920397d2017-12-13 16:27:50 -080011162 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011163 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011164 return true;
11165 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011166 }
11167
11168 return false;
11169}
11170
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011171static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011172{
11173 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011174
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011175 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011176 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011177 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011178
Dustin Brown5ec6b552017-03-31 12:11:40 -070011179 return is_running;
11180}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011181
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011182static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011183{
11184 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11185 hdd_ctx->bus_bw_timer_running = true;
11186 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11187 hdd_ctx->config->busBandwidthComputeInterval);
11188 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11189}
11190
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011191void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011192{
11193 ENTER();
11194
11195 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11196 hdd_debug("Bandwidth compute timer already started");
11197 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011198 }
11199
Dustin Brown5ec6b552017-03-31 12:11:40 -070011200 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11201
11202 EXIT();
11203}
11204
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011205void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011206{
11207 ENTER();
11208
11209 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11210 hdd_debug("Bandwidth compute timer already started");
11211 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011212 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011213
11214 if (hdd_any_adapter_is_assoc(hdd_ctx))
11215 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11216
11217 EXIT();
11218}
11219
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011220static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011221{
11222 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
11223
11224 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11225 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11226 hdd_ctx->bus_bw_timer_running = false;
11227 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11228
11229 hdd_reset_tcp_delack(hdd_ctx);
11230}
11231
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011232void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011233{
11234 ENTER();
11235
11236 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11237 hdd_debug("Bandwidth compute timer already stopped");
11238 return;
11239 }
11240
11241 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11242
11243 EXIT();
11244}
11245
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011246void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011247{
11248 ENTER();
11249
11250 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11251 hdd_debug("Bandwidth compute timer already stopped");
11252 return;
11253 }
11254
11255 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11256 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11257
11258 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011259}
11260#endif
11261
11262/**
11263 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11264 * and sta's operating channel.
11265 * @sta_adapter: Describe the first argument to foobar.
11266 * @ap_adapter: Describe the second argument to foobar.
11267 * @roam_profile: Roam profile of AP to which STA wants to connect.
11268 * @concurrent_chnl_same: If both SAP and STA channels are same then
11269 * set this flag to true else false.
11270 *
11271 * This function checks the sap's operating channel and sta's operating channel.
11272 * if both are same then it will return false else it will restart the sap in
11273 * sta's channel and return true.
11274 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011275 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011276 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011277QDF_STATUS
11278wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11279 struct hdd_adapter *ap_adapter,
11280 tCsrRoamProfile *roam_profile,
11281 tScanResultHandle *scan_cache,
11282 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011283{
Jeff Johnson87251032017-08-29 13:31:11 -070011284 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011285 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011286 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011287 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011288 *concurrent_chnl_same = true;
11289
11290 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11291 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011292 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011293 scan_cache,
11294 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011295 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011296 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011297 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011298 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011299 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011300 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011301 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011302 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011303 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011304 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011305 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011306 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011307 }
11308 }
11309 } else {
11310 /*
11311 * Lets handle worst case scenario here, Scan cache lookup is
11312 * failed so we have to stop the SAP to avoid any channel
11313 * discrepancy between SAP's channel and STA's channel.
11314 * Return the status as failure so caller function could know
11315 * that scan look up is failed.
11316 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011317 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011318 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011319 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011320 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011321}
11322
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011323/**
11324 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11325 * @ap_adapter: SAP adapter
11326 *
11327 * This function will process the stopping of sap adapter.
11328 *
11329 * Return: None
11330 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011331void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011332{
Jeff Johnson87251032017-08-29 13:31:11 -070011333 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011334 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011335 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011336 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011337
11338 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011339 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011340 return;
11341 }
11342
11343 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11344 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011345 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011346 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011347
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011348 mutex_lock(&hdd_ctx->sap_lock);
11349 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011350 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011351 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011352 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011353 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011354 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011355 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011356 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011357 qdf_stop_bss_event,
11358 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011359 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011360 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011361 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011362 return;
11363 }
11364 }
11365 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011366 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11367 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011368 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011369 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011370 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011371 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011372 }
11373 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011374}
11375
11376/**
11377 * wlan_hdd_start_sap() - this function starts bss of SAP.
11378 * @ap_adapter: SAP adapter
11379 *
11380 * This function will process the starting of sap adapter.
11381 *
11382 * Return: None
11383 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011384void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011385{
Jeff Johnson87251032017-08-29 13:31:11 -070011386 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011387 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011388 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011389 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011390 tsap_Config_t *sap_config;
11391
11392 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011393 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011394 return;
11395 }
11396
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011397 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011398 hdd_err("SoftAp role has not been enabled");
11399 return;
11400 }
11401
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011402 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11403 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11404 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011405 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011406
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011407 mutex_lock(&hdd_ctx->sap_lock);
11408 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11409 goto end;
11410
11411 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011412 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011413 goto end;
11414 }
11415
Wei Song2f76f642016-11-18 16:32:53 +080011416 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011417 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011418 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011419 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011420 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011421 goto end;
11422
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011423 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011424 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011425 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011426 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011427 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011428 goto end;
11429 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011430 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011431 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011432 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011433 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011434 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11435 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011436 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011437 mutex_unlock(&hdd_ctx->sap_lock);
11438
11439 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011440end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011441 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011442 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011443 /* SAP context and beacon cleanup will happen during driver unload
11444 * in hdd_stop_adapter
11445 */
11446 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11447
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011448}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011449
11450/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011451 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11452 * mac scan config
11453 * @status: Status of set antenna mode
11454 *
11455 * Callback on setting the dual mac configuration
11456 *
11457 * Return: None
11458 */
11459void wlan_hdd_soc_set_antenna_mode_cb(
11460 enum set_antenna_mode_status status)
11461{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011462 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011463
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011464 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011465
11466 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11467 if (0 != wlan_hdd_validate_context(hdd_ctx))
11468 return;
11469
11470 /* Signal the completion of set dual mac config */
11471 complete(&hdd_ctx->set_antenna_mode_cmpl);
11472}
11473
11474/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011475 * hdd_get_fw_version() - Get FW version
11476 * @hdd_ctx: pointer to HDD context.
11477 * @major_spid: FW version - major spid.
11478 * @minor_spid: FW version - minor spid
11479 * @ssid: FW version - ssid
11480 * @crmid: FW version - crmid
11481 *
11482 * This function is called to get the firmware build version stored
11483 * as part of the HDD context
11484 *
11485 * Return: None
11486 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011487void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011488 uint32_t *major_spid, uint32_t *minor_spid,
11489 uint32_t *siid, uint32_t *crmid)
11490{
11491 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11492 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11493 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11494 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11495}
11496
11497#ifdef QCA_CONFIG_SMP
11498/**
11499 * wlan_hdd_get_cpu() - get cpu_index
11500 *
11501 * Return: cpu_index
11502 */
11503int wlan_hdd_get_cpu(void)
11504{
11505 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011507 put_cpu();
11508 return cpu_index;
11509}
11510#endif
11511
11512/**
11513 * hdd_get_fwpath() - get framework path
11514 *
11515 * This function is used to get the string written by
11516 * userspace to start the wlan driver
11517 *
11518 * Return: string
11519 */
11520const char *hdd_get_fwpath(void)
11521{
11522 return fwpath.string;
11523}
11524
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011525static int hdd_qdf_print_init(void)
11526{
11527 int qdf_print_idx;
11528 QDF_STATUS status;
11529
11530 status = qdf_print_setup();
11531 if (status != QDF_STATUS_SUCCESS) {
11532 pr_err("qdf_print_setup failed\n");
11533 return -EINVAL;
11534 }
11535
11536 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11537
11538 if (qdf_print_idx < 0) {
11539 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11540 qdf_print_idx);
11541 return -EINVAL;
11542 }
11543
11544 qdf_set_pidx(qdf_print_idx);
11545
11546 return 0;
11547}
11548
11549static void hdd_qdf_print_deinit(void)
11550{
11551 int qdf_print_idx;
11552
11553 qdf_print_idx = qdf_get_pidx();
11554 qdf_print_ctrl_cleanup(qdf_print_idx);
11555}
11556
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011557/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011558 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011559 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011560 * This function initilizes CDS global context with the help of cds_init. This
11561 * has to be the first function called after probe to get a valid global
11562 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011563 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011564 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011565 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011566int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011567{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011568 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011569 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011570
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011571 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011572 if (QDF_IS_STATUS_ERROR(status)) {
11573 hdd_err("Failed to allocate CDS context");
11574 ret = -ENOMEM;
11575 goto err_out;
11576 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011577
11578 wlan_init_bug_report_lock();
11579
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011580#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11581 wlan_logging_sock_init_svc();
11582#endif
11583
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011584 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11585 (void *)hdd_drv_ops_inactivity_handler, NULL,
11586 QDF_TIMER_TYPE_SW);
11587
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011588 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011589 hdd_qdf_print_init();
11590
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011591 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011592
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011593err_out:
11594 return ret;
11595}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011596
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011597/**
11598 * hdd_deinit() - Deinitialize Driver
11599 *
11600 * This function frees CDS global context with the help of cds_deinit. This
11601 * has to be the last function call in remove callback to free the global
11602 * context.
11603 */
11604void hdd_deinit(void)
11605{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011606 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011607
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011608 wlan_destroy_bug_report_lock();
11609 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011610
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011611 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011612#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11613 wlan_logging_sock_deinit_svc();
11614#endif
11615}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011616
Yue Ma6e7b1a02017-04-03 14:17:46 -070011617#ifdef QCA_WIFI_NAPIER_EMULATION
11618#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11619#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011620#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011621#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011622
Sachin Ahujadddd2632017-03-07 19:07:24 +053011623static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11624 struct file *file)
11625{
11626 return 0;
11627}
11628
11629static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11630 const char __user *user_buf,
11631 size_t count,
11632 loff_t *f_pos)
11633{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011634 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011635 static const char wlan_off_str[] = "OFF";
11636 static const char wlan_on_str[] = "ON";
11637 int ret;
11638 unsigned long rc;
11639
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011640 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011641 pr_err("Failed to read buffer\n");
11642 return -EINVAL;
11643 }
11644
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011645 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011646 pr_debug("Wifi turning off from UI\n");
11647 goto exit;
11648 }
11649
Sachin Ahuja16904db2017-12-13 19:56:57 +053011650 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
11651 pr_info("Wifi Turning On from UI\n");
11652 }
11653
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011654 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011655 pr_err("Invalid value received from framework");
11656 goto exit;
11657 }
11658
11659 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011660 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011661 rc = wait_for_completion_timeout(&wlan_start_comp,
11662 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11663 if (!rc) {
11664 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11665 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053011666 return ret;
11667 }
11668
11669 hdd_start_complete(0);
11670 }
11671
11672exit:
11673 return count;
11674}
11675
11676
11677const struct file_operations wlan_hdd_state_fops = {
11678 .owner = THIS_MODULE,
11679 .open = wlan_hdd_state_ctrl_param_open,
11680 .write = wlan_hdd_state_ctrl_param_write,
11681};
11682
11683static int wlan_hdd_state_ctrl_param_create(void)
11684{
11685 unsigned int wlan_hdd_state_major = 0;
11686 int ret;
11687 struct device *dev;
11688
11689 device = MKDEV(wlan_hdd_state_major, 0);
11690
11691 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11692 if (ret) {
11693 pr_err("Failed to register qcwlanstate");
11694 goto dev_alloc_err;
11695 }
11696 wlan_hdd_state_major = MAJOR(device);
11697
11698 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11699 if (IS_ERR(class)) {
11700 pr_err("wlan_hdd_state class_create error");
11701 goto class_err;
11702 }
11703
11704 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11705 if (IS_ERR(dev)) {
11706 pr_err("wlan_hdd_statedevice_create error");
11707 goto err_class_destroy;
11708 }
11709
11710 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11711 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11712 if (ret) {
11713 pr_err("Failed to add cdev error");
11714 goto cdev_add_err;
11715 }
11716
11717 pr_info("wlan_hdd_state %s major(%d) initialized",
11718 WLAN_MODULE_NAME, wlan_hdd_state_major);
11719
11720 return 0;
11721
11722cdev_add_err:
11723 device_destroy(class, device);
11724err_class_destroy:
11725 class_destroy(class);
11726class_err:
11727 unregister_chrdev_region(device, dev_num);
11728dev_alloc_err:
11729 return -ENODEV;
11730}
11731
11732static void wlan_hdd_state_ctrl_param_destroy(void)
11733{
11734 cdev_del(&wlan_hdd_state_cdev);
11735 device_destroy(class, device);
11736 class_destroy(class);
11737 unregister_chrdev_region(device, dev_num);
11738
11739 pr_info("Device node unregistered");
11740}
11741
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011742/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011743 * component_init - API to init cld component's
11744 *
11745 * Return: None
11746 */
11747static void component_init(void)
11748{
11749 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011750 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011751 ucfg_ocb_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011752}
11753
11754/**
11755 * component_deinit - API to deinit cld component's
11756 *
11757 * Return: None
11758 */
11759static void component_deinit(void)
11760{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011761 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011762 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011763 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011764}
11765
11766void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11767{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011768 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011769 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011770}
11771
11772void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11773{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011774 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011775 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011776}
11777
11778/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011779 * __hdd_module_init - Module init helper
11780 *
11781 * Module init helper function used by both module and static driver.
11782 *
11783 * Return: 0 for success, errno on failure
11784 */
11785static int __hdd_module_init(void)
11786{
11787 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011788
Dustin Brown96cd9632017-11-13 12:45:04 -080011789 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011790 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011791 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080011792 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011793
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011794 pld_init();
11795
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011796 ret = hdd_init();
11797 if (ret) {
11798 pr_err("hdd_init failed %x\n", ret);
11799 goto err_hdd_init;
11800 }
11801
Rajeev Kumar97767a02016-11-30 11:20:40 -080011802 dispatcher_init();
11803
Mukul Sharmad75a6672017-06-22 15:40:53 +053011804 /* Ensure to call post objmgr init */
11805 component_init();
11806
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011807 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011808
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011809 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011810
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011811 ret = wlan_hdd_register_driver();
11812 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011813 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11814 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011815 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011816 }
11817
Sachin Ahuja16904db2017-12-13 19:56:57 +053011818 ret = wlan_hdd_state_ctrl_param_create();
11819 if (ret) {
11820 pr_err("wlan_hdd_state_create:%x\n", ret);
11821 goto out;
11822 }
11823
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011824 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011825
11826 return 0;
11827out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011828 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011829 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011830 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011831 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011832
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011833err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011834 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011835 return ret;
11836}
11837
11838/**
11839 * __hdd_module_exit - Module exit helper
11840 *
11841 * Module exit helper function used by both module and static driver.
11842 */
11843static void __hdd_module_exit(void)
11844{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011845
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011846 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11847 QWLAN_VERSIONSTR);
11848
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011849 hdd_wait_for_recovery_completion();
11850
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011851 wlan_hdd_unregister_driver();
11852
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011853 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011854
Mukul Sharmad75a6672017-06-22 15:40:53 +053011855 /* Ensure to call prior to objmgr deinit */
11856 component_deinit();
11857
Rajeev Kumar97767a02016-11-30 11:20:40 -080011858 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011859
11860 hdd_sysfs_destroy_version_interface();
11861
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011862 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011863 pld_deinit();
11864
Sachin Ahujadddd2632017-03-07 19:07:24 +053011865 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011866}
11867
Arun Khandavallifae92942016-08-01 13:31:08 +053011868#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011869/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011870 * wlan_boot_cb() - Wlan boot callback
11871 * @kobj: object whose directory we're creating the link in.
11872 * @attr: attribute the user is interacting with
11873 * @buff: the buffer containing the user data
11874 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011875 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011876 * This callback is invoked when the fs is ready to start the
11877 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011878 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011879 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011880 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011881static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011882 struct kobj_attribute *attr,
11883 const char *buf,
11884 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011885{
Arun Khandavallifae92942016-08-01 13:31:08 +053011886
Arun Khandavallifae92942016-08-01 13:31:08 +053011887 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011888 pr_err("%s: wlan driver already initialized\n", __func__);
11889 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011890 }
11891
Arun Khandavallifae92942016-08-01 13:31:08 +053011892 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011893 pr_err("%s: wlan driver initialization failed\n", __func__);
11894 return -EIO;
11895 }
11896
11897 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011898
11899 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011900}
Arun Khandavallifae92942016-08-01 13:31:08 +053011901
11902/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011903 * hdd_sysfs_cleanup() - cleanup sysfs
11904 *
11905 * Return: None
11906 *
11907 */
11908static void hdd_sysfs_cleanup(void)
11909{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011910 /* remove from group */
11911 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11912 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11913 wlan_loader->attr_group);
11914
11915 /* unlink the object from parent */
11916 kobject_del(wlan_loader->boot_wlan_obj);
11917
11918 /* free the object */
11919 kobject_put(wlan_loader->boot_wlan_obj);
11920
11921 kfree(wlan_loader->attr_group);
11922 kfree(wlan_loader);
11923
11924 wlan_loader = NULL;
11925}
11926
11927/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011928 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11929 * ready
11930 *
11931 * This is creates the syfs entry boot_wlan. Which shall be invoked
11932 * when the filesystem is ready.
11933 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011934 * QDF API cannot be used here since this function is called even before
11935 * initializing WLAN driver.
11936 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011937 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011938 */
11939static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011940{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011941 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011942
11943 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011944 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011945 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011946
11947 wlan_loader->boot_wlan_obj = NULL;
11948 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11949 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011950 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011951 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011952
11953 wlan_loader->loaded_state = 0;
11954 wlan_loader->attr_group->attrs = attrs;
11955
11956 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11957 kernel_kobj);
11958 if (!wlan_loader->boot_wlan_obj) {
11959 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011960 goto error_return;
11961 }
11962
11963 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11964 wlan_loader->attr_group);
11965 if (ret) {
11966 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11967 goto error_return;
11968 }
11969
11970 return 0;
11971
11972error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011973 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011974
11975 return ret;
11976}
11977
11978/**
11979 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11980 *
11981 * Return: 0 on success or errno on failure
11982 */
11983static int wlan_deinit_sysfs(void)
11984{
Arun Khandavallifae92942016-08-01 13:31:08 +053011985 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011986 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011987 return -EINVAL;
11988 }
11989
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011990 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011991 return 0;
11992}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011993
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011994#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011995
11996#ifdef MODULE
11997/**
11998 * __hdd_module_init - Module init helper
11999 *
12000 * Module init helper function used by both module and static driver.
12001 *
12002 * Return: 0 for success, errno on failure
12003 */
12004static int hdd_module_init(void)
12005{
Arun Khandavallifae92942016-08-01 13:31:08 +053012006 if (__hdd_module_init()) {
12007 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012008 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012009 }
12010
Dustin Brownab482ac2017-06-09 17:00:44 -070012011 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012012}
12013#else
12014static int __init hdd_module_init(void)
12015{
12016 int ret = -EINVAL;
12017
12018 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012019 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012020 pr_err("Failed to create sysfs entry for loading wlan");
12021
12022 return ret;
12023}
12024#endif
12025
12026
12027#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012028/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012029 * hdd_module_exit() - Exit function
12030 *
12031 * This is the driver exit point (invoked when module is unloaded using rmmod)
12032 *
12033 * Return: None
12034 */
12035static void __exit hdd_module_exit(void)
12036{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012037 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012038}
Arun Khandavallifae92942016-08-01 13:31:08 +053012039#else
12040static void __exit hdd_module_exit(void)
12041{
12042 __hdd_module_exit();
12043 wlan_deinit_sysfs();
12044}
12045#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012046
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012047static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
12048{
12049 return param_set_copystring(kmessage, kp);
12050}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012051
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012052/**
12053 * is_con_mode_valid() check con mode is valid or not
12054 * @mode: global con mode
12055 *
12056 * Return: TRUE on success FALSE on failure
12057 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012058static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012059{
12060 switch (mode) {
12061 case QDF_GLOBAL_MONITOR_MODE:
12062 case QDF_GLOBAL_FTM_MODE:
12063 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012064 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012065 return true;
12066 default:
12067 return false;
12068 }
12069}
12070
12071/**
12072 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12073 * @mode: global con mode
12074 *
12075 * Return: adapter mode
12076 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012077static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012078 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012079{
12080
12081 switch (mode) {
12082 case QDF_GLOBAL_MISSION_MODE:
12083 return QDF_STA_MODE;
12084 case QDF_GLOBAL_MONITOR_MODE:
12085 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012086 case QDF_GLOBAL_EPPING_MODE:
12087 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012088 case QDF_GLOBAL_FTM_MODE:
12089 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012090 case QDF_GLOBAL_QVIT_MODE:
12091 return QDF_QVIT_MODE;
12092 default:
12093 return QDF_MAX_NO_OF_MODE;
12094 }
12095}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012096
Dustin Brown27cd9942017-09-27 16:11:44 -070012097static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012098 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012099{
12100 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12101 return;
12102
12103 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012104 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012105 hdd_info("Release wakelock for monitor mode!");
12106 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12107 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12108 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012109 case QDF_GLOBAL_FTM_MODE:
12110 hdd_abort_mac_scan_all_adapters(hdd_ctx);
12111 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012112 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012113
Dustin Brown27cd9942017-09-27 16:11:44 -070012114 break;
12115 default:
12116 break;
12117 }
12118}
12119
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012120static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012121 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012122{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012123 int driver_status;
12124
12125 driver_status = hdd_ctx->driver_status;
12126
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012127 switch (curr_mode) {
12128 case QDF_GLOBAL_MISSION_MODE:
12129 case QDF_GLOBAL_MONITOR_MODE:
12130 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012131 hdd_deinit_all_adapters(hdd_ctx, false);
12132 hdd_close_all_adapters(hdd_ctx, false);
12133 break;
12134 case QDF_GLOBAL_EPPING_MODE:
12135 epping_disable();
12136 epping_close();
12137 break;
12138 default:
12139 return;
12140 }
12141}
12142
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012143static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012144 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012145{
Jeff Johnson9d295242017-08-29 14:39:48 -070012146 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012147 int ret = 0;
12148 bool rtnl_held;
12149 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12150 QDF_STATUS status;
12151
12152 if (!qdf_dev) {
12153 hdd_err("qdf device context is Null return!");
12154 return -EINVAL;
12155 }
12156
12157 rtnl_held = hdd_hold_rtnl_lock();
12158 switch (mode) {
12159 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012160 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12161 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012162 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012163 break;
12164 case QDF_GLOBAL_FTM_MODE:
12165 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12166 wlan_hdd_get_intf_addr(hdd_ctx),
12167 NET_NAME_UNKNOWN, rtnl_held);
12168 if (adapter == NULL)
12169 ret = -EINVAL;
12170 break;
12171 case QDF_GLOBAL_MONITOR_MODE:
12172 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12173 wlan_hdd_get_intf_addr(hdd_ctx),
12174 NET_NAME_UNKNOWN, rtnl_held);
12175 if (adapter == NULL)
12176 ret = -EINVAL;
12177 break;
12178 case QDF_GLOBAL_EPPING_MODE:
12179 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012180 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012181 hdd_err("Failed to open in eeping mode: %d", status);
12182 ret = -EINVAL;
12183 break;
12184 }
12185 ret = epping_enable(qdf_dev->dev);
12186 if (ret) {
12187 hdd_err("Failed to enable in epping mode : %d", ret);
12188 epping_close();
12189 }
12190 break;
12191 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012192 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012193 ret = -ENOTSUPP;
12194 break;
12195 }
12196 hdd_release_rtnl_lock();
12197 rtnl_held = false;
12198 return ret;
12199}
12200
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012201/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012202 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012203 * @kmessage: con mode name on which driver to be bring up
12204 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012205 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012206 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012207 * This function is invoked when user updates con mode using sys entry,
12208 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012209 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012210 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012211 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012212static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012213 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012214{
12215 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012216 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012217 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012218 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012219 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012220
Dustin Brownab6029b2017-05-24 13:04:19 -070012221 hdd_info("con_mode handler: %s", kmessage);
12222
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012223 ret = wlan_hdd_validate_context(hdd_ctx);
12224 if (ret)
12225 return ret;
12226
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012227 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012228 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012229
Dustin Brown20024e32018-01-03 12:34:58 -080012230 ret = kstrtoint(kmessage, 0, &new_con_mode);
12231 if (ret) {
12232 hdd_err("Failed to parse con_mode '%s'", kmessage);
12233 goto reset_flags;
12234 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012235 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012236
Dustin Brown20024e32018-01-03 12:34:58 -080012237 if (!is_con_mode_valid(new_con_mode)) {
12238 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012239 ret = -EINVAL;
12240 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012241 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012242
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012243 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012244 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012245 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012246 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012247 ret = 0;
12248 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012249 }
12250
Dustin Brown27cd9942017-09-27 16:11:44 -070012251 /* ensure adapters are stopped */
12252 hdd_stop_present_mode(hdd_ctx, curr_mode);
12253
Frank Liu6666f832018-01-04 10:06:05 +080012254 /* Cleanup present mode before switching to new mode */
12255 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12256
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012257 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012258 if (ret) {
12259 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012260 goto reset_flags;
12261 }
12262
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012263
Dustin Brown20024e32018-01-03 12:34:58 -080012264 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012265
Frank Liu6666f832018-01-04 10:06:05 +080012266 /*
12267 * Set ACTIVE domain before adapters created, otherwise check domain
12268 * match will fail when cleanup adapters.
12269 */
12270 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012271 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012272 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012273 if (ret) {
12274 hdd_err("Failed to register for new mode");
12275 goto reset_flags;
12276 }
12277
Dustin Brown20024e32018-01-03 12:34:58 -080012278 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012279 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12280 hdd_err("invalid adapter");
12281 ret = -EINVAL;
12282 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012283 }
12284
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012285 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012286 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012287 hdd_err("Failed to get adapter:%d", adapter_mode);
12288 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012289 }
12290
12291 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12292 if (ret) {
12293 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012294 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012295 }
12296
Dustin Brown20024e32018-01-03 12:34:58 -080012297 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012298 if (hdd_start_adapter(adapter)) {
12299 hdd_err("Failed to start %s adapter", kmessage);
12300 ret = -EINVAL;
12301 goto reset_flags;
12302 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012303
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012304 hdd_info("Acquire wakelock for monitor mode!");
12305 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12306 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12307 }
12308
Dustin Brown20024e32018-01-03 12:34:58 -080012309 /* con_mode is a global module parameter */
12310 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012311 hdd_info("Mode successfully changed to %s", kmessage);
12312 ret = 0;
12313
12314reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012315 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012316 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012317 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012318 return ret;
12319}
12320
12321
12322static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12323{
12324 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012325 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012326
12327 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12328 ret = wlan_hdd_validate_context(hdd_ctx);
12329 if (ret)
12330 return ret;
12331
12332 cds_ssr_protect(__func__);
12333 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12334 cds_ssr_unprotect(__func__);
12335
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012336 return ret;
12337}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012338
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012339static int con_mode_handler_ftm(const char *kmessage,
12340 struct kernel_param *kp)
12341{
12342 int ret;
12343
12344 ret = param_set_int(kmessage, kp);
12345
12346 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12347 pr_err("Only FTM mode supported!");
12348 return -ENOTSUPP;
12349 }
12350
12351 hdd_set_conparam(con_mode_ftm);
12352 con_mode = con_mode_ftm;
12353
12354 return ret;
12355}
12356
Ravi Joshia307f632017-07-17 23:41:41 -070012357static int con_mode_handler_monitor(const char *kmessage,
12358 struct kernel_param *kp)
12359{
12360 int ret;
12361
12362 ret = param_set_int(kmessage, kp);
12363
12364 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12365 pr_err("Only Monitor mode supported!");
12366 return -ENOTSUPP;
12367 }
12368
12369 hdd_set_conparam(con_mode_monitor);
12370 con_mode = con_mode_monitor;
12371
12372 return ret;
12373}
12374
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012375/**
12376 * hdd_get_conparam() - driver exit point
12377 *
12378 * This is the driver exit point (invoked when module is unloaded using rmmod)
12379 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012380 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012381 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012382enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012383{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012384 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012385}
12386
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012387void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012388{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012389 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012390}
12391
Komal Seelamc11bb222016-01-27 18:57:10 +053012392/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012393 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12394 * @hdd_ctx: HDD context
12395 *
12396 * Cleans up the pre cac interface, if it exists
12397 *
12398 * Return: None
12399 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012400void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012401{
12402 uint8_t session_id;
12403 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012404 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012405
12406 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12407 if (QDF_IS_STATUS_ERROR(status)) {
12408 hdd_err("failed to get pre cac vdev id");
12409 return;
12410 }
12411
12412 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12413 if (!precac_adapter) {
12414 hdd_err("invalid pre cac adapater");
12415 return;
12416 }
12417
12418 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12419 wlan_hdd_sap_pre_cac_failure,
12420 (void *)precac_adapter);
12421 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12422
12423}
12424
12425/**
Komal Seelamec702b02016-02-24 18:42:16 +053012426 * hdd_update_ol_config - API to update ol configuration parameters
12427 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012428 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012429 * Return: void
12430 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012431static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012432{
Komal Seelamec702b02016-02-24 18:42:16 +053012433 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012434 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012435
Komal Seelamec702b02016-02-24 18:42:16 +053012436 if (!ol_ctx)
12437 return;
12438
12439 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12440 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12441 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12442 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012443 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012444
12445 ol_init_ini_config(ol_ctx, &cfg);
12446}
12447
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012448#ifdef FEATURE_RUNTIME_PM
12449/**
12450 * hdd_populate_runtime_cfg() - populate runtime configuration
12451 * @hdd_ctx: hdd context
12452 * @cfg: pointer to the configuration memory being populated
12453 *
12454 * Return: void
12455 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012456static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012457 struct hif_config_info *cfg)
12458{
12459 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12460 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12461}
12462#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012463static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012464 struct hif_config_info *cfg)
12465{
12466}
12467#endif
12468
Komal Seelamec702b02016-02-24 18:42:16 +053012469/**
12470 * hdd_update_hif_config - API to update HIF configuration parameters
12471 * @hdd_ctx: HDD Context
12472 *
12473 * Return: void
12474 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012475static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012476{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012477 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012478 struct hif_config_info cfg;
12479
12480 if (!scn)
12481 return;
12482
12483 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012484 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012485 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012486
12487 if (hdd_ctx->config->prevent_link_down)
12488 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012489}
12490
12491/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012492 * hdd_update_dp_config() - Propagate config parameters to Lithium
12493 * datapath
12494 * @hdd_ctx: HDD Context
12495 *
12496 * Return: 0 for success/errno for failure
12497 */
12498static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12499{
12500 struct cdp_config_params params;
12501 QDF_STATUS status;
12502
12503 params.tso_enable = hdd_ctx->config->tso_enable;
12504 params.lro_enable = hdd_ctx->config->lro_enable;
12505#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12506 params.tx_flow_stop_queue_threshold =
12507 hdd_ctx->config->TxFlowStopQueueThreshold;
12508 params.tx_flow_start_queue_offset =
12509 hdd_ctx->config->TxFlowStartQueueOffset;
12510#endif
12511 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12512 params.napi_enable = hdd_ctx->napi_enable;
12513 params.tcp_udp_checksumoffload =
12514 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12515
12516 status = cdp_update_config_parameters(
12517 cds_get_context(QDF_MODULE_ID_SOC),
12518 &params);
12519 if (status) {
12520 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12521 "%s: Failed to attach config parameters", __func__);
12522 return status;
12523 }
12524
12525 return 0;
12526}
12527
12528/**
Komal Seelamec702b02016-02-24 18:42:16 +053012529 * hdd_update_config() - Initialize driver per module ini parameters
12530 * @hdd_ctx: HDD Context
12531 *
12532 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012533 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012534 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012535int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012536{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012537 int ret;
12538
Komal Seelamec702b02016-02-24 18:42:16 +053012539 hdd_update_ol_config(hdd_ctx);
12540 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012541 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12542 ret = hdd_update_cds_config_ftm(hdd_ctx);
12543 else
12544 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012545 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012546
12547 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012548}
12549
Mukul Sharma9d797a02017-01-05 20:26:03 +053012550#ifdef FEATURE_WLAN_RA_FILTERING
12551/**
12552 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12553 * @psoc_cfg: pmo psoc Configuration
12554 * @hdd_ctx: Pointer to hdd context
12555 *
12556 * Return: none
12557 */
12558static inline void hdd_ra_populate_pmo_config(
12559 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012560 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012561{
12562 psoc_cfg->ra_ratelimit_interval =
12563 hdd_ctx->config->RArateLimitInterval;
12564 psoc_cfg->ra_ratelimit_enable =
12565 hdd_ctx->config->IsRArateLimitEnabled;
12566}
12567#else
12568static inline void hdd_ra_populate_pmo_config(
12569 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012570 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012571{
12572}
12573#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012574
Mukul Sharma9d797a02017-01-05 20:26:03 +053012575/**
12576 * hdd_update_pmo_config - API to update pmo configuration parameters
12577 * @hdd_ctx: HDD context
12578 *
12579 * Return: void
12580 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012581static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012582{
12583 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12584 struct pmo_psoc_cfg psoc_cfg;
12585 QDF_STATUS status;
12586
12587 /*
12588 * Value of hdd_ctx->wowEnable can be,
12589 * 0 - Disable both magic pattern match and pattern byte match.
12590 * 1 - Enable magic pattern match on all interfaces.
12591 * 2 - Enable pattern byte match on all interfaces.
12592 * 3 - Enable both magic patter and pattern byte match on
12593 * all interfaces.
12594 */
12595 psoc_cfg.magic_ptrn_enable =
12596 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12597 psoc_cfg.ptrn_match_enable_all_vdev =
12598 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012599 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
Sourav Mohapatra89c85d12017-12-01 09:17:54 +053012600 wmi_service_unified_wow_capability);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012601 psoc_cfg.bpf_enable =
12602 hdd_ctx->config->bpf_packet_filter_enable;
12603 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012604 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012605 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12606 if (hdd_ctx->config->fhostNSOffload)
12607 psoc_cfg.ns_offload_enable_dynamic = true;
12608 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12609 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12610 psoc_cfg.active_mode_offload =
12611 hdd_ctx->config->active_mode_offload;
12612 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012613 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012614 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012615 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12616 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12617 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12618 psoc_cfg.power_save_mode =
12619 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012620 psoc_cfg.auto_power_save_fail_mode =
12621 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012622
12623 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012624 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12625 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012626 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012627 if (status != QDF_STATUS_SUCCESS) {
12628 hdd_err("failed pmo psoc configuration");
12629 return -EINVAL;
12630 }
12631
12632 return 0;
12633}
12634
Abhishek Singhb20db962017-03-03 21:28:46 +053012635#ifdef FEATURE_WLAN_SCAN_PNO
12636static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12637 struct hdd_config *cfg)
12638{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012639 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12640
Abhishek Singhb20db962017-03-03 21:28:46 +053012641 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12642 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12643 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12644 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12645 pno_cfg->channel_prediction_full_scan =
12646 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012647 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12648 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12649 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12650 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012651}
12652#else
12653static inline void
12654hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012655 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012656{
Abhishek Singhb20db962017-03-03 21:28:46 +053012657}
12658#endif
12659
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012660void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12661 struct hdd_config *cfg)
12662{
12663 uint8_t i = 0;
12664
12665 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12666 if (!ie_whitelist->white_list)
12667 return;
12668
12669 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12670 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12671 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12672 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12673 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12674 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12675 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12676 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12677
12678 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12679 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12680 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12681}
12682
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012683uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12684{
12685 uint8_t i, score;
12686
12687 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12688 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12689 if (score > MAX_INDEX_SCORE)
12690 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12691 MAX_INDEX_SCORE, i);
12692 }
12693
12694 return per_index_score;
12695}
12696
12697/**
12698 * hdd_update_score_config - API to update candidate scoring related params
12699 * configuration parameters
12700 * @score_config: score config to update
12701 * @cfg: config params
12702 *
12703 * Return: 0 if success else err
12704 */
12705static void hdd_update_score_config(
12706 struct scoring_config *score_config, struct hdd_config *cfg)
12707{
12708 int total_weight;
12709
12710 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12711 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12712 score_config->weight_cfg.vht_caps_weightage =
12713 cfg->vht_caps_weightage;
12714 score_config->weight_cfg.he_caps_weightage =
12715 cfg->he_caps_weightage;
12716 score_config->weight_cfg.chan_width_weightage =
12717 cfg->chan_width_weightage;
12718 score_config->weight_cfg.chan_band_weightage =
12719 cfg->chan_band_weightage;
12720 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12721 score_config->weight_cfg.beamforming_cap_weightage =
12722 cfg->beamforming_cap_weightage;
12723 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12724 score_config->weight_cfg.channel_congestion_weightage =
12725 cfg->channel_congestion_weightage;
12726 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12727
12728 total_weight = score_config->weight_cfg.rssi_weightage +
12729 score_config->weight_cfg.ht_caps_weightage +
12730 score_config->weight_cfg.vht_caps_weightage +
12731 score_config->weight_cfg.he_caps_weightage +
12732 score_config->weight_cfg.chan_width_weightage +
12733 score_config->weight_cfg.chan_band_weightage +
12734 score_config->weight_cfg.nss_weightage +
12735 score_config->weight_cfg.beamforming_cap_weightage +
12736 score_config->weight_cfg.pcl_weightage +
12737 score_config->weight_cfg.channel_congestion_weightage +
12738 score_config->weight_cfg.oce_wan_weightage;
12739
12740 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12741 hdd_err("total weight is greater than %d fallback to default values",
12742 BEST_CANDIDATE_MAX_WEIGHT);
12743
12744 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12745 score_config->weight_cfg.ht_caps_weightage =
12746 HT_CAPABILITY_WEIGHTAGE;
12747 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12748 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12749 score_config->weight_cfg.chan_width_weightage =
12750 CHAN_WIDTH_WEIGHTAGE;
12751 score_config->weight_cfg.chan_band_weightage =
12752 CHAN_BAND_WEIGHTAGE;
12753 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12754 score_config->weight_cfg.beamforming_cap_weightage =
12755 BEAMFORMING_CAP_WEIGHTAGE;
12756 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12757 score_config->weight_cfg.channel_congestion_weightage =
12758 CHANNEL_CONGESTION_WEIGHTAGE;
12759 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12760 }
12761
12762 score_config->bandwidth_weight_per_index =
12763 hdd_limit_max_per_index_score(
12764 cfg->bandwidth_weight_per_index);
12765 score_config->nss_weight_per_index =
12766 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12767 score_config->band_weight_per_index =
12768 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12769
12770 score_config->rssi_score.best_rssi_threshold =
12771 cfg->best_rssi_threshold;
12772 score_config->rssi_score.good_rssi_threshold =
12773 cfg->good_rssi_threshold;
12774 score_config->rssi_score.bad_rssi_threshold =
12775 cfg->bad_rssi_threshold;
12776 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12777 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12778 score_config->rssi_score.good_rssi_bucket_size =
12779 cfg->good_rssi_bucket_size;
12780 score_config->rssi_score.bad_rssi_bucket_size =
12781 cfg->bad_rssi_bucket_size;
12782 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12783 cfg->rssi_pref_5g_rssi_thresh;
12784
12785 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12786 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12787 hdd_limit_max_per_index_score(
12788 cfg->esp_qbss_score_slots3_to_0);
12789 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12790 hdd_limit_max_per_index_score(
12791 cfg->esp_qbss_score_slots7_to_4);
12792 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12793 hdd_limit_max_per_index_score(
12794 cfg->esp_qbss_score_slots11_to_8);
12795 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12796 hdd_limit_max_per_index_score(
12797 cfg->esp_qbss_score_slots15_to_12);
12798
12799 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12800 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12801 hdd_limit_max_per_index_score(
12802 cfg->oce_wan_score_slots3_to_0);
12803 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12804 hdd_limit_max_per_index_score(
12805 cfg->oce_wan_score_slots7_to_4);
12806 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12807 hdd_limit_max_per_index_score(
12808 cfg->oce_wan_score_slots11_to_8);
12809 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12810 hdd_limit_max_per_index_score(
12811 cfg->oce_wan_score_slots15_to_12);
12812
12813
12814 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12815 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12816 score_config->nss = cfg->enable2x2 ? 2 : 1;
12817
12818 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12819 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12820 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12821 score_config->he_cap = 1;
12822
12823 if (score_config->he_cap ||
12824 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12825 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12826 score_config->vht_cap = 1;
12827
12828 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12829 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12830 score_config->ht_cap = 1;
12831
12832 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12833 score_config->vht_24G_cap = 1;
12834
12835 if (cfg->enableTxBF)
12836 score_config->beamformee_cap = 1;
12837
12838}
12839
Abhishek Singh257a9482017-03-06 16:52:39 +053012840/**
bings81fe50a2017-11-27 14:33:26 +080012841 * hdd_update_dfs_config() - API to update dfs configuration parameters.
12842 * @hdd_ctx: HDD context
12843 *
12844 * Return: 0 if success else err
12845 */
12846static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
12847{
12848 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12849 struct hdd_config *cfg = hdd_ctx->config;
12850 struct dfs_user_config dfs_cfg;
12851 QDF_STATUS status;
12852
12853 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
12854 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
12855 if (QDF_IS_STATUS_ERROR(status)) {
12856 hdd_err("failed dfs psoc configuration");
12857 return -EINVAL;
12858 }
12859
12860 return 0;
12861}
12862
12863/**
Abhishek Singh257a9482017-03-06 16:52:39 +053012864 * hdd_update_scan_config - API to update scan configuration parameters
12865 * @hdd_ctx: HDD context
12866 *
12867 * Return: 0 if success else err
12868 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012869static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012870{
12871 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12872 struct scan_user_cfg scan_cfg;
12873 struct hdd_config *cfg = hdd_ctx->config;
12874 QDF_STATUS status;
12875
12876 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12877 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12878 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12879 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12880 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12881 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12882 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012883 /* convert to ms */
12884 scan_cfg.scan_cache_aging_time =
12885 cfg->scanAgingTimeout * 1000;
12886 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12887 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12888 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12889 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012890 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012891 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012892 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12893 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012894 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012895 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053012896 scan_cfg.sta_miracast_mcc_rest_time =
12897 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053012898
Abhishek Singhb20db962017-03-03 21:28:46 +053012899 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012900 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012901 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012902
Abhishek Singh257a9482017-03-06 16:52:39 +053012903 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12904 if (status != QDF_STATUS_SUCCESS) {
12905 hdd_err("failed pmo psoc configuration");
12906 return -EINVAL;
12907 }
12908
12909 return 0;
12910}
Abhishek Singh257a9482017-03-06 16:52:39 +053012911
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012912int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012913{
12914 int ret;
12915
12916 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012917 if (ret)
12918 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012919
Abhishek Singh257a9482017-03-06 16:52:39 +053012920 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012921 if (ret)
12922 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012923
Frank Liud4b2fa02017-03-29 11:46:48 +080012924 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012925 if (ret)
12926 return ret;
12927
12928 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080012929 if (ret)
12930 return ret;
12931
12932 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012933
12934 return ret;
12935}
12936
Agrawal Ashish65634612016-08-18 13:24:32 +053012937/**
12938 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12939 * @mode : cfg80211 DFS mode
12940 *
12941 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12942 */
12943enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12944{
12945 switch (mode) {
12946 case DFS_MODE_ENABLE:
12947 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012948 case DFS_MODE_DISABLE:
12949 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012950 case DFS_MODE_DEPRIORITIZE:
12951 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012952 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012953 hdd_debug("ACS dfs mode is NONE");
12954 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012955 }
12956}
12957
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012958/**
12959 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12960 * @hddctx: pointer to hdd context
12961 * @set_value: enable/disable
12962 *
12963 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12964 * Host(even though it is duplicate). When Host send vendor command
12965 * disable,FW doesn't perform any action. Whenever any change in
12966 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12967 *
12968 * return - 0 on success, appropriate error values on failure.
12969 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012970int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012971{
12972 QDF_STATUS status;
12973
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012974 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012975 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012976
12977 if (!hddctx->config->goptimize_chan_avoid_event) {
12978 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12979 return -EINVAL;
12980 }
12981
12982 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12983 if (!QDF_IS_STATUS_SUCCESS(status)) {
12984 hdd_err("Failed to send chan avoid command to SME");
12985 return -EINVAL;
12986 }
12987 return 0;
12988}
Agrawal Ashish65634612016-08-18 13:24:32 +053012989
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012990/**
12991 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12992 * @value: value to set
12993 *
12994 * This function will set the passed value to roaming in progress flag.
12995 *
12996 * Return: None
12997 */
12998void hdd_set_roaming_in_progress(bool value)
12999{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013000 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013001
13002 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13003 if (!hdd_ctx) {
13004 hdd_err("HDD context is NULL");
13005 return;
13006 }
13007
13008 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013009 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013010}
13011
13012/**
13013 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013014 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013015 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013016 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013017 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013018bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013019{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013020 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013021 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013022
13023 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13024 if (!hdd_ctx) {
13025 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013026 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013027 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013028 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13029 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013030 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13031 hdd_ctx->roaming_in_progress);
13032
13033 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013034}
13035
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013036/**
13037 * hdd_is_connection_in_progress() - check if connection is in
13038 * progress
13039 * @session_id: session id
13040 * @reason: scan reject reason
13041 *
13042 * Go through each adapter and check if Connection is in progress
13043 *
13044 * Return: true if connection is in progress else false
13045 */
13046bool hdd_is_connection_in_progress(uint8_t *session_id,
13047 enum scan_reject_states *reason)
13048{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013049 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013050 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013051 uint8_t sta_id = 0;
13052 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013053 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013054
13055 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13056 if (!hdd_ctx) {
13057 hdd_err("HDD context is NULL");
13058 return false;
13059 }
13060
Dustin Brown920397d2017-12-13 16:27:50 -080013061 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013062 hdd_info("Adapter with device mode %s(%d) exists",
13063 hdd_device_mode_to_string(adapter->device_mode),
13064 adapter->device_mode);
13065 if (((QDF_STA_MODE == adapter->device_mode)
13066 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13067 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13068 && (eConnectionState_Connecting ==
13069 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13070 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013071 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013072 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013073 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013074 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013075 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013076 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013077 }
13078 return true;
13079 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013080 /*
13081 * sme_neighbor_middle_of_roaming is for LFR2
13082 * hdd_is_roaming_in_progress is for LFR3
13083 */
13084 if (((QDF_STA_MODE == adapter->device_mode) &&
13085 sme_neighbor_middle_of_roaming(
13086 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013087 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013088 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013089 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013090 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013091 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013092 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013093 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013094 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013095 }
13096 return true;
13097 }
13098 if ((QDF_STA_MODE == adapter->device_mode) ||
13099 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13100 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13101 hdd_sta_ctx =
13102 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13103 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013104 hdd_sta_ctx->conn_info.connState)
13105 && sme_is_sta_key_exchange_in_progress(
13106 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013107 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013108 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013109 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013110 " is in middle of WPS/EAPOL exchange.",
13111 MAC_ADDR_ARRAY(sta_mac));
13112 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013113 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013114 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013115 }
13116 return true;
13117 }
13118 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13119 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13120 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13121 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013122 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013123 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013124 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013125 continue;
13126
13127 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013128 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013129 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013130 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013131 " of SAP/GO is in middle of WPS/EAPOL exchange",
13132 MAC_ADDR_ARRAY(sta_mac));
13133 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013134 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013135 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013136 }
13137 return true;
13138 }
13139 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013140 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013141 return true;
13142 }
13143 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013144 }
Dustin Brown920397d2017-12-13 16:27:50 -080013145
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013146 return false;
13147}
13148
13149/**
13150 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013151 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013152 *
13153 * Return: None
13154 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013155void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013156{
Jeff Johnson87251032017-08-29 13:31:11 -070013157 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013158 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013159 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013160 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013161 tsap_Config_t *sap_config;
13162 void *sap_ctx;
13163
13164 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013165 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013166 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013167
13168 mutex_lock(&hdd_ctx->sap_lock);
13169 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13170 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013171 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13172 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13173 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13174 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013175 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013176 qdf_stop_bss_event,
13177 SME_CMD_TIMEOUT_VALUE);
13178
13179 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013180 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013181 goto end;
13182 }
13183 }
13184 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013185 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013186 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013187 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013188
13189 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013190 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013191 wlansap_reset_sap_config_add_ie(sap_config,
13192 eUPDATE_IE_ALL);
13193 goto end;
13194 }
13195
13196 qdf_event_reset(&hostapd_state->qdf_event);
13197 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13198 sap_config,
13199 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013200 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013201 wlansap_reset_sap_config_add_ie(sap_config,
13202 eUPDATE_IE_ALL);
13203 goto end;
13204 }
13205
Jeff Johnson6867ec32017-09-29 20:30:20 -070013206 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013207 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013208 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013209 SME_CMD_TIMEOUT_VALUE);
13210 wlansap_reset_sap_config_add_ie(sap_config,
13211 eUPDATE_IE_ALL);
13212 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013213 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013214 goto end;
13215 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013216 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013217 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070013218 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013219 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13220 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013221 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013222 }
13223end:
13224 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013225}
13226
13227/**
13228 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13229 * with non dfs acs
13230 *
13231 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13232 *
13233 * Return: None
13234 */
13235void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13236{
Jeff Johnson9d295242017-08-29 14:39:48 -070013237 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013238 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013239 cds_context_type *cds_ctx;
13240
13241 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13242 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013243 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013244 return;
13245 }
13246
13247 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13248 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013249 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013250 return;
13251 }
13252
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013253 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13254 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013255 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013256 return;
13257 }
13258
13259 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013260 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13261 &ap_adapter->event_flags) &&
13262 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013263 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013264
Jeff Johnson6867ec32017-09-29 20:30:20 -070013265 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013266 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013267 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013268 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013269 acs_cfg.acs_mode = true;
13270
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013271 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013272 }
13273}
13274
13275/**
13276 * hdd_set_connection_in_progress() - to set the connection in
13277 * progress flag
13278 * @value: value to set
13279 *
13280 * This function will set the passed value to connection in progress flag.
13281 * If value is previously being set to true then no need to set it again.
13282 *
13283 * Return: true if value is being set correctly and false otherwise.
13284 */
13285bool hdd_set_connection_in_progress(bool value)
13286{
13287 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013288 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013289
13290 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13291 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013292 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013293 return false;
13294 }
13295
13296 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13297 /*
13298 * if the value is set to true previously and if someone is
13299 * trying to make it true again then it could be some race
13300 * condition being triggered. Avoid this situation by returning
13301 * false
13302 */
13303 if (hdd_ctx->connection_in_progress && value)
13304 status = false;
13305 else
13306 hdd_ctx->connection_in_progress = value;
13307 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13308 return status;
13309}
13310
Jeff Johnson9d295242017-08-29 14:39:48 -070013311int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013312{
13313 if (!adapter) {
13314 hdd_err("Invalid adapter");
13315 return -EINVAL;
13316 }
13317 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013318 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013319 WMA_VDEV_MCC_SET_TIME_QUOTA,
13320 set_value, VDEV_CMD);
13321 return 0;
13322
13323}
13324
Jeff Johnson9d295242017-08-29 14:39:48 -070013325int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013326{
13327 if (!adapter) {
13328 hdd_err("Invalid adapter");
13329 return -EINVAL;
13330 }
13331
13332 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013333 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013334 WMA_VDEV_MCC_SET_TIME_LATENCY,
13335 set_value, VDEV_CMD);
13336 return 0;
13337}
13338
Jeff Johnson9d295242017-08-29 14:39:48 -070013339struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013340 *psoc, uint8_t vdev_id)
13341{
Jeff Johnson9d295242017-08-29 14:39:48 -070013342 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013343 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013344
13345 /*
13346 * Currently PSOC is not being used. But this logic will
13347 * change once we have the converged implementation of
13348 * HDD context per PSOC in place. This would break if
13349 * multiple vdev objects reuse the vdev id.
13350 */
13351 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13352 if (!adapter)
13353 hdd_err("Get adapter by vdev id failed");
13354
13355 return adapter;
13356}
13357
Jeff Johnson9d295242017-08-29 14:39:48 -070013358int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013359 int8_t *rssi, int8_t *snr)
13360{
13361 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070013362 struct hdd_wext_state *wext_state =
13363 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013364 tCsrRoamProfile *profile = &wext_state->roamProfile;
13365
13366 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
13367 profile, bssid, rssi, snr);
13368 if (QDF_STATUS_SUCCESS != status) {
13369 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13370 return -EINVAL;
13371 }
13372
13373 return 0;
13374}
13375
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013376/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013377 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13378 * @adapter - HDD adapter
13379 * @tos - type of service
13380 * @status - status of the traffic
13381 *
13382 * Return: 0 on success and non zero value on failure
13383 */
13384
13385int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13386 bool is_tos_active)
13387{
13388 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013389 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013390 uint32_t max_off_chan_time = 0;
13391 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013392 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013393 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013394
13395 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13396 ret = wlan_hdd_validate_context(hdd_ctx);
13397
13398 if (ret < 0) {
13399 hdd_err("failed to set limit off chan params");
13400 return ret;
13401 }
13402
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013403 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13404
13405 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013406 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013407 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013408 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013409
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013410 if (adapter->active_ac) {
13411 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013412 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013413 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13414 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13415 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013416 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013417 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013418 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13419 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13420 PM_LATENCY);
13421 } else {
13422 /*ignore this command if only BE/BK is active */
13423 is_tos_active = false;
13424 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13425 hdd_ctx->config->conc_system_pref);
13426 }
13427 } else {
13428 /* No active tos */
13429 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13430 hdd_ctx->config->conc_system_pref);
13431 }
13432
Jeff Johnson1b780e42017-10-31 14:11:45 -070013433 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013434 is_tos_active, max_off_chan_time,
13435 hdd_ctx->config->nRestTimeConc, true);
13436 if (!QDF_IS_STATUS_SUCCESS(status)) {
13437 hdd_err("failed to set limit off chan params");
13438 ret = -EINVAL;
13439 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013440
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013441 return ret;
13442}
13443
13444/**
13445 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13446 * @adapter - HDD adapter
13447 *
13448 * Return: 0 on success and non zero value on failure
13449 */
13450int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13451{
13452 struct hdd_context *hdd_ctx;
13453 int ret;
13454 QDF_STATUS status;
13455 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13456
13457 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13458 ret = wlan_hdd_validate_context(hdd_ctx);
13459 if (ret < 0)
13460 return ret;
13461
13462 /* set the system preferece to default */
13463 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13464 hdd_ctx->config->conc_system_pref);
13465
13466 /* clear the bitmap */
13467 adapter->active_ac = 0;
13468
13469 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013470 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013471
Jeff Johnson1b780e42017-10-31 14:11:45 -070013472 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013473 false, 0, 0, false);
13474 if (!QDF_IS_STATUS_SUCCESS(status)) {
13475 hdd_err("failed to reset limit off chan params");
13476 ret = -EINVAL;
13477 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013478
13479 return ret;
13480}
13481
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013482/**
13483 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13484 * @drv_op: Enum indicating driver op
13485 *
13486 * Return: none
13487 */
13488void hdd_start_driver_ops_timer(int drv_op)
13489{
13490 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13491 switch (drv_op) {
13492 case eHDD_DRV_OP_PROBE:
13493 memcpy(drv_ops_string, "probe", sizeof("probe"));
13494 break;
13495 case eHDD_DRV_OP_REMOVE:
13496 memcpy(drv_ops_string, "remove", sizeof("remove"));
13497 break;
13498 case eHDD_DRV_OP_SHUTDOWN:
13499 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13500 break;
13501 case eHDD_DRV_OP_REINIT:
13502 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13503 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013504 case eHDD_DRV_OP_IFF_UP:
13505 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13506 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013507 }
13508
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013509 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013510 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13511 HDD_OPS_INACTIVITY_TIMEOUT);
13512}
13513
13514/**
13515 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13516 *
13517 * Return: none
13518 */
13519void hdd_stop_driver_ops_timer(void)
13520{
13521 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13522}
13523
13524/**
13525 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13526 * inactivity timer
13527 *
13528 * Return: None
13529 */
13530void hdd_drv_ops_inactivity_handler(void)
13531{
13532 hdd_err("%s: %d Sec timer expired while in .%s",
13533 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13534
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013535 if (hdd_drv_ops_task) {
13536 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13537 qdf_print_thread_trace(hdd_drv_ops_task);
13538 } else {
13539 hdd_err("hdd_drv_ops_task is null");
13540 }
13541
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013542 /* Driver shutdown is stuck, no recovery possible at this point */
13543 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13544 sizeof("shutdown")))
13545 QDF_BUG(0);
13546
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013547 if (cds_is_fw_down()) {
13548 hdd_err("FW is down");
13549 return;
13550 }
13551
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013552 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013553 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013554 else
13555 QDF_BUG(0);
13556}
13557
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013558void hdd_pld_ipa_uc_shutdown_pipes(void)
13559{
13560 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13561
13562 if (!hdd_ctx)
13563 return;
13564
13565 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13566}
13567
Yun Parkff6a16a2017-09-26 16:38:18 -070013568/**
13569 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13570 * @struct hdd_context *hdd_ctx
13571 * @struct hdd_adapter *padapter
13572 * @bool enble
13573 *
13574 * Return: none
13575 */
13576void hdd_set_rx_mode_rps(bool enable)
13577{
13578 struct cds_config_info *cds_cfg = cds_get_ini_config();
13579 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13580 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13581
13582 if (adapter && hdd_ctx &&
13583 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13584 if (enable && !cds_cfg->rps_enabled)
13585 hdd_send_rps_ind(adapter);
13586 else if (!enable && cds_cfg->rps_enabled)
13587 hdd_send_rps_disable_ind(adapter);
13588 }
13589}
13590
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013591/* Register the module init/exit functions */
13592module_init(hdd_module_init);
13593module_exit(hdd_module_exit);
13594
13595MODULE_LICENSE("Dual BSD/GPL");
13596MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13597MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13598
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013599module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13600 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013601
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013602module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13603 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13604
Ravi Joshia307f632017-07-17 23:41:41 -070013605module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13606 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13607
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013608module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13609 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13610
13611module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13612
13613module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13614
13615module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);