blob: e583c1a0d09f0cd2ac10f69da27253de3e6f7a9a [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
Sachin Ahujadddd2632017-03-07 19:07:24 +0530161int wlan_start_ret_val;
162static DECLARE_COMPLETION(wlan_start_comp);
163static unsigned int dev_num = 1;
164static struct cdev wlan_hdd_state_cdev;
165static struct class *class;
166static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530167#ifndef MODULE
168static struct gwlan_loader *wlan_loader;
169static ssize_t wlan_boot_cb(struct kobject *kobj,
170 struct kobj_attribute *attr,
171 const char *buf, size_t count);
172struct gwlan_loader {
173 bool loaded_state;
174 struct kobject *boot_wlan_obj;
175 struct attribute_group *attr_group;
176};
177
178static struct kobj_attribute wlan_boot_attribute =
179 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
180
181static struct attribute *attrs[] = {
182 &wlan_boot_attribute.attr,
183 NULL,
184};
185
186#define MODULE_INITIALIZED 1
187#endif
188
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530189#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
190#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800191#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530192
193static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800194static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530195static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
196
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800197/* the Android framework expects this param even though we don't use it */
198#define BUF_LEN 20
199static char fwpath_buffer[BUF_LEN];
200static struct kparam_string fwpath = {
201 .string = fwpath_buffer,
202 .maxlen = BUF_LEN,
203};
204
205static char *country_code;
206static int enable_11d = -1;
207static int enable_dfs_chan_scan = -1;
208
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800209/*
210 * spinlock for synchronizing asynchronous request/response
211 * (full description of use in wlan_hdd_main.h)
212 */
213DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530214DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800215
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800216#define WLAN_NLINK_CESIUM 30
217
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530218static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800219
220#define WOW_MAX_FILTER_LISTS 1
221#define WOW_MAX_FILTERS_PER_LIST 4
222#define WOW_MIN_PATTERN_SIZE 6
223#define WOW_MAX_PATTERN_SIZE 64
224
225#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
226static const struct wiphy_wowlan_support wowlan_support_reg_init = {
227 .flags = WIPHY_WOWLAN_ANY |
228 WIPHY_WOWLAN_MAGIC_PKT |
229 WIPHY_WOWLAN_DISCONNECT |
230 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
231 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
232 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
233 WIPHY_WOWLAN_4WAY_HANDSHAKE |
234 WIPHY_WOWLAN_RFKILL_RELEASE,
235 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
236 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
237 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
238};
239#endif
240
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700241static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
242 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
243 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
244 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
254 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
255 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
256 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
257 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
258 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700276 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700277 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700278 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530279 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800280 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700281};
282
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530283int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
284 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
285 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
286 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
287 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
288};
289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800290/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530291struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800292
293struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800294#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700295static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800296#endif
297
Sachin Ahujadddd2632017-03-07 19:07:24 +0530298void hdd_start_complete(int ret)
299{
300 wlan_start_ret_val = ret;
301
302 complete(&wlan_start_comp);
303}
304
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800305/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530306 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700307 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530308 *
309 * Return: none
310 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700311static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530312{
Jeff Johnson9d295242017-08-29 14:39:48 -0700313 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530314
Dustin Brown920397d2017-12-13 16:27:50 -0800315 hdd_for_each_adapter(hdd_ctx, adapter)
316 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530317}
318
319/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800320 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
321 * @vdev_id: vdev_id
322 * @action: action type
323 * @reason: reason type
324 *
325 * Return: none
326 */
327void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
328 enum netif_action_type action, enum netif_reason_type reason)
329{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700330 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700331 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800332
333 if (!hdd_ctx) {
334 hdd_err("hdd ctx is NULL");
335 return;
336 }
337 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
338
339 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800340}
341
342/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700343 * Store WLAN driver version and timestamp info in global variables such that
344 * crash debugger can extract them from driver debug symbol and crashdump for
345 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800346 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800347#ifdef BUILD_TAG
348uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
349#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800350uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700351#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800352
353/**
354 * hdd_device_mode_to_string() - return string conversion of device mode
355 * @device_mode: device mode
356 *
357 * This utility function helps log string conversion of device mode.
358 *
359 * Return: string conversion of device mode, if match found;
360 * "Unknown" otherwise.
361 */
362const char *hdd_device_mode_to_string(uint8_t device_mode)
363{
364 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800365 CASE_RETURN_STRING(QDF_STA_MODE);
366 CASE_RETURN_STRING(QDF_SAP_MODE);
367 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
368 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
369 CASE_RETURN_STRING(QDF_FTM_MODE);
370 CASE_RETURN_STRING(QDF_IBSS_MODE);
371 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
372 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700373 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800374 default:
375 return "Unknown";
376 }
377}
378
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530379/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500380 * hdd_get_valid_chan() - return current chan list from regulatory.
381 * @hdd_ctx: HDD context
382 * @chan_list: buf hold returned chan list
383 * @chan_num: input buf size and output returned chan num
384 *
385 * This function helps get current available chan list from regulatory
386 * module. It excludes the "disabled" and "invalid" channels.
387 *
388 * Return: 0 for success.
389 */
390static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
391 uint8_t *chan_list,
392 uint32_t *chan_num)
393{
394 int i = 0, j = 0;
395 struct regulatory_channel *cur_chan_list;
396 struct wlan_objmgr_pdev *pdev;
397
398 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
399 return -EINVAL;
400
401 pdev = hdd_ctx->hdd_pdev;
402 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
403 sizeof(struct regulatory_channel));
404 if (!cur_chan_list)
405 return -ENOMEM;
406
407 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
408 QDF_STATUS_SUCCESS) {
409 qdf_mem_free(cur_chan_list);
410 return -EINVAL;
411 }
412
413 for (i = 0; i < NUM_CHANNELS; i++) {
414 uint32_t ch = cur_chan_list[i].chan_num;
415 enum channel_state state = wlan_reg_get_channel_state(pdev,
416 ch);
417
418 if (state != CHANNEL_STATE_DISABLE &&
419 state != CHANNEL_STATE_INVALID &&
420 j < *chan_num) {
421 chan_list[j] = (uint8_t)ch;
422 j++;
423 }
424 }
425 *chan_num = j;
426 qdf_mem_free(cur_chan_list);
427 return 0;
428}
429
430/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530431 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
432 * @adapter: HDD adapter
433 * @chan_number: Channel number
434 * @chan_bw: Bandwidth
435 *
436 * Checks if the given bandwidth is valid for the given channel number.
437 *
438 * Return: 0 for success, non-zero for failure
439 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700440int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530441 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800442 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530443{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500444 uint8_t chan[NUM_CHANNELS];
445 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530446 bool found = false;
447 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500448 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530449
450 hal = WLAN_HDD_GET_HAL_CTX(adapter);
451 if (!hal) {
452 hdd_err("Invalid HAL context");
453 return -EINVAL;
454 }
455
Liangwei Dong17bf2662018-01-05 02:02:05 -0500456 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
457 &len);
458 if (ret) {
459 hdd_err("error %d in getting valid channel list", ret);
460 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530461 }
462
463 for (i = 0; i < len; i++) {
464 if (chan[i] == chan_number) {
465 found = true;
466 break;
467 }
468 }
469
470 if (found == false) {
471 hdd_err("Channel not in driver's valid channel list");
472 return -EOPNOTSUPP;
473 }
474
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700475 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
476 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530477 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
478 return -EINVAL;
479 }
480
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700481 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530482 if (chan_bw == CH_WIDTH_80MHZ) {
483 hdd_err("BW80 not possible in 2.4GHz band");
484 return -EINVAL;
485 }
486 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
487 (chan_bw != CH_WIDTH_MAX)) {
488 hdd_err("Only BW20 possible on channel 14");
489 return -EINVAL;
490 }
491 }
492
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700493 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530494 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
495 (chan_bw != CH_WIDTH_MAX)) {
496 hdd_err("Only BW20 possible on channel 165");
497 return -EINVAL;
498 }
499 }
500
501 return 0;
502}
503
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530504/**
505 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
506 *
507 * Block the unloading of the driver (or) interface up until the
508 * cds recovery is completed
509 *
510 * Return: true for recovery completion else false
511 */
512static bool hdd_wait_for_recovery_completion(void)
513{
514 int retry = 0;
515
516 /* Wait for recovery to complete */
517 while (cds_is_driver_recovering()) {
518 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
519 hdd_err("Recovery in progress; wait here!!!");
520 msleep(1000);
521 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
522 hdd_err("SSR never completed, error");
523 /*
524 * Trigger the bug_on in the internal builds, in the
525 * customer builds self-recovery will be enabled
526 * in those cases just return error.
527 */
528 if (cds_is_self_recovery_enabled())
529 return false;
530 QDF_BUG(0);
531 }
532 }
533
534 hdd_info("Recovery completed successfully!");
535 return true;
536}
537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800538static int __hdd_netdev_notifier_call(struct notifier_block *nb,
539 unsigned long state, void *data)
540{
541#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
542 struct netdev_notifier_info *dev_notif_info = data;
543 struct net_device *dev = dev_notif_info->dev;
544#else
545 struct net_device *dev = data;
546#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700547 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700548 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800549
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800550 ENTER_DEV(dev);
551
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800552 /* Make sure that this callback corresponds to our device. */
553 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
554 return NOTIFY_DONE;
555
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530556 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800557 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700558 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800559 return NOTIFY_DONE;
560 }
561
562 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700563 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800564 return NOTIFY_DONE;
565 }
566
567 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
568 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800569 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530570 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800571 return NOTIFY_DONE;
572 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800573
574 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
575 hdd_err("%s: Driver module is closed", __func__);
576 return NOTIFY_DONE;
577 }
578
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530579 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580 return NOTIFY_DONE;
581
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800582 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800583 dev->name, state);
584
585 switch (state) {
586 case NETDEV_REGISTER:
587 break;
588
589 case NETDEV_UNREGISTER:
590 break;
591
592 case NETDEV_UP:
593 sme_ch_avoid_update_req(hdd_ctx->hHal);
594 break;
595
596 case NETDEV_DOWN:
597 break;
598
599 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700600 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800601 complete(&adapter->linkup_event_var);
602 break;
603
604 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700605 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
606 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530607 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700608 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800609 } else {
hqueaa33ee2017-05-04 17:56:35 +0800610 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800611 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800612 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530613 /*
614 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
615 * of return status of hdd_stop call, kernel resets the IFF_UP
616 * flag after which driver does not send the cfg80211_scan_done.
617 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
618 */
619 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800620 break;
621
622 default:
623 break;
624 }
625
626 return NOTIFY_DONE;
627}
628
629/**
630 * hdd_netdev_notifier_call() - netdev notifier callback function
631 * @nb: pointer to notifier block
632 * @state: state
633 * @ndev: ndev pointer
634 *
635 * Return: 0 on success, error number otherwise.
636 */
637static int hdd_netdev_notifier_call(struct notifier_block *nb,
638 unsigned long state,
639 void *ndev)
640{
641 int ret;
642
643 cds_ssr_protect(__func__);
644 ret = __hdd_netdev_notifier_call(nb, state, ndev);
645 cds_ssr_unprotect(__func__);
646
647 return ret;
648}
649
650struct notifier_block hdd_netdev_notifier = {
651 .notifier_call = hdd_netdev_notifier_call,
652};
653
654/* variable to hold the insmod parameters */
655static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800656
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530657static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700658int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530659
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800660/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800661static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800662
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530663/**
664 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
665 * @ch_width: NL channel width
666 *
667 * Converts the NL channel width to the driver's internal representation
668 *
669 * Return: Converted channel width. In case of non matching NL channel width,
670 * CH_WIDTH_MAX will be returned.
671 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800672enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530673{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800674 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700675
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800676 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530677 switch (ch_width) {
678 case NL80211_CHAN_WIDTH_20_NOHT:
679 case NL80211_CHAN_WIDTH_20:
680 return CH_WIDTH_20MHZ;
681 case NL80211_CHAN_WIDTH_40:
682 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530683 case NL80211_CHAN_WIDTH_80:
684 return CH_WIDTH_80MHZ;
685 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800686 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
687 return CH_WIDTH_80P80MHZ;
688 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
689 return CH_WIDTH_160MHZ;
690 else
691 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530692 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800693 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
694 return CH_WIDTH_160MHZ;
695 else
696 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530697 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800698 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530699 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800700 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530701 default:
702 hdd_err("Invalid channel width %d, setting to default",
703 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800704 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530705 }
706}
707
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530708/* wlan_hdd_find_opclass() - Find operating class for a channel
709 * @hal: handler to HAL
710 * @channel: channel id
711 * @bw_offset: bandwidth offset
712 *
713 * Function invokes sme api to find the operating class
714 *
715 * Return: operating class
716 */
717uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
718 uint8_t bw_offset)
719{
720 uint8_t opclass = 0;
721
722 sme_get_opclass(hal, channel, bw_offset, &opclass);
723 return opclass;
724}
725
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800726/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530727 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530728 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800729 * @bitmask: Bitmask of log levels to be enabled
730 *
731 * Called immediately after the cfg.ini is read in order to configure
732 * the desired trace levels.
733 *
734 * Return: None
735 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530736int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800737{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530738 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530739 int qdf_print_idx = -1;
740 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741 /*
742 * if the bitmask is the default value, then a bitmask was not
743 * specified in cfg.ini, so leave the logging level alone (it
744 * will remain at the "compiled in" default value)
745 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700746 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530747 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800748
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530749 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800750
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530751 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530752 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530753 QDF_TRACE_LEVEL_NONE, 0);
754
755 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530756 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800757 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530758 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759 while (0 != bitmask) {
760 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530761 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530762 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530763 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530764 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767 level++;
768 bitmask >>= 1;
769 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530770 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771}
772
773/**
Chris Guo1751acf2017-07-03 14:09:01 +0800774 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
775 * @hdd_ctx: HDD context pointer
776 *
777 * Return: 0 if the context is valid. Error code otherwise
778 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700779int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800780{
781 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
782 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
783 return -ENODEV;
784 }
785
786 if (cds_is_driver_recovering()) {
787 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
788 (void *)_RET_IP_, cds_get_driver_state());
789 return -EAGAIN;
790 }
791
792 if (hdd_ctx->start_modules_in_progress ||
793 hdd_ctx->stop_modules_in_progress) {
794 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
795 (void *)_RET_IP_);
796 return -EAGAIN;
797 }
798
799 return 0;
800}
801
802
803/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800804 * wlan_hdd_validate_context() - check the HDD context
805 * @hdd_ctx: HDD context pointer
806 *
807 * Return: 0 if the context is valid. Error code otherwise
808 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700809int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800811 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530812 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800813 return -ENODEV;
814 }
815
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800816 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800817 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530818 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800819 return -EAGAIN;
820 }
821
Yue Ma9f275d92017-09-14 16:58:41 -0700822 if (cds_is_load_or_unload_in_progress()) {
823 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
824 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800825 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700826 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530827
828 if (hdd_ctx->start_modules_in_progress ||
829 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800830 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530831 (void *)_RET_IP_);
832 return -EAGAIN;
833 }
834
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530835 if (cds_is_driver_in_bad_state()) {
836 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
837 (void *)_RET_IP_, cds_get_driver_state());
838 return -ENODEV;
839 }
840
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 return 0;
842}
843
Jeff Johnson9d295242017-08-29 14:39:48 -0700844int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700845{
846 if (!adapter) {
847 hdd_err("adapter is null");
848 return -EINVAL;
849 }
850
851 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
852 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
853 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
854 return -EINVAL;
855 }
856
857 if (!adapter->dev) {
858 hdd_err("adapter net_device is null");
859 return -EINVAL;
860 }
861
862 if (!(adapter->dev->flags & IFF_UP)) {
863 hdd_info("adapter net_device is not up");
864 return -EAGAIN;
865 }
866
Jeff Johnson1b780e42017-10-31 14:11:45 -0700867 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700868 hdd_info("adapter session is not open");
869 return -EAGAIN;
870 }
871
Jeff Johnson1b780e42017-10-31 14:11:45 -0700872 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
873 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700874 return -EINVAL;
875 }
876
877 return 0;
878}
879
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800880/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530881 * wlan_hdd_validate_modules_state() - Check modules status
882 * @hdd_ctx: HDD context pointer
883 *
884 * Check's the driver module's state and returns true if the
885 * modules are enabled returns false if modules are closed.
886 *
887 * Return: True if modules are enabled or false.
888 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700889bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530890{
891 mutex_lock(&hdd_ctx->iface_change_lock);
892 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
893 mutex_unlock(&hdd_ctx->iface_change_lock);
894 hdd_notice("Modules not enabled, Present status: %d",
895 hdd_ctx->driver_status);
896 return false;
897 }
898 mutex_unlock(&hdd_ctx->iface_change_lock);
899 return true;
900}
901
902/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800903 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700904 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905 *
906 * This function sets the IBSS power save config parameters to WMA
907 * which will send it to firmware if FW supports IBSS power save
908 * before vdev start.
909 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530910 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 * on failure.
912 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700913QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914{
915 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700916 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917
918 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700919 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530920 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 }
922
Jeff Johnson1b780e42017-10-31 14:11:45 -0700923 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
925 hdd_ctx->config->ibssATIMWinSize,
926 VDEV_CMD);
927 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700928 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530929 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800930 }
931
Jeff Johnson1b780e42017-10-31 14:11:45 -0700932 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
934 hdd_ctx->config->isIbssPowerSaveAllowed,
935 VDEV_CMD);
936 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700937 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
938 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530939 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800940 }
941
Jeff Johnson1b780e42017-10-31 14:11:45 -0700942 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800943 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
944 hdd_ctx->config->
945 isIbssPowerCollapseAllowed, VDEV_CMD);
946 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700947 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
948 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530949 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 }
951
Jeff Johnson1b780e42017-10-31 14:11:45 -0700952 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800953 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
954 hdd_ctx->config->isIbssAwakeOnTxRx,
955 VDEV_CMD);
956 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700957 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530958 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959 }
960
Jeff Johnson1b780e42017-10-31 14:11:45 -0700961 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800962 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
963 hdd_ctx->config->ibssInactivityCount,
964 VDEV_CMD);
965 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700966 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530967 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 }
969
Jeff Johnson1b780e42017-10-31 14:11:45 -0700970 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
972 hdd_ctx->config->ibssTxSpEndInactivityTime,
973 VDEV_CMD);
974 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700975 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
976 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530977 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800978 }
979
Jeff Johnson1b780e42017-10-31 14:11:45 -0700980 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
982 hdd_ctx->config->ibssPsWarmupTime,
983 VDEV_CMD);
984 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700985 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
986 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530987 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988 }
989
Jeff Johnson1b780e42017-10-31 14:11:45 -0700990 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
992 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
993 VDEV_CMD);
994 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700995 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
996 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530997 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998 }
999
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301000 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001}
1002
Yue Macd359b72017-10-03 15:21:00 -07001003#ifdef FEATURE_RUNTIME_PM
1004/**
1005 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1006 * @hdd_ctx: HDD context
1007 *
1008 * Return: None
1009 */
1010static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1011{
1012 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1013
Yue Macd359b72017-10-03 15:21:00 -07001014 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001015 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001016
1017 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1018}
1019
1020/**
1021 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1022 * @hdd_ctx: HDD Context
1023 *
1024 * Return: None
1025 */
1026static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1027{
1028 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1029
Yue Macd359b72017-10-03 15:21:00 -07001030 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001031 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001032
1033 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1034}
1035
Yue Macd359b72017-10-03 15:21:00 -07001036#else /* FEATURE_RUNTIME_PM */
1037static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1038static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001039#endif /* FEATURE_RUNTIME_PM */
1040
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001041#define INTF_MACADDR_MASK 0x7
1042
1043/**
1044 * hdd_update_macaddr() - update mac address
1045 * @config: hdd configuration
1046 * @hw_macaddr: mac address
1047 *
1048 * Mac address for multiple virtual interface is found as following
1049 * i) The mac address of the first interface is just the actual hw mac address.
1050 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1051 * define the mac address for the remaining interfaces and locally
1052 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1053 * supported virtual interfaces, right now this is 0x07 (meaning 8
1054 * interface).
1055 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1056 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1057 *
1058 * Return: None
1059 */
1060void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301061 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001062{
1063 int8_t i;
1064 uint8_t macaddr_b3, tmp_br3;
1065
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301066 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301067 QDF_MAC_ADDR_SIZE);
1068 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301069 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301070 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001071 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1072 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1073 INTF_MACADDR_MASK;
1074 macaddr_b3 += tmp_br3;
1075
1076 /* XOR-ing bit-24 of the mac address. This will give enough
1077 * mac address range before collision
1078 */
1079 macaddr_b3 ^= (1 << 7);
1080
1081 /* Set locally administered bit */
1082 config->intfMacAddr[i].bytes[0] |= 0x02;
1083 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001084 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085 MAC_ADDRESS_STR, i,
1086 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1087 }
1088}
1089
Kabilan Kannan44a58372017-12-06 18:16:11 -08001090static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1091{
1092 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1093 struct tdls_start_params tdls_cfg;
1094 struct tdls_user_config *config = &tdls_cfg.config;
1095 struct hdd_config *cfg = hdd_ctx->config;
1096 QDF_STATUS status;
1097
1098 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1099 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1100 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1101 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1102 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1103 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1104 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1105 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1106 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1107 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1108 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1109 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1110 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1111 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1112 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1113 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1114 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1115 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1116 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1117 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1118 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1119 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1120 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1121 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1122 (cfg->fEnableTDLSImplicitTrigger ?
1123 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1124 (cfg->fTDLSExternalControl ?
1125 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1126 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1127 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1128
1129 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1130 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1131 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1132 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1133 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1134 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1135 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1136 tdls_cfg.tdls_evt_cb_data = psoc;
1137 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
1138 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
1139 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
1140 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1141 tdls_cfg.tdls_wmm_cb_data = psoc;
1142 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1143 tdls_cfg.tdls_rx_cb_data = psoc;
1144 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1145
1146 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1147 if (status != QDF_STATUS_SUCCESS) {
1148 hdd_err("failed pmo psoc configuration");
1149 return -EINVAL;
1150 }
1151
1152 hdd_ctx->tdls_umac_comp_active = true;
1153 /* enable napier specific tdls data path */
1154 hdd_ctx->tdls_nap_active = true;
1155
1156 return 0;
1157}
1158
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001159static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001160 struct wma_tgt_services *cfg)
1161{
1162 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163
1164 /* Set up UAPSD */
1165 config->apUapsdEnabled &= cfg->uapsd;
1166
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001167 /* 11AX mode support */
1168 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1169 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1170 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1171
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172 /* 11AC mode support */
1173 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1174 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1175 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001176
1177 /* ARP offload: override user setting if invalid */
1178 config->fhostArpOffload &= cfg->arp_offload;
1179
1180#ifdef FEATURE_WLAN_SCAN_PNO
1181 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001182 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001183 if (cfg->pno_offload)
1184 config->PnoOffload = true;
1185#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001186#ifdef FEATURE_WLAN_TDLS
1187 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301188 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1189 cfg->en_tdls_offchan;
1190 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1191 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001192 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001194 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001196#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001197#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1198 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1199#endif
Will Huang496b36c2017-07-11 16:38:50 +08001200 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001201 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001202 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001203 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204
1205}
1206
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001207/**
1208 * hdd_update_vdev_nss() - sets the vdev nss
1209 * @hdd_ctx: HDD context
1210 *
1211 * Sets the Nss per vdev type based on INI
1212 *
1213 * Return: None
1214 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001215static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001216{
1217 struct hdd_config *cfg_ini = hdd_ctx->config;
1218 uint8_t max_supp_nss = 1;
1219
Naveen Rawat10b1c152017-01-18 11:16:06 -08001220 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001221 max_supp_nss = 2;
1222
1223 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001224 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001225
1226 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001227 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001228}
1229
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301230/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301231 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1232 * @hdd_ctx: HDD context
1233 *
1234 * Updates wiphy vhtcap fields
1235 *
1236 * Return: None
1237 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001238static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301239{
1240 struct ieee80211_supported_band *band_5g =
1241 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1242 uint32_t val;
1243
1244 if (!band_5g) {
1245 hdd_debug("5GHz band disabled, skipping capability population");
1246 return;
1247 }
1248
1249 val = hdd_ctx->config->txBFCsnValue;
1250 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1251
1252 val = NUM_OF_SOUNDING_DIMENSIONS;
1253 band_5g->vht_cap.cap |=
1254 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1255
1256 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1257 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1258}
1259
1260/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301261 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1262 * @hdd_ctx: HDD context
1263 *
1264 * Sets the DBS capability as per INI and firmware capability
1265 *
1266 * Return: None
1267 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001268static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301269{
1270 struct hdd_config *cfg_ini = hdd_ctx->config;
1271 uint8_t hw_dbs_capable = 0;
1272
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001273 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1274 ((cfg_ini->dual_mac_feature_disable ==
1275 ENABLE_DBS_CXN_AND_SCAN) ||
1276 (cfg_ini->dual_mac_feature_disable ==
1277 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301278 hw_dbs_capable = 1;
1279
1280 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1281}
1282
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001283static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001284 struct wma_tgt_ht_cap *cfg)
1285{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301286 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001287 uint32_t value, val32;
1288 uint16_t val16;
1289 struct hdd_config *pconfig = hdd_ctx->config;
1290 tSirMacHTCapabilityInfo *phtCapInfo;
1291 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1292 uint8_t enable_tx_stbc;
1293
1294 /* check and update RX STBC */
1295 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1296 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1297
1298 /* get the MPDU density */
1299 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1300
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301301 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001302 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001303 value = 0;
1304 }
1305
1306 /*
1307 * MPDU density:
1308 * override user's setting if value is larger
1309 * than the one supported by target
1310 */
1311 if (value > cfg->mpdu_density) {
1312 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1313 cfg->mpdu_density);
1314
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301315 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001316 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001317 }
1318
1319 /* get the HT capability info */
1320 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301321 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001322 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 return;
1324 }
1325 val16 = (uint16_t) val32;
1326 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1327
1328 /* Set the LDPC capability */
1329 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1330
1331 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1332 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1333
1334 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1335 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1336
1337 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1338 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1339
1340 enable_tx_stbc = pconfig->enableTxSTBC;
1341
1342 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1343 pconfig->enable2x2 = 1;
1344 } else {
1345 pconfig->enable2x2 = 0;
1346 enable_tx_stbc = 0;
1347
1348 /* 1x1 */
1349 /* Update Rx Highest Long GI data Rate */
1350 if (sme_cfg_set_int(hdd_ctx->hHal,
1351 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001352 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301353 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001354 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001355 }
1356
1357 /* Update Tx Highest Long GI data Rate */
1358 if (sme_cfg_set_int
1359 (hdd_ctx->hHal,
1360 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001361 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301362 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001363 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364 }
1365 }
1366 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1367 enable_tx_stbc = 0;
1368 phtCapInfo->txSTBC = enable_tx_stbc;
1369
1370 val32 = val16;
1371 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301372 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001373 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1375 value = SIZE_OF_SUPPORTED_MCS_SET;
1376 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301377 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001378 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379
1380 if (pconfig->enable2x2) {
1381 for (value = 0; value < cfg->num_rf_chains; value++)
1382 mcs_set[value] =
1383 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1384
1385 status =
1386 sme_cfg_set_str(hdd_ctx->hHal,
1387 WNI_CFG_SUPPORTED_MCS_SET,
1388 mcs_set,
1389 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301390 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001391 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001392 }
1393 }
1394#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1395}
1396
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001397static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001398 struct wma_tgt_vht_cap *cfg)
1399{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301400 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 uint32_t value = 0;
1402 struct hdd_config *pconfig = hdd_ctx->config;
1403 struct wiphy *wiphy = hdd_ctx->wiphy;
1404 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001405 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001406 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001407 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001408 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409
Dustin Brown5e06bd32016-10-04 12:49:10 -07001410 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001411 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001412 return;
1413 }
1414
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001415 /* Get the current MPDU length */
1416 status =
1417 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1418 &value);
1419
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301420 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001421 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001422 value = 0;
1423 }
1424
1425 /*
1426 * VHT max MPDU length:
1427 * override if user configured value is too high
1428 * that the target cannot support
1429 */
1430 if (value > cfg->vht_max_mpdu) {
1431 status = sme_cfg_set_int(hdd_ctx->hHal,
1432 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1433 cfg->vht_max_mpdu);
1434
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001435 if (status == QDF_STATUS_E_FAILURE)
1436 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437 }
1438
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001439 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1440 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1441
1442 if (pconfig->enable2x2)
1443 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1444
1445 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1446 QDF_STATUS_E_FAILURE) {
1447 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1448 }
1449
1450 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1451 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1452 if (pconfig->enable2x2)
1453 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1454
1455 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1456 QDF_STATUS_E_FAILURE) {
1457 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1458 }
1459
1460 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1461 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1462 if (pconfig->enable2x2)
1463 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1464
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001465 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001466 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1467
1468 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1469 QDF_STATUS_E_FAILURE) {
1470 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1471 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001472 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001473 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001474 &value);
1475
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301476 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001477 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001478 value = 0;
1479 }
1480
jiad4a7a33c2017-08-08 15:32:24 +08001481 /* Set HW RX LDPC capability */
1482 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1483 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001484 status = sme_cfg_set_int(hdd_ctx->hHal,
1485 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001486 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001487
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001488 if (status == QDF_STATUS_E_FAILURE)
1489 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 }
1491
1492 /* Get current GI 80 value */
1493 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1494 &value);
1495
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301496 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001497 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001498 value = 0;
1499 }
1500
1501 /* set the Guard interval 80MHz */
1502 if (value && !cfg->vht_short_gi_80) {
1503 status = sme_cfg_set_int(hdd_ctx->hHal,
1504 WNI_CFG_VHT_SHORT_GI_80MHZ,
1505 cfg->vht_short_gi_80);
1506
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001507 if (status == QDF_STATUS_E_FAILURE)
1508 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001509 }
1510
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001511 /* Get VHT TX STBC cap */
1512 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1513
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301514 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001515 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516 value = 0;
1517 }
1518
1519 /* VHT TX STBC cap */
1520 if (value && !cfg->vht_tx_stbc) {
1521 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1522 cfg->vht_tx_stbc);
1523
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001524 if (status == QDF_STATUS_E_FAILURE)
1525 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526 }
1527
1528 /* Get VHT RX STBC cap */
1529 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1530
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301531 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001532 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001533 value = 0;
1534 }
1535
1536 /* VHT RX STBC cap */
1537 if (value && !cfg->vht_rx_stbc) {
1538 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1539 cfg->vht_rx_stbc);
1540
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001541 if (status == QDF_STATUS_E_FAILURE)
1542 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001543 }
1544
1545 /* Get VHT SU Beamformer cap */
1546 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1547 &value);
1548
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301549 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001550 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001551 value = 0;
1552 }
1553
1554 /* set VHT SU Beamformer cap */
1555 if (value && !cfg->vht_su_bformer) {
1556 status = sme_cfg_set_int(hdd_ctx->hHal,
1557 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1558 cfg->vht_su_bformer);
1559
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001560 if (status == QDF_STATUS_E_FAILURE)
1561 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001562 }
1563
1564 /* check and update SU BEAMFORMEE capabality */
1565 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1566 pconfig->enableTxBF = cfg->vht_su_bformee;
1567
1568 status = sme_cfg_set_int(hdd_ctx->hHal,
1569 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1570 pconfig->enableTxBF);
1571
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001572 if (status == QDF_STATUS_E_FAILURE)
1573 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001574
1575 /* Get VHT MU Beamformer cap */
1576 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1577 &value);
1578
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301579 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001580 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001581 value = 0;
1582 }
1583
1584 /* set VHT MU Beamformer cap */
1585 if (value && !cfg->vht_mu_bformer) {
1586 status = sme_cfg_set_int(hdd_ctx->hHal,
1587 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1588 cfg->vht_mu_bformer);
1589
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001590 if (status == QDF_STATUS_E_FAILURE)
1591 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001592 }
1593
1594 /* Get VHT MU Beamformee cap */
1595 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1596 &value);
1597
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301598 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001599 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 value = 0;
1601 }
1602
1603 /* set VHT MU Beamformee cap */
1604 if (value && !cfg->vht_mu_bformee) {
1605 status = sme_cfg_set_int(hdd_ctx->hHal,
1606 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1607 cfg->vht_mu_bformee);
1608
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001609 if (status == QDF_STATUS_E_FAILURE)
1610 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 }
1612
1613 /* Get VHT MAX AMPDU Len exp */
1614 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1615 &value);
1616
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301617 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001618 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619 value = 0;
1620 }
1621
1622 /*
1623 * VHT max AMPDU len exp:
1624 * override if user configured value is too high
1625 * that the target cannot support.
1626 * Even though Rome publish ampdu_len=7, it can
1627 * only support 4 because of some h/w bug.
1628 */
1629
1630 if (value > cfg->vht_max_ampdu_len_exp) {
1631 status = sme_cfg_set_int(hdd_ctx->hHal,
1632 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1633 cfg->vht_max_ampdu_len_exp);
1634
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001635 if (status == QDF_STATUS_E_FAILURE)
1636 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001637 }
1638
1639 /* Get VHT TXOP PS CAP */
1640 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1641
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301642 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001643 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644 value = 0;
1645 }
1646
1647 /* set VHT TXOP PS cap */
1648 if (value && !cfg->vht_txop_ps) {
1649 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1650 cfg->vht_txop_ps);
1651
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001652 if (status == QDF_STATUS_E_FAILURE)
1653 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001654 }
1655
1656 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1657 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1658 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1659 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1660 else
1661 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1662
1663
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001664 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1665 status = sme_cfg_set_int(hdd_ctx->hHal,
1666 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1667 VHT_CAP_160_AND_80P80_SUPP);
1668 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001669 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670 band_5g->vht_cap.cap |=
1671 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001672 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1673 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1674 status = sme_cfg_set_int(hdd_ctx->hHal,
1675 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1676 VHT_CAP_160_SUPP);
1677 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001678 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001679 band_5g->vht_cap.cap |=
1680 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001681 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1682 }
1683 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1684 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301685 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001686 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301687 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001688 &value);
1689 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301690 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001691 value = 0;
1692 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301693 /* set the Guard interval 160MHz */
1694 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001695 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301696 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1697 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001698
1699 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301700 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001701 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001702
1703 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1704 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1705
1706 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1707 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1708 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1709 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1710
1711 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1712 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1713
1714 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1715 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1716 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1717 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1718 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1719 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1720
1721 band_5g->vht_cap.cap |=
1722 (cfg->vht_max_ampdu_len_exp <<
1723 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1724
1725 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1726 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1727 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1728 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1729 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1730 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1731 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1732 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1733
1734 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1735 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1736
1737}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001739/**
1740 * hdd_generate_macaddr_auto() - Auto-generate mac address
1741 * @hdd_ctx: Pointer to the HDD context
1742 *
1743 * Auto-generate mac address using device serial number.
1744 * Keep the first 3 bytes of OUI as before and replace
1745 * the last 3 bytes with the lower 3 bytes of serial number.
1746 *
1747 * Return: 0 for success
1748 * Non zero failure code for errors
1749 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001750static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001751{
1752 unsigned int serialno = 0;
1753 struct qdf_mac_addr mac_addr = {
1754 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1755 };
1756
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001757 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001758 if (serialno == 0)
1759 return -EINVAL;
1760
1761 serialno &= 0x00ffffff;
1762
1763 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1764 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1765 mac_addr.bytes[5] = serialno & 0xff;
1766
1767 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1768 return 0;
1769}
1770
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301771/**
1772 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1773 * configuration to cfg_ini in HDD
1774 * @hdd_ctx: Pointer to hdd_ctx
1775 * @cfg: target configuration
1776 *
1777 * Return: None
1778 */
1779#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001780static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301781 struct wma_tgt_cfg *cfg)
1782{
1783 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1784}
1785#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001786static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301787 struct wma_tgt_cfg *cfg)
1788{
1789}
1790#endif
1791
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301792uint8_t hdd_check_green_ap_enable(struct hdd_context *hdd_ctx,
1793 bool *is_enabled)
1794{
1795 struct hdd_config *cfg;
1796 uint32_t concurrency_mode;
1797
1798 cfg = hdd_ctx->config;
1799 if (!cfg) {
1800 hdd_err("NULL hdd config");
1801 return -EINVAL;
1802 }
1803
1804 concurrency_mode = policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc);
1805
1806 if (cfg->enable2x2 && cfg->enableGreenAP) {
1807 if ((concurrency_mode & (1 << QDF_SAP_MODE)) &&
1808 !(concurrency_mode & (~(1 << QDF_SAP_MODE))))
1809 *is_enabled = true;
1810 }
1811 return 0;
1812}
1813
1814static int hdd_update_green_ap_config(struct hdd_context *hdd_ctx)
1815{
1816 struct green_ap_user_cfg green_ap_cfg;
1817 struct hdd_config *cfg = hdd_ctx->config;
1818 QDF_STATUS status;
1819
1820 green_ap_cfg.host_enable_egap = cfg->enable_egap;
1821 green_ap_cfg.egap_inactivity_time = cfg->egap_inact_time;
1822 green_ap_cfg.egap_wait_time = cfg->egap_wait_time;
1823 green_ap_cfg.egap_feature_flags = cfg->egap_feature_flag;
1824
1825 status = ucfg_green_ap_update_user_config(hdd_ctx->hdd_pdev,
1826 &green_ap_cfg);
1827 if (status != QDF_STATUS_SUCCESS) {
1828 hdd_err("failed to update green ap user configuration");
1829 return -EINVAL;
1830 }
1831
1832 return 0;
1833}
1834
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001835void hdd_update_tgt_cfg(void *context, void *param)
1836{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001837 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001838 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001839 struct wma_tgt_cfg *cfg = param;
1840 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001841 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301842 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001843 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301844
Dustin Brownbd68fe12017-11-21 15:28:52 -08001845 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1846 if (ret) {
1847 hdd_err("Failed to create pdev; errno:%d", ret);
1848 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001849 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001850 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001851 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001852 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1853 hdd_err("dispatcher pdev open failed");
1854 QDF_BUG(0);
1855 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301856 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001857
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301858 ret = hdd_update_green_ap_config(hdd_ctx);
1859
Naveen Rawat64e477e2016-05-20 10:34:56 -07001860 if (cds_cfg) {
1861 if (hdd_ctx->config->enable_sub_20_channel_width !=
1862 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1863 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1864 cds_cfg->sub_20_channel_width =
1865 WLAN_SUB_20_CH_WIDTH_NONE;
1866 } else {
1867 cds_cfg->sub_20_channel_width =
1868 hdd_ctx->config->enable_sub_20_channel_width;
1869 }
1870 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001871
1872 /* first store the INI band capability */
1873 temp_band_cap = hdd_ctx->config->nBandCapability;
1874
1875 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301876 hdd_ctx->is_fils_roaming_supported =
1877 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301879 hdd_ctx->config->is_11k_offload_supported =
1880 cfg->services.is_11k_offload_supported;
1881
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001882 /*
1883 * now overwrite the target band capability with INI
1884 * setting if INI setting is a subset
1885 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001886
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001887 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1888 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001889 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001890 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1891 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001892 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001893 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001894 }
1895
Amar Singhal58b45ef2017-08-01 13:43:54 -07001896 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1897
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301898 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001899 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1900 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1901 }
1902
1903 /* This can be extended to other configurations like ht, vht cap... */
1904
Anurag Chouhanc5548422016-02-24 18:33:27 +05301905 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001906 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001907 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001908 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001909 static struct qdf_mac_addr default_mac_addr = {
1910 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1911 };
1912 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1913 &default_mac_addr)) {
1914 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1915 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1916 MAC_ADDRESS_STR,
1917 MAC_ADDR_ARRAY(hdd_ctx->config->
1918 intfMacAddr[0].bytes));
1919 } else {
1920 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1921 MAC_ADDRESS_STR,
1922 MAC_ADDR_ARRAY(hdd_ctx->config->
1923 intfMacAddr[0].bytes));
1924 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001925 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001926 }
1927
1928 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001929 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930
1931 hdd_ctx->max_intf_count = cfg->max_intf_count;
1932
Jeff Johnsonc875e242016-09-23 18:12:34 -07001933 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1936 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1937
1938 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1939
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001940 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001941 if (cfg->services.en_11ax) {
1942 hdd_info("11AX: 11ax is enabled - update HDD config");
1943 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1944 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001945
1946 hdd_update_vdev_nss(hdd_ctx);
1947
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301948 hdd_update_hw_dbs_capable(hdd_ctx);
1949
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001950 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001951 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001952 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001953 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001954
Nitesh Shahe50711f2017-04-26 16:30:45 +05301955 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1956 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1957 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001958 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001959 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001960
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001961 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1962 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301963 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301964 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301965
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301966 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001967 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1968 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301969 hdd_ctx->config->txBFCsnValue =
1970 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1971
Arif Hussainee10f902017-12-27 16:30:17 -08001972 status = sme_cfg_set_int(hdd_ctx->hHal,
1973 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1974 hdd_ctx->config->txBFCsnValue);
1975 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301976 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1977
1978
1979 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001980 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1981 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301982
1983 /*
1984 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1985 */
1986 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301987
Arun Khandavallid454d422016-08-17 12:47:05 +05301988 /*
1989 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1990 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1991 * configure the STA mode wow pattern.
1992 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301993 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301994 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301995
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301996 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1997
Yue Macd359b72017-10-03 15:21:00 -07001998 /*
1999 * This needs to be done after HDD pdev is created and stored since
2000 * it will access the HDD pdev object lock.
2001 */
2002 hdd_runtime_suspend_context_init(hdd_ctx);
2003
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002004 /* Configure NAN datapath features */
2005 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002006 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002007 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002008 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2009 cfg->obss_detection_offloaded);
2010 if (QDF_IS_STATUS_ERROR(status))
2011 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002012}
2013
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002014bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015{
Jeff Johnson9d295242017-08-29 14:39:48 -07002016 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002017 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002018
Jiachao Wuf610d912018-01-23 17:47:32 +08002019 if (!hdd_ctx) {
2020 hdd_info("Couldn't get hdd_ctx");
2021 return true;
2022 }
2023
2024 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002025 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002026 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302027 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002028 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029
Dustin Brown920397d2017-12-13 16:27:50 -08002030 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002031 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2032
2033 if ((QDF_SAP_MODE == adapter->device_mode ||
2034 QDF_P2P_GO_MODE == adapter->device_mode) &&
2035 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002036 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002037 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2038 true;
2039 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002040 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302041 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002042 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302043
2044 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002045}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046
2047/**
2048 * hdd_is_valid_mac_address() - validate MAC address
2049 * @pMacAddr: Pointer to the input MAC address
2050 *
2051 * This function validates whether the given MAC address is valid or not
2052 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2053 * where X is the hexa decimal digit character and separated by ':'
2054 * This algorithm works even if MAC address is not separated by ':'
2055 *
2056 * This code checks given input string mac contains exactly 12 hexadecimal
2057 * digits and a separator colon : appears in the input string only after
2058 * an even number of hex digits.
2059 *
2060 * Return: 1 for valid and 0 for invalid
2061 */
2062bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2063{
2064 int xdigit = 0;
2065 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002066
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002067 while (*pMacAddr) {
2068 if (isxdigit(*pMacAddr)) {
2069 xdigit++;
2070 } else if (':' == *pMacAddr) {
2071 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2072 break;
2073
2074 ++separator;
2075 } else {
2076 /* Invalid MAC found */
2077 return 0;
2078 }
2079 ++pMacAddr;
2080 }
2081 return xdigit == 12 && (separator == 5 || separator == 0);
2082}
2083
2084/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302085 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2086 * @dev: Handle to struct net_device to be updated.
2087 *
2088 * Return: None
2089 */
2090static void hdd_mon_mode_ether_setup(struct net_device *dev)
2091{
2092 dev->header_ops = NULL;
2093 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2094 dev->hard_header_len = ETH_HLEN;
2095 dev->mtu = ETH_DATA_LEN;
2096 dev->addr_len = ETH_ALEN;
2097 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2098 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2099 dev->priv_flags |= IFF_TX_SKB_SHARING;
2100
2101 memset(dev->broadcast, 0xFF, ETH_ALEN);
2102}
2103
2104/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002105 * __hdd__mon_open() - HDD Open function
2106 * @dev: Pointer to net_device structure
2107 *
2108 * This is called in response to ifconfig up
2109 *
2110 * Return: 0 for success; non-zero for failure
2111 */
2112static int __hdd_mon_open(struct net_device *dev)
2113{
2114 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002115 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2116 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002117
2118 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002119
2120 ret = wlan_hdd_validate_context(hdd_ctx);
2121 if (ret)
2122 return ret;
2123
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302124 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002125
2126 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2127 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2128 if (ret) {
2129 hdd_err("Failed to start WLAN modules return");
2130 return ret;
2131 }
2132 hdd_err("hdd_wlan_start_modules() successful !");
2133
2134 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2135 ret = hdd_start_adapter(adapter);
2136 if (ret) {
2137 hdd_err("Failed to start adapter :%d",
2138 adapter->device_mode);
2139 return ret;
2140 }
2141 hdd_err("hdd_start_adapters() successful !");
2142 }
2143 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2144 }
2145
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002146 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002147
2148 if (!ret)
2149 ret = hdd_enable_monitor_mode(dev);
2150
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002151 return ret;
2152}
2153
2154/**
2155 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2156 * @dev: Pointer to net_device structure
2157 *
2158 * This is called in response to ifconfig up
2159 *
2160 * Return: 0 for success; non-zero for failure
2161 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002162static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002163{
2164 int ret;
2165
2166 cds_ssr_protect(__func__);
2167 ret = __hdd_mon_open(dev);
2168 cds_ssr_unprotect(__func__);
2169
2170 return ret;
2171}
2172
2173/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302174 * hdd_start_adapter() - Wrapper function for device specific adapter
2175 * @adapter: pointer to HDD adapter
2176 *
2177 * This function is called to start the device specific adapter for
2178 * the mode passed in the adapter's device_mode.
2179 *
2180 * Return: 0 for success; non-zero for failure
2181 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002182int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302183{
2184
2185 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002186 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302187
2188 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002189 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302190
2191 switch (device_mode) {
2192 case QDF_P2P_CLIENT_MODE:
2193 case QDF_P2P_DEVICE_MODE:
2194 case QDF_OCB_MODE:
2195 case QDF_STA_MODE:
2196 case QDF_MONITOR_MODE:
2197 ret = hdd_start_station_adapter(adapter);
2198 if (ret)
2199 goto err_start_adapter;
2200 break;
2201 case QDF_P2P_GO_MODE:
2202 case QDF_SAP_MODE:
2203 ret = hdd_start_ap_adapter(adapter);
2204 if (ret)
2205 goto err_start_adapter;
2206 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302207 case QDF_IBSS_MODE:
2208 /*
2209 * For IBSS interface is initialized as part of
2210 * hdd_init_station_mode()
2211 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002212 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302213 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002214 /* vdevs are dynamically managed by firmware in FTM */
2215 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302216 default:
2217 hdd_err("Invalid session type %d", device_mode);
2218 QDF_ASSERT(0);
2219 goto err_start_adapter;
2220 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002221
Arun Khandavallifae92942016-08-01 13:31:08 +05302222 if (hdd_set_fw_params(adapter))
2223 hdd_err("Failed to set the FW params for the adapter!");
2224
2225 /*
2226 * Action frame registered in one adapter which will
2227 * applicable to all interfaces
2228 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302229 ret = wlan_hdd_cfg80211_register_frames(adapter);
2230 if (ret < 0) {
2231 hdd_err("Failed to register frames - ret %d", ret);
2232 goto err_start_adapter;
2233 }
2234
Dustin Browndb2a8be2017-12-20 11:49:56 -08002235exit_with_success:
Arun Khandavallifae92942016-08-01 13:31:08 +05302236 EXIT();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002237
Arun Khandavallifae92942016-08-01 13:31:08 +05302238 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002239
Arun Khandavallifae92942016-08-01 13:31:08 +05302240err_start_adapter:
2241 return -EINVAL;
2242}
2243
2244/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302245 * hdd_enable_power_management() - API to Enable Power Management
2246 *
2247 * API invokes Bus Interface Layer power management functionality
2248 *
2249 * Return: None
2250 */
2251static void hdd_enable_power_management(void)
2252{
2253 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2254
2255 if (!hif_ctx) {
2256 hdd_err("Bus Interface Context is Invalid");
2257 return;
2258 }
2259
2260 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2261}
2262
2263/**
2264 * hdd_disable_power_management() - API to disable Power Management
2265 *
2266 * API disable Bus Interface Layer Power management functionality
2267 *
2268 * Return: None
2269 */
2270static void hdd_disable_power_management(void)
2271{
2272 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2273
2274 if (!hif_ctx) {
2275 hdd_err("Bus Interface Context is Invalid");
2276 return;
2277 }
2278
2279 hif_disable_power_management(hif_ctx);
2280}
2281
2282/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302283 * hdd_update_hw_sw_info() - API to update the HW/SW information
2284 *
2285 * API to update the HW and SW information in the driver
2286 *
2287 * Return: None
2288 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002289static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302290{
2291 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002292 size_t target_hw_name_len;
2293 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302294
2295 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2296 if (!hif_sc) {
2297 hdd_err("HIF context is NULL");
2298 return;
2299 }
2300
2301 /*
2302 * target hw version/revision would only be retrieved after firmware
2303 * download
2304 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002305 hif_get_hw_info(hif_sc,
2306 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302307 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002308 &target_hw_name);
2309
2310 if (hdd_ctx->target_hw_name)
2311 qdf_mem_free(hdd_ctx->target_hw_name);
2312
2313 target_hw_name_len = strlen(target_hw_name) + 1;
2314 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2315 if (hdd_ctx->target_hw_name)
2316 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2317 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302318
2319 /* Get the wlan hw/fw version */
2320 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302321}
2322
2323/**
gbian62edd7e2017-03-07 13:12:13 +08002324 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2325 * @hdd_ctx: Pointer to hdd context
2326 *
2327 * Return: none
2328 */
2329static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002330hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002331{
2332 uint8_t num_entries = 0;
2333 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2334 uint8_t *tx_sched_wrr_ac;
2335 int i;
2336 cds_context_type *cds_ctx;
2337
2338 if (NULL == hdd_ctx)
2339 return;
2340
2341 if (NULL == hdd_ctx->config) {
2342 /* Do nothing if hdd_ctx is invalid */
2343 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2344 return;
2345 }
2346
2347 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2348
2349 if (!cds_ctx) {
2350 hdd_err("Invalid CDS Context");
2351 return;
2352 }
2353
2354 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2355 switch (i) {
2356 case OL_TX_WMM_AC_BE:
2357 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2358 break;
2359 case OL_TX_WMM_AC_BK:
2360 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2361 break;
2362 case OL_TX_WMM_AC_VI:
2363 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2364 break;
2365 case OL_TX_WMM_AC_VO:
2366 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2367 break;
2368 default:
2369 tx_sched_wrr_ac = NULL;
2370 break;
2371 }
2372
2373 hdd_string_to_u8_array(tx_sched_wrr_ac,
2374 tx_sched_wrr_param,
2375 &num_entries,
2376 sizeof(tx_sched_wrr_param));
2377
2378 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2379 cds_ctx->ac_specs[i].wrr_skip_weight =
2380 tx_sched_wrr_param[0];
2381 cds_ctx->ac_specs[i].credit_threshold =
2382 tx_sched_wrr_param[1];
2383 cds_ctx->ac_specs[i].send_limit =
2384 tx_sched_wrr_param[2];
2385 cds_ctx->ac_specs[i].credit_reserve =
2386 tx_sched_wrr_param[3];
2387 cds_ctx->ac_specs[i].discard_weight =
2388 tx_sched_wrr_param[4];
2389 }
2390
2391 num_entries = 0;
2392 }
2393}
2394
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002395#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002396static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2397 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2398{
Jeff Johnson9d295242017-08-29 14:39:48 -07002399 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002400 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002401
2402 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2403 if (!adapter) {
2404 hdd_err("Adapter is NULL");
2405 return PM_MAX_NUM_OF_MODE;
2406 }
2407
2408 return policy_mgr_convert_device_mode_to_qdf_type(
2409 adapter->device_mode);
2410}
2411
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002412static void hdd_register_policy_manager_callback(
2413 struct wlan_objmgr_psoc *psoc)
2414{
2415 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002416
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002417 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002418 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002419 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2420 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002421 hdd_cbacks.get_mode_for_non_connected_vdev =
2422 wlan_hdd_get_mode_for_non_connected_vdev;
2423
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002424 if (QDF_STATUS_SUCCESS !=
2425 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2426 hdd_err("HDD callback registration with policy manager failed");
2427 }
2428}
2429#else
2430static void hdd_register_policy_manager_callback(
2431 struct wlan_objmgr_psoc *psoc)
2432{
2433}
2434#endif
2435
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002436static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002437{
2438 struct nan_callbacks cb_obj = {0};
2439
2440 cb_obj.ndi_open = hdd_ndi_open;
2441 cb_obj.ndi_close = hdd_ndi_close;
2442 cb_obj.ndi_start = hdd_ndi_start;
2443 cb_obj.ndi_delete = hdd_ndi_delete;
2444 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2445 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2446
Naveen Rawat37f62c82017-03-26 22:24:43 -07002447 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2448 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002449 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002450
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002451 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2452}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002453
Dustin Brown26b3d042017-12-21 11:13:27 -08002454#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002455/**
2456 * hdd_check_for_leaks() - Perform runtime memory leak checks
2457 *
2458 * This API triggers runtime memory leak detection. This feature enforces the
2459 * policy that any memory allocated at runtime must also be released at runtime.
2460 *
2461 * Allocating memory at runtime and releasing it at unload is effectively a
2462 * memory leak for configurations which never unload (e.g. LONU, statically
2463 * compiled driver). Such memory leaks are NOT false positives, and must be
2464 * fixed.
2465 *
2466 * Return: None
2467 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002468static void hdd_check_for_leaks(void)
2469{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002470 /* DO NOT REMOVE these checks; for false positives, read above first */
2471
Dustin Brown677e0862017-10-10 16:30:09 -07002472 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002473 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002474 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002475}
2476
Dustin Brown26b3d042017-12-21 11:13:27 -08002477#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2478#else
2479static inline void hdd_check_for_leaks(void) {}
2480
2481#define hdd_debug_domain_set(domain)
2482#endif /* CONFIG_LEAK_DETECTION */
2483
gbian62edd7e2017-03-07 13:12:13 +08002484/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002485 * hdd_update_country_code - Update country code
2486 * @hdd_ctx: HDD context
2487 *
2488 * Update country code based on module parameter country_code
2489 *
2490 * Return: 0 on success and errno on failure
2491 */
2492static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2493{
2494 if (!country_code)
2495 return 0;
2496
2497 return hdd_reg_set_country(hdd_ctx, country_code);
2498}
2499
2500/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302501 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2502 * @hdd_ctx: HDD context
2503 * @adapter: HDD adapter
2504 * @reinit: flag to indicate from SSR or normal path
2505 *
2506 * This function maintains the driver state machine it will be invoked from
2507 * startup, reinit and change interface. Depending on the driver state shall
2508 * perform the opening of the modules.
2509 *
2510 * Return: 0 for success; non-zero for failure
2511 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002512int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2513 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302514 bool reinit)
2515{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002516 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302517 qdf_device_t qdf_dev;
2518 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302519 bool unint = false;
2520 void *hif_ctx;
2521
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002522 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302523
2524 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2525 if (!qdf_dev) {
2526 hdd_err("QDF Device Context is Invalid return");
2527 return -EINVAL;
2528 }
2529
Dustin Brown6f427922017-09-19 12:19:00 -07002530 hdd_set_idle_ps_config(hdd_ctx, false);
2531 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302532
Dustin Brown1fe30a82017-10-03 16:13:36 -07002533 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302534 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2535 mutex_unlock(&hdd_ctx->iface_change_lock);
2536 hdd_info("Driver modules already Enabled");
2537 EXIT();
2538 return 0;
2539 }
2540
Dustin Brown1fe30a82017-10-03 16:13:36 -07002541 hdd_ctx->start_modules_in_progress = true;
2542
Arun Khandavallifae92942016-08-01 13:31:08 +05302543 switch (hdd_ctx->driver_status) {
2544 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002545 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302546 unint = true;
2547 /* Fall through dont add break here */
2548 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002549 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2550
Dustin Brown26b3d042017-12-21 11:13:27 -08002551 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002552
Arun Khandavallifae92942016-08-01 13:31:08 +05302553 if (!reinit && !unint) {
2554 ret = pld_power_on(qdf_dev->dev);
2555 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002556 hdd_err("Failed to Powerup the device; errno: %d",
2557 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302558 goto release_lock;
2559 }
2560 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002561
2562 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2563 hdd_ctx->config->enable_fw_log);
2564
Arun Khandavallifae92942016-08-01 13:31:08 +05302565 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2566 qdf_dev->bus_type,
2567 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2568 HIF_ENABLE_TYPE_PROBE);
2569 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002570 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302571 goto power_down;
2572 }
2573
2574 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302575 if (!hif_ctx) {
2576 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002577 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302578 goto power_down;
2579 }
2580
Arun Khandavallifae92942016-08-01 13:31:08 +05302581 status = ol_cds_init(qdf_dev, hif_ctx);
2582 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002583 hdd_err("No Memory to Create BMI Context; status: %d",
2584 status);
2585 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302586 goto hif_close;
2587 }
2588
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002589 ret = hdd_update_config(hdd_ctx);
2590 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002591 hdd_err("Failed to update configuration; errno: %d",
2592 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002593 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002594 }
2595
gbian62edd7e2017-03-07 13:12:13 +08002596 hdd_update_cds_ac_specs_params(hdd_ctx);
2597
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302598 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002599 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002600 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002601 ret = qdf_status_to_os_return(status);
2602 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302603 }
2604
Mukul Sharma9d797a02017-01-05 20:26:03 +05302605 /* initalize components configurations after psoc open */
2606 ret = hdd_update_components_config(hdd_ctx);
2607 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002608 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302609 ret);
2610 goto close;
2611 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002612 status = cds_dp_open(hdd_ctx->hdd_psoc);
2613 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002614 hdd_err("Failed to Open cds post open; status: %d",
2615 status);
2616 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002617 goto close;
2618 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302619
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002620 /*
2621 * NAN compoenet requires certian operations like, open adapter,
2622 * close adapter, etc. to be initiated by HDD, for those
2623 * register HDD callbacks with UMAC's NAN componenet.
2624 */
2625 hdd_nan_register_callbacks(hdd_ctx);
2626
Arun Khandavallifae92942016-08-01 13:31:08 +05302627 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2628
Jeff Johnson3a280122017-09-13 07:42:00 -07002629 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302630 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002631 hdd_err("Failed to pre-enable CDS; status: %d", status);
2632 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002633 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302634 }
2635
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002636 hdd_register_policy_manager_callback(
2637 hdd_ctx->hdd_psoc);
2638
Amar Singhal0928b192017-12-01 10:50:54 -08002639 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2640
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302641 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302642 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002643 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302644
Arun Khandavallifae92942016-08-01 13:31:08 +05302645 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002646 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302647 break;
2648 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302649
2650 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002651 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2652 if (ret) {
2653 hdd_err("HDD IPA UC reinit failed; errno: %d",
2654 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002655 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002656 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302657 }
2658
Arun Khandavallifae92942016-08-01 13:31:08 +05302659 /* Fall through dont add break here */
2660 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002661 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2662
Arun Khandavallifae92942016-08-01 13:31:08 +05302663 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002664 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002665 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002666 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302667 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302668 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2669 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002670 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302671 break;
2672 }
Dustin Browndca39692017-11-09 15:30:25 -08002673
2674 ret = hdd_configure_cds(hdd_ctx, adapter);
2675 if (ret) {
2676 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002677 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302678 }
Dustin Browndca39692017-11-09 15:30:25 -08002679
Komal Seelamf2136bb2016-09-28 18:30:44 +05302680 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002681
Arun Khandavallifae92942016-08-01 13:31:08 +05302682 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002683 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302684 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002685
Arun Khandavallifae92942016-08-01 13:31:08 +05302686 default:
2687 hdd_err("WLAN start invoked in wrong state! :%d\n",
2688 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002689 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302690 goto release_lock;
2691 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002692
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302693 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002694 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2695 ret = hdd_update_country_code(hdd_ctx);
2696 if (ret)
2697 hdd_err("Failed to update command line country code!");
2698 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302699 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002700
Arun Khandavallifae92942016-08-01 13:31:08 +05302701 EXIT();
Dustin Brown550f6d22017-12-14 15:44:01 -08002702
Arun Khandavallifae92942016-08-01 13:31:08 +05302703 return 0;
2704
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002705post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002706 cds_post_disable();
Amar Singhal410675c2018-01-10 12:14:21 -08002707 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Dustin Brownbd68fe12017-11-21 15:28:52 -08002708 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002709
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002710cds_txrx_free:
2711 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002712
Arun Khandavallifae92942016-08-01 13:31:08 +05302713close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002714 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002715 hdd_info("Wlan transition aborted (now CLOSED)");
2716
Jeff Johnsone4b14592017-09-13 14:23:33 -07002717 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302718
Dustin Brown28b17892017-10-10 13:29:38 -07002719deinit_config:
2720 cds_deinit_ini_config();
2721
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002722cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302723 ol_cds_free();
2724
2725hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002726 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2727 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302728power_down:
2729 if (!reinit && !unint)
2730 pld_power_off(qdf_dev->dev);
2731release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302732 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302733 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002734
2735 /* many adapter resources are not freed by design in SSR case */
2736 if (!reinit)
2737 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002738 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002739
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302740 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002741
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002742 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302743}
2744
Naveen Rawat910726a2017-03-06 11:42:51 -08002745#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002746static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002747{
2748 int ret = os_if_wifi_pos_register_nl();
2749
2750 if (ret)
2751 hdd_err("os_if_wifi_pos_register_nl failed");
2752
2753 return ret;
2754}
2755
2756static int hdd_deactivate_wifi_pos(void)
2757{
2758 int ret = os_if_wifi_pos_deregister_nl();
2759
2760 if (ret)
2761 hdd_err("os_if_wifi_pos_deregister_nl failed");
2762
2763 return ret;
2764}
2765
2766/**
2767 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2768 * @hdd_ctx: hdd context
2769 *
2770 * Return: status of operation
2771 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002772static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002773{
2774 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2775 struct hdd_config *cfg = hdd_ctx->config;
2776
2777 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2778 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2779 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2780 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2781 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2782 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2783 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2784 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2785}
2786#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002787static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002788{
2789 return oem_activate_service(hdd_ctx);
2790}
2791
2792static int hdd_deactivate_wifi_pos(void)
2793{
2794 return 0;
2795}
2796
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002797static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002798{
2799}
2800#endif
2801
Arun Khandavallifae92942016-08-01 13:31:08 +05302802/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803 * __hdd_open() - HDD Open function
2804 * @dev: Pointer to net_device structure
2805 *
2806 * This is called in response to ifconfig up
2807 *
2808 * Return: 0 for success; non-zero for failure
2809 */
2810static int __hdd_open(struct net_device *dev)
2811{
Jeff Johnson9d295242017-08-29 14:39:48 -07002812 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002813 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814 int ret;
2815
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002816 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302817 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002818 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002819
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302820 /* Nothing to be done if device is unloading */
2821 if (cds_is_driver_unloading()) {
2822 hdd_err("Driver is unloading can not open the hdd");
2823 return -EBUSY;
2824 }
2825
Dustin Brown01847752017-10-25 13:56:27 -07002826 if (cds_is_driver_recovering()) {
2827 hdd_err("WLAN is currently recovering; Please try again.");
2828 return -EBUSY;
2829 }
2830
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302831 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2832 hdd_err("con_mode_handler is in progress; Please try again.");
2833 return -EBUSY;
2834 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302835
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302836 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302837 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2838
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302839 /*
2840 * This scenario can be hit in cases where in the wlan driver after
2841 * registering the netdevices and there is a failure in driver
2842 * initialization. So return error gracefully because the netdevices
2843 * will be de-registered as part of the load failure.
2844 */
2845
2846 if (!cds_is_driver_loaded()) {
2847 hdd_err("Failed to start the wlan driver!!");
2848 ret = -EIO;
2849 goto err_hdd_hdd_init_deinit_lock;
2850 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302851
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002852
Arun Khandavallifae92942016-08-01 13:31:08 +05302853 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2854 if (ret) {
2855 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302856 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302857 }
2858
2859
2860 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2861 ret = hdd_start_adapter(adapter);
2862 if (ret) {
2863 hdd_err("Failed to start adapter :%d",
2864 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302865 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302866 }
2867 }
2868
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2870 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002871 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002872 /* Enable TX queues only when we are connected */
2873 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302874 WLAN_START_ALL_NETIF_QUEUE,
2875 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002876 }
2877
Naveen Rawat286def52016-09-23 15:38:02 -07002878 /* Enable carrier and transmit queues for NDI */
2879 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002880 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002881 wlan_hdd_netif_queue_control(adapter,
2882 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2883 WLAN_CONTROL_PATH);
2884 }
2885
Naveen Rawat910726a2017-03-06 11:42:51 -08002886 hdd_populate_wifi_pos_cfg(hdd_ctx);
2887
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302888err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302889 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302890 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002891 return ret;
2892}
2893
Arun Khandavallifae92942016-08-01 13:31:08 +05302894
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002895/**
2896 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2897 * @dev: Pointer to net_device structure
2898 *
2899 * This is called in response to ifconfig up
2900 *
2901 * Return: 0 for success; non-zero for failure
2902 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002903static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002904{
2905 int ret;
2906
2907 cds_ssr_protect(__func__);
2908 ret = __hdd_open(dev);
2909 cds_ssr_unprotect(__func__);
2910
2911 return ret;
2912}
2913
2914/**
2915 * __hdd_stop() - HDD stop function
2916 * @dev: Pointer to net_device structure
2917 *
2918 * This is called in response to ifconfig down
2919 *
2920 * Return: 0 for success; non-zero for failure
2921 */
2922static int __hdd_stop(struct net_device *dev)
2923{
Jeff Johnson9d295242017-08-29 14:39:48 -07002924 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002925 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 int ret;
2927
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002928 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002929
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302930 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002931 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002932
2933 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302934 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002935 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002936
2937 /* Nothing to be done if the interface is not opened */
2938 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002939 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002940 return -ENODEV;
2941 }
2942
2943 /* Make sure the interface is marked as closed */
2944 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302945
2946 hdd_debug("Disabling Auto Power save timer");
2947 sme_ps_disable_auto_ps_timer(
2948 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002949 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302950
2951 /*
2952 * Disable TX on the interface, after this hard_start_xmit() will not
2953 * be called on that interface
2954 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002955 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2956 hdd_device_mode_to_string(adapter->device_mode),
2957 adapter->device_mode);
2958
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302959 wlan_hdd_netif_queue_control(adapter,
2960 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2961 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002962
2963 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002964 * NAN data interface is different in some sense. The traffic on NDI is
2965 * bursty in nature and depends on the need to transfer. The service
2966 * layer may down the interface after the usage and up again when
2967 * required. In some sense, the NDI is expected to be available
2968 * (like SAP) iface until NDI delete request is issued by the service
2969 * layer. Skip BSS termination and adapter deletion for NAN Data
2970 * interface (NDI).
2971 */
2972 if (WLAN_HDD_IS_NDI(adapter))
2973 return 0;
2974
2975 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002976 * The interface is marked as down for outside world (aka kernel)
2977 * But the driver is pretty much alive inside. The driver needs to
2978 * tear down the existing connection on the netdev (session)
2979 * cleanup the data pipes and wait until the control plane is stabilized
2980 * for this interface. The call also needs to wait until the above
2981 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002982 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002983 * That is intentional to be able to scan if it is a STA/P2P interface
2984 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002985 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002986
2987 /* DeInit the adapter. This ensures datapath cleanup as well */
2988 hdd_deinit_adapter(hdd_ctx, adapter, true);
2989
Arun Khandavallifae92942016-08-01 13:31:08 +05302990
2991 /*
2992 * Find if any iface is up. If any iface is up then can't put device to
2993 * sleep/power save mode
2994 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302995 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002996 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07002997 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
2998 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302999 hdd_prevent_suspend_timeout(
3000 hdd_ctx->config->iface_change_wait_time,
3001 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303002 }
3003
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004 EXIT();
3005 return 0;
3006}
3007
3008/**
3009 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3010 * @dev: pointer to net_device structure
3011 *
3012 * This is called in response to ifconfig down
3013 *
3014 * Return: 0 for success and error number for failure
3015 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003016static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003017{
3018 int ret;
3019
3020 cds_ssr_protect(__func__);
3021 ret = __hdd_stop(dev);
3022 cds_ssr_unprotect(__func__);
3023
3024 return ret;
3025}
3026
3027/**
3028 * __hdd_uninit() - HDD uninit function
3029 * @dev: Pointer to net_device structure
3030 *
3031 * This is called during the netdev unregister to uninitialize all data
3032 * associated with the device
3033 *
3034 * Return: None
3035 */
3036static void __hdd_uninit(struct net_device *dev)
3037{
Jeff Johnson9d295242017-08-29 14:39:48 -07003038 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003039 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003040
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003041 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003042
3043 do {
3044 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003045 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003046 break;
3047 }
3048
Jeff Johnson399c6272017-08-30 10:51:00 -07003049 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3050 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003051 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003052 break;
3053 }
3054
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003055 if (dev != adapter->dev)
3056 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003057
Jeff Johnson399c6272017-08-30 10:51:00 -07003058 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059
3060 /* after uninit our adapter structure will no longer be valid */
3061 adapter->dev = NULL;
3062 adapter->magic = 0;
3063 } while (0);
3064
3065 EXIT();
3066}
3067
3068/**
3069 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3070 * @dev: pointer to net_device structure
3071 *
3072 * This is called during the netdev unregister to uninitialize all data
3073 * associated with the device
3074 *
3075 * Return: none
3076 */
3077static void hdd_uninit(struct net_device *dev)
3078{
3079 cds_ssr_protect(__func__);
3080 __hdd_uninit(dev);
3081 cds_ssr_unprotect(__func__);
3082}
3083
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003084static int hdd_open_cesium_nl_sock(void)
3085{
3086#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3087 struct netlink_kernel_cfg cfg = {
3088 .groups = WLAN_NLINK_MCAST_GRP_ID,
3089 .input = NULL
3090 };
3091#endif
3092 int ret = 0;
3093
3094#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3095 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3096#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3097 THIS_MODULE,
3098#endif
3099 &cfg);
3100#else
3101 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3102 WLAN_NLINK_MCAST_GRP_ID,
3103 NULL, NULL, THIS_MODULE);
3104#endif
3105
3106 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003107 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003108 ret = -ECONNREFUSED;
3109 }
3110
3111 return ret;
3112}
3113
3114static void hdd_close_cesium_nl_sock(void)
3115{
3116 if (NULL != cesium_nl_srv_sock) {
3117 netlink_kernel_release(cesium_nl_srv_sock);
3118 cesium_nl_srv_sock = NULL;
3119 }
3120}
3121
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122/**
3123 * __hdd_set_mac_address() - set the user specified mac address
3124 * @dev: Pointer to the net device.
3125 * @addr: Pointer to the sockaddr.
3126 *
3127 * This function sets the user specified mac address using
3128 * the command ifconfig wlanX hw ether <mac adress>.
3129 *
3130 * Return: 0 for success, non zero for failure
3131 */
3132static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3133{
Jeff Johnson9d295242017-08-29 14:39:48 -07003134 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003135 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003136 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303137 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138 int ret;
3139
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003140 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141
3142 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3143 ret = wlan_hdd_validate_context(hdd_ctx);
3144 if (0 != ret)
3145 return ret;
3146
Jeff Johnson1e851a12017-10-28 14:36:12 -07003147 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3149
3150 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303151 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152}
3153
3154/**
3155 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3156 * function from SSR
3157 * @dev: pointer to net_device structure
3158 * @addr: Pointer to the sockaddr
3159 *
3160 * This function sets the user specified mac address using
3161 * the command ifconfig wlanX hw ether <mac adress>.
3162 *
3163 * Return: 0 for success.
3164 */
3165static int hdd_set_mac_address(struct net_device *dev, void *addr)
3166{
3167 int ret;
3168
3169 cds_ssr_protect(__func__);
3170 ret = __hdd_set_mac_address(dev, addr);
3171 cds_ssr_unprotect(__func__);
3172
3173 return ret;
3174}
3175
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003176uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177{
3178 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003179
Anurag Chouhan6d760662016-02-20 16:05:43 +05303180 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3182 break;
3183 }
3184
Anurag Chouhan6d760662016-02-20 16:05:43 +05303185 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186 return NULL;
3187
3188 hdd_ctx->config->intfAddrMask |= (1 << i);
3189 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3190}
3191
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003192void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3193 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194{
3195 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003196
Anurag Chouhan6d760662016-02-20 16:05:43 +05303197 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198 if (!memcmp(releaseAddr,
3199 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3200 6)) {
3201 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3202 break;
3203 }
3204 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205}
3206
3207#ifdef WLAN_FEATURE_PACKET_FILTERING
3208/**
3209 * __hdd_set_multicast_list() - set the multicast address list
3210 * @dev: Pointer to the WLAN device.
3211 * @skb: Pointer to OS packet (sk_buff).
3212 *
3213 * This funciton sets the multicast address list.
3214 *
3215 * Return: None
3216 */
3217static void __hdd_set_multicast_list(struct net_device *dev)
3218{
Jeff Johnson9d295242017-08-29 14:39:48 -07003219 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220 int i = 0, status;
3221 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003222 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303223 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3224 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3225 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003226
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003227 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303228 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303229 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303232 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303233 goto out;
3234
Dustin Brownc788acb2017-08-01 17:43:51 -07003235 status = hdd_validate_adapter(adapter);
3236 if (status)
3237 goto out;
3238
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303239 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3240 hdd_err("%s: Driver module is closed", __func__);
3241 return;
3242 }
3243
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303244 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3245 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003246 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303247 goto out;
3248 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303250 /* Delete already configured multicast address list */
3251 if (adapter->mc_addr_list.mc_cnt > 0) {
3252 hdd_info("clear previously configured MC address list");
3253 hdd_disable_and_flush_mc_addr_list(adapter,
3254 pmo_mc_list_change_notify);
3255 }
3256
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003257 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003258 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303259 hdd_disable_and_flush_mc_addr_list(adapter,
3260 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261 } else {
3262 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303263 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003264 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303265 pmo_ucfg_max_mc_addr_supported(psoc));
3266 hdd_disable_and_flush_mc_addr_list(adapter,
3267 pmo_mc_list_change_notify);
3268 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003271 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303272 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273 if (i == mc_count)
3274 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303275 memset(&(mc_list_request->mc_addr[i].bytes),
3276 0, ETH_ALEN);
3277 memcpy(&(mc_list_request->mc_addr[i].bytes),
3278 ha->addr, ETH_ALEN);
3279 hdd_info("mlist[%d] = %pM", i,
3280 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281 i++;
3282 }
3283 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303284
3285 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003286 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303287 mc_list_request->count = mc_count;
3288 status = hdd_cache_mc_addr_list(mc_list_request);
3289 if (status == 0) {
3290 hdd_enable_mc_addr_filtering(adapter,
3291 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003292 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303293 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003294 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303295out:
3296 if (mc_list_request)
3297 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303298 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299}
3300
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303301
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003302/**
3303 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3304 * @dev: pointer to net_device
3305 *
3306 * Return: none
3307 */
3308static void hdd_set_multicast_list(struct net_device *dev)
3309{
3310 cds_ssr_protect(__func__);
3311 __hdd_set_multicast_list(dev);
3312 cds_ssr_unprotect(__func__);
3313}
3314#endif
3315
3316/**
3317 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3318 * @dev: Pointer to the WLAN device.
3319 * @skb: Pointer to OS packet (sk_buff).
3320 *
3321 * This function is registered with the Linux OS for network
3322 * core to decide which queue to use first.
3323 *
3324 * Return: ac, Queue Index/access category corresponding to UP in IP header
3325 */
3326static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3327#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3328 , void *accel_priv
3329#endif
3330#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3331 , select_queue_fallback_t fallback
3332#endif
3333)
3334{
3335 return hdd_wmm_select_queue(dev, skb);
3336}
3337
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003338static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339 .ndo_open = hdd_open,
3340 .ndo_stop = hdd_stop,
3341 .ndo_uninit = hdd_uninit,
3342 .ndo_start_xmit = hdd_hard_start_xmit,
3343 .ndo_tx_timeout = hdd_tx_timeout,
3344 .ndo_get_stats = hdd_get_stats,
3345 .ndo_do_ioctl = hdd_ioctl,
3346 .ndo_set_mac_address = hdd_set_mac_address,
3347 .ndo_select_queue = hdd_select_queue,
3348#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003349 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003350#endif
3351};
3352
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003353/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003354static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003355 .ndo_open = hdd_mon_open,
3356 .ndo_stop = hdd_stop,
3357 .ndo_get_stats = hdd_get_stats,
3358};
3359
3360/**
3361 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003362 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003363 * Return: None
3364 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003365void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003367 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003368 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003369 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003370 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003371}
3372
3373/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003374 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3375 * @hdd_ctx: global hdd context
3376 * @macAddr: mac address to assign to the interface
3377 * @name: User-visible name of the interface
3378 *
3379 * hdd adapter pointer would point to the netdev->priv space, this function
3380 * would retrive the pointer, and setup the hdd adapter configuration.
3381 *
3382 * Return: the pointer to hdd adapter, otherwise NULL
3383 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003384static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003386 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003387 const char *name)
3388{
Jeff Johnson5505db82017-11-02 21:19:23 -07003389 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003390 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003391 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303392 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003393 /*
3394 * cfg80211 initialization and registration....
3395 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003396 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003397#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3398 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003399#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003400 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3401 hdd_mon_mode_ether_setup : ether_setup),
3402 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003403
Jeff Johnson5505db82017-11-02 21:19:23 -07003404 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405
3406 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003407 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408
Jeff Johnson9d295242017-08-29 14:39:48 -07003409 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003410 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303411 qdf_mem_set(sta_ctx->conn_info.staId,
3412 sizeof(sta_ctx->conn_info.staId),
3413 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003414 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003415 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003417 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003418
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303419 qdf_status = qdf_event_create(
3420 &adapter->qdf_session_open_event);
3421 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3422 hdd_err("Session open QDF event init failed!");
3423 free_netdev(adapter->dev);
3424 return NULL;
3425 }
3426
3427 qdf_status = qdf_event_create(
3428 &adapter->qdf_session_close_event);
3429 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3430 hdd_err("Session close QDF event init failed!");
3431 free_netdev(adapter->dev);
3432 return NULL;
3433 }
3434
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303436 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437 init_completion(&adapter->linkup_event_var);
3438 init_completion(&adapter->cancel_rem_on_chan_var);
3439 init_completion(&adapter->rem_on_chan_ready_event);
3440 init_completion(&adapter->sta_authorized_event);
3441 init_completion(&adapter->offchannel_tx_event);
3442 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003443 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303445 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003446
3447 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003448 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003450 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003451
Jeff Johnson5505db82017-11-02 21:19:23 -07003452 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003454 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003455 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003456 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003457
3458 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003459 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003461 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462
Jeff Johnson5505db82017-11-02 21:19:23 -07003463 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003464
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465 hdd_set_station_ops(adapter->dev);
3466
Jeff Johnson5505db82017-11-02 21:19:23 -07003467 hdd_dev_setup_destructor(dev);
3468 dev->ieee80211_ptr = &adapter->wdev;
3469 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003470 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003471 adapter->wdev.netdev = dev;
3472 /* set dev's parent to underlying device */
3473 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474 hdd_wmm_init(adapter);
3475 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303476 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 }
3478
3479 return adapter;
3480}
3481
Jeff Johnson9d295242017-08-29 14:39:48 -07003482static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003484 struct net_device *dev = adapter->dev;
3485 int ret;
3486
3487 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003489 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003490 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3491
3492 ret = dev_alloc_name(dev, dev->name);
3493 if (ret < 0) {
3494 hdd_err(
3495 "unable to get dev name: %s, err = 0x%x",
3496 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303497 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498 }
3499 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003500
3501 ret = register_netdevice(dev);
3502 if (ret) {
3503 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3504 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303505 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003506 }
3507 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003508 ret = register_netdev(dev);
3509 if (ret) {
3510 hdd_err("register_netdev(%s) failed, err = 0x%x",
3511 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303512 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003513 }
3514 }
3515 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3516
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003517 EXIT();
3518
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303519 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520}
3521
Krunal Sonib51eec72017-11-20 21:53:01 -08003522QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003523{
Krunal Sonib51eec72017-11-20 21:53:01 -08003524 struct hdd_adapter *adapter;
3525 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003526
Krunal Sonib51eec72017-11-20 21:53:01 -08003527 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3528 if (!hdd_ctx) {
3529 hdd_err("Invalid HDD_CTX");
3530 return QDF_STATUS_E_FAILURE;
3531 }
3532
3533 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3534 if (NULL == adapter) {
3535 hdd_err("NULL adapter");
3536 return QDF_STATUS_E_INVAL;
3537 }
3538 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303539 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003540 hdd_debug("session %d opened", adapter->session_id);
3541
3542 return QDF_STATUS_SUCCESS;
3543}
3544
3545QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3546{
3547 struct hdd_adapter *adapter;
3548 struct hdd_context *hdd_ctx;
3549
3550 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3551 if (!hdd_ctx) {
3552 hdd_err("Invalid HDD_CTX");
3553 return QDF_STATUS_E_FAILURE;
3554 }
3555
3556 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003558 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303559 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560 }
3561
3562 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003563 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303564 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003565 }
3566
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003567 /*
3568 * For NAN Data interface, the close session results in the final
3569 * indication to the userspace
3570 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003571 if (adapter->device_mode == QDF_NDI_MODE)
3572 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003573
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003574 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3575
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576 /*
3577 * We can be blocked while waiting for scheduled work to be
3578 * flushed, and the adapter structure can potentially be freed, in
3579 * which case the magic will have been reset. So make sure the
3580 * magic is still good, and hence the adapter structure is still
3581 * valid, before signaling completion
3582 */
3583 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303584 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303586 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587}
3588
Jeff Johnson9d295242017-08-29 14:39:48 -07003589int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590{
Dustin Brownd28772b2017-03-17 14:16:07 -07003591 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592
Dustin Brownd28772b2017-03-17 14:16:07 -07003593 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003594 if (QDF_IS_STATUS_ERROR(status))
3595 return qdf_status_to_os_return(status);
3596
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003597 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003598 if (QDF_IS_STATUS_ERROR(status))
3599 return qdf_status_to_os_return(status);
3600
3601 if (wma_capability_enhanced_mcast_filter())
3602 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3603 else
3604 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003605
3606 return qdf_status_to_os_return(status);
3607}
3608
Jeff Johnson9d295242017-08-29 14:39:48 -07003609int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003610{
3611 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003612 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003613 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003614 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003615
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003616 vdev_id = adapter->session_id;
3617 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003618
3619 /* vdev created sanity check */
3620 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003621 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003622 return -EINVAL;
3623 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003624 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003625
Dustin Brownd28772b2017-03-17 14:16:07 -07003626 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303627 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003628 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003629 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003630 if (QDF_IS_STATUS_ERROR(status)) {
3631 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003632 errno = qdf_status_to_os_return(status);
3633 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003634 }
3635
3636 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303637 status = qdf_wait_for_event_completion(
3638 &adapter->qdf_session_close_event,
3639 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3640 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003641 if (adapter->device_mode == QDF_NDI_MODE)
3642 hdd_ndp_session_end_handler(adapter);
3643 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303644 adapter->session_id = HDD_SESSION_ID_INVALID;
3645 if (QDF_STATUS_E_TIMEOUT != status) {
3646 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003647 errno = -ETIMEDOUT;
3648 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303649 } else if (adapter->qdf_session_close_event.force_set) {
3650 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003651 errno = -EINVAL;
3652 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303653 } else {
3654 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003655 errno = -EINVAL;
3656 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303657 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003658 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003659
Yue Maf9782842017-05-08 12:49:49 -07003660release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003661 /*
3662 * In SSR or driver unloading case, directly exit may cause objects
3663 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003664 */
Frank Liuc66d4bf2018-01-26 16:18:18 +08003665 if (errno && !(cds_is_driver_recovering() || cds_is_driver_unloading()))
Jiachao Wu2c42c222018-01-15 18:13:19 +08003666 return errno;
3667
Sandeep Puligillaef415362017-08-30 16:37:13 -07003668 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003669 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003670 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003671 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003672 return errno;
3673 }
3674
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003675 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003676
3677 return 0;
3678}
3679
Krunal Sonib51eec72017-11-20 21:53:01 -08003680static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3681 struct sme_session_params *session_param,
3682 csr_roam_completeCallback callback,
3683 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003684{
Dustin Brownd28772b2017-03-17 14:16:07 -07003685 uint32_t type;
3686 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003687 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003688
3689 /* determine vdev (sub)type */
3690 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303691 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003692 hdd_err("failed to get vdev type: %d", status);
3693 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003695 session_param->sme_session_id = adapter->session_id;
3696 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3697 session_param->type_of_persona = type;
3698 session_param->subtype_of_persona = sub_type;
3699 session_param->session_open_cb = hdd_sme_open_session_callback;
3700 session_param->session_close_cb = hdd_sme_close_session_callback;
3701 session_param->callback = callback;
3702 session_param->callback_ctx = callback_ctx;
3703
3704 return 0;
3705}
3706
3707int hdd_vdev_create(struct hdd_adapter *adapter,
3708 csr_roam_completeCallback callback, void *ctx)
3709{
3710 QDF_STATUS status;
3711 int errno;
3712 struct hdd_context *hdd_ctx;
3713 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003714
3715 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003716
3717 /* do vdev create via objmgr */
3718 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003719 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003720 if (errno) {
3721 hdd_err("failed to create objmgr vdev: %d", errno);
3722 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003724
3725 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303726 status = qdf_event_reset(&adapter->qdf_session_open_event);
3727 if (QDF_STATUS_SUCCESS != status) {
3728 hdd_err("failed to reinit session open event");
3729 return -EINVAL;
3730 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003731 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3732 callback, ctx);
3733 if (errno) {
3734 hdd_err("failed to populating SME params");
3735 goto objmgr_vdev_destroy_procedure;
3736 }
3737
3738 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003739 if (QDF_IS_STATUS_ERROR(status)) {
3740 hdd_err("failed to open sme session: %d", status);
3741 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003742 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003743 }
3744
3745 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303746 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3747 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3748 if (QDF_STATUS_SUCCESS != status) {
3749 if (adapter->qdf_session_open_event.force_set) {
3750 /*
3751 * SSR/PDR has caused shutdown, which has forcefully
3752 * set the event. Return without the closing session.
3753 */
3754 adapter->session_id = HDD_SESSION_ID_INVALID;
3755 hdd_err("Session open event forcefully set");
3756 return -EINVAL;
3757 } else {
3758 if (QDF_STATUS_E_TIMEOUT == status)
3759 hdd_err("Session failed to open within timeout period");
3760 else
3761 hdd_err("Failed to wait for session open event(status-%d)",
3762 status);
3763 errno = -ETIMEDOUT;
3764 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3765 goto hdd_vdev_destroy_procedure;
3766 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003767 }
3768
3769 /* firmware ready for component communication, raise vdev_ready event */
3770 errno = hdd_vdev_ready(adapter);
3771 if (errno) {
3772 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003773 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003774 }
3775
Jeff Johnson1b780e42017-10-31 14:11:45 -07003776 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003777
3778 return 0;
3779
3780 /*
3781 * Due to legacy constraints, we need to destroy in the same order as
3782 * create. So, split error handling into 2 cases to accommodate.
3783 */
3784
Krunal Soni4a020c72017-10-30 20:58:40 -07003785objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003786 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003787
3788 return errno;
3789
Krunal Soni4a020c72017-10-30 20:58:40 -07003790hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003791 QDF_BUG(!hdd_vdev_destroy(adapter));
3792
3793 return errno;
3794}
3795
Jeff Johnson9d295242017-08-29 14:39:48 -07003796QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003797{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003798 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003799 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003800 QDF_STATUS status;
3801 int ret_val;
3802
Dustin Brownd28772b2017-03-17 14:16:07 -07003803 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3804 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3805 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003806 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003808 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003809 status = hdd_register_wext(adapter->dev);
3810 if (QDF_IS_STATUS_ERROR(status)) {
3811 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003812 goto error_register_wext;
3813 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003814 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003815
Himanshu Agarwalb229a142017-12-21 10:16:45 +05303816 hdd_debug("Disabling Green AP");
3817 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev, false);
3818 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
3819
Jeff Johnsond377dce2017-10-04 10:32:42 -07003820 qdf_mem_set(sta_ctx->conn_info.staId,
3821 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303822
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003823 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003824 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303825 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003827 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003828 hdd_ctx->config->OperatingChannel;
3829
3830 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003831 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003832
3833 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303834 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003835 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003836 status, status);
3837 goto error_init_txrx;
3838 }
3839
3840 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3841
3842 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303843 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003844 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845 status, status);
3846 goto error_wmm_init;
3847 }
3848
3849 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3850
Jeff Johnson1b780e42017-10-31 14:11:45 -07003851 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003852 WMI_PDEV_PARAM_BURST_ENABLE,
3853 hdd_ctx->config->enableSifsBurst,
3854 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003855 if (ret_val)
3856 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303858 /*
3859 * In case of USB tethering, LRO is disabled. If SSR happened
3860 * during that time, then as part of SSR init, do not enable
3861 * the LRO again. Keep the LRO state same as before SSR.
3862 */
3863 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003864 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303865
3866 /* rcpi info initialization */
3867 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3868
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303869 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003871error_wmm_init:
3872 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3873 hdd_deinit_tx_rx(adapter);
3874error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003875 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003877 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003879 return status;
3880}
3881
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303882/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003883 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303884 * @hdd_ctx: global hdd context
3885 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003886 * @rtnl_held: Used to indicate whether or not the caller is holding
3887 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303888 *
3889 * This function De-initializes the STA/P2P/OCB adapter.
3890 *
3891 * Return: None.
3892 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003893static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003894 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003895 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303896{
3897 ENTER_DEV(adapter->dev);
3898
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303899 if (adapter->dev) {
3900 if (rtnl_held)
3901 adapter->dev->wireless_handlers = NULL;
3902 else {
3903 rtnl_lock();
3904 adapter->dev->wireless_handlers = NULL;
3905 rtnl_unlock();
3906 }
3907 }
3908
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303909 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3910 hdd_deinit_tx_rx(adapter);
3911 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3912 }
3913
3914 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3915 hdd_wmm_adapter_close(adapter);
3916 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3917 }
3918
Krunal Sonib51eec72017-11-20 21:53:01 -08003919
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303920 EXIT();
3921}
3922
Krunal Sonib51eec72017-11-20 21:53:01 -08003923void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3924 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925 bool rtnl_held)
3926{
3927 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303928
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003930 case QDF_STA_MODE:
3931 case QDF_P2P_CLIENT_MODE:
3932 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003933 case QDF_IBSS_MODE:
3934 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003936 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 break;
3938 }
3939
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003940 case QDF_SAP_MODE:
3941 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003943 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003944 break;
3945 }
3946
3947 default:
3948 break;
3949 }
3950
3951 EXIT();
3952}
3953
Jeff Johnson9d295242017-08-29 14:39:48 -07003954static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003955 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956{
Jeff Johnson5505db82017-11-02 21:19:23 -07003957 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958
3959 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003960 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003961 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003962 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963 return;
3964 }
3965
Rajeev Kumardca5f812016-02-04 17:28:06 -08003966 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303967
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968 /*
3969 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3970 * the driver is almost closed and cannot handle either control
3971 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003972 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3973 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974 * is not right. Setting this flag helps hdd_stop() to recognize that
3975 * the interface is closed and restricts any operations on that
3976 */
3977 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3978
3979 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003980 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003981 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003982 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003983 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984 /*
3985 * Note that the adapter is no longer valid at this point
3986 * since the memory has been reclaimed
3987 */
3988 }
3989}
3990
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003991static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003992 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993{
Jeff Johnson9d295242017-08-29 14:39:48 -07003994 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003995
Dustin Brown920397d2017-12-13 16:27:50 -08003996 hdd_for_each_adapter(hdd_ctx, adapter) {
3997 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
3998 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303999 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 }
Dustin Brown920397d2017-12-13 16:27:50 -08004002
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304003 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004005
Arun Khandavalli2358d522016-05-16 18:05:37 +05304006#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4007/**
4008 * hdd_set_fw_log_params() - Set log parameters to FW
4009 * @hdd_ctx: HDD Context
4010 * @adapter: HDD Adapter
4011 *
4012 * This function set the FW Debug log level based on the INI.
4013 *
4014 * Return: None
4015 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004016static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004017 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304018{
4019 uint8_t count = 0, numentries = 0,
4020 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4021 uint32_t value = 0;
4022 int ret;
4023
Arun Khandavallifae92942016-08-01 13:31:08 +05304024 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4025 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004026 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304027 return;
4028 }
4029
Arun Khandavallifae92942016-08-01 13:31:08 +05304030 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304031 hdd_ctx->fw_log_settings.dl_type =
4032 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004033 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304034 WMI_DBGLOG_TYPE,
4035 hdd_ctx->config->enableFwLogType,
4036 DBG_CMD);
4037 if (ret != 0)
4038 hdd_err("Failed to enable FW log type ret %d",
4039 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304040
4041 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304042 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004043 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304044 WMI_DBGLOG_LOG_LEVEL,
4045 hdd_ctx->config->enableFwLogLevel,
4046 DBG_CMD);
4047 if (ret != 0)
4048 hdd_err("Failed to enable FW log level ret %d",
4049 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304050
4051 hdd_string_to_u8_array(
4052 hdd_ctx->config->enableFwModuleLogLevel,
4053 moduleloglevel,
4054 &numentries,
4055 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4056
4057 while (count < numentries) {
4058 /*
4059 * FW module log level input string looks like
4060 * below:
4061 * gFwDebugModuleLoglevel=<FW Module ID>,
4062 * <Log Level>,...
4063 * For example:
4064 * gFwDebugModuleLoglevel=
4065 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4066 * Above input string means :
4067 * For FW module ID 1 enable log level 0
4068 * For FW module ID 2 enable log level 1
4069 * For FW module ID 3 enable log level 2
4070 * For FW module ID 4 enable log level 3
4071 * For FW module ID 5 enable log level 4
4072 * For FW module ID 6 enable log level 5
4073 * For FW module ID 7 enable log level 6
4074 */
4075
Nishank Aggarwale239d962017-03-03 12:26:02 +05304076 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4077 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4078 hdd_err("Module id %d and dbglog level %d input length is more than max",
4079 moduleloglevel[count],
4080 moduleloglevel[count + 1]);
4081 return;
4082 }
4083
4084 value = moduleloglevel[count] << 16;
4085 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004086 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304087 WMI_DBGLOG_MOD_LOG_LEVEL,
4088 value, DBG_CMD);
4089 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304090 hdd_err("Failed to enable FW module log level %d ret %d",
4091 value, ret);
4092
4093 count += 2;
4094 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304095
Arun Khandavalli2358d522016-05-16 18:05:37 +05304096}
4097#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004098static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004099 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304100{
4101}
4102
4103#endif
4104
4105/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004106 * hdd_configure_chain_mask() - programs chain mask to firmware
4107 * @adapter: HDD adapter
4108 *
4109 * Return: 0 on success or errno on failure
4110 */
4111static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4112{
4113 int ret_val;
4114 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4115
4116 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4117 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4118 hdd_ctx->config->txchainmask1x1,
4119 hdd_ctx->config->rxchainmask1x1);
4120 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4121 hdd_ctx->config->dual_mac_feature_disable,
4122 hdd_ctx->config->tx_chain_mask_2g,
4123 hdd_ctx->config->rx_chain_mask_2g);
4124 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4125 hdd_ctx->config->tx_chain_mask_5g,
4126 hdd_ctx->config->rx_chain_mask_5g);
4127
4128 if (hdd_ctx->config->enable2x2) {
4129 hdd_info("2x2 enabled. skip chain mask programming");
4130 return 0;
4131 }
4132
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004133 if (hdd_ctx->config->dual_mac_feature_disable !=
4134 DISABLE_DBS_CXN_AND_SCAN) {
4135 hdd_info("DBS enabled(%d). skip chain mask programming",
4136 hdd_ctx->config->dual_mac_feature_disable);
4137 return 0;
4138 }
4139
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004140 if (hdd_ctx->config->txchainmask1x1) {
4141 ret_val = sme_cli_set_command(adapter->session_id,
4142 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4143 hdd_ctx->config->txchainmask1x1,
4144 PDEV_CMD);
4145 if (ret_val)
4146 goto error;
4147 }
4148
4149 if (hdd_ctx->config->rxchainmask1x1) {
4150 ret_val = sme_cli_set_command(adapter->session_id,
4151 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4152 hdd_ctx->config->rxchainmask1x1,
4153 PDEV_CMD);
4154 if (ret_val)
4155 goto error;
4156 }
4157
4158 if (hdd_ctx->lte_coex_ant_share) {
4159 hdd_info("lte ant sharing enabled. skip per band chain mask");
4160 return 0;
4161 }
4162
4163 if (hdd_ctx->config->txchainmask1x1 ||
4164 hdd_ctx->config->rxchainmask1x1) {
4165 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4166 return 0;
4167 }
4168
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004169 if (hdd_ctx->config->tx_chain_mask_2g) {
4170 ret_val = sme_cli_set_command(adapter->session_id,
4171 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4172 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4173 if (0 != ret_val)
4174 goto error;
4175 }
4176
4177 if (hdd_ctx->config->rx_chain_mask_2g) {
4178 ret_val = sme_cli_set_command(adapter->session_id,
4179 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4180 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4181 if (0 != ret_val)
4182 goto error;
4183 }
4184
4185 if (hdd_ctx->config->tx_chain_mask_5g) {
4186 ret_val = sme_cli_set_command(adapter->session_id,
4187 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4188 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4189 if (0 != ret_val)
4190 goto error;
4191 }
4192
4193 if (hdd_ctx->config->rx_chain_mask_5g) {
4194 ret_val = sme_cli_set_command(adapter->session_id,
4195 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4196 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4197 if (0 != ret_val)
4198 goto error;
4199 }
4200
4201 return 0;
4202
4203error:
4204 hdd_err("WMI PDEV set param failed %d", ret_val);
4205 return -EINVAL;
4206}
4207
4208/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304209 * hdd_set_fw_params() - Set parameters to firmware
4210 * @adapter: HDD adapter
4211 *
4212 * This function Sets various parameters to fw once the
4213 * adapter is started.
4214 *
4215 * Return: 0 on success or errno on failure
4216 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004217int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304218{
4219 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004220 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304221
4222 ENTER_DEV(adapter->dev);
4223
4224 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4225 if (!hdd_ctx)
4226 return -EINVAL;
4227
Dustin Brown732ab9c2017-06-15 13:24:09 -07004228 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4229 hdd_debug("FTM Mode is active; nothing to do");
4230 return 0;
4231 }
4232
Jeff Johnson1b780e42017-10-31 14:11:45 -07004233 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304234 WMI_PDEV_PARAM_DTIM_SYNTH,
4235 hdd_ctx->config->enable_lprx, PDEV_CMD);
4236 if (ret) {
4237 hdd_err("Failed to set LPRx");
4238 goto error;
4239 }
4240
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304241 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004242 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304243 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4244 hdd_ctx->config->upper_brssi_thresh);
4245
Jeff Johnson1b780e42017-10-31 14:11:45 -07004246 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304247 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4248 hdd_ctx->config->lower_brssi_thresh);
4249
Jeff Johnson1b780e42017-10-31 14:11:45 -07004250 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304251 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4252 hdd_ctx->config->enable_dtim_1chrx);
4253 }
4254
Dustin Brown732ab9c2017-06-15 13:24:09 -07004255 if (hdd_ctx->config->enable2x2) {
4256 hdd_debug("configuring 2x2 mode fw params");
4257
Jeff Johnson1b780e42017-10-31 14:11:45 -07004258 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004259 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4260 hdd_ctx->config->enable_cck_tx_fir_override,
4261 PDEV_CMD);
4262 if (ret) {
4263 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4264 ret);
4265 goto error;
4266 }
4267 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304268#define HDD_DTIM_1CHAIN_RX_ID 0x5
4269#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004270 hdd_debug("configuring 1x1 mode fw params");
4271
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004272 /*
4273 * Disable DTIM 1 chain Rx when in 1x1,
4274 * we are passing two value
4275 * as param_id << 29 | param_value.
4276 * Below param_value = 0(disable)
4277 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004278 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004279 WMI_STA_SMPS_PARAM_CMDID,
4280 HDD_DTIM_1CHAIN_RX_ID <<
4281 HDD_SMPS_PARAM_VALUE_S,
4282 VDEV_CMD);
4283 if (ret) {
4284 hdd_err("DTIM 1 chain set failed %d", ret);
4285 goto error;
4286 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304287
Arun Khandavalli2358d522016-05-16 18:05:37 +05304288#undef HDD_DTIM_1CHAIN_RX_ID
4289#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004290
4291 if (hdd_configure_chain_mask(adapter))
4292 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004293 }
4294
Jeff Johnson1b780e42017-10-31 14:11:45 -07004295 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004296 WMI_PDEV_PARAM_HYST_EN,
4297 hdd_ctx->config->enableMemDeepSleep,
4298 PDEV_CMD);
4299 if (ret) {
4300 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4301 goto error;
4302 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304303
Jeff Johnson1b780e42017-10-31 14:11:45 -07004304 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004305 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4306 hdd_ctx->config->rts_profile,
4307 VDEV_CMD);
4308 if (ret) {
4309 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4310 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304311 }
4312
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004313 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4314
Jeff Johnson1b780e42017-10-31 14:11:45 -07004315 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004316 GEN_VDEV_PARAM_AMSDU,
4317 hdd_ctx->config->max_amsdu_num,
4318 GEN_CMD);
4319 if (ret != 0) {
4320 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4321 goto error;
4322 }
4323
Arun Khandavalli2358d522016-05-16 18:05:37 +05304324 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304325 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004326
Arun Khandavalli2358d522016-05-16 18:05:37 +05304327 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304328
Arun Khandavalli2358d522016-05-16 18:05:37 +05304329error:
4330 return -EINVAL;
4331}
4332
Ryan Hsu07495ea2016-01-21 15:25:39 -08004333/**
4334 * hdd_open_adapter() - open and setup the hdd adatper
4335 * @hdd_ctx: global hdd context
4336 * @session_type: type of the interface to be created
4337 * @iface_name: User-visible name of the interface
4338 * @macAddr: MAC address to assign to the interface
4339 * @name_assign_type: the name of assign type of the netdev
4340 * @rtnl_held: the rtnl lock hold flag
4341 *
4342 * This function open and setup the hdd adpater according to the device
4343 * type request, assign the name, the mac address assigned, and then prepared
4344 * the hdd related parameters, queue, lock and ready to start.
4345 *
4346 * Return: the pointer of hdd adapter, otherwise NULL.
4347 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004348struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004350 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004351 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004352{
Jeff Johnson9d295242017-08-29 14:39:48 -07004353 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304354 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004355
4356 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4357 /*
4358 * Max limit reached on the number of vdevs configured by the
4359 * host. Return error
4360 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304361 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4362 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363 return NULL;
4364 }
4365
4366 if (macAddr == NULL) {
4367 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304368 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369 return NULL;
4370 }
4371 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304372 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304373 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4374 " already exists",
4375 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004376 return NULL;
4377 }
4378
4379 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004380 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 /* Reset locally administered bit if the device mode is STA */
4382 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304383 hdd_info("locally administered bit reset in sta mode: "
4384 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004386 case QDF_P2P_CLIENT_MODE:
4387 case QDF_P2P_DEVICE_MODE:
4388 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004389 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304390 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004391 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4392 name_assign_type,
4393 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394
4395 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304396 hdd_err("failed to allocate adapter for session %d",
4397 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 return NULL;
4399 }
4400
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004401 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004403 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004404 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304405 else if (QDF_MONITOR_MODE == session_type)
4406 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004407 else
4408 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4409
4410 adapter->device_mode = session_type;
4411
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413 /*
4414 * Workqueue which gets scheduled in IPv4 notification
4415 * callback
4416 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004417 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004418 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004419
4420#ifdef WLAN_NS_OFFLOAD
4421 /*
4422 * Workqueue which gets scheduled in IPv6
4423 * notification callback.
4424 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004425 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004426 hdd_ipv6_notifier_work_queue);
4427#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004428 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004429 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004430 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431
4432 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004433 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304435 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4436 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304437
Ravi Joshi1a292562017-05-18 16:28:54 -07004438 /* Initialize NAN Data Interface */
4439 if (QDF_NDI_MODE == session_type) {
4440 status = hdd_init_nan_data_mode(adapter);
4441 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004442 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004443 }
4444
4445 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004447 case QDF_P2P_GO_MODE:
4448 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004449 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4450 name_assign_type,
4451 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004452 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004453 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304454 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004455 return NULL;
4456 }
4457
4458 adapter->wdev.iftype =
4459 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004460 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004461 NL80211_IFTYPE_P2P_GO;
4462 adapter->device_mode = session_type;
4463
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004464 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004465 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004467
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004468 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004469 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304470 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4471 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304472
4473 /*
4474 * Workqueue which gets scheduled in IPv4 notification
4475 * callback
4476 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004477 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304478 hdd_ipv4_notifier_work_queue);
4479
4480#ifdef WLAN_NS_OFFLOAD
4481 /*
4482 * Workqueue which gets scheduled in IPv6
4483 * notification callback.
4484 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004485 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304486 hdd_ipv6_notifier_work_queue);
4487#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004488 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304489 case QDF_FTM_MODE:
4490 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4491 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004492 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304493 if (NULL == adapter) {
4494 hdd_err("Failed to allocate adapter for FTM mode");
4495 return NULL;
4496 }
4497 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4498 adapter->device_mode = session_type;
4499 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004500 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004501 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004502
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304503 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004504 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304505 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304506 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4507 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304508 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004509 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004510 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304511 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004512 return NULL;
4513 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004514
hqueaa33ee2017-05-04 17:56:35 +08004515 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4516
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304517 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004519 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004520 }
4521
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304522 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004523 if (NULL != adapter) {
4524 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4525 adapter = NULL;
4526 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004527
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528 return NULL;
4529 }
4530
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304531 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004532 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4533 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004534
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004535 /* Adapter successfully added. Increment the vdev count */
4536 hdd_ctx->current_intf_count++;
4537
Jeff Johnson5880d792016-08-15 13:32:30 -07004538 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004539 hdd_ctx->current_intf_count);
4540
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004541 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004542 }
4543
Rajeev Kumardca5f812016-02-04 17:28:06 -08004544 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004545 hdd_err("Interface %s wow debug_fs init failed",
4546 netdev_name(adapter->dev));
4547
4548 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4549 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550
4551 return adapter;
4552
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004553err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004554 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304555 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004556
4557 return NULL;
4558}
4559
Jeff Johnson9d295242017-08-29 14:39:48 -07004560QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004561 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004562{
Dustin Brown920397d2017-12-13 16:27:50 -08004563 /*
4564 * Here we are stopping global bus_bw timer & work per adapter.
4565 *
4566 * The reason is to fix one race condition between
4567 * bus bandwidth work and cleaning up an adapter.
4568 * Under some conditions, it is possible for the bus bandwidth
4569 * work to access a particularly destroyed adapter, leading to
4570 * use-after-free.
4571 */
4572 hdd_debug("wait for bus bw work to flush");
4573 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4574 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004575
Dustin Brown920397d2017-12-13 16:27:50 -08004576 /* cleanup adapter */
4577 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4578 adapter->device_mode);
4579 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4580 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004581
Dustin Brown920397d2017-12-13 16:27:50 -08004582 /* conditionally restart the bw timer */
4583 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004584
Dustin Brown920397d2017-12-13 16:27:50 -08004585 /* Adapter removed. Decrement vdev count */
4586 if (hdd_ctx->current_intf_count != 0)
4587 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004588
Dustin Brown920397d2017-12-13 16:27:50 -08004589 /* Fw will take care incase of concurrency */
4590 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004591}
4592
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004593/**
4594 * hdd_close_all_adapters - Close all open adapters
4595 * @hdd_ctx: Hdd context
4596 * rtnl_held: True if RTNL lock held
4597 *
4598 * Close all open adapters.
4599 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304600 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004601 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004602QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004603{
Dustin Brown920397d2017-12-13 16:27:50 -08004604 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304605 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004606
4607 ENTER();
4608
4609 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004610 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4611 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304612 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004613 adapter->mac_addr.bytes);
4614 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4615
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304616 /* Adapter removed. Decrement vdev count */
4617 if (hdd_ctx->current_intf_count != 0)
4618 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619 }
Dustin Brown920397d2017-12-13 16:27:50 -08004620 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004621
4622 EXIT();
4623
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304624 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625}
4626
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004627void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004628{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304629 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004630 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004631
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004632 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004633 case QDF_STA_MODE:
4634 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004635 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004636 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004637 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004638 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004639 break;
4640 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004641 case QDF_SAP_MODE:
4642 case QDF_P2P_GO_MODE:
4643 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004644 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004645 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004646 break;
4647 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004648 case QDF_FTM_MODE:
4649 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004650 default:
4651 /*
4652 * wlan_hdd_reset_prob_rspies should not have been called
4653 * for these kind of devices
4654 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004655 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004656 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004657 return;
4658 }
4659
Anurag Chouhanc5548422016-02-24 18:33:27 +05304660 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004661 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 updateIE.ieBufferlength = 0;
4663 updateIE.pAdditionIEBuffer = NULL;
4664 updateIE.append = true;
4665 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004666 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304668 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004669 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004670 }
4671}
4672
Dustin Browndb2a8be2017-12-20 11:49:56 -08004673QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4674 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004675{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304676 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004677 struct hdd_wext_state *pWextState =
4678 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004679 union iwreq_data wrqu;
4680 tSirUpdateIE updateIE;
4681 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304682 tsap_Config_t *sap_config;
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304683 bool is_enabled = false;
4684 uint8_t ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004685
4686 ENTER();
4687
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004688 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304689 wlan_hdd_netif_queue_control(adapter,
4690 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4691 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004692 /*
4693 * if this is the last active connection check & stop the
4694 * opportunistic timer first
4695 */
4696 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4697 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4698 policy_mgr_convert_device_mode_to_qdf_type(
4699 adapter->device_mode), NULL) == 1)) ||
4700 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4701 policy_mgr_check_and_stop_opportunistic_timer(
4702 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004703 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004704 case QDF_STA_MODE:
4705 case QDF_P2P_CLIENT_MODE:
4706 case QDF_IBSS_MODE:
4707 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004708 case QDF_NDI_MODE:
4709 if ((QDF_NDI_MODE == adapter->device_mode) ||
4710 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004711 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4712 hdd_is_connecting(
4713 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004714 INIT_COMPLETION(adapter->disconnect_comp_var);
4715 /*
4716 * For NDI do not use pWextState from sta_ctx, if needed
4717 * extract from ndi_ctx.
4718 */
4719 if (QDF_NDI_MODE == adapter->device_mode)
4720 qdf_ret_status = sme_roam_disconnect(
4721 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004722 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004723 eCSR_DISCONNECT_REASON_NDI_DELETE);
4724 else if (pWextState->roamProfile.BSSType ==
4725 eCSR_BSS_TYPE_START_IBSS)
4726 qdf_ret_status = sme_roam_disconnect(
4727 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004728 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004729 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004730 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004731 qdf_ret_status =
4732 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004733 hdd_debug("Send disconnected event to userspace");
4734 wlan_hdd_cfg80211_indicate_disconnect(
4735 adapter->dev, true,
4736 WLAN_REASON_UNSPECIFIED);
4737 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004738 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004739 qdf_ret_status = sme_roam_disconnect(
4740 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004741 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004742 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004743 /* success implies disconnect command got
4744 * queued up successfully
4745 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004746 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4747 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004748 rc = wait_for_completion_timeout(
4749 &adapter->disconnect_comp_var,
4750 msecs_to_jiffies
4751 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004752 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004753 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004754 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004755 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4756 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004757 memset(&wrqu, '\0', sizeof(wrqu));
4758 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4759 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4760 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4761 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304762 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004763 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004764
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304765 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304766 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004767
4768#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004769 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004770#endif
4771
4772 hdd_deregister_tx_flow_control(adapter);
4773
4774#ifdef WLAN_NS_OFFLOAD
4775#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004776 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777#endif
4778#endif
4779
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304780 if (adapter->device_mode == QDF_STA_MODE)
4781 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4782 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004783
4784 if (wlan_hdd_try_disconnect(adapter)) {
4785 hdd_err("Error: Can't disconnect adapter");
4786 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004787 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004788
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304789 ret = hdd_check_green_ap_enable(hdd_ctx, &is_enabled);
4790 if (!ret) {
4791 hdd_debug("Green AP enable status: %d", is_enabled);
4792 if (is_enabled) {
4793 hdd_debug("Enabling Green AP");
4794 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
4795 true);
4796 wlan_green_ap_start(hdd_ctx->hdd_pdev);
4797 }
4798 } else {
4799 hdd_err("Failed to check if Green AP should be enabled or not");
4800 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004801
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304802 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004803 break;
4804
Rajeev Kumar3b906202018-02-01 10:55:14 -08004805 case QDF_MONITOR_MODE:
4806 wlan_hdd_scan_abort(adapter);
4807 hdd_deregister_tx_flow_control(adapter);
4808 hdd_vdev_destroy(adapter);
4809 break;
4810
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004811 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004812 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304813 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304814 sap_config = &adapter->session.ap.sap_config;
4815 if (sap_config)
4816 wlansap_reset_sap_config_add_ie(sap_config,
4817 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304818 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004819 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004820
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004821 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004822 if (QDF_SAP_MODE == adapter->device_mode) {
4823 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4824 cds_flush_delayed_work(
4825 &adapter->acs_pending_work);
4826 clear_bit(ACS_PENDING, &adapter->event_flags);
4827 }
4828 }
Krunal Soni22208392017-09-29 18:10:34 -07004829 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004830
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004831 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004832 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004833 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004834 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4835
4836 hdd_deregister_tx_flow_control(adapter);
4837
Kapil Guptac1224bf2017-06-22 21:22:40 +05304838 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839 mutex_lock(&hdd_ctx->sap_lock);
4840 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304841 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304842 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004843
4844 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004845 status = wlansap_stop_bss(
4846 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004847
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304848 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004849 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304851 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304852 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304853 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304854 qdf_wait_for_event_completion(
4855 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004856 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857
Anurag Chouhance0dc992016-02-16 18:18:03 +05304858 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004859 hdd_err("failure waiting for wlansap_stop_bss %d",
4860 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004861 }
4862 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004863 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004864 }
4865 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004866 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4867 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004868 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004869
Anurag Chouhanc5548422016-02-24 18:33:27 +05304870 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004871 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004872 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873 updateIE.ieBufferlength = 0;
4874 updateIE.pAdditionIEBuffer = NULL;
4875 updateIE.append = false;
4876 updateIE.notify = false;
4877 /* Probe bcn reset */
4878 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4879 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304880 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004881 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004882 }
4883 /* Assoc resp reset */
4884 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4885 &updateIE,
4886 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304887 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004888 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889 }
4890 /* Reset WNI_CFG_PROBE_RSP Flags */
4891 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004892 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004893 qdf_mem_free(adapter->session.ap.beacon);
4894 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304895 /*
4896 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4897 */
4898 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4899 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4900
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304901#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004902 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304903#endif
4904
4905#ifdef WLAN_NS_OFFLOAD
4906#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004907 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304908#endif
4909#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08004910
4911 hdd_vdev_destroy(adapter);
4912
Krunal Sonib51eec72017-11-20 21:53:01 -08004913 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004914 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004915 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004916 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004917 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004918 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08004919 hdd_deregister_tx_flow_control(adapter);
4920 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004921 break;
4922 default:
4923 break;
4924 }
4925
Dustin Brown04348372017-12-14 16:13:39 -08004926 if (adapter->scan_info.default_scan_ies) {
4927 qdf_mem_free(adapter->scan_info.default_scan_ies);
4928 adapter->scan_info.default_scan_ies = NULL;
4929 }
4930
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004931 EXIT();
Dustin Brown04348372017-12-14 16:13:39 -08004932
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304933 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004934}
4935
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304936/**
4937 * hdd_deinit_all_adapters - deinit all adapters
4938 * @hdd_ctx: HDD context
4939 * @rtnl_held: True if RTNL lock held
4940 *
4941 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004942void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304943{
Jeff Johnson9d295242017-08-29 14:39:48 -07004944 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304945
4946 ENTER();
4947
Dustin Brown920397d2017-12-13 16:27:50 -08004948 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304949 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304950
4951 EXIT();
4952}
4953
Dustin Browndb2a8be2017-12-20 11:49:56 -08004954QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004955{
Jeff Johnson9d295242017-08-29 14:39:48 -07004956 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004957
4958 ENTER();
4959
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304960 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4961
Dustin Brown920397d2017-12-13 16:27:50 -08004962 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08004963 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004964
4965 EXIT();
4966
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304967 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004968}
4969
Paul Zhang84fa9382017-11-10 21:18:21 +08004970static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4971 struct hdd_adapter *adapter)
4972{
4973 switch (adapter->device_mode) {
4974 case QDF_STA_MODE:
4975 case QDF_P2P_CLIENT_MODE:
4976 case QDF_IBSS_MODE:
4977 case QDF_P2P_DEVICE_MODE:
4978 case QDF_NDI_MODE:
4979 wlan_hdd_scan_abort(adapter);
4980 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4981 if (adapter->device_mode == QDF_STA_MODE)
4982 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4983 adapter->dev);
4984 break;
4985 case QDF_P2P_GO_MODE:
4986 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4987 break;
4988 case QDF_SAP_MODE:
4989 wlan_hdd_undo_acs(adapter);
4990 break;
4991 default:
4992 break;
4993 }
4994}
4995
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004996QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004997{
Jeff Johnson9d295242017-08-29 14:39:48 -07004998 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004999 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005000 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005001 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002
5003 ENTER();
5004
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305005 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5006
Dustin Brown920397d2017-12-13 16:27:50 -08005007 hdd_for_each_adapter(hdd_ctx, adapter) {
Yue Ma42654682018-01-11 16:55:24 -08005008 hdd_notice("[SSR] reset adapter with device mode %s(%d)",
5009 hdd_device_mode_to_string(adapter->device_mode),
Yue Mad5b4b9f2017-05-26 16:23:40 -07005010 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305011
5012 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07005013 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305014 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005015 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305016
Arun Khandavallicc544b32017-01-30 19:52:16 +05305017 if (hdd_ctx->config->sap_internal_restart &&
5018 adapter->device_mode == QDF_SAP_MODE) {
5019 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305020 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305021 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005022 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005023 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005024 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005025 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5026 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305027 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305028 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005029 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005030 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031
Paul Zhang84fa9382017-11-10 21:18:21 +08005032 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005033 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005034
5035 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005036 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005037 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5039 hdd_wmm_adapter_close(adapter);
5040 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5041 }
5042
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305043 if (adapter->device_mode == QDF_STA_MODE)
5044 hdd_clear_fils_connection_info(adapter);
5045
Wu Gao3545e642017-07-14 19:24:41 +08005046 if (adapter->device_mode == QDF_SAP_MODE) {
5047 /*
5048 * If adapter is SAP, set session ID to invalid
5049 * since SAP session will be cleanup during SSR.
5050 */
Wu Gao36717432016-11-21 15:09:48 +08005051 wlansap_set_invalid_session(
5052 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5053
Wu Gao3545e642017-07-14 19:24:41 +08005054 wlansap_cleanup_cac_timer(
5055 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5056 }
5057
Yue Ma42654682018-01-11 16:55:24 -08005058 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005059 if (adapter->device_mode == QDF_STA_MODE ||
5060 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005061 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005062 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005063 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005064
5065 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5066 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005067 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5068 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5069 if (adapter->sta_info[sta_id].in_use) {
5070 hdd_debug("[SSR] deregister STA with ID %d",
5071 sta_id);
5072 hdd_softap_deregister_sta(adapter,
5073 sta_id);
5074 adapter->sta_info[sta_id].in_use = 0;
5075 }
5076 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005077 }
5078
Yue Maf9782842017-05-08 12:49:49 -07005079 /* Destroy vdev which will be recreated during reinit. */
5080 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081 }
5082
5083 EXIT();
5084
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305085 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005086}
5087
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005088bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305089{
Dustin Brown920397d2017-12-13 16:27:50 -08005090 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305091 bool close_modules = true;
5092
Arun Khandavalliba479c42017-07-26 21:29:40 +05305093 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5094 hdd_info("FTM mode, don't close the module");
5095 return false;
5096 }
5097
Dustin Brown920397d2017-12-13 16:27:50 -08005098 hdd_for_each_adapter(hdd_ctx, adapter) {
5099 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5100 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005101 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305102 close_modules = false;
5103 break;
5104 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305105 }
5106
5107 return close_modules;
5108}
5109
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305110bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305111{
5112 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5113 return true;
5114 else
5115 return false;
5116}
5117
Anurag Chouhanc4092922016-09-08 15:56:11 +05305118#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005119 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305120struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5121 struct ieee80211_channel *channel,
5122 const u8 *bssid, const u8 *ssid,
5123 size_t ssid_len)
5124{
5125 return cfg80211_get_bss(wiphy, channel, bssid,
5126 ssid, ssid_len,
5127 WLAN_CAPABILITY_ESS,
5128 WLAN_CAPABILITY_ESS);
5129}
5130#else
5131struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5132 struct ieee80211_channel *channel,
5133 const u8 *bssid, const u8 *ssid,
5134 size_t ssid_len)
5135{
5136 return cfg80211_get_bss(wiphy, channel, bssid,
5137 ssid, ssid_len,
5138 IEEE80211_BSS_TYPE_ESS,
5139 IEEE80211_PRIVACY_ANY);
5140}
5141#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305142
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305143#if defined CFG80211_CONNECT_BSS || \
5144 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305145#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305146 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305147/**
5148 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5149 * @timeout_reason: reason for connect timeout
5150 *
5151 * This function is used to convert host timeout
5152 * reason enum to kernel specific enum.
5153 *
5154 * Return: nl timeout enum
5155 */
5156static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5157 tSirResultCodes timeout_reason)
5158{
5159 switch (timeout_reason) {
5160 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5161 return NL80211_TIMEOUT_SCAN;
5162 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5163 return NL80211_TIMEOUT_AUTH;
5164 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5165 return NL80211_TIMEOUT_ASSOC;
5166 default:
5167 return NL80211_TIMEOUT_UNSPECIFIED;
5168 }
5169}
5170
5171/**
5172 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5173 * @dev: network device
5174 * @bssid: bssid to which we want to associate
5175 * @timeout_reason: reason for connect timeout
5176 *
5177 * This API is used to send connection timeout reason to supplicant
5178 *
5179 * Return: void
5180 */
5181static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5182 const u8 *bssid,
5183 tSirResultCodes timeout_reason)
5184{
5185 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005186
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305187 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5188
5189 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5190 nl_timeout_reason);
5191}
5192
5193/**
5194 * __hdd_connect_bss() - API to send connection status to supplicant
5195 * @dev: network device
5196 * @bssid: bssid to which we want to associate
5197 * @req_ie: Request Information Element
5198 * @req_ie_len: len of the req IE
5199 * @resp_ie: Response IE
5200 * @resp_ie_len: len of ht response IE
5201 * @status: status
5202 * @gfp: Kernel Flag
5203 * @timeout_reason: reason for connect timeout
5204 *
5205 * Return: void
5206 */
5207static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5208 struct cfg80211_bss *bss, const u8 *req_ie,
5209 size_t req_ie_len, const u8 *resp_ie,
5210 size_t resp_ie_len, int status, gfp_t gfp,
5211 tSirResultCodes timeout_reason)
5212{
5213 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005214
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305215 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5216
5217 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5218 resp_ie, resp_ie_len, status, gfp,
5219 nl_timeout_reason);
5220}
5221#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305222#if defined CFG80211_CONNECT_TIMEOUT || \
5223 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305224static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5225 const u8 *bssid,
5226 tSirResultCodes timeout_reason)
5227{
5228 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5229}
5230#endif
5231
5232static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5233 struct cfg80211_bss *bss, const u8 *req_ie,
5234 size_t req_ie_len, const u8 *resp_ie,
5235 size_t resp_ie_len, int status, gfp_t gfp,
5236 tSirResultCodes timeout_reason)
5237{
5238 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5239 resp_ie, resp_ie_len, status, gfp);
5240}
5241#endif
5242
Abhishek Singha84d3952016-09-13 13:45:05 +05305243/**
5244 * hdd_connect_bss() - API to send connection status to supplicant
5245 * @dev: network device
5246 * @bssid: bssid to which we want to associate
5247 * @req_ie: Request Information Element
5248 * @req_ie_len: len of the req IE
5249 * @resp_ie: Response IE
5250 * @resp_ie_len: len of ht response IE
5251 * @status: status
5252 * @gfp: Kernel Flag
5253 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305254 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305255 *
5256 * The API is a wrapper to send connection status to supplicant
5257 *
5258 * Return: Void
5259 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305260#if defined CFG80211_CONNECT_TIMEOUT || \
5261 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305262static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5263 struct cfg80211_bss *bss, const u8 *req_ie,
5264 size_t req_ie_len, const u8 *resp_ie,
5265 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305266 bool connect_timeout,
5267 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305268{
5269 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305270 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305271 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305272 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5273 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305274}
5275#else
5276static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5277 struct cfg80211_bss *bss, const u8 *req_ie,
5278 size_t req_ie_len, const u8 *resp_ie,
5279 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305280 bool connect_timeout,
5281 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305282{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305283 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5284 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305285}
5286#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305287
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305288#if defined(WLAN_FEATURE_FILS_SK)
5289#if defined(CFG80211_CONNECT_DONE) || \
5290 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5291#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5292 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305293/**
5294 * hdd_populate_fils_params() - Populate FILS keys to connect response
5295 * @fils_params: connect response to supplicant
5296 * @fils_kek: FILS kek
5297 * @fils_kek_len: FILS kek length
5298 * @pmk: FILS PMK
5299 * @pmk_len: FILS PMK length
5300 * @pmkid: PMKID
5301 * @fils_seq_num: FILS Seq number
5302 *
5303 * Return: None
5304 */
5305static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5306 *fils_params, const uint8_t *fils_kek,
5307 size_t fils_kek_len, const uint8_t *pmk,
5308 size_t pmk_len, const uint8_t *pmkid,
5309 uint16_t fils_seq_num)
5310{
5311 /* Increament seq number to be used for next FILS */
5312 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5313 fils_params->update_erp_next_seq_num = true;
5314 fils_params->fils_kek = fils_kek;
5315 fils_params->fils_kek_len = fils_kek_len;
5316 fils_params->pmk = pmk;
5317 fils_params->pmk_len = pmk_len;
5318 fils_params->pmkid = pmkid;
5319}
5320#else
5321static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5322 *fils_params, const uint8_t
5323 *fils_kek, size_t fils_kek_len,
5324 const uint8_t *pmk, size_t pmk_len,
5325 const uint8_t *pmkid,
5326 uint16_t fils_seq_num)
5327{ }
5328#endif
5329
Jeff Johnson172237b2017-11-07 15:32:59 -08005330void hdd_update_hlp_info(struct net_device *dev,
5331 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305332{
5333 struct sk_buff *skb;
5334 uint16_t skb_len;
5335 struct llc_snap_hdr_t *llc_hdr;
5336 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305337 uint8_t *hlp_data;
5338 uint16_t hlp_data_len;
5339 struct fils_join_rsp_params *roam_fils_params
5340 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305341 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5342
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305343 if (!roam_fils_params) {
5344 hdd_err("FILS Roam Param NULL");
5345 return;
5346 }
5347
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005348 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305349 hdd_err("FILS HLP Data NULL, len %d",
5350 roam_fils_params->hlp_data_len);
5351 return;
5352 }
5353
5354 hlp_data = roam_fils_params->hlp_data;
5355 hlp_data_len = roam_fils_params->hlp_data_len;
5356
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305357 /* Calculate skb length */
5358 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5359 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5360 if (skb == NULL) {
5361 hdd_err("HLP packet nbuf alloc fails");
5362 return;
5363 }
5364
5365 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5366 QDF_MAC_ADDR_SIZE);
5367 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5368 QDF_MAC_ADDR_SIZE);
5369
5370 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5371 if (IS_SNAP(llc_hdr)) {
5372 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5373 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5374 }
5375
5376 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5377
5378 /*
5379 * This HLP packet is formed from HLP info encapsulated
5380 * in assoc response frame which is AEAD encrypted.
5381 * Hence, this checksum validation can be set unnecessary.
5382 * i.e. network layer need not worry about checksum.
5383 */
5384 skb->ip_summed = CHECKSUM_UNNECESSARY;
5385
5386 status = hdd_rx_packet_cbk(padapter, skb);
5387 if (QDF_IS_STATUS_ERROR(status)) {
5388 hdd_err("Sending HLP packet fails");
5389 return;
5390 }
5391 hdd_debug("send HLP packet to netif successfully");
5392}
5393
5394/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305395 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5396 * @dev: network device
5397 * @bssid: bssid to which we want to associate
5398 * @bss: cfg80211 bss info
5399 * @roam_info: information about connected bss
5400 * @req_ie: Request Information Element
5401 * @req_ie_len: len of the req IE
5402 * @resp_ie: Response IE
5403 * @resp_ie_len: len of ht response IE
5404 * @status: status
5405 * @gfp: allocation flags
5406 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5407 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305408 *
5409 * This API is used as wrapper to send FILS key/sequence number
5410 * params etc. to supplicant in case of FILS connection
5411 *
5412 * Return: None
5413 */
5414static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005415 struct cfg80211_bss *bss,
5416 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305417 const u8 *req_ie, size_t req_ie_len,
5418 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005419 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305420 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305421{
5422 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305423 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5424 struct fils_join_rsp_params *roam_fils_params =
5425 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005426
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305427 qdf_mem_zero(&fils_params, sizeof(fils_params));
5428
5429 if (!roam_fils_params) {
5430 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5431 } else {
5432 fils_params.status = status;
5433 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005434 fils_params.timeout_reason =
5435 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305436 fils_params.req_ie = req_ie;
5437 fils_params.req_ie_len = req_ie_len;
5438 fils_params.resp_ie = resp_ie;
5439 fils_params.resp_ie_len = resp_ie_len;
5440 fils_params.bss = bss;
5441 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5442 roam_fils_params->kek_len,
5443 roam_fils_params->fils_pmk,
5444 roam_fils_params->fils_pmk_len,
5445 roam_fils_params->fils_pmkid,
5446 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305447 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305448 }
5449 hdd_debug("FILS indicate connect status %d seq no %d",
5450 fils_params.status,
5451 fils_params.fils_erp_next_seq_num);
5452
5453 cfg80211_connect_done(dev, &fils_params, gfp);
5454
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305455 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305456 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305457
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305458 /* Clear all the FILS key info */
5459 if (roam_fils_params && roam_fils_params->fils_pmk)
5460 qdf_mem_free(roam_fils_params->fils_pmk);
5461 if (roam_fils_params)
5462 qdf_mem_free(roam_fils_params);
5463 roam_info->fils_join_rsp = NULL;
5464}
5465#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005466static inline void
5467hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005468 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005469 const u8 *req_ie, size_t req_ie_len,
5470 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5471 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305472 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305473{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305474#endif
5475#endif
5476
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305477#if defined(WLAN_FEATURE_FILS_SK) && \
5478 (defined(CFG80211_CONNECT_DONE) || \
5479 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305480/**
5481 * hdd_fils_update_connect_results() - API to send fils connection status to
5482 * supplicant.
5483 * @dev: network device
5484 * @bssid: bssid to which we want to associate
5485 * @bss: cfg80211 bss info
5486 * @roam_info: information about connected bss
5487 * @req_ie: Request Information Element
5488 * @req_ie_len: len of the req IE
5489 * @resp_ie: Response IE
5490 * @resp_ie_len: len of ht response IE
5491 * @status: status
5492 * @gfp: allocation flags
5493 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5494 * @timeout_reason: reason for connect timeout
5495 *
5496 * The API is a wrapper to send connection status to supplicant
5497 *
5498 * Return: 0 if success else failure
5499 */
5500static int hdd_fils_update_connect_results(struct net_device *dev,
5501 const u8 *bssid,
5502 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005503 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305504 size_t req_ie_len, const u8 *resp_ie,
5505 size_t resp_ie_len, u16 status, gfp_t gfp,
5506 bool connect_timeout,
5507 tSirResultCodes timeout_reason)
5508{
5509 ENTER();
5510 if (!roam_info || !roam_info->is_fils_connection)
5511 return -EINVAL;
5512
5513 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5514 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305515 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305516 return 0;
5517}
5518#else
5519static inline int hdd_fils_update_connect_results(struct net_device *dev,
5520 const u8 *bssid,
5521 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005522 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305523 size_t req_ie_len, const u8 *resp_ie,
5524 size_t resp_ie_len, u16 status, gfp_t gfp,
5525 bool connect_timeout,
5526 tSirResultCodes timeout_reason)
5527{
5528 return -EINVAL;
5529}
5530#endif
5531
Anurag Chouhanc4092922016-09-08 15:56:11 +05305532/**
5533 * hdd_connect_result() - API to send connection status to supplicant
5534 * @dev: network device
5535 * @bssid: bssid to which we want to associate
5536 * @roam_info: information about connected bss
5537 * @req_ie: Request Information Element
5538 * @req_ie_len: len of the req IE
5539 * @resp_ie: Response IE
5540 * @resp_ie_len: len of ht response IE
5541 * @status: status
5542 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305543 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305544 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305545 *
5546 * The API is a wrapper to send connection status to supplicant
5547 * and allow runtime suspend
5548 *
5549 * Return: Void
5550 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305551void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005552 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305553 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305554 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305555 bool connect_timeout,
5556 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305557{
Jeff Johnson9d295242017-08-29 14:39:48 -07005558 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305559 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005560 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305561
5562 if (WLAN_STATUS_SUCCESS == status) {
5563 struct ieee80211_channel *chan;
5564 int freq;
5565 int chan_no = roam_info->pBssDesc->channelId;
5566
5567 if (chan_no <= 14)
5568 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005569 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305570 else
5571 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005572 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305573
5574 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5575 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5576 roam_info->u.pConnectedProfile->SSID.ssId,
5577 roam_info->u.pConnectedProfile->SSID.length);
5578 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305579
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305580 if (hdd_fils_update_connect_results(dev, bssid, bss,
5581 roam_info, req_ie, req_ie_len, resp_ie,
5582 resp_ie_len, status, gfp, connect_timeout,
5583 timeout_reason) != 0) {
5584 hdd_connect_bss(dev, bssid, bss, req_ie,
5585 req_ie_len, resp_ie, resp_ie_len,
5586 status, gfp, connect_timeout, timeout_reason);
5587 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305588
Jingxiang Geb49aa302018-01-17 20:54:15 +08005589 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005590 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305591}
5592#else
5593void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005594 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305595 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305596 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305597 bool connect_timeout,
5598 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305599{
Jeff Johnson9d295242017-08-29 14:39:48 -07005600 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005601 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305602
Anurag Chouhanc4092922016-09-08 15:56:11 +05305603 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5604 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005605
Jingxiang Geb49aa302018-01-17 20:54:15 +08005606 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005607 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305608}
5609#endif
5610
5611
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005612QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005613{
Jeff Johnson9d295242017-08-29 14:39:48 -07005614 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005615#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005616 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005617#endif
5618 eConnectionState connState;
5619
5620 ENTER();
5621
Dustin Brown920397d2017-12-13 16:27:50 -08005622 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305623 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005624 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305625
Yue Ma42654682018-01-11 16:55:24 -08005626 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5627 hdd_device_mode_to_string(adapter->device_mode),
5628 adapter->device_mode);
5629
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005630 hdd_wmm_init(adapter);
5631
5632 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005633 case QDF_STA_MODE:
5634 case QDF_P2P_CLIENT_MODE:
5635 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005636
5637 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5638 ->conn_info.connState;
5639
Krunal Sonib51eec72017-11-20 21:53:01 -08005640 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005641 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005642 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005643
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005644 /* Indicate disconnect event to supplicant
5645 * if associated previously
5646 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005647 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005648 eConnectionState_IbssConnected == connState ||
5649 eConnectionState_NotConnected == connState ||
5650 eConnectionState_IbssDisconnected == connState ||
5651 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005652 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005653
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005654 memset(&wrqu, '\0', sizeof(wrqu));
5655 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5656 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5657 wireless_send_event(adapter->dev, SIOCGIWAP,
5658 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005659 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005660 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005661
5662 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305663 wlan_hdd_cfg80211_indicate_disconnect(
5664 adapter->dev, false,
5665 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005666 } else if (eConnectionState_Connecting == connState) {
5667 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005668 * Indicate connect failure to supplicant if we
5669 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005670 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305671 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305672 NULL, 0, NULL, 0,
5673 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005674 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005675 }
5676
5677 hdd_register_tx_flow_control(adapter,
5678 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005679 hdd_tx_resume_cb,
5680 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681
5682 break;
5683
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005684 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005685 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005686 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305687
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005688 break;
5689
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005690 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005691#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005692 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005693 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5694#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005695 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005696 /* event supplicant to restart */
5697 cfg80211_del_sta(adapter->dev,
5698 (const u8 *)&bcastMac.bytes[0],
5699 GFP_KERNEL);
5700#endif
5701 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305702 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005703 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305704 hdd_set_mon_rx_cb(adapter->dev);
5705 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5706 adapter->mon_bandwidth);
5707 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005708 default:
5709 break;
5710 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005711 /*
5712 * Action frame registered in one adapter which will
5713 * applicable to all interfaces
5714 */
5715 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005716 }
5717
5718 EXIT();
5719
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305720 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005721}
5722
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005723QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005724 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005725{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305726 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005727 qdf_list_node_t *node;
5728
5729 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005730
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005731 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005732 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005733 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005734
5735 if (QDF_IS_STATUS_ERROR(status))
5736 return status;
5737
5738 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5739
5740 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005741}
5742
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005743QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005744 struct hdd_adapter *current_adapter,
5745 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005746{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305747 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005748 qdf_list_node_t *node;
5749
5750 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005751
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005752 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005753 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005754 &current_adapter->node,
5755 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005756 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005757
5758 if (QDF_IS_STATUS_ERROR(status))
5759 return status;
5760
5761 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5762
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005763 return status;
5764}
5765
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005766QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005767 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005768{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305769 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005770
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005771 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005772 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005773 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005774
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005775 return status;
5776}
5777
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005778QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005779 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005780{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305781 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005782 qdf_list_node_t *node;
5783
5784 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005785
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005786 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005787 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005788 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005789
5790 if (QDF_IS_STATUS_ERROR(status))
5791 return status;
5792
5793 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5794
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005795 return status;
5796}
5797
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005798QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005799 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005800{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305801 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005802
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005803 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005804 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005805 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005807 return status;
5808}
5809
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005810QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005811 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005812{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305813 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005814
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005815 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005816 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005817 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005818
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005819 return status;
5820}
5821
Jeff Johnson9d295242017-08-29 14:39:48 -07005822struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005823 tSirMacAddr macAddr)
5824{
Jeff Johnson9d295242017-08-29 14:39:48 -07005825 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005826
Dustin Brown920397d2017-12-13 16:27:50 -08005827 hdd_for_each_adapter(hdd_ctx, adapter) {
5828 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5829 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005830 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005831 }
5832
5833 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005834}
5835
Jeff Johnson9d295242017-08-29 14:39:48 -07005836struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005837 uint32_t vdev_id)
5838{
Jeff Johnson9d295242017-08-29 14:39:48 -07005839 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005840
Dustin Brown920397d2017-12-13 16:27:50 -08005841 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005842 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005843 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005844 }
5845
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005846 return NULL;
5847}
5848
Abhishek Singh7996eb72015-12-30 17:24:02 +05305849/**
5850 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5851 * the sessionid
5852 * @hdd_ctx: hdd context.
5853 * @sme_session_id: sme session is for the adapter to get.
5854 *
5855 * This function is used to get the adapter with provided session id
5856 *
5857 * Return: adapter pointer if found
5858 *
5859 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005860struct hdd_adapter *
5861hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5862 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305863{
Jeff Johnson9d295242017-08-29 14:39:48 -07005864 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305865
Dustin Brown920397d2017-12-13 16:27:50 -08005866 hdd_for_each_adapter(hdd_ctx, adapter) {
5867 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305868 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305869 }
Dustin Brown920397d2017-12-13 16:27:50 -08005870
Abhishek Singh7996eb72015-12-30 17:24:02 +05305871 return NULL;
5872}
5873
Jeff Johnson9d295242017-08-29 14:39:48 -07005874struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005875 const char *iface_name)
5876{
Jeff Johnson9d295242017-08-29 14:39:48 -07005877 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005878
Dustin Brown920397d2017-12-13 16:27:50 -08005879 hdd_for_each_adapter(hdd_ctx, adapter) {
5880 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07005881 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005882 }
Dustin Brown920397d2017-12-13 16:27:50 -08005883
Naveen Rawat4edb6822017-04-12 10:09:17 -07005884 return NULL;
5885}
5886
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005887/**
5888 * hdd_get_adapter() - to get adapter matching the mode
5889 * @hdd_ctx: hdd context
5890 * @mode: adapter mode
5891 *
5892 * This routine will return the pointer to adapter matching
5893 * with the passed mode.
5894 *
5895 * Return: pointer to adapter or null
5896 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005897struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005898 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005899{
Jeff Johnson9d295242017-08-29 14:39:48 -07005900 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005901
Dustin Brown920397d2017-12-13 16:27:50 -08005902 hdd_for_each_adapter(hdd_ctx, adapter) {
5903 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005904 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005905 }
5906
5907 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005908}
5909
5910/**
5911 * hdd_get_operating_channel() - return operating channel of the device mode
5912 * @hdd_ctx: Pointer to the HDD context.
5913 * @mode: Device mode for which operating channel is required.
5914 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005915 * QDF_STA_MODE,
5916 * QDF_P2P_CLIENT_MODE,
5917 * QDF_SAP_MODE,
5918 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005919 *
5920 * This API returns the operating channel of the requested device mode
5921 *
5922 * Return: channel number. "0" id the requested device is not found OR it is
5923 * not connected.
5924 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005925uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005926 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005927{
Jeff Johnson9d295242017-08-29 14:39:48 -07005928 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005929 uint8_t operatingChannel = 0;
5930
Dustin Brown920397d2017-12-13 16:27:50 -08005931 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005932 if (mode == adapter->device_mode) {
5933 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005934 case QDF_STA_MODE:
5935 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005936 if (hdd_conn_is_connected
5937 (WLAN_HDD_GET_STATION_CTX_PTR
5938 (adapter))) {
5939 operatingChannel =
5940 (WLAN_HDD_GET_STATION_CTX_PTR
5941 (adapter))->conn_info.
5942 operationChannel;
5943 }
5944 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005945 case QDF_SAP_MODE:
5946 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005947 /* softap connection info */
5948 if (test_bit
5949 (SOFTAP_BSS_STARTED,
5950 &adapter->event_flags))
5951 operatingChannel =
5952 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005953 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954 break;
5955 default:
5956 break;
5957 }
5958
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005959 /* Found the device of interest. break the loop */
5960 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005961 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005962 }
Dustin Brown920397d2017-12-13 16:27:50 -08005963
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005964 return operatingChannel;
5965}
5966
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005967static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005968 hdd_ctx)
5969{
Jeff Johnson9d295242017-08-29 14:39:48 -07005970 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005971
5972 ENTER();
5973
Dustin Brown920397d2017-12-13 16:27:50 -08005974 hdd_for_each_adapter(hdd_ctx, adapter) {
5975 if (adapter->device_mode == QDF_STA_MODE ||
5976 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5977 adapter->device_mode == QDF_IBSS_MODE ||
5978 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5979 adapter->device_mode == QDF_SAP_MODE ||
5980 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005981 wlan_hdd_cfg80211_deregister_frames(adapter);
5982 hdd_unregister_wext(adapter->dev);
5983 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005984 }
5985
5986 EXIT();
5987
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305988 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005989}
5990
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005991QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005992{
Jeff Johnson9d295242017-08-29 14:39:48 -07005993 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005994
5995 ENTER();
5996
Dustin Brown920397d2017-12-13 16:27:50 -08005997 hdd_for_each_adapter(hdd_ctx, adapter) {
5998 if (adapter->device_mode == QDF_STA_MODE ||
5999 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6000 adapter->device_mode == QDF_IBSS_MODE ||
6001 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6002 adapter->device_mode == QDF_SAP_MODE ||
6003 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006004 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006005 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306006 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006007 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006008 }
6009
6010 EXIT();
6011
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306012 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006013}
6014
Dustin Brownf27bce82016-11-03 12:52:27 -07006015/**
6016 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6017 * adapters
6018 * @hdd_ctx: The HDD context containing the adapters to operate on
6019 *
6020 * return: QDF_STATUS_SUCCESS
6021 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006022static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006023{
Jeff Johnson9d295242017-08-29 14:39:48 -07006024 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006025 int err;
6026
6027 ENTER();
6028
Dustin Brown920397d2017-12-13 16:27:50 -08006029 hdd_for_each_adapter(hdd_ctx, adapter) {
6030 if (adapter->device_mode == QDF_STA_MODE ||
6031 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6032 adapter->device_mode == QDF_IBSS_MODE ||
6033 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6034 adapter->device_mode == QDF_SAP_MODE ||
6035 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006036 err = wlan_hdd_sched_scan_stop(adapter->dev);
6037 if (err)
6038 hdd_err("Unable to stop scheduled scan");
6039 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006040 }
6041
6042 EXIT();
6043
6044 return QDF_STATUS_SUCCESS;
6045}
6046
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006047#ifdef WLAN_NS_OFFLOAD
6048/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006049 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006050 * @hdd_ctx: Pointer to hdd context
6051 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006052 * Unregister for IPv6 address change notifications.
6053 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006054 * Return: None
6055 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006056static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006057{
6058 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006059}
6060
6061/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006062 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006063 * @hdd_ctx: Pointer to hdd context
6064 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006065 * Register for IPv6 address change notifications.
6066 *
6067 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006068 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006069static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006070{
6071 int ret;
6072
6073 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6074 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006075 if (ret) {
6076 hdd_err("Failed to register IPv6 notifier: %d", ret);
6077 goto out;
6078 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006079
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006080 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006081out:
6082 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006083}
6084#else
6085/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006086 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006087 * @hdd_ctx: Pointer to hdd context
6088 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006089 * Unregister for IPv6 address change notifications.
6090 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006091 * Return: None
6092 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006093static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006094{
6095}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006096
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006097/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006098 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006099 * @hdd_ctx: Pointer to hdd context
6100 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006101 * Register for IPv6 address change notifications.
6102 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006103 * Return: None
6104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006105static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006106{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006107 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006108}
6109#endif
6110
6111/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006112 * hdd_register_notifiers - Register netdev notifiers.
6113 * @hdd_ctx: HDD context
6114 *
6115 * Register netdev notifiers like IPv4 and IPv6.
6116 *
6117 * Return: 0 on success and errno on failure
6118 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006119static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006120{
6121 int ret;
6122
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006123 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6124 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306125 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006126
6127 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6128 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6129 if (ret) {
6130 hdd_err("Failed to register IPv4 notifier: %d", ret);
6131 goto unregister_ip6_notifier;
6132 }
6133
6134 return 0;
6135
6136unregister_ip6_notifier:
6137 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006138out:
6139 return ret;
6140
6141}
6142
6143/**
6144 * hdd_unregister_notifiers - Unregister netdev notifiers.
6145 * @hdd_ctx: HDD context
6146 *
6147 * Unregister netdev notifiers like IPv4 and IPv6.
6148 *
6149 * Return: None.
6150 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006151void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006152{
6153 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6154
6155 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006156}
6157
6158/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006159 * hdd_exit_netlink_services - Exit netlink services
6160 * @hdd_ctx: HDD context
6161 *
6162 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6163 * nl service.
6164 *
6165 * Return: None.
6166 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006167static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006168{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006169 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006170 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006171 ptt_sock_deactivate_svc();
6172
6173 nl_srv_exit();
6174}
6175
6176/**
6177 * hdd_init_netlink_services- Init netlink services
6178 * @hdd_ctx: HDD context
6179 *
6180 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6181 * nl service.
6182 *
6183 * Return: 0 on success and errno on failure.
6184 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006185static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006186{
6187 int ret;
6188
Ryan Hsuceddceb2016-04-28 10:20:14 -07006189 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006190 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006191 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006192 goto out;
6193 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006194 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006195
Naveen Rawat910726a2017-03-06 11:42:51 -08006196 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006197 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006198 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006199 goto err_nl_srv;
6200 }
6201
6202 ret = ptt_sock_activate_svc();
6203 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006204 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006205 goto err_nl_srv;
6206 }
6207
6208 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006209 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006210 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006211
6212 ret = cnss_diag_activate_service();
6213 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006214 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006215 goto err_close_cesium;
6216 }
6217
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006218 ret = spectral_scan_activate_service();
6219 if (ret) {
6220 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6221 goto err_close_cesium;
6222 }
6223
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006224 return 0;
6225
6226err_close_cesium:
6227 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006228 ptt_sock_deactivate_svc();
6229err_nl_srv:
6230 nl_srv_exit();
6231out:
6232 return ret;
6233}
6234
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006235/**
6236 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6237 * @hdd_ctx: HDD context.
6238 *
6239 * Destroy RX wakelock.
6240 *
6241 * Return: None.
6242 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006243static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006244{
6245 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6246}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006247
6248/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006249 * hdd_rx_wake_lock_create() - Create RX wakelock
6250 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006251 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006252 * Create RX wakelock.
6253 *
6254 * Return: None.
6255 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006256static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006257{
6258 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6259}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006260
6261/**
Houston Hoffman160db392016-10-10 17:37:51 -07006262 * hdd_context_deinit() - Deinitialize HDD context
6263 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006264 *
Houston Hoffman160db392016-10-10 17:37:51 -07006265 * Deinitialize HDD context along with all the feature specific contexts but
6266 * do not free hdd context itself. Caller of this API is supposed to free
6267 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006268 *
Houston Hoffman160db392016-10-10 17:37:51 -07006269 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006270 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006271static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006272{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306273 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6274
Houston Hoffman160db392016-10-10 17:37:51 -07006275 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006276
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006277 hdd_sap_context_destroy(hdd_ctx);
6278
6279 hdd_rx_wake_lock_destroy(hdd_ctx);
6280
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006281 hdd_scan_context_destroy(hdd_ctx);
6282
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006283 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006284
Houston Hoffman160db392016-10-10 17:37:51 -07006285 return 0;
6286}
6287
6288/**
6289 * hdd_context_destroy() - Destroy HDD context
6290 * @hdd_ctx: HDD context to be destroyed.
6291 *
6292 * Free config and HDD context as well as destroy all the resources.
6293 *
6294 * Return: None
6295 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006296static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006297{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006298 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306299
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306300 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6301
Houston Hoffman160db392016-10-10 17:37:51 -07006302 hdd_context_deinit(hdd_ctx);
6303
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306304 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006305 hdd_ctx->config = NULL;
6306
6307 wiphy_free(hdd_ctx->wiphy);
6308}
6309
6310/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306311 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6312 *
6313 * This function is used to destroy bug report lock
6314 *
6315 * Return: None
6316 */
6317static void wlan_destroy_bug_report_lock(void)
6318{
6319 p_cds_contextType p_cds_context;
6320
6321 p_cds_context = cds_get_global_context();
6322 if (!p_cds_context) {
6323 hdd_err("cds context is NULL");
6324 return;
6325 }
6326
6327 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6328}
6329
6330/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006331 * hdd_wlan_exit() - HDD WLAN exit function
6332 * @hdd_ctx: Pointer to the HDD Context
6333 *
6334 * This is the driver exit point (invoked during rmmod)
6335 *
6336 * Return: None
6337 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006338static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006340 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306341 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006342
6343 ENTER();
6344
Dustin Brown6f427922017-09-19 12:19:00 -07006345 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306346
6347 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006348
Prashanth Bhattaab004382016-10-11 16:08:11 -07006349 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006350
6351#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306352 if (QDF_TIMER_STATE_RUNNING ==
6353 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6354 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006355 }
6356
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306357 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306358 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006359 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006360 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006361 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6362 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6363 hdd_ctx->last_acs_channel_list = NULL;
6364 hdd_ctx->num_of_channels = 0;
6365 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006367
Arun Khandavallifae92942016-08-01 13:31:08 +05306368 mutex_lock(&hdd_ctx->iface_change_lock);
6369 driver_status = hdd_ctx->driver_status;
6370 mutex_unlock(&hdd_ctx->iface_change_lock);
6371
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372 /*
6373 * Powersave Offload Case
6374 * Disable Idle Power Save Mode
6375 */
6376 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006377 /* clear the scan queue in all the scenarios */
6378 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006379
Arun Khandavallifae92942016-08-01 13:31:08 +05306380 if (driver_status != DRIVER_MODULES_CLOSED) {
6381 hdd_unregister_wext_all_adapters(hdd_ctx);
6382 /*
6383 * Cancel any outstanding scan requests. We are about to close
6384 * all of our adapters, but an adapter structure is what SME
6385 * passes back to our callback function. Hence if there
6386 * are any outstanding scan requests then there is a
6387 * race condition between when the adapter is closed and
6388 * when the callback is invoked. We try to resolve that
6389 * race condition here by canceling any outstanding scans
6390 * before we close the adapters.
6391 * Note that the scans may be cancelled in an asynchronous
6392 * manner, so ideally there needs to be some kind of
6393 * synchronization. Rather than introduce a new
6394 * synchronization here, we will utilize the fact that we are
6395 * about to Request Full Power, and since that is synchronized,
6396 * the expectation is that by the time Request Full Power has
6397 * completed, all scans will be cancelled
6398 */
6399 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006400 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006401 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006402 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006403 }
6404
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306405 unregister_netdevice_notifier(&hdd_netdev_notifier);
6406
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006407 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306408
Dustin Brown021cecd2017-12-11 13:56:43 -08006409 hdd_driver_memdump_deinit();
6410
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306411 qdf_nbuf_deinit_replenish_timer();
6412
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306413 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6414 hdd_info("Release wakelock for monitor mode!");
6415 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6416 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6417 }
6418
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306419 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6420 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6421 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6422
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006423 /*
6424 * Close CDS
6425 * This frees pMac(HAL) context. There should not be any call
6426 * that requires pMac access after this.
6427 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006428
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006429 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006430
Dustin Brownd005ad82018-01-19 10:32:13 -08006431 hdd_close_all_adapters(hdd_ctx, false);
6432
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006433 hdd_ipa_cleanup(hdd_ctx);
6434
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306435 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306436 /*
6437 * If there is re_init failure wiphy would have already de-registered
6438 * check the wiphy status before un-registering again
6439 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306440 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306441 wiphy_unregister(wiphy);
6442 wlan_hdd_cfg80211_deinit(wiphy);
6443 hdd_lpass_notify_stop(hdd_ctx);
6444 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006445
Arun Khandavallifae92942016-08-01 13:31:08 +05306446 hdd_exit_netlink_services(hdd_ctx);
6447 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306448#ifdef FEATURE_WLAN_CH_AVOID
6449 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6450#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306451
Abhishek Singhe9068f12017-03-31 14:14:52 +05306452 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6453 if (driver_status)
6454 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006455
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006456 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006457}
6458
6459void __hdd_wlan_exit(void)
6460{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006461 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006462
6463 ENTER();
6464
Anurag Chouhan6d760662016-02-20 16:05:43 +05306465 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006466 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006467 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006468 EXIT();
6469 return;
6470 }
6471
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006472 /* Do all the cleanup before deregistering the driver */
6473 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006474
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006475 EXIT();
6476}
6477
6478#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006479/**
6480 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006481 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006482 *
6483 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6484 * Then new ACS request will do a fresh scan without reusing the cached
6485 * scan information.
6486 *
6487 * Return: void
6488 */
Tang Yingying523322d2017-01-17 23:28:43 +08006489static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006490{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006491 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006492
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006493 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006494 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006495 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6496 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6497 hdd_ctx->last_acs_channel_list = NULL;
6498 hdd_ctx->num_of_channels = 0;
6499 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006500
6501 if (!hdd_ctx->hHal)
6502 return;
6503 sme_scan_flush_result(hdd_ctx->hHal);
6504}
6505#endif
6506
6507#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006508int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6509 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006510{
6511 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306512 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006513 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514
6515 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6516
6517 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306518 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006519 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306520
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006521 if (!hdd_ctx->hHal)
6522 return -EINVAL;
6523
Jeff Johnsone7672e72017-10-21 15:10:04 -07006524 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006525 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306526 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006527 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006528 return -EINVAL;
6529 }
6530
6531 return 0;
6532}
6533#endif
6534
6535/**
6536 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6537 * @state: state
6538 *
6539 * This function notifies FW with modem power status
6540 *
6541 * Return: 0 if successful, error number otherwise
6542 */
6543int hdd_wlan_notify_modem_power_state(int state)
6544{
6545 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306546 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006547 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006548
Anurag Chouhan6d760662016-02-20 16:05:43 +05306549 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006550 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306551 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006552 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306553
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006554 if (!hdd_ctx->hHal)
6555 return -EINVAL;
6556
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306557 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6558 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006559 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006560 state);
6561 return -EINVAL;
6562 }
6563 return 0;
6564}
6565
6566/**
6567 *
6568 * hdd_post_cds_enable_config() - HDD post cds start config helper
6569 * @adapter - Pointer to the HDD
6570 *
6571 * Return: None
6572 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006573QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006574{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306575 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006576
6577 /*
6578 * Send ready indication to the HDD. This will kick off the MAC
6579 * into a 'running' state and should kick off an initial scan.
6580 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306581 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6582 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006583 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6584 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306585 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006586 }
6587
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306588 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006589}
6590
6591/* wake lock APIs for HDD */
6592void hdd_prevent_suspend(uint32_t reason)
6593{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306594 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006595}
6596
6597void hdd_allow_suspend(uint32_t reason)
6598{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306599 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006600}
6601
6602void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6603{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306604 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6605 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006606}
6607
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006608/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006609QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006610{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006611
Amar Singhal6f8592b2017-04-26 14:31:58 -07006612 return sme_init_chan_list(hdd_ctx->hHal,
6613 hdd_ctx->reg.alpha2,
6614 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006615}
6616
6617/**
6618 * hdd_is_5g_supported() - check if hardware supports 5GHz
6619 * @hdd_ctx: Pointer to the hdd context
6620 *
6621 * HDD function to know if hardware supports 5GHz
6622 *
6623 * Return: true if hardware supports 5GHz
6624 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006625bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006626{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006627 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006628 return true;
6629
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006630 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006631 return true;
6632 else
6633 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006634}
6635
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006636static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006637{
6638 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006639 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006640
6641 wiphy = hdd_ctx->wiphy;
6642
6643 /*
6644 * The channel information in
6645 * wiphy needs to be initialized before wiphy registration
6646 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006647 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6648 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006649 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006650 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006651 }
6652
6653#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6654 wiphy->wowlan = &wowlan_support_reg_init;
6655#else
6656 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6657 WIPHY_WOWLAN_MAGIC_PKT |
6658 WIPHY_WOWLAN_DISCONNECT |
6659 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6660 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6661 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6662 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6663 WIPHY_WOWLAN_RFKILL_RELEASE;
6664
6665 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6666 WOW_MAX_FILTERS_PER_LIST);
6667 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6668 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6669#endif
6670
6671 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006672 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306673 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006674 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306675 return ret_val;
6676 }
6677
Amar Singhal2d812012018-02-03 15:06:47 +08006678 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679
Amar Singhale4f28ee2015-10-21 14:36:56 -07006680 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006681}
6682
Mohit Khannaca4173b2017-09-12 21:52:19 -07006683#ifdef MSM_PLATFORM
6684/**
6685 * hdd_display_periodic_stats() - Function to display periodic stats
6686 * @hdd_ctx - handle to hdd context
6687 * @bool data_in_interval - true, if data detected in bw time interval
6688 *
6689 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6690 * Stats show up in wlan driver logs.
6691 *
6692 * Returns: None
6693 */
6694static inline
6695void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6696 bool data_in_interval)
6697{
6698 static u32 counter;
6699 static bool data_in_time_period;
6700 ol_txrx_pdev_handle pdev;
6701
6702 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6703 return;
6704
6705 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6706 if (!pdev) {
6707 hdd_err("pdev is NULL");
6708 return;
6709 }
6710
6711 counter++;
6712 if (data_in_interval)
6713 data_in_time_period = data_in_interval;
6714
6715 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6716 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6717 if (data_in_time_period) {
6718 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6719 CDP_TXRX_PATH_STATS,
6720 QDF_STATS_VERBOSITY_LEVEL_LOW);
6721 wlan_hdd_display_netif_queue_history
6722 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6723 qdf_dp_trace_dump_stats();
6724 }
6725 counter = 0;
6726 data_in_time_period = false;
6727 }
6728}
6729
Ravi Joshie2331e82015-07-01 18:18:54 -07006730/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006731 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006732 * @hdd_ctx - handle to hdd context
6733 * @tx_packets - transmit packet count
6734 * @rx_packets - receive packet count
6735 *
6736 * The function controls the bus bandwidth and dynamic control of
6737 * tcp delayed ack configuration
6738 *
6739 * Returns: None
6740 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006741
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006742static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006743 const uint64_t tx_packets,
6744 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006745{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006746 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006747 uint64_t temp_rx = 0;
6748 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006749 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006750 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006751 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006752 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006753 uint16_t index = 0;
6754 bool vote_level_change = false;
6755 bool rx_level_change = false;
6756 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006757
Mohit Khannaca4173b2017-09-12 21:52:19 -07006758 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006759 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006760 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006761 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006762 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006763 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006764 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006765 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006767 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006768 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6769 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006771 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006772 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306773 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306774 if (hdd_ctx->hbw_requested) {
6775 pld_remove_pm_qos(hdd_ctx->parent_dev);
6776 hdd_ctx->hbw_requested = false;
6777 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306778 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006779 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006780 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306781 if (!hdd_ctx->hbw_requested) {
6782 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6783 hdd_ctx->hbw_requested = true;
6784 }
6785
Nirav Shah3bbfa512016-05-12 16:43:49 +05306786 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006787 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006788 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006789 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006790 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006791
Mohit Khannaf8f96822017-05-17 17:11:59 -07006792 qdf_dp_trace_throttle_live_mode(
6793 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6794
Mohit Khannae71e2262015-11-10 09:37:24 -08006795 /* fine-tuning parameters for RX Flows */
6796 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6797
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006799
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306800 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6801 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6802 else
6803 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6804
Ravi Joshifed83572016-10-07 16:20:37 -07006805 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6806 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6807 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6808 next_rx_level = WLAN_SVC_TP_HIGH;
6809 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006810 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006811 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006812 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006813 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006814
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006815 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006816 struct wlan_rx_tp_data rx_tp_data = {0};
6817
Ravi Joshie2331e82015-07-01 18:18:54 -07006818 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006819 next_rx_level, temp_rx);
6820 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006821 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006822 /* Send throughput indication only if it is enabled.
6823 * Disabling tcp_del_ack will revert the tcp stack behavior
6824 * to default delayed ack. Note that this will disable the
6825 * dynamic delayed ack mechanism across the system
6826 */
6827 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006828 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6829
Mohit Khanna6272fb682017-04-13 09:34:36 -07006830 if (hdd_ctx->config->enable_tcp_adv_win_scale)
6831 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6832
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006833 rx_tp_data.level = next_rx_level;
6834 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6835 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6836 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006837 }
6838
Mohit Khannae71e2262015-11-10 09:37:24 -08006839 /* fine-tuning parameters for TX Flows */
6840 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6841 hdd_ctx->prev_tx = tx_packets;
6842 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6843 next_tx_level = WLAN_SVC_TP_HIGH;
6844 else
6845 next_tx_level = WLAN_SVC_TP_LOW;
6846
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006847 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006848 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6849 next_tx_level, temp_tx);
6850 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006851 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306852 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6853 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006854 &next_tx_level,
6855 sizeof(next_tx_level));
6856 }
6857
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006858 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006859 if (vote_level_change || tx_level_change || rx_level_change) {
6860 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6861 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6862 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6863 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6864 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6865 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6866 hdd_ctx->hdd_txrx_hist_idx++;
6867 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6868 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07006869
6870 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006871}
6872
6873#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306874static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006876 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306877 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006878 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306879 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306880 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6881 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306883 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006884 bool connected = false;
6885 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6886
Prashanth Bhattaab004382016-10-11 16:08:11 -07006887 if (wlan_hdd_validate_context(hdd_ctx))
6888 return;
6889
Jeff Johnson214671b2017-10-30 19:45:23 -07006890 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006891 goto restart_timer;
6892
Dustin Brown920397d2017-12-13 16:27:50 -08006893 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05306894 /*
6895 * Validate magic so we don't end up accessing
6896 * an invalid adapter.
6897 */
6898 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6899 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006900
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006901 if ((adapter->device_mode == QDF_STA_MODE ||
6902 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006903 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6904 != eConnectionState_Associated) {
6905
6906 continue;
6907 }
6908
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006909 if ((adapter->device_mode == QDF_SAP_MODE ||
6910 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006911 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006912
6913 continue;
6914 }
6915
6916 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6917 adapter->prev_tx_packets);
6918 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6919 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306920
6921 if (adapter->device_mode == QDF_SAP_MODE ||
6922 adapter->device_mode == QDF_P2P_GO_MODE ||
6923 adapter->device_mode == QDF_IBSS_MODE) {
6924
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006925 ret = cdp_get_intra_bss_fwd_pkts_count(
6926 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006927 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306928 &fwd_tx_packets, &fwd_rx_packets);
6929 if (ret == A_OK) {
6930 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6931 fwd_tx_packets,
6932 adapter->prev_fwd_tx_packets);
6933 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6934 fwd_tx_packets,
6935 adapter->prev_fwd_rx_packets);
6936 }
6937 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006938
6939 total_rx += adapter->stats.rx_packets;
6940 total_tx += adapter->stats.tx_packets;
6941
6942 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6943 adapter->prev_tx_packets = adapter->stats.tx_packets;
6944 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306945 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6946 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006947 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6948 connected = true;
6949 }
6950
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306951 /* add intra bss forwarded tx and rx packets */
6952 tx_packets += fwd_tx_packets_diff;
6953 rx_packets += fwd_rx_packets_diff;
6954
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006955 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6956 tx_packets += (uint64_t)ipa_tx_packets;
6957 rx_packets += (uint64_t)ipa_rx_packets;
6958
Yun Park2aa880c2017-08-22 10:58:10 -07006959 if (adapter) {
6960 adapter->stats.tx_packets += ipa_tx_packets;
6961 adapter->stats.rx_packets += ipa_rx_packets;
6962 }
6963
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006964 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006965 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006966 return;
6967 }
6968
Yuanyuan Liu13738502016-04-06 17:41:37 -07006969 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006970
6971 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6972 hdd_ipa_uc_stat_request(adapter, 2);
6973
Jingxiang Gec64e1932017-08-22 14:38:59 +08006974restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006975 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006976 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006977 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306978 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006979 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006980 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006981}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006982
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306983/**
6984 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6985 * @arg: Argument of timer function
6986 *
6987 * Schedule a workqueue in this function where all the processing is done.
6988 *
6989 * Return: None.
6990 */
6991static void __hdd_bus_bw_cbk(void *arg)
6992{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006993 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306994
6995 if (wlan_hdd_validate_context(hdd_ctx))
6996 return;
6997
6998 schedule_work(&hdd_ctx->bus_bw_work);
6999}
7000
7001/**
7002 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7003 * @arg: Argument of timer function
7004 *
7005 * Return: None.
7006 */
7007static void hdd_bus_bw_cbk(void *arg)
7008{
7009 cds_ssr_protect(__func__);
7010 __hdd_bus_bw_cbk(arg);
7011 cds_ssr_unprotect(__func__);
7012}
7013
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007014int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007015{
7016 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307017 INIT_WORK(&hdd_ctx->bus_bw_work,
7018 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007019 hdd_ctx->bus_bw_timer_running = false;
7020 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307021 qdf_timer_init(NULL,
7022 &hdd_ctx->bus_bw_timer,
7023 hdd_bus_bw_cbk, (void *)hdd_ctx,
7024 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007025
7026 return 0;
7027}
7028
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007029void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007030{
Dustin Brownfce08d12017-01-17 16:29:38 -08007031 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007032 hdd_reset_tcp_delack(hdd_ctx);
7033
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007034 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307035 cancel_work_sync(&hdd_ctx->bus_bw_work);
7036 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007037 hdd_ctx->bus_bw_timer_running = false;
7038 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007039}
Lin Baic5c06882017-09-21 13:58:43 +08007040
7041void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7042{
7043 if (hdd_ctx)
7044 cancel_work_sync(&hdd_ctx->bus_bw_work);
7045}
jiadcdaf9bd2017-10-26 12:20:21 +08007046
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007047#endif
7048
7049/**
Nirav Shahed34b212016-04-25 10:59:16 +05307050 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7051 * @hdd_ctx: hdd context
7052 *
7053 * Return: 0 for success or error code
7054 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007055static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307056{
7057 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7058 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7059 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007060 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307061 return -ENOMEM;
7062 }
7063 return 0;
7064}
7065
7066/**
7067 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7068 * @hdd_ctx: hdd context
7069 *
7070 * Return: none
7071 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007072void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307073{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307074 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7075 return;
7076
7077 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7078 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307079}
7080
Nirav Shahda008342016-05-17 18:50:40 +05307081static uint8_t *convert_level_to_string(uint32_t level)
7082{
7083 switch (level) {
7084 /* initialize the wlan sub system */
7085 case WLAN_SVC_TP_NONE:
7086 return "NONE";
7087 case WLAN_SVC_TP_LOW:
7088 return "LOW";
7089 case WLAN_SVC_TP_MEDIUM:
7090 return "MED";
7091 case WLAN_SVC_TP_HIGH:
7092 return "HIGH";
7093 default:
7094 return "INVAL";
7095 }
7096}
7097
Nirav Shahed34b212016-04-25 10:59:16 +05307098
7099/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007100 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7101 * @hdd_ctx: hdd context
7102 *
7103 * Return: none
7104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007105void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007106{
7107 int i;
7108
7109#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007110 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307111 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007112 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007113 hdd_ctx->config->busBandwidthHighThreshold,
7114 hdd_ctx->config->busBandwidthMediumThreshold,
7115 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007116 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307117 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007118 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007119 hdd_ctx->config->tcpDelackThresholdHigh,
7120 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007121 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307122 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007123#endif
7124
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007125 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307126 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7127
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007128 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007129
7130 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007131 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007132 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07007133 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007134 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7135 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007136 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007137 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7138 convert_level_to_string(
7139 hdd_ctx->hdd_txrx_hist[i].
7140 next_vote_level),
7141 convert_level_to_string(
7142 hdd_ctx->hdd_txrx_hist[i].
7143 next_rx_level),
7144 convert_level_to_string(
7145 hdd_ctx->hdd_txrx_hist[i].
7146 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007147 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007148}
7149
7150/**
7151 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7152 * @hdd_ctx: hdd context
7153 *
7154 * Return: none
7155 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007156void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007157{
7158 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307159 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7160 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007161}
7162
Mohit Khannaca4173b2017-09-12 21:52:19 -07007163/* length of the netif queue log needed per adapter */
7164#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7165
7166/**
7167 *
7168 * hdd_display_netif_queue_history_compact() - display compact netifq history
7169 * @hdd_ctx: hdd context
7170 *
7171 * Return: none
7172 */
7173static void
7174hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7175{
7176 int adapter_num = 0;
7177 int i;
7178 int bytes_written;
7179 u32 tbytes;
7180 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007181 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007182 char *comb_log_str;
7183 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007184 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007185
jiadbdefb252018-01-03 14:27:06 +08007186 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7187 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7188 if (!comb_log_str) {
7189 hdd_err("failed to alloc comb_log_str");
7190 return;
7191 }
7192
Mohit Khannaca4173b2017-09-12 21:52:19 -07007193 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007194
Dustin Brown920397d2017-12-13 16:27:50 -08007195 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007196 curr_time = qdf_system_ticks();
7197 total = curr_time - adapter->start_time;
7198 delta = curr_time - adapter->last_time;
7199
7200 if (adapter->pause_map) {
7201 pause = adapter->total_pause_time + delta;
7202 unpause = adapter->total_unpause_time;
7203 } else {
7204 unpause = adapter->total_unpause_time + delta;
7205 pause = adapter->total_pause_time;
7206 }
7207
7208 tbytes = 0;
7209 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7210 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7211 if (adapter->queue_oper_stats[i].pause_count == 0)
7212 continue;
7213 tbytes +=
7214 snprintf(
7215 &temp_str[tbytes],
7216 (tbytes >= sizeof(temp_str) ?
7217 0 : sizeof(temp_str) - tbytes),
7218 "%d(%d,%d) ",
7219 i,
7220 adapter->queue_oper_stats[i].
7221 pause_count,
7222 adapter->queue_oper_stats[i].
7223 unpause_count);
7224 }
7225 if (tbytes >= sizeof(temp_str))
7226 hdd_warn("log truncated");
7227
7228 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007229 bytes_written >= comb_log_str_size ? 0 :
7230 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007231 "[%d %d] (%d) %u/%ums %s|",
7232 adapter->session_id, adapter->device_mode,
7233 adapter->pause_map,
7234 qdf_system_ticks_to_msecs(pause),
7235 qdf_system_ticks_to_msecs(total),
7236 temp_str);
7237
Mohit Khannaca4173b2017-09-12 21:52:19 -07007238 adapter_num++;
7239 }
7240
7241 /* using QDF_TRACE to avoid printing function name */
7242 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7243 "STATS |%s", comb_log_str);
7244
jiadbdefb252018-01-03 14:27:06 +08007245 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007246 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007247
7248 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007249}
7250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007251/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007252 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007253 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007254 *
7255 * Return: none
7256 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007257void
7258wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7259 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007260{
7261
Jeff Johnson9d295242017-08-29 14:39:48 -07007262 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007263 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307264 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007265
Mohit Khannaca4173b2017-09-12 21:52:19 -07007266 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7267 hdd_display_netif_queue_history_compact(hdd_ctx);
7268 return;
7269 }
7270
Dustin Brown920397d2017-12-13 16:27:50 -08007271 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007272 hdd_debug("Netif queue operation statistics:");
7273 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007274 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007275 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307276 curr_time = qdf_system_ticks();
7277 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307278 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307279 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307280 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307281 unpause = adapter->total_unpause_time;
7282 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307283 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307284 pause = adapter->total_pause_time;
7285 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007286 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307287 qdf_system_ticks_to_msecs(total),
7288 qdf_system_ticks_to_msecs(pause),
7289 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007290 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007291
Nirav Shahda008342016-05-17 18:50:40 +05307292 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7293 qdf_time_t pause_delta = 0;
7294
7295 if (adapter->pause_map & (1 << i))
7296 pause_delta = delta;
7297
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007298 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07007299 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007300 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007301 hdd_reason_type_to_string(i),
7302 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05307303 adapter->queue_oper_stats[i].unpause_count,
7304 qdf_system_ticks_to_msecs(
7305 adapter->queue_oper_stats[i].total_pause_time +
7306 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007307 }
7308
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007309 hdd_debug("Netif queue operation history:");
7310 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307311 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7312
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007313 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007314
7315 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007316 /* using hdd_log to avoid printing function name */
7317 if (adapter->queue_oper_history[i].time == 0)
7318 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07007319 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007320 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05307321 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007322 adapter->queue_oper_history[i].time),
7323 hdd_action_type_to_string(
7324 adapter->queue_oper_history[i].netif_action),
7325 hdd_reason_type_to_string(
7326 adapter->queue_oper_history[i].netif_reason),
7327 adapter->queue_oper_history[i].pause_map);
7328 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007329 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007330}
7331
7332/**
7333 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7334 * @hdd_ctx: hdd context
7335 *
7336 * Return: none
7337 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007338void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007339{
Jeff Johnson9d295242017-08-29 14:39:48 -07007340 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007341
Dustin Brown920397d2017-12-13 16:27:50 -08007342 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307343 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007344 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307345 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007346 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307347 adapter->history_index = 0;
7348 adapter->start_time = adapter->last_time = qdf_system_ticks();
7349 adapter->total_pause_time = 0;
7350 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351 }
7352}
7353
7354/**
7355 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7356 * @halHandle: Hal handle
7357 * @pContext: Pointer to the context
7358 * @sessionId: Session ID
7359 * @scanId: Scan ID
7360 * @status: Status
7361 *
7362 * This is the callback to be executed when 11d scan is completed to flush out
7363 * the scan results
7364 *
7365 * 11d scan is done during driver load and is a passive scan on all
7366 * channels supported by the device, 11d scans may find some APs on
7367 * frequencies which are forbidden to be used in the regulatory domain
7368 * the device is operating in. If these APs are notified to the supplicant
7369 * it may try to connect to these APs, thus flush out all the scan results
7370 * which are present in SME after 11d scan is done.
7371 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307372 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007373 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307374static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007375 uint8_t sessionId, uint32_t scanId,
7376 eCsrScanStatus status)
7377{
7378 ENTER();
7379
7380 sme_scan_flush_result(halHandle);
7381
7382 EXIT();
7383
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307384 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007385}
7386
7387#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7388/**
7389 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7390 * @hdd_ctx: hdd global context
7391 *
7392 * Return: none
7393 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007394static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007395{
7396 uint8_t i;
7397
7398 mutex_init(&hdd_ctx->op_ctx.op_lock);
7399 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7400 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7401 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7402 }
7403}
7404#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007405static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007406{
7407}
7408#endif
7409
Yingying Tang95409972016-10-20 15:16:15 +08007410#ifdef WLAN_FEATURE_WOW_PULSE
7411/**
7412 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007413 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007414 * @enable: enable or disable this behaviour
7415 *
7416 * Return: int
7417 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007418static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007419{
7420 struct hdd_config *pcfg_ini = phddctx->config;
7421 struct wow_pulse_mode wow_pulse_set_info;
7422 QDF_STATUS status;
7423
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007424 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007425
7426 if (false == phddctx->config->wow_pulse_support)
7427 return 0;
7428
7429 /* prepare the request to send to SME */
7430 if (enable == true) {
7431 wow_pulse_set_info.wow_pulse_enable = true;
7432 wow_pulse_set_info.wow_pulse_pin =
7433 pcfg_ini->wow_pulse_pin;
7434 wow_pulse_set_info.wow_pulse_interval_low =
7435 pcfg_ini->wow_pulse_interval_low;
7436 wow_pulse_set_info.wow_pulse_interval_high =
7437 pcfg_ini->wow_pulse_interval_high;
7438 } else {
7439 wow_pulse_set_info.wow_pulse_enable = false;
7440 wow_pulse_set_info.wow_pulse_pin = 0;
7441 wow_pulse_set_info.wow_pulse_interval_low = 0;
7442 wow_pulse_set_info.wow_pulse_interval_high = 0;
7443 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007444 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007445 wow_pulse_set_info.wow_pulse_enable,
7446 wow_pulse_set_info.wow_pulse_pin,
7447 wow_pulse_set_info.wow_pulse_interval_low,
7448 wow_pulse_set_info.wow_pulse_interval_high);
7449
7450 status = sme_set_wow_pulse(&wow_pulse_set_info);
7451 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007452 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007453 return -EIO;
7454 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007455 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007456 return 0;
7457}
7458#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007459static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007460{
7461 return 0;
7462}
7463#endif
7464
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007465#ifdef WLAN_FEATURE_FASTPATH
7466/**
7467 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7468 * @hdd_cfg: hdd config
7469 * @context: lower layer context
7470 *
7471 * Return: none
7472 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307473void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007474 void *context)
7475{
7476 if (hdd_cfg->fastpath_enable)
7477 hif_enable_fastpath(context);
7478}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007479#endif
7480
Yuanyuan Liu13738502016-04-06 17:41:37 -07007481#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007482/**
7483 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007484 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007485 * @level: thermal level
7486 *
7487 * Change IPA data path to SW path when the thermal throttle level greater
7488 * than 0, and restore the original data path when throttle level is 0
7489 *
7490 * Return: none
7491 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007492static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007493{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007494 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007495
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007496 /* Change IPA to SW path when throttle level greater than 0 */
7497 if (level > THROTTLE_LEVEL_0)
7498 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7499 else
7500 /* restore original concurrency mode */
7501 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7502}
7503
7504/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307505 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7506 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307507 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007508 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307509 * Get a safe channel to restart SAP. PCL already takes into account the
7510 * unsafe channels. So, the PCL is validated with the ACS range to provide
7511 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007512 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307513 * Return: Channel number to restart SAP in case of success. In case of any
7514 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007515 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307516static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007517 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007518{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307519 struct sir_pcl_list pcl;
7520 QDF_STATUS status;
7521 uint32_t i, j;
7522 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007523 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307524 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007525 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007526
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307527 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7528 if (!hdd_ctx) {
7529 hdd_err("invalid HDD context");
7530 return INVALID_CHANNEL_ID;
7531 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007532
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307533 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7534 if (!hal_handle) {
7535 hdd_err("invalid HAL handle");
7536 return INVALID_CHANNEL_ID;
7537 }
7538
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007539 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7540 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007541 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7542 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307543 if (QDF_IS_STATUS_ERROR(status)) {
7544 hdd_err("Get PCL failed");
7545 return INVALID_CHANNEL_ID;
7546 }
7547
Frank Liudc2cefb2017-06-21 15:38:18 +08007548 /*
7549 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7550 * channel is unsafe channel, the pcl may be empty, instead of return,
7551 * try to choose a safe channel from acs range.
7552 */
7553 if (!pcl.pcl_len)
7554 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307555
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007556 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007557 adapter->session.ap.sap_config.acs_cfg.start_ch,
7558 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307559
7560 /* PCL already takes unsafe channel into account */
7561 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007562 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307563 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007564 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307565 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007566 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007567 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307568 return pcl.pcl_list[i];
7569 }
7570 }
7571
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007572 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307573
7574 /* Try for safe channel from all valid channel */
7575 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007576 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7577 &pcl.pcl_len);
7578 if (ret) {
7579 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307580 return INVALID_CHANNEL_ID;
7581 }
7582
7583 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007584 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307585 found = false;
7586 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007587 if (pcl.pcl_list[i] ==
7588 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007589 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307590 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007591 break;
7592 }
7593 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307594
7595 if (found)
7596 continue;
7597
7598 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007599 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307600 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007601 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007602 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307603 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007604 }
7605 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307606
7607 return INVALID_CHANNEL_ID;
7608}
7609
7610/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007611 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307612 * @adapter: AP adapter
7613 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007614 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307615 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007616 * Moves the SAP interface by invoking the function which
7617 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307618 *
7619 * Return: None
7620 */
Min Liu2fef5792018-01-19 17:59:42 +08007621void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7622 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307623{
Jeff Johnson87251032017-08-29 13:31:11 -07007624 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307625 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007626 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307627
7628 if (!adapter) {
7629 hdd_err("invalid adapter");
7630 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307632
7633 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7634
7635 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7636 if (!hal_handle) {
7637 hdd_err("invalid HAL handle");
7638 return;
7639 }
7640
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007641 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7642
Jeff Johnson91df29d2017-10-27 19:29:50 -07007643 hdd_ap_ctx->sap_config.channel = channel;
7644 hdd_ap_ctx->sap_config.ch_params.ch_width =
7645 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307646
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007647 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007648 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307649
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007650 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007651 hdd_ap_ctx->sap_config.channel,
7652 hdd_ap_ctx->sap_config.sec_ch,
7653 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307654
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007655 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007656 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007657 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007658}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307659
Jeff Johnson9d295242017-08-29 14:39:48 -07007660int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307661{
7662 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307663 int status;
7664 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307665
7666 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7667
7668 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007669 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307670 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007671 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307672 }
7673 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007674 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307675 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307676 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007677 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307678 WLAN_VENDOR_ACS_WAIT_TIME);
7679 if (qdf_status != QDF_STATUS_SUCCESS) {
7680 hdd_err("failed to start external acs timer");
7681 return -ENOSPC;
7682 }
7683 /* Update config to application */
7684 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307685 hdd_notice("Updated ACS config to nl with reason %d", reason);
7686
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307687 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307688}
7689
Agrawal Ashish467dde42016-09-08 18:44:22 +05307690/**
7691 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7692 * @hdd_ctx: hdd context pointer
7693 *
7694 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7695 * and if ACS is enabled, driver will ask userspace to restart the
7696 * sap. User space on LTE coex indication restart driver.
7697 *
7698 * Return - none
7699 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007700void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307701{
Dustin Brown920397d2017-12-13 16:27:50 -08007702 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307703 uint32_t i;
7704 bool found = false;
7705 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007706
Dustin Brown920397d2017-12-13 16:27:50 -08007707 hdd_for_each_adapter(hdd_ctxt, adapter) {
7708 if (!(adapter->device_mode == QDF_SAP_MODE &&
7709 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007710 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007711 adapter->device_mode,
7712 adapter->session.ap.sap_config.
7713 acs_cfg.acs_mode);
7714 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307715 }
7716
7717 found = false;
7718 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007719 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307720 hdd_ctxt->unsafe_channel_list[i]) {
7721 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007722 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007723 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307724 break;
7725 }
7726 }
7727
7728 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007729 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007730 adapter->session.ap.operating_channel);
7731 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307732 }
7733
Kapil Gupta8878ad92017-02-13 11:56:04 +05307734 if (hdd_ctxt->config->vendor_acs_support &&
7735 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007736 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307737 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007738 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307739 } else
7740 restart_chan =
7741 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007742 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307743 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007744 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307745 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007746 /*
7747 * SAP restart due to unsafe channel. While
7748 * restarting the SAP, make sure to clear
7749 * acs_channel, channel to reset to
7750 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307751 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007752 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307753 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007754 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307755 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007756 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307757 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7758 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007759 hdd_debug("driver to start sap: %d",
7760 hdd_ctxt->config->sap_internal_restart);
7761 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08007762 hdd_switch_sap_channel(adapter, restart_chan,
7763 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04007764 else
7765 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307766 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307767 }
7768}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307769
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007770/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007771 * hdd_init_channel_avoidance() - Initialize channel avoidance
7772 * @hdd_ctx: HDD global context
7773 *
7774 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007775 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007776 * down to the lower layers. Then subscribe to subsequent channel
7777 * avoidance events.
7778 *
7779 * Return: None
7780 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007781static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007782{
7783 uint16_t unsafe_channel_count;
7784 int index;
7785
Yuanyuan Liu13738502016-04-06 17:41:37 -07007786 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7787 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007788 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007789 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007790
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007791 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007792 hdd_ctx->unsafe_channel_count);
7793
Anurag Chouhan6d760662016-02-20 16:05:43 +05307794 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007795 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007796
7797 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007798 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007799 hdd_ctx->unsafe_channel_list[index]);
7800
7801 }
7802
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007803}
Dustin Brown676a2322017-08-15 13:16:13 -07007804
Jeff Johnson9d295242017-08-29 14:39:48 -07007805static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007806 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007807{
7808 uint8_t restart_chan;
7809
7810 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7811 if (!restart_chan) {
7812 hdd_alert("fail to restart SAP");
7813 return;
7814 }
7815
7816 /* SAP restart due to unsafe channel. While restarting
7817 * the SAP, make sure to clear acs_channel, channel to
7818 * reset to 0. Otherwise these settings will override
7819 * the ACS while restart.
7820 */
7821 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007822 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007823
7824 hdd_debug("sending coex indication");
7825
7826 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7827 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08007828 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07007829}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007830
7831int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7832 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7833{
7834 uint32_t size;
7835 uint16_t *unsafe_list;
7836 uint16_t chan_count;
7837
7838 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7839 return -EINVAL;
7840
7841 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7842 NUM_CHANNELS);
7843 if (chan_count) {
7844 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7845 unsafe_list = qdf_mem_malloc(size);
7846 if (!unsafe_list) {
7847 hdd_err("No memory for unsafe chan list size%d",
7848 size);
7849 return -ENOMEM;
7850 }
7851 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7852 } else {
7853 unsafe_list = NULL;
7854 }
7855
7856 *local_unsafe_list = unsafe_list;
7857 *local_unsafe_list_count = chan_count;
7858
7859 return 0;
7860}
7861
7862bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7863 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7864{
7865 int i, j;
7866
7867 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7868 return true;
7869 if (local_unsafe_list_count == 0)
7870 return false;
7871 for (i = 0; i < local_unsafe_list_count; i++) {
7872 for (j = 0; j < local_unsafe_list_count; j++)
7873 if (local_unsafe_list[i] ==
7874 hdd_ctx->unsafe_channel_list[j])
7875 break;
7876 if (j >= local_unsafe_list_count)
7877 break;
7878 }
7879 if (i >= local_unsafe_list_count) {
7880 hdd_info("unsafe chan list same");
7881 return false;
7882 }
7883
7884 return true;
7885}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007886#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007887static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007888{
7889}
Dustin Brown676a2322017-08-15 13:16:13 -07007890
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007891static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007892{
7893}
Dustin Brown676a2322017-08-15 13:16:13 -07007894
Jeff Johnson9d295242017-08-29 14:39:48 -07007895static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007896 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007897{
7898 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7899}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007900#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007901
7902/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007903 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7904 * user space
7905 * @frame_ind: Management frame data to be informed.
7906 *
7907 * This function is used to indicate management frame to
7908 * user space
7909 *
7910 * Return: None
7911 *
7912 */
7913void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7914{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007915 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007916 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007917 int i;
7918
Rajeev Kumard004abc2016-02-17 12:09:56 -08007919 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007920 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007921
7922 if (0 != wlan_hdd_validate_context(hdd_ctx))
7923 return;
7924
7925 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7926 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7927 adapter =
7928 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7929 if (adapter)
7930 break;
7931 }
Wu Gaoa0230a62018-01-04 20:56:57 +08007932 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
7933 hdd_for_each_adapter(hdd_ctx, adapter) {
7934 if ((NULL != adapter) &&
7935 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
7936 __hdd_indicate_mgmt_frame(adapter,
7937 frame_ind->frame_len,
7938 frame_ind->frameBuf,
7939 frame_ind->frameType,
7940 frame_ind->rxChan,
7941 frame_ind->rxRssi);
7942 }
7943 }
7944 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007945 } else {
7946 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7947 frame_ind->sessionId);
7948 }
7949
7950 if ((NULL != adapter) &&
7951 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7952 __hdd_indicate_mgmt_frame(adapter,
7953 frame_ind->frame_len,
7954 frame_ind->frameBuf,
7955 frame_ind->frameType,
7956 frame_ind->rxChan,
7957 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007958}
7959
Kapil Gupta8878ad92017-02-13 11:56:04 +05307960void hdd_acs_response_timeout_handler(void *context)
7961{
7962 struct hdd_external_acs_timer_context *timer_context =
7963 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007964 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007965 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307966 uint8_t reason;
7967
7968 ENTER();
7969 if (!timer_context) {
7970 hdd_err("invlaid timer context");
7971 return;
7972 }
7973 adapter = timer_context->adapter;
7974 reason = timer_context->reason;
7975
7976
7977 if ((!adapter) ||
7978 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7979 hdd_err("invalid adapter or adapter has invalid magic");
7980 return;
7981 }
7982 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7983 if (wlan_hdd_validate_context(hdd_ctx))
7984 return;
7985
7986 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7987 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7988 else
7989 return;
7990
7991 hdd_err("ACS timeout happened for %s reason %d",
7992 adapter->dev->name, reason);
7993 switch (reason) {
7994 /* SAP init case */
7995 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7996 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7997 false);
7998 wlan_hdd_cfg80211_start_acs(adapter);
7999 break;
8000 /* DFS detected on current channel */
8001 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8002 wlan_sap_update_next_channel(
8003 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8004 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008005 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308006 break;
8007 /* LTE coex event on current channel */
8008 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8009 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8010 break;
8011 default:
8012 hdd_info("invalid reason for timer invoke");
8013
8014 }
8015}
8016
Rajeev Kumard004abc2016-02-17 12:09:56 -08008017/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008018 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
8019 * @hdd_ctx: HDD context
8020 *
8021 * Disables all the dual mac features like DBS, Agile DFS etc.
8022 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308023 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008024 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008025static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008026{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008027 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308028 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008029
8030 if (!hdd_ctx) {
8031 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308032 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008033 }
8034
8035 cfg.scan_config = 0;
8036 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008037 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008038
8039 hdd_debug("Disabling all dual mac features...");
8040
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008041 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308042 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008043 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8044 return status;
8045 }
8046
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308047 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008048}
8049
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008050static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008051wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008052{
8053 struct policy_mgr_dual_mac_config cfg = {0};
8054 QDF_STATUS status;
8055
8056 if (!hdd_ctx) {
8057 hdd_err("HDD context is NULL");
8058 return QDF_STATUS_E_FAILURE;
8059 }
8060
8061 cfg.scan_config = 0;
8062 cfg.fw_mode_config = 0;
8063 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
8064 status = policy_mgr_get_updated_scan_and_fw_mode_config(
8065 hdd_ctx->hdd_psoc, &cfg.scan_config,
8066 &cfg.fw_mode_config,
8067 hdd_ctx->config->dual_mac_feature_disable);
8068
8069 if (status != QDF_STATUS_SUCCESS) {
8070 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
8071 status);
8072 return status;
8073 }
8074
8075 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
8076 cfg.scan_config, cfg.fw_mode_config);
8077
8078 status = sme_soc_set_dual_mac_config(cfg);
8079 if (status != QDF_STATUS_SUCCESS) {
8080 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
8081 return status;
8082 }
8083
8084 return QDF_STATUS_SUCCESS;
8085}
8086
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008087/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008088 * hdd_override_ini_config - Override INI config
8089 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008090 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008091 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008092 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008093 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008094 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008095static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008096{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008097
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008098 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8099 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008100 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008101 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008102 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008103 if (0 == enable_11d || 1 == enable_11d) {
8104 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008105 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008106 }
Leo Chang11545d62016-10-17 14:53:50 -07008107
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008108 if (!hdd_ipa_is_present(hdd_ctx)) {
Leo Chang11545d62016-10-17 14:53:50 -07008109 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008110 hdd_debug("IpaConfig override to %d",
8111 hdd_ctx->config->IpaConfig);
8112 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308113
8114 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8115 !hdd_ctx->config->enable_bcast_probe_rsp) {
8116 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8117 hdd_ctx->config->rssi_assoc_reject_enabled,
8118 hdd_ctx->config->enable_bcast_probe_rsp);
8119 hdd_ctx->config->oce_sta_enabled = 0;
8120 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008121}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008122
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008123/**
8124 * hdd_set_trace_level_for_each - Set trace level for each INI config
8125 * @hdd_ctx - HDD context
8126 *
8127 * Set trace level for each module based on INI config.
8128 *
8129 * Return: None
8130 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008131static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008132{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308133 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8134 hdd_ctx->config->qdf_trace_enable_wdi);
8135 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8136 hdd_ctx->config->qdf_trace_enable_hdd);
8137 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8138 hdd_ctx->config->qdf_trace_enable_sme);
8139 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8140 hdd_ctx->config->qdf_trace_enable_pe);
8141 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8142 hdd_ctx->config->qdf_trace_enable_wma);
8143 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8144 hdd_ctx->config->qdf_trace_enable_sys);
8145 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8146 hdd_ctx->config->qdf_trace_enable_qdf);
8147 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8148 hdd_ctx->config->qdf_trace_enable_sap);
8149 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8150 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8151 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8152 hdd_ctx->config->qdf_trace_enable_bmi);
8153 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8154 hdd_ctx->config->qdf_trace_enable_cfg);
8155 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8156 hdd_ctx->config->qdf_trace_enable_epping);
8157 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8158 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8159 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008160 hdd_ctx->config->qdf_trace_enable_txrx);
8161 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8162 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308163 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8164 hdd_ctx->config->qdf_trace_enable_htc);
8165 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8166 hdd_ctx->config->qdf_trace_enable_hif);
8167 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8168 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8169 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8170 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008171 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8172 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008173 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8174 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008175 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8176 hdd_ctx->config->qdf_trace_enable_regulatory);
8177
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008178 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008179}
8180
8181/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008182 * hdd_context_init() - Initialize HDD context
8183 * @hdd_ctx: HDD context.
8184 *
8185 * Initialize HDD context along with all the feature specific contexts.
8186 *
8187 * return: 0 on success and errno on failure.
8188 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008189static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008190{
8191 int ret;
8192
8193 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8194 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8195
8196 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308197 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008198
8199 init_completion(&hdd_ctx->mc_sus_event_var);
8200 init_completion(&hdd_ctx->ready_to_suspend);
8201
8202 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308203 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008204 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308205
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008206 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008207
8208 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8209
8210 ret = hdd_scan_context_init(hdd_ctx);
8211 if (ret)
8212 goto list_destroy;
8213
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008214 hdd_rx_wake_lock_create(hdd_ctx);
8215
8216 ret = hdd_sap_context_init(hdd_ctx);
8217 if (ret)
8218 goto scan_destroy;
8219
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008220 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8221
8222 hdd_init_offloaded_packets_ctx(hdd_ctx);
8223
8224 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8225 hdd_ctx->config);
8226 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008227 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008228
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308229 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8230 "monitor_mode_wakelock");
8231
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008232 return 0;
8233
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008234sap_destroy:
8235 hdd_sap_context_destroy(hdd_ctx);
8236
8237scan_destroy:
8238 hdd_scan_context_destroy(hdd_ctx);
8239 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008240list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008241 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008242
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008243 return ret;
8244}
8245
8246/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308247 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8248 * @hdd_ctx: pointer to hdd context
8249 *
8250 * Return: status of initialization
8251 * 0 - success
8252 * negative value - failure
8253 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008254static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308255{
8256 int ret;
8257
8258 if (!hdd_ctx->config->probe_req_ie_whitelist)
8259 return 0;
8260
8261 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8262 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8263 hdd_ctx->config->probe_req_ie_whitelist = false;
8264 return -EINVAL;
8265 }
8266
8267 /* parse ini string probe req oui */
8268 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8269 if (ret) {
8270 hdd_err("parsing error: disable ie whitelisting");
8271 hdd_ctx->config->probe_req_ie_whitelist = false;
8272 }
8273
8274 return ret;
8275}
8276
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308277
8278/**
8279 * hdd_iface_change_callback() - Function invoked when stop modules expires
8280 * @priv: pointer to hdd context
8281 *
8282 * This function is invoked when the timer waiting for the interface change
8283 * expires, it shall cut-down the power to wlan and stop all the modules.
8284 *
8285 * Return: void
8286 */
8287static void hdd_iface_change_callback(void *priv)
8288{
8289 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8290 int ret;
8291 int status = wlan_hdd_validate_context(hdd_ctx);
8292
8293 if (status)
8294 return;
8295
8296 ENTER();
8297 hdd_debug("Interface change timer expired close the modules!");
8298 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8299 if (ret)
8300 hdd_err("Failed to stop modules");
8301 EXIT();
8302}
8303
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308304/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008305 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308306 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008307 *
8308 * Allocate and initialize HDD context. HDD context is allocated as part of
8309 * wiphy allocation and then context is initialized.
8310 *
8311 * Return: HDD context on success and ERR_PTR on failure
8312 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008313static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008314{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308315 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008316 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008317 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008318
8319 ENTER();
8320
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008321 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008322 if (hdd_ctx == NULL) {
8323 ret = -ENOMEM;
8324 goto err_out;
8325 }
8326
Dustin Brown6f427922017-09-19 12:19:00 -07008327 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8328 hdd_iface_change_callback,
8329 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308330
8331 mutex_init(&hdd_ctx->iface_change_lock);
8332
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008333 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308334 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008335
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308336 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008337 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008338 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008339 ret = -ENOMEM;
8340 goto err_free_hdd_context;
8341 }
8342
8343 /* Read and parse the qcom_cfg.ini file */
8344 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308345 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308346 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008347 WLAN_INI_FILE);
8348 ret = -EINVAL;
8349 goto err_free_config;
8350 }
8351
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308352 ie_whitelist_attrs_init(hdd_ctx);
8353
Dustin Brown7f939932017-05-18 15:02:17 -07008354 hdd_debug("setting timer multiplier: %u",
8355 hdd_ctx->config->timer_multiplier);
8356 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8357
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008358
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308359 if (hdd_ctx->config->fhostNSOffload)
8360 hdd_ctx->ns_offload_enable = true;
8361
Abhishek Singh5ea86532016-04-27 14:10:53 +05308362 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8363
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008364 hdd_override_ini_config(hdd_ctx);
8365
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008366 ret = hdd_context_init(hdd_ctx);
8367
8368 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008369 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008370
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008371 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308372 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008373
Anurag Chouhan6d760662016-02-20 16:05:43 +05308374 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008375 goto skip_multicast_logging;
8376
8377 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8378
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008379 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8380 if (ret)
8381 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308382
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008383 ret = hdd_init_netlink_services(hdd_ctx);
8384 if (ret)
8385 goto err_deinit_txrx_histogram;
8386
Dustin Brown7b3dea22017-07-10 13:02:47 -07008387 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
8388 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05308389
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008390skip_multicast_logging:
8391 hdd_set_trace_level_for_each(hdd_ctx);
8392
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008393 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8394
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008395 EXIT();
8396
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008397 return hdd_ctx;
8398
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008399err_deinit_txrx_histogram:
8400 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8401
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008402err_deinit_hdd_context:
8403 hdd_context_deinit(hdd_ctx);
8404
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008405err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308406 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008407
8408err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308409 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008410 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008411
8412err_out:
8413 return ERR_PTR(ret);
8414}
8415
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008416#ifdef WLAN_OPEN_P2P_INTERFACE
8417/**
8418 * hdd_open_p2p_interface - Open P2P interface
8419 * @hdd_ctx: HDD context
8420 * @rtnl_held: True if RTNL lock held
8421 *
8422 * Open P2P interface during probe. This function called to open the P2P
8423 * interface at probe along with STA interface.
8424 *
8425 * Return: 0 on success and errno on failure
8426 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008427static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008428{
Jeff Johnson9d295242017-08-29 14:39:48 -07008429 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008430 uint8_t *p2p_dev_addr;
8431
8432 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8433 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008434 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008435 hdd_ctx->config->intfMacAddr[0].bytes,
8436 sizeof(tSirMacAddr));
8437
8438 /*
8439 * Generate the P2P Device Address. This consists of
8440 * the device's primary MAC address with the locally
8441 * administered bit set.
8442 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008443 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008444 } else {
8445 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8446 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008447 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008448 return -ENOSPC;
8449 }
8450
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008451 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8452 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008453 }
8454
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008455 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008456 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008457 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008458
8459 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008460 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008461 return -ENOSPC;
8462 }
8463
8464 return 0;
8465}
8466#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008467static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008468 bool rtnl_held)
8469{
8470 return 0;
8471}
8472#endif
8473
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008474static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008475{
Jeff Johnson9d295242017-08-29 14:39:48 -07008476 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008477 int ret = 0;
8478
8479 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8480 wlan_hdd_get_intf_addr(hdd_ctx),
8481 NET_NAME_UNKNOWN, rtnl_held);
8482 if (adapter == NULL) {
8483 hdd_err("Failed to open 802.11p interface");
8484 ret = -ENOSPC;
8485 }
8486
8487 return ret;
8488}
8489
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008490/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308491 * hdd_start_station_adapter()- Start the Station Adapter
8492 * @adapter: HDD adapter
8493 *
8494 * This function initializes the adapter for the station mode.
8495 *
8496 * Return: 0 on success or errno on failure.
8497 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008498int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308499{
8500 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008501 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308502
8503 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008504 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8505 hdd_err("session is already opened, %d",
8506 adapter->session_id);
8507 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8508 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308509
Krunal Sonib51eec72017-11-20 21:53:01 -08008510 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8511 if (ret) {
8512 hdd_err("failed to create vdev: %d", ret);
8513 return ret;
8514 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308515 status = hdd_init_station_mode(adapter);
8516
8517 if (QDF_STATUS_SUCCESS != status) {
8518 hdd_err("Error Initializing station mode: %d", status);
8519 return qdf_status_to_os_return(status);
8520 }
8521
Arun Khandavallifae92942016-08-01 13:31:08 +05308522 hdd_register_tx_flow_control(adapter,
8523 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008524 hdd_tx_resume_cb,
8525 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308526
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308527 EXIT();
8528 return 0;
8529}
8530
8531/**
8532 * hdd_start_ap_adapter()- Start AP Adapter
8533 * @adapter: HDD adapter
8534 *
8535 * This function initializes the adapter for the AP mode.
8536 *
8537 * Return: 0 on success errno on failure.
8538 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008539int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308540{
8541 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008542 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008543 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008544 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308545
8546 ENTER();
8547
Krunal Sonib51eec72017-11-20 21:53:01 -08008548 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8549 hdd_err("session is already opened, %d",
8550 adapter->session_id);
8551 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8552 }
8553 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008554 * In SSR case no need to create new sap context.
8555 * Otherwise create sap context first and then create
8556 * vdev as while creating the vdev, driver needs to
8557 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008558 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008559 if (adapter->session.ap.sap_context) {
8560 is_ssr = true;
8561 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008562 hdd_err("sap creation failed");
8563 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8564 }
8565
8566 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8567 adapter->session.ap.sap_context);
8568 if (ret) {
8569 hdd_err("failed to create vdev, status:%d", ret);
8570 hdd_sap_destroy_ctx(adapter);
8571 return ret;
8572 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008573
8574 if (adapter->device_mode == QDF_SAP_MODE)
8575 sme_cli_set_command(adapter->session_id,
8576 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8577 (bool)(hdd_ctx->config->fine_time_meas_cap &
8578 WMI_FW_AP_RTT_RESPR),
8579 VDEV_CMD);
8580
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008581 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308582
8583 if (QDF_STATUS_SUCCESS != status) {
8584 hdd_err("Error Initializing the AP mode: %d", status);
8585 return qdf_status_to_os_return(status);
8586 }
8587
Arun Khandavallifae92942016-08-01 13:31:08 +05308588 hdd_register_tx_flow_control(adapter,
8589 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008590 hdd_softap_tx_resume_cb,
8591 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308592
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308593 EXIT();
8594 return 0;
8595}
8596
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308597static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8598 bool rtnl_held)
8599{
8600 struct hdd_adapter *adapter;
8601
8602 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8603 hdd_ctx->config->enableConcurrentSTA,
8604 wlan_hdd_get_intf_addr(hdd_ctx),
8605 NET_NAME_UNKNOWN, rtnl_held);
8606
8607 if (!adapter)
8608 return -ENOSPC;
8609
8610 return 0;
8611}
8612
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308613/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008614 * hdd_open_interfaces - Open all required interfaces
8615 * hdd_ctx: HDD context
8616 * rtnl_held: True if RTNL lock is held
8617 *
8618 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8619 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008620 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008621 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008622static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008623{
Jeff Johnson9d295242017-08-29 14:39:48 -07008624 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008625 int ret;
8626
Ravi Joshia307f632017-07-17 23:41:41 -07008627 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008628 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8629 con_mode == QDF_GLOBAL_FTM_MODE) {
8630 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8631 QDF_MONITOR_MODE : QDF_FTM_MODE;
8632
8633 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8634 wlan_hdd_get_intf_addr(hdd_ctx),
8635 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008636 if (!adapter) {
8637 hdd_err("open adapter failed");
8638 return -ENOSPC;
8639 }
Lin Bai1c678482017-12-18 18:29:11 +08008640
Ravi Joshia307f632017-07-17 23:41:41 -07008641 return 0;
8642 }
8643
Jeff Johnson957bc272017-02-02 08:54:48 -08008644 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308645 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008646 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008647
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008648 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008649 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008650 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008651
8652 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008653 return -ENOSPC;
8654
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308655 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8656 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8657 if (ret)
8658 hdd_err("Cannot create concurrent STA interface");
8659 }
8660
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008661 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8662 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008663 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008664
8665 /* Open 802.11p Interface */
8666 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008667 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8668 if (ret)
8669 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008670 }
8671
Jeff Johnson957bc272017-02-02 08:54:48 -08008672 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008673
Jeff Johnson957bc272017-02-02 08:54:48 -08008674err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008675 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008676 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008677}
8678
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008679
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308680#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8681/**
8682 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8683 * @cds_cfg: CDS Configuration
8684 * @hdd_ctx: Pointer to hdd context
8685 *
8686 * Return: none
8687 */
8688static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8689 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008690 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308691{
8692 cds_cfg->tx_flow_stop_queue_th =
8693 hdd_ctx->config->TxFlowStopQueueThreshold;
8694 cds_cfg->tx_flow_start_queue_offset =
8695 hdd_ctx->config->TxFlowStartQueueOffset;
8696}
8697#else
8698static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8699 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008700 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308701{
8702}
8703#endif
8704
8705#ifdef FEATURE_WLAN_RA_FILTERING
8706/**
8707 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8708 * @cds_cfg: CDS Configuration
8709 * @hdd_ctx: Pointer to hdd context
8710 *
8711 * Return: none
8712 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308713static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008714 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308715{
8716 cds_cfg->ra_ratelimit_interval =
8717 hdd_ctx->config->RArateLimitInterval;
8718 cds_cfg->is_ra_ratelimit_enabled =
8719 hdd_ctx->config->IsRArateLimitEnabled;
8720}
8721#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308722static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008723 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308724{
8725}
8726#endif
8727
8728/**
8729 * hdd_update_cds_config() - API to update cds configuration parameters
8730 * @hdd_ctx: HDD Context
8731 *
8732 * Return: 0 for Success, errno on failure
8733 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008734static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308735{
8736 struct cds_config_info *cds_cfg;
8737
8738 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8739 if (!cds_cfg) {
8740 hdd_err("failed to allocate cds config");
8741 return -ENOMEM;
8742 }
8743
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008744 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008745 if (!hdd_ctx->config->nMaxPsPoll ||
8746 !hdd_ctx->config->enablePowersaveOffload) {
8747 cds_cfg->powersave_offload_enabled =
8748 hdd_ctx->config->enablePowersaveOffload;
8749 } else {
8750 if ((hdd_ctx->config->enablePowersaveOffload ==
8751 PS_QPOWER_NODEEPSLEEP) ||
8752 (hdd_ctx->config->enablePowersaveOffload ==
8753 PS_LEGACY_NODEEPSLEEP))
8754 cds_cfg->powersave_offload_enabled =
8755 PS_LEGACY_NODEEPSLEEP;
8756 else
8757 cds_cfg->powersave_offload_enabled =
8758 PS_LEGACY_DEEPSLEEP;
8759 hdd_info("Qpower disabled in cds config, %d",
8760 cds_cfg->powersave_offload_enabled);
8761 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308762 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8763 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8764 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8765 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8766 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8767
8768 /* Here ol_ini_info is used to store ini status of arp offload
8769 * ns offload and others. Currently 1st bit is used for arp
8770 * off load and 2nd bit for ns offload currently, rest bits are unused
8771 */
8772 if (hdd_ctx->config->fhostArpOffload)
8773 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8774 if (hdd_ctx->config->fhostNSOffload)
8775 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8776
8777 /*
8778 * Copy the DFS Phyerr Filtering Offload status.
8779 * This parameter reflects the value of the
8780 * dfs_phyerr_filter_offload flag as set in the ini.
8781 */
8782 cds_cfg->dfs_phyerr_filter_offload =
8783 hdd_ctx->config->fDfsPhyerrFilterOffload;
8784 if (hdd_ctx->config->ssdp)
8785 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8786
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308787 cds_cfg->force_target_assert_enabled =
8788 hdd_ctx->config->crash_inject_enabled;
8789
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308790 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8791 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8792
8793 cds_cfg->ap_maxoffload_reorderbuffs =
8794 hdd_ctx->config->apMaxOffloadReorderBuffs;
8795
8796 cds_cfg->ap_disable_intrabss_fwd =
8797 hdd_ctx->config->apDisableIntraBssFwd;
8798
8799 cds_cfg->dfs_pri_multiplier =
8800 hdd_ctx->config->dfsRadarPriMultiplier;
8801 cds_cfg->reorder_offload =
8802 hdd_ctx->config->reorderOffloadSupport;
8803
8804 /* IPA micro controller data path offload resource config item */
8805 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008806 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8807 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008808 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008809 hdd_ctx->config->IpaUcTxBufCount);
8810 hdd_ctx->config->IpaUcTxBufCount =
8811 rounddown_pow_of_two(
8812 hdd_ctx->config->IpaUcTxBufCount);
8813 if (!hdd_ctx->config->IpaUcTxBufCount) {
8814 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308815 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008816 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008817 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008818 hdd_ctx->config->IpaUcTxBufCount);
8819 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308820 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8821 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008822 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8823 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008824 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008825 hdd_ctx->config->IpaUcRxIndRingCount);
8826 hdd_ctx->config->IpaUcRxIndRingCount =
8827 rounddown_pow_of_two(
8828 hdd_ctx->config->IpaUcRxIndRingCount);
8829 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8830 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308831 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008832 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008833 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008834 hdd_ctx->config->IpaUcRxIndRingCount);
8835 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308836 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008837 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308838 cds_cfg->uc_tx_partition_base =
8839 hdd_ctx->config->IpaUcTxPartitionBase;
8840 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8841
8842 cds_cfg->ip_tcp_udp_checksum_offload =
8843 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008844 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308845 cds_cfg->ce_classify_enabled =
8846 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008847 cds_cfg->bpf_packet_filter_enable =
8848 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308849 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8850 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8851 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008852 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008853 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008854 cds_cfg->max_msdus_per_rxinorderind =
8855 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008856 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008857 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308858 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8859 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308860 cds_cfg->auto_power_save_fail_mode =
8861 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308862
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308863 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008864 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308865
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308866 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8867 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8868 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008869 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308870 cds_init_ini_config(cds_cfg);
8871 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308872
8873exit:
8874 qdf_mem_free(cds_cfg);
8875 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308876}
8877
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008878/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008879 * hdd_update_user_config() - API to update user configuration
8880 * parameters to obj mgr which are used by multiple components
8881 * @hdd_ctx: HDD Context
8882 *
8883 * Return: 0 for Success, errno on failure
8884 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008885static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008886{
8887 struct wlan_objmgr_psoc_user_config *user_config;
8888
8889 user_config = qdf_mem_malloc(sizeof(*user_config));
8890 if (user_config == NULL) {
8891 hdd_alert("Failed to alloc memory for user_config!");
8892 return -ENOMEM;
8893 }
8894
8895 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8896 user_config->dual_mac_feature_disable =
8897 hdd_ctx->config->dual_mac_feature_disable;
8898 user_config->indoor_channel_support =
8899 hdd_ctx->config->indoor_channel_support;
8900 user_config->is_11d_support_enabled =
8901 hdd_ctx->config->Is11dSupportEnabled;
8902 user_config->is_11h_support_enabled =
8903 hdd_ctx->config->Is11hSupportEnabled;
8904 user_config->optimize_chan_avoid_event =
8905 hdd_ctx->config->goptimize_chan_avoid_event;
8906 user_config->skip_dfs_chnl_in_p2p_search =
8907 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008908 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008909 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8910
8911 qdf_mem_free(user_config);
8912 return 0;
8913}
8914
8915/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008916 * hdd_init_thermal_info - Initialize thermal level
8917 * @hdd_ctx: HDD context
8918 *
8919 * Initialize thermal level at SME layer and set the thermal level callback
8920 * which would be called when a configured thermal threshold is hit.
8921 *
8922 * Return: 0 on success and errno on failure
8923 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008924static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008925{
8926 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308927 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008928
8929 thermal_param.smeThermalMgmtEnabled =
8930 hdd_ctx->config->thermalMitigationEnable;
8931 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8932
Poddar, Siddarth83905022016-04-16 17:56:08 -07008933 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8934 hdd_ctx->config->throttle_dutycycle_level0;
8935 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8936 hdd_ctx->config->throttle_dutycycle_level1;
8937 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8938 hdd_ctx->config->throttle_dutycycle_level2;
8939 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8940 hdd_ctx->config->throttle_dutycycle_level3;
8941
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008942 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8943 hdd_ctx->config->thermalTempMinLevel0;
8944 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8945 hdd_ctx->config->thermalTempMaxLevel0;
8946 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8947 hdd_ctx->config->thermalTempMinLevel1;
8948 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8949 hdd_ctx->config->thermalTempMaxLevel1;
8950 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8951 hdd_ctx->config->thermalTempMinLevel2;
8952 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8953 hdd_ctx->config->thermalTempMaxLevel2;
8954 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8955 hdd_ctx->config->thermalTempMinLevel3;
8956 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8957 hdd_ctx->config->thermalTempMaxLevel3;
8958
8959 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8960
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308961 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308962 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008963
8964 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8965 hdd_set_thermal_level_cb);
8966
8967 return 0;
8968
8969}
8970
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008971#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8972/**
8973 * hdd_hold_rtnl_lock - Hold RTNL lock
8974 *
8975 * Hold RTNL lock
8976 *
8977 * Return: True if held and false otherwise
8978 */
8979static inline bool hdd_hold_rtnl_lock(void)
8980{
8981 rtnl_lock();
8982 return true;
8983}
8984
8985/**
8986 * hdd_release_rtnl_lock - Release RTNL lock
8987 *
8988 * Release RTNL lock
8989 *
8990 * Return: None
8991 */
8992static inline void hdd_release_rtnl_lock(void)
8993{
8994 rtnl_unlock();
8995}
8996#else
8997static inline bool hdd_hold_rtnl_lock(void) { return false; }
8998static inline void hdd_release_rtnl_lock(void) { }
8999#endif
9000
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009001#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009002
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309003/* MAX iwpriv command support */
9004#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309005#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309006#define MAX_PKTLOG_SIZE 16
9007
9008/**
9009 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9010 * @hdd_ctx: hdd context
9011 * @set_value2: pktlog buffer size value
9012 *
9013 *
9014 * Return: 0 for success or error.
9015 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009016static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309017{
9018 struct sir_wifi_start_log start_log = { 0 };
9019 QDF_STATUS status;
9020
9021 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9022 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9023 start_log.ini_triggered = cds_is_packet_log_enabled();
9024 start_log.user_triggered = 1;
9025 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309026 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309027
9028 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9029 if (!QDF_IS_STATUS_SUCCESS(status)) {
9030 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9031 EXIT();
9032 return -EINVAL;
9033 }
9034
9035 return 0;
9036}
9037
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009038/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309039 * hdd_pktlog_clear_buff() - clear pktlog buffer
9040 * @hdd_ctx: hdd context
9041 *
9042 * Return: 0 for success or error.
9043 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009044static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309045{
9046 struct sir_wifi_start_log start_log;
9047 QDF_STATUS status;
9048
9049 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9050 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9051 start_log.ini_triggered = cds_is_packet_log_enabled();
9052 start_log.user_triggered = 1;
9053 start_log.size = 0;
9054 start_log.is_pktlog_buff_clear = true;
9055
9056 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9057 if (!QDF_IS_STATUS_SUCCESS(status)) {
9058 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9059 EXIT();
9060 return -EINVAL;
9061 }
9062
9063 return 0;
9064}
9065
9066
9067/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009068 * hdd_process_pktlog_command() - process pktlog command
9069 * @hdd_ctx: hdd context
9070 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309071 * @set_value2: pktlog buffer size value
9072 *
9073 * This function process pktlog command.
9074 * set_value2 only matters when set_value is 3 (set buff size)
9075 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009076 *
9077 * Return: 0 for success or error.
9078 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009079int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309080 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009081{
9082 int ret;
9083 bool enable;
9084 uint8_t user_triggered = 0;
9085
9086 ret = wlan_hdd_validate_context(hdd_ctx);
9087 if (0 != ret)
9088 return ret;
9089
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009090 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009091
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309092 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009093 hdd_err("invalid pktlog value %d", set_value);
9094 return -EINVAL;
9095 }
9096
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309097 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9098 if (set_value2 <= 0) {
9099 hdd_err("invalid pktlog size %d", set_value2);
9100 return -EINVAL;
9101 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9102 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9103 return -EINVAL;
9104 }
9105 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309106 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9107 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309108 }
9109
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009110 /*
9111 * set_value = 0 then disable packetlog
9112 * set_value = 1 enable packetlog forcefully
9113 * set_vlaue = 2 then disable packetlog if disabled through ini or
9114 * enable packetlog with AUTO type.
9115 */
9116 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9117 true : false;
9118
9119 if (1 == set_value) {
9120 enable = true;
9121 user_triggered = 1;
9122 }
9123
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309124 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009125}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009126
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009127/**
9128 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9129 * @hdd_ctx: HDD context
9130 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309131 * @user_triggered: triggered through iwpriv
9132 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009133 *
9134 * Return: 0 on success; error number otherwise
9135 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009136int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309137 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009138{
9139 struct sir_wifi_start_log start_log;
9140 QDF_STATUS status;
9141
9142 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9143 start_log.verbose_level =
9144 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009145 start_log.ini_triggered = cds_is_packet_log_enabled();
9146 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309147 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309148 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309149 /*
9150 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9151 * commands. Host uses this flag to decide whether to send pktlog
9152 * disable command to fw without sending pktlog enable command
9153 * previously. For eg, If vendor sends pktlog disable command without
9154 * sending pktlog enable command, then host discards the packet
9155 * but for iwpriv command, host will send it to fw.
9156 */
9157 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009158 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9159 if (!QDF_IS_STATUS_SUCCESS(status)) {
9160 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
9161 EXIT();
9162 return -EINVAL;
9163 }
9164
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309165 if (enable == true)
9166 hdd_ctx->is_pktlog_enabled = 1;
9167 else
9168 hdd_ctx->is_pktlog_enabled = 0;
9169
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009170 return 0;
9171}
9172#endif /* REMOVE_PKT_LOG */
9173
Komal Seelam92fff912016-03-24 11:51:41 +05309174/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009175 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9176 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309177 * @dev: Device Pointer
9178 * @num: Number of Valid Mac address
9179 *
9180 * Return: Pointer to MAC address buffer
9181 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009182static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9183 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309184{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009185 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309186}
Komal Seelam92fff912016-03-24 11:51:41 +05309187
9188/**
9189 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9190 * @hdd_ctx: HDD Context
9191 * @num: Number of random mac addresses needed
9192 *
9193 * Generate random addresses using bit manipulation on the base mac address
9194 *
9195 * Return: None
9196 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009197void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309198{
9199 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9200 uint32_t iter;
9201 struct hdd_config *ini = hdd_ctx->config;
9202 uint8_t *buf = NULL;
9203 uint8_t macaddr_b3, tmp_br3;
9204 uint8_t *src = ini->intfMacAddr[0].bytes;
9205
9206 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9207 buf = ini->intfMacAddr[iter].bytes;
9208 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9209 macaddr_b3 = buf[3];
9210 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9211 INTF_MACADDR_MASK;
9212 macaddr_b3 += tmp_br3;
9213 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9214 buf[0] |= 0x02;
9215 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009216 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309217 }
9218}
9219
9220/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009221 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309222 * @hdd_ctx: HDD Context
9223 *
9224 * API to get mac addresses from platform driver and update the driver
9225 * structures and configure FW with the base mac address.
9226 * Return: int
9227 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009228static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309229{
9230 uint32_t no_of_mac_addr, iter;
9231 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9232 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9233 uint8_t *addr, *buf;
9234 struct device *dev = hdd_ctx->parent_dev;
9235 struct hdd_config *ini = hdd_ctx->config;
9236 tSirMacAddr mac_addr;
9237 QDF_STATUS status;
9238
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009239 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309240
9241 if (no_of_mac_addr == 0 || !addr) {
9242 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9243 return -EINVAL;
9244 }
9245
9246 if (no_of_mac_addr > max_mac_addr)
9247 no_of_mac_addr = max_mac_addr;
9248
9249 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9250
9251 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9252 buf = ini->intfMacAddr[iter].bytes;
9253 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009254 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309255 }
9256
9257 status = sme_set_custom_mac_addr(mac_addr);
9258
9259 if (!QDF_IS_STATUS_SUCCESS(status))
9260 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009261
Komal Seelam92fff912016-03-24 11:51:41 +05309262 if (no_of_mac_addr < max_mac_addr)
9263 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9264 no_of_mac_addr);
9265 return 0;
9266}
9267
9268/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009269 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9270 * @hdd_ctx: HDD Context
9271 *
9272 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9273 * will generate its own MAC and update it to FW.
9274 *
9275 * Return: 0 for success
9276 * Non-zero error code for failure
9277 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009278static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009279{
9280 tSirMacAddr customMacAddr;
9281 QDF_STATUS status;
9282
9283 qdf_mem_copy(&customMacAddr,
9284 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9285 sizeof(tSirMacAddr));
9286 status = sme_set_custom_mac_addr(customMacAddr);
9287 if (!QDF_IS_STATUS_SUCCESS(status))
9288 return -EAGAIN;
9289 return 0;
9290}
9291
9292/**
Komal Seelam92fff912016-03-24 11:51:41 +05309293 * hdd_initialize_mac_address() - API to get wlan mac addresses
9294 * @hdd_ctx: HDD Context
9295 *
9296 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9297 * is provisioned with mac addresses, driver uses it, else it will use
9298 * wlan_mac.bin to update HW MAC addresses.
9299 *
9300 * Return: None
9301 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009302static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309303{
9304 QDF_STATUS status;
9305 int ret;
9306
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009307 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309308 if (ret == 0)
9309 return;
9310
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009311 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9312 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309313
9314 status = hdd_update_mac_config(hdd_ctx);
9315
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009316 if (QDF_IS_STATUS_SUCCESS(status))
9317 return;
9318
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009319 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9320 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009321
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009322 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009323 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009324 if (ret != 0) {
9325 hdd_err("MAC address out-of-sync, ret:%d", ret);
9326 QDF_ASSERT(ret);
9327 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009328 }
Komal Seelam92fff912016-03-24 11:51:41 +05309329}
9330
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009331static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009332{
9333 int vdev_id = 0;
9334 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9335 int value = hdd_ctx->config->smart_chainmask_enabled;
9336 int vpdev = PDEV_CMD;
9337 int ret;
9338
Naveen Rawat247a8682017-06-05 15:00:31 -07009339 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009340 if (ret)
9341 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9342
9343 return ret;
9344}
9345
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009346static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009347{
9348 int vdev_id = 0;
9349 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9350 int value = hdd_ctx->config->alternative_chainmask_enabled;
9351 int vpdev = PDEV_CMD;
9352 int ret;
9353
Naveen Rawat247a8682017-06-05 15:00:31 -07009354 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009355 if (ret)
9356 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9357 ret);
9358
9359 return ret;
9360}
9361
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009362static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009363{
9364 int vdev_id = 0;
9365 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9366 int value = hdd_ctx->config->ani_enabled;
9367 int vpdev = PDEV_CMD;
9368 int ret;
9369
Naveen Rawat247a8682017-06-05 15:00:31 -07009370 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009371 if (ret)
9372 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9373
9374 return ret;
9375}
9376
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009377/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009378 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9379 * @hdd_ctx: HDD context
9380 *
9381 * Pre configurations to be done at lower layer before calling cds enable.
9382 *
9383 * Return: 0 on success and errno on failure.
9384 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009385static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009386{
9387 int ret;
9388 QDF_STATUS status;
9389 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009390 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009391
Leo Changfdb45c32016-10-28 11:09:23 -07009392 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009393 /*
9394 * Set 802.11p config
9395 * TODO-OCB: This has been temporarily added here to ensure this
9396 * parameter is set in CSR when we init the channel list. This should
9397 * be removed once the 5.9 GHz channels are added to the regulatory
9398 * domain.
9399 */
9400 hdd_set_dot11p_config(hdd_ctx);
9401
9402 /*
9403 * Note that the cds_pre_enable() sequence triggers the cfg download.
9404 * The cfg download must occur before we update the SME config
9405 * since the SME config operation must access the cfg database
9406 */
9407 status = hdd_set_sme_config(hdd_ctx);
9408
9409 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009410 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009411 ret = qdf_status_to_os_return(status);
9412 goto out;
9413 }
9414
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009415 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9416 if (QDF_STATUS_SUCCESS != status) {
9417 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9418 ret = qdf_status_to_os_return(status);
9419 goto out;
9420 }
9421
Naveen Rawat247a8682017-06-05 15:00:31 -07009422 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009423 hdd_ctx->config->tx_chain_mask_1ss,
9424 PDEV_CMD);
9425 if (0 != ret) {
9426 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9427 goto out;
9428 }
9429
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009430 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9431 if (ret)
9432 goto out;
9433
9434 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9435 if (ret)
9436 goto out;
9437
Jeff Johnson12a744b2017-04-04 08:19:37 -07009438 ret = hdd_set_ani_enabled(hdd_ctx);
9439 if (ret)
9440 goto out;
9441
Naveen Rawat247a8682017-06-05 15:00:31 -07009442 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009443 hdd_ctx->config->arp_ac_category,
9444 PDEV_CMD);
9445 if (0 != ret) {
9446 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9447 hdd_ctx->config->arp_ac_category, ret);
9448 goto out;
9449 }
9450
Prashanth Bhatta07998752016-04-28 12:35:33 -07009451 status = hdd_set_sme_chan_list(hdd_ctx);
9452 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009453 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009454 ret = qdf_status_to_os_return(status);
9455 goto out;
9456 }
9457
9458 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009459 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009460 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009461 ret = -EINVAL;
9462 goto out;
9463 }
9464
Prashanth Bhatta07998752016-04-28 12:35:33 -07009465 /*
9466 * Set the MAC Address Currently this is used by HAL to add self sta.
9467 * Remove this once self sta is added as part of session open.
9468 */
9469 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9470 hdd_ctx->config->intfMacAddr[0].bytes,
9471 sizeof(hdd_ctx->config->intfMacAddr[0]));
9472
9473 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9474 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9475 hal_status, hal_status);
9476 ret = -EINVAL;
9477 goto out;
9478 }
9479
9480 hdd_init_channel_avoidance(hdd_ctx);
9481
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309482 /* update enable sap mandatory chan list */
9483 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9484 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009485out:
9486 return ret;
9487}
9488
9489/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009490 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9491 * @context_ptr - hdd context pointer
9492 * @event_ptr - event structure pointer
9493 *
9494 * This is the p2p listen offload stop event handler, it sends vendor
9495 * event back to supplicant to notify the stop reason.
9496 *
9497 * Return: None
9498 */
9499static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9500 void *event_ptr)
9501{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009502 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009503 struct sir_p2p_lo_event *evt = event_ptr;
9504 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009505 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009506
9507 ENTER();
9508
9509 if (hdd_ctx == NULL) {
9510 hdd_err("Invalid HDD context pointer");
9511 return;
9512 }
9513
Peng Xu5c682812017-08-06 07:39:13 -07009514 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9515 if (!adapter) {
9516 hdd_err("Cannot find adapter by vdev_id = %d",
9517 evt->vdev_id);
9518 return;
9519 }
9520
Peng Xu8fdaa492016-06-22 10:20:47 -07009521 vendor_event =
9522 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009523 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009524 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9525 GFP_KERNEL);
9526
9527 if (!vendor_event) {
9528 hdd_err("cfg80211_vendor_event_alloc failed");
9529 return;
9530 }
9531
9532 if (nla_put_u32(vendor_event,
9533 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9534 evt->reason_code)) {
9535 hdd_err("nla put failed");
9536 kfree_skb(vendor_event);
9537 return;
9538 }
9539
9540 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009541 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9542 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009543}
9544
9545/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309546 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9547 * @hdd_ctx: HDD context
9548 *
9549 * This function sends the adaptive dwell time config configuration to the
9550 * firmware via WMA
9551 *
9552 * Return: 0 - success, < 0 - failure
9553 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009554static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309555{
9556 QDF_STATUS status;
9557 struct adaptive_dwelltime_params dwelltime_params;
9558
9559 dwelltime_params.is_enabled =
9560 hdd_ctx->config->adaptive_dwell_mode_enabled;
9561 dwelltime_params.dwelltime_mode =
9562 hdd_ctx->config->global_adapt_dwelltime_mode;
9563 dwelltime_params.lpf_weight =
9564 hdd_ctx->config->adapt_dwell_lpf_weight;
9565 dwelltime_params.passive_mon_intval =
9566 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9567 dwelltime_params.wifi_act_threshold =
9568 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9569
9570 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9571 &dwelltime_params);
9572
9573 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9574 if (!QDF_IS_STATUS_SUCCESS(status)) {
9575 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9576 return -EAGAIN;
9577 }
9578 return 0;
9579}
9580
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009581int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309582{
9583 QDF_STATUS status;
9584 struct wmi_dbs_scan_sel_params dbs_scan_params;
9585 uint32_t i = 0;
9586 uint8_t count = 0, numentries = 0;
9587 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9588 * CDS_DBS_SCAN_CLIENTS_MAX];
9589
9590 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009591 if (hdd_ctx->config->dual_mac_feature_disable ==
9592 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309593 return -EINVAL;
9594
9595 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9596 dbs_scan_config, &numentries,
9597 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9598 * CDS_DBS_SCAN_CLIENTS_MAX));
9599
9600 hdd_info("numentries %hu", numentries);
9601 if (!numentries) {
9602 hdd_info("Donot send scan_selection_config");
9603 return 0;
9604 }
9605
9606 /* hdd_set_fw_log_params */
9607 dbs_scan_params.num_clients = 0;
9608 while (count < (numentries - 2)) {
9609 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9610 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9611 dbs_scan_params.num_non_dbs_scans[i] =
9612 dbs_scan_config[count + 2];
9613 dbs_scan_params.num_clients++;
9614 hdd_debug("module:%d NDS:%d NNDS:%d",
9615 dbs_scan_params.module_id[i],
9616 dbs_scan_params.num_dbs_scans[i],
9617 dbs_scan_params.num_non_dbs_scans[i]);
9618 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9619 i++;
9620 }
9621
9622 dbs_scan_params.pdev_id = 0;
9623
9624 hdd_debug("clients:%d pdev:%d",
9625 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9626
9627 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9628 &dbs_scan_params);
9629 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9630 if (!QDF_IS_STATUS_SUCCESS(status)) {
9631 hdd_err("Failed to send DBS Scan selection configuration!");
9632 return -EAGAIN;
9633 }
9634 return 0;
9635}
9636
Arun Khandavallid4349a92016-07-25 11:10:43 +05309637#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9638/**
9639 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9640 * @hdd_ctx: HDD context
9641 *
9642 * Set auto shutdown callback to get indications from firmware to indicate
9643 * userspace to shutdown WLAN after a configured amount of inactivity.
9644 *
9645 * Return: 0 on success and errno on failure.
9646 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009647static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309648{
9649 QDF_STATUS status;
9650
9651 if (!hdd_ctx->config->WlanAutoShutdown)
9652 return 0;
9653
9654 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9655 wlan_hdd_auto_shutdown_cb);
9656 if (status != QDF_STATUS_SUCCESS)
9657 hdd_err("Auto shutdown feature could not be enabled: %d",
9658 status);
9659
9660 return qdf_status_to_os_return(status);
9661}
9662#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009663static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309664{
9665 return 0;
9666}
9667#endif
9668
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009669static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009670{
9671 QDF_STATUS status = QDF_STATUS_SUCCESS;
9672
9673 switch (hdd_ctx->config->dual_mac_feature_disable) {
9674 case DISABLE_DBS_CXN_AND_SCAN:
9675 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9676 if (status != QDF_STATUS_SUCCESS)
9677 hdd_err("Failed to disable dual mac features");
9678 break;
9679 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9680 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9681 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9682 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9683 if (status != QDF_STATUS_SUCCESS)
9684 hdd_err("Failed to set dbs scan and fw mode config");
9685 break;
9686 default:
9687 break;
9688 }
9689
9690 return status;
9691}
9692
Arun Khandavallid4349a92016-07-25 11:10:43 +05309693/**
9694 * hdd_features_init() - Init features
9695 * @hdd_ctx: HDD context
9696 * @adapter: Primary adapter context
9697 *
9698 * Initialize features and their feature context after WLAN firmware is up.
9699 *
9700 * Return: 0 on success and errno on failure.
9701 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009702static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309703{
9704 tSirTxPowerLimit hddtxlimit;
9705 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309706 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309707 int ret;
9708
9709 ENTER();
9710
Arun Khandavallid4349a92016-07-25 11:10:43 +05309711 /* FW capabilities received, Set the Dot11 mode */
9712 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009713 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9714 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309715
Arun Khandavallid4349a92016-07-25 11:10:43 +05309716
9717 if (hdd_ctx->config->fIsImpsEnabled)
9718 hdd_set_idle_ps_config(hdd_ctx, true);
9719 else
9720 hdd_set_idle_ps_config(hdd_ctx, false);
9721
Poddar, Siddarth37033032017-10-11 15:47:40 +05309722 /* Send Enable/Disable data stall detection cmd to FW */
9723 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9724 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9725
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309726 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009727 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309728
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309729 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9730 hdd_warn("Error in setting Voltage Corner mode config to FW");
9731
Arun Khandavallid4349a92016-07-25 11:10:43 +05309732 if (hdd_lro_init(hdd_ctx))
9733 hdd_err("Unable to initialize LRO in fw");
9734
9735 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9736 hdd_err("Unable to send adaptive dwelltime setting to FW");
9737
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309738 if (hdd_dbs_scan_selection_init(hdd_ctx))
9739 hdd_err("Unable to send DBS scan selection setting to FW");
9740
Arun Khandavallid4349a92016-07-25 11:10:43 +05309741 ret = hdd_init_thermal_info(hdd_ctx);
9742 if (ret) {
9743 hdd_err("Error while initializing thermal information");
9744 goto deregister_frames;
9745 }
9746
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309747 /**
9748 * In case of SSR/PDR, if pktlog was enabled manually before
9749 * SSR/PDR, Then enabled it again automatically after Wlan
9750 * device up.
9751 */
9752 if (cds_is_driver_recovering()) {
9753 if (hdd_ctx->is_pktlog_enabled)
9754 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9755 } else if (cds_is_packet_log_enabled())
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309756 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9757
Arun Khandavallid4349a92016-07-25 11:10:43 +05309758 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9759 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9760 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9761 if (!QDF_IS_STATUS_SUCCESS(status))
9762 hdd_err("Error setting txlimit in sme: %d", status);
9763
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009764 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309765
Arun Khandavallid4349a92016-07-25 11:10:43 +05309766 ret = hdd_register_cb(hdd_ctx);
9767 if (ret) {
9768 hdd_err("Failed to register HDD callbacks!");
9769 goto deregister_frames;
9770 }
9771
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009772 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9773 if (!QDF_IS_STATUS_SUCCESS(status)) {
9774 hdd_err("Failed to set dbs scan and fw mode cfg");
9775 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309776 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009777
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309778 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9779 status = sme_enable_disable_chanavoidind_event(
9780 hdd_ctx->hHal, 0);
9781 if (!QDF_IS_STATUS_SUCCESS(status)) {
9782 hdd_err("Failed to disable Chan Avoidance Indication");
9783 goto deregister_cb;
9784 }
9785 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309786
Manjeet Singha9cae432017-02-28 11:58:22 +05309787 if (hdd_ctx->config->enable_5g_band_pref) {
9788 band_pref_params.rssi_boost_threshold_5g =
9789 hdd_ctx->config->rssi_boost_threshold_5g;
9790 band_pref_params.rssi_boost_factor_5g =
9791 hdd_ctx->config->rssi_boost_factor_5g;
9792 band_pref_params.max_rssi_boost_5g =
9793 hdd_ctx->config->max_rssi_boost_5g;
9794 band_pref_params.rssi_penalize_threshold_5g =
9795 hdd_ctx->config->rssi_penalize_threshold_5g;
9796 band_pref_params.rssi_penalize_factor_5g =
9797 hdd_ctx->config->rssi_penalize_factor_5g;
9798 band_pref_params.max_rssi_penalize_5g =
9799 hdd_ctx->config->max_rssi_penalize_5g;
9800 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9801 }
9802
Arun Khandavallid4349a92016-07-25 11:10:43 +05309803 /* register P2P Listen Offload event callback */
9804 if (wma_is_p2p_lo_capable())
9805 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9806 wlan_hdd_p2p_lo_event_callback);
9807
9808 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9809
9810 if (ret)
9811 goto deregister_cb;
9812
Dustin Brown11638b72018-01-25 17:37:25 +05309813 wlan_hdd_init_chan_info(hdd_ctx);
9814
Arun Khandavallid4349a92016-07-25 11:10:43 +05309815 EXIT();
9816 return 0;
9817
9818deregister_cb:
9819 hdd_deregister_cb(hdd_ctx);
9820deregister_frames:
9821 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309822 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309823}
9824
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009825/**
9826 * hdd_features_deinit() - Deinit features
9827 * @hdd_ctx: HDD context
9828 *
9829 * De-Initialize features and their feature context.
9830 *
9831 * Return: none.
9832 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009833static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009834{
Dustin Brown11638b72018-01-25 17:37:25 +05309835 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009836 wlan_hdd_tsf_deinit(hdd_ctx);
9837}
9838
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309839/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009840 * hdd_register_bcn_cb() - register scan beacon callback
9841 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309842 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009843 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309844 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009845static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309846{
9847 QDF_STATUS status;
9848
9849 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9850 wlan_cfg80211_inform_bss_frame,
9851 SCAN_CB_TYPE_INFORM_BCN);
9852 if (!QDF_IS_STATUS_SUCCESS(status)) {
9853 hdd_err("failed with status code %08d [x%08x]",
9854 status, status);
9855 return status;
9856 }
9857
9858 return QDF_STATUS_SUCCESS;
9859}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309860
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309861/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309862 * hdd_configure_cds() - Configure cds modules
9863 * @hdd_ctx: HDD context
9864 * @adapter: Primary adapter context
9865 *
9866 * Enable Cds modules after WLAN firmware is up.
9867 *
9868 * Return: 0 on success and errno on failure.
9869 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009870int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309871{
9872 int ret;
9873 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309874 int set_value;
9875 uint32_t num_abg_tx_chains = 0;
9876 uint32_t num_11b_tx_chains = 0;
9877 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009878 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309879
9880 if (hdd_ctx->config->sifs_burst_duration) {
9881 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9882 hdd_ctx->config->sifs_burst_duration;
9883
9884 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9885 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9886 set_value, PDEV_CMD);
9887 }
9888
9889 if (hdd_ctx->config->is_force_1x1)
9890 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9891 1, PDEV_CMD);
9892 /* set chip power save failure detected callback */
9893 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9894 hdd_chip_pwr_save_fail_detected_cb);
9895
9896 if (hdd_ctx->config->max_mpdus_inampdu) {
9897 set_value = hdd_ctx->config->max_mpdus_inampdu;
9898 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9899 set_value, PDEV_CMD);
9900 }
9901
9902 if (hdd_ctx->config->enable_rts_sifsbursting) {
9903 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9904 sme_cli_set_command(0,
9905 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9906 set_value, PDEV_CMD);
9907 }
9908
9909 if (hdd_ctx->config->sap_get_peer_info) {
9910 set_value = hdd_ctx->config->sap_get_peer_info;
9911 sme_cli_set_command(0,
9912 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9913 set_value, PDEV_CMD);
9914 }
9915
9916 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9917 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9918 if (!hdd_ctx->config->enable2x2) {
9919 if (num_11b_tx_chains > 1)
9920 num_11b_tx_chains = 1;
9921 if (num_11ag_tx_chains > 1)
9922 num_11ag_tx_chains = 1;
9923 }
9924 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9925 num_11b_tx_chains);
9926 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9927 num_11ag_tx_chains);
9928 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9929 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309930
9931 ret = hdd_pre_enable_configure(hdd_ctx);
9932 if (ret) {
9933 hdd_err("Failed to pre-configure cds");
9934 goto out;
9935 }
9936
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009937 /* Always get latest IPA resources allocated from cds_open and configure
9938 * IPA module before configuring them to FW. Sequence required as crash
9939 * observed otherwise.
9940 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009941 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9942 hdd_err("Failed to setup pipes");
9943 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009944 }
9945
Arun Khandavallifae92942016-08-01 13:31:08 +05309946 /*
9947 * Start CDS which starts up the SME/MAC/HAL modules and everything
9948 * else
9949 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009950 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309951
9952 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009953 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309954 goto out;
9955 }
9956
9957 status = hdd_post_cds_enable_config(hdd_ctx);
9958 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009959 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009960 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309961 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309962 status = hdd_register_bcn_cb(hdd_ctx);
9963 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +08009964 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309965 goto cds_disable;
9966 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309967
9968 ret = hdd_features_init(hdd_ctx, adapter);
9969 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009970 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309971
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009972 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009973 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009974 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9975 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009976 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009977 goto cds_disable;
9978 }
9979
Himanshu Agarwalb229a142017-12-21 10:16:45 +05309980 if (ucfg_green_ap_enable_egap(hdd_ctx->hdd_pdev))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309981 hdd_debug("enhance green ap is not enabled");
9982
Nachiket Kukadedd302662017-07-13 17:31:44 +05309983 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9984 hdd_debug("Failed to set wow pulse");
9985
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +05309986 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
9987 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309988 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9989 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9990
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309991
9992 if (hdd_ctx->config->enable_phy_reg_retention)
9993 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9994 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9995
Arun Khandavallifae92942016-08-01 13:31:08 +05309996 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009997
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009998cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009999 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010000
Arun Khandavallifae92942016-08-01 13:31:08 +053010001out:
10002 return -EINVAL;
10003}
10004
10005/**
10006 * hdd_deconfigure_cds() -De-Configure cds
10007 * @hdd_ctx: HDD context
10008 *
10009 * Deconfigure Cds modules before WLAN firmware is down.
10010 *
10011 * Return: 0 on success and errno on failure.
10012 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010013static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010014{
10015 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010016 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010017
10018 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010019
10020 /* De-init features */
10021 hdd_features_deinit(hdd_ctx);
10022
Arun Khandavallifae92942016-08-01 13:31:08 +053010023 /* De-register the SME callbacks */
10024 hdd_deregister_cb(hdd_ctx);
10025
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010026 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010027 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10028 hdd_err("Failed to Disable the CDS Modules! :%d",
10029 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010030 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010031 }
10032
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010033 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
10034 hdd_err("Failed to disconnect pipes");
10035 ret = -EINVAL;
10036 }
10037
Arun Khandavallifae92942016-08-01 13:31:08 +053010038 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010039 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010040}
10041
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010042#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10043static void hdd_deregister_policy_manager_callback(
10044 struct wlan_objmgr_psoc *psoc)
10045{
10046 if (QDF_STATUS_SUCCESS !=
10047 policy_mgr_deregister_hdd_cb(psoc)) {
10048 hdd_err("HDD callback deregister with policy manager failed");
10049 }
10050}
10051#else
10052static void hdd_deregister_policy_manager_callback(
10053 struct wlan_objmgr_psoc *psoc)
10054{
10055}
10056#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010057
10058/**
10059 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10060 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010061 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010062 *
10063 * This function maintains the driver state machine it will be invoked from
10064 * exit, shutdown and con_mode change handler. Depending on the driver state
10065 * shall perform the stopping/closing of the modules.
10066 *
10067 * Return: 0 for success; non-zero for failure
10068 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010069int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010070{
10071 void *hif_ctx;
10072 qdf_device_t qdf_ctx;
10073 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010074 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010075 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010076 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10077 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010078 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010079 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010080
10081 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -070010082 hdd_alert("stop WLAN module: entering driver status=%d",
10083 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010084
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010085 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10086
Arun Khandavallifae92942016-08-01 13:31:08 +053010087 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10088 if (!qdf_ctx) {
10089 hdd_err("QDF device context NULL");
10090 return -EINVAL;
10091 }
10092
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010093 mutex_lock(&hdd_ctx->iface_change_lock);
10094 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010095 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010096
Dustin Brown70111822017-03-30 15:31:40 -070010097 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010098 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010099 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010100 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010101
10102 cds_print_external_threads();
10103
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010104 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010105 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010106 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10107 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010108 hdd_prevent_suspend_timeout(
10109 hdd_ctx->config->iface_change_wait_time,
10110 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010111 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010112 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010113 return 0;
10114 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010115 }
10116
Arun Khandavallifae92942016-08-01 13:31:08 +053010117 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10118
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010119 /* free user wowl patterns */
10120 hdd_free_user_wowl_ptrns();
10121
Arun Khandavallifae92942016-08-01 13:31:08 +053010122 switch (hdd_ctx->driver_status) {
10123 case DRIVER_MODULES_UNINITIALIZED:
10124 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010125 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010126 case DRIVER_MODULES_CLOSED:
10127 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010128 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010129 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010130 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10131
Komal Seelamf2136bb2016-09-28 18:30:44 +053010132 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010133 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010134 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010135 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010136 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010137 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010138 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010139
Arun Khandavallifae92942016-08-01 13:31:08 +053010140 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010141 hdd_info("Wlan transitioned (now OPENED)");
10142
10143 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010144 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010145 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010146 break;
10147 default:
10148 hdd_err("Trying to stop wlan in a wrong state: %d",
10149 hdd_ctx->driver_status);
10150 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010151 ret = -EINVAL;
10152 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010153 }
10154
Amar Singhal18081642018-01-26 16:04:13 -080010155 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010156 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010157
Rajeev Kumarbe021242017-02-16 16:12:23 -080010158 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010159 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10160 hdd_err("Failed to process post CDS disable Modules! :%d",
10161 qdf_status);
10162 ret = -EINVAL;
10163 QDF_ASSERT(0);
10164 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010165
psimhadeea0a12017-12-18 14:50:02 -080010166 hdd_runtime_suspend_context_deinit(hdd_ctx);
10167
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010168 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10169 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10170 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10171 ret = -EINVAL;
10172 QDF_ASSERT(0);
10173 }
10174
Jeff Johnsone4b14592017-09-13 14:23:33 -070010175 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010176 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010177 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010178 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010179 QDF_ASSERT(0);
10180 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010181
Amar Singhal410675c2018-01-10 12:14:21 -080010182 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010183 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10184 if (ret) {
10185 hdd_err("Failed to destroy pdev; errno:%d", ret);
10186 QDF_ASSERT(0);
10187 }
10188
10189 /*
10190 * Reset total mac phy during module stop such that during
10191 * next module start same psoc is used to populate new service
10192 * ready data
10193 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010194 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10195 if (tgt_hdl)
10196 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10197
Liangwei Dong50a64a72018-01-11 01:17:00 -050010198
Arun Khandavallifae92942016-08-01 13:31:08 +053010199 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10200 if (!hif_ctx) {
10201 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010202 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010203 }
10204
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010205 if (hdd_ctx->target_hw_name) {
10206 qdf_mem_free(hdd_ctx->target_hw_name);
10207 hdd_ctx->target_hw_name = NULL;
10208 }
10209
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010210 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010211
10212 ol_cds_free();
10213
Dustin Brown70111822017-03-30 15:31:40 -070010214 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010215 ret = pld_power_off(qdf_ctx->dev);
10216 if (ret)
10217 hdd_err("CNSS power down failed put device into Low power mode:%d",
10218 ret);
10219 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010220
Dustin Brown4bc0a622017-12-06 15:56:50 -080010221 /* many adapter resources are not freed by design in SSR case */
10222 if (!is_recovery_stop)
10223 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010224 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010225
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010226 /* Once the firmware sequence is completed reset this flag */
10227 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010228 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010229 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010230
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010231done:
10232 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010233 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010234 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010235 hdd_alert("stop WLAN module: exit driver status=%d",
10236 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010237
Arun Khandavallifae92942016-08-01 13:31:08 +053010238 EXIT();
10239
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010240 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010241}
10242
Arun Khandavallifae92942016-08-01 13:31:08 +053010243
10244/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010245 * hdd_state_info_dump() - prints state information of hdd layer
10246 * @buf: buffer pointer
10247 * @size: size of buffer to be filled
10248 *
10249 * This function is used to dump state information of hdd layer
10250 *
10251 * Return: None
10252 */
10253static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10254{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010255 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010256 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010257 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010258 uint16_t len = 0;
10259 char *buf = *buf_ptr;
10260
10261 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10262 if (!hdd_ctx) {
10263 hdd_err("Failed to get hdd context ");
10264 return;
10265 }
10266
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010267 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010268
10269 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010270 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010271 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010272 "\n is_scheduler_suspended %d",
10273 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010274
Dustin Brown920397d2017-12-13 16:27:50 -080010275 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010276 if (adapter->dev)
10277 len += scnprintf(buf + len, *size - len,
10278 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010279 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010280 "\n device_mode: %d", adapter->device_mode);
10281 switch (adapter->device_mode) {
10282 case QDF_STA_MODE:
10283 case QDF_P2P_CLIENT_MODE:
10284 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10285 len += scnprintf(buf + len, *size - len,
10286 "\n connState: %d",
10287 hdd_sta_ctx->conn_info.connState);
10288 break;
10289
10290 default:
10291 break;
10292 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010293 }
10294
10295 *size -= len;
10296 *buf_ptr += len;
10297}
10298
10299/**
10300 * hdd_register_debug_callback() - registration function for hdd layer
10301 * to print hdd state information
10302 *
10303 * Return: None
10304 */
10305static void hdd_register_debug_callback(void)
10306{
10307 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10308}
10309
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010310/*
10311 * wlan_init_bug_report_lock() - Initialize bug report lock
10312 *
10313 * This function is used to create bug report lock
10314 *
10315 * Return: None
10316 */
10317static void wlan_init_bug_report_lock(void)
10318{
10319 p_cds_contextType p_cds_context;
10320
10321 p_cds_context = cds_get_global_context();
10322 if (!p_cds_context) {
10323 hdd_err("cds context is NULL");
10324 return;
10325 }
10326
10327 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10328}
10329
Mohit Khannaf8f96822017-05-17 17:11:59 -070010330void hdd_dp_trace_init(struct hdd_config *config)
10331{
10332
10333 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10334 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10335 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10336 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10337 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10338 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10339 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010340 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010341
10342 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10343 &num_entries, sizeof(config_params));
10344
10345 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010346 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010347 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010348 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010349 else if (bw_compute_interval > 1000) {
10350 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10351 thresh_time_limit = 1;
10352 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010353 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10354
10355 switch (num_entries) {
10356 case 4:
10357 proto_bitmap = config_params[3];
10358 case 3:
10359 verbosity = config_params[2];
10360 case 2:
10361 thresh = config_params[1];
10362 case 1:
10363 live_mode = config_params[0];
10364 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010365 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010366 live_mode, thresh, thresh_time_limit,
10367 verbosity, proto_bitmap);
10368 };
10369
10370 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10371 verbosity, proto_bitmap);
10372
10373}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010374/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010375 * hdd_wlan_startup() - HDD init function
10376 * @dev: Pointer to the underlying device
10377 *
10378 * This is the driver startup code executed once a WLAN device has been detected
10379 *
10380 * Return: 0 for success, < 0 for failure
10381 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010382int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010383{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010384 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010385 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010386 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010387 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010388
10389 ENTER();
10390
Arun Khandavallifae92942016-08-01 13:31:08 +053010391 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010392
10393 if (IS_ERR(hdd_ctx))
10394 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010395
Abhishek Singhe9068f12017-03-31 14:14:52 +053010396 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10397 DEFAULT_PSOC_ID);
10398 if (ret) {
10399 hdd_err("Psoc creation fails!");
10400 QDF_BUG(0);
10401 goto err_hdd_free_context;
10402 }
10403
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010404 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010405#ifdef FEATURE_WLAN_CH_AVOID
10406 mutex_init(&hdd_ctx->avoid_freq_lock);
10407#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010408
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010409 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010410 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010411
Dustin Brown021cecd2017-12-11 13:56:43 -080010412 hdd_driver_memdump_init();
10413
Jeff Johnson957bc272017-02-02 08:54:48 -080010414 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010415 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010416 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010417 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010418 }
10419
Yingying Tang80e15f32016-09-27 18:23:01 +080010420 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010421
Anurag Chouhan6d760662016-02-20 16:05:43 +053010422 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010423
10424 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010425 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010426 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010427 }
10428
Prashanth Bhatta07998752016-04-28 12:35:33 -070010429 ret = hdd_wiphy_init(hdd_ctx);
10430 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010431 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010432 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010433 }
10434
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010435 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010436 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010437
jiad195f7032018-01-31 15:18:09 +080010438 ret = hdd_ipa_init(hdd_ctx);
10439 if (ret == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010440 goto err_wiphy_unregister;
10441
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010442 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010443
Paul Zhangfb02f452017-12-22 11:58:43 +080010444 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10445 if (ret) {
10446 hdd_err("register_netdevice_notifier failed: %d", ret);
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010447 goto err_ipa_cleanup;
Paul Zhangfb02f452017-12-22 11:58:43 +080010448 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010449
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010450 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010451
Jeff Johnson957bc272017-02-02 08:54:48 -080010452 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10453 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010454 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010455 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010456 }
10457
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010458 hdd_release_rtnl_lock();
10459 rtnl_held = false;
10460
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010461 wlan_hdd_update_11n_mode(hdd_ctx->config);
10462
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010463#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010464 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010465 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010466 hdd_skip_acs_scan_timer_handler,
10467 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010468 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010469 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010470 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010471#endif
10472
Prashanth Bhattaab004382016-10-11 16:08:11 -070010473 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010474
Jeff Johnson9afc5012016-09-23 13:56:27 -070010475 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010476
Nirav Shahbd36b062016-07-18 11:12:59 +053010477 if (hdd_ctx->rps)
10478 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010479
Paul Zhangfb02f452017-12-22 11:58:43 +080010480 ret = hdd_register_notifiers(hdd_ctx);
10481 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010482 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010483
Paul Zhangfb02f452017-12-22 11:58:43 +080010484 status = wlansap_global_init();
10485 if (QDF_IS_STATUS_ERROR(status)) {
10486 hdd_unregister_notifiers(hdd_ctx);
10487 goto err_close_adapters;
10488 }
10489
Arun Khandavallifae92942016-08-01 13:31:08 +053010490 if (hdd_ctx->config->fIsImpsEnabled)
10491 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010492 else
10493 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010494
Mukul Sharma07bd8752017-10-10 16:58:14 +053010495 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010496 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10497 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010498 hdd_prevent_suspend_timeout(
10499 hdd_ctx->config->iface_change_wait_time,
10500 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10501 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010502
Sachin Ahujadddd2632017-03-07 19:07:24 +053010503 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010504 goto success;
10505
Jeff Johnson957bc272017-02-02 08:54:48 -080010506err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010507 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010508
Jeff Johnson46bde382017-02-01 15:31:16 -080010509err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010510 if (rtnl_held)
10511 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010512
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010513 unregister_netdevice_notifier(&hdd_netdev_notifier);
10514
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010515err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010516 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010517
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010518err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010519 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010520
Arun Khandavallifae92942016-08-01 13:31:08 +053010521err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010522 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010523
Dustin Brown021cecd2017-12-11 13:56:43 -080010524err_memdump_deinit:
10525 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010526
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010527 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010528 hdd_exit_netlink_services(hdd_ctx);
10529
Dustin Brown20912462017-06-07 13:48:25 -070010530 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10531
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010532err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010533 if (cds_is_fw_down())
10534 hdd_err("Not setting the complete event as fw is down");
10535 else
10536 hdd_start_complete(ret);
10537
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010538 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010539 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010540 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010541
10542success:
10543 EXIT();
10544 return 0;
10545}
10546
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010547/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010548 * hdd_wlan_update_target_info() - update target type info
10549 * @hdd_ctx: HDD context
10550 * @context: hif context
10551 *
10552 * Update target info received from firmware in hdd context
10553 * Return:None
10554 */
10555
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010556void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010557{
10558 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10559
10560 if (!tgt_info) {
10561 hdd_err("Target info is Null");
10562 return;
10563 }
10564
10565 hdd_ctx->target_type = tgt_info->target_type;
10566}
10567
10568/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010569 * hdd_get_nud_stats_cb() - callback api to update the stats
10570 * received from the firmware
10571 * @data: pointer to adapter.
10572 * @rsp: pointer to data received from FW.
10573 *
10574 * This is called when wlan driver received response event for
10575 * get arp stats to firmware.
10576 *
10577 * Return: None
10578 */
10579static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10580{
10581 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10582 struct hdd_nud_stats_context *context;
10583 int status;
10584 struct hdd_adapter *adapter = NULL;
10585
10586 ENTER();
10587
10588 if (!rsp) {
10589 hdd_err("data is null");
10590 return;
10591 }
10592
10593 status = wlan_hdd_validate_context(hdd_ctx);
10594 if (0 != status)
10595 return;
10596
10597 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10598 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10599 hdd_err("Invalid adapter or adapter has invalid magic");
10600 return;
10601 }
10602
10603 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10604 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10605 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10606 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10607 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10608 rsp->out_of_order_arp_rsp_drop_cnt);
10609 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10610 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10611 hdd_notice("rsp->ba_session_establishment_status :%x",
10612 rsp->ba_session_establishment_status);
10613
10614 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10615 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10616 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10617 adapter->dad |= rsp->dad_detected;
10618 adapter->con_status = rsp->connect_status;
10619
10620 spin_lock(&hdd_context_lock);
10621 context = &hdd_ctx->nud_stats_context;
10622 complete(&context->response_event);
10623 spin_unlock(&hdd_context_lock);
10624
10625 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010626}
10627
10628/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010629 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010630 * @hdd_ctx: HDD context
10631 *
10632 * Register the HDD callbacks to CDS/SME.
10633 *
10634 * Return: 0 for success or Error code for failure
10635 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010636int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010637{
10638 QDF_STATUS status;
10639 int ret = 0;
10640
10641 ENTER();
10642
10643 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10644
10645 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10646 hdd_send_oem_data_rsp_msg);
10647
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010648 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10649 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010650 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10651 sme_nan_register_callback(hdd_ctx->hHal,
10652 wlan_hdd_cfg80211_nan_callback);
10653 sme_stats_ext_register_callback(hdd_ctx->hHal,
10654 wlan_hdd_cfg80211_stats_ext_callback);
10655
10656 sme_ext_scan_register_callback(hdd_ctx->hHal,
10657 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010658 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10659 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010660
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010661 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10662 hdd_rssi_threshold_breached);
10663
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010664 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10665
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010666 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10667 wlan_hdd_cfg80211_link_layer_stats_callback);
10668
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010669 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10670
Zhang Qianca38fb12016-12-23 11:10:48 +080010671 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10672 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10673
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010674 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10675 hdd_lost_link_info_cb);
10676 /* print error and not block the startup process */
10677 if (!QDF_IS_STATUS_SUCCESS(status))
10678 hdd_err("set lost link info callback failed");
10679
Poddar, Siddarth34872782017-08-10 14:08:51 +053010680 ret = hdd_register_data_stall_detect_cb();
10681 if (ret) {
10682 hdd_err("Register data stall detect detect callback failed.");
10683 return ret;
10684 }
10685
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010686 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10687
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010688 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010689 hdd_set_connection_in_progress,
10690 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010691
10692 status = sme_congestion_register_callback(hdd_ctx->hHal,
10693 hdd_update_cca_info_cb);
10694 if (!QDF_IS_STATUS_SUCCESS(status))
10695 hdd_err("set congestion callback failed");
10696
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010697 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10698 hdd_bt_activity_cb);
10699 if (!QDF_IS_STATUS_SUCCESS(status))
10700 hdd_err("set bt activity info callback failed");
10701
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010702 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10703 hdd_tx_queue_cb);
10704 if (!QDF_IS_STATUS_SUCCESS(status))
10705 hdd_err("Register tx queue callback failed");
10706
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010707 EXIT();
10708
10709 return ret;
10710}
10711
10712/**
10713 * hdd_deregister_cb() - De-Register HDD callbacks.
10714 * @hdd_ctx: HDD context
10715 *
10716 * De-Register the HDD callbacks to CDS/SME.
10717 *
10718 * Return: void
10719 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010720void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010721{
10722 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010723 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010724
10725 ENTER();
10726
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010727 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010728 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10729 if (!QDF_IS_STATUS_SUCCESS(status))
10730 hdd_err("De-register of dcc stats callback failed: %d",
10731 status);
10732
10733 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010734 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10735
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010736 sme_stats_ext_register_callback(hdd_ctx->hHal,
10737 wlan_hdd_cfg80211_stats_ext_callback);
10738
10739 sme_nan_deregister_callback(hdd_ctx->hHal);
10740 status = sme_reset_tsfcb(hdd_ctx->hHal);
10741 if (!QDF_IS_STATUS_SUCCESS(status))
10742 hdd_err("Failed to de-register tsfcb the callback:%d",
10743 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010744
Poddar, Siddarth34872782017-08-10 14:08:51 +053010745 ret = hdd_deregister_data_stall_detect_cb();
10746 if (ret)
10747 hdd_err("Failed to de-register data stall detect event callback");
10748
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010749 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10750 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10751
10752 EXIT();
10753}
10754
10755/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010756 * hdd_softap_sta_deauth() - handle deauth req from HDD
10757 * @adapter: Pointer to the HDD
10758 * @enable: bool value
10759 *
10760 * This to take counter measure to handle deauth req from HDD
10761 *
10762 * Return: None
10763 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010764QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010765 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010766{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010767 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010768
10769 ENTER();
10770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010771 /* Ignore request to deauth bcmc station */
10772 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010773 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010774
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010775 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010776 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10777 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010778
10779 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010780 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010781}
10782
10783/**
10784 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10785 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010786 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010787 *
10788 * This to take counter measure to handle deauth req from HDD
10789 *
10790 * Return: None
10791 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010792void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010793 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010794{
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010795 struct sir_peer_sta_info peer_sta_info;
10796 struct hdd_station_info *stainfo;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010797 ENTER();
10798
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010799 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010800 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010801 return;
10802
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010803 wlan_hdd_get_peer_rssi(adapter, &pDelStaParams->peerMacAddr,
10804 &peer_sta_info);
10805 stainfo = hdd_get_stainfo(adapter->cache_sta_info,
10806 pDelStaParams->peerMacAddr);
10807 if (stainfo) {
10808 stainfo->rssi = peer_sta_info.info[0].rssi;
10809 stainfo->tx_rate = peer_sta_info.info[0].tx_rate;
10810 stainfo->rx_rate = peer_sta_info.info[0].rx_rate;
Jiachao Wuf610d912018-01-23 17:47:32 +080010811 stainfo->reason_code = pDelStaParams->reason_code;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010812 }
10813
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010814 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010815 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010816}
10817
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010818/**
10819 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10820 * @hdd_ctx: HDD Context
10821 *
10822 * API to find if there is any STA or P2P-Client is connected
10823 *
10824 * Return: true if connected; false otherwise
10825 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010826QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010827{
10828 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10829}
10830
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010831/**
10832 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10833 * @adapter: HDD adapter pointer
10834 *
10835 * This function loop through each adapter and disable roaming on each STA
10836 * device mode except the input adapter.
10837 *
10838 * Note: On the input adapter roaming is not enabled yet hence no need to
10839 * disable.
10840 *
10841 * Return: None
10842 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010843void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010844{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010845 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010846 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010847
10848 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010849 hdd_ctx->config->isRoamOffloadScanEnabled &&
10850 QDF_STA_MODE == adapter->device_mode &&
10851 policy_mgr_is_sta_active_connection_exists(
10852 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010853 hdd_debug("Connect received on STA session Id(%d)",
10854 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010855 /*
10856 * Loop through adapter and disable roaming for each STA device
10857 * mode except the input adapter.
10858 */
Dustin Brown920397d2017-12-13 16:27:50 -080010859 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010860 if (QDF_STA_MODE == adapterIdx->device_mode &&
10861 adapter->session_id != adapterIdx->session_id) {
10862 hdd_debug("Disable Roaming on session Id(%d)",
10863 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010864 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10865 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010866 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010867 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010868 }
10869 }
10870}
10871
10872/**
10873 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10874 * @adapter: HDD adapter pointer
10875 *
10876 * This function loop through each adapter and enable roaming on each STA
10877 * device mode except the input adapter.
10878 * Note: On the input adapter no need to enable roaming because link got
10879 * disconnected on this.
10880 *
10881 * Return: None
10882 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010883void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010884{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010885 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010886 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010887
10888 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010889 hdd_ctx->config->isRoamOffloadScanEnabled &&
10890 QDF_STA_MODE == adapter->device_mode &&
10891 policy_mgr_is_sta_active_connection_exists(
10892 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010893 hdd_debug("Disconnect received on STA session Id(%d)",
10894 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010895 /*
10896 * Loop through adapter and enable roaming for each STA device
10897 * mode except the input adapter.
10898 */
Dustin Brown920397d2017-12-13 16:27:50 -080010899 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010900 if (QDF_STA_MODE == adapterIdx->device_mode &&
10901 adapter->session_id != adapterIdx->session_id) {
10902 hdd_debug("Enabling Roaming on session Id(%d)",
10903 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010904 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10905 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010906 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010907 REASON_CONNECT);
10908 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010909 }
10910 }
10911}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010912
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010913/**
10914 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10915 * @skb: sk buffer pointer
10916 *
10917 * Sends the bcast message to SVC multicast group with generic nl socket
10918 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10919 *
10920 * Return: None
10921 */
10922static void nl_srv_bcast_svc(struct sk_buff *skb)
10923{
10924#ifdef CNSS_GENL
10925 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10926#else
10927 nl_srv_bcast(skb);
10928#endif
10929}
10930
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010931void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010932{
10933 struct sk_buff *skb;
10934 struct nlmsghdr *nlh;
10935 tAniMsgHdr *ani_hdr;
10936 void *nl_data = NULL;
10937 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010938 struct radio_index_tlv *radio_info;
10939 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010940
10941 if (in_interrupt() || irqs_disabled() || in_atomic())
10942 flags = GFP_ATOMIC;
10943
10944 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10945
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010946 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010947 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010948
10949 nlh = (struct nlmsghdr *)skb->data;
10950 nlh->nlmsg_pid = 0; /* from kernel */
10951 nlh->nlmsg_flags = 0;
10952 nlh->nlmsg_seq = 0;
10953 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10954
10955 ani_hdr = NLMSG_DATA(nlh);
10956 ani_hdr->type = type;
10957
10958 switch (type) {
10959 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010960 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010961 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010962 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010963 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010964 ani_hdr->length = 0;
10965 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010966 break;
10967 case WLAN_SVC_WLAN_STATUS_IND:
10968 case WLAN_SVC_WLAN_VERSION_IND:
10969 case WLAN_SVC_DFS_CAC_START_IND:
10970 case WLAN_SVC_DFS_CAC_END_IND:
10971 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10972 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10973 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010974 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010975 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010976 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010977 ani_hdr->length = len;
10978 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10979 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10980 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010981 break;
10982
10983 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010984 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010985 type);
10986 kfree_skb(skb);
10987 return;
10988 }
10989
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010990 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010991 * Add radio index at the end of the svc event in TLV format
10992 * to maintain the backward compatibility with userspace
10993 * applications.
10994 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010995
10996 tlv_len = 0;
10997
10998 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10999 < WLAN_NL_MAX_PAYLOAD) {
11000 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11001 sizeof(*ani_hdr) + len);
11002 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11003 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11004 radio_info->radio = radio;
11005 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080011006 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011007 "Added radio index tlv - radio index %d",
11008 radio_info->radio);
11009 }
11010
11011 nlh->nlmsg_len += tlv_len;
11012 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11013
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011014 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011015}
11016
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011017#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11018void wlan_hdd_auto_shutdown_cb(void)
11019{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011020 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011021
11022 if (!hdd_ctx)
11023 return;
11024
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011025 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011026 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11027 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011028}
11029
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011030void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011031{
Jeff Johnson9d295242017-08-29 14:39:48 -070011032 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011033 bool ap_connected = false, sta_connected = false;
11034 tHalHandle hal_handle;
11035
11036 hal_handle = hdd_ctx->hHal;
11037 if (hal_handle == NULL)
11038 return;
11039
11040 if (hdd_ctx->config->WlanAutoShutdown == 0)
11041 return;
11042
11043 if (enable == false) {
11044 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011045 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011046 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011047 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011048 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011049 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011050 return;
11051 }
11052
11053 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011054 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11055 hdd_for_each_adapter(hdd_ctx, adapter) {
11056 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011057 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11058 conn_info.connState ==
11059 eConnectionState_Associated) {
11060 sta_connected = true;
11061 break;
11062 }
11063 }
Dustin Brown920397d2017-12-13 16:27:50 -080011064
11065 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011066 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011067 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011068 ap_connected = true;
11069 break;
11070 }
11071 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011072 }
11073 }
11074
11075 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011076 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011077 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011078 }
Jeff Johnson68755312017-02-10 11:46:55 -080011079
11080 if (sme_set_auto_shutdown_timer(hal_handle,
11081 hdd_ctx->config->WlanAutoShutdown)
11082 != QDF_STATUS_SUCCESS)
11083 hdd_err("Failed to start wlan auto shutdown timer");
11084 else
11085 hdd_notice("Auto Shutdown timer for %d seconds enabled",
11086 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011087}
11088#endif
11089
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011090struct hdd_adapter *
11091hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11092 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011093{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011094 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011095 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011096
11097 con_sap_adapter = NULL;
11098
Dustin Brown920397d2017-12-13 16:27:50 -080011099 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011100 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11101 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011102 adapter != this_sap_adapter) {
11103 if (check_start_bss) {
11104 if (test_bit(SOFTAP_BSS_STARTED,
11105 &adapter->event_flags)) {
11106 con_sap_adapter = adapter;
11107 break;
11108 }
11109 } else {
11110 con_sap_adapter = adapter;
11111 break;
11112 }
11113 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011114 }
11115
11116 return con_sap_adapter;
11117}
11118
11119#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011120static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011121{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011122 return adapter->device_mode == QDF_STA_MODE ||
11123 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011124}
11125
Jeff Johnson9d295242017-08-29 14:39:48 -070011126static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011127{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011128 return adapter->device_mode == QDF_SAP_MODE ||
11129 adapter->device_mode == QDF_P2P_GO_MODE;
11130}
11131
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011132static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011133{
Dustin Brown920397d2017-12-13 16:27:50 -080011134 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011135
Dustin Brown920397d2017-12-13 16:27:50 -080011136 hdd_for_each_adapter(hdd_ctx, adapter) {
11137 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011138 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11139 conn_info.connState == eConnectionState_Associated) {
11140 return true;
11141 }
11142
Dustin Brown920397d2017-12-13 16:27:50 -080011143 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011144 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011145 return true;
11146 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011147 }
11148
11149 return false;
11150}
11151
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011152static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011153{
11154 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011155
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011156 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011157 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011158 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011159
Dustin Brown5ec6b552017-03-31 12:11:40 -070011160 return is_running;
11161}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011162
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011163static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011164{
11165 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11166 hdd_ctx->bus_bw_timer_running = true;
11167 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11168 hdd_ctx->config->busBandwidthComputeInterval);
11169 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11170}
11171
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011172void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011173{
11174 ENTER();
11175
11176 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11177 hdd_debug("Bandwidth compute timer already started");
11178 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011179 }
11180
Dustin Brown5ec6b552017-03-31 12:11:40 -070011181 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11182
11183 EXIT();
11184}
11185
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011186void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011187{
11188 ENTER();
11189
11190 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11191 hdd_debug("Bandwidth compute timer already started");
11192 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011193 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011194
11195 if (hdd_any_adapter_is_assoc(hdd_ctx))
11196 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11197
11198 EXIT();
11199}
11200
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011201static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011202{
11203 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
11204
11205 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11206 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11207 hdd_ctx->bus_bw_timer_running = false;
11208 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11209
11210 hdd_reset_tcp_delack(hdd_ctx);
11211}
11212
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011213void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011214{
11215 ENTER();
11216
11217 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11218 hdd_debug("Bandwidth compute timer already stopped");
11219 return;
11220 }
11221
11222 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11223
11224 EXIT();
11225}
11226
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011227void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011228{
11229 ENTER();
11230
11231 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11232 hdd_debug("Bandwidth compute timer already stopped");
11233 return;
11234 }
11235
11236 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11237 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11238
11239 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011240}
11241#endif
11242
11243/**
11244 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11245 * and sta's operating channel.
11246 * @sta_adapter: Describe the first argument to foobar.
11247 * @ap_adapter: Describe the second argument to foobar.
11248 * @roam_profile: Roam profile of AP to which STA wants to connect.
11249 * @concurrent_chnl_same: If both SAP and STA channels are same then
11250 * set this flag to true else false.
11251 *
11252 * This function checks the sap's operating channel and sta's operating channel.
11253 * if both are same then it will return false else it will restart the sap in
11254 * sta's channel and return true.
11255 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011256 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011257 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011258QDF_STATUS
11259wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11260 struct hdd_adapter *ap_adapter,
11261 tCsrRoamProfile *roam_profile,
11262 tScanResultHandle *scan_cache,
11263 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011264{
Jeff Johnson87251032017-08-29 13:31:11 -070011265 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011266 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011267 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011268 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011269 *concurrent_chnl_same = true;
11270
11271 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11272 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011273 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011274 scan_cache,
11275 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011276 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011277 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011278 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011279 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011280 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011281 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011282 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011283 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011284 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011285 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011286 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011287 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011288 }
11289 }
11290 } else {
11291 /*
11292 * Lets handle worst case scenario here, Scan cache lookup is
11293 * failed so we have to stop the SAP to avoid any channel
11294 * discrepancy between SAP's channel and STA's channel.
11295 * Return the status as failure so caller function could know
11296 * that scan look up is failed.
11297 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011298 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011299 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011300 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011301 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011302}
11303
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011304/**
11305 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11306 * @ap_adapter: SAP adapter
11307 *
11308 * This function will process the stopping of sap adapter.
11309 *
11310 * Return: None
11311 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011312void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011313{
Jeff Johnson87251032017-08-29 13:31:11 -070011314 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011315 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011316 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011317 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011318
11319 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011320 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011321 return;
11322 }
11323
11324 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11325 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011326 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011327 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011328
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011329 mutex_lock(&hdd_ctx->sap_lock);
11330 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011331 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011332 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011333 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011334 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011335 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011336 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011337 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011338 qdf_stop_bss_event,
11339 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011340 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011341 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011342 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011343 return;
11344 }
11345 }
11346 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011347 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11348 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011349 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011350 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011351 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011352 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011353 }
11354 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011355}
11356
11357/**
11358 * wlan_hdd_start_sap() - this function starts bss of SAP.
11359 * @ap_adapter: SAP adapter
11360 *
11361 * This function will process the starting of sap adapter.
11362 *
11363 * Return: None
11364 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011365void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011366{
Jeff Johnson87251032017-08-29 13:31:11 -070011367 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011368 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011369 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011370 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011371 tsap_Config_t *sap_config;
11372
11373 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011374 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011375 return;
11376 }
11377
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011378 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011379 hdd_err("SoftAp role has not been enabled");
11380 return;
11381 }
11382
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011383 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11384 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11385 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011386 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011388 mutex_lock(&hdd_ctx->sap_lock);
11389 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11390 goto end;
11391
11392 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011393 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011394 goto end;
11395 }
11396
Wei Song2f76f642016-11-18 16:32:53 +080011397 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011398 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011399 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011400 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011401 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011402 goto end;
11403
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011404 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011405 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011406 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011407 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011408 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011409 goto end;
11410 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011411 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011412 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011413 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011414 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011415 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11416 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011417 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011418 mutex_unlock(&hdd_ctx->sap_lock);
11419
11420 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011421end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011422 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011423 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011424 /* SAP context and beacon cleanup will happen during driver unload
11425 * in hdd_stop_adapter
11426 */
11427 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11428
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011429}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011430
11431/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011432 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11433 * mac scan config
11434 * @status: Status of set antenna mode
11435 *
11436 * Callback on setting the dual mac configuration
11437 *
11438 * Return: None
11439 */
11440void wlan_hdd_soc_set_antenna_mode_cb(
11441 enum set_antenna_mode_status status)
11442{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011443 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011444
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011445 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011446
11447 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11448 if (0 != wlan_hdd_validate_context(hdd_ctx))
11449 return;
11450
11451 /* Signal the completion of set dual mac config */
11452 complete(&hdd_ctx->set_antenna_mode_cmpl);
11453}
11454
11455/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011456 * hdd_get_fw_version() - Get FW version
11457 * @hdd_ctx: pointer to HDD context.
11458 * @major_spid: FW version - major spid.
11459 * @minor_spid: FW version - minor spid
11460 * @ssid: FW version - ssid
11461 * @crmid: FW version - crmid
11462 *
11463 * This function is called to get the firmware build version stored
11464 * as part of the HDD context
11465 *
11466 * Return: None
11467 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011468void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011469 uint32_t *major_spid, uint32_t *minor_spid,
11470 uint32_t *siid, uint32_t *crmid)
11471{
11472 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11473 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11474 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11475 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11476}
11477
11478#ifdef QCA_CONFIG_SMP
11479/**
11480 * wlan_hdd_get_cpu() - get cpu_index
11481 *
11482 * Return: cpu_index
11483 */
11484int wlan_hdd_get_cpu(void)
11485{
11486 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011487
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011488 put_cpu();
11489 return cpu_index;
11490}
11491#endif
11492
11493/**
11494 * hdd_get_fwpath() - get framework path
11495 *
11496 * This function is used to get the string written by
11497 * userspace to start the wlan driver
11498 *
11499 * Return: string
11500 */
11501const char *hdd_get_fwpath(void)
11502{
11503 return fwpath.string;
11504}
11505
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011506static int hdd_qdf_print_init(void)
11507{
11508 int qdf_print_idx;
11509 QDF_STATUS status;
11510
11511 status = qdf_print_setup();
11512 if (status != QDF_STATUS_SUCCESS) {
11513 pr_err("qdf_print_setup failed\n");
11514 return -EINVAL;
11515 }
11516
11517 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11518
11519 if (qdf_print_idx < 0) {
11520 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11521 qdf_print_idx);
11522 return -EINVAL;
11523 }
11524
11525 qdf_set_pidx(qdf_print_idx);
11526
11527 return 0;
11528}
11529
11530static void hdd_qdf_print_deinit(void)
11531{
11532 int qdf_print_idx;
11533
11534 qdf_print_idx = qdf_get_pidx();
11535 qdf_print_ctrl_cleanup(qdf_print_idx);
11536}
11537
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011538/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011539 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011540 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011541 * This function initilizes CDS global context with the help of cds_init. This
11542 * has to be the first function called after probe to get a valid global
11543 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011544 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011545 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011546 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011547int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011548{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011549 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011550 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011551
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011552 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011553 if (QDF_IS_STATUS_ERROR(status)) {
11554 hdd_err("Failed to allocate CDS context");
11555 ret = -ENOMEM;
11556 goto err_out;
11557 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011558
11559 wlan_init_bug_report_lock();
11560
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011561#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11562 wlan_logging_sock_init_svc();
11563#endif
11564
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011565 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11566 (void *)hdd_drv_ops_inactivity_handler, NULL,
11567 QDF_TIMER_TYPE_SW);
11568
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011569 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011570 hdd_qdf_print_init();
11571
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011572 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011573
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011574err_out:
11575 return ret;
11576}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011577
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011578/**
11579 * hdd_deinit() - Deinitialize Driver
11580 *
11581 * This function frees CDS global context with the help of cds_deinit. This
11582 * has to be the last function call in remove callback to free the global
11583 * context.
11584 */
11585void hdd_deinit(void)
11586{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011587 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011588
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011589 wlan_destroy_bug_report_lock();
11590 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011591
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011592 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011593#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11594 wlan_logging_sock_deinit_svc();
11595#endif
11596}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011597
Yue Ma6e7b1a02017-04-03 14:17:46 -070011598#ifdef QCA_WIFI_NAPIER_EMULATION
11599#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11600#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011601#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011602#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011603
Sachin Ahujadddd2632017-03-07 19:07:24 +053011604static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11605 struct file *file)
11606{
11607 return 0;
11608}
11609
11610static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11611 const char __user *user_buf,
11612 size_t count,
11613 loff_t *f_pos)
11614{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011615 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011616 static const char wlan_off_str[] = "OFF";
11617 static const char wlan_on_str[] = "ON";
11618 int ret;
11619 unsigned long rc;
11620
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011621 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011622 pr_err("Failed to read buffer\n");
11623 return -EINVAL;
11624 }
11625
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011626 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011627 pr_debug("Wifi turning off from UI\n");
11628 goto exit;
11629 }
11630
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011631 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011632 pr_err("Invalid value received from framework");
11633 goto exit;
11634 }
11635
11636 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011637 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011638 rc = wait_for_completion_timeout(&wlan_start_comp,
11639 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11640 if (!rc) {
11641 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11642 ret = -EINVAL;
11643 hdd_start_complete(ret);
11644 return ret;
11645 }
11646
11647 hdd_start_complete(0);
11648 }
11649
11650exit:
11651 return count;
11652}
11653
11654
11655const struct file_operations wlan_hdd_state_fops = {
11656 .owner = THIS_MODULE,
11657 .open = wlan_hdd_state_ctrl_param_open,
11658 .write = wlan_hdd_state_ctrl_param_write,
11659};
11660
11661static int wlan_hdd_state_ctrl_param_create(void)
11662{
11663 unsigned int wlan_hdd_state_major = 0;
11664 int ret;
11665 struct device *dev;
11666
11667 device = MKDEV(wlan_hdd_state_major, 0);
11668
11669 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11670 if (ret) {
11671 pr_err("Failed to register qcwlanstate");
11672 goto dev_alloc_err;
11673 }
11674 wlan_hdd_state_major = MAJOR(device);
11675
11676 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11677 if (IS_ERR(class)) {
11678 pr_err("wlan_hdd_state class_create error");
11679 goto class_err;
11680 }
11681
11682 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11683 if (IS_ERR(dev)) {
11684 pr_err("wlan_hdd_statedevice_create error");
11685 goto err_class_destroy;
11686 }
11687
11688 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11689 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11690 if (ret) {
11691 pr_err("Failed to add cdev error");
11692 goto cdev_add_err;
11693 }
11694
11695 pr_info("wlan_hdd_state %s major(%d) initialized",
11696 WLAN_MODULE_NAME, wlan_hdd_state_major);
11697
11698 return 0;
11699
11700cdev_add_err:
11701 device_destroy(class, device);
11702err_class_destroy:
11703 class_destroy(class);
11704class_err:
11705 unregister_chrdev_region(device, dev_num);
11706dev_alloc_err:
11707 return -ENODEV;
11708}
11709
11710static void wlan_hdd_state_ctrl_param_destroy(void)
11711{
11712 cdev_del(&wlan_hdd_state_cdev);
11713 device_destroy(class, device);
11714 class_destroy(class);
11715 unregister_chrdev_region(device, dev_num);
11716
11717 pr_info("Device node unregistered");
11718}
11719
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011720/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011721 * component_init - API to init cld component's
11722 *
11723 * Return: None
11724 */
11725static void component_init(void)
11726{
11727 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011728 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011729 ucfg_ocb_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011730}
11731
11732/**
11733 * component_deinit - API to deinit cld component's
11734 *
11735 * Return: None
11736 */
11737static void component_deinit(void)
11738{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011739 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011740 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011741 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011742}
11743
11744void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11745{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011746 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011747 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011748}
11749
11750void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11751{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011752 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011753 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011754}
11755
11756/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011757 * __hdd_module_init - Module init helper
11758 *
11759 * Module init helper function used by both module and static driver.
11760 *
11761 * Return: 0 for success, errno on failure
11762 */
11763static int __hdd_module_init(void)
11764{
11765 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011766
Dustin Brown96cd9632017-11-13 12:45:04 -080011767 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011768 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011769 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011770 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011771
Sachin Ahujadddd2632017-03-07 19:07:24 +053011772 ret = wlan_hdd_state_ctrl_param_create();
11773 if (ret) {
11774 pr_err("wlan_hdd_state_create:%x\n", ret);
11775 goto err_dev_state;
11776 }
11777
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011778 pld_init();
11779
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011780 ret = hdd_init();
11781 if (ret) {
11782 pr_err("hdd_init failed %x\n", ret);
11783 goto err_hdd_init;
11784 }
11785
Rajeev Kumar97767a02016-11-30 11:20:40 -080011786 dispatcher_init();
11787
Mukul Sharmad75a6672017-06-22 15:40:53 +053011788 /* Ensure to call post objmgr init */
11789 component_init();
11790
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011791 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011792
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011793 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011794
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011795 ret = wlan_hdd_register_driver();
11796 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011797 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11798 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011799 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011800 }
11801
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011802 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011803
11804 return 0;
11805out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011806 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011807 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011808 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011809 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011810
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011811err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011812 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011813 wlan_hdd_state_ctrl_param_destroy();
11814err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011815 return ret;
11816}
11817
11818/**
11819 * __hdd_module_exit - Module exit helper
11820 *
11821 * Module exit helper function used by both module and static driver.
11822 */
11823static void __hdd_module_exit(void)
11824{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011825
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011826 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11827 QWLAN_VERSIONSTR);
11828
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011829 hdd_wait_for_recovery_completion();
11830
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011831 wlan_hdd_unregister_driver();
11832
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011833 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011834
Mukul Sharmad75a6672017-06-22 15:40:53 +053011835 /* Ensure to call prior to objmgr deinit */
11836 component_deinit();
11837
Rajeev Kumar97767a02016-11-30 11:20:40 -080011838 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011839
11840 hdd_sysfs_destroy_version_interface();
11841
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011842 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011843 pld_deinit();
11844
Sachin Ahujadddd2632017-03-07 19:07:24 +053011845 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011846}
11847
Arun Khandavallifae92942016-08-01 13:31:08 +053011848#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011849/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011850 * wlan_boot_cb() - Wlan boot callback
11851 * @kobj: object whose directory we're creating the link in.
11852 * @attr: attribute the user is interacting with
11853 * @buff: the buffer containing the user data
11854 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011855 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011856 * This callback is invoked when the fs is ready to start the
11857 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011858 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011859 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011860 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011861static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011862 struct kobj_attribute *attr,
11863 const char *buf,
11864 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011865{
Arun Khandavallifae92942016-08-01 13:31:08 +053011866
Arun Khandavallifae92942016-08-01 13:31:08 +053011867 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011868 pr_err("%s: wlan driver already initialized\n", __func__);
11869 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011870 }
11871
Arun Khandavallifae92942016-08-01 13:31:08 +053011872 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011873 pr_err("%s: wlan driver initialization failed\n", __func__);
11874 return -EIO;
11875 }
11876
11877 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011878
11879 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011880}
Arun Khandavallifae92942016-08-01 13:31:08 +053011881
11882/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011883 * hdd_sysfs_cleanup() - cleanup sysfs
11884 *
11885 * Return: None
11886 *
11887 */
11888static void hdd_sysfs_cleanup(void)
11889{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011890 /* remove from group */
11891 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11892 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11893 wlan_loader->attr_group);
11894
11895 /* unlink the object from parent */
11896 kobject_del(wlan_loader->boot_wlan_obj);
11897
11898 /* free the object */
11899 kobject_put(wlan_loader->boot_wlan_obj);
11900
11901 kfree(wlan_loader->attr_group);
11902 kfree(wlan_loader);
11903
11904 wlan_loader = NULL;
11905}
11906
11907/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011908 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11909 * ready
11910 *
11911 * This is creates the syfs entry boot_wlan. Which shall be invoked
11912 * when the filesystem is ready.
11913 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011914 * QDF API cannot be used here since this function is called even before
11915 * initializing WLAN driver.
11916 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011917 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011918 */
11919static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011920{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011921 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011922
11923 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011924 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011925 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011926
11927 wlan_loader->boot_wlan_obj = NULL;
11928 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11929 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011930 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011931 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011932
11933 wlan_loader->loaded_state = 0;
11934 wlan_loader->attr_group->attrs = attrs;
11935
11936 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11937 kernel_kobj);
11938 if (!wlan_loader->boot_wlan_obj) {
11939 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011940 goto error_return;
11941 }
11942
11943 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11944 wlan_loader->attr_group);
11945 if (ret) {
11946 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11947 goto error_return;
11948 }
11949
11950 return 0;
11951
11952error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011953 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011954
11955 return ret;
11956}
11957
11958/**
11959 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11960 *
11961 * Return: 0 on success or errno on failure
11962 */
11963static int wlan_deinit_sysfs(void)
11964{
Arun Khandavallifae92942016-08-01 13:31:08 +053011965 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011966 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011967 return -EINVAL;
11968 }
11969
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011970 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011971 return 0;
11972}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011973
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011974#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011975
11976#ifdef MODULE
11977/**
11978 * __hdd_module_init - Module init helper
11979 *
11980 * Module init helper function used by both module and static driver.
11981 *
11982 * Return: 0 for success, errno on failure
11983 */
11984static int hdd_module_init(void)
11985{
Arun Khandavallifae92942016-08-01 13:31:08 +053011986 if (__hdd_module_init()) {
11987 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011988 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011989 }
11990
Dustin Brownab482ac2017-06-09 17:00:44 -070011991 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011992}
11993#else
11994static int __init hdd_module_init(void)
11995{
11996 int ret = -EINVAL;
11997
11998 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011999 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012000 pr_err("Failed to create sysfs entry for loading wlan");
12001
12002 return ret;
12003}
12004#endif
12005
12006
12007#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012008/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012009 * hdd_module_exit() - Exit function
12010 *
12011 * This is the driver exit point (invoked when module is unloaded using rmmod)
12012 *
12013 * Return: None
12014 */
12015static void __exit hdd_module_exit(void)
12016{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012017 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012018}
Arun Khandavallifae92942016-08-01 13:31:08 +053012019#else
12020static void __exit hdd_module_exit(void)
12021{
12022 __hdd_module_exit();
12023 wlan_deinit_sysfs();
12024}
12025#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012026
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012027static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
12028{
12029 return param_set_copystring(kmessage, kp);
12030}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012031
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012032/**
12033 * is_con_mode_valid() check con mode is valid or not
12034 * @mode: global con mode
12035 *
12036 * Return: TRUE on success FALSE on failure
12037 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012038static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012039{
12040 switch (mode) {
12041 case QDF_GLOBAL_MONITOR_MODE:
12042 case QDF_GLOBAL_FTM_MODE:
12043 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012044 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012045 return true;
12046 default:
12047 return false;
12048 }
12049}
12050
12051/**
12052 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12053 * @mode: global con mode
12054 *
12055 * Return: adapter mode
12056 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012057static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012058 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012059{
12060
12061 switch (mode) {
12062 case QDF_GLOBAL_MISSION_MODE:
12063 return QDF_STA_MODE;
12064 case QDF_GLOBAL_MONITOR_MODE:
12065 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012066 case QDF_GLOBAL_EPPING_MODE:
12067 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012068 case QDF_GLOBAL_FTM_MODE:
12069 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012070 case QDF_GLOBAL_QVIT_MODE:
12071 return QDF_QVIT_MODE;
12072 default:
12073 return QDF_MAX_NO_OF_MODE;
12074 }
12075}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012076
Dustin Brown27cd9942017-09-27 16:11:44 -070012077static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012078 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012079{
12080 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12081 return;
12082
12083 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012084 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012085 hdd_info("Release wakelock for monitor mode!");
12086 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12087 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12088 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012089 case QDF_GLOBAL_FTM_MODE:
12090 hdd_abort_mac_scan_all_adapters(hdd_ctx);
12091 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012092 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012093
Dustin Brown27cd9942017-09-27 16:11:44 -070012094 break;
12095 default:
12096 break;
12097 }
12098}
12099
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012100static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012101 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012102{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012103 int driver_status;
12104
12105 driver_status = hdd_ctx->driver_status;
12106
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012107 switch (curr_mode) {
12108 case QDF_GLOBAL_MISSION_MODE:
12109 case QDF_GLOBAL_MONITOR_MODE:
12110 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012111 hdd_deinit_all_adapters(hdd_ctx, false);
12112 hdd_close_all_adapters(hdd_ctx, false);
12113 break;
12114 case QDF_GLOBAL_EPPING_MODE:
12115 epping_disable();
12116 epping_close();
12117 break;
12118 default:
12119 return;
12120 }
12121}
12122
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012123static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012124 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012125{
Jeff Johnson9d295242017-08-29 14:39:48 -070012126 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012127 int ret = 0;
12128 bool rtnl_held;
12129 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12130 QDF_STATUS status;
12131
12132 if (!qdf_dev) {
12133 hdd_err("qdf device context is Null return!");
12134 return -EINVAL;
12135 }
12136
12137 rtnl_held = hdd_hold_rtnl_lock();
12138 switch (mode) {
12139 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012140 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12141 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012142 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012143 break;
12144 case QDF_GLOBAL_FTM_MODE:
12145 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12146 wlan_hdd_get_intf_addr(hdd_ctx),
12147 NET_NAME_UNKNOWN, rtnl_held);
12148 if (adapter == NULL)
12149 ret = -EINVAL;
12150 break;
12151 case QDF_GLOBAL_MONITOR_MODE:
12152 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12153 wlan_hdd_get_intf_addr(hdd_ctx),
12154 NET_NAME_UNKNOWN, rtnl_held);
12155 if (adapter == NULL)
12156 ret = -EINVAL;
12157 break;
12158 case QDF_GLOBAL_EPPING_MODE:
12159 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012160 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012161 hdd_err("Failed to open in eeping mode: %d", status);
12162 ret = -EINVAL;
12163 break;
12164 }
12165 ret = epping_enable(qdf_dev->dev);
12166 if (ret) {
12167 hdd_err("Failed to enable in epping mode : %d", ret);
12168 epping_close();
12169 }
12170 break;
12171 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012172 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012173 ret = -ENOTSUPP;
12174 break;
12175 }
12176 hdd_release_rtnl_lock();
12177 rtnl_held = false;
12178 return ret;
12179}
12180
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012181/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012182 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012183 * @kmessage: con mode name on which driver to be bring up
12184 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012185 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012186 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012187 * This function is invoked when user updates con mode using sys entry,
12188 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012189 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012190 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012191 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012192static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012193 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012194{
12195 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012196 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012197 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012198 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012199 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012200
Dustin Brownab6029b2017-05-24 13:04:19 -070012201 hdd_info("con_mode handler: %s", kmessage);
12202
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012203 ret = wlan_hdd_validate_context(hdd_ctx);
12204 if (ret)
12205 return ret;
12206
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012207 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012208 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012209
Dustin Brown20024e32018-01-03 12:34:58 -080012210 ret = kstrtoint(kmessage, 0, &new_con_mode);
12211 if (ret) {
12212 hdd_err("Failed to parse con_mode '%s'", kmessage);
12213 goto reset_flags;
12214 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012215 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012216
Dustin Brown20024e32018-01-03 12:34:58 -080012217 if (!is_con_mode_valid(new_con_mode)) {
12218 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012219 ret = -EINVAL;
12220 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012221 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012222
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012223 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012224 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012225 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012226 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012227 ret = 0;
12228 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012229 }
12230
Dustin Brown27cd9942017-09-27 16:11:44 -070012231 /* ensure adapters are stopped */
12232 hdd_stop_present_mode(hdd_ctx, curr_mode);
12233
Frank Liu6666f832018-01-04 10:06:05 +080012234 /* Cleanup present mode before switching to new mode */
12235 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12236
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012237 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012238 if (ret) {
12239 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012240 goto reset_flags;
12241 }
12242
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012243
Dustin Brown20024e32018-01-03 12:34:58 -080012244 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012245
Frank Liu6666f832018-01-04 10:06:05 +080012246 /*
12247 * Set ACTIVE domain before adapters created, otherwise check domain
12248 * match will fail when cleanup adapters.
12249 */
12250 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012251 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012252 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012253 if (ret) {
12254 hdd_err("Failed to register for new mode");
12255 goto reset_flags;
12256 }
12257
Dustin Brown20024e32018-01-03 12:34:58 -080012258 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012259 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12260 hdd_err("invalid adapter");
12261 ret = -EINVAL;
12262 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012263 }
12264
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012265 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012266 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012267 hdd_err("Failed to get adapter:%d", adapter_mode);
12268 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012269 }
12270
12271 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12272 if (ret) {
12273 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012274 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012275 }
12276
Dustin Brown20024e32018-01-03 12:34:58 -080012277 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012278 if (hdd_start_adapter(adapter)) {
12279 hdd_err("Failed to start %s adapter", kmessage);
12280 ret = -EINVAL;
12281 goto reset_flags;
12282 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012283
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012284 hdd_info("Acquire wakelock for monitor mode!");
12285 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12286 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12287 }
12288
Dustin Brown20024e32018-01-03 12:34:58 -080012289 /* con_mode is a global module parameter */
12290 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012291 hdd_info("Mode successfully changed to %s", kmessage);
12292 ret = 0;
12293
12294reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012295 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012296 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012297 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012298 return ret;
12299}
12300
12301
12302static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12303{
12304 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012305 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012306
12307 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12308 ret = wlan_hdd_validate_context(hdd_ctx);
12309 if (ret)
12310 return ret;
12311
12312 cds_ssr_protect(__func__);
12313 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12314 cds_ssr_unprotect(__func__);
12315
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012316 return ret;
12317}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012318
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012319static int con_mode_handler_ftm(const char *kmessage,
12320 struct kernel_param *kp)
12321{
12322 int ret;
12323
12324 ret = param_set_int(kmessage, kp);
12325
12326 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12327 pr_err("Only FTM mode supported!");
12328 return -ENOTSUPP;
12329 }
12330
12331 hdd_set_conparam(con_mode_ftm);
12332 con_mode = con_mode_ftm;
12333
12334 return ret;
12335}
12336
Ravi Joshia307f632017-07-17 23:41:41 -070012337static int con_mode_handler_monitor(const char *kmessage,
12338 struct kernel_param *kp)
12339{
12340 int ret;
12341
12342 ret = param_set_int(kmessage, kp);
12343
12344 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12345 pr_err("Only Monitor mode supported!");
12346 return -ENOTSUPP;
12347 }
12348
12349 hdd_set_conparam(con_mode_monitor);
12350 con_mode = con_mode_monitor;
12351
12352 return ret;
12353}
12354
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012355/**
12356 * hdd_get_conparam() - driver exit point
12357 *
12358 * This is the driver exit point (invoked when module is unloaded using rmmod)
12359 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012360 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012361 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012362enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012363{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012364 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012365}
12366
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012367void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012368{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012369 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012370}
12371
Komal Seelamc11bb222016-01-27 18:57:10 +053012372/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012373 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12374 * @hdd_ctx: HDD context
12375 *
12376 * Cleans up the pre cac interface, if it exists
12377 *
12378 * Return: None
12379 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012380void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012381{
12382 uint8_t session_id;
12383 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012384 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012385
12386 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12387 if (QDF_IS_STATUS_ERROR(status)) {
12388 hdd_err("failed to get pre cac vdev id");
12389 return;
12390 }
12391
12392 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12393 if (!precac_adapter) {
12394 hdd_err("invalid pre cac adapater");
12395 return;
12396 }
12397
12398 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12399 wlan_hdd_sap_pre_cac_failure,
12400 (void *)precac_adapter);
12401 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12402
12403}
12404
12405/**
Komal Seelamec702b02016-02-24 18:42:16 +053012406 * hdd_update_ol_config - API to update ol configuration parameters
12407 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012408 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012409 * Return: void
12410 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012411static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012412{
Komal Seelamec702b02016-02-24 18:42:16 +053012413 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012414 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012415
Komal Seelamec702b02016-02-24 18:42:16 +053012416 if (!ol_ctx)
12417 return;
12418
12419 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12420 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12421 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12422 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012423 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012424
12425 ol_init_ini_config(ol_ctx, &cfg);
12426}
12427
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012428#ifdef FEATURE_RUNTIME_PM
12429/**
12430 * hdd_populate_runtime_cfg() - populate runtime configuration
12431 * @hdd_ctx: hdd context
12432 * @cfg: pointer to the configuration memory being populated
12433 *
12434 * Return: void
12435 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012436static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012437 struct hif_config_info *cfg)
12438{
12439 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12440 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12441}
12442#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012443static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012444 struct hif_config_info *cfg)
12445{
12446}
12447#endif
12448
Komal Seelamec702b02016-02-24 18:42:16 +053012449/**
12450 * hdd_update_hif_config - API to update HIF configuration parameters
12451 * @hdd_ctx: HDD Context
12452 *
12453 * Return: void
12454 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012455static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012456{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012457 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012458 struct hif_config_info cfg;
12459
12460 if (!scn)
12461 return;
12462
12463 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012464 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012465 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012466
12467 if (hdd_ctx->config->prevent_link_down)
12468 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012469}
12470
12471/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012472 * hdd_update_dp_config() - Propagate config parameters to Lithium
12473 * datapath
12474 * @hdd_ctx: HDD Context
12475 *
12476 * Return: 0 for success/errno for failure
12477 */
12478static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12479{
12480 struct cdp_config_params params;
12481 QDF_STATUS status;
12482
12483 params.tso_enable = hdd_ctx->config->tso_enable;
12484 params.lro_enable = hdd_ctx->config->lro_enable;
12485#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12486 params.tx_flow_stop_queue_threshold =
12487 hdd_ctx->config->TxFlowStopQueueThreshold;
12488 params.tx_flow_start_queue_offset =
12489 hdd_ctx->config->TxFlowStartQueueOffset;
12490#endif
12491 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12492 params.napi_enable = hdd_ctx->napi_enable;
12493 params.tcp_udp_checksumoffload =
12494 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12495
12496 status = cdp_update_config_parameters(
12497 cds_get_context(QDF_MODULE_ID_SOC),
12498 &params);
12499 if (status) {
12500 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12501 "%s: Failed to attach config parameters", __func__);
12502 return status;
12503 }
12504
12505 return 0;
12506}
12507
12508/**
Komal Seelamec702b02016-02-24 18:42:16 +053012509 * hdd_update_config() - Initialize driver per module ini parameters
12510 * @hdd_ctx: HDD Context
12511 *
12512 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012513 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012514 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012515int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012516{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012517 int ret;
12518
Komal Seelamec702b02016-02-24 18:42:16 +053012519 hdd_update_ol_config(hdd_ctx);
12520 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012521 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12522 ret = hdd_update_cds_config_ftm(hdd_ctx);
12523 else
12524 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012525 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012526
12527 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012528}
12529
Mukul Sharma9d797a02017-01-05 20:26:03 +053012530#ifdef FEATURE_WLAN_RA_FILTERING
12531/**
12532 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12533 * @psoc_cfg: pmo psoc Configuration
12534 * @hdd_ctx: Pointer to hdd context
12535 *
12536 * Return: none
12537 */
12538static inline void hdd_ra_populate_pmo_config(
12539 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012540 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012541{
12542 psoc_cfg->ra_ratelimit_interval =
12543 hdd_ctx->config->RArateLimitInterval;
12544 psoc_cfg->ra_ratelimit_enable =
12545 hdd_ctx->config->IsRArateLimitEnabled;
12546}
12547#else
12548static inline void hdd_ra_populate_pmo_config(
12549 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012550 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012551{
12552}
12553#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012554
Mukul Sharma9d797a02017-01-05 20:26:03 +053012555/**
12556 * hdd_update_pmo_config - API to update pmo configuration parameters
12557 * @hdd_ctx: HDD context
12558 *
12559 * Return: void
12560 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012561static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012562{
12563 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12564 struct pmo_psoc_cfg psoc_cfg;
12565 QDF_STATUS status;
12566
12567 /*
12568 * Value of hdd_ctx->wowEnable can be,
12569 * 0 - Disable both magic pattern match and pattern byte match.
12570 * 1 - Enable magic pattern match on all interfaces.
12571 * 2 - Enable pattern byte match on all interfaces.
12572 * 3 - Enable both magic patter and pattern byte match on
12573 * all interfaces.
12574 */
12575 psoc_cfg.magic_ptrn_enable =
12576 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12577 psoc_cfg.ptrn_match_enable_all_vdev =
12578 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012579 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
Sourav Mohapatra89c85d12017-12-01 09:17:54 +053012580 wmi_service_unified_wow_capability);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012581 psoc_cfg.bpf_enable =
12582 hdd_ctx->config->bpf_packet_filter_enable;
12583 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012584 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012585 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12586 if (hdd_ctx->config->fhostNSOffload)
12587 psoc_cfg.ns_offload_enable_dynamic = true;
12588 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12589 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12590 psoc_cfg.active_mode_offload =
12591 hdd_ctx->config->active_mode_offload;
12592 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012593 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012594 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012595 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12596 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12597 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12598 psoc_cfg.power_save_mode =
12599 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012600 psoc_cfg.auto_power_save_fail_mode =
12601 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012602
12603 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012604 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12605 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012606 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012607 if (status != QDF_STATUS_SUCCESS) {
12608 hdd_err("failed pmo psoc configuration");
12609 return -EINVAL;
12610 }
12611
12612 return 0;
12613}
12614
Abhishek Singhb20db962017-03-03 21:28:46 +053012615#ifdef FEATURE_WLAN_SCAN_PNO
12616static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12617 struct hdd_config *cfg)
12618{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012619 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12620
Abhishek Singhb20db962017-03-03 21:28:46 +053012621 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12622 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12623 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12624 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12625 pno_cfg->channel_prediction_full_scan =
12626 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012627 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12628 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12629 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12630 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012631}
12632#else
12633static inline void
12634hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012635 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012636{
Abhishek Singhb20db962017-03-03 21:28:46 +053012637}
12638#endif
12639
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012640void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12641 struct hdd_config *cfg)
12642{
12643 uint8_t i = 0;
12644
12645 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12646 if (!ie_whitelist->white_list)
12647 return;
12648
12649 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12650 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12651 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12652 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12653 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12654 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12655 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12656 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12657
12658 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12659 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12660 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12661}
12662
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012663uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12664{
12665 uint8_t i, score;
12666
12667 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12668 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12669 if (score > MAX_INDEX_SCORE)
12670 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12671 MAX_INDEX_SCORE, i);
12672 }
12673
12674 return per_index_score;
12675}
12676
12677/**
12678 * hdd_update_score_config - API to update candidate scoring related params
12679 * configuration parameters
12680 * @score_config: score config to update
12681 * @cfg: config params
12682 *
12683 * Return: 0 if success else err
12684 */
12685static void hdd_update_score_config(
12686 struct scoring_config *score_config, struct hdd_config *cfg)
12687{
12688 int total_weight;
12689
12690 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12691 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12692 score_config->weight_cfg.vht_caps_weightage =
12693 cfg->vht_caps_weightage;
12694 score_config->weight_cfg.he_caps_weightage =
12695 cfg->he_caps_weightage;
12696 score_config->weight_cfg.chan_width_weightage =
12697 cfg->chan_width_weightage;
12698 score_config->weight_cfg.chan_band_weightage =
12699 cfg->chan_band_weightage;
12700 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12701 score_config->weight_cfg.beamforming_cap_weightage =
12702 cfg->beamforming_cap_weightage;
12703 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12704 score_config->weight_cfg.channel_congestion_weightage =
12705 cfg->channel_congestion_weightage;
12706 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12707
12708 total_weight = score_config->weight_cfg.rssi_weightage +
12709 score_config->weight_cfg.ht_caps_weightage +
12710 score_config->weight_cfg.vht_caps_weightage +
12711 score_config->weight_cfg.he_caps_weightage +
12712 score_config->weight_cfg.chan_width_weightage +
12713 score_config->weight_cfg.chan_band_weightage +
12714 score_config->weight_cfg.nss_weightage +
12715 score_config->weight_cfg.beamforming_cap_weightage +
12716 score_config->weight_cfg.pcl_weightage +
12717 score_config->weight_cfg.channel_congestion_weightage +
12718 score_config->weight_cfg.oce_wan_weightage;
12719
12720 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12721 hdd_err("total weight is greater than %d fallback to default values",
12722 BEST_CANDIDATE_MAX_WEIGHT);
12723
12724 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12725 score_config->weight_cfg.ht_caps_weightage =
12726 HT_CAPABILITY_WEIGHTAGE;
12727 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12728 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12729 score_config->weight_cfg.chan_width_weightage =
12730 CHAN_WIDTH_WEIGHTAGE;
12731 score_config->weight_cfg.chan_band_weightage =
12732 CHAN_BAND_WEIGHTAGE;
12733 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12734 score_config->weight_cfg.beamforming_cap_weightage =
12735 BEAMFORMING_CAP_WEIGHTAGE;
12736 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12737 score_config->weight_cfg.channel_congestion_weightage =
12738 CHANNEL_CONGESTION_WEIGHTAGE;
12739 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12740 }
12741
12742 score_config->bandwidth_weight_per_index =
12743 hdd_limit_max_per_index_score(
12744 cfg->bandwidth_weight_per_index);
12745 score_config->nss_weight_per_index =
12746 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12747 score_config->band_weight_per_index =
12748 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12749
12750 score_config->rssi_score.best_rssi_threshold =
12751 cfg->best_rssi_threshold;
12752 score_config->rssi_score.good_rssi_threshold =
12753 cfg->good_rssi_threshold;
12754 score_config->rssi_score.bad_rssi_threshold =
12755 cfg->bad_rssi_threshold;
12756 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12757 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12758 score_config->rssi_score.good_rssi_bucket_size =
12759 cfg->good_rssi_bucket_size;
12760 score_config->rssi_score.bad_rssi_bucket_size =
12761 cfg->bad_rssi_bucket_size;
12762 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12763 cfg->rssi_pref_5g_rssi_thresh;
12764
12765 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12766 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12767 hdd_limit_max_per_index_score(
12768 cfg->esp_qbss_score_slots3_to_0);
12769 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12770 hdd_limit_max_per_index_score(
12771 cfg->esp_qbss_score_slots7_to_4);
12772 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12773 hdd_limit_max_per_index_score(
12774 cfg->esp_qbss_score_slots11_to_8);
12775 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12776 hdd_limit_max_per_index_score(
12777 cfg->esp_qbss_score_slots15_to_12);
12778
12779 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12780 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12781 hdd_limit_max_per_index_score(
12782 cfg->oce_wan_score_slots3_to_0);
12783 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12784 hdd_limit_max_per_index_score(
12785 cfg->oce_wan_score_slots7_to_4);
12786 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12787 hdd_limit_max_per_index_score(
12788 cfg->oce_wan_score_slots11_to_8);
12789 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12790 hdd_limit_max_per_index_score(
12791 cfg->oce_wan_score_slots15_to_12);
12792
12793
12794 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12795 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12796 score_config->nss = cfg->enable2x2 ? 2 : 1;
12797
12798 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12799 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12800 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12801 score_config->he_cap = 1;
12802
12803 if (score_config->he_cap ||
12804 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12805 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12806 score_config->vht_cap = 1;
12807
12808 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12809 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12810 score_config->ht_cap = 1;
12811
12812 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12813 score_config->vht_24G_cap = 1;
12814
12815 if (cfg->enableTxBF)
12816 score_config->beamformee_cap = 1;
12817
12818}
12819
Abhishek Singh257a9482017-03-06 16:52:39 +053012820/**
bings81fe50a2017-11-27 14:33:26 +080012821 * hdd_update_dfs_config() - API to update dfs configuration parameters.
12822 * @hdd_ctx: HDD context
12823 *
12824 * Return: 0 if success else err
12825 */
12826static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
12827{
12828 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12829 struct hdd_config *cfg = hdd_ctx->config;
12830 struct dfs_user_config dfs_cfg;
12831 QDF_STATUS status;
12832
12833 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
12834 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
12835 if (QDF_IS_STATUS_ERROR(status)) {
12836 hdd_err("failed dfs psoc configuration");
12837 return -EINVAL;
12838 }
12839
12840 return 0;
12841}
12842
12843/**
Abhishek Singh257a9482017-03-06 16:52:39 +053012844 * hdd_update_scan_config - API to update scan configuration parameters
12845 * @hdd_ctx: HDD context
12846 *
12847 * Return: 0 if success else err
12848 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012849static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012850{
12851 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12852 struct scan_user_cfg scan_cfg;
12853 struct hdd_config *cfg = hdd_ctx->config;
12854 QDF_STATUS status;
12855
12856 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12857 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12858 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12859 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12860 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12861 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12862 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012863 /* convert to ms */
12864 scan_cfg.scan_cache_aging_time =
12865 cfg->scanAgingTimeout * 1000;
12866 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12867 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12868 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12869 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012870 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012871 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012872 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12873 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012874 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012875 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053012876 scan_cfg.sta_miracast_mcc_rest_time =
12877 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053012878
Abhishek Singhb20db962017-03-03 21:28:46 +053012879 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012880 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012881 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012882
Abhishek Singh257a9482017-03-06 16:52:39 +053012883 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12884 if (status != QDF_STATUS_SUCCESS) {
12885 hdd_err("failed pmo psoc configuration");
12886 return -EINVAL;
12887 }
12888
12889 return 0;
12890}
Abhishek Singh257a9482017-03-06 16:52:39 +053012891
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012892int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012893{
12894 int ret;
12895
12896 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012897 if (ret)
12898 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012899
Abhishek Singh257a9482017-03-06 16:52:39 +053012900 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012901 if (ret)
12902 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012903
Frank Liud4b2fa02017-03-29 11:46:48 +080012904 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012905 if (ret)
12906 return ret;
12907
12908 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080012909 if (ret)
12910 return ret;
12911
12912 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012913
12914 return ret;
12915}
12916
Agrawal Ashish65634612016-08-18 13:24:32 +053012917/**
12918 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12919 * @mode : cfg80211 DFS mode
12920 *
12921 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12922 */
12923enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12924{
12925 switch (mode) {
12926 case DFS_MODE_ENABLE:
12927 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012928 case DFS_MODE_DISABLE:
12929 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012930 case DFS_MODE_DEPRIORITIZE:
12931 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012932 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012933 hdd_debug("ACS dfs mode is NONE");
12934 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012935 }
12936}
12937
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012938/**
12939 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12940 * @hddctx: pointer to hdd context
12941 * @set_value: enable/disable
12942 *
12943 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12944 * Host(even though it is duplicate). When Host send vendor command
12945 * disable,FW doesn't perform any action. Whenever any change in
12946 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12947 *
12948 * return - 0 on success, appropriate error values on failure.
12949 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012950int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012951{
12952 QDF_STATUS status;
12953
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012954 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012955 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012956
12957 if (!hddctx->config->goptimize_chan_avoid_event) {
12958 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12959 return -EINVAL;
12960 }
12961
12962 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12963 if (!QDF_IS_STATUS_SUCCESS(status)) {
12964 hdd_err("Failed to send chan avoid command to SME");
12965 return -EINVAL;
12966 }
12967 return 0;
12968}
Agrawal Ashish65634612016-08-18 13:24:32 +053012969
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012970/**
12971 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12972 * @value: value to set
12973 *
12974 * This function will set the passed value to roaming in progress flag.
12975 *
12976 * Return: None
12977 */
12978void hdd_set_roaming_in_progress(bool value)
12979{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012980 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012981
12982 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12983 if (!hdd_ctx) {
12984 hdd_err("HDD context is NULL");
12985 return;
12986 }
12987
12988 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012989 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012990}
12991
12992/**
12993 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012994 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012995 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012996 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012997 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012998bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012999{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013000 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013001 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013002
13003 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13004 if (!hdd_ctx) {
13005 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013006 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013007 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013008 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13009 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013010 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13011 hdd_ctx->roaming_in_progress);
13012
13013 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013014}
13015
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013016/**
13017 * hdd_is_connection_in_progress() - check if connection is in
13018 * progress
13019 * @session_id: session id
13020 * @reason: scan reject reason
13021 *
13022 * Go through each adapter and check if Connection is in progress
13023 *
13024 * Return: true if connection is in progress else false
13025 */
13026bool hdd_is_connection_in_progress(uint8_t *session_id,
13027 enum scan_reject_states *reason)
13028{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013029 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013030 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013031 uint8_t sta_id = 0;
13032 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013033 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013034
13035 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13036 if (!hdd_ctx) {
13037 hdd_err("HDD context is NULL");
13038 return false;
13039 }
13040
Dustin Brown920397d2017-12-13 16:27:50 -080013041 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013042 hdd_info("Adapter with device mode %s(%d) exists",
13043 hdd_device_mode_to_string(adapter->device_mode),
13044 adapter->device_mode);
13045 if (((QDF_STA_MODE == adapter->device_mode)
13046 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13047 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13048 && (eConnectionState_Connecting ==
13049 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13050 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013051 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013052 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013053 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013054 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013055 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013056 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013057 }
13058 return true;
13059 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013060 /*
13061 * sme_neighbor_middle_of_roaming is for LFR2
13062 * hdd_is_roaming_in_progress is for LFR3
13063 */
13064 if (((QDF_STA_MODE == adapter->device_mode) &&
13065 sme_neighbor_middle_of_roaming(
13066 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013067 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013068 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013069 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013070 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013071 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013072 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013073 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013074 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013075 }
13076 return true;
13077 }
13078 if ((QDF_STA_MODE == adapter->device_mode) ||
13079 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13080 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13081 hdd_sta_ctx =
13082 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13083 if ((eConnectionState_Associated ==
13084 hdd_sta_ctx->conn_info.connState)
13085 && (false ==
13086 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
13087 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013088 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013089 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013090 " is in middle of WPS/EAPOL exchange.",
13091 MAC_ADDR_ARRAY(sta_mac));
13092 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 = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013095 }
13096 return true;
13097 }
13098 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13099 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13100 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13101 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013102 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013103 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013104 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013105 continue;
13106
13107 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013108 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013109 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013110 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013111 " of SAP/GO is in middle of WPS/EAPOL exchange",
13112 MAC_ADDR_ARRAY(sta_mac));
13113 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013114 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013115 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013116 }
13117 return true;
13118 }
13119 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013120 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013121 return true;
13122 }
13123 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013124 }
Dustin Brown920397d2017-12-13 16:27:50 -080013125
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013126 return false;
13127}
13128
13129/**
13130 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013131 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013132 *
13133 * Return: None
13134 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013135void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013136{
Jeff Johnson87251032017-08-29 13:31:11 -070013137 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013138 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013139 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013140 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013141 tsap_Config_t *sap_config;
13142 void *sap_ctx;
13143
13144 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013145 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013146 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013147
13148 mutex_lock(&hdd_ctx->sap_lock);
13149 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13150 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013151 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13152 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13153 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13154 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013155 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013156 qdf_stop_bss_event,
13157 SME_CMD_TIMEOUT_VALUE);
13158
13159 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013160 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013161 goto end;
13162 }
13163 }
13164 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013165 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013166 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013167 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013168
13169 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013170 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013171 wlansap_reset_sap_config_add_ie(sap_config,
13172 eUPDATE_IE_ALL);
13173 goto end;
13174 }
13175
13176 qdf_event_reset(&hostapd_state->qdf_event);
13177 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13178 sap_config,
13179 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013180 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013181 wlansap_reset_sap_config_add_ie(sap_config,
13182 eUPDATE_IE_ALL);
13183 goto end;
13184 }
13185
Jeff Johnson6867ec32017-09-29 20:30:20 -070013186 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013187 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013188 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013189 SME_CMD_TIMEOUT_VALUE);
13190 wlansap_reset_sap_config_add_ie(sap_config,
13191 eUPDATE_IE_ALL);
13192 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013193 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013194 goto end;
13195 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013196 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013197 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070013198 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013199 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13200 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013201 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013202 }
13203end:
13204 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013205}
13206
13207/**
13208 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13209 * with non dfs acs
13210 *
13211 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13212 *
13213 * Return: None
13214 */
13215void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13216{
Jeff Johnson9d295242017-08-29 14:39:48 -070013217 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013218 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013219 cds_context_type *cds_ctx;
13220
13221 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13222 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013223 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013224 return;
13225 }
13226
13227 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13228 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013229 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013230 return;
13231 }
13232
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013233 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13234 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013235 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013236 return;
13237 }
13238
13239 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013240 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13241 &ap_adapter->event_flags) &&
13242 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013243 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013244
Jeff Johnson6867ec32017-09-29 20:30:20 -070013245 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013246 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013247 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013248 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013249 acs_cfg.acs_mode = true;
13250
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013251 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013252 }
13253}
13254
13255/**
13256 * hdd_set_connection_in_progress() - to set the connection in
13257 * progress flag
13258 * @value: value to set
13259 *
13260 * This function will set the passed value to connection in progress flag.
13261 * If value is previously being set to true then no need to set it again.
13262 *
13263 * Return: true if value is being set correctly and false otherwise.
13264 */
13265bool hdd_set_connection_in_progress(bool value)
13266{
13267 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013268 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013269
13270 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13271 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013272 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013273 return false;
13274 }
13275
13276 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13277 /*
13278 * if the value is set to true previously and if someone is
13279 * trying to make it true again then it could be some race
13280 * condition being triggered. Avoid this situation by returning
13281 * false
13282 */
13283 if (hdd_ctx->connection_in_progress && value)
13284 status = false;
13285 else
13286 hdd_ctx->connection_in_progress = value;
13287 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13288 return status;
13289}
13290
Jeff Johnson9d295242017-08-29 14:39:48 -070013291int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013292{
13293 if (!adapter) {
13294 hdd_err("Invalid adapter");
13295 return -EINVAL;
13296 }
13297 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013298 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013299 WMA_VDEV_MCC_SET_TIME_QUOTA,
13300 set_value, VDEV_CMD);
13301 return 0;
13302
13303}
13304
Jeff Johnson9d295242017-08-29 14:39:48 -070013305int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013306{
13307 if (!adapter) {
13308 hdd_err("Invalid adapter");
13309 return -EINVAL;
13310 }
13311
13312 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013313 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013314 WMA_VDEV_MCC_SET_TIME_LATENCY,
13315 set_value, VDEV_CMD);
13316 return 0;
13317}
13318
Jeff Johnson9d295242017-08-29 14:39:48 -070013319struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013320 *psoc, uint8_t vdev_id)
13321{
Jeff Johnson9d295242017-08-29 14:39:48 -070013322 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013323 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013324
13325 /*
13326 * Currently PSOC is not being used. But this logic will
13327 * change once we have the converged implementation of
13328 * HDD context per PSOC in place. This would break if
13329 * multiple vdev objects reuse the vdev id.
13330 */
13331 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13332 if (!adapter)
13333 hdd_err("Get adapter by vdev id failed");
13334
13335 return adapter;
13336}
13337
Jeff Johnson9d295242017-08-29 14:39:48 -070013338int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013339 int8_t *rssi, int8_t *snr)
13340{
13341 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070013342 struct hdd_wext_state *wext_state =
13343 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013344 tCsrRoamProfile *profile = &wext_state->roamProfile;
13345
13346 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
13347 profile, bssid, rssi, snr);
13348 if (QDF_STATUS_SUCCESS != status) {
13349 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13350 return -EINVAL;
13351 }
13352
13353 return 0;
13354}
13355
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013356/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013357 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13358 * @adapter - HDD adapter
13359 * @tos - type of service
13360 * @status - status of the traffic
13361 *
13362 * Return: 0 on success and non zero value on failure
13363 */
13364
13365int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13366 bool is_tos_active)
13367{
13368 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013369 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013370 uint32_t max_off_chan_time = 0;
13371 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013372 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013373 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013374
13375 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13376 ret = wlan_hdd_validate_context(hdd_ctx);
13377
13378 if (ret < 0) {
13379 hdd_err("failed to set limit off chan params");
13380 return ret;
13381 }
13382
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013383 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13384
13385 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013386 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013387 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013388 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013389
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013390 if (adapter->active_ac) {
13391 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013392 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013393 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13394 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13395 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013396 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013397 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013398 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13399 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13400 PM_LATENCY);
13401 } else {
13402 /*ignore this command if only BE/BK is active */
13403 is_tos_active = false;
13404 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13405 hdd_ctx->config->conc_system_pref);
13406 }
13407 } else {
13408 /* No active tos */
13409 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13410 hdd_ctx->config->conc_system_pref);
13411 }
13412
Jeff Johnson1b780e42017-10-31 14:11:45 -070013413 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013414 is_tos_active, max_off_chan_time,
13415 hdd_ctx->config->nRestTimeConc, true);
13416 if (!QDF_IS_STATUS_SUCCESS(status)) {
13417 hdd_err("failed to set limit off chan params");
13418 ret = -EINVAL;
13419 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013420
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013421 return ret;
13422}
13423
13424/**
13425 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13426 * @adapter - HDD adapter
13427 *
13428 * Return: 0 on success and non zero value on failure
13429 */
13430int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13431{
13432 struct hdd_context *hdd_ctx;
13433 int ret;
13434 QDF_STATUS status;
13435 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13436
13437 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13438 ret = wlan_hdd_validate_context(hdd_ctx);
13439 if (ret < 0)
13440 return ret;
13441
13442 /* set the system preferece to default */
13443 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13444 hdd_ctx->config->conc_system_pref);
13445
13446 /* clear the bitmap */
13447 adapter->active_ac = 0;
13448
13449 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013450 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013451
Jeff Johnson1b780e42017-10-31 14:11:45 -070013452 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013453 false, 0, 0, false);
13454 if (!QDF_IS_STATUS_SUCCESS(status)) {
13455 hdd_err("failed to reset limit off chan params");
13456 ret = -EINVAL;
13457 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013458
13459 return ret;
13460}
13461
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013462/**
13463 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13464 * @drv_op: Enum indicating driver op
13465 *
13466 * Return: none
13467 */
13468void hdd_start_driver_ops_timer(int drv_op)
13469{
13470 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13471 switch (drv_op) {
13472 case eHDD_DRV_OP_PROBE:
13473 memcpy(drv_ops_string, "probe", sizeof("probe"));
13474 break;
13475 case eHDD_DRV_OP_REMOVE:
13476 memcpy(drv_ops_string, "remove", sizeof("remove"));
13477 break;
13478 case eHDD_DRV_OP_SHUTDOWN:
13479 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13480 break;
13481 case eHDD_DRV_OP_REINIT:
13482 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13483 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013484 case eHDD_DRV_OP_IFF_UP:
13485 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13486 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013487 }
13488
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013489 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013490 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13491 HDD_OPS_INACTIVITY_TIMEOUT);
13492}
13493
13494/**
13495 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13496 *
13497 * Return: none
13498 */
13499void hdd_stop_driver_ops_timer(void)
13500{
13501 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13502}
13503
13504/**
13505 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13506 * inactivity timer
13507 *
13508 * Return: None
13509 */
13510void hdd_drv_ops_inactivity_handler(void)
13511{
13512 hdd_err("%s: %d Sec timer expired while in .%s",
13513 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13514
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013515 if (hdd_drv_ops_task) {
13516 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13517 qdf_print_thread_trace(hdd_drv_ops_task);
13518 } else {
13519 hdd_err("hdd_drv_ops_task is null");
13520 }
13521
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013522 /* Driver shutdown is stuck, no recovery possible at this point */
13523 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13524 sizeof("shutdown")))
13525 QDF_BUG(0);
13526
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013527 if (cds_is_fw_down()) {
13528 hdd_err("FW is down");
13529 return;
13530 }
13531
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013532 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013533 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013534 else
13535 QDF_BUG(0);
13536}
13537
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013538void hdd_pld_ipa_uc_shutdown_pipes(void)
13539{
13540 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13541
13542 if (!hdd_ctx)
13543 return;
13544
13545 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13546}
13547
Yun Parkff6a16a2017-09-26 16:38:18 -070013548/**
13549 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13550 * @struct hdd_context *hdd_ctx
13551 * @struct hdd_adapter *padapter
13552 * @bool enble
13553 *
13554 * Return: none
13555 */
13556void hdd_set_rx_mode_rps(bool enable)
13557{
13558 struct cds_config_info *cds_cfg = cds_get_ini_config();
13559 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13560 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13561
13562 if (adapter && hdd_ctx &&
13563 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13564 if (enable && !cds_cfg->rps_enabled)
13565 hdd_send_rps_ind(adapter);
13566 else if (!enable && cds_cfg->rps_enabled)
13567 hdd_send_rps_disable_ind(adapter);
13568 }
13569}
13570
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013571/* Register the module init/exit functions */
13572module_init(hdd_module_init);
13573module_exit(hdd_module_exit);
13574
13575MODULE_LICENSE("Dual BSD/GPL");
13576MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13577MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13578
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013579module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13580 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013581
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013582module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13583 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13584
Ravi Joshia307f632017-07-17 23:41:41 -070013585module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13586 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13587
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013588module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13589 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13590
13591module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13592
13593module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13594
13595module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);