blob: 72690600e7f76aedf3d8da845330feb8f68c29f4 [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"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800106#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530107#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700108#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700109#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530110#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700111#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530112#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800113#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800114#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530115#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800116#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800117#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530118#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530119#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800120#include "os_if_wifi_pos.h"
121#include "wifi_pos_api.h"
122#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800123#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700124#include "os_if_nan.h"
125#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700126#include "wlan_reg_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"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800132
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530133#ifdef CNSS_GENL
134#include <net/cnss_nl.h>
135#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800136#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530137
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800138#ifdef MODULE
139#define WLAN_MODULE_NAME module_name(THIS_MODULE)
140#else
141#define WLAN_MODULE_NAME "wlan"
142#endif
143
144#ifdef TIMER_MANAGER
145#define TIMER_MANAGER_STR " +TIMER_MANAGER"
146#else
147#define TIMER_MANAGER_STR ""
148#endif
149
150#ifdef MEMORY_DEBUG
151#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
152#else
153#define MEMORY_DEBUG_STR ""
154#endif
155
Sachin Ahujadddd2632017-03-07 19:07:24 +0530156int wlan_start_ret_val;
157static DECLARE_COMPLETION(wlan_start_comp);
158static unsigned int dev_num = 1;
159static struct cdev wlan_hdd_state_cdev;
160static struct class *class;
161static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530162#ifndef MODULE
163static struct gwlan_loader *wlan_loader;
164static ssize_t wlan_boot_cb(struct kobject *kobj,
165 struct kobj_attribute *attr,
166 const char *buf, size_t count);
167struct gwlan_loader {
168 bool loaded_state;
169 struct kobject *boot_wlan_obj;
170 struct attribute_group *attr_group;
171};
172
173static struct kobj_attribute wlan_boot_attribute =
174 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
175
176static struct attribute *attrs[] = {
177 &wlan_boot_attribute.attr,
178 NULL,
179};
180
181#define MODULE_INITIALIZED 1
182#endif
183
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530184#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
185#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800186#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530187
188static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800189static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530190static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
191
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800192/* the Android framework expects this param even though we don't use it */
193#define BUF_LEN 20
194static char fwpath_buffer[BUF_LEN];
195static struct kparam_string fwpath = {
196 .string = fwpath_buffer,
197 .maxlen = BUF_LEN,
198};
199
200static char *country_code;
201static int enable_11d = -1;
202static int enable_dfs_chan_scan = -1;
203
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800204/*
205 * spinlock for synchronizing asynchronous request/response
206 * (full description of use in wlan_hdd_main.h)
207 */
208DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530209DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800210
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800211#define WLAN_NLINK_CESIUM 30
212
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530213static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800214
215#define WOW_MAX_FILTER_LISTS 1
216#define WOW_MAX_FILTERS_PER_LIST 4
217#define WOW_MIN_PATTERN_SIZE 6
218#define WOW_MAX_PATTERN_SIZE 64
219
220#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
221static const struct wiphy_wowlan_support wowlan_support_reg_init = {
222 .flags = WIPHY_WOWLAN_ANY |
223 WIPHY_WOWLAN_MAGIC_PKT |
224 WIPHY_WOWLAN_DISCONNECT |
225 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
226 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
227 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
228 WIPHY_WOWLAN_4WAY_HANDSHAKE |
229 WIPHY_WOWLAN_RFKILL_RELEASE,
230 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
231 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
232 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
233};
234#endif
235
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700236static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
237 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
243 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
244 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
249 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
250 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
251 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
252 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
253 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700271 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700272 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700273 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700274};
275
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530276int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
277 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
278 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
279 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
280 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
281};
282
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800283/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530284struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800285
286struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800287#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700288static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800289#endif
290
Sachin Ahujadddd2632017-03-07 19:07:24 +0530291void hdd_start_complete(int ret)
292{
293 wlan_start_ret_val = ret;
294
295 complete(&wlan_start_comp);
296}
297
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800298/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530299 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700300 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530301 *
302 * Return: none
303 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700304static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530305{
Jeff Johnson9d295242017-08-29 14:39:48 -0700306 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530307
Dustin Brown920397d2017-12-13 16:27:50 -0800308 hdd_for_each_adapter(hdd_ctx, adapter)
309 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530310}
311
312/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800313 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
314 * @vdev_id: vdev_id
315 * @action: action type
316 * @reason: reason type
317 *
318 * Return: none
319 */
320void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
321 enum netif_action_type action, enum netif_reason_type reason)
322{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700323 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700324 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800325
326 if (!hdd_ctx) {
327 hdd_err("hdd ctx is NULL");
328 return;
329 }
330 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
331
332 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800333}
334
335/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700336 * Store WLAN driver version and timestamp info in global variables such that
337 * crash debugger can extract them from driver debug symbol and crashdump for
338 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800339 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800340#ifdef BUILD_TAG
341uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
342#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800343uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700344#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800345
346/**
347 * hdd_device_mode_to_string() - return string conversion of device mode
348 * @device_mode: device mode
349 *
350 * This utility function helps log string conversion of device mode.
351 *
352 * Return: string conversion of device mode, if match found;
353 * "Unknown" otherwise.
354 */
355const char *hdd_device_mode_to_string(uint8_t device_mode)
356{
357 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800358 CASE_RETURN_STRING(QDF_STA_MODE);
359 CASE_RETURN_STRING(QDF_SAP_MODE);
360 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
361 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
362 CASE_RETURN_STRING(QDF_FTM_MODE);
363 CASE_RETURN_STRING(QDF_IBSS_MODE);
364 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
365 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700366 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800367 default:
368 return "Unknown";
369 }
370}
371
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530372/**
373 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
374 * @adapter: HDD adapter
375 * @chan_number: Channel number
376 * @chan_bw: Bandwidth
377 *
378 * Checks if the given bandwidth is valid for the given channel number.
379 *
380 * Return: 0 for success, non-zero for failure
381 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700382int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530383 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800384 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530385{
386 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
387 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
388 bool found = false;
389 tHalHandle hal;
390
391 hal = WLAN_HDD_GET_HAL_CTX(adapter);
392 if (!hal) {
393 hdd_err("Invalid HAL context");
394 return -EINVAL;
395 }
396
397 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
398 hdd_err("No valid channel list");
399 return -EOPNOTSUPP;
400 }
401
402 for (i = 0; i < len; i++) {
403 if (chan[i] == chan_number) {
404 found = true;
405 break;
406 }
407 }
408
409 if (found == false) {
410 hdd_err("Channel not in driver's valid channel list");
411 return -EOPNOTSUPP;
412 }
413
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700414 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
415 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530416 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
417 return -EINVAL;
418 }
419
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700420 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530421 if (chan_bw == CH_WIDTH_80MHZ) {
422 hdd_err("BW80 not possible in 2.4GHz band");
423 return -EINVAL;
424 }
425 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
426 (chan_bw != CH_WIDTH_MAX)) {
427 hdd_err("Only BW20 possible on channel 14");
428 return -EINVAL;
429 }
430 }
431
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700432 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530433 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
434 (chan_bw != CH_WIDTH_MAX)) {
435 hdd_err("Only BW20 possible on channel 165");
436 return -EINVAL;
437 }
438 }
439
440 return 0;
441}
442
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530443/**
444 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
445 *
446 * Block the unloading of the driver (or) interface up until the
447 * cds recovery is completed
448 *
449 * Return: true for recovery completion else false
450 */
451static bool hdd_wait_for_recovery_completion(void)
452{
453 int retry = 0;
454
455 /* Wait for recovery to complete */
456 while (cds_is_driver_recovering()) {
457 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
458 hdd_err("Recovery in progress; wait here!!!");
459 msleep(1000);
460 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
461 hdd_err("SSR never completed, error");
462 /*
463 * Trigger the bug_on in the internal builds, in the
464 * customer builds self-recovery will be enabled
465 * in those cases just return error.
466 */
467 if (cds_is_self_recovery_enabled())
468 return false;
469 QDF_BUG(0);
470 }
471 }
472
473 hdd_info("Recovery completed successfully!");
474 return true;
475}
476
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800477static int __hdd_netdev_notifier_call(struct notifier_block *nb,
478 unsigned long state, void *data)
479{
480#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
481 struct netdev_notifier_info *dev_notif_info = data;
482 struct net_device *dev = dev_notif_info->dev;
483#else
484 struct net_device *dev = data;
485#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700486 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700487 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800488
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800489 ENTER_DEV(dev);
490
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491 /* Make sure that this callback corresponds to our device. */
492 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
493 return NOTIFY_DONE;
494
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530495 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700497 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498 return NOTIFY_DONE;
499 }
500
501 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700502 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800503 return NOTIFY_DONE;
504 }
505
506 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
507 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800508 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530509 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800510 return NOTIFY_DONE;
511 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800512
513 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
514 hdd_err("%s: Driver module is closed", __func__);
515 return NOTIFY_DONE;
516 }
517
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530518 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800519 return NOTIFY_DONE;
520
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800521 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800522 dev->name, state);
523
524 switch (state) {
525 case NETDEV_REGISTER:
526 break;
527
528 case NETDEV_UNREGISTER:
529 break;
530
531 case NETDEV_UP:
532 sme_ch_avoid_update_req(hdd_ctx->hHal);
533 break;
534
535 case NETDEV_DOWN:
536 break;
537
538 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700539 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800540 complete(&adapter->linkup_event_var);
541 break;
542
543 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700544 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
545 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530546 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700547 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548 } else {
hqueaa33ee2017-05-04 17:56:35 +0800549 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800550 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800551 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530552 /*
553 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
554 * of return status of hdd_stop call, kernel resets the IFF_UP
555 * flag after which driver does not send the cfg80211_scan_done.
556 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
557 */
558 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800559 break;
560
561 default:
562 break;
563 }
564
565 return NOTIFY_DONE;
566}
567
568/**
569 * hdd_netdev_notifier_call() - netdev notifier callback function
570 * @nb: pointer to notifier block
571 * @state: state
572 * @ndev: ndev pointer
573 *
574 * Return: 0 on success, error number otherwise.
575 */
576static int hdd_netdev_notifier_call(struct notifier_block *nb,
577 unsigned long state,
578 void *ndev)
579{
580 int ret;
581
582 cds_ssr_protect(__func__);
583 ret = __hdd_netdev_notifier_call(nb, state, ndev);
584 cds_ssr_unprotect(__func__);
585
586 return ret;
587}
588
589struct notifier_block hdd_netdev_notifier = {
590 .notifier_call = hdd_netdev_notifier_call,
591};
592
593/* variable to hold the insmod parameters */
594static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800595
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530596static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700597int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530598
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800599/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800601
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530602/**
603 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
604 * @ch_width: NL channel width
605 *
606 * Converts the NL channel width to the driver's internal representation
607 *
608 * Return: Converted channel width. In case of non matching NL channel width,
609 * CH_WIDTH_MAX will be returned.
610 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800611enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530612{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800613 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700614
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800615 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530616 switch (ch_width) {
617 case NL80211_CHAN_WIDTH_20_NOHT:
618 case NL80211_CHAN_WIDTH_20:
619 return CH_WIDTH_20MHZ;
620 case NL80211_CHAN_WIDTH_40:
621 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530622 case NL80211_CHAN_WIDTH_80:
623 return CH_WIDTH_80MHZ;
624 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800625 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
626 return CH_WIDTH_80P80MHZ;
627 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
628 return CH_WIDTH_160MHZ;
629 else
630 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530631 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800632 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
633 return CH_WIDTH_160MHZ;
634 else
635 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530636 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800637 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530638 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800639 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530640 default:
641 hdd_err("Invalid channel width %d, setting to default",
642 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800643 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530644 }
645}
646
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530647/* wlan_hdd_find_opclass() - Find operating class for a channel
648 * @hal: handler to HAL
649 * @channel: channel id
650 * @bw_offset: bandwidth offset
651 *
652 * Function invokes sme api to find the operating class
653 *
654 * Return: operating class
655 */
656uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
657 uint8_t bw_offset)
658{
659 uint8_t opclass = 0;
660
661 sme_get_opclass(hal, channel, bw_offset, &opclass);
662 return opclass;
663}
664
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800665/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530666 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530667 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800668 * @bitmask: Bitmask of log levels to be enabled
669 *
670 * Called immediately after the cfg.ini is read in order to configure
671 * the desired trace levels.
672 *
673 * Return: None
674 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530675int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800676{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530677 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530678 int qdf_print_idx = -1;
679 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800680 /*
681 * if the bitmask is the default value, then a bitmask was not
682 * specified in cfg.ini, so leave the logging level alone (it
683 * will remain at the "compiled in" default value)
684 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700685 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530686 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800687
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530688 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800689
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530690 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530691 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530692 QDF_TRACE_LEVEL_NONE, 0);
693
694 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530695 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800696 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530697 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800698 while (0 != bitmask) {
699 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530700 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530701 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530702 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530703 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800704 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700705
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800706 level++;
707 bitmask >>= 1;
708 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530709 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800710}
711
712/**
Chris Guo1751acf2017-07-03 14:09:01 +0800713 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
714 * @hdd_ctx: HDD context pointer
715 *
716 * Return: 0 if the context is valid. Error code otherwise
717 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700718int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800719{
720 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
721 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
722 return -ENODEV;
723 }
724
725 if (cds_is_driver_recovering()) {
726 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
727 (void *)_RET_IP_, cds_get_driver_state());
728 return -EAGAIN;
729 }
730
731 if (hdd_ctx->start_modules_in_progress ||
732 hdd_ctx->stop_modules_in_progress) {
733 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
734 (void *)_RET_IP_);
735 return -EAGAIN;
736 }
737
738 return 0;
739}
740
741
742/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743 * wlan_hdd_validate_context() - check the HDD context
744 * @hdd_ctx: HDD context pointer
745 *
746 * Return: 0 if the context is valid. Error code otherwise
747 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700748int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800749{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800750 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530751 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800752 return -ENODEV;
753 }
754
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800755 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800756 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530757 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758 return -EAGAIN;
759 }
760
Yue Ma9f275d92017-09-14 16:58:41 -0700761 if (cds_is_load_or_unload_in_progress()) {
762 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
763 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700765 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530766
767 if (hdd_ctx->start_modules_in_progress ||
768 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800769 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530770 (void *)_RET_IP_);
771 return -EAGAIN;
772 }
773
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530774 if (cds_is_driver_in_bad_state()) {
775 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
776 (void *)_RET_IP_, cds_get_driver_state());
777 return -ENODEV;
778 }
779
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800780 return 0;
781}
782
Jeff Johnson9d295242017-08-29 14:39:48 -0700783int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700784{
785 if (!adapter) {
786 hdd_err("adapter is null");
787 return -EINVAL;
788 }
789
790 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
791 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
792 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
793 return -EINVAL;
794 }
795
796 if (!adapter->dev) {
797 hdd_err("adapter net_device is null");
798 return -EINVAL;
799 }
800
801 if (!(adapter->dev->flags & IFF_UP)) {
802 hdd_info("adapter net_device is not up");
803 return -EAGAIN;
804 }
805
Jeff Johnson1b780e42017-10-31 14:11:45 -0700806 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700807 hdd_info("adapter session is not open");
808 return -EAGAIN;
809 }
810
Jeff Johnson1b780e42017-10-31 14:11:45 -0700811 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
812 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700813 return -EINVAL;
814 }
815
816 return 0;
817}
818
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800819/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530820 * wlan_hdd_validate_modules_state() - Check modules status
821 * @hdd_ctx: HDD context pointer
822 *
823 * Check's the driver module's state and returns true if the
824 * modules are enabled returns false if modules are closed.
825 *
826 * Return: True if modules are enabled or false.
827 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700828bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530829{
830 mutex_lock(&hdd_ctx->iface_change_lock);
831 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
832 mutex_unlock(&hdd_ctx->iface_change_lock);
833 hdd_notice("Modules not enabled, Present status: %d",
834 hdd_ctx->driver_status);
835 return false;
836 }
837 mutex_unlock(&hdd_ctx->iface_change_lock);
838 return true;
839}
840
841/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700843 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844 *
845 * This function sets the IBSS power save config parameters to WMA
846 * which will send it to firmware if FW supports IBSS power save
847 * before vdev start.
848 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530849 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 * on failure.
851 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700852QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853{
854 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700855 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856
857 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700858 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530859 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860 }
861
Jeff Johnson1b780e42017-10-31 14:11:45 -0700862 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
864 hdd_ctx->config->ibssATIMWinSize,
865 VDEV_CMD);
866 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700867 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530868 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869 }
870
Jeff Johnson1b780e42017-10-31 14:11:45 -0700871 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
873 hdd_ctx->config->isIbssPowerSaveAllowed,
874 VDEV_CMD);
875 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700876 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
877 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530878 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 }
880
Jeff Johnson1b780e42017-10-31 14:11:45 -0700881 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800882 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
883 hdd_ctx->config->
884 isIbssPowerCollapseAllowed, VDEV_CMD);
885 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700886 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
887 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530888 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800889 }
890
Jeff Johnson1b780e42017-10-31 14:11:45 -0700891 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
893 hdd_ctx->config->isIbssAwakeOnTxRx,
894 VDEV_CMD);
895 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700896 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530897 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800898 }
899
Jeff Johnson1b780e42017-10-31 14:11:45 -0700900 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
902 hdd_ctx->config->ibssInactivityCount,
903 VDEV_CMD);
904 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700905 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530906 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907 }
908
Jeff Johnson1b780e42017-10-31 14:11:45 -0700909 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800910 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
911 hdd_ctx->config->ibssTxSpEndInactivityTime,
912 VDEV_CMD);
913 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700914 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
915 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530916 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 }
918
Jeff Johnson1b780e42017-10-31 14:11:45 -0700919 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
921 hdd_ctx->config->ibssPsWarmupTime,
922 VDEV_CMD);
923 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700924 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
925 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530926 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927 }
928
Jeff Johnson1b780e42017-10-31 14:11:45 -0700929 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800930 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
931 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
932 VDEV_CMD);
933 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700934 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
935 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530936 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937 }
938
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530939 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800940}
941
Yue Macd359b72017-10-03 15:21:00 -0700942#ifdef FEATURE_RUNTIME_PM
943/**
944 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
945 * @hdd_ctx: HDD context
946 *
947 * Return: None
948 */
949static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
950{
951 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
952
Yue Macd359b72017-10-03 15:21:00 -0700953 qdf_runtime_lock_init(&ctx->dfs);
954
955 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
956}
957
958/**
959 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
960 * @hdd_ctx: HDD Context
961 *
962 * Return: None
963 */
964static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
965{
966 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
967
Yue Macd359b72017-10-03 15:21:00 -0700968 qdf_runtime_lock_deinit(&ctx->dfs);
969
970 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
971}
972
973static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
974{
975 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
976
977 qdf_runtime_lock_init(&ctx->connect);
978}
979
Yue Ma9e89e832017-11-14 11:40:23 -0800980static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter)
Yue Macd359b72017-10-03 15:21:00 -0700981{
982 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
983
984 qdf_runtime_lock_deinit(&ctx->connect);
985}
986#else /* FEATURE_RUNTIME_PM */
987static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
988static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
989static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
Yue Ma9e89e832017-11-14 11:40:23 -0800990static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter) {}
Yue Macd359b72017-10-03 15:21:00 -0700991#endif /* FEATURE_RUNTIME_PM */
992
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993#define INTF_MACADDR_MASK 0x7
994
995/**
996 * hdd_update_macaddr() - update mac address
997 * @config: hdd configuration
998 * @hw_macaddr: mac address
999 *
1000 * Mac address for multiple virtual interface is found as following
1001 * i) The mac address of the first interface is just the actual hw mac address.
1002 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1003 * define the mac address for the remaining interfaces and locally
1004 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1005 * supported virtual interfaces, right now this is 0x07 (meaning 8
1006 * interface).
1007 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1008 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1009 *
1010 * Return: None
1011 */
1012void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301013 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001014{
1015 int8_t i;
1016 uint8_t macaddr_b3, tmp_br3;
1017
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301018 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301019 QDF_MAC_ADDR_SIZE);
1020 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301021 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301022 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001023 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1024 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1025 INTF_MACADDR_MASK;
1026 macaddr_b3 += tmp_br3;
1027
1028 /* XOR-ing bit-24 of the mac address. This will give enough
1029 * mac address range before collision
1030 */
1031 macaddr_b3 ^= (1 << 7);
1032
1033 /* Set locally administered bit */
1034 config->intfMacAddr[i].bytes[0] |= 0x02;
1035 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001036 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 MAC_ADDRESS_STR, i,
1038 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1039 }
1040}
1041
Kabilan Kannan44a58372017-12-06 18:16:11 -08001042static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1043{
1044 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1045 struct tdls_start_params tdls_cfg;
1046 struct tdls_user_config *config = &tdls_cfg.config;
1047 struct hdd_config *cfg = hdd_ctx->config;
1048 QDF_STATUS status;
1049
1050 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1051 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1052 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1053 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1054 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1055 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1056 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1057 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1058 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1059 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1060 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1061 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1062 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1063 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1064 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1065 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1066 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1067 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1068 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1069 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1070 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1071 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1072 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1073 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1074 (cfg->fEnableTDLSImplicitTrigger ?
1075 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1076 (cfg->fTDLSExternalControl ?
1077 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1078 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1079 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1080
1081 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1082 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1083 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1084 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1085 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1086 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1087 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1088 tdls_cfg.tdls_evt_cb_data = psoc;
1089 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
1090 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
1091 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
1092 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1093 tdls_cfg.tdls_wmm_cb_data = psoc;
1094 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1095 tdls_cfg.tdls_rx_cb_data = psoc;
1096 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1097
1098 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1099 if (status != QDF_STATUS_SUCCESS) {
1100 hdd_err("failed pmo psoc configuration");
1101 return -EINVAL;
1102 }
1103
1104 hdd_ctx->tdls_umac_comp_active = true;
1105 /* enable napier specific tdls data path */
1106 hdd_ctx->tdls_nap_active = true;
1107
1108 return 0;
1109}
1110
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001111static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001112 struct wma_tgt_services *cfg)
1113{
1114 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115
1116 /* Set up UAPSD */
1117 config->apUapsdEnabled &= cfg->uapsd;
1118
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001119 /* 11AX mode support */
1120 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1121 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1122 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1123
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001124 /* 11AC mode support */
1125 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1126 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1127 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128
1129 /* ARP offload: override user setting if invalid */
1130 config->fhostArpOffload &= cfg->arp_offload;
1131
1132#ifdef FEATURE_WLAN_SCAN_PNO
1133 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001134 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135 if (cfg->pno_offload)
1136 config->PnoOffload = true;
1137#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138#ifdef FEATURE_WLAN_TDLS
1139 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301140 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1141 cfg->en_tdls_offchan;
1142 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1143 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001144 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001145 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001146 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001147 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001149#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1150 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1151#endif
Will Huang496b36c2017-07-11 16:38:50 +08001152 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001153 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001154 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001155 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001156
1157}
1158
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001159/**
1160 * hdd_update_vdev_nss() - sets the vdev nss
1161 * @hdd_ctx: HDD context
1162 *
1163 * Sets the Nss per vdev type based on INI
1164 *
1165 * Return: None
1166 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001167static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001168{
1169 struct hdd_config *cfg_ini = hdd_ctx->config;
1170 uint8_t max_supp_nss = 1;
1171
Naveen Rawat10b1c152017-01-18 11:16:06 -08001172 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001173 max_supp_nss = 2;
1174
1175 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001176 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001177
1178 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001179 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001180}
1181
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301182/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301183 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1184 * @hdd_ctx: HDD context
1185 *
1186 * Updates wiphy vhtcap fields
1187 *
1188 * Return: None
1189 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001190static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301191{
1192 struct ieee80211_supported_band *band_5g =
1193 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1194 uint32_t val;
1195
1196 if (!band_5g) {
1197 hdd_debug("5GHz band disabled, skipping capability population");
1198 return;
1199 }
1200
1201 val = hdd_ctx->config->txBFCsnValue;
1202 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1203
1204 val = NUM_OF_SOUNDING_DIMENSIONS;
1205 band_5g->vht_cap.cap |=
1206 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1207
1208 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1209 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1210}
1211
1212/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301213 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1214 * @hdd_ctx: HDD context
1215 *
1216 * Sets the DBS capability as per INI and firmware capability
1217 *
1218 * Return: None
1219 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001220static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301221{
1222 struct hdd_config *cfg_ini = hdd_ctx->config;
1223 uint8_t hw_dbs_capable = 0;
1224
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001225 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1226 ((cfg_ini->dual_mac_feature_disable ==
1227 ENABLE_DBS_CXN_AND_SCAN) ||
1228 (cfg_ini->dual_mac_feature_disable ==
1229 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301230 hw_dbs_capable = 1;
1231
1232 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1233}
1234
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001235static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 struct wma_tgt_ht_cap *cfg)
1237{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301238 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001239 uint32_t value, val32;
1240 uint16_t val16;
1241 struct hdd_config *pconfig = hdd_ctx->config;
1242 tSirMacHTCapabilityInfo *phtCapInfo;
1243 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1244 uint8_t enable_tx_stbc;
1245
1246 /* check and update RX STBC */
1247 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1248 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1249
1250 /* get the MPDU density */
1251 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1252
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301253 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001254 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255 value = 0;
1256 }
1257
1258 /*
1259 * MPDU density:
1260 * override user's setting if value is larger
1261 * than the one supported by target
1262 */
1263 if (value > cfg->mpdu_density) {
1264 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1265 cfg->mpdu_density);
1266
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301267 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001268 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 }
1270
1271 /* get the HT capability info */
1272 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301273 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001274 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001275 return;
1276 }
1277 val16 = (uint16_t) val32;
1278 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1279
1280 /* Set the LDPC capability */
1281 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1282
1283 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1284 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1285
1286 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1287 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1288
1289 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1290 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1291
1292 enable_tx_stbc = pconfig->enableTxSTBC;
1293
1294 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1295 pconfig->enable2x2 = 1;
1296 } else {
1297 pconfig->enable2x2 = 0;
1298 enable_tx_stbc = 0;
1299
1300 /* 1x1 */
1301 /* Update Rx Highest Long GI data Rate */
1302 if (sme_cfg_set_int(hdd_ctx->hHal,
1303 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001304 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301305 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001306 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001307 }
1308
1309 /* Update Tx Highest Long GI data Rate */
1310 if (sme_cfg_set_int
1311 (hdd_ctx->hHal,
1312 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001313 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301314 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001315 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001316 }
1317 }
1318 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1319 enable_tx_stbc = 0;
1320 phtCapInfo->txSTBC = enable_tx_stbc;
1321
1322 val32 = val16;
1323 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301324 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001325 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001326#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1327 value = SIZE_OF_SUPPORTED_MCS_SET;
1328 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301329 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001330 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001331
1332 if (pconfig->enable2x2) {
1333 for (value = 0; value < cfg->num_rf_chains; value++)
1334 mcs_set[value] =
1335 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1336
1337 status =
1338 sme_cfg_set_str(hdd_ctx->hHal,
1339 WNI_CFG_SUPPORTED_MCS_SET,
1340 mcs_set,
1341 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301342 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001343 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344 }
1345 }
1346#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1347}
1348
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001349static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001350 struct wma_tgt_vht_cap *cfg)
1351{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301352 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001353 uint32_t value = 0;
1354 struct hdd_config *pconfig = hdd_ctx->config;
1355 struct wiphy *wiphy = hdd_ctx->wiphy;
1356 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001357 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001358 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001359 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001360 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361
Dustin Brown5e06bd32016-10-04 12:49:10 -07001362 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001363 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001364 return;
1365 }
1366
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001367 /* Get the current MPDU length */
1368 status =
1369 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1370 &value);
1371
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301372 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001373 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 value = 0;
1375 }
1376
1377 /*
1378 * VHT max MPDU length:
1379 * override if user configured value is too high
1380 * that the target cannot support
1381 */
1382 if (value > cfg->vht_max_mpdu) {
1383 status = sme_cfg_set_int(hdd_ctx->hHal,
1384 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1385 cfg->vht_max_mpdu);
1386
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001387 if (status == QDF_STATUS_E_FAILURE)
1388 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001389 }
1390
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001391 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1392 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1393
1394 if (pconfig->enable2x2)
1395 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1396
1397 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1398 QDF_STATUS_E_FAILURE) {
1399 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1400 }
1401
1402 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1403 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1404 if (pconfig->enable2x2)
1405 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1406
1407 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1408 QDF_STATUS_E_FAILURE) {
1409 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1410 }
1411
1412 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1413 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1414 if (pconfig->enable2x2)
1415 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1416
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001417 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001418 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1419
1420 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1421 QDF_STATUS_E_FAILURE) {
1422 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1423 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001424 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001425 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426 &value);
1427
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301428 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001429 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001430 value = 0;
1431 }
1432
jiad4a7a33c2017-08-08 15:32:24 +08001433 /* Set HW RX LDPC capability */
1434 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1435 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001436 status = sme_cfg_set_int(hdd_ctx->hHal,
1437 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001438 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001440 if (status == QDF_STATUS_E_FAILURE)
1441 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 }
1443
1444 /* Get current GI 80 value */
1445 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1446 &value);
1447
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301448 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001449 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450 value = 0;
1451 }
1452
1453 /* set the Guard interval 80MHz */
1454 if (value && !cfg->vht_short_gi_80) {
1455 status = sme_cfg_set_int(hdd_ctx->hHal,
1456 WNI_CFG_VHT_SHORT_GI_80MHZ,
1457 cfg->vht_short_gi_80);
1458
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001459 if (status == QDF_STATUS_E_FAILURE)
1460 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461 }
1462
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001463 /* Get VHT TX STBC cap */
1464 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1465
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301466 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001467 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 value = 0;
1469 }
1470
1471 /* VHT TX STBC cap */
1472 if (value && !cfg->vht_tx_stbc) {
1473 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1474 cfg->vht_tx_stbc);
1475
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001476 if (status == QDF_STATUS_E_FAILURE)
1477 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001478 }
1479
1480 /* Get VHT RX STBC cap */
1481 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1482
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301483 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001484 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001485 value = 0;
1486 }
1487
1488 /* VHT RX STBC cap */
1489 if (value && !cfg->vht_rx_stbc) {
1490 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1491 cfg->vht_rx_stbc);
1492
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001493 if (status == QDF_STATUS_E_FAILURE)
1494 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001495 }
1496
1497 /* Get VHT SU Beamformer cap */
1498 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1499 &value);
1500
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301501 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001502 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001503 value = 0;
1504 }
1505
1506 /* set VHT SU Beamformer cap */
1507 if (value && !cfg->vht_su_bformer) {
1508 status = sme_cfg_set_int(hdd_ctx->hHal,
1509 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1510 cfg->vht_su_bformer);
1511
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001512 if (status == QDF_STATUS_E_FAILURE)
1513 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514 }
1515
1516 /* check and update SU BEAMFORMEE capabality */
1517 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1518 pconfig->enableTxBF = cfg->vht_su_bformee;
1519
1520 status = sme_cfg_set_int(hdd_ctx->hHal,
1521 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1522 pconfig->enableTxBF);
1523
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001524 if (status == QDF_STATUS_E_FAILURE)
1525 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526
1527 /* Get VHT MU Beamformer cap */
1528 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1529 &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 MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001533 value = 0;
1534 }
1535
1536 /* set VHT MU Beamformer cap */
1537 if (value && !cfg->vht_mu_bformer) {
1538 status = sme_cfg_set_int(hdd_ctx->hHal,
1539 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1540 cfg->vht_mu_bformer);
1541
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001542 if (status == QDF_STATUS_E_FAILURE)
1543 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001544 }
1545
1546 /* Get VHT MU Beamformee cap */
1547 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1548 &value);
1549
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301550 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001551 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552 value = 0;
1553 }
1554
1555 /* set VHT MU Beamformee cap */
1556 if (value && !cfg->vht_mu_bformee) {
1557 status = sme_cfg_set_int(hdd_ctx->hHal,
1558 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1559 cfg->vht_mu_bformee);
1560
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001561 if (status == QDF_STATUS_E_FAILURE)
1562 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001563 }
1564
1565 /* Get VHT MAX AMPDU Len exp */
1566 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1567 &value);
1568
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301569 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001570 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001571 value = 0;
1572 }
1573
1574 /*
1575 * VHT max AMPDU len exp:
1576 * override if user configured value is too high
1577 * that the target cannot support.
1578 * Even though Rome publish ampdu_len=7, it can
1579 * only support 4 because of some h/w bug.
1580 */
1581
1582 if (value > cfg->vht_max_ampdu_len_exp) {
1583 status = sme_cfg_set_int(hdd_ctx->hHal,
1584 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1585 cfg->vht_max_ampdu_len_exp);
1586
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001587 if (status == QDF_STATUS_E_FAILURE)
1588 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001589 }
1590
1591 /* Get VHT TXOP PS CAP */
1592 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1593
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301594 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001595 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001596 value = 0;
1597 }
1598
1599 /* set VHT TXOP PS cap */
1600 if (value && !cfg->vht_txop_ps) {
1601 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1602 cfg->vht_txop_ps);
1603
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001604 if (status == QDF_STATUS_E_FAILURE)
1605 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606 }
1607
1608 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1609 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1610 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1611 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1612 else
1613 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1614
1615
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001616 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1617 status = sme_cfg_set_int(hdd_ctx->hHal,
1618 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1619 VHT_CAP_160_AND_80P80_SUPP);
1620 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001621 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 band_5g->vht_cap.cap |=
1623 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001624 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1625 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1626 status = sme_cfg_set_int(hdd_ctx->hHal,
1627 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1628 VHT_CAP_160_SUPP);
1629 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001630 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 band_5g->vht_cap.cap |=
1632 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001633 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1634 }
1635 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1636 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301637 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001638 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301639 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001640 &value);
1641 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301642 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001643 value = 0;
1644 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301645 /* set the Guard interval 160MHz */
1646 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001647 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301648 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1649 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001650
1651 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301652 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001653 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001654
1655 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1656 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1657
1658 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1659 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1660 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1661 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1662
1663 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1664 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1665
1666 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1667 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1668 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1669 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1670 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1671 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1672
1673 band_5g->vht_cap.cap |=
1674 (cfg->vht_max_ampdu_len_exp <<
1675 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1676
1677 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1678 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1679 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1680 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1681 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1682 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1683 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1684 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1685
1686 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1687 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1688
1689}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001690
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001691/**
1692 * hdd_generate_macaddr_auto() - Auto-generate mac address
1693 * @hdd_ctx: Pointer to the HDD context
1694 *
1695 * Auto-generate mac address using device serial number.
1696 * Keep the first 3 bytes of OUI as before and replace
1697 * the last 3 bytes with the lower 3 bytes of serial number.
1698 *
1699 * Return: 0 for success
1700 * Non zero failure code for errors
1701 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001702static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001703{
1704 unsigned int serialno = 0;
1705 struct qdf_mac_addr mac_addr = {
1706 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1707 };
1708
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001709 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001710 if (serialno == 0)
1711 return -EINVAL;
1712
1713 serialno &= 0x00ffffff;
1714
1715 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1716 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1717 mac_addr.bytes[5] = serialno & 0xff;
1718
1719 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1720 return 0;
1721}
1722
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301723/**
1724 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1725 * configuration to cfg_ini in HDD
1726 * @hdd_ctx: Pointer to hdd_ctx
1727 * @cfg: target configuration
1728 *
1729 * Return: None
1730 */
1731#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001732static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301733 struct wma_tgt_cfg *cfg)
1734{
1735 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1736}
1737#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001738static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301739 struct wma_tgt_cfg *cfg)
1740{
1741}
1742#endif
1743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001744void hdd_update_tgt_cfg(void *context, void *param)
1745{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001746 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001747 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001748 struct wma_tgt_cfg *cfg = param;
1749 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001750 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301751 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301752
Dustin Brownbd68fe12017-11-21 15:28:52 -08001753 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1754 if (ret) {
1755 hdd_err("Failed to create pdev; errno:%d", ret);
1756 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001757 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001758 hdd_debug("New pdev has been created with pdev_id = %u",
1759 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301760 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001761
Naveen Rawat64e477e2016-05-20 10:34:56 -07001762 if (cds_cfg) {
1763 if (hdd_ctx->config->enable_sub_20_channel_width !=
1764 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1765 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1766 cds_cfg->sub_20_channel_width =
1767 WLAN_SUB_20_CH_WIDTH_NONE;
1768 } else {
1769 cds_cfg->sub_20_channel_width =
1770 hdd_ctx->config->enable_sub_20_channel_width;
1771 }
1772 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773
1774 /* first store the INI band capability */
1775 temp_band_cap = hdd_ctx->config->nBandCapability;
1776
1777 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301778 hdd_ctx->is_fils_roaming_supported =
1779 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001781 /*
1782 * now overwrite the target band capability with INI
1783 * setting if INI setting is a subset
1784 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001785
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001786 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1787 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001788 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001789 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1790 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001791 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001792 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001793 }
1794
Amar Singhal58b45ef2017-08-01 13:43:54 -07001795 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1796
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301797 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001798 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1799 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1800 }
1801
1802 /* This can be extended to other configurations like ht, vht cap... */
1803
Anurag Chouhanc5548422016-02-24 18:33:27 +05301804 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001805 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001806 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001807 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001808 static struct qdf_mac_addr default_mac_addr = {
1809 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1810 };
1811 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1812 &default_mac_addr)) {
1813 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1814 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1815 MAC_ADDRESS_STR,
1816 MAC_ADDR_ARRAY(hdd_ctx->config->
1817 intfMacAddr[0].bytes));
1818 } else {
1819 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1820 MAC_ADDRESS_STR,
1821 MAC_ADDR_ARRAY(hdd_ctx->config->
1822 intfMacAddr[0].bytes));
1823 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001824 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001825 }
1826
1827 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001828 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001829
1830 hdd_ctx->max_intf_count = cfg->max_intf_count;
1831
Jeff Johnsonc875e242016-09-23 18:12:34 -07001832 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001833 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001834
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001835 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1836 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1837
1838 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1839
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001841 if (cfg->services.en_11ax) {
1842 hdd_info("11AX: 11ax is enabled - update HDD config");
1843 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1844 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001845
1846 hdd_update_vdev_nss(hdd_ctx);
1847
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301848 hdd_update_hw_dbs_capable(hdd_ctx);
1849
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001850 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001851 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001852 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001853 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001854
Nitesh Shahe50711f2017-04-26 16:30:45 +05301855 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1856 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1857 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001858 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001859 hdd_ctx->current_antenna_mode);
1860
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001861 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1862 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301863 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301864 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301865
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301866 if ((hdd_ctx->config->txBFCsnValue >
1867 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1868 !cfg->tx_bfee_8ss_enabled)
1869 hdd_ctx->config->txBFCsnValue =
1870 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1871
1872 if (sme_cfg_set_int(hdd_ctx->hHal,
1873 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1874 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1875 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1876
1877
1878 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1879 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1880 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301881
1882 /*
1883 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1884 */
1885 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301886
Arun Khandavallid454d422016-08-17 12:47:05 +05301887 /*
1888 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1889 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1890 * configure the STA mode wow pattern.
1891 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301892 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301893 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301894
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301895 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1896
Yue Macd359b72017-10-03 15:21:00 -07001897 /*
1898 * This needs to be done after HDD pdev is created and stored since
1899 * it will access the HDD pdev object lock.
1900 */
1901 hdd_runtime_suspend_context_init(hdd_ctx);
1902
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001903 /* Configure NAN datapath features */
1904 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001905 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08001906 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907}
1908
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001909bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910{
Jeff Johnson9d295242017-08-29 14:39:48 -07001911 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07001912 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913
Arif Hussaincd151632017-02-11 16:57:19 -08001914 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001915 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001916 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301917 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001918 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001919
Dustin Brown920397d2017-12-13 16:27:50 -08001920 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08001921 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1922
1923 if ((QDF_SAP_MODE == adapter->device_mode ||
1924 QDF_P2P_GO_MODE == adapter->device_mode) &&
1925 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07001926 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08001927 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1928 true;
1929 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07001930 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301931 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001932 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301933
1934 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001936
1937/**
1938 * hdd_is_valid_mac_address() - validate MAC address
1939 * @pMacAddr: Pointer to the input MAC address
1940 *
1941 * This function validates whether the given MAC address is valid or not
1942 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1943 * where X is the hexa decimal digit character and separated by ':'
1944 * This algorithm works even if MAC address is not separated by ':'
1945 *
1946 * This code checks given input string mac contains exactly 12 hexadecimal
1947 * digits and a separator colon : appears in the input string only after
1948 * an even number of hex digits.
1949 *
1950 * Return: 1 for valid and 0 for invalid
1951 */
1952bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1953{
1954 int xdigit = 0;
1955 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 while (*pMacAddr) {
1958 if (isxdigit(*pMacAddr)) {
1959 xdigit++;
1960 } else if (':' == *pMacAddr) {
1961 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1962 break;
1963
1964 ++separator;
1965 } else {
1966 /* Invalid MAC found */
1967 return 0;
1968 }
1969 ++pMacAddr;
1970 }
1971 return xdigit == 12 && (separator == 5 || separator == 0);
1972}
1973
1974/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301975 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1976 * @dev: Handle to struct net_device to be updated.
1977 *
1978 * Return: None
1979 */
1980static void hdd_mon_mode_ether_setup(struct net_device *dev)
1981{
1982 dev->header_ops = NULL;
1983 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1984 dev->hard_header_len = ETH_HLEN;
1985 dev->mtu = ETH_DATA_LEN;
1986 dev->addr_len = ETH_ALEN;
1987 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1988 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1989 dev->priv_flags |= IFF_TX_SKB_SHARING;
1990
1991 memset(dev->broadcast, 0xFF, ETH_ALEN);
1992}
1993
1994/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001995 * __hdd__mon_open() - HDD Open function
1996 * @dev: Pointer to net_device structure
1997 *
1998 * This is called in response to ifconfig up
1999 *
2000 * Return: 0 for success; non-zero for failure
2001 */
2002static int __hdd_mon_open(struct net_device *dev)
2003{
2004 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002005 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2006 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002007
2008 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002009
2010 ret = wlan_hdd_validate_context(hdd_ctx);
2011 if (ret)
2012 return ret;
2013
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302014 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002015
2016 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2017 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2018 if (ret) {
2019 hdd_err("Failed to start WLAN modules return");
2020 return ret;
2021 }
2022 hdd_err("hdd_wlan_start_modules() successful !");
2023
2024 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2025 ret = hdd_start_adapter(adapter);
2026 if (ret) {
2027 hdd_err("Failed to start adapter :%d",
2028 adapter->device_mode);
2029 return ret;
2030 }
2031 hdd_err("hdd_start_adapters() successful !");
2032 }
2033 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2034 }
2035
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002036 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002037
2038 if (!ret)
2039 ret = hdd_enable_monitor_mode(dev);
2040
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002041 return ret;
2042}
2043
2044/**
2045 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2046 * @dev: Pointer to net_device structure
2047 *
2048 * This is called in response to ifconfig up
2049 *
2050 * Return: 0 for success; non-zero for failure
2051 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002052static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002053{
2054 int ret;
2055
2056 cds_ssr_protect(__func__);
2057 ret = __hdd_mon_open(dev);
2058 cds_ssr_unprotect(__func__);
2059
2060 return ret;
2061}
2062
2063/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302064 * hdd_start_adapter() - Wrapper function for device specific adapter
2065 * @adapter: pointer to HDD adapter
2066 *
2067 * This function is called to start the device specific adapter for
2068 * the mode passed in the adapter's device_mode.
2069 *
2070 * Return: 0 for success; non-zero for failure
2071 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002072int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302073{
2074
2075 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002076 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302077
2078 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002079 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302080
2081 switch (device_mode) {
2082 case QDF_P2P_CLIENT_MODE:
2083 case QDF_P2P_DEVICE_MODE:
2084 case QDF_OCB_MODE:
2085 case QDF_STA_MODE:
2086 case QDF_MONITOR_MODE:
2087 ret = hdd_start_station_adapter(adapter);
2088 if (ret)
2089 goto err_start_adapter;
2090 break;
2091 case QDF_P2P_GO_MODE:
2092 case QDF_SAP_MODE:
2093 ret = hdd_start_ap_adapter(adapter);
2094 if (ret)
2095 goto err_start_adapter;
2096 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302097 case QDF_IBSS_MODE:
2098 /*
2099 * For IBSS interface is initialized as part of
2100 * hdd_init_station_mode()
2101 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002102 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302103 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002104 /* vdevs are dynamically managed by firmware in FTM */
2105 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302106 default:
2107 hdd_err("Invalid session type %d", device_mode);
2108 QDF_ASSERT(0);
2109 goto err_start_adapter;
2110 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002111
Arun Khandavallifae92942016-08-01 13:31:08 +05302112 if (hdd_set_fw_params(adapter))
2113 hdd_err("Failed to set the FW params for the adapter!");
2114
2115 /*
2116 * Action frame registered in one adapter which will
2117 * applicable to all interfaces
2118 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302119 ret = wlan_hdd_cfg80211_register_frames(adapter);
2120 if (ret < 0) {
2121 hdd_err("Failed to register frames - ret %d", ret);
2122 goto err_start_adapter;
2123 }
2124
Dustin Browndb2a8be2017-12-20 11:49:56 -08002125exit_with_success:
Arun Khandavallifae92942016-08-01 13:31:08 +05302126 EXIT();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002127
Arun Khandavallifae92942016-08-01 13:31:08 +05302128 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002129
Arun Khandavallifae92942016-08-01 13:31:08 +05302130err_start_adapter:
2131 return -EINVAL;
2132}
2133
2134/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302135 * hdd_enable_power_management() - API to Enable Power Management
2136 *
2137 * API invokes Bus Interface Layer power management functionality
2138 *
2139 * Return: None
2140 */
2141static void hdd_enable_power_management(void)
2142{
2143 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2144
2145 if (!hif_ctx) {
2146 hdd_err("Bus Interface Context is Invalid");
2147 return;
2148 }
2149
2150 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2151}
2152
2153/**
2154 * hdd_disable_power_management() - API to disable Power Management
2155 *
2156 * API disable Bus Interface Layer Power management functionality
2157 *
2158 * Return: None
2159 */
2160static void hdd_disable_power_management(void)
2161{
2162 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2163
2164 if (!hif_ctx) {
2165 hdd_err("Bus Interface Context is Invalid");
2166 return;
2167 }
2168
2169 hif_disable_power_management(hif_ctx);
2170}
2171
2172/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302173 * hdd_update_hw_sw_info() - API to update the HW/SW information
2174 *
2175 * API to update the HW and SW information in the driver
2176 *
2177 * Return: None
2178 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002179static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302180{
2181 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002182 size_t target_hw_name_len;
2183 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302184
2185 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2186 if (!hif_sc) {
2187 hdd_err("HIF context is NULL");
2188 return;
2189 }
2190
2191 /*
2192 * target hw version/revision would only be retrieved after firmware
2193 * download
2194 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002195 hif_get_hw_info(hif_sc,
2196 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302197 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002198 &target_hw_name);
2199
2200 if (hdd_ctx->target_hw_name)
2201 qdf_mem_free(hdd_ctx->target_hw_name);
2202
2203 target_hw_name_len = strlen(target_hw_name) + 1;
2204 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2205 if (hdd_ctx->target_hw_name)
2206 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2207 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302208
2209 /* Get the wlan hw/fw version */
2210 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302211}
2212
2213/**
gbian62edd7e2017-03-07 13:12:13 +08002214 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2215 * @hdd_ctx: Pointer to hdd context
2216 *
2217 * Return: none
2218 */
2219static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002220hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002221{
2222 uint8_t num_entries = 0;
2223 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2224 uint8_t *tx_sched_wrr_ac;
2225 int i;
2226 cds_context_type *cds_ctx;
2227
2228 if (NULL == hdd_ctx)
2229 return;
2230
2231 if (NULL == hdd_ctx->config) {
2232 /* Do nothing if hdd_ctx is invalid */
2233 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2234 return;
2235 }
2236
2237 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2238
2239 if (!cds_ctx) {
2240 hdd_err("Invalid CDS Context");
2241 return;
2242 }
2243
2244 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2245 switch (i) {
2246 case OL_TX_WMM_AC_BE:
2247 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2248 break;
2249 case OL_TX_WMM_AC_BK:
2250 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2251 break;
2252 case OL_TX_WMM_AC_VI:
2253 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2254 break;
2255 case OL_TX_WMM_AC_VO:
2256 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2257 break;
2258 default:
2259 tx_sched_wrr_ac = NULL;
2260 break;
2261 }
2262
2263 hdd_string_to_u8_array(tx_sched_wrr_ac,
2264 tx_sched_wrr_param,
2265 &num_entries,
2266 sizeof(tx_sched_wrr_param));
2267
2268 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2269 cds_ctx->ac_specs[i].wrr_skip_weight =
2270 tx_sched_wrr_param[0];
2271 cds_ctx->ac_specs[i].credit_threshold =
2272 tx_sched_wrr_param[1];
2273 cds_ctx->ac_specs[i].send_limit =
2274 tx_sched_wrr_param[2];
2275 cds_ctx->ac_specs[i].credit_reserve =
2276 tx_sched_wrr_param[3];
2277 cds_ctx->ac_specs[i].discard_weight =
2278 tx_sched_wrr_param[4];
2279 }
2280
2281 num_entries = 0;
2282 }
2283}
2284
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002285#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002286static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2287 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2288{
Jeff Johnson9d295242017-08-29 14:39:48 -07002289 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002290 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002291
2292 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2293 if (!adapter) {
2294 hdd_err("Adapter is NULL");
2295 return PM_MAX_NUM_OF_MODE;
2296 }
2297
2298 return policy_mgr_convert_device_mode_to_qdf_type(
2299 adapter->device_mode);
2300}
2301
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002302static void hdd_register_policy_manager_callback(
2303 struct wlan_objmgr_psoc *psoc)
2304{
2305 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002306
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002307 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002308 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002309 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2310 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002311 hdd_cbacks.get_mode_for_non_connected_vdev =
2312 wlan_hdd_get_mode_for_non_connected_vdev;
2313
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002314 if (QDF_STATUS_SUCCESS !=
2315 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2316 hdd_err("HDD callback registration with policy manager failed");
2317 }
2318}
2319#else
2320static void hdd_register_policy_manager_callback(
2321 struct wlan_objmgr_psoc *psoc)
2322{
2323}
2324#endif
2325
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002326#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002327static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002328{
2329 struct nan_callbacks cb_obj = {0};
2330
2331 cb_obj.ndi_open = hdd_ndi_open;
2332 cb_obj.ndi_close = hdd_ndi_close;
2333 cb_obj.ndi_start = hdd_ndi_start;
2334 cb_obj.ndi_delete = hdd_ndi_delete;
2335 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2336 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2337
Naveen Rawat37f62c82017-03-26 22:24:43 -07002338 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2339 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002340 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002341
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002342 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2343}
2344#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002345static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002346{
2347}
2348#endif
2349
Dustin Brown26b3d042017-12-21 11:13:27 -08002350#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002351/**
2352 * hdd_check_for_leaks() - Perform runtime memory leak checks
2353 *
2354 * This API triggers runtime memory leak detection. This feature enforces the
2355 * policy that any memory allocated at runtime must also be released at runtime.
2356 *
2357 * Allocating memory at runtime and releasing it at unload is effectively a
2358 * memory leak for configurations which never unload (e.g. LONU, statically
2359 * compiled driver). Such memory leaks are NOT false positives, and must be
2360 * fixed.
2361 *
2362 * Return: None
2363 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002364static void hdd_check_for_leaks(void)
2365{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002366 /* DO NOT REMOVE these checks; for false positives, read above first */
2367
Dustin Brown677e0862017-10-10 16:30:09 -07002368 qdf_mc_timer_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002369 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002370}
2371
Dustin Brown26b3d042017-12-21 11:13:27 -08002372#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2373#else
2374static inline void hdd_check_for_leaks(void) {}
2375
2376#define hdd_debug_domain_set(domain)
2377#endif /* CONFIG_LEAK_DETECTION */
2378
gbian62edd7e2017-03-07 13:12:13 +08002379/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302380 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2381 * @hdd_ctx: HDD context
2382 * @adapter: HDD adapter
2383 * @reinit: flag to indicate from SSR or normal path
2384 *
2385 * This function maintains the driver state machine it will be invoked from
2386 * startup, reinit and change interface. Depending on the driver state shall
2387 * perform the opening of the modules.
2388 *
2389 * Return: 0 for success; non-zero for failure
2390 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002391int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2392 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302393 bool reinit)
2394{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002395 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302396 qdf_device_t qdf_dev;
2397 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302398 bool unint = false;
2399 void *hif_ctx;
2400
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002401 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302402
2403 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2404 if (!qdf_dev) {
2405 hdd_err("QDF Device Context is Invalid return");
2406 return -EINVAL;
2407 }
2408
Dustin Brown6f427922017-09-19 12:19:00 -07002409 hdd_set_idle_ps_config(hdd_ctx, false);
2410 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302411
Dustin Brown1fe30a82017-10-03 16:13:36 -07002412 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302413 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2414 mutex_unlock(&hdd_ctx->iface_change_lock);
2415 hdd_info("Driver modules already Enabled");
2416 EXIT();
2417 return 0;
2418 }
2419
Dustin Brown1fe30a82017-10-03 16:13:36 -07002420 hdd_ctx->start_modules_in_progress = true;
2421
Arun Khandavallifae92942016-08-01 13:31:08 +05302422 switch (hdd_ctx->driver_status) {
2423 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002424 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302425 unint = true;
2426 /* Fall through dont add break here */
2427 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002428 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2429
Dustin Brown26b3d042017-12-21 11:13:27 -08002430 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002431
Arun Khandavallifae92942016-08-01 13:31:08 +05302432 if (!reinit && !unint) {
2433 ret = pld_power_on(qdf_dev->dev);
2434 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002435 hdd_err("Failed to Powerup the device; errno: %d",
2436 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302437 goto release_lock;
2438 }
2439 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002440
2441 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2442 hdd_ctx->config->enable_fw_log);
2443
Arun Khandavallifae92942016-08-01 13:31:08 +05302444 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2445 qdf_dev->bus_type,
2446 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2447 HIF_ENABLE_TYPE_PROBE);
2448 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002449 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302450 goto power_down;
2451 }
2452
2453 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302454 if (!hif_ctx) {
2455 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002456 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302457 goto power_down;
2458 }
2459
Arun Khandavallifae92942016-08-01 13:31:08 +05302460 status = ol_cds_init(qdf_dev, hif_ctx);
2461 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002462 hdd_err("No Memory to Create BMI Context; status: %d",
2463 status);
2464 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302465 goto hif_close;
2466 }
2467
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002468 ret = hdd_update_config(hdd_ctx);
2469 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002470 hdd_err("Failed to update configuration; errno: %d",
2471 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002472 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002473 }
2474
gbian62edd7e2017-03-07 13:12:13 +08002475 hdd_update_cds_ac_specs_params(hdd_ctx);
2476
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302477 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002478 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002479 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002480 ret = qdf_status_to_os_return(status);
2481 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302482 }
2483
Mukul Sharma9d797a02017-01-05 20:26:03 +05302484 /* initalize components configurations after psoc open */
2485 ret = hdd_update_components_config(hdd_ctx);
2486 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002487 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302488 ret);
2489 goto close;
2490 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002491 status = cds_dp_open(hdd_ctx->hdd_psoc);
2492 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002493 hdd_err("Failed to Open cds post open; status: %d",
2494 status);
2495 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002496 goto close;
2497 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302498
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002499 /*
2500 * NAN compoenet requires certian operations like, open adapter,
2501 * close adapter, etc. to be initiated by HDD, for those
2502 * register HDD callbacks with UMAC's NAN componenet.
2503 */
2504 hdd_nan_register_callbacks(hdd_ctx);
2505
Arun Khandavallifae92942016-08-01 13:31:08 +05302506 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2507
Jeff Johnson3a280122017-09-13 07:42:00 -07002508 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302509 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002510 hdd_err("Failed to pre-enable CDS; status: %d", status);
2511 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002512 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302513 }
2514
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002515 hdd_register_policy_manager_callback(
2516 hdd_ctx->hdd_psoc);
2517
Amar Singhal0928b192017-12-01 10:50:54 -08002518 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2519
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302520 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302521 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002522 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302523
Arun Khandavallifae92942016-08-01 13:31:08 +05302524 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2525 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2526 hdd_ftm_mc_process_msg);
2527 break;
2528 }
2529 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002530 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302531 break;
2532 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302533
2534 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002535 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2536 if (ret) {
2537 hdd_err("HDD IPA UC reinit failed; errno: %d",
2538 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002539 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002540 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302541 }
2542
Arun Khandavallifae92942016-08-01 13:31:08 +05302543 /* Fall through dont add break here */
2544 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002545 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2546
Arun Khandavallifae92942016-08-01 13:31:08 +05302547 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002548 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002549 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002550 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302551 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302552 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2553 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002554 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302555 break;
2556 }
Dustin Browndca39692017-11-09 15:30:25 -08002557
2558 ret = hdd_configure_cds(hdd_ctx, adapter);
2559 if (ret) {
2560 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002561 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302562 }
Dustin Browndca39692017-11-09 15:30:25 -08002563
Komal Seelamf2136bb2016-09-28 18:30:44 +05302564 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002565
Arun Khandavallifae92942016-08-01 13:31:08 +05302566 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002567 hdd_info("Wlan transitioned (now ENABLED)");
2568
Arun Khandavallifae92942016-08-01 13:31:08 +05302569 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002570
Arun Khandavallifae92942016-08-01 13:31:08 +05302571 default:
2572 hdd_err("WLAN start invoked in wrong state! :%d\n",
2573 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002574 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302575 goto release_lock;
2576 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002577
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302578 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302579 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002580
Arun Khandavallifae92942016-08-01 13:31:08 +05302581 EXIT();
Dustin Brown550f6d22017-12-14 15:44:01 -08002582
Arun Khandavallifae92942016-08-01 13:31:08 +05302583 return 0;
2584
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002585post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002586 cds_post_disable();
Dustin Brownbd68fe12017-11-21 15:28:52 -08002587 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002588
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002589cds_txrx_free:
2590 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002591
Arun Khandavallifae92942016-08-01 13:31:08 +05302592close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002593 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002594 hdd_info("Wlan transition aborted (now CLOSED)");
2595
Jeff Johnsone4b14592017-09-13 14:23:33 -07002596 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302597
Dustin Brown28b17892017-10-10 13:29:38 -07002598deinit_config:
2599 cds_deinit_ini_config();
2600
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002601cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302602 ol_cds_free();
2603
2604hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002605 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2606 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302607power_down:
2608 if (!reinit && !unint)
2609 pld_power_off(qdf_dev->dev);
2610release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302611 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302612 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002613
2614 /* many adapter resources are not freed by design in SSR case */
2615 if (!reinit)
2616 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002617 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002618
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302619 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002620
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002621 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302622}
2623
Naveen Rawat910726a2017-03-06 11:42:51 -08002624#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002625static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002626{
2627 int ret = os_if_wifi_pos_register_nl();
2628
2629 if (ret)
2630 hdd_err("os_if_wifi_pos_register_nl failed");
2631
2632 return ret;
2633}
2634
2635static int hdd_deactivate_wifi_pos(void)
2636{
2637 int ret = os_if_wifi_pos_deregister_nl();
2638
2639 if (ret)
2640 hdd_err("os_if_wifi_pos_deregister_nl failed");
2641
2642 return ret;
2643}
2644
2645/**
2646 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2647 * @hdd_ctx: hdd context
2648 *
2649 * Return: status of operation
2650 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002651static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002652{
2653 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2654 struct hdd_config *cfg = hdd_ctx->config;
2655
2656 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2657 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2658 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2659 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2660 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2661 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2662 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2663 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2664}
2665#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002666static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002667{
2668 return oem_activate_service(hdd_ctx);
2669}
2670
2671static int hdd_deactivate_wifi_pos(void)
2672{
2673 return 0;
2674}
2675
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002676static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002677{
2678}
2679#endif
2680
Arun Khandavallifae92942016-08-01 13:31:08 +05302681/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002682 * __hdd_open() - HDD Open function
2683 * @dev: Pointer to net_device structure
2684 *
2685 * This is called in response to ifconfig up
2686 *
2687 * Return: 0 for success; non-zero for failure
2688 */
2689static int __hdd_open(struct net_device *dev)
2690{
Jeff Johnson9d295242017-08-29 14:39:48 -07002691 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002692 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002693 int ret;
2694
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002695 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302696 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002697 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002698
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302699 /* Nothing to be done if device is unloading */
2700 if (cds_is_driver_unloading()) {
2701 hdd_err("Driver is unloading can not open the hdd");
2702 return -EBUSY;
2703 }
2704
Dustin Brown01847752017-10-25 13:56:27 -07002705 if (cds_is_driver_recovering()) {
2706 hdd_err("WLAN is currently recovering; Please try again.");
2707 return -EBUSY;
2708 }
2709
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302710 mutex_lock(&hdd_init_deinit_lock);
2711
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302712 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2713
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302714 /*
2715 * This scenario can be hit in cases where in the wlan driver after
2716 * registering the netdevices and there is a failure in driver
2717 * initialization. So return error gracefully because the netdevices
2718 * will be de-registered as part of the load failure.
2719 */
2720
2721 if (!cds_is_driver_loaded()) {
2722 hdd_err("Failed to start the wlan driver!!");
2723 ret = -EIO;
2724 goto err_hdd_hdd_init_deinit_lock;
2725 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302726
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002727
Arun Khandavallifae92942016-08-01 13:31:08 +05302728 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2729 if (ret) {
2730 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302731 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302732 }
2733
2734
2735 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2736 ret = hdd_start_adapter(adapter);
2737 if (ret) {
2738 hdd_err("Failed to start adapter :%d",
2739 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302740 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302741 }
2742 }
2743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002744 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2745 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002746 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002747 /* Enable TX queues only when we are connected */
2748 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302749 WLAN_START_ALL_NETIF_QUEUE,
2750 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002751 }
2752
Naveen Rawat286def52016-09-23 15:38:02 -07002753 /* Enable carrier and transmit queues for NDI */
2754 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002755 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002756 wlan_hdd_netif_queue_control(adapter,
2757 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2758 WLAN_CONTROL_PATH);
2759 }
2760
Naveen Rawat910726a2017-03-06 11:42:51 -08002761 hdd_populate_wifi_pos_cfg(hdd_ctx);
2762
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302763err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302764 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302765 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002766 return ret;
2767}
2768
Arun Khandavallifae92942016-08-01 13:31:08 +05302769
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002770/**
2771 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2772 * @dev: Pointer to net_device structure
2773 *
2774 * This is called in response to ifconfig up
2775 *
2776 * Return: 0 for success; non-zero for failure
2777 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002778static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002779{
2780 int ret;
2781
2782 cds_ssr_protect(__func__);
2783 ret = __hdd_open(dev);
2784 cds_ssr_unprotect(__func__);
2785
2786 return ret;
2787}
2788
2789/**
2790 * __hdd_stop() - HDD stop function
2791 * @dev: Pointer to net_device structure
2792 *
2793 * This is called in response to ifconfig down
2794 *
2795 * Return: 0 for success; non-zero for failure
2796 */
2797static int __hdd_stop(struct net_device *dev)
2798{
Jeff Johnson9d295242017-08-29 14:39:48 -07002799 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002800 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002801 int ret;
2802
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002803 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002804
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302805 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002806 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002807
2808 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302809 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002810 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002811
2812 /* Nothing to be done if the interface is not opened */
2813 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002814 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002815 return -ENODEV;
2816 }
2817
2818 /* Make sure the interface is marked as closed */
2819 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302820
2821 hdd_debug("Disabling Auto Power save timer");
2822 sme_ps_disable_auto_ps_timer(
2823 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002824 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302825
2826 /*
2827 * Disable TX on the interface, after this hard_start_xmit() will not
2828 * be called on that interface
2829 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002830 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2831 hdd_device_mode_to_string(adapter->device_mode),
2832 adapter->device_mode);
2833
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302834 wlan_hdd_netif_queue_control(adapter,
2835 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2836 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002837
2838 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002839 * NAN data interface is different in some sense. The traffic on NDI is
2840 * bursty in nature and depends on the need to transfer. The service
2841 * layer may down the interface after the usage and up again when
2842 * required. In some sense, the NDI is expected to be available
2843 * (like SAP) iface until NDI delete request is issued by the service
2844 * layer. Skip BSS termination and adapter deletion for NAN Data
2845 * interface (NDI).
2846 */
2847 if (WLAN_HDD_IS_NDI(adapter))
2848 return 0;
2849
2850 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002851 * The interface is marked as down for outside world (aka kernel)
2852 * But the driver is pretty much alive inside. The driver needs to
2853 * tear down the existing connection on the netdev (session)
2854 * cleanup the data pipes and wait until the control plane is stabilized
2855 * for this interface. The call also needs to wait until the above
2856 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002857 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002858 * That is intentional to be able to scan if it is a STA/P2P interface
2859 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002860 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002861
2862 /* DeInit the adapter. This ensures datapath cleanup as well */
2863 hdd_deinit_adapter(hdd_ctx, adapter, true);
2864
Arun Khandavallifae92942016-08-01 13:31:08 +05302865
2866 /*
2867 * Find if any iface is up. If any iface is up then can't put device to
2868 * sleep/power save mode
2869 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302870 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002871 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07002872 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
2873 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302874 hdd_prevent_suspend_timeout(
2875 hdd_ctx->config->iface_change_wait_time,
2876 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302877 }
2878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002879 EXIT();
2880 return 0;
2881}
2882
2883/**
2884 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2885 * @dev: pointer to net_device structure
2886 *
2887 * This is called in response to ifconfig down
2888 *
2889 * Return: 0 for success and error number for failure
2890 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002891static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002892{
2893 int ret;
2894
2895 cds_ssr_protect(__func__);
2896 ret = __hdd_stop(dev);
2897 cds_ssr_unprotect(__func__);
2898
2899 return ret;
2900}
2901
2902/**
2903 * __hdd_uninit() - HDD uninit function
2904 * @dev: Pointer to net_device structure
2905 *
2906 * This is called during the netdev unregister to uninitialize all data
2907 * associated with the device
2908 *
2909 * Return: None
2910 */
2911static void __hdd_uninit(struct net_device *dev)
2912{
Jeff Johnson9d295242017-08-29 14:39:48 -07002913 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002914 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002915
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002916 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002917
2918 do {
2919 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002920 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002921 break;
2922 }
2923
Jeff Johnson399c6272017-08-30 10:51:00 -07002924 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2925 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002926 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002927 break;
2928 }
2929
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002930 if (dev != adapter->dev)
2931 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002932
Jeff Johnson399c6272017-08-30 10:51:00 -07002933 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002934
2935 /* after uninit our adapter structure will no longer be valid */
2936 adapter->dev = NULL;
2937 adapter->magic = 0;
2938 } while (0);
2939
2940 EXIT();
2941}
2942
2943/**
2944 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2945 * @dev: pointer to net_device structure
2946 *
2947 * This is called during the netdev unregister to uninitialize all data
2948 * associated with the device
2949 *
2950 * Return: none
2951 */
2952static void hdd_uninit(struct net_device *dev)
2953{
2954 cds_ssr_protect(__func__);
2955 __hdd_uninit(dev);
2956 cds_ssr_unprotect(__func__);
2957}
2958
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002959static int hdd_open_cesium_nl_sock(void)
2960{
2961#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2962 struct netlink_kernel_cfg cfg = {
2963 .groups = WLAN_NLINK_MCAST_GRP_ID,
2964 .input = NULL
2965 };
2966#endif
2967 int ret = 0;
2968
2969#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2970 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2971#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2972 THIS_MODULE,
2973#endif
2974 &cfg);
2975#else
2976 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2977 WLAN_NLINK_MCAST_GRP_ID,
2978 NULL, NULL, THIS_MODULE);
2979#endif
2980
2981 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002982 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002983 ret = -ECONNREFUSED;
2984 }
2985
2986 return ret;
2987}
2988
2989static void hdd_close_cesium_nl_sock(void)
2990{
2991 if (NULL != cesium_nl_srv_sock) {
2992 netlink_kernel_release(cesium_nl_srv_sock);
2993 cesium_nl_srv_sock = NULL;
2994 }
2995}
2996
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002997/**
2998 * __hdd_set_mac_address() - set the user specified mac address
2999 * @dev: Pointer to the net device.
3000 * @addr: Pointer to the sockaddr.
3001 *
3002 * This function sets the user specified mac address using
3003 * the command ifconfig wlanX hw ether <mac adress>.
3004 *
3005 * Return: 0 for success, non zero for failure
3006 */
3007static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3008{
Jeff Johnson9d295242017-08-29 14:39:48 -07003009 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003010 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303012 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013 int ret;
3014
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003015 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003016
3017 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3018 ret = wlan_hdd_validate_context(hdd_ctx);
3019 if (0 != ret)
3020 return ret;
3021
Jeff Johnson1e851a12017-10-28 14:36:12 -07003022 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003023 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3024
3025 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303026 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003027}
3028
3029/**
3030 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3031 * function from SSR
3032 * @dev: pointer to net_device structure
3033 * @addr: Pointer to the sockaddr
3034 *
3035 * This function sets the user specified mac address using
3036 * the command ifconfig wlanX hw ether <mac adress>.
3037 *
3038 * Return: 0 for success.
3039 */
3040static int hdd_set_mac_address(struct net_device *dev, void *addr)
3041{
3042 int ret;
3043
3044 cds_ssr_protect(__func__);
3045 ret = __hdd_set_mac_address(dev, addr);
3046 cds_ssr_unprotect(__func__);
3047
3048 return ret;
3049}
3050
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003051uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003052{
3053 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003054
Anurag Chouhan6d760662016-02-20 16:05:43 +05303055 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003056 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3057 break;
3058 }
3059
Anurag Chouhan6d760662016-02-20 16:05:43 +05303060 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003061 return NULL;
3062
3063 hdd_ctx->config->intfAddrMask |= (1 << i);
3064 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3065}
3066
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003067void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3068 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003069{
3070 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003071
Anurag Chouhan6d760662016-02-20 16:05:43 +05303072 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003073 if (!memcmp(releaseAddr,
3074 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3075 6)) {
3076 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3077 break;
3078 }
3079 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080}
3081
3082#ifdef WLAN_FEATURE_PACKET_FILTERING
3083/**
3084 * __hdd_set_multicast_list() - set the multicast address list
3085 * @dev: Pointer to the WLAN device.
3086 * @skb: Pointer to OS packet (sk_buff).
3087 *
3088 * This funciton sets the multicast address list.
3089 *
3090 * Return: None
3091 */
3092static void __hdd_set_multicast_list(struct net_device *dev)
3093{
Jeff Johnson9d295242017-08-29 14:39:48 -07003094 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003095 int i = 0, status;
3096 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003097 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303098 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3099 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3100 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003101
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003102 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303103 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303104 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303105
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303107 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303108 goto out;
3109
Dustin Brownc788acb2017-08-01 17:43:51 -07003110 status = hdd_validate_adapter(adapter);
3111 if (status)
3112 goto out;
3113
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303114 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3115 hdd_err("%s: Driver module is closed", __func__);
3116 return;
3117 }
3118
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303119 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3120 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003121 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303122 goto out;
3123 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303125 /* Delete already configured multicast address list */
3126 if (adapter->mc_addr_list.mc_cnt > 0) {
3127 hdd_info("clear previously configured MC address list");
3128 hdd_disable_and_flush_mc_addr_list(adapter,
3129 pmo_mc_list_change_notify);
3130 }
3131
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003132 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003133 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303134 hdd_disable_and_flush_mc_addr_list(adapter,
3135 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003136 } else {
3137 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303138 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003139 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303140 pmo_ucfg_max_mc_addr_supported(psoc));
3141 hdd_disable_and_flush_mc_addr_list(adapter,
3142 pmo_mc_list_change_notify);
3143 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003144 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003145 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003146 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303147 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 if (i == mc_count)
3149 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303150 memset(&(mc_list_request->mc_addr[i].bytes),
3151 0, ETH_ALEN);
3152 memcpy(&(mc_list_request->mc_addr[i].bytes),
3153 ha->addr, ETH_ALEN);
3154 hdd_info("mlist[%d] = %pM", i,
3155 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003156 i++;
3157 }
3158 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303159
3160 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003161 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303162 mc_list_request->count = mc_count;
3163 status = hdd_cache_mc_addr_list(mc_list_request);
3164 if (status == 0) {
3165 hdd_enable_mc_addr_filtering(adapter,
3166 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003167 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303168 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303170out:
3171 if (mc_list_request)
3172 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303173 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174}
3175
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303176
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177/**
3178 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3179 * @dev: pointer to net_device
3180 *
3181 * Return: none
3182 */
3183static void hdd_set_multicast_list(struct net_device *dev)
3184{
3185 cds_ssr_protect(__func__);
3186 __hdd_set_multicast_list(dev);
3187 cds_ssr_unprotect(__func__);
3188}
3189#endif
3190
3191/**
3192 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3193 * @dev: Pointer to the WLAN device.
3194 * @skb: Pointer to OS packet (sk_buff).
3195 *
3196 * This function is registered with the Linux OS for network
3197 * core to decide which queue to use first.
3198 *
3199 * Return: ac, Queue Index/access category corresponding to UP in IP header
3200 */
3201static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3202#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3203 , void *accel_priv
3204#endif
3205#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3206 , select_queue_fallback_t fallback
3207#endif
3208)
3209{
3210 return hdd_wmm_select_queue(dev, skb);
3211}
3212
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003213static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003214 .ndo_open = hdd_open,
3215 .ndo_stop = hdd_stop,
3216 .ndo_uninit = hdd_uninit,
3217 .ndo_start_xmit = hdd_hard_start_xmit,
3218 .ndo_tx_timeout = hdd_tx_timeout,
3219 .ndo_get_stats = hdd_get_stats,
3220 .ndo_do_ioctl = hdd_ioctl,
3221 .ndo_set_mac_address = hdd_set_mac_address,
3222 .ndo_select_queue = hdd_select_queue,
3223#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003224 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003225#endif
3226};
3227
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003228/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003229static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003230 .ndo_open = hdd_mon_open,
3231 .ndo_stop = hdd_stop,
3232 .ndo_get_stats = hdd_get_stats,
3233};
3234
3235/**
3236 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003237 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003238 * Return: None
3239 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003240void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003242 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003243 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003244 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003245 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003246}
3247
3248/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003249 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3250 * @hdd_ctx: global hdd context
3251 * @macAddr: mac address to assign to the interface
3252 * @name: User-visible name of the interface
3253 *
3254 * hdd adapter pointer would point to the netdev->priv space, this function
3255 * would retrive the pointer, and setup the hdd adapter configuration.
3256 *
3257 * Return: the pointer to hdd adapter, otherwise NULL
3258 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003259static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003260 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003261 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003262 const char *name)
3263{
Jeff Johnson5505db82017-11-02 21:19:23 -07003264 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003265 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003266 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303267 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268 /*
3269 * cfg80211 initialization and registration....
3270 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003271 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003272#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3273 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003274#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003275 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3276 hdd_mon_mode_ether_setup : ether_setup),
3277 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003278
Jeff Johnson5505db82017-11-02 21:19:23 -07003279 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280
3281 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003282 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283
Jeff Johnson9d295242017-08-29 14:39:48 -07003284 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003285 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303286 qdf_mem_set(sta_ctx->conn_info.staId,
3287 sizeof(sta_ctx->conn_info.staId),
3288 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003289 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003290 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003291 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003292 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003293
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303294 qdf_status = qdf_event_create(
3295 &adapter->qdf_session_open_event);
3296 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3297 hdd_err("Session open QDF event init failed!");
3298 free_netdev(adapter->dev);
3299 return NULL;
3300 }
3301
3302 qdf_status = qdf_event_create(
3303 &adapter->qdf_session_close_event);
3304 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3305 hdd_err("Session close QDF event init failed!");
3306 free_netdev(adapter->dev);
3307 return NULL;
3308 }
3309
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003310 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303311 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312 init_completion(&adapter->linkup_event_var);
3313 init_completion(&adapter->cancel_rem_on_chan_var);
3314 init_completion(&adapter->rem_on_chan_ready_event);
3315 init_completion(&adapter->sta_authorized_event);
3316 init_completion(&adapter->offchannel_tx_event);
3317 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003318 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003319 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303320 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003321
3322 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003323 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003324 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003325 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003326
Jeff Johnson5505db82017-11-02 21:19:23 -07003327 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003328 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003329 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003330 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003331 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003332
3333 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003334 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003335 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003336 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337
Jeff Johnson5505db82017-11-02 21:19:23 -07003338 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003340 hdd_set_station_ops(adapter->dev);
3341
Jeff Johnson5505db82017-11-02 21:19:23 -07003342 hdd_dev_setup_destructor(dev);
3343 dev->ieee80211_ptr = &adapter->wdev;
3344 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003345 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003346 adapter->wdev.netdev = dev;
3347 /* set dev's parent to underlying device */
3348 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003349 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303350 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003351 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303352 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003353 }
3354
3355 return adapter;
3356}
3357
Jeff Johnson9d295242017-08-29 14:39:48 -07003358static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003360 struct net_device *dev = adapter->dev;
3361 int ret;
3362
3363 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003365 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003366 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3367
3368 ret = dev_alloc_name(dev, dev->name);
3369 if (ret < 0) {
3370 hdd_err(
3371 "unable to get dev name: %s, err = 0x%x",
3372 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303373 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003374 }
3375 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003376
3377 ret = register_netdevice(dev);
3378 if (ret) {
3379 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3380 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303381 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003382 }
3383 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003384 ret = register_netdev(dev);
3385 if (ret) {
3386 hdd_err("register_netdev(%s) failed, err = 0x%x",
3387 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303388 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003389 }
3390 }
3391 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3392
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003393 EXIT();
3394
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303395 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396}
3397
Krunal Sonib51eec72017-11-20 21:53:01 -08003398QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003399{
Krunal Sonib51eec72017-11-20 21:53:01 -08003400 struct hdd_adapter *adapter;
3401 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003402
Krunal Sonib51eec72017-11-20 21:53:01 -08003403 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3404 if (!hdd_ctx) {
3405 hdd_err("Invalid HDD_CTX");
3406 return QDF_STATUS_E_FAILURE;
3407 }
3408
3409 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3410 if (NULL == adapter) {
3411 hdd_err("NULL adapter");
3412 return QDF_STATUS_E_INVAL;
3413 }
3414 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303415 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003416 hdd_debug("session %d opened", adapter->session_id);
3417
3418 return QDF_STATUS_SUCCESS;
3419}
3420
3421QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3422{
3423 struct hdd_adapter *adapter;
3424 struct hdd_context *hdd_ctx;
3425
3426 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3427 if (!hdd_ctx) {
3428 hdd_err("Invalid HDD_CTX");
3429 return QDF_STATUS_E_FAILURE;
3430 }
3431
3432 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003433 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003434 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303435 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 }
3437
3438 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003439 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303440 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441 }
3442
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003443 /*
3444 * For NAN Data interface, the close session results in the final
3445 * indication to the userspace
3446 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003447 if (adapter->device_mode == QDF_NDI_MODE)
3448 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003449
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3451
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 /*
3453 * We can be blocked while waiting for scheduled work to be
3454 * flushed, and the adapter structure can potentially be freed, in
3455 * which case the magic will have been reset. So make sure the
3456 * magic is still good, and hence the adapter structure is still
3457 * valid, before signaling completion
3458 */
3459 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303460 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303462 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463}
3464
Jeff Johnson9d295242017-08-29 14:39:48 -07003465int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003466{
Dustin Brownd28772b2017-03-17 14:16:07 -07003467 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468
Dustin Brownd28772b2017-03-17 14:16:07 -07003469 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003470 if (QDF_IS_STATUS_ERROR(status))
3471 return qdf_status_to_os_return(status);
3472
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003473 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003474 if (QDF_IS_STATUS_ERROR(status))
3475 return qdf_status_to_os_return(status);
3476
3477 if (wma_capability_enhanced_mcast_filter())
3478 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3479 else
3480 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003481
3482 return qdf_status_to_os_return(status);
3483}
3484
Jeff Johnson9d295242017-08-29 14:39:48 -07003485int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003486{
3487 QDF_STATUS status;
3488 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003489 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003490 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003491
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003492 vdev_id = adapter->session_id;
3493 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003494
3495 /* vdev created sanity check */
3496 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003497 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003498 return -EINVAL;
3499 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003500 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003501 /*
3502 * In SSR case, there is no need to destroy vdev in firmware since
3503 * it has already asserted. vdev can be released directly.
3504 */
Krunal Sonib51eec72017-11-20 21:53:01 -08003505 if (cds_is_driver_recovering()) {
3506 hdd_debug("SSR: silently release the vdev for session-id: %d",
3507 adapter->session_id);
3508 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Yue Maf9782842017-05-08 12:49:49 -07003509 goto release_vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08003510 }
Yue Maf9782842017-05-08 12:49:49 -07003511
Dustin Brownd28772b2017-03-17 14:16:07 -07003512 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303513 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003514 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003515 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003516 if (QDF_IS_STATUS_ERROR(status)) {
3517 hdd_err("failed to close sme session: %d", status);
3518 return qdf_status_to_os_return(status);
3519 }
3520
3521 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303522 status = qdf_wait_for_event_completion(
3523 &adapter->qdf_session_close_event,
3524 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3525 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003526 if (adapter->device_mode == QDF_NDI_MODE)
3527 hdd_ndp_session_end_handler(adapter);
3528 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303529 adapter->session_id = HDD_SESSION_ID_INVALID;
3530 if (QDF_STATUS_E_TIMEOUT != status) {
3531 hdd_err("timed out waiting for close sme session: %u", status);
3532 return -ETIMEDOUT;
3533 } else if (adapter->qdf_session_close_event.force_set) {
3534 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
3535 return -EINVAL;
3536 } else {
3537 hdd_err("Failed to close sme session (%u)", status);
3538 return -EINVAL;
3539 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003540 }
Yue Maf9782842017-05-08 12:49:49 -07003541release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003542 /* do vdev logical destroy via objmgr */
3543 errno = hdd_objmgr_destroy_vdev(adapter);
3544 if (errno) {
3545 hdd_err("failed to destroy objmgr vdev: %d", errno);
3546 return errno;
3547 }
3548
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003549 /* now that sme session is closed, allow physical vdev destroy */
3550 errno = hdd_objmgr_release_vdev(adapter);
3551 if (errno) {
3552 hdd_err("failed to release objmgr vdev: %d", errno);
3553 return errno;
3554 }
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003555 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003556
3557 return 0;
3558}
3559
Krunal Sonib51eec72017-11-20 21:53:01 -08003560static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3561 struct sme_session_params *session_param,
3562 csr_roam_completeCallback callback,
3563 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003564{
Dustin Brownd28772b2017-03-17 14:16:07 -07003565 uint32_t type;
3566 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003567 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003568
3569 /* determine vdev (sub)type */
3570 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303571 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003572 hdd_err("failed to get vdev type: %d", status);
3573 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003574 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003575 session_param->sme_session_id = adapter->session_id;
3576 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3577 session_param->type_of_persona = type;
3578 session_param->subtype_of_persona = sub_type;
3579 session_param->session_open_cb = hdd_sme_open_session_callback;
3580 session_param->session_close_cb = hdd_sme_close_session_callback;
3581 session_param->callback = callback;
3582 session_param->callback_ctx = callback_ctx;
3583
3584 return 0;
3585}
3586
3587int hdd_vdev_create(struct hdd_adapter *adapter,
3588 csr_roam_completeCallback callback, void *ctx)
3589{
3590 QDF_STATUS status;
3591 int errno;
3592 struct hdd_context *hdd_ctx;
3593 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003594
3595 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003596
3597 /* do vdev create via objmgr */
3598 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003599 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003600 if (errno) {
3601 hdd_err("failed to create objmgr vdev: %d", errno);
3602 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003604
3605 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303606 status = qdf_event_reset(&adapter->qdf_session_open_event);
3607 if (QDF_STATUS_SUCCESS != status) {
3608 hdd_err("failed to reinit session open event");
3609 return -EINVAL;
3610 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003611 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3612 callback, ctx);
3613 if (errno) {
3614 hdd_err("failed to populating SME params");
3615 goto objmgr_vdev_destroy_procedure;
3616 }
3617
3618 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003619 if (QDF_IS_STATUS_ERROR(status)) {
3620 hdd_err("failed to open sme session: %d", status);
3621 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003622 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003623 }
3624
3625 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303626 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3627 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3628 if (QDF_STATUS_SUCCESS != status) {
3629 if (adapter->qdf_session_open_event.force_set) {
3630 /*
3631 * SSR/PDR has caused shutdown, which has forcefully
3632 * set the event. Return without the closing session.
3633 */
3634 adapter->session_id = HDD_SESSION_ID_INVALID;
3635 hdd_err("Session open event forcefully set");
3636 return -EINVAL;
3637 } else {
3638 if (QDF_STATUS_E_TIMEOUT == status)
3639 hdd_err("Session failed to open within timeout period");
3640 else
3641 hdd_err("Failed to wait for session open event(status-%d)",
3642 status);
3643 errno = -ETIMEDOUT;
3644 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3645 goto hdd_vdev_destroy_procedure;
3646 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003647 }
3648
3649 /* firmware ready for component communication, raise vdev_ready event */
3650 errno = hdd_vdev_ready(adapter);
3651 if (errno) {
3652 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003653 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003654 }
3655
Jeff Johnson1b780e42017-10-31 14:11:45 -07003656 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003657
3658 return 0;
3659
3660 /*
3661 * Due to legacy constraints, we need to destroy in the same order as
3662 * create. So, split error handling into 2 cases to accommodate.
3663 */
3664
Krunal Soni4a020c72017-10-30 20:58:40 -07003665objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003666 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003667
3668 return errno;
3669
Krunal Soni4a020c72017-10-30 20:58:40 -07003670hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003671 QDF_BUG(!hdd_vdev_destroy(adapter));
3672
3673 return errno;
3674}
3675
Jeff Johnson9d295242017-08-29 14:39:48 -07003676QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003677{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003678 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003679 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003680 QDF_STATUS status;
3681 int ret_val;
3682
Dustin Brownd28772b2017-03-17 14:16:07 -07003683 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3684 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3685 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003686 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003687
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003688 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003689 status = hdd_register_wext(adapter->dev);
3690 if (QDF_IS_STATUS_ERROR(status)) {
3691 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692 goto error_register_wext;
3693 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003694 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003695
Jeff Johnsond377dce2017-10-04 10:32:42 -07003696 qdf_mem_set(sta_ctx->conn_info.staId,
3697 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303698
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003699 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003700 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003701 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003703 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003704 hdd_ctx->config->OperatingChannel;
3705
3706 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003707 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003708
3709 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303710 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003711 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712 status, status);
3713 goto error_init_txrx;
3714 }
3715
3716 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3717
3718 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303719 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003720 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003721 status, status);
3722 goto error_wmm_init;
3723 }
3724
3725 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3726
Jeff Johnson1b780e42017-10-31 14:11:45 -07003727 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003728 WMI_PDEV_PARAM_BURST_ENABLE,
3729 hdd_ctx->config->enableSifsBurst,
3730 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003731 if (ret_val)
3732 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003733
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303734 /*
3735 * In case of USB tethering, LRO is disabled. If SSR happened
3736 * during that time, then as part of SSR init, do not enable
3737 * the LRO again. Keep the LRO state same as before SSR.
3738 */
3739 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003740 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303741
3742 /* rcpi info initialization */
3743 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3744
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303745 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003746
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003747error_wmm_init:
3748 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3749 hdd_deinit_tx_rx(adapter);
3750error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003751 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003752error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003753 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003754
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003755 return status;
3756}
3757
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303758/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003759 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303760 * @hdd_ctx: global hdd context
3761 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003762 * @rtnl_held: Used to indicate whether or not the caller is holding
3763 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303764 *
3765 * This function De-initializes the STA/P2P/OCB adapter.
3766 *
3767 * Return: None.
3768 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003769static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003770 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003771 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303772{
3773 ENTER_DEV(adapter->dev);
3774
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303775 if (adapter->dev) {
3776 if (rtnl_held)
3777 adapter->dev->wireless_handlers = NULL;
3778 else {
3779 rtnl_lock();
3780 adapter->dev->wireless_handlers = NULL;
3781 rtnl_unlock();
3782 }
3783 }
3784
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303785 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3786 hdd_deinit_tx_rx(adapter);
3787 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3788 }
3789
3790 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3791 hdd_wmm_adapter_close(adapter);
3792 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3793 }
3794
Krunal Sonib51eec72017-11-20 21:53:01 -08003795
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303796 EXIT();
3797}
3798
Krunal Sonib51eec72017-11-20 21:53:01 -08003799void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3800 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003801 bool rtnl_held)
3802{
3803 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303804
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003805 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003806 case QDF_STA_MODE:
3807 case QDF_P2P_CLIENT_MODE:
3808 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003809 case QDF_IBSS_MODE:
3810 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003812 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 break;
3814 }
3815
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003816 case QDF_SAP_MODE:
3817 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003818 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003819 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003820 break;
3821 }
3822
3823 default:
3824 break;
3825 }
3826
3827 EXIT();
3828}
3829
Jeff Johnson9d295242017-08-29 14:39:48 -07003830static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003831 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003832{
Jeff Johnson5505db82017-11-02 21:19:23 -07003833 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003834
3835 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003836 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003837 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003838 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839 return;
3840 }
3841
Rajeev Kumardca5f812016-02-04 17:28:06 -08003842 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303843
Yue Ma9e89e832017-11-14 11:40:23 -08003844 hdd_adapter_runtime_suspend_deinit(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303845
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003846 /*
3847 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3848 * the driver is almost closed and cannot handle either control
3849 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003850 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3851 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003852 * is not right. Setting this flag helps hdd_stop() to recognize that
3853 * the interface is closed and restricts any operations on that
3854 */
3855 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3856
3857 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003858 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003859 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003860 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003861 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862 /*
3863 * Note that the adapter is no longer valid at this point
3864 * since the memory has been reclaimed
3865 */
3866 }
3867}
3868
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003869static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003870 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003871{
Jeff Johnson9d295242017-08-29 14:39:48 -07003872 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003873
Dustin Brown920397d2017-12-13 16:27:50 -08003874 hdd_for_each_adapter(hdd_ctx, adapter) {
3875 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
3876 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303877 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003879 }
Dustin Brown920397d2017-12-13 16:27:50 -08003880
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303881 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003882}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003883
Arun Khandavalli2358d522016-05-16 18:05:37 +05303884#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3885/**
3886 * hdd_set_fw_log_params() - Set log parameters to FW
3887 * @hdd_ctx: HDD Context
3888 * @adapter: HDD Adapter
3889 *
3890 * This function set the FW Debug log level based on the INI.
3891 *
3892 * Return: None
3893 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003894static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003895 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303896{
3897 uint8_t count = 0, numentries = 0,
3898 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3899 uint32_t value = 0;
3900 int ret;
3901
Arun Khandavallifae92942016-08-01 13:31:08 +05303902 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3903 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003904 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303905 return;
3906 }
3907
Arun Khandavallifae92942016-08-01 13:31:08 +05303908 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303909 hdd_ctx->fw_log_settings.dl_type =
3910 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003911 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303912 WMI_DBGLOG_TYPE,
3913 hdd_ctx->config->enableFwLogType,
3914 DBG_CMD);
3915 if (ret != 0)
3916 hdd_err("Failed to enable FW log type ret %d",
3917 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303918
3919 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303920 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003921 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303922 WMI_DBGLOG_LOG_LEVEL,
3923 hdd_ctx->config->enableFwLogLevel,
3924 DBG_CMD);
3925 if (ret != 0)
3926 hdd_err("Failed to enable FW log level ret %d",
3927 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303928
3929 hdd_string_to_u8_array(
3930 hdd_ctx->config->enableFwModuleLogLevel,
3931 moduleloglevel,
3932 &numentries,
3933 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3934
3935 while (count < numentries) {
3936 /*
3937 * FW module log level input string looks like
3938 * below:
3939 * gFwDebugModuleLoglevel=<FW Module ID>,
3940 * <Log Level>,...
3941 * For example:
3942 * gFwDebugModuleLoglevel=
3943 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3944 * Above input string means :
3945 * For FW module ID 1 enable log level 0
3946 * For FW module ID 2 enable log level 1
3947 * For FW module ID 3 enable log level 2
3948 * For FW module ID 4 enable log level 3
3949 * For FW module ID 5 enable log level 4
3950 * For FW module ID 6 enable log level 5
3951 * For FW module ID 7 enable log level 6
3952 */
3953
Nishank Aggarwale239d962017-03-03 12:26:02 +05303954 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3955 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3956 hdd_err("Module id %d and dbglog level %d input length is more than max",
3957 moduleloglevel[count],
3958 moduleloglevel[count + 1]);
3959 return;
3960 }
3961
3962 value = moduleloglevel[count] << 16;
3963 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07003964 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303965 WMI_DBGLOG_MOD_LOG_LEVEL,
3966 value, DBG_CMD);
3967 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303968 hdd_err("Failed to enable FW module log level %d ret %d",
3969 value, ret);
3970
3971 count += 2;
3972 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303973
Arun Khandavalli2358d522016-05-16 18:05:37 +05303974}
3975#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003976static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003977 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303978{
3979}
3980
3981#endif
3982
3983/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08003984 * hdd_configure_chain_mask() - programs chain mask to firmware
3985 * @adapter: HDD adapter
3986 *
3987 * Return: 0 on success or errno on failure
3988 */
3989static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
3990{
3991 int ret_val;
3992 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3993
3994 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
3995 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
3996 hdd_ctx->config->txchainmask1x1,
3997 hdd_ctx->config->rxchainmask1x1);
3998 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
3999 hdd_ctx->config->dual_mac_feature_disable,
4000 hdd_ctx->config->tx_chain_mask_2g,
4001 hdd_ctx->config->rx_chain_mask_2g);
4002 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4003 hdd_ctx->config->tx_chain_mask_5g,
4004 hdd_ctx->config->rx_chain_mask_5g);
4005
4006 if (hdd_ctx->config->enable2x2) {
4007 hdd_info("2x2 enabled. skip chain mask programming");
4008 return 0;
4009 }
4010
4011 if (hdd_ctx->config->txchainmask1x1) {
4012 ret_val = sme_cli_set_command(adapter->session_id,
4013 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4014 hdd_ctx->config->txchainmask1x1,
4015 PDEV_CMD);
4016 if (ret_val)
4017 goto error;
4018 }
4019
4020 if (hdd_ctx->config->rxchainmask1x1) {
4021 ret_val = sme_cli_set_command(adapter->session_id,
4022 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4023 hdd_ctx->config->rxchainmask1x1,
4024 PDEV_CMD);
4025 if (ret_val)
4026 goto error;
4027 }
4028
4029 if (hdd_ctx->lte_coex_ant_share) {
4030 hdd_info("lte ant sharing enabled. skip per band chain mask");
4031 return 0;
4032 }
4033
4034 if (hdd_ctx->config->txchainmask1x1 ||
4035 hdd_ctx->config->rxchainmask1x1) {
4036 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4037 return 0;
4038 }
4039
4040 if (!hdd_ctx->config->dual_mac_feature_disable) {
4041 hdd_info("DBS enabled. skip per band chain mask");
4042 return 0;
4043 }
4044
4045 if (hdd_ctx->config->tx_chain_mask_2g) {
4046 ret_val = sme_cli_set_command(adapter->session_id,
4047 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4048 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4049 if (0 != ret_val)
4050 goto error;
4051 }
4052
4053 if (hdd_ctx->config->rx_chain_mask_2g) {
4054 ret_val = sme_cli_set_command(adapter->session_id,
4055 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4056 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4057 if (0 != ret_val)
4058 goto error;
4059 }
4060
4061 if (hdd_ctx->config->tx_chain_mask_5g) {
4062 ret_val = sme_cli_set_command(adapter->session_id,
4063 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4064 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4065 if (0 != ret_val)
4066 goto error;
4067 }
4068
4069 if (hdd_ctx->config->rx_chain_mask_5g) {
4070 ret_val = sme_cli_set_command(adapter->session_id,
4071 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4072 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4073 if (0 != ret_val)
4074 goto error;
4075 }
4076
4077 return 0;
4078
4079error:
4080 hdd_err("WMI PDEV set param failed %d", ret_val);
4081 return -EINVAL;
4082}
4083
4084/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304085 * hdd_set_fw_params() - Set parameters to firmware
4086 * @adapter: HDD adapter
4087 *
4088 * This function Sets various parameters to fw once the
4089 * adapter is started.
4090 *
4091 * Return: 0 on success or errno on failure
4092 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004093int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304094{
4095 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004096 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304097
4098 ENTER_DEV(adapter->dev);
4099
4100 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4101 if (!hdd_ctx)
4102 return -EINVAL;
4103
Dustin Brown732ab9c2017-06-15 13:24:09 -07004104 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4105 hdd_debug("FTM Mode is active; nothing to do");
4106 return 0;
4107 }
4108
Jeff Johnson1b780e42017-10-31 14:11:45 -07004109 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304110 WMI_PDEV_PARAM_DTIM_SYNTH,
4111 hdd_ctx->config->enable_lprx, PDEV_CMD);
4112 if (ret) {
4113 hdd_err("Failed to set LPRx");
4114 goto error;
4115 }
4116
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304117 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004118 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304119 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4120 hdd_ctx->config->upper_brssi_thresh);
4121
Jeff Johnson1b780e42017-10-31 14:11:45 -07004122 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304123 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4124 hdd_ctx->config->lower_brssi_thresh);
4125
Jeff Johnson1b780e42017-10-31 14:11:45 -07004126 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304127 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4128 hdd_ctx->config->enable_dtim_1chrx);
4129 }
4130
Dustin Brown732ab9c2017-06-15 13:24:09 -07004131 if (hdd_ctx->config->enable2x2) {
4132 hdd_debug("configuring 2x2 mode fw params");
4133
Jeff Johnson1b780e42017-10-31 14:11:45 -07004134 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004135 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4136 hdd_ctx->config->enable_cck_tx_fir_override,
4137 PDEV_CMD);
4138 if (ret) {
4139 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4140 ret);
4141 goto error;
4142 }
4143 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304144#define HDD_DTIM_1CHAIN_RX_ID 0x5
4145#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004146 hdd_debug("configuring 1x1 mode fw params");
4147
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004148 /*
4149 * Disable DTIM 1 chain Rx when in 1x1,
4150 * we are passing two value
4151 * as param_id << 29 | param_value.
4152 * Below param_value = 0(disable)
4153 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004154 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004155 WMI_STA_SMPS_PARAM_CMDID,
4156 HDD_DTIM_1CHAIN_RX_ID <<
4157 HDD_SMPS_PARAM_VALUE_S,
4158 VDEV_CMD);
4159 if (ret) {
4160 hdd_err("DTIM 1 chain set failed %d", ret);
4161 goto error;
4162 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304163
Arun Khandavalli2358d522016-05-16 18:05:37 +05304164#undef HDD_DTIM_1CHAIN_RX_ID
4165#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004166
4167 if (hdd_configure_chain_mask(adapter))
4168 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004169 }
4170
Jeff Johnson1b780e42017-10-31 14:11:45 -07004171 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004172 WMI_PDEV_PARAM_HYST_EN,
4173 hdd_ctx->config->enableMemDeepSleep,
4174 PDEV_CMD);
4175 if (ret) {
4176 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4177 goto error;
4178 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304179
Jeff Johnson1b780e42017-10-31 14:11:45 -07004180 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004181 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4182 hdd_ctx->config->rts_profile,
4183 VDEV_CMD);
4184 if (ret) {
4185 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4186 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304187 }
4188
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004189 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4190
Jeff Johnson1b780e42017-10-31 14:11:45 -07004191 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004192 GEN_VDEV_PARAM_AMSDU,
4193 hdd_ctx->config->max_amsdu_num,
4194 GEN_CMD);
4195 if (ret != 0) {
4196 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4197 goto error;
4198 }
4199
Arun Khandavalli2358d522016-05-16 18:05:37 +05304200 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304201 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004202
Arun Khandavalli2358d522016-05-16 18:05:37 +05304203 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304204
Arun Khandavalli2358d522016-05-16 18:05:37 +05304205error:
4206 return -EINVAL;
4207}
4208
Ryan Hsu07495ea2016-01-21 15:25:39 -08004209/**
4210 * hdd_open_adapter() - open and setup the hdd adatper
4211 * @hdd_ctx: global hdd context
4212 * @session_type: type of the interface to be created
4213 * @iface_name: User-visible name of the interface
4214 * @macAddr: MAC address to assign to the interface
4215 * @name_assign_type: the name of assign type of the netdev
4216 * @rtnl_held: the rtnl lock hold flag
4217 *
4218 * This function open and setup the hdd adpater according to the device
4219 * type request, assign the name, the mac address assigned, and then prepared
4220 * the hdd related parameters, queue, lock and ready to start.
4221 *
4222 * Return: the pointer of hdd adapter, otherwise NULL.
4223 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004224struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004225 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004226 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004227 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004228{
Jeff Johnson9d295242017-08-29 14:39:48 -07004229 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304230 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004231
4232 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4233 /*
4234 * Max limit reached on the number of vdevs configured by the
4235 * host. Return error
4236 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304237 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4238 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 return NULL;
4240 }
4241
4242 if (macAddr == NULL) {
4243 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304244 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245 return NULL;
4246 }
4247 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304248 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304249 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4250 " already exists",
4251 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004252 return NULL;
4253 }
4254
4255 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004256 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004257 /* Reset locally administered bit if the device mode is STA */
4258 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304259 hdd_info("locally administered bit reset in sta mode: "
4260 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004261 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004262 case QDF_P2P_CLIENT_MODE:
4263 case QDF_P2P_DEVICE_MODE:
4264 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004265 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304266 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004267 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4268 name_assign_type,
4269 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004270
4271 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304272 hdd_err("failed to allocate adapter for session %d",
4273 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274 return NULL;
4275 }
4276
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004277 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004279 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304281 else if (QDF_MONITOR_MODE == session_type)
4282 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 else
4284 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4285
4286 adapter->device_mode = session_type;
4287
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004289 /*
4290 * Workqueue which gets scheduled in IPv4 notification
4291 * callback
4292 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004293 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004294 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004295
4296#ifdef WLAN_NS_OFFLOAD
4297 /*
4298 * Workqueue which gets scheduled in IPv6
4299 * notification callback.
4300 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004301 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302 hdd_ipv6_notifier_work_queue);
4303#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004305 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004306 goto err_deinit_adapter_runtime_pm;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307
4308 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004309 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004310 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304311 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4312 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304313
Ravi Joshi1a292562017-05-18 16:28:54 -07004314 /* Initialize NAN Data Interface */
4315 if (QDF_NDI_MODE == session_type) {
4316 status = hdd_init_nan_data_mode(adapter);
4317 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004318 goto err_deinit_adapter_runtime_pm;
Ravi Joshi1a292562017-05-18 16:28:54 -07004319 }
4320
4321 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004323 case QDF_P2P_GO_MODE:
4324 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004325 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4326 name_assign_type,
4327 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004329 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304330 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004331 return NULL;
4332 }
4333
4334 adapter->wdev.iftype =
4335 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004336 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004337 NL80211_IFTYPE_P2P_GO;
4338 adapter->device_mode = session_type;
4339
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004340 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004341 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004342 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004343
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004344 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004345 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304346 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4347 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304348
4349 /*
4350 * Workqueue which gets scheduled in IPv4 notification
4351 * callback
4352 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004353 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304354 hdd_ipv4_notifier_work_queue);
4355
4356#ifdef WLAN_NS_OFFLOAD
4357 /*
4358 * Workqueue which gets scheduled in IPv6
4359 * notification callback.
4360 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004361 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304362 hdd_ipv6_notifier_work_queue);
4363#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304365 case QDF_FTM_MODE:
4366 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4367 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004368 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304369 if (NULL == adapter) {
4370 hdd_err("Failed to allocate adapter for FTM mode");
4371 return NULL;
4372 }
4373 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4374 adapter->device_mode = session_type;
4375 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004376 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004377 goto err_deinit_adapter_runtime_pm;
Krunal Sonib51eec72017-11-20 21:53:01 -08004378
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304379 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004380 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304381 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304382 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4383 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304384 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004386 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304387 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004388 return NULL;
4389 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004390
hqueaa33ee2017-05-04 17:56:35 +08004391 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4392
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304393 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004395 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 }
4397
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304398 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399 if (NULL != adapter) {
4400 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4401 adapter = NULL;
4402 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004403
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004404 return NULL;
4405 }
4406
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304407 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004408 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4409 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004411 /* Adapter successfully added. Increment the vdev count */
4412 hdd_ctx->current_intf_count++;
4413
Jeff Johnson5880d792016-08-15 13:32:30 -07004414 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415 hdd_ctx->current_intf_count);
4416
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004417 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004418 }
4419
Rajeev Kumardca5f812016-02-04 17:28:06 -08004420 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004421 hdd_err("Interface %s wow debug_fs init failed",
4422 netdev_name(adapter->dev));
4423
4424 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4425 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004426
4427 return adapter;
4428
Yue Ma9e89e832017-11-14 11:40:23 -08004429err_deinit_adapter_runtime_pm:
4430 /*
4431 * For certain error cases that hdd_alloc_station_adapter()
4432 * is used to allocate the adapter.
4433 */
4434 hdd_adapter_runtime_suspend_deinit(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004435err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004436 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304437 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438
4439 return NULL;
4440}
4441
Jeff Johnson9d295242017-08-29 14:39:48 -07004442QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004443 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004444{
Dustin Brown920397d2017-12-13 16:27:50 -08004445 /*
4446 * Here we are stopping global bus_bw timer & work per adapter.
4447 *
4448 * The reason is to fix one race condition between
4449 * bus bandwidth work and cleaning up an adapter.
4450 * Under some conditions, it is possible for the bus bandwidth
4451 * work to access a particularly destroyed adapter, leading to
4452 * use-after-free.
4453 */
4454 hdd_debug("wait for bus bw work to flush");
4455 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4456 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004457
Dustin Brown920397d2017-12-13 16:27:50 -08004458 /* cleanup adapter */
4459 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4460 adapter->device_mode);
4461 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4462 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463
Dustin Brown920397d2017-12-13 16:27:50 -08004464 /* conditionally restart the bw timer */
4465 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466
Dustin Brown920397d2017-12-13 16:27:50 -08004467 /* Adapter removed. Decrement vdev count */
4468 if (hdd_ctx->current_intf_count != 0)
4469 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004470
Dustin Brown920397d2017-12-13 16:27:50 -08004471 /* Fw will take care incase of concurrency */
4472 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004473}
4474
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004475/**
4476 * hdd_close_all_adapters - Close all open adapters
4477 * @hdd_ctx: Hdd context
4478 * rtnl_held: True if RTNL lock held
4479 *
4480 * Close all open adapters.
4481 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304482 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004483 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004484QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004485{
Dustin Brown920397d2017-12-13 16:27:50 -08004486 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304487 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004488
4489 ENTER();
4490
4491 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004492 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4493 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304494 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004495 adapter->mac_addr.bytes);
4496 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4497
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304498 /* Adapter removed. Decrement vdev count */
4499 if (hdd_ctx->current_intf_count != 0)
4500 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004501 }
Dustin Brown920397d2017-12-13 16:27:50 -08004502 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004503
4504 EXIT();
4505
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304506 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507}
4508
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004509void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004510{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304511 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004512 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004513
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004514 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004515 case QDF_STA_MODE:
4516 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004517 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004518 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004519 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004520 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004521 break;
4522 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004523 case QDF_SAP_MODE:
4524 case QDF_P2P_GO_MODE:
4525 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004526 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004527 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528 break;
4529 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004530 case QDF_FTM_MODE:
4531 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004532 default:
4533 /*
4534 * wlan_hdd_reset_prob_rspies should not have been called
4535 * for these kind of devices
4536 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004537 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004538 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004539 return;
4540 }
4541
Anurag Chouhanc5548422016-02-24 18:33:27 +05304542 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004543 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004544 updateIE.ieBufferlength = 0;
4545 updateIE.pAdditionIEBuffer = NULL;
4546 updateIE.append = true;
4547 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004548 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004549 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304550 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004551 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004552 }
4553}
4554
Dustin Browndb2a8be2017-12-20 11:49:56 -08004555QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4556 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004557{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304558 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004559 struct hdd_wext_state *pWextState =
4560 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004561 union iwreq_data wrqu;
4562 tSirUpdateIE updateIE;
4563 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304564 tsap_Config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004565
4566 ENTER();
4567
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004568 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304569 wlan_hdd_netif_queue_control(adapter,
4570 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4571 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004572 /*
4573 * if this is the last active connection check & stop the
4574 * opportunistic timer first
4575 */
4576 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4577 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4578 policy_mgr_convert_device_mode_to_qdf_type(
4579 adapter->device_mode), NULL) == 1)) ||
4580 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4581 policy_mgr_check_and_stop_opportunistic_timer(
4582 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004583 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004584 case QDF_STA_MODE:
4585 case QDF_P2P_CLIENT_MODE:
4586 case QDF_IBSS_MODE:
4587 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004588 case QDF_NDI_MODE:
4589 if ((QDF_NDI_MODE == adapter->device_mode) ||
4590 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004591 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4592 hdd_is_connecting(
4593 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004594 INIT_COMPLETION(adapter->disconnect_comp_var);
4595 /*
4596 * For NDI do not use pWextState from sta_ctx, if needed
4597 * extract from ndi_ctx.
4598 */
4599 if (QDF_NDI_MODE == adapter->device_mode)
4600 qdf_ret_status = sme_roam_disconnect(
4601 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004602 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004603 eCSR_DISCONNECT_REASON_NDI_DELETE);
4604 else if (pWextState->roamProfile.BSSType ==
4605 eCSR_BSS_TYPE_START_IBSS)
4606 qdf_ret_status = sme_roam_disconnect(
4607 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004608 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004609 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004610 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004611 qdf_ret_status =
4612 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004613 hdd_debug("Send disconnected event to userspace");
4614 wlan_hdd_cfg80211_indicate_disconnect(
4615 adapter->dev, true,
4616 WLAN_REASON_UNSPECIFIED);
4617 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004619 qdf_ret_status = sme_roam_disconnect(
4620 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004621 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004622 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004623 /* success implies disconnect command got
4624 * queued up successfully
4625 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004626 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4627 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004628 rc = wait_for_completion_timeout(
4629 &adapter->disconnect_comp_var,
4630 msecs_to_jiffies
4631 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004632 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004633 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004634 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004635 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4636 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004637 memset(&wrqu, '\0', sizeof(wrqu));
4638 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4639 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4640 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4641 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304642 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004643 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004644
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304645 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304646 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004647
4648#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004649 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004650#endif
4651
4652 hdd_deregister_tx_flow_control(adapter);
4653
4654#ifdef WLAN_NS_OFFLOAD
4655#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004656 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004657#endif
4658#endif
4659
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304660 if (adapter->device_mode == QDF_STA_MODE)
4661 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4662 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004663
4664 if (wlan_hdd_try_disconnect(adapter)) {
4665 hdd_err("Error: Can't disconnect adapter");
4666 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004667 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004668
4669 hdd_vdev_destroy(adapter);
4670
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004671 break;
4672
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004673 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004674 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304675 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304676 sap_config = &adapter->session.ap.sap_config;
4677 if (sap_config)
4678 wlansap_reset_sap_config_add_ie(sap_config,
4679 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304680 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004681 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004682
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004683 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004684 if (QDF_SAP_MODE == adapter->device_mode) {
4685 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4686 cds_flush_delayed_work(
4687 &adapter->acs_pending_work);
4688 clear_bit(ACS_PENDING, &adapter->event_flags);
4689 }
4690 }
Krunal Soni22208392017-09-29 18:10:34 -07004691 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004693 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004694 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004695 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004696 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4697
4698 hdd_deregister_tx_flow_control(adapter);
4699
Kapil Guptac1224bf2017-06-22 21:22:40 +05304700 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004701 mutex_lock(&hdd_ctx->sap_lock);
4702 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304703 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304704 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004705
4706 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004707 status = wlansap_stop_bss(
4708 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004709
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304710 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004711 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304713 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304714 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304715 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304716 qdf_wait_for_event_completion(
4717 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004718 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004719
Anurag Chouhance0dc992016-02-16 18:18:03 +05304720 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004721 hdd_err("failure waiting for wlansap_stop_bss %d",
4722 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004723 }
4724 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004725 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004726 }
4727 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004728 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4729 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004730 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004731
Anurag Chouhanc5548422016-02-24 18:33:27 +05304732 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004733 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004734 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004735 updateIE.ieBufferlength = 0;
4736 updateIE.pAdditionIEBuffer = NULL;
4737 updateIE.append = false;
4738 updateIE.notify = false;
4739 /* Probe bcn reset */
4740 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4741 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304742 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004743 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744 }
4745 /* Assoc resp reset */
4746 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4747 &updateIE,
4748 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304749 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004750 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004751 }
4752 /* Reset WNI_CFG_PROBE_RSP Flags */
4753 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004754 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004755 qdf_mem_free(adapter->session.ap.beacon);
4756 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304757 /*
4758 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4759 */
4760 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4761 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4762
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304763#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004764 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304765#endif
4766
4767#ifdef WLAN_NS_OFFLOAD
4768#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004769 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304770#endif
4771#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08004772
4773 hdd_vdev_destroy(adapter);
4774
Krunal Sonib51eec72017-11-20 21:53:01 -08004775 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004776 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004777 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004778 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004779 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004780 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004781 break;
4782 default:
4783 break;
4784 }
4785
Dustin Brown04348372017-12-14 16:13:39 -08004786 if (adapter->scan_info.default_scan_ies) {
4787 qdf_mem_free(adapter->scan_info.default_scan_ies);
4788 adapter->scan_info.default_scan_ies = NULL;
4789 }
4790
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791 EXIT();
Dustin Brown04348372017-12-14 16:13:39 -08004792
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304793 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004794}
4795
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304796/**
4797 * hdd_deinit_all_adapters - deinit all adapters
4798 * @hdd_ctx: HDD context
4799 * @rtnl_held: True if RTNL lock held
4800 *
4801 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004802void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304803{
Jeff Johnson9d295242017-08-29 14:39:48 -07004804 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304805
4806 ENTER();
4807
Dustin Brown920397d2017-12-13 16:27:50 -08004808 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304809 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304810
4811 EXIT();
4812}
4813
Dustin Browndb2a8be2017-12-20 11:49:56 -08004814QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004815{
Jeff Johnson9d295242017-08-29 14:39:48 -07004816 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004817
4818 ENTER();
4819
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304820 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4821
Dustin Brown920397d2017-12-13 16:27:50 -08004822 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08004823 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004824
4825 EXIT();
4826
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304827 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004828}
4829
Paul Zhang84fa9382017-11-10 21:18:21 +08004830static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4831 struct hdd_adapter *adapter)
4832{
4833 switch (adapter->device_mode) {
4834 case QDF_STA_MODE:
4835 case QDF_P2P_CLIENT_MODE:
4836 case QDF_IBSS_MODE:
4837 case QDF_P2P_DEVICE_MODE:
4838 case QDF_NDI_MODE:
4839 wlan_hdd_scan_abort(adapter);
4840 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4841 if (adapter->device_mode == QDF_STA_MODE)
4842 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4843 adapter->dev);
4844 break;
4845 case QDF_P2P_GO_MODE:
4846 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4847 break;
4848 case QDF_SAP_MODE:
4849 wlan_hdd_undo_acs(adapter);
4850 break;
4851 default:
4852 break;
4853 }
4854}
4855
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004856QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857{
Jeff Johnson9d295242017-08-29 14:39:48 -07004858 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004859 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004860 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004861
4862 ENTER();
4863
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304864 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4865
Dustin Brown920397d2017-12-13 16:27:50 -08004866 hdd_for_each_adapter(hdd_ctx, adapter) {
Yue Mad5b4b9f2017-05-26 16:23:40 -07004867 hdd_notice("Disabling queues for adapter type: %d",
4868 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304869
4870 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004871 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304872 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004873 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304874
Arun Khandavallicc544b32017-01-30 19:52:16 +05304875 if (hdd_ctx->config->sap_internal_restart &&
4876 adapter->device_mode == QDF_SAP_MODE) {
4877 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304878 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304879 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004880 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08004881 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004882 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004883 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4884 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304885 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304886 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004887 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004888 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889
Paul Zhang84fa9382017-11-10 21:18:21 +08004890 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07004891 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004892
4893 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004894 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004895 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004896 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4897 hdd_wmm_adapter_close(adapter);
4898 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4899 }
4900
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304901 if (adapter->device_mode == QDF_STA_MODE)
4902 hdd_clear_fils_connection_info(adapter);
4903
Wu Gao3545e642017-07-14 19:24:41 +08004904 if (adapter->device_mode == QDF_SAP_MODE) {
4905 /*
4906 * If adapter is SAP, set session ID to invalid
4907 * since SAP session will be cleanup during SSR.
4908 */
Wu Gao36717432016-11-21 15:09:48 +08004909 wlansap_set_invalid_session(
4910 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4911
Wu Gao3545e642017-07-14 19:24:41 +08004912 wlansap_cleanup_cac_timer(
4913 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4914 }
4915
Yue Mad5b4b9f2017-05-26 16:23:40 -07004916 /* Delete peers if any for STA and P2P client modes */
4917 if (adapter->device_mode == QDF_STA_MODE ||
4918 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004919 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004920 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004921 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004922
4923 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4924 peerMacAddr.bytes);
4925 }
4926
Yue Maf9782842017-05-08 12:49:49 -07004927 /* Destroy vdev which will be recreated during reinit. */
4928 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004929 }
4930
4931 EXIT();
4932
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304933 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004934}
4935
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004936bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304937{
Dustin Brown920397d2017-12-13 16:27:50 -08004938 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304939 bool close_modules = true;
4940
Arun Khandavalliba479c42017-07-26 21:29:40 +05304941 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4942 hdd_info("FTM mode, don't close the module");
4943 return false;
4944 }
4945
Dustin Brown920397d2017-12-13 16:27:50 -08004946 hdd_for_each_adapter(hdd_ctx, adapter) {
4947 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
4948 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004949 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304950 close_modules = false;
4951 break;
4952 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304953 }
4954
4955 return close_modules;
4956}
4957
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304958bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304959{
4960 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4961 return true;
4962 else
4963 return false;
4964}
4965
Anurag Chouhanc4092922016-09-08 15:56:11 +05304966#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004967 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304968struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4969 struct ieee80211_channel *channel,
4970 const u8 *bssid, const u8 *ssid,
4971 size_t ssid_len)
4972{
4973 return cfg80211_get_bss(wiphy, channel, bssid,
4974 ssid, ssid_len,
4975 WLAN_CAPABILITY_ESS,
4976 WLAN_CAPABILITY_ESS);
4977}
4978#else
4979struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4980 struct ieee80211_channel *channel,
4981 const u8 *bssid, const u8 *ssid,
4982 size_t ssid_len)
4983{
4984 return cfg80211_get_bss(wiphy, channel, bssid,
4985 ssid, ssid_len,
4986 IEEE80211_BSS_TYPE_ESS,
4987 IEEE80211_PRIVACY_ANY);
4988}
4989#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304990
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304991#if defined CFG80211_CONNECT_BSS || \
4992 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304993#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304994 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304995/**
4996 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4997 * @timeout_reason: reason for connect timeout
4998 *
4999 * This function is used to convert host timeout
5000 * reason enum to kernel specific enum.
5001 *
5002 * Return: nl timeout enum
5003 */
5004static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5005 tSirResultCodes timeout_reason)
5006{
5007 switch (timeout_reason) {
5008 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5009 return NL80211_TIMEOUT_SCAN;
5010 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5011 return NL80211_TIMEOUT_AUTH;
5012 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5013 return NL80211_TIMEOUT_ASSOC;
5014 default:
5015 return NL80211_TIMEOUT_UNSPECIFIED;
5016 }
5017}
5018
5019/**
5020 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5021 * @dev: network device
5022 * @bssid: bssid to which we want to associate
5023 * @timeout_reason: reason for connect timeout
5024 *
5025 * This API is used to send connection timeout reason to supplicant
5026 *
5027 * Return: void
5028 */
5029static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5030 const u8 *bssid,
5031 tSirResultCodes timeout_reason)
5032{
5033 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005034
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305035 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5036
5037 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5038 nl_timeout_reason);
5039}
5040
5041/**
5042 * __hdd_connect_bss() - API to send connection status to supplicant
5043 * @dev: network device
5044 * @bssid: bssid to which we want to associate
5045 * @req_ie: Request Information Element
5046 * @req_ie_len: len of the req IE
5047 * @resp_ie: Response IE
5048 * @resp_ie_len: len of ht response IE
5049 * @status: status
5050 * @gfp: Kernel Flag
5051 * @timeout_reason: reason for connect timeout
5052 *
5053 * Return: void
5054 */
5055static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5056 struct cfg80211_bss *bss, const u8 *req_ie,
5057 size_t req_ie_len, const u8 *resp_ie,
5058 size_t resp_ie_len, int status, gfp_t gfp,
5059 tSirResultCodes timeout_reason)
5060{
5061 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005062
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305063 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5064
5065 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5066 resp_ie, resp_ie_len, status, gfp,
5067 nl_timeout_reason);
5068}
5069#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305070#if defined CFG80211_CONNECT_TIMEOUT || \
5071 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305072static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5073 const u8 *bssid,
5074 tSirResultCodes timeout_reason)
5075{
5076 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5077}
5078#endif
5079
5080static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5081 struct cfg80211_bss *bss, const u8 *req_ie,
5082 size_t req_ie_len, const u8 *resp_ie,
5083 size_t resp_ie_len, int status, gfp_t gfp,
5084 tSirResultCodes timeout_reason)
5085{
5086 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5087 resp_ie, resp_ie_len, status, gfp);
5088}
5089#endif
5090
Abhishek Singha84d3952016-09-13 13:45:05 +05305091/**
5092 * hdd_connect_bss() - API to send connection status to supplicant
5093 * @dev: network device
5094 * @bssid: bssid to which we want to associate
5095 * @req_ie: Request Information Element
5096 * @req_ie_len: len of the req IE
5097 * @resp_ie: Response IE
5098 * @resp_ie_len: len of ht response IE
5099 * @status: status
5100 * @gfp: Kernel Flag
5101 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305102 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305103 *
5104 * The API is a wrapper to send connection status to supplicant
5105 *
5106 * Return: Void
5107 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305108#if defined CFG80211_CONNECT_TIMEOUT || \
5109 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305110static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5111 struct cfg80211_bss *bss, const u8 *req_ie,
5112 size_t req_ie_len, const u8 *resp_ie,
5113 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305114 bool connect_timeout,
5115 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305116{
5117 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305118 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305119 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305120 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5121 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305122}
5123#else
5124static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5125 struct cfg80211_bss *bss, const u8 *req_ie,
5126 size_t req_ie_len, const u8 *resp_ie,
5127 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305128 bool connect_timeout,
5129 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305130{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305131 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5132 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305133}
5134#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305135
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305136#if defined(WLAN_FEATURE_FILS_SK)
5137#if defined(CFG80211_CONNECT_DONE) || \
5138 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5139#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5140 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305141/**
5142 * hdd_populate_fils_params() - Populate FILS keys to connect response
5143 * @fils_params: connect response to supplicant
5144 * @fils_kek: FILS kek
5145 * @fils_kek_len: FILS kek length
5146 * @pmk: FILS PMK
5147 * @pmk_len: FILS PMK length
5148 * @pmkid: PMKID
5149 * @fils_seq_num: FILS Seq number
5150 *
5151 * Return: None
5152 */
5153static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5154 *fils_params, const uint8_t *fils_kek,
5155 size_t fils_kek_len, const uint8_t *pmk,
5156 size_t pmk_len, const uint8_t *pmkid,
5157 uint16_t fils_seq_num)
5158{
5159 /* Increament seq number to be used for next FILS */
5160 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5161 fils_params->update_erp_next_seq_num = true;
5162 fils_params->fils_kek = fils_kek;
5163 fils_params->fils_kek_len = fils_kek_len;
5164 fils_params->pmk = pmk;
5165 fils_params->pmk_len = pmk_len;
5166 fils_params->pmkid = pmkid;
5167}
5168#else
5169static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5170 *fils_params, const uint8_t
5171 *fils_kek, size_t fils_kek_len,
5172 const uint8_t *pmk, size_t pmk_len,
5173 const uint8_t *pmkid,
5174 uint16_t fils_seq_num)
5175{ }
5176#endif
5177
Jeff Johnson172237b2017-11-07 15:32:59 -08005178void hdd_update_hlp_info(struct net_device *dev,
5179 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305180{
5181 struct sk_buff *skb;
5182 uint16_t skb_len;
5183 struct llc_snap_hdr_t *llc_hdr;
5184 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305185 uint8_t *hlp_data;
5186 uint16_t hlp_data_len;
5187 struct fils_join_rsp_params *roam_fils_params
5188 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305189 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5190
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305191 if (!roam_fils_params) {
5192 hdd_err("FILS Roam Param NULL");
5193 return;
5194 }
5195
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005196 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305197 hdd_err("FILS HLP Data NULL, len %d",
5198 roam_fils_params->hlp_data_len);
5199 return;
5200 }
5201
5202 hlp_data = roam_fils_params->hlp_data;
5203 hlp_data_len = roam_fils_params->hlp_data_len;
5204
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305205 /* Calculate skb length */
5206 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5207 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5208 if (skb == NULL) {
5209 hdd_err("HLP packet nbuf alloc fails");
5210 return;
5211 }
5212
5213 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5214 QDF_MAC_ADDR_SIZE);
5215 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5216 QDF_MAC_ADDR_SIZE);
5217
5218 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5219 if (IS_SNAP(llc_hdr)) {
5220 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5221 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5222 }
5223
5224 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5225
5226 /*
5227 * This HLP packet is formed from HLP info encapsulated
5228 * in assoc response frame which is AEAD encrypted.
5229 * Hence, this checksum validation can be set unnecessary.
5230 * i.e. network layer need not worry about checksum.
5231 */
5232 skb->ip_summed = CHECKSUM_UNNECESSARY;
5233
5234 status = hdd_rx_packet_cbk(padapter, skb);
5235 if (QDF_IS_STATUS_ERROR(status)) {
5236 hdd_err("Sending HLP packet fails");
5237 return;
5238 }
5239 hdd_debug("send HLP packet to netif successfully");
5240}
5241
5242/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305243 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5244 * @dev: network device
5245 * @bssid: bssid to which we want to associate
5246 * @bss: cfg80211 bss info
5247 * @roam_info: information about connected bss
5248 * @req_ie: Request Information Element
5249 * @req_ie_len: len of the req IE
5250 * @resp_ie: Response IE
5251 * @resp_ie_len: len of ht response IE
5252 * @status: status
5253 * @gfp: allocation flags
5254 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5255 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305256 *
5257 * This API is used as wrapper to send FILS key/sequence number
5258 * params etc. to supplicant in case of FILS connection
5259 *
5260 * Return: None
5261 */
5262static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005263 struct cfg80211_bss *bss,
5264 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305265 const u8 *req_ie, size_t req_ie_len,
5266 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005267 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305268 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305269{
5270 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305271 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5272 struct fils_join_rsp_params *roam_fils_params =
5273 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005274
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305275 qdf_mem_zero(&fils_params, sizeof(fils_params));
5276
5277 if (!roam_fils_params) {
5278 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5279 } else {
5280 fils_params.status = status;
5281 fils_params.bssid = bssid;
5282 fils_params.timeout_reason = timeout_reason;
5283 fils_params.req_ie = req_ie;
5284 fils_params.req_ie_len = req_ie_len;
5285 fils_params.resp_ie = resp_ie;
5286 fils_params.resp_ie_len = resp_ie_len;
5287 fils_params.bss = bss;
5288 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5289 roam_fils_params->kek_len,
5290 roam_fils_params->fils_pmk,
5291 roam_fils_params->fils_pmk_len,
5292 roam_fils_params->fils_pmkid,
5293 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305294 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305295 }
5296 hdd_debug("FILS indicate connect status %d seq no %d",
5297 fils_params.status,
5298 fils_params.fils_erp_next_seq_num);
5299
5300 cfg80211_connect_done(dev, &fils_params, gfp);
5301
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305302 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305303 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305304
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305305 /* Clear all the FILS key info */
5306 if (roam_fils_params && roam_fils_params->fils_pmk)
5307 qdf_mem_free(roam_fils_params->fils_pmk);
5308 if (roam_fils_params)
5309 qdf_mem_free(roam_fils_params);
5310 roam_info->fils_join_rsp = NULL;
5311}
5312#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005313static inline void
5314hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005315 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005316 const u8 *req_ie, size_t req_ie_len,
5317 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5318 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305319 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305320{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305321#endif
5322#endif
5323
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305324#if defined(WLAN_FEATURE_FILS_SK) && \
5325 (defined(CFG80211_CONNECT_DONE) || \
5326 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305327/**
5328 * hdd_fils_update_connect_results() - API to send fils connection status to
5329 * supplicant.
5330 * @dev: network device
5331 * @bssid: bssid to which we want to associate
5332 * @bss: cfg80211 bss info
5333 * @roam_info: information about connected bss
5334 * @req_ie: Request Information Element
5335 * @req_ie_len: len of the req IE
5336 * @resp_ie: Response IE
5337 * @resp_ie_len: len of ht response IE
5338 * @status: status
5339 * @gfp: allocation flags
5340 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5341 * @timeout_reason: reason for connect timeout
5342 *
5343 * The API is a wrapper to send connection status to supplicant
5344 *
5345 * Return: 0 if success else failure
5346 */
5347static int hdd_fils_update_connect_results(struct net_device *dev,
5348 const u8 *bssid,
5349 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005350 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305351 size_t req_ie_len, const u8 *resp_ie,
5352 size_t resp_ie_len, u16 status, gfp_t gfp,
5353 bool connect_timeout,
5354 tSirResultCodes timeout_reason)
5355{
5356 ENTER();
5357 if (!roam_info || !roam_info->is_fils_connection)
5358 return -EINVAL;
5359
5360 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5361 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305362 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305363 return 0;
5364}
5365#else
5366static inline int hdd_fils_update_connect_results(struct net_device *dev,
5367 const u8 *bssid,
5368 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005369 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305370 size_t req_ie_len, const u8 *resp_ie,
5371 size_t resp_ie_len, u16 status, gfp_t gfp,
5372 bool connect_timeout,
5373 tSirResultCodes timeout_reason)
5374{
5375 return -EINVAL;
5376}
5377#endif
5378
Anurag Chouhanc4092922016-09-08 15:56:11 +05305379/**
5380 * hdd_connect_result() - API to send connection status to supplicant
5381 * @dev: network device
5382 * @bssid: bssid to which we want to associate
5383 * @roam_info: information about connected bss
5384 * @req_ie: Request Information Element
5385 * @req_ie_len: len of the req IE
5386 * @resp_ie: Response IE
5387 * @resp_ie_len: len of ht response IE
5388 * @status: status
5389 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305390 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305391 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305392 *
5393 * The API is a wrapper to send connection status to supplicant
5394 * and allow runtime suspend
5395 *
5396 * Return: Void
5397 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305398void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005399 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305400 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305401 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305402 bool connect_timeout,
5403 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305404{
Jeff Johnson9d295242017-08-29 14:39:48 -07005405 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305406 struct cfg80211_bss *bss = NULL;
5407
5408 if (WLAN_STATUS_SUCCESS == status) {
5409 struct ieee80211_channel *chan;
5410 int freq;
5411 int chan_no = roam_info->pBssDesc->channelId;
5412
5413 if (chan_no <= 14)
5414 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005415 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305416 else
5417 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005418 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305419
5420 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5421 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5422 roam_info->u.pConnectedProfile->SSID.ssId,
5423 roam_info->u.pConnectedProfile->SSID.length);
5424 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305425
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305426 if (hdd_fils_update_connect_results(dev, bssid, bss,
5427 roam_info, req_ie, req_ie_len, resp_ie,
5428 resp_ie_len, status, gfp, connect_timeout,
5429 timeout_reason) != 0) {
5430 hdd_connect_bss(dev, bssid, bss, req_ie,
5431 req_ie_len, resp_ie, resp_ie_len,
5432 status, gfp, connect_timeout, timeout_reason);
5433 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305434
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005435 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005436 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305437}
5438#else
5439void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005440 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305441 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305442 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305443 bool connect_timeout,
5444 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305445{
Jeff Johnson9d295242017-08-29 14:39:48 -07005446 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305447
Anurag Chouhanc4092922016-09-08 15:56:11 +05305448 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5449 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005450
5451 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005452 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305453}
5454#endif
5455
5456
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005457QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005458{
Jeff Johnson9d295242017-08-29 14:39:48 -07005459 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005460#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305461 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005462#endif
5463 eConnectionState connState;
5464
5465 ENTER();
5466
Dustin Brown920397d2017-12-13 16:27:50 -08005467 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305468 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005469 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305470
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005471 hdd_wmm_init(adapter);
5472
5473 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005474 case QDF_STA_MODE:
5475 case QDF_P2P_CLIENT_MODE:
5476 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005477
5478 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5479 ->conn_info.connState;
5480
Krunal Sonib51eec72017-11-20 21:53:01 -08005481 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005482 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005483 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005484
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005485 /* Indicate disconnect event to supplicant
5486 * if associated previously
5487 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005488 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005489 eConnectionState_IbssConnected == connState ||
5490 eConnectionState_NotConnected == connState ||
5491 eConnectionState_IbssDisconnected == connState ||
5492 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005493 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005494
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005495 memset(&wrqu, '\0', sizeof(wrqu));
5496 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5497 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5498 wireless_send_event(adapter->dev, SIOCGIWAP,
5499 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005500 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005501 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005502
5503 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305504 wlan_hdd_cfg80211_indicate_disconnect(
5505 adapter->dev, false,
5506 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005507 } else if (eConnectionState_Connecting == connState) {
5508 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005509 * Indicate connect failure to supplicant if we
5510 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005511 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305512 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305513 NULL, 0, NULL, 0,
5514 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005515 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005516 }
5517
5518 hdd_register_tx_flow_control(adapter,
5519 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005520 hdd_tx_resume_cb,
5521 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005522
5523 break;
5524
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005525 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005526 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005527 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305528
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005529 break;
5530
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005531 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005532#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005533 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005534 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5535#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005536 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005537 /* event supplicant to restart */
5538 cfg80211_del_sta(adapter->dev,
5539 (const u8 *)&bcastMac.bytes[0],
5540 GFP_KERNEL);
5541#endif
5542 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305543 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005544 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305545 hdd_set_mon_rx_cb(adapter->dev);
5546 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5547 adapter->mon_bandwidth);
5548 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005549 default:
5550 break;
5551 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005552 /*
5553 * Action frame registered in one adapter which will
5554 * applicable to all interfaces
5555 */
5556 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005557 }
5558
5559 EXIT();
5560
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305561 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562}
5563
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005564QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005565 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005566{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305567 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005568 qdf_list_node_t *node;
5569
5570 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005571
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005572 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005573 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005574 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005575
5576 if (QDF_IS_STATUS_ERROR(status))
5577 return status;
5578
5579 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5580
5581 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005582}
5583
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005584QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005585 struct hdd_adapter *current_adapter,
5586 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305588 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005589 qdf_list_node_t *node;
5590
5591 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005592
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005593 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005594 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005595 &current_adapter->node,
5596 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005597 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005598
5599 if (QDF_IS_STATUS_ERROR(status))
5600 return status;
5601
5602 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5603
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005604 return status;
5605}
5606
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005607QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005608 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005609{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305610 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005611
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005612 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005613 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005614 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005615
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005616 return status;
5617}
5618
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005619QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005620 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005621{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305622 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005623 qdf_list_node_t *node;
5624
5625 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005626
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005627 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005628 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005629 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005630
5631 if (QDF_IS_STATUS_ERROR(status))
5632 return status;
5633
5634 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5635
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005636 return status;
5637}
5638
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005639QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005640 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005641{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305642 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005643
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005644 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005645 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005646 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005647
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005648 return status;
5649}
5650
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005651QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005652 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005653{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305654 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005655
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005656 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005657 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005658 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660 return status;
5661}
5662
Jeff Johnson9d295242017-08-29 14:39:48 -07005663struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005664 tSirMacAddr macAddr)
5665{
Jeff Johnson9d295242017-08-29 14:39:48 -07005666 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005667
Dustin Brown920397d2017-12-13 16:27:50 -08005668 hdd_for_each_adapter(hdd_ctx, adapter) {
5669 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5670 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005672 }
5673
5674 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005675}
5676
Jeff Johnson9d295242017-08-29 14:39:48 -07005677struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005678 uint32_t vdev_id)
5679{
Jeff Johnson9d295242017-08-29 14:39:48 -07005680 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681
Dustin Brown920397d2017-12-13 16:27:50 -08005682 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005683 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005684 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005685 }
5686
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -08005687 hdd_err_ratelimited(RATE_LIMIT_ERROR_LOG,
5688 "vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689
5690 return NULL;
5691}
5692
Abhishek Singh7996eb72015-12-30 17:24:02 +05305693/**
5694 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5695 * the sessionid
5696 * @hdd_ctx: hdd context.
5697 * @sme_session_id: sme session is for the adapter to get.
5698 *
5699 * This function is used to get the adapter with provided session id
5700 *
5701 * Return: adapter pointer if found
5702 *
5703 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005704struct hdd_adapter *
5705hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5706 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305707{
Jeff Johnson9d295242017-08-29 14:39:48 -07005708 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305709
Dustin Brown920397d2017-12-13 16:27:50 -08005710 hdd_for_each_adapter(hdd_ctx, adapter) {
5711 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305712 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305713 }
Dustin Brown920397d2017-12-13 16:27:50 -08005714
Abhishek Singh7996eb72015-12-30 17:24:02 +05305715 return NULL;
5716}
5717
Jeff Johnson9d295242017-08-29 14:39:48 -07005718struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005719 const char *iface_name)
5720{
Jeff Johnson9d295242017-08-29 14:39:48 -07005721 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005722
Dustin Brown920397d2017-12-13 16:27:50 -08005723 hdd_for_each_adapter(hdd_ctx, adapter) {
5724 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07005725 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005726 }
Dustin Brown920397d2017-12-13 16:27:50 -08005727
Naveen Rawat4edb6822017-04-12 10:09:17 -07005728 return NULL;
5729}
5730
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005731/**
5732 * hdd_get_adapter() - to get adapter matching the mode
5733 * @hdd_ctx: hdd context
5734 * @mode: adapter mode
5735 *
5736 * This routine will return the pointer to adapter matching
5737 * with the passed mode.
5738 *
5739 * Return: pointer to adapter or null
5740 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005741struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005742 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005743{
Jeff Johnson9d295242017-08-29 14:39:48 -07005744 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005745
Dustin Brown920397d2017-12-13 16:27:50 -08005746 hdd_for_each_adapter(hdd_ctx, adapter) {
5747 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005748 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005749 }
5750
5751 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005752}
5753
5754/**
5755 * hdd_get_operating_channel() - return operating channel of the device mode
5756 * @hdd_ctx: Pointer to the HDD context.
5757 * @mode: Device mode for which operating channel is required.
5758 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005759 * QDF_STA_MODE,
5760 * QDF_P2P_CLIENT_MODE,
5761 * QDF_SAP_MODE,
5762 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005763 *
5764 * This API returns the operating channel of the requested device mode
5765 *
5766 * Return: channel number. "0" id the requested device is not found OR it is
5767 * not connected.
5768 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005769uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005770 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005771{
Jeff Johnson9d295242017-08-29 14:39:48 -07005772 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005773 uint8_t operatingChannel = 0;
5774
Dustin Brown920397d2017-12-13 16:27:50 -08005775 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005776 if (mode == adapter->device_mode) {
5777 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005778 case QDF_STA_MODE:
5779 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005780 if (hdd_conn_is_connected
5781 (WLAN_HDD_GET_STATION_CTX_PTR
5782 (adapter))) {
5783 operatingChannel =
5784 (WLAN_HDD_GET_STATION_CTX_PTR
5785 (adapter))->conn_info.
5786 operationChannel;
5787 }
5788 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005789 case QDF_SAP_MODE:
5790 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005791 /* softap connection info */
5792 if (test_bit
5793 (SOFTAP_BSS_STARTED,
5794 &adapter->event_flags))
5795 operatingChannel =
5796 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005797 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005798 break;
5799 default:
5800 break;
5801 }
5802
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005803 /* Found the device of interest. break the loop */
5804 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005806 }
Dustin Brown920397d2017-12-13 16:27:50 -08005807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005808 return operatingChannel;
5809}
5810
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005811static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005812 hdd_ctx)
5813{
Jeff Johnson9d295242017-08-29 14:39:48 -07005814 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005815
5816 ENTER();
5817
Dustin Brown920397d2017-12-13 16:27:50 -08005818 hdd_for_each_adapter(hdd_ctx, adapter) {
5819 if (adapter->device_mode == QDF_STA_MODE ||
5820 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5821 adapter->device_mode == QDF_IBSS_MODE ||
5822 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5823 adapter->device_mode == QDF_SAP_MODE ||
5824 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005825 wlan_hdd_cfg80211_deregister_frames(adapter);
5826 hdd_unregister_wext(adapter->dev);
5827 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005828 }
5829
5830 EXIT();
5831
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305832 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005833}
5834
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005835QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005836{
Jeff Johnson9d295242017-08-29 14:39:48 -07005837 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005838
5839 ENTER();
5840
Dustin Brown920397d2017-12-13 16:27:50 -08005841 hdd_for_each_adapter(hdd_ctx, adapter) {
5842 if (adapter->device_mode == QDF_STA_MODE ||
5843 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5844 adapter->device_mode == QDF_IBSS_MODE ||
5845 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5846 adapter->device_mode == QDF_SAP_MODE ||
5847 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005848 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005849 adapter->session_id, INVALID_SCAN_ID,
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005850 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005851 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005852 }
5853
5854 EXIT();
5855
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305856 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005857}
5858
Dustin Brownf27bce82016-11-03 12:52:27 -07005859/**
5860 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5861 * adapters
5862 * @hdd_ctx: The HDD context containing the adapters to operate on
5863 *
5864 * return: QDF_STATUS_SUCCESS
5865 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005866static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005867{
Jeff Johnson9d295242017-08-29 14:39:48 -07005868 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005869 int err;
5870
5871 ENTER();
5872
Dustin Brown920397d2017-12-13 16:27:50 -08005873 hdd_for_each_adapter(hdd_ctx, adapter) {
5874 if (adapter->device_mode == QDF_STA_MODE ||
5875 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5876 adapter->device_mode == QDF_IBSS_MODE ||
5877 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5878 adapter->device_mode == QDF_SAP_MODE ||
5879 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07005880 err = wlan_hdd_sched_scan_stop(adapter->dev);
5881 if (err)
5882 hdd_err("Unable to stop scheduled scan");
5883 }
Dustin Brownf27bce82016-11-03 12:52:27 -07005884 }
5885
5886 EXIT();
5887
5888 return QDF_STATUS_SUCCESS;
5889}
5890
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005891#ifdef WLAN_NS_OFFLOAD
5892/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005893 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005894 * @hdd_ctx: Pointer to hdd context
5895 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005896 * Unregister for IPv6 address change notifications.
5897 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898 * Return: None
5899 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005900static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005901{
5902 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005903}
5904
5905/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005906 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005907 * @hdd_ctx: Pointer to hdd context
5908 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005909 * Register for IPv6 address change notifications.
5910 *
5911 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005912 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005913static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005914{
5915 int ret;
5916
5917 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5918 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005919 if (ret) {
5920 hdd_err("Failed to register IPv6 notifier: %d", ret);
5921 goto out;
5922 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005923
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005924 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005925out:
5926 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005927}
5928#else
5929/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005930 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005931 * @hdd_ctx: Pointer to hdd context
5932 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005933 * Unregister for IPv6 address change notifications.
5934 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005935 * Return: None
5936 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005937static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005938{
5939}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005940
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005941/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005942 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005943 * @hdd_ctx: Pointer to hdd context
5944 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005945 * Register for IPv6 address change notifications.
5946 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005947 * Return: None
5948 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005949static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005950{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005951 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005952}
5953#endif
5954
5955/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005956 * hdd_register_notifiers - Register netdev notifiers.
5957 * @hdd_ctx: HDD context
5958 *
5959 * Register netdev notifiers like IPv4 and IPv6.
5960 *
5961 * Return: 0 on success and errno on failure
5962 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005963static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005964{
5965 int ret;
5966
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005967 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5968 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305969 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005970
5971 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5972 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5973 if (ret) {
5974 hdd_err("Failed to register IPv4 notifier: %d", ret);
5975 goto unregister_ip6_notifier;
5976 }
5977
5978 return 0;
5979
5980unregister_ip6_notifier:
5981 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005982out:
5983 return ret;
5984
5985}
5986
5987/**
5988 * hdd_unregister_notifiers - Unregister netdev notifiers.
5989 * @hdd_ctx: HDD context
5990 *
5991 * Unregister netdev notifiers like IPv4 and IPv6.
5992 *
5993 * Return: None.
5994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005995void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005996{
5997 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5998
5999 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006000}
6001
6002/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006003 * hdd_exit_netlink_services - Exit netlink services
6004 * @hdd_ctx: HDD context
6005 *
6006 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6007 * nl service.
6008 *
6009 * Return: None.
6010 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006011static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006012{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006013 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006014 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006015 ptt_sock_deactivate_svc();
6016
6017 nl_srv_exit();
6018}
6019
6020/**
6021 * hdd_init_netlink_services- Init netlink services
6022 * @hdd_ctx: HDD context
6023 *
6024 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6025 * nl service.
6026 *
6027 * Return: 0 on success and errno on failure.
6028 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006029static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006030{
6031 int ret;
6032
Ryan Hsuceddceb2016-04-28 10:20:14 -07006033 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006034 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006035 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006036 goto out;
6037 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006038 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006039
Naveen Rawat910726a2017-03-06 11:42:51 -08006040 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006041 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006042 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006043 goto err_nl_srv;
6044 }
6045
6046 ret = ptt_sock_activate_svc();
6047 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006048 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006049 goto err_nl_srv;
6050 }
6051
6052 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006053 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006054 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006055
6056 ret = cnss_diag_activate_service();
6057 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006058 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006059 goto err_close_cesium;
6060 }
6061
6062 return 0;
6063
6064err_close_cesium:
6065 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006066 ptt_sock_deactivate_svc();
6067err_nl_srv:
6068 nl_srv_exit();
6069out:
6070 return ret;
6071}
6072
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006073/**
6074 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6075 * @hdd_ctx: HDD context.
6076 *
6077 * Destroy RX wakelock.
6078 *
6079 * Return: None.
6080 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006081static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006082{
6083 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6084}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006085
6086/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006087 * hdd_rx_wake_lock_create() - Create RX wakelock
6088 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006089 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006090 * Create RX wakelock.
6091 *
6092 * Return: None.
6093 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006094static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006095{
6096 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6097}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006098
6099/**
Houston Hoffman160db392016-10-10 17:37:51 -07006100 * hdd_context_deinit() - Deinitialize HDD context
6101 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006102 *
Houston Hoffman160db392016-10-10 17:37:51 -07006103 * Deinitialize HDD context along with all the feature specific contexts but
6104 * do not free hdd context itself. Caller of this API is supposed to free
6105 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006106 *
Houston Hoffman160db392016-10-10 17:37:51 -07006107 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006108 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006109static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006110{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306111 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6112
Houston Hoffman160db392016-10-10 17:37:51 -07006113 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006114
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006115 hdd_sap_context_destroy(hdd_ctx);
6116
6117 hdd_rx_wake_lock_destroy(hdd_ctx);
6118
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006119 hdd_scan_context_destroy(hdd_ctx);
6120
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006121 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006122
Houston Hoffman160db392016-10-10 17:37:51 -07006123 return 0;
6124}
6125
6126/**
6127 * hdd_context_destroy() - Destroy HDD context
6128 * @hdd_ctx: HDD context to be destroyed.
6129 *
6130 * Free config and HDD context as well as destroy all the resources.
6131 *
6132 * Return: None
6133 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006134static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006135{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006136 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306137
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306138 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6139
Houston Hoffman160db392016-10-10 17:37:51 -07006140 hdd_context_deinit(hdd_ctx);
6141
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306142 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006143 hdd_ctx->config = NULL;
6144
6145 wiphy_free(hdd_ctx->wiphy);
6146}
6147
6148/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306149 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6150 *
6151 * This function is used to destroy bug report lock
6152 *
6153 * Return: None
6154 */
6155static void wlan_destroy_bug_report_lock(void)
6156{
6157 p_cds_contextType p_cds_context;
6158
6159 p_cds_context = cds_get_global_context();
6160 if (!p_cds_context) {
6161 hdd_err("cds context is NULL");
6162 return;
6163 }
6164
6165 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6166}
6167
6168/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006169 * hdd_wlan_exit() - HDD WLAN exit function
6170 * @hdd_ctx: Pointer to the HDD Context
6171 *
6172 * This is the driver exit point (invoked during rmmod)
6173 *
6174 * Return: None
6175 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006176static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006177{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006178 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306179 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006180
6181 ENTER();
6182
Dustin Brown6f427922017-09-19 12:19:00 -07006183 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306184
6185 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006186
Prashanth Bhattaab004382016-10-11 16:08:11 -07006187 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006188
6189#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306190 if (QDF_TIMER_STATE_RUNNING ==
6191 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6192 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006193 }
6194
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306195 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306196 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006197 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006198 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006199 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6200 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6201 hdd_ctx->last_acs_channel_list = NULL;
6202 hdd_ctx->num_of_channels = 0;
6203 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006205
Arun Khandavallifae92942016-08-01 13:31:08 +05306206 mutex_lock(&hdd_ctx->iface_change_lock);
6207 driver_status = hdd_ctx->driver_status;
6208 mutex_unlock(&hdd_ctx->iface_change_lock);
6209
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006210 /*
6211 * Powersave Offload Case
6212 * Disable Idle Power Save Mode
6213 */
6214 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006215 /* clear the scan queue in all the scenarios */
6216 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006217
Arun Khandavallifae92942016-08-01 13:31:08 +05306218 if (driver_status != DRIVER_MODULES_CLOSED) {
6219 hdd_unregister_wext_all_adapters(hdd_ctx);
6220 /*
6221 * Cancel any outstanding scan requests. We are about to close
6222 * all of our adapters, but an adapter structure is what SME
6223 * passes back to our callback function. Hence if there
6224 * are any outstanding scan requests then there is a
6225 * race condition between when the adapter is closed and
6226 * when the callback is invoked. We try to resolve that
6227 * race condition here by canceling any outstanding scans
6228 * before we close the adapters.
6229 * Note that the scans may be cancelled in an asynchronous
6230 * manner, so ideally there needs to be some kind of
6231 * synchronization. Rather than introduce a new
6232 * synchronization here, we will utilize the fact that we are
6233 * about to Request Full Power, and since that is synchronized,
6234 * the expectation is that by the time Request Full Power has
6235 * completed, all scans will be cancelled
6236 */
6237 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006238 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006239 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006240 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241 }
6242
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306243 unregister_netdevice_notifier(&hdd_netdev_notifier);
6244
Dustin Brown36e24e22017-12-21 12:34:13 -08006245 hdd_close_all_adapters(hdd_ctx, false);
6246
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006247 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306248
Dustin Brown021cecd2017-12-11 13:56:43 -08006249 hdd_driver_memdump_deinit();
6250
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306251 qdf_nbuf_deinit_replenish_timer();
6252
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306253 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6254 hdd_info("Release wakelock for monitor mode!");
6255 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6256 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6257 }
6258
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306259 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6260 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6261 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006263 /*
6264 * Close CDS
6265 * This frees pMac(HAL) context. There should not be any call
6266 * that requires pMac access after this.
6267 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006268
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006269 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006270 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006271
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006272 hdd_ipa_cleanup(hdd_ctx);
6273
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306274 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306275 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306276 /*
6277 * If there is re_init failure wiphy would have already de-registered
6278 * check the wiphy status before un-registering again
6279 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306280 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306281 wiphy_unregister(wiphy);
6282 wlan_hdd_cfg80211_deinit(wiphy);
6283 hdd_lpass_notify_stop(hdd_ctx);
6284 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006285
Arun Khandavallifae92942016-08-01 13:31:08 +05306286 hdd_exit_netlink_services(hdd_ctx);
6287 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306288#ifdef FEATURE_WLAN_CH_AVOID
6289 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6290#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306291
Abhishek Singhe9068f12017-03-31 14:14:52 +05306292 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6293 if (driver_status)
6294 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006295
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006296 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006297}
6298
6299void __hdd_wlan_exit(void)
6300{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006301 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006302
6303 ENTER();
6304
Anurag Chouhan6d760662016-02-20 16:05:43 +05306305 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006306 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006307 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006308 EXIT();
6309 return;
6310 }
6311
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006312 /* Do all the cleanup before deregistering the driver */
6313 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006314
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315 EXIT();
6316}
6317
6318#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006319/**
6320 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006321 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006322 *
6323 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6324 * Then new ACS request will do a fresh scan without reusing the cached
6325 * scan information.
6326 *
6327 * Return: void
6328 */
Tang Yingying523322d2017-01-17 23:28:43 +08006329static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006330{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006331 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006332
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006333 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006334 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006335 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6336 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6337 hdd_ctx->last_acs_channel_list = NULL;
6338 hdd_ctx->num_of_channels = 0;
6339 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006340
6341 if (!hdd_ctx->hHal)
6342 return;
6343 sme_scan_flush_result(hdd_ctx->hHal);
6344}
6345#endif
6346
6347#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006348int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6349 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006350{
6351 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306352 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006353 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354
6355 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6356
6357 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306358 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006359 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306360
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006361 if (!hdd_ctx->hHal)
6362 return -EINVAL;
6363
Jeff Johnsone7672e72017-10-21 15:10:04 -07006364 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006365 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306366 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006367 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368 return -EINVAL;
6369 }
6370
6371 return 0;
6372}
6373#endif
6374
6375/**
6376 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6377 * @state: state
6378 *
6379 * This function notifies FW with modem power status
6380 *
6381 * Return: 0 if successful, error number otherwise
6382 */
6383int hdd_wlan_notify_modem_power_state(int state)
6384{
6385 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306386 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006387 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006388
Anurag Chouhan6d760662016-02-20 16:05:43 +05306389 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006390 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306391 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006392 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306393
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006394 if (!hdd_ctx->hHal)
6395 return -EINVAL;
6396
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306397 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6398 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006399 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006400 state);
6401 return -EINVAL;
6402 }
6403 return 0;
6404}
6405
6406/**
6407 *
6408 * hdd_post_cds_enable_config() - HDD post cds start config helper
6409 * @adapter - Pointer to the HDD
6410 *
6411 * Return: None
6412 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006413QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006414{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306415 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006416
6417 /*
6418 * Send ready indication to the HDD. This will kick off the MAC
6419 * into a 'running' state and should kick off an initial scan.
6420 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306421 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6422 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006423 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6424 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306425 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006426 }
6427
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306428 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006429}
6430
6431/* wake lock APIs for HDD */
6432void hdd_prevent_suspend(uint32_t reason)
6433{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306434 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006435}
6436
6437void hdd_allow_suspend(uint32_t reason)
6438{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306439 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006440}
6441
6442void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6443{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306444 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6445 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006446}
6447
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006448/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006449QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006451
Amar Singhal6f8592b2017-04-26 14:31:58 -07006452 return sme_init_chan_list(hdd_ctx->hHal,
6453 hdd_ctx->reg.alpha2,
6454 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006455}
6456
6457/**
6458 * hdd_is_5g_supported() - check if hardware supports 5GHz
6459 * @hdd_ctx: Pointer to the hdd context
6460 *
6461 * HDD function to know if hardware supports 5GHz
6462 *
6463 * Return: true if hardware supports 5GHz
6464 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006465bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006466{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006467 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006468 return true;
6469
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006470 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006471 return true;
6472 else
6473 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006474}
6475
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006476static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006477{
6478 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006479 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480
6481 wiphy = hdd_ctx->wiphy;
6482
6483 /*
6484 * The channel information in
6485 * wiphy needs to be initialized before wiphy registration
6486 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006487 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6488 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006489 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006490 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006491 }
6492
6493#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6494 wiphy->wowlan = &wowlan_support_reg_init;
6495#else
6496 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6497 WIPHY_WOWLAN_MAGIC_PKT |
6498 WIPHY_WOWLAN_DISCONNECT |
6499 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6500 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6501 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6502 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6503 WIPHY_WOWLAN_RFKILL_RELEASE;
6504
6505 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6506 WOW_MAX_FILTERS_PER_LIST);
6507 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6508 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6509#endif
6510
6511 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006512 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306513 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006514 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306515 return ret_val;
6516 }
6517
Amar Singhal5cccafe2017-02-15 12:42:58 -08006518 if (!hdd_ctx->reg_offload)
6519 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006520
Amar Singhale4f28ee2015-10-21 14:36:56 -07006521 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522}
6523
Mohit Khannaca4173b2017-09-12 21:52:19 -07006524#ifdef MSM_PLATFORM
6525/**
6526 * hdd_display_periodic_stats() - Function to display periodic stats
6527 * @hdd_ctx - handle to hdd context
6528 * @bool data_in_interval - true, if data detected in bw time interval
6529 *
6530 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6531 * Stats show up in wlan driver logs.
6532 *
6533 * Returns: None
6534 */
6535static inline
6536void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6537 bool data_in_interval)
6538{
6539 static u32 counter;
6540 static bool data_in_time_period;
6541 ol_txrx_pdev_handle pdev;
6542
6543 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6544 return;
6545
6546 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6547 if (!pdev) {
6548 hdd_err("pdev is NULL");
6549 return;
6550 }
6551
6552 counter++;
6553 if (data_in_interval)
6554 data_in_time_period = data_in_interval;
6555
6556 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6557 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6558 if (data_in_time_period) {
6559 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6560 CDP_TXRX_PATH_STATS,
6561 QDF_STATS_VERBOSITY_LEVEL_LOW);
6562 wlan_hdd_display_netif_queue_history
6563 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6564 qdf_dp_trace_dump_stats();
6565 }
6566 counter = 0;
6567 data_in_time_period = false;
6568 }
6569}
6570
Ravi Joshie2331e82015-07-01 18:18:54 -07006571/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006572 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006573 * @hdd_ctx - handle to hdd context
6574 * @tx_packets - transmit packet count
6575 * @rx_packets - receive packet count
6576 *
6577 * The function controls the bus bandwidth and dynamic control of
6578 * tcp delayed ack configuration
6579 *
6580 * Returns: None
6581 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006582
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006583static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006584 const uint64_t tx_packets,
6585 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006586{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006587 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006588 uint64_t temp_rx = 0;
6589 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006590 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006591 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006592 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006593 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006594 uint16_t index = 0;
6595 bool vote_level_change = false;
6596 bool rx_level_change = false;
6597 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006598
Mohit Khannaca4173b2017-09-12 21:52:19 -07006599 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006600 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006601 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006602 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006603 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006604 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006605 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006606 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006607
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006608 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006609 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6610 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006611 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006612 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006613 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306614 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306615 if (hdd_ctx->hbw_requested) {
6616 pld_remove_pm_qos(hdd_ctx->parent_dev);
6617 hdd_ctx->hbw_requested = false;
6618 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306619 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006620 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006621 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306622 if (!hdd_ctx->hbw_requested) {
6623 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6624 hdd_ctx->hbw_requested = true;
6625 }
6626
Nirav Shah3bbfa512016-05-12 16:43:49 +05306627 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006628 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006629 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006630 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006631 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006632
Mohit Khannaf8f96822017-05-17 17:11:59 -07006633 qdf_dp_trace_throttle_live_mode(
6634 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6635
Mohit Khannae71e2262015-11-10 09:37:24 -08006636 /* fine-tuning parameters for RX Flows */
6637 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006639 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006640
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306641 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6642 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6643 else
6644 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6645
Ravi Joshifed83572016-10-07 16:20:37 -07006646 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6647 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6648 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6649 next_rx_level = WLAN_SVC_TP_HIGH;
6650 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006651 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006652 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006653 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006654 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006655
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006656 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006657 struct wlan_rx_tp_data rx_tp_data = {0};
6658
Ravi Joshie2331e82015-07-01 18:18:54 -07006659 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006660 next_rx_level, temp_rx);
6661 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006662 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006663 /* Send throughput indication only if it is enabled.
6664 * Disabling tcp_del_ack will revert the tcp stack behavior
6665 * to default delayed ack. Note that this will disable the
6666 * dynamic delayed ack mechanism across the system
6667 */
6668 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006669 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6670
Mohit Khanna6272fb682017-04-13 09:34:36 -07006671 if (hdd_ctx->config->enable_tcp_adv_win_scale)
6672 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6673
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006674 rx_tp_data.level = next_rx_level;
6675 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6676 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6677 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006678 }
6679
Mohit Khannae71e2262015-11-10 09:37:24 -08006680 /* fine-tuning parameters for TX Flows */
6681 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6682 hdd_ctx->prev_tx = tx_packets;
6683 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6684 next_tx_level = WLAN_SVC_TP_HIGH;
6685 else
6686 next_tx_level = WLAN_SVC_TP_LOW;
6687
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006688 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006689 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6690 next_tx_level, temp_tx);
6691 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006692 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306693 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6694 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006695 &next_tx_level,
6696 sizeof(next_tx_level));
6697 }
6698
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006699 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006700 if (vote_level_change || tx_level_change || rx_level_change) {
6701 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6702 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6703 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6704 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6705 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6706 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6707 hdd_ctx->hdd_txrx_hist_idx++;
6708 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6709 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07006710
6711 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006712}
6713
6714#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306715static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006716{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006717 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306718 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006719 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306720 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306721 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6722 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006723 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306724 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006725 bool connected = false;
6726 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6727
Prashanth Bhattaab004382016-10-11 16:08:11 -07006728 if (wlan_hdd_validate_context(hdd_ctx))
6729 return;
6730
Jeff Johnson214671b2017-10-30 19:45:23 -07006731 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006732 goto restart_timer;
6733
Dustin Brown920397d2017-12-13 16:27:50 -08006734 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05306735 /*
6736 * Validate magic so we don't end up accessing
6737 * an invalid adapter.
6738 */
6739 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6740 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006741
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006742 if ((adapter->device_mode == QDF_STA_MODE ||
6743 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006744 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6745 != eConnectionState_Associated) {
6746
6747 continue;
6748 }
6749
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006750 if ((adapter->device_mode == QDF_SAP_MODE ||
6751 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006752 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006753
6754 continue;
6755 }
6756
6757 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6758 adapter->prev_tx_packets);
6759 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6760 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306761
6762 if (adapter->device_mode == QDF_SAP_MODE ||
6763 adapter->device_mode == QDF_P2P_GO_MODE ||
6764 adapter->device_mode == QDF_IBSS_MODE) {
6765
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006766 ret = cdp_get_intra_bss_fwd_pkts_count(
6767 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006768 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306769 &fwd_tx_packets, &fwd_rx_packets);
6770 if (ret == A_OK) {
6771 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6772 fwd_tx_packets,
6773 adapter->prev_fwd_tx_packets);
6774 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6775 fwd_tx_packets,
6776 adapter->prev_fwd_rx_packets);
6777 }
6778 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779
6780 total_rx += adapter->stats.rx_packets;
6781 total_tx += adapter->stats.tx_packets;
6782
6783 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6784 adapter->prev_tx_packets = adapter->stats.tx_packets;
6785 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306786 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6787 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6789 connected = true;
6790 }
6791
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306792 /* add intra bss forwarded tx and rx packets */
6793 tx_packets += fwd_tx_packets_diff;
6794 rx_packets += fwd_rx_packets_diff;
6795
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006796 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6797 tx_packets += (uint64_t)ipa_tx_packets;
6798 rx_packets += (uint64_t)ipa_rx_packets;
6799
Yun Park2aa880c2017-08-22 10:58:10 -07006800 if (adapter) {
6801 adapter->stats.tx_packets += ipa_tx_packets;
6802 adapter->stats.rx_packets += ipa_rx_packets;
6803 }
6804
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006805 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006806 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807 return;
6808 }
6809
Yuanyuan Liu13738502016-04-06 17:41:37 -07006810 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006811
6812 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6813 hdd_ipa_uc_stat_request(adapter, 2);
6814
Jingxiang Gec64e1932017-08-22 14:38:59 +08006815restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006816 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006817 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006818 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306819 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006820 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006821 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006822}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006823
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306824/**
6825 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6826 * @arg: Argument of timer function
6827 *
6828 * Schedule a workqueue in this function where all the processing is done.
6829 *
6830 * Return: None.
6831 */
6832static void __hdd_bus_bw_cbk(void *arg)
6833{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006834 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306835
6836 if (wlan_hdd_validate_context(hdd_ctx))
6837 return;
6838
6839 schedule_work(&hdd_ctx->bus_bw_work);
6840}
6841
6842/**
6843 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6844 * @arg: Argument of timer function
6845 *
6846 * Return: None.
6847 */
6848static void hdd_bus_bw_cbk(void *arg)
6849{
6850 cds_ssr_protect(__func__);
6851 __hdd_bus_bw_cbk(arg);
6852 cds_ssr_unprotect(__func__);
6853}
6854
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006855int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006856{
6857 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306858 INIT_WORK(&hdd_ctx->bus_bw_work,
6859 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006860 hdd_ctx->bus_bw_timer_running = false;
6861 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306862 qdf_timer_init(NULL,
6863 &hdd_ctx->bus_bw_timer,
6864 hdd_bus_bw_cbk, (void *)hdd_ctx,
6865 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006866
6867 return 0;
6868}
6869
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006870void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006871{
Dustin Brownfce08d12017-01-17 16:29:38 -08006872 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006873 hdd_reset_tcp_delack(hdd_ctx);
6874
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006875 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306876 cancel_work_sync(&hdd_ctx->bus_bw_work);
6877 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006878 hdd_ctx->bus_bw_timer_running = false;
6879 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006880}
Lin Baic5c06882017-09-21 13:58:43 +08006881
6882void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6883{
6884 if (hdd_ctx)
6885 cancel_work_sync(&hdd_ctx->bus_bw_work);
6886}
jiadcdaf9bd2017-10-26 12:20:21 +08006887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888#endif
6889
6890/**
Nirav Shahed34b212016-04-25 10:59:16 +05306891 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6892 * @hdd_ctx: hdd context
6893 *
6894 * Return: 0 for success or error code
6895 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006896static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306897{
6898 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6899 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6900 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006901 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306902 return -ENOMEM;
6903 }
6904 return 0;
6905}
6906
6907/**
6908 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6909 * @hdd_ctx: hdd context
6910 *
6911 * Return: none
6912 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006913void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306914{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306915 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6916 return;
6917
6918 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6919 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306920}
6921
Nirav Shahda008342016-05-17 18:50:40 +05306922static uint8_t *convert_level_to_string(uint32_t level)
6923{
6924 switch (level) {
6925 /* initialize the wlan sub system */
6926 case WLAN_SVC_TP_NONE:
6927 return "NONE";
6928 case WLAN_SVC_TP_LOW:
6929 return "LOW";
6930 case WLAN_SVC_TP_MEDIUM:
6931 return "MED";
6932 case WLAN_SVC_TP_HIGH:
6933 return "HIGH";
6934 default:
6935 return "INVAL";
6936 }
6937}
6938
Nirav Shahed34b212016-04-25 10:59:16 +05306939
6940/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006941 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6942 * @hdd_ctx: hdd context
6943 *
6944 * Return: none
6945 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006946void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006947{
6948 int i;
6949
6950#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006951 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306952 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006953 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006954 hdd_ctx->config->busBandwidthHighThreshold,
6955 hdd_ctx->config->busBandwidthMediumThreshold,
6956 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006957 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306958 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006959 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006960 hdd_ctx->config->tcpDelackThresholdHigh,
6961 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006962 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306963 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006964#endif
6965
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006966 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306967 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6968
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006969 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006970
6971 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006972 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006973 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006974 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006975 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6976 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006977 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006978 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6979 convert_level_to_string(
6980 hdd_ctx->hdd_txrx_hist[i].
6981 next_vote_level),
6982 convert_level_to_string(
6983 hdd_ctx->hdd_txrx_hist[i].
6984 next_rx_level),
6985 convert_level_to_string(
6986 hdd_ctx->hdd_txrx_hist[i].
6987 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006988 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989}
6990
6991/**
6992 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6993 * @hdd_ctx: hdd context
6994 *
6995 * Return: none
6996 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006997void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006998{
6999 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307000 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7001 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007002}
7003
Mohit Khannaca4173b2017-09-12 21:52:19 -07007004/* length of the netif queue log needed per adapter */
7005#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7006
7007/**
7008 *
7009 * hdd_display_netif_queue_history_compact() - display compact netifq history
7010 * @hdd_ctx: hdd context
7011 *
7012 * Return: none
7013 */
7014static void
7015hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7016{
7017 int adapter_num = 0;
7018 int i;
7019 int bytes_written;
7020 u32 tbytes;
7021 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007022 char temp_str[20 * WLAN_REASON_TYPE_MAX];
7023 char comb_log_str[(ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1];
7024 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007025
7026 bytes_written = 0;
7027 qdf_mem_set(comb_log_str, 0, sizeof(comb_log_str));
Mohit Khannaca4173b2017-09-12 21:52:19 -07007028
Dustin Brown920397d2017-12-13 16:27:50 -08007029 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007030 curr_time = qdf_system_ticks();
7031 total = curr_time - adapter->start_time;
7032 delta = curr_time - adapter->last_time;
7033
7034 if (adapter->pause_map) {
7035 pause = adapter->total_pause_time + delta;
7036 unpause = adapter->total_unpause_time;
7037 } else {
7038 unpause = adapter->total_unpause_time + delta;
7039 pause = adapter->total_pause_time;
7040 }
7041
7042 tbytes = 0;
7043 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7044 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7045 if (adapter->queue_oper_stats[i].pause_count == 0)
7046 continue;
7047 tbytes +=
7048 snprintf(
7049 &temp_str[tbytes],
7050 (tbytes >= sizeof(temp_str) ?
7051 0 : sizeof(temp_str) - tbytes),
7052 "%d(%d,%d) ",
7053 i,
7054 adapter->queue_oper_stats[i].
7055 pause_count,
7056 adapter->queue_oper_stats[i].
7057 unpause_count);
7058 }
7059 if (tbytes >= sizeof(temp_str))
7060 hdd_warn("log truncated");
7061
7062 bytes_written += snprintf(&comb_log_str[bytes_written],
7063 bytes_written >= sizeof(comb_log_str) ? 0 :
7064 sizeof(comb_log_str) - bytes_written,
7065 "[%d %d] (%d) %u/%ums %s|",
7066 adapter->session_id, adapter->device_mode,
7067 adapter->pause_map,
7068 qdf_system_ticks_to_msecs(pause),
7069 qdf_system_ticks_to_msecs(total),
7070 temp_str);
7071
Mohit Khannaca4173b2017-09-12 21:52:19 -07007072 adapter_num++;
7073 }
7074
7075 /* using QDF_TRACE to avoid printing function name */
7076 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7077 "STATS |%s", comb_log_str);
7078
7079 if (bytes_written >= sizeof(comb_log_str))
7080 hdd_warn("log string truncated");
7081}
7082
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007083/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007084 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007085 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007086 *
7087 * Return: none
7088 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007089void
7090wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7091 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007092{
7093
Jeff Johnson9d295242017-08-29 14:39:48 -07007094 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007095 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307096 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007097
Mohit Khannaca4173b2017-09-12 21:52:19 -07007098 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7099 hdd_display_netif_queue_history_compact(hdd_ctx);
7100 return;
7101 }
7102
Dustin Brown920397d2017-12-13 16:27:50 -08007103 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007104 hdd_debug("Netif queue operation statistics:");
7105 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007106 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007107 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307108 curr_time = qdf_system_ticks();
7109 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307110 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307111 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307112 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307113 unpause = adapter->total_unpause_time;
7114 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307115 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307116 pause = adapter->total_pause_time;
7117 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007118 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307119 qdf_system_ticks_to_msecs(total),
7120 qdf_system_ticks_to_msecs(pause),
7121 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007122 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007123
Nirav Shahda008342016-05-17 18:50:40 +05307124 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7125 qdf_time_t pause_delta = 0;
7126
7127 if (adapter->pause_map & (1 << i))
7128 pause_delta = delta;
7129
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007130 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07007131 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007132 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007133 hdd_reason_type_to_string(i),
7134 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05307135 adapter->queue_oper_stats[i].unpause_count,
7136 qdf_system_ticks_to_msecs(
7137 adapter->queue_oper_stats[i].total_pause_time +
7138 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007139 }
7140
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007141 hdd_debug("Netif queue operation history:");
7142 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307143 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7144
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007145 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007146
7147 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007148 /* using hdd_log to avoid printing function name */
7149 if (adapter->queue_oper_history[i].time == 0)
7150 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07007151 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007152 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05307153 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007154 adapter->queue_oper_history[i].time),
7155 hdd_action_type_to_string(
7156 adapter->queue_oper_history[i].netif_action),
7157 hdd_reason_type_to_string(
7158 adapter->queue_oper_history[i].netif_reason),
7159 adapter->queue_oper_history[i].pause_map);
7160 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007161 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007162}
7163
7164/**
7165 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7166 * @hdd_ctx: hdd context
7167 *
7168 * Return: none
7169 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007170void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007171{
Jeff Johnson9d295242017-08-29 14:39:48 -07007172 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007173
Dustin Brown920397d2017-12-13 16:27:50 -08007174 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307175 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007176 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307177 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007178 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307179 adapter->history_index = 0;
7180 adapter->start_time = adapter->last_time = qdf_system_ticks();
7181 adapter->total_pause_time = 0;
7182 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007183 }
7184}
7185
7186/**
7187 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7188 * @halHandle: Hal handle
7189 * @pContext: Pointer to the context
7190 * @sessionId: Session ID
7191 * @scanId: Scan ID
7192 * @status: Status
7193 *
7194 * This is the callback to be executed when 11d scan is completed to flush out
7195 * the scan results
7196 *
7197 * 11d scan is done during driver load and is a passive scan on all
7198 * channels supported by the device, 11d scans may find some APs on
7199 * frequencies which are forbidden to be used in the regulatory domain
7200 * the device is operating in. If these APs are notified to the supplicant
7201 * it may try to connect to these APs, thus flush out all the scan results
7202 * which are present in SME after 11d scan is done.
7203 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307204 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007205 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307206static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007207 uint8_t sessionId, uint32_t scanId,
7208 eCsrScanStatus status)
7209{
7210 ENTER();
7211
7212 sme_scan_flush_result(halHandle);
7213
7214 EXIT();
7215
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307216 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007217}
7218
7219#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7220/**
7221 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7222 * @hdd_ctx: hdd global context
7223 *
7224 * Return: none
7225 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007226static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007227{
7228 uint8_t i;
7229
7230 mutex_init(&hdd_ctx->op_ctx.op_lock);
7231 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7232 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7233 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7234 }
7235}
7236#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007237static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007238{
7239}
7240#endif
7241
Yingying Tang95409972016-10-20 15:16:15 +08007242#ifdef WLAN_FEATURE_WOW_PULSE
7243/**
7244 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007245 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007246 * @enable: enable or disable this behaviour
7247 *
7248 * Return: int
7249 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007250static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007251{
7252 struct hdd_config *pcfg_ini = phddctx->config;
7253 struct wow_pulse_mode wow_pulse_set_info;
7254 QDF_STATUS status;
7255
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007256 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007257
7258 if (false == phddctx->config->wow_pulse_support)
7259 return 0;
7260
7261 /* prepare the request to send to SME */
7262 if (enable == true) {
7263 wow_pulse_set_info.wow_pulse_enable = true;
7264 wow_pulse_set_info.wow_pulse_pin =
7265 pcfg_ini->wow_pulse_pin;
7266 wow_pulse_set_info.wow_pulse_interval_low =
7267 pcfg_ini->wow_pulse_interval_low;
7268 wow_pulse_set_info.wow_pulse_interval_high =
7269 pcfg_ini->wow_pulse_interval_high;
7270 } else {
7271 wow_pulse_set_info.wow_pulse_enable = false;
7272 wow_pulse_set_info.wow_pulse_pin = 0;
7273 wow_pulse_set_info.wow_pulse_interval_low = 0;
7274 wow_pulse_set_info.wow_pulse_interval_high = 0;
7275 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007276 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007277 wow_pulse_set_info.wow_pulse_enable,
7278 wow_pulse_set_info.wow_pulse_pin,
7279 wow_pulse_set_info.wow_pulse_interval_low,
7280 wow_pulse_set_info.wow_pulse_interval_high);
7281
7282 status = sme_set_wow_pulse(&wow_pulse_set_info);
7283 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007284 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007285 return -EIO;
7286 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007287 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007288 return 0;
7289}
7290#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007291static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007292{
7293 return 0;
7294}
7295#endif
7296
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007297#ifdef WLAN_FEATURE_FASTPATH
7298/**
7299 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7300 * @hdd_cfg: hdd config
7301 * @context: lower layer context
7302 *
7303 * Return: none
7304 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307305void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007306 void *context)
7307{
7308 if (hdd_cfg->fastpath_enable)
7309 hif_enable_fastpath(context);
7310}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007311#endif
7312
Yuanyuan Liu13738502016-04-06 17:41:37 -07007313#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007314/**
7315 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007316 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007317 * @level: thermal level
7318 *
7319 * Change IPA data path to SW path when the thermal throttle level greater
7320 * than 0, and restore the original data path when throttle level is 0
7321 *
7322 * Return: none
7323 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007324static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007325{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007326 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007327
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007328 /* Change IPA to SW path when throttle level greater than 0 */
7329 if (level > THROTTLE_LEVEL_0)
7330 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7331 else
7332 /* restore original concurrency mode */
7333 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7334}
7335
7336/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307337 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7338 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307339 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007340 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307341 * Get a safe channel to restart SAP. PCL already takes into account the
7342 * unsafe channels. So, the PCL is validated with the ACS range to provide
7343 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007344 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307345 * Return: Channel number to restart SAP in case of success. In case of any
7346 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007347 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307348static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007349 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007350{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307351 struct sir_pcl_list pcl;
7352 QDF_STATUS status;
7353 uint32_t i, j;
7354 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007355 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307356 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007357
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307358 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7359 if (!hdd_ctx) {
7360 hdd_err("invalid HDD context");
7361 return INVALID_CHANNEL_ID;
7362 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007363
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307364 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7365 if (!hal_handle) {
7366 hdd_err("invalid HAL handle");
7367 return INVALID_CHANNEL_ID;
7368 }
7369
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007370 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7371 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007372 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7373 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307374 if (QDF_IS_STATUS_ERROR(status)) {
7375 hdd_err("Get PCL failed");
7376 return INVALID_CHANNEL_ID;
7377 }
7378
Frank Liudc2cefb2017-06-21 15:38:18 +08007379 /*
7380 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7381 * channel is unsafe channel, the pcl may be empty, instead of return,
7382 * try to choose a safe channel from acs range.
7383 */
7384 if (!pcl.pcl_len)
7385 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307386
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007387 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007388 adapter->session.ap.sap_config.acs_cfg.start_ch,
7389 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307390
7391 /* PCL already takes unsafe channel into account */
7392 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007393 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307394 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007395 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307396 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007397 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007398 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307399 return pcl.pcl_list[i];
7400 }
7401 }
7402
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007403 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307404
7405 /* Try for safe channel from all valid channel */
7406 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007407 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307408 &pcl.pcl_len);
7409 if (QDF_IS_STATUS_ERROR(status)) {
7410 hdd_err("error in getting valid channel list");
7411 return INVALID_CHANNEL_ID;
7412 }
7413
7414 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007415 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307416 found = false;
7417 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007418 if (pcl.pcl_list[i] ==
7419 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007420 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307421 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007422 break;
7423 }
7424 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307425
7426 if (found)
7427 continue;
7428
7429 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007430 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307431 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007432 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007433 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307434 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435 }
7436 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307437
7438 return INVALID_CHANNEL_ID;
7439}
7440
7441/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007442 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307443 * @adapter: AP adapter
7444 * @channel: Channel
7445 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007446 * Moves the SAP interface by invoking the function which
7447 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307448 *
7449 * Return: None
7450 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007451void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307452{
Jeff Johnson87251032017-08-29 13:31:11 -07007453 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307454 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007455 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307456
7457 if (!adapter) {
7458 hdd_err("invalid adapter");
7459 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007460 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307461
7462 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7463
7464 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7465 if (!hal_handle) {
7466 hdd_err("invalid HAL handle");
7467 return;
7468 }
7469
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007470 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7471
Jeff Johnson91df29d2017-10-27 19:29:50 -07007472 hdd_ap_ctx->sap_config.channel = channel;
7473 hdd_ap_ctx->sap_config.ch_params.ch_width =
7474 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307475
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007476 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007477 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307478
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007479 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007480 hdd_ap_ctx->sap_config.channel,
7481 hdd_ap_ctx->sap_config.sec_ch,
7482 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307483
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007484 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007485 adapter->session_id, channel,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007486 hdd_ap_ctx->sap_config.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007487}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307488
Jeff Johnson9d295242017-08-29 14:39:48 -07007489int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307490{
7491 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307492 int status;
7493 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307494
7495 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7496
7497 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007498 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307499 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007500 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307501 }
7502 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007503 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307504 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307505 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007506 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307507 WLAN_VENDOR_ACS_WAIT_TIME);
7508 if (qdf_status != QDF_STATUS_SUCCESS) {
7509 hdd_err("failed to start external acs timer");
7510 return -ENOSPC;
7511 }
7512 /* Update config to application */
7513 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307514 hdd_notice("Updated ACS config to nl with reason %d", reason);
7515
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307516 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307517}
7518
Agrawal Ashish467dde42016-09-08 18:44:22 +05307519/**
7520 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7521 * @hdd_ctx: hdd context pointer
7522 *
7523 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7524 * and if ACS is enabled, driver will ask userspace to restart the
7525 * sap. User space on LTE coex indication restart driver.
7526 *
7527 * Return - none
7528 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007529void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307530{
Dustin Brown920397d2017-12-13 16:27:50 -08007531 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307532 uint32_t i;
7533 bool found = false;
7534 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007535
Dustin Brown920397d2017-12-13 16:27:50 -08007536 hdd_for_each_adapter(hdd_ctxt, adapter) {
7537 if (!(adapter->device_mode == QDF_SAP_MODE &&
7538 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007539 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007540 adapter->device_mode,
7541 adapter->session.ap.sap_config.
7542 acs_cfg.acs_mode);
7543 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307544 }
7545
7546 found = false;
7547 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007548 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307549 hdd_ctxt->unsafe_channel_list[i]) {
7550 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007551 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007552 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307553 break;
7554 }
7555 }
7556
7557 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007558 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007559 adapter->session.ap.operating_channel);
7560 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307561 }
7562
Kapil Gupta8878ad92017-02-13 11:56:04 +05307563 if (hdd_ctxt->config->vendor_acs_support &&
7564 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007565 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307566 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007567 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307568 } else
7569 restart_chan =
7570 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007571 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307572 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007573 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307574 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007575 /*
7576 * SAP restart due to unsafe channel. While
7577 * restarting the SAP, make sure to clear
7578 * acs_channel, channel to reset to
7579 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307580 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007581 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307582 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007583 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307584 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007585 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307586 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7587 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007588 hdd_debug("driver to start sap: %d",
7589 hdd_ctxt->config->sap_internal_restart);
7590 if (hdd_ctxt->config->sap_internal_restart)
Dustin Brown920397d2017-12-13 16:27:50 -08007591 hdd_switch_sap_channel(adapter, restart_chan);
Liangwei Dong6663d162017-07-10 03:29:36 -04007592 else
7593 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307594 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307595 }
7596}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007598/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007599 * hdd_init_channel_avoidance() - Initialize channel avoidance
7600 * @hdd_ctx: HDD global context
7601 *
7602 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007603 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007604 * down to the lower layers. Then subscribe to subsequent channel
7605 * avoidance events.
7606 *
7607 * Return: None
7608 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007609static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007610{
7611 uint16_t unsafe_channel_count;
7612 int index;
7613
Yuanyuan Liu13738502016-04-06 17:41:37 -07007614 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7615 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007616 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007617 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007618
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007619 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007620 hdd_ctx->unsafe_channel_count);
7621
Anurag Chouhan6d760662016-02-20 16:05:43 +05307622 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007623 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007624
7625 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007626 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627 hdd_ctx->unsafe_channel_list[index]);
7628
7629 }
7630
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631}
Dustin Brown676a2322017-08-15 13:16:13 -07007632
Jeff Johnson9d295242017-08-29 14:39:48 -07007633static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007634 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007635{
7636 uint8_t restart_chan;
7637
7638 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7639 if (!restart_chan) {
7640 hdd_alert("fail to restart SAP");
7641 return;
7642 }
7643
7644 /* SAP restart due to unsafe channel. While restarting
7645 * the SAP, make sure to clear acs_channel, channel to
7646 * reset to 0. Otherwise these settings will override
7647 * the ACS while restart.
7648 */
7649 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007650 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007651
7652 hdd_debug("sending coex indication");
7653
7654 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7655 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7656 hdd_switch_sap_channel(adapter, restart_chan);
7657}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007658
7659int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7660 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7661{
7662 uint32_t size;
7663 uint16_t *unsafe_list;
7664 uint16_t chan_count;
7665
7666 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7667 return -EINVAL;
7668
7669 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7670 NUM_CHANNELS);
7671 if (chan_count) {
7672 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7673 unsafe_list = qdf_mem_malloc(size);
7674 if (!unsafe_list) {
7675 hdd_err("No memory for unsafe chan list size%d",
7676 size);
7677 return -ENOMEM;
7678 }
7679 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7680 } else {
7681 unsafe_list = NULL;
7682 }
7683
7684 *local_unsafe_list = unsafe_list;
7685 *local_unsafe_list_count = chan_count;
7686
7687 return 0;
7688}
7689
7690bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7691 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7692{
7693 int i, j;
7694
7695 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7696 return true;
7697 if (local_unsafe_list_count == 0)
7698 return false;
7699 for (i = 0; i < local_unsafe_list_count; i++) {
7700 for (j = 0; j < local_unsafe_list_count; j++)
7701 if (local_unsafe_list[i] ==
7702 hdd_ctx->unsafe_channel_list[j])
7703 break;
7704 if (j >= local_unsafe_list_count)
7705 break;
7706 }
7707 if (i >= local_unsafe_list_count) {
7708 hdd_info("unsafe chan list same");
7709 return false;
7710 }
7711
7712 return true;
7713}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007714#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007715static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007716{
7717}
Dustin Brown676a2322017-08-15 13:16:13 -07007718
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007719static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007720{
7721}
Dustin Brown676a2322017-08-15 13:16:13 -07007722
Jeff Johnson9d295242017-08-29 14:39:48 -07007723static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007724 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007725{
7726 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7727}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007728#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007729
7730/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007731 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7732 * user space
7733 * @frame_ind: Management frame data to be informed.
7734 *
7735 * This function is used to indicate management frame to
7736 * user space
7737 *
7738 * Return: None
7739 *
7740 */
7741void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7742{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007743 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007744 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007745 int i;
7746
Rajeev Kumard004abc2016-02-17 12:09:56 -08007747 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007748 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007749
7750 if (0 != wlan_hdd_validate_context(hdd_ctx))
7751 return;
7752
7753 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7754 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7755 adapter =
7756 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7757 if (adapter)
7758 break;
7759 }
7760 } else {
7761 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7762 frame_ind->sessionId);
7763 }
7764
7765 if ((NULL != adapter) &&
7766 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7767 __hdd_indicate_mgmt_frame(adapter,
7768 frame_ind->frame_len,
7769 frame_ind->frameBuf,
7770 frame_ind->frameType,
7771 frame_ind->rxChan,
7772 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007773}
7774
Kapil Gupta8878ad92017-02-13 11:56:04 +05307775void hdd_acs_response_timeout_handler(void *context)
7776{
7777 struct hdd_external_acs_timer_context *timer_context =
7778 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007779 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007780 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307781 uint8_t reason;
7782
7783 ENTER();
7784 if (!timer_context) {
7785 hdd_err("invlaid timer context");
7786 return;
7787 }
7788 adapter = timer_context->adapter;
7789 reason = timer_context->reason;
7790
7791
7792 if ((!adapter) ||
7793 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7794 hdd_err("invalid adapter or adapter has invalid magic");
7795 return;
7796 }
7797 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7798 if (wlan_hdd_validate_context(hdd_ctx))
7799 return;
7800
7801 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7802 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7803 else
7804 return;
7805
7806 hdd_err("ACS timeout happened for %s reason %d",
7807 adapter->dev->name, reason);
7808 switch (reason) {
7809 /* SAP init case */
7810 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7811 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7812 false);
7813 wlan_hdd_cfg80211_start_acs(adapter);
7814 break;
7815 /* DFS detected on current channel */
7816 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7817 wlan_sap_update_next_channel(
7818 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7819 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007820 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307821 break;
7822 /* LTE coex event on current channel */
7823 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7824 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7825 break;
7826 default:
7827 hdd_info("invalid reason for timer invoke");
7828
7829 }
7830}
7831
Rajeev Kumard004abc2016-02-17 12:09:56 -08007832/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007833 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7834 * @hdd_ctx: HDD context
7835 *
7836 * Disables all the dual mac features like DBS, Agile DFS etc.
7837 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307838 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007839 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007840static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007841{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007842 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307843 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007844
7845 if (!hdd_ctx) {
7846 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307847 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007848 }
7849
7850 cfg.scan_config = 0;
7851 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007852 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007853
7854 hdd_debug("Disabling all dual mac features...");
7855
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007856 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307857 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007858 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7859 return status;
7860 }
7861
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307862 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007863}
7864
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007865static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007866wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007867{
7868 struct policy_mgr_dual_mac_config cfg = {0};
7869 QDF_STATUS status;
7870
7871 if (!hdd_ctx) {
7872 hdd_err("HDD context is NULL");
7873 return QDF_STATUS_E_FAILURE;
7874 }
7875
7876 cfg.scan_config = 0;
7877 cfg.fw_mode_config = 0;
7878 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7879 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7880 hdd_ctx->hdd_psoc, &cfg.scan_config,
7881 &cfg.fw_mode_config,
7882 hdd_ctx->config->dual_mac_feature_disable);
7883
7884 if (status != QDF_STATUS_SUCCESS) {
7885 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7886 status);
7887 return status;
7888 }
7889
7890 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7891 cfg.scan_config, cfg.fw_mode_config);
7892
7893 status = sme_soc_set_dual_mac_config(cfg);
7894 if (status != QDF_STATUS_SUCCESS) {
7895 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7896 return status;
7897 }
7898
7899 return QDF_STATUS_SUCCESS;
7900}
7901
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007902/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007903 * hdd_override_ini_config - Override INI config
7904 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007905 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007906 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007907 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007908 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007909 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007910static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007911{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007912
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007913 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7914 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007915 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007916 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007917 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007918 if (0 == enable_11d || 1 == enable_11d) {
7919 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007920 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007921 }
Leo Chang11545d62016-10-17 14:53:50 -07007922
7923 if (!hdd_ipa_is_present(hdd_ctx))
7924 hdd_ctx->config->IpaConfig = 0;
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05307925
7926 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
7927 !hdd_ctx->config->enable_bcast_probe_rsp) {
7928 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
7929 hdd_ctx->config->rssi_assoc_reject_enabled,
7930 hdd_ctx->config->enable_bcast_probe_rsp);
7931 hdd_ctx->config->oce_sta_enabled = 0;
7932 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007933}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007934
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007935/**
7936 * hdd_set_trace_level_for_each - Set trace level for each INI config
7937 * @hdd_ctx - HDD context
7938 *
7939 * Set trace level for each module based on INI config.
7940 *
7941 * Return: None
7942 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007943static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007944{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307945 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7946 hdd_ctx->config->qdf_trace_enable_wdi);
7947 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7948 hdd_ctx->config->qdf_trace_enable_hdd);
7949 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7950 hdd_ctx->config->qdf_trace_enable_sme);
7951 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7952 hdd_ctx->config->qdf_trace_enable_pe);
7953 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7954 hdd_ctx->config->qdf_trace_enable_wma);
7955 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7956 hdd_ctx->config->qdf_trace_enable_sys);
7957 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7958 hdd_ctx->config->qdf_trace_enable_qdf);
7959 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7960 hdd_ctx->config->qdf_trace_enable_sap);
7961 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7962 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7963 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7964 hdd_ctx->config->qdf_trace_enable_bmi);
7965 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7966 hdd_ctx->config->qdf_trace_enable_cfg);
7967 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7968 hdd_ctx->config->qdf_trace_enable_epping);
7969 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7970 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7971 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007972 hdd_ctx->config->qdf_trace_enable_txrx);
7973 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7974 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307975 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7976 hdd_ctx->config->qdf_trace_enable_htc);
7977 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7978 hdd_ctx->config->qdf_trace_enable_hif);
7979 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7980 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7981 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7982 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007983 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7984 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007985 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7986 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007987 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7988 hdd_ctx->config->qdf_trace_enable_regulatory);
7989
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007990 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007991}
7992
7993/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007994 * hdd_context_init() - Initialize HDD context
7995 * @hdd_ctx: HDD context.
7996 *
7997 * Initialize HDD context along with all the feature specific contexts.
7998 *
7999 * return: 0 on success and errno on failure.
8000 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008001static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008002{
8003 int ret;
8004
8005 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8006 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8007
8008 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308009 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008010
8011 init_completion(&hdd_ctx->mc_sus_event_var);
8012 init_completion(&hdd_ctx->ready_to_suspend);
8013
8014 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308015 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008016 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308017
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008018 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008019
8020 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8021
8022 ret = hdd_scan_context_init(hdd_ctx);
8023 if (ret)
8024 goto list_destroy;
8025
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008026 hdd_rx_wake_lock_create(hdd_ctx);
8027
8028 ret = hdd_sap_context_init(hdd_ctx);
8029 if (ret)
8030 goto scan_destroy;
8031
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008032 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8033
8034 hdd_init_offloaded_packets_ctx(hdd_ctx);
8035
8036 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8037 hdd_ctx->config);
8038 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008039 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008040
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308041 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8042 "monitor_mode_wakelock");
8043
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008044 return 0;
8045
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008046sap_destroy:
8047 hdd_sap_context_destroy(hdd_ctx);
8048
8049scan_destroy:
8050 hdd_scan_context_destroy(hdd_ctx);
8051 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008052list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008053 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008054
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008055 return ret;
8056}
8057
8058/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308059 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8060 * @hdd_ctx: pointer to hdd context
8061 *
8062 * Return: status of initialization
8063 * 0 - success
8064 * negative value - failure
8065 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008066static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308067{
8068 int ret;
8069
8070 if (!hdd_ctx->config->probe_req_ie_whitelist)
8071 return 0;
8072
8073 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8074 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8075 hdd_ctx->config->probe_req_ie_whitelist = false;
8076 return -EINVAL;
8077 }
8078
8079 /* parse ini string probe req oui */
8080 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8081 if (ret) {
8082 hdd_err("parsing error: disable ie whitelisting");
8083 hdd_ctx->config->probe_req_ie_whitelist = false;
8084 }
8085
8086 return ret;
8087}
8088
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308089
8090/**
8091 * hdd_iface_change_callback() - Function invoked when stop modules expires
8092 * @priv: pointer to hdd context
8093 *
8094 * This function is invoked when the timer waiting for the interface change
8095 * expires, it shall cut-down the power to wlan and stop all the modules.
8096 *
8097 * Return: void
8098 */
8099static void hdd_iface_change_callback(void *priv)
8100{
8101 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8102 int ret;
8103 int status = wlan_hdd_validate_context(hdd_ctx);
8104
8105 if (status)
8106 return;
8107
8108 ENTER();
8109 hdd_debug("Interface change timer expired close the modules!");
8110 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8111 if (ret)
8112 hdd_err("Failed to stop modules");
8113 EXIT();
8114}
8115
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308116/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008117 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308118 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008119 *
8120 * Allocate and initialize HDD context. HDD context is allocated as part of
8121 * wiphy allocation and then context is initialized.
8122 *
8123 * Return: HDD context on success and ERR_PTR on failure
8124 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008125static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008126{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308127 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008128 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008129 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008130
8131 ENTER();
8132
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008133 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008134 if (hdd_ctx == NULL) {
8135 ret = -ENOMEM;
8136 goto err_out;
8137 }
8138
Dustin Brown6f427922017-09-19 12:19:00 -07008139 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8140 hdd_iface_change_callback,
8141 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308142
8143 mutex_init(&hdd_ctx->iface_change_lock);
8144
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008145 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308146 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008147
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308148 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008149 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008150 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008151 ret = -ENOMEM;
8152 goto err_free_hdd_context;
8153 }
8154
8155 /* Read and parse the qcom_cfg.ini file */
8156 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308157 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308158 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008159 WLAN_INI_FILE);
8160 ret = -EINVAL;
8161 goto err_free_config;
8162 }
8163
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308164 ie_whitelist_attrs_init(hdd_ctx);
8165
Dustin Brown7f939932017-05-18 15:02:17 -07008166 hdd_debug("setting timer multiplier: %u",
8167 hdd_ctx->config->timer_multiplier);
8168 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8169
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008170
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308171 if (hdd_ctx->config->fhostNSOffload)
8172 hdd_ctx->ns_offload_enable = true;
8173
Abhishek Singh5ea86532016-04-27 14:10:53 +05308174 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8175
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008176 hdd_override_ini_config(hdd_ctx);
8177
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008178 ret = hdd_context_init(hdd_ctx);
8179
8180 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008181 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008182
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008183 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308184 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008185
Anurag Chouhan6d760662016-02-20 16:05:43 +05308186 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008187 goto skip_multicast_logging;
8188
8189 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8190
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008191 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8192 if (ret)
8193 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308194
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008195 ret = hdd_init_netlink_services(hdd_ctx);
8196 if (ret)
8197 goto err_deinit_txrx_histogram;
8198
Dustin Brown7b3dea22017-07-10 13:02:47 -07008199 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
8200 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05308201
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008202skip_multicast_logging:
8203 hdd_set_trace_level_for_each(hdd_ctx);
8204
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008205 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8206
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008207 EXIT();
8208
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008209 return hdd_ctx;
8210
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008211err_deinit_txrx_histogram:
8212 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8213
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008214err_deinit_hdd_context:
8215 hdd_context_deinit(hdd_ctx);
8216
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008217err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308218 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008219
8220err_free_hdd_context:
8221 wiphy_free(hdd_ctx->wiphy);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308222 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008223
8224err_out:
8225 return ERR_PTR(ret);
8226}
8227
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008228#ifdef WLAN_OPEN_P2P_INTERFACE
8229/**
8230 * hdd_open_p2p_interface - Open P2P interface
8231 * @hdd_ctx: HDD context
8232 * @rtnl_held: True if RTNL lock held
8233 *
8234 * Open P2P interface during probe. This function called to open the P2P
8235 * interface at probe along with STA interface.
8236 *
8237 * Return: 0 on success and errno on failure
8238 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008239static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008240{
Jeff Johnson9d295242017-08-29 14:39:48 -07008241 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008242 uint8_t *p2p_dev_addr;
8243
8244 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8245 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008246 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008247 hdd_ctx->config->intfMacAddr[0].bytes,
8248 sizeof(tSirMacAddr));
8249
8250 /*
8251 * Generate the P2P Device Address. This consists of
8252 * the device's primary MAC address with the locally
8253 * administered bit set.
8254 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008255 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008256 } else {
8257 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8258 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008259 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008260 return -ENOSPC;
8261 }
8262
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008263 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8264 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008265 }
8266
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008267 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008268 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008269 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008270
8271 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008272 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008273 return -ENOSPC;
8274 }
8275
8276 return 0;
8277}
8278#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008279static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008280 bool rtnl_held)
8281{
8282 return 0;
8283}
8284#endif
8285
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008286static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008287{
Jeff Johnson9d295242017-08-29 14:39:48 -07008288 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008289 int ret = 0;
8290
8291 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8292 wlan_hdd_get_intf_addr(hdd_ctx),
8293 NET_NAME_UNKNOWN, rtnl_held);
8294 if (adapter == NULL) {
8295 hdd_err("Failed to open 802.11p interface");
8296 ret = -ENOSPC;
8297 }
8298
8299 return ret;
8300}
8301
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008302/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308303 * hdd_start_station_adapter()- Start the Station Adapter
8304 * @adapter: HDD adapter
8305 *
8306 * This function initializes the adapter for the station mode.
8307 *
8308 * Return: 0 on success or errno on failure.
8309 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008310int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308311{
8312 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008313 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308314
8315 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008316 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8317 hdd_err("session is already opened, %d",
8318 adapter->session_id);
8319 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8320 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308321
Krunal Sonib51eec72017-11-20 21:53:01 -08008322 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8323 if (ret) {
8324 hdd_err("failed to create vdev: %d", ret);
8325 return ret;
8326 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308327 status = hdd_init_station_mode(adapter);
8328
8329 if (QDF_STATUS_SUCCESS != status) {
8330 hdd_err("Error Initializing station mode: %d", status);
8331 return qdf_status_to_os_return(status);
8332 }
8333
Arun Khandavallifae92942016-08-01 13:31:08 +05308334 hdd_register_tx_flow_control(adapter,
8335 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008336 hdd_tx_resume_cb,
8337 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308338
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308339 EXIT();
8340 return 0;
8341}
8342
8343/**
8344 * hdd_start_ap_adapter()- Start AP Adapter
8345 * @adapter: HDD adapter
8346 *
8347 * This function initializes the adapter for the AP mode.
8348 *
8349 * Return: 0 on success errno on failure.
8350 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008351int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308352{
8353 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008354 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008355 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308356
8357 ENTER();
8358
Krunal Sonib51eec72017-11-20 21:53:01 -08008359 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8360 hdd_err("session is already opened, %d",
8361 adapter->session_id);
8362 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8363 }
8364 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008365 * In SSR case no need to create new sap context.
8366 * Otherwise create sap context first and then create
8367 * vdev as while creating the vdev, driver needs to
8368 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008369 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008370 if (adapter->session.ap.sap_context) {
8371 is_ssr = true;
8372 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008373 hdd_err("sap creation failed");
8374 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8375 }
8376
8377 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8378 adapter->session.ap.sap_context);
8379 if (ret) {
8380 hdd_err("failed to create vdev, status:%d", ret);
8381 hdd_sap_destroy_ctx(adapter);
8382 return ret;
8383 }
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008384 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308385
8386 if (QDF_STATUS_SUCCESS != status) {
8387 hdd_err("Error Initializing the AP mode: %d", status);
8388 return qdf_status_to_os_return(status);
8389 }
8390
Arun Khandavallifae92942016-08-01 13:31:08 +05308391 hdd_register_tx_flow_control(adapter,
8392 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008393 hdd_softap_tx_resume_cb,
8394 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308395
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308396 EXIT();
8397 return 0;
8398}
8399
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308400static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8401 bool rtnl_held)
8402{
8403 struct hdd_adapter *adapter;
8404
8405 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8406 hdd_ctx->config->enableConcurrentSTA,
8407 wlan_hdd_get_intf_addr(hdd_ctx),
8408 NET_NAME_UNKNOWN, rtnl_held);
8409
8410 if (!adapter)
8411 return -ENOSPC;
8412
8413 return 0;
8414}
8415
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308416/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008417 * hdd_open_interfaces - Open all required interfaces
8418 * hdd_ctx: HDD context
8419 * rtnl_held: True if RTNL lock is held
8420 *
8421 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8422 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008423 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008424 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008425static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008426{
Jeff Johnson9d295242017-08-29 14:39:48 -07008427 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008428 int ret;
8429
Ravi Joshia307f632017-07-17 23:41:41 -07008430 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008431 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8432 con_mode == QDF_GLOBAL_FTM_MODE) {
8433 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8434 QDF_MONITOR_MODE : QDF_FTM_MODE;
8435
8436 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8437 wlan_hdd_get_intf_addr(hdd_ctx),
8438 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008439 if (!adapter) {
8440 hdd_err("open adapter failed");
8441 return -ENOSPC;
8442 }
Lin Bai1c678482017-12-18 18:29:11 +08008443
Ravi Joshia307f632017-07-17 23:41:41 -07008444 return 0;
8445 }
8446
Jeff Johnson957bc272017-02-02 08:54:48 -08008447 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308448 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008449 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008450
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008451 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008452 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008453 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008454
8455 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008456 return -ENOSPC;
8457
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008458 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8459 adapter->fast_roaming_allowed = true;
8460
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308461 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8462 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8463 if (ret)
8464 hdd_err("Cannot create concurrent STA interface");
8465 }
8466
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008467 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8468 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008469 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008470
8471 /* Open 802.11p Interface */
8472 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008473 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8474 if (ret)
8475 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008476 }
8477
Jeff Johnson957bc272017-02-02 08:54:48 -08008478 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008479
Jeff Johnson957bc272017-02-02 08:54:48 -08008480err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008481 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008482 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008483}
8484
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008485/**
8486 * hdd_update_country_code - Update country code
8487 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008488 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008489 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008490 *
8491 * Return: 0 on success and errno on failure
8492 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008493static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008494{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008495 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008496 return 0;
8497
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008498 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008499}
8500
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308501#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8502/**
8503 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8504 * @cds_cfg: CDS Configuration
8505 * @hdd_ctx: Pointer to hdd context
8506 *
8507 * Return: none
8508 */
8509static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8510 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008511 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308512{
8513 cds_cfg->tx_flow_stop_queue_th =
8514 hdd_ctx->config->TxFlowStopQueueThreshold;
8515 cds_cfg->tx_flow_start_queue_offset =
8516 hdd_ctx->config->TxFlowStartQueueOffset;
8517}
8518#else
8519static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8520 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008521 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308522{
8523}
8524#endif
8525
8526#ifdef FEATURE_WLAN_RA_FILTERING
8527/**
8528 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8529 * @cds_cfg: CDS Configuration
8530 * @hdd_ctx: Pointer to hdd context
8531 *
8532 * Return: none
8533 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308534static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008535 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308536{
8537 cds_cfg->ra_ratelimit_interval =
8538 hdd_ctx->config->RArateLimitInterval;
8539 cds_cfg->is_ra_ratelimit_enabled =
8540 hdd_ctx->config->IsRArateLimitEnabled;
8541}
8542#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308543static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008544 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308545{
8546}
8547#endif
8548
8549/**
8550 * hdd_update_cds_config() - API to update cds configuration parameters
8551 * @hdd_ctx: HDD Context
8552 *
8553 * Return: 0 for Success, errno on failure
8554 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008555static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308556{
8557 struct cds_config_info *cds_cfg;
8558
8559 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8560 if (!cds_cfg) {
8561 hdd_err("failed to allocate cds config");
8562 return -ENOMEM;
8563 }
8564
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008565 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008566 if (!hdd_ctx->config->nMaxPsPoll ||
8567 !hdd_ctx->config->enablePowersaveOffload) {
8568 cds_cfg->powersave_offload_enabled =
8569 hdd_ctx->config->enablePowersaveOffload;
8570 } else {
8571 if ((hdd_ctx->config->enablePowersaveOffload ==
8572 PS_QPOWER_NODEEPSLEEP) ||
8573 (hdd_ctx->config->enablePowersaveOffload ==
8574 PS_LEGACY_NODEEPSLEEP))
8575 cds_cfg->powersave_offload_enabled =
8576 PS_LEGACY_NODEEPSLEEP;
8577 else
8578 cds_cfg->powersave_offload_enabled =
8579 PS_LEGACY_DEEPSLEEP;
8580 hdd_info("Qpower disabled in cds config, %d",
8581 cds_cfg->powersave_offload_enabled);
8582 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308583 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8584 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8585 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8586 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8587 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8588
8589 /* Here ol_ini_info is used to store ini status of arp offload
8590 * ns offload and others. Currently 1st bit is used for arp
8591 * off load and 2nd bit for ns offload currently, rest bits are unused
8592 */
8593 if (hdd_ctx->config->fhostArpOffload)
8594 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8595 if (hdd_ctx->config->fhostNSOffload)
8596 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8597
8598 /*
8599 * Copy the DFS Phyerr Filtering Offload status.
8600 * This parameter reflects the value of the
8601 * dfs_phyerr_filter_offload flag as set in the ini.
8602 */
8603 cds_cfg->dfs_phyerr_filter_offload =
8604 hdd_ctx->config->fDfsPhyerrFilterOffload;
8605 if (hdd_ctx->config->ssdp)
8606 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8607
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308608 cds_cfg->force_target_assert_enabled =
8609 hdd_ctx->config->crash_inject_enabled;
8610
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308611 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8612 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8613
8614 cds_cfg->ap_maxoffload_reorderbuffs =
8615 hdd_ctx->config->apMaxOffloadReorderBuffs;
8616
8617 cds_cfg->ap_disable_intrabss_fwd =
8618 hdd_ctx->config->apDisableIntraBssFwd;
8619
8620 cds_cfg->dfs_pri_multiplier =
8621 hdd_ctx->config->dfsRadarPriMultiplier;
8622 cds_cfg->reorder_offload =
8623 hdd_ctx->config->reorderOffloadSupport;
8624
8625 /* IPA micro controller data path offload resource config item */
8626 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008627 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8628 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008629 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008630 hdd_ctx->config->IpaUcTxBufCount);
8631 hdd_ctx->config->IpaUcTxBufCount =
8632 rounddown_pow_of_two(
8633 hdd_ctx->config->IpaUcTxBufCount);
8634 if (!hdd_ctx->config->IpaUcTxBufCount) {
8635 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308636 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008637 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008638 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008639 hdd_ctx->config->IpaUcTxBufCount);
8640 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308641 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8642 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008643 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8644 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008645 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008646 hdd_ctx->config->IpaUcRxIndRingCount);
8647 hdd_ctx->config->IpaUcRxIndRingCount =
8648 rounddown_pow_of_two(
8649 hdd_ctx->config->IpaUcRxIndRingCount);
8650 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8651 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308652 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008653 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008654 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008655 hdd_ctx->config->IpaUcRxIndRingCount);
8656 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308657 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008658 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308659 cds_cfg->uc_tx_partition_base =
8660 hdd_ctx->config->IpaUcTxPartitionBase;
8661 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8662
8663 cds_cfg->ip_tcp_udp_checksum_offload =
8664 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008665 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308666 cds_cfg->ce_classify_enabled =
8667 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008668 cds_cfg->bpf_packet_filter_enable =
8669 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308670 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8671 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8672 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008673 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008674 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008675 cds_cfg->max_msdus_per_rxinorderind =
8676 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008677 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008678 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308679 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8680 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308681 cds_cfg->auto_power_save_fail_mode =
8682 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308683
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308684 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008685 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308686
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308687 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8688 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8689 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008690 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308691 cds_init_ini_config(cds_cfg);
8692 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308693
8694exit:
8695 qdf_mem_free(cds_cfg);
8696 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308697}
8698
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008699/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008700 * hdd_update_user_config() - API to update user configuration
8701 * parameters to obj mgr which are used by multiple components
8702 * @hdd_ctx: HDD Context
8703 *
8704 * Return: 0 for Success, errno on failure
8705 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008706static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008707{
8708 struct wlan_objmgr_psoc_user_config *user_config;
8709
8710 user_config = qdf_mem_malloc(sizeof(*user_config));
8711 if (user_config == NULL) {
8712 hdd_alert("Failed to alloc memory for user_config!");
8713 return -ENOMEM;
8714 }
8715
8716 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8717 user_config->dual_mac_feature_disable =
8718 hdd_ctx->config->dual_mac_feature_disable;
8719 user_config->indoor_channel_support =
8720 hdd_ctx->config->indoor_channel_support;
8721 user_config->is_11d_support_enabled =
8722 hdd_ctx->config->Is11dSupportEnabled;
8723 user_config->is_11h_support_enabled =
8724 hdd_ctx->config->Is11hSupportEnabled;
8725 user_config->optimize_chan_avoid_event =
8726 hdd_ctx->config->goptimize_chan_avoid_event;
8727 user_config->skip_dfs_chnl_in_p2p_search =
8728 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008729 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008730 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8731
8732 qdf_mem_free(user_config);
8733 return 0;
8734}
8735
8736/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008737 * hdd_init_thermal_info - Initialize thermal level
8738 * @hdd_ctx: HDD context
8739 *
8740 * Initialize thermal level at SME layer and set the thermal level callback
8741 * which would be called when a configured thermal threshold is hit.
8742 *
8743 * Return: 0 on success and errno on failure
8744 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008745static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008746{
8747 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308748 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008749
8750 thermal_param.smeThermalMgmtEnabled =
8751 hdd_ctx->config->thermalMitigationEnable;
8752 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8753
Poddar, Siddarth83905022016-04-16 17:56:08 -07008754 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8755 hdd_ctx->config->throttle_dutycycle_level0;
8756 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8757 hdd_ctx->config->throttle_dutycycle_level1;
8758 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8759 hdd_ctx->config->throttle_dutycycle_level2;
8760 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8761 hdd_ctx->config->throttle_dutycycle_level3;
8762
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008763 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8764 hdd_ctx->config->thermalTempMinLevel0;
8765 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8766 hdd_ctx->config->thermalTempMaxLevel0;
8767 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8768 hdd_ctx->config->thermalTempMinLevel1;
8769 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8770 hdd_ctx->config->thermalTempMaxLevel1;
8771 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8772 hdd_ctx->config->thermalTempMinLevel2;
8773 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8774 hdd_ctx->config->thermalTempMaxLevel2;
8775 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8776 hdd_ctx->config->thermalTempMinLevel3;
8777 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8778 hdd_ctx->config->thermalTempMaxLevel3;
8779
8780 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8781
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308782 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308783 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008784
8785 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8786 hdd_set_thermal_level_cb);
8787
8788 return 0;
8789
8790}
8791
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008792#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8793/**
8794 * hdd_hold_rtnl_lock - Hold RTNL lock
8795 *
8796 * Hold RTNL lock
8797 *
8798 * Return: True if held and false otherwise
8799 */
8800static inline bool hdd_hold_rtnl_lock(void)
8801{
8802 rtnl_lock();
8803 return true;
8804}
8805
8806/**
8807 * hdd_release_rtnl_lock - Release RTNL lock
8808 *
8809 * Release RTNL lock
8810 *
8811 * Return: None
8812 */
8813static inline void hdd_release_rtnl_lock(void)
8814{
8815 rtnl_unlock();
8816}
8817#else
8818static inline bool hdd_hold_rtnl_lock(void) { return false; }
8819static inline void hdd_release_rtnl_lock(void) { }
8820#endif
8821
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008822#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008823
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308824/* MAX iwpriv command support */
8825#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308826#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308827#define MAX_PKTLOG_SIZE 16
8828
8829/**
8830 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8831 * @hdd_ctx: hdd context
8832 * @set_value2: pktlog buffer size value
8833 *
8834 *
8835 * Return: 0 for success or error.
8836 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008837static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308838{
8839 struct sir_wifi_start_log start_log = { 0 };
8840 QDF_STATUS status;
8841
8842 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8843 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8844 start_log.ini_triggered = cds_is_packet_log_enabled();
8845 start_log.user_triggered = 1;
8846 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308847 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308848
8849 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8850 if (!QDF_IS_STATUS_SUCCESS(status)) {
8851 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8852 EXIT();
8853 return -EINVAL;
8854 }
8855
8856 return 0;
8857}
8858
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008859/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308860 * hdd_pktlog_clear_buff() - clear pktlog buffer
8861 * @hdd_ctx: hdd context
8862 *
8863 * Return: 0 for success or error.
8864 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008865static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308866{
8867 struct sir_wifi_start_log start_log;
8868 QDF_STATUS status;
8869
8870 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8871 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8872 start_log.ini_triggered = cds_is_packet_log_enabled();
8873 start_log.user_triggered = 1;
8874 start_log.size = 0;
8875 start_log.is_pktlog_buff_clear = true;
8876
8877 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8878 if (!QDF_IS_STATUS_SUCCESS(status)) {
8879 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8880 EXIT();
8881 return -EINVAL;
8882 }
8883
8884 return 0;
8885}
8886
8887
8888/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008889 * hdd_process_pktlog_command() - process pktlog command
8890 * @hdd_ctx: hdd context
8891 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308892 * @set_value2: pktlog buffer size value
8893 *
8894 * This function process pktlog command.
8895 * set_value2 only matters when set_value is 3 (set buff size)
8896 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008897 *
8898 * Return: 0 for success or error.
8899 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008900int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308901 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008902{
8903 int ret;
8904 bool enable;
8905 uint8_t user_triggered = 0;
8906
8907 ret = wlan_hdd_validate_context(hdd_ctx);
8908 if (0 != ret)
8909 return ret;
8910
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008911 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008912
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308913 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008914 hdd_err("invalid pktlog value %d", set_value);
8915 return -EINVAL;
8916 }
8917
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308918 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8919 if (set_value2 <= 0) {
8920 hdd_err("invalid pktlog size %d", set_value2);
8921 return -EINVAL;
8922 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8923 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8924 return -EINVAL;
8925 }
8926 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308927 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8928 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308929 }
8930
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008931 /*
8932 * set_value = 0 then disable packetlog
8933 * set_value = 1 enable packetlog forcefully
8934 * set_vlaue = 2 then disable packetlog if disabled through ini or
8935 * enable packetlog with AUTO type.
8936 */
8937 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8938 true : false;
8939
8940 if (1 == set_value) {
8941 enable = true;
8942 user_triggered = 1;
8943 }
8944
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308945 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008946}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008947
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008948/**
8949 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8950 * @hdd_ctx: HDD context
8951 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308952 * @user_triggered: triggered through iwpriv
8953 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008954 *
8955 * Return: 0 on success; error number otherwise
8956 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008957int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308958 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008959{
8960 struct sir_wifi_start_log start_log;
8961 QDF_STATUS status;
8962
8963 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8964 start_log.verbose_level =
8965 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008966 start_log.ini_triggered = cds_is_packet_log_enabled();
8967 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308968 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308969 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308970 /*
8971 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8972 * commands. Host uses this flag to decide whether to send pktlog
8973 * disable command to fw without sending pktlog enable command
8974 * previously. For eg, If vendor sends pktlog disable command without
8975 * sending pktlog enable command, then host discards the packet
8976 * but for iwpriv command, host will send it to fw.
8977 */
8978 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008979 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8980 if (!QDF_IS_STATUS_SUCCESS(status)) {
8981 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8982 EXIT();
8983 return -EINVAL;
8984 }
8985
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05308986 if (enable == true)
8987 hdd_ctx->is_pktlog_enabled = 1;
8988 else
8989 hdd_ctx->is_pktlog_enabled = 0;
8990
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008991 return 0;
8992}
8993#endif /* REMOVE_PKT_LOG */
8994
Komal Seelam92fff912016-03-24 11:51:41 +05308995/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008996 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8997 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308998 * @dev: Device Pointer
8999 * @num: Number of Valid Mac address
9000 *
9001 * Return: Pointer to MAC address buffer
9002 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009003static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9004 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309005{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009006 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309007}
Komal Seelam92fff912016-03-24 11:51:41 +05309008
9009/**
9010 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9011 * @hdd_ctx: HDD Context
9012 * @num: Number of random mac addresses needed
9013 *
9014 * Generate random addresses using bit manipulation on the base mac address
9015 *
9016 * Return: None
9017 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009018void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309019{
9020 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9021 uint32_t iter;
9022 struct hdd_config *ini = hdd_ctx->config;
9023 uint8_t *buf = NULL;
9024 uint8_t macaddr_b3, tmp_br3;
9025 uint8_t *src = ini->intfMacAddr[0].bytes;
9026
9027 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9028 buf = ini->intfMacAddr[iter].bytes;
9029 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9030 macaddr_b3 = buf[3];
9031 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9032 INTF_MACADDR_MASK;
9033 macaddr_b3 += tmp_br3;
9034 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9035 buf[0] |= 0x02;
9036 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009037 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309038 }
9039}
9040
9041/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009042 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309043 * @hdd_ctx: HDD Context
9044 *
9045 * API to get mac addresses from platform driver and update the driver
9046 * structures and configure FW with the base mac address.
9047 * Return: int
9048 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009049static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309050{
9051 uint32_t no_of_mac_addr, iter;
9052 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9053 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9054 uint8_t *addr, *buf;
9055 struct device *dev = hdd_ctx->parent_dev;
9056 struct hdd_config *ini = hdd_ctx->config;
9057 tSirMacAddr mac_addr;
9058 QDF_STATUS status;
9059
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009060 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309061
9062 if (no_of_mac_addr == 0 || !addr) {
9063 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9064 return -EINVAL;
9065 }
9066
9067 if (no_of_mac_addr > max_mac_addr)
9068 no_of_mac_addr = max_mac_addr;
9069
9070 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9071
9072 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9073 buf = ini->intfMacAddr[iter].bytes;
9074 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009075 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309076 }
9077
9078 status = sme_set_custom_mac_addr(mac_addr);
9079
9080 if (!QDF_IS_STATUS_SUCCESS(status))
9081 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009082
Komal Seelam92fff912016-03-24 11:51:41 +05309083 if (no_of_mac_addr < max_mac_addr)
9084 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9085 no_of_mac_addr);
9086 return 0;
9087}
9088
9089/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009090 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9091 * @hdd_ctx: HDD Context
9092 *
9093 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9094 * will generate its own MAC and update it to FW.
9095 *
9096 * Return: 0 for success
9097 * Non-zero error code for failure
9098 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009099static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009100{
9101 tSirMacAddr customMacAddr;
9102 QDF_STATUS status;
9103
9104 qdf_mem_copy(&customMacAddr,
9105 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9106 sizeof(tSirMacAddr));
9107 status = sme_set_custom_mac_addr(customMacAddr);
9108 if (!QDF_IS_STATUS_SUCCESS(status))
9109 return -EAGAIN;
9110 return 0;
9111}
9112
9113/**
Komal Seelam92fff912016-03-24 11:51:41 +05309114 * hdd_initialize_mac_address() - API to get wlan mac addresses
9115 * @hdd_ctx: HDD Context
9116 *
9117 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9118 * is provisioned with mac addresses, driver uses it, else it will use
9119 * wlan_mac.bin to update HW MAC addresses.
9120 *
9121 * Return: None
9122 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009123static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309124{
9125 QDF_STATUS status;
9126 int ret;
9127
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009128 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309129 if (ret == 0)
9130 return;
9131
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009132 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9133 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309134
9135 status = hdd_update_mac_config(hdd_ctx);
9136
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009137 if (QDF_IS_STATUS_SUCCESS(status))
9138 return;
9139
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009140 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9141 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009142
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009143 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009144 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009145 if (ret != 0) {
9146 hdd_err("MAC address out-of-sync, ret:%d", ret);
9147 QDF_ASSERT(ret);
9148 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009149 }
Komal Seelam92fff912016-03-24 11:51:41 +05309150}
9151
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009152static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009153{
9154 int vdev_id = 0;
9155 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9156 int value = hdd_ctx->config->smart_chainmask_enabled;
9157 int vpdev = PDEV_CMD;
9158 int ret;
9159
Naveen Rawat247a8682017-06-05 15:00:31 -07009160 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009161 if (ret)
9162 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9163
9164 return ret;
9165}
9166
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009167static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009168{
9169 int vdev_id = 0;
9170 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9171 int value = hdd_ctx->config->alternative_chainmask_enabled;
9172 int vpdev = PDEV_CMD;
9173 int ret;
9174
Naveen Rawat247a8682017-06-05 15:00:31 -07009175 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009176 if (ret)
9177 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9178 ret);
9179
9180 return ret;
9181}
9182
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009183static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009184{
9185 int vdev_id = 0;
9186 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9187 int value = hdd_ctx->config->ani_enabled;
9188 int vpdev = PDEV_CMD;
9189 int ret;
9190
Naveen Rawat247a8682017-06-05 15:00:31 -07009191 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009192 if (ret)
9193 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9194
9195 return ret;
9196}
9197
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009198/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009199 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9200 * @hdd_ctx: HDD context
9201 *
9202 * Pre configurations to be done at lower layer before calling cds enable.
9203 *
9204 * Return: 0 on success and errno on failure.
9205 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009206static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009207{
9208 int ret;
9209 QDF_STATUS status;
9210 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009211 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009212
Leo Changfdb45c32016-10-28 11:09:23 -07009213 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009214 /*
9215 * Set 802.11p config
9216 * TODO-OCB: This has been temporarily added here to ensure this
9217 * parameter is set in CSR when we init the channel list. This should
9218 * be removed once the 5.9 GHz channels are added to the regulatory
9219 * domain.
9220 */
9221 hdd_set_dot11p_config(hdd_ctx);
9222
9223 /*
9224 * Note that the cds_pre_enable() sequence triggers the cfg download.
9225 * The cfg download must occur before we update the SME config
9226 * since the SME config operation must access the cfg database
9227 */
9228 status = hdd_set_sme_config(hdd_ctx);
9229
9230 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009231 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009232 ret = qdf_status_to_os_return(status);
9233 goto out;
9234 }
9235
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009236 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9237 if (QDF_STATUS_SUCCESS != status) {
9238 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9239 ret = qdf_status_to_os_return(status);
9240 goto out;
9241 }
9242
Naveen Rawat247a8682017-06-05 15:00:31 -07009243 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009244 hdd_ctx->config->tx_chain_mask_1ss,
9245 PDEV_CMD);
9246 if (0 != ret) {
9247 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9248 goto out;
9249 }
9250
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009251 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9252 if (ret)
9253 goto out;
9254
9255 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9256 if (ret)
9257 goto out;
9258
Jeff Johnson12a744b2017-04-04 08:19:37 -07009259 ret = hdd_set_ani_enabled(hdd_ctx);
9260 if (ret)
9261 goto out;
9262
Naveen Rawat247a8682017-06-05 15:00:31 -07009263 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009264 hdd_ctx->config->arp_ac_category,
9265 PDEV_CMD);
9266 if (0 != ret) {
9267 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9268 hdd_ctx->config->arp_ac_category, ret);
9269 goto out;
9270 }
9271
Prashanth Bhatta07998752016-04-28 12:35:33 -07009272 status = hdd_set_sme_chan_list(hdd_ctx);
9273 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009274 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009275 ret = qdf_status_to_os_return(status);
9276 goto out;
9277 }
9278
9279 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009280 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009281 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009282 ret = -EINVAL;
9283 goto out;
9284 }
9285
Prashanth Bhatta07998752016-04-28 12:35:33 -07009286 /*
9287 * Set the MAC Address Currently this is used by HAL to add self sta.
9288 * Remove this once self sta is added as part of session open.
9289 */
9290 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9291 hdd_ctx->config->intfMacAddr[0].bytes,
9292 sizeof(hdd_ctx->config->intfMacAddr[0]));
9293
9294 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9295 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9296 hal_status, hal_status);
9297 ret = -EINVAL;
9298 goto out;
9299 }
9300
9301 hdd_init_channel_avoidance(hdd_ctx);
9302
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309303 /* update enable sap mandatory chan list */
9304 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9305 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009306out:
9307 return ret;
9308}
9309
9310/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009311 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9312 * @context_ptr - hdd context pointer
9313 * @event_ptr - event structure pointer
9314 *
9315 * This is the p2p listen offload stop event handler, it sends vendor
9316 * event back to supplicant to notify the stop reason.
9317 *
9318 * Return: None
9319 */
9320static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9321 void *event_ptr)
9322{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009323 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009324 struct sir_p2p_lo_event *evt = event_ptr;
9325 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009326 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009327
9328 ENTER();
9329
9330 if (hdd_ctx == NULL) {
9331 hdd_err("Invalid HDD context pointer");
9332 return;
9333 }
9334
Peng Xu5c682812017-08-06 07:39:13 -07009335 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9336 if (!adapter) {
9337 hdd_err("Cannot find adapter by vdev_id = %d",
9338 evt->vdev_id);
9339 return;
9340 }
9341
Peng Xu8fdaa492016-06-22 10:20:47 -07009342 vendor_event =
9343 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009344 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009345 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9346 GFP_KERNEL);
9347
9348 if (!vendor_event) {
9349 hdd_err("cfg80211_vendor_event_alloc failed");
9350 return;
9351 }
9352
9353 if (nla_put_u32(vendor_event,
9354 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9355 evt->reason_code)) {
9356 hdd_err("nla put failed");
9357 kfree_skb(vendor_event);
9358 return;
9359 }
9360
9361 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009362 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9363 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009364}
9365
9366/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309367 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9368 * @hdd_ctx: HDD context
9369 *
9370 * This function sends the adaptive dwell time config configuration to the
9371 * firmware via WMA
9372 *
9373 * Return: 0 - success, < 0 - failure
9374 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009375static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309376{
9377 QDF_STATUS status;
9378 struct adaptive_dwelltime_params dwelltime_params;
9379
9380 dwelltime_params.is_enabled =
9381 hdd_ctx->config->adaptive_dwell_mode_enabled;
9382 dwelltime_params.dwelltime_mode =
9383 hdd_ctx->config->global_adapt_dwelltime_mode;
9384 dwelltime_params.lpf_weight =
9385 hdd_ctx->config->adapt_dwell_lpf_weight;
9386 dwelltime_params.passive_mon_intval =
9387 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9388 dwelltime_params.wifi_act_threshold =
9389 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9390
9391 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9392 &dwelltime_params);
9393
9394 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9395 if (!QDF_IS_STATUS_SUCCESS(status)) {
9396 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9397 return -EAGAIN;
9398 }
9399 return 0;
9400}
9401
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009402int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309403{
9404 QDF_STATUS status;
9405 struct wmi_dbs_scan_sel_params dbs_scan_params;
9406 uint32_t i = 0;
9407 uint8_t count = 0, numentries = 0;
9408 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9409 * CDS_DBS_SCAN_CLIENTS_MAX];
9410
9411 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009412 if (hdd_ctx->config->dual_mac_feature_disable ==
9413 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309414 return -EINVAL;
9415
9416 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9417 dbs_scan_config, &numentries,
9418 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9419 * CDS_DBS_SCAN_CLIENTS_MAX));
9420
9421 hdd_info("numentries %hu", numentries);
9422 if (!numentries) {
9423 hdd_info("Donot send scan_selection_config");
9424 return 0;
9425 }
9426
9427 /* hdd_set_fw_log_params */
9428 dbs_scan_params.num_clients = 0;
9429 while (count < (numentries - 2)) {
9430 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9431 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9432 dbs_scan_params.num_non_dbs_scans[i] =
9433 dbs_scan_config[count + 2];
9434 dbs_scan_params.num_clients++;
9435 hdd_debug("module:%d NDS:%d NNDS:%d",
9436 dbs_scan_params.module_id[i],
9437 dbs_scan_params.num_dbs_scans[i],
9438 dbs_scan_params.num_non_dbs_scans[i]);
9439 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9440 i++;
9441 }
9442
9443 dbs_scan_params.pdev_id = 0;
9444
9445 hdd_debug("clients:%d pdev:%d",
9446 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9447
9448 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9449 &dbs_scan_params);
9450 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9451 if (!QDF_IS_STATUS_SUCCESS(status)) {
9452 hdd_err("Failed to send DBS Scan selection configuration!");
9453 return -EAGAIN;
9454 }
9455 return 0;
9456}
9457
Arun Khandavallid4349a92016-07-25 11:10:43 +05309458#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9459/**
9460 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9461 * @hdd_ctx: HDD context
9462 *
9463 * Set auto shutdown callback to get indications from firmware to indicate
9464 * userspace to shutdown WLAN after a configured amount of inactivity.
9465 *
9466 * Return: 0 on success and errno on failure.
9467 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009468static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309469{
9470 QDF_STATUS status;
9471
9472 if (!hdd_ctx->config->WlanAutoShutdown)
9473 return 0;
9474
9475 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9476 wlan_hdd_auto_shutdown_cb);
9477 if (status != QDF_STATUS_SUCCESS)
9478 hdd_err("Auto shutdown feature could not be enabled: %d",
9479 status);
9480
9481 return qdf_status_to_os_return(status);
9482}
9483#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009484static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309485{
9486 return 0;
9487}
9488#endif
9489
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009490static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009491{
9492 QDF_STATUS status = QDF_STATUS_SUCCESS;
9493
9494 switch (hdd_ctx->config->dual_mac_feature_disable) {
9495 case DISABLE_DBS_CXN_AND_SCAN:
9496 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9497 if (status != QDF_STATUS_SUCCESS)
9498 hdd_err("Failed to disable dual mac features");
9499 break;
9500 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9501 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9502 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9503 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9504 if (status != QDF_STATUS_SUCCESS)
9505 hdd_err("Failed to set dbs scan and fw mode config");
9506 break;
9507 default:
9508 break;
9509 }
9510
9511 return status;
9512}
9513
Arun Khandavallid4349a92016-07-25 11:10:43 +05309514/**
9515 * hdd_features_init() - Init features
9516 * @hdd_ctx: HDD context
9517 * @adapter: Primary adapter context
9518 *
9519 * Initialize features and their feature context after WLAN firmware is up.
9520 *
9521 * Return: 0 on success and errno on failure.
9522 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009523static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309524{
9525 tSirTxPowerLimit hddtxlimit;
9526 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309527 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309528 int ret;
9529
9530 ENTER();
9531
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009532 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309533 if (ret) {
9534 hdd_err("Failed to update country code: %d", ret);
9535 goto out;
9536 }
9537
9538 /* FW capabilities received, Set the Dot11 mode */
9539 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009540 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9541 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309542
Arun Khandavallid4349a92016-07-25 11:10:43 +05309543
9544 if (hdd_ctx->config->fIsImpsEnabled)
9545 hdd_set_idle_ps_config(hdd_ctx, true);
9546 else
9547 hdd_set_idle_ps_config(hdd_ctx, false);
9548
Poddar, Siddarth37033032017-10-11 15:47:40 +05309549 /* Send Enable/Disable data stall detection cmd to FW */
9550 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9551 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9552
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309553 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009554 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309555
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309556 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9557 hdd_warn("Error in setting Voltage Corner mode config to FW");
9558
Arun Khandavallid4349a92016-07-25 11:10:43 +05309559 if (hdd_lro_init(hdd_ctx))
9560 hdd_err("Unable to initialize LRO in fw");
9561
9562 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9563 hdd_err("Unable to send adaptive dwelltime setting to FW");
9564
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309565 if (hdd_dbs_scan_selection_init(hdd_ctx))
9566 hdd_err("Unable to send DBS scan selection setting to FW");
9567
Arun Khandavallid4349a92016-07-25 11:10:43 +05309568 ret = hdd_init_thermal_info(hdd_ctx);
9569 if (ret) {
9570 hdd_err("Error while initializing thermal information");
9571 goto deregister_frames;
9572 }
9573
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309574 /**
9575 * In case of SSR/PDR, if pktlog was enabled manually before
9576 * SSR/PDR, Then enabled it again automatically after Wlan
9577 * device up.
9578 */
9579 if (cds_is_driver_recovering()) {
9580 if (hdd_ctx->is_pktlog_enabled)
9581 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9582 } else if (cds_is_packet_log_enabled())
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309583 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9584
Arun Khandavallid4349a92016-07-25 11:10:43 +05309585 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9586 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9587 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9588 if (!QDF_IS_STATUS_SUCCESS(status))
9589 hdd_err("Error setting txlimit in sme: %d", status);
9590
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009591 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309592
Arun Khandavallid4349a92016-07-25 11:10:43 +05309593 ret = hdd_register_cb(hdd_ctx);
9594 if (ret) {
9595 hdd_err("Failed to register HDD callbacks!");
9596 goto deregister_frames;
9597 }
9598
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009599 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9600 if (!QDF_IS_STATUS_SUCCESS(status)) {
9601 hdd_err("Failed to set dbs scan and fw mode cfg");
9602 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309603 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009604
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309605 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9606 status = sme_enable_disable_chanavoidind_event(
9607 hdd_ctx->hHal, 0);
9608 if (!QDF_IS_STATUS_SUCCESS(status)) {
9609 hdd_err("Failed to disable Chan Avoidance Indication");
9610 goto deregister_cb;
9611 }
9612 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309613
Manjeet Singha9cae432017-02-28 11:58:22 +05309614 if (hdd_ctx->config->enable_5g_band_pref) {
9615 band_pref_params.rssi_boost_threshold_5g =
9616 hdd_ctx->config->rssi_boost_threshold_5g;
9617 band_pref_params.rssi_boost_factor_5g =
9618 hdd_ctx->config->rssi_boost_factor_5g;
9619 band_pref_params.max_rssi_boost_5g =
9620 hdd_ctx->config->max_rssi_boost_5g;
9621 band_pref_params.rssi_penalize_threshold_5g =
9622 hdd_ctx->config->rssi_penalize_threshold_5g;
9623 band_pref_params.rssi_penalize_factor_5g =
9624 hdd_ctx->config->rssi_penalize_factor_5g;
9625 band_pref_params.max_rssi_penalize_5g =
9626 hdd_ctx->config->max_rssi_penalize_5g;
9627 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9628 }
9629
Arun Khandavallid4349a92016-07-25 11:10:43 +05309630 /* register P2P Listen Offload event callback */
9631 if (wma_is_p2p_lo_capable())
9632 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9633 wlan_hdd_p2p_lo_event_callback);
9634
9635 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9636
9637 if (ret)
9638 goto deregister_cb;
9639
9640 EXIT();
9641 return 0;
9642
9643deregister_cb:
9644 hdd_deregister_cb(hdd_ctx);
9645deregister_frames:
9646 wlan_hdd_cfg80211_deregister_frames(adapter);
9647out:
9648 return -EINVAL;
9649
9650}
9651
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009652/**
9653 * hdd_features_deinit() - Deinit features
9654 * @hdd_ctx: HDD context
9655 *
9656 * De-Initialize features and their feature context.
9657 *
9658 * Return: none.
9659 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009660static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009661{
9662 wlan_hdd_tsf_deinit(hdd_ctx);
9663}
9664
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309665/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009666 * hdd_register_bcn_cb() - register scan beacon callback
9667 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309668 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009669 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309670 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009671static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309672{
9673 QDF_STATUS status;
9674
9675 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9676 wlan_cfg80211_inform_bss_frame,
9677 SCAN_CB_TYPE_INFORM_BCN);
9678 if (!QDF_IS_STATUS_SUCCESS(status)) {
9679 hdd_err("failed with status code %08d [x%08x]",
9680 status, status);
9681 return status;
9682 }
9683
9684 return QDF_STATUS_SUCCESS;
9685}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309686
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309687/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309688 * hdd_configure_cds() - Configure cds modules
9689 * @hdd_ctx: HDD context
9690 * @adapter: Primary adapter context
9691 *
9692 * Enable Cds modules after WLAN firmware is up.
9693 *
9694 * Return: 0 on success and errno on failure.
9695 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009696int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309697{
9698 int ret;
9699 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309700 int set_value;
9701 uint32_t num_abg_tx_chains = 0;
9702 uint32_t num_11b_tx_chains = 0;
9703 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009704 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309705
9706 if (hdd_ctx->config->sifs_burst_duration) {
9707 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9708 hdd_ctx->config->sifs_burst_duration;
9709
9710 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9711 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9712 set_value, PDEV_CMD);
9713 }
9714
9715 if (hdd_ctx->config->is_force_1x1)
9716 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9717 1, PDEV_CMD);
9718 /* set chip power save failure detected callback */
9719 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9720 hdd_chip_pwr_save_fail_detected_cb);
9721
9722 if (hdd_ctx->config->max_mpdus_inampdu) {
9723 set_value = hdd_ctx->config->max_mpdus_inampdu;
9724 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9725 set_value, PDEV_CMD);
9726 }
9727
9728 if (hdd_ctx->config->enable_rts_sifsbursting) {
9729 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9730 sme_cli_set_command(0,
9731 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9732 set_value, PDEV_CMD);
9733 }
9734
9735 if (hdd_ctx->config->sap_get_peer_info) {
9736 set_value = hdd_ctx->config->sap_get_peer_info;
9737 sme_cli_set_command(0,
9738 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9739 set_value, PDEV_CMD);
9740 }
9741
9742 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9743 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9744 if (!hdd_ctx->config->enable2x2) {
9745 if (num_11b_tx_chains > 1)
9746 num_11b_tx_chains = 1;
9747 if (num_11ag_tx_chains > 1)
9748 num_11ag_tx_chains = 1;
9749 }
9750 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9751 num_11b_tx_chains);
9752 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9753 num_11ag_tx_chains);
9754 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9755 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309756
9757 ret = hdd_pre_enable_configure(hdd_ctx);
9758 if (ret) {
9759 hdd_err("Failed to pre-configure cds");
9760 goto out;
9761 }
9762
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009763 /* Always get latest IPA resources allocated from cds_open and configure
9764 * IPA module before configuring them to FW. Sequence required as crash
9765 * observed otherwise.
9766 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009767 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9768 hdd_err("Failed to setup pipes");
9769 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009770 }
9771
Arun Khandavallifae92942016-08-01 13:31:08 +05309772 /*
9773 * Start CDS which starts up the SME/MAC/HAL modules and everything
9774 * else
9775 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009776 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309777
9778 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009779 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309780 goto out;
9781 }
9782
9783 status = hdd_post_cds_enable_config(hdd_ctx);
9784 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009785 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009786 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309787 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309788 status = hdd_register_bcn_cb(hdd_ctx);
9789 if (!QDF_IS_STATUS_SUCCESS(status)) {
9790 hdd_alert("hdd_post_cds_enable_config failed");
9791 goto cds_disable;
9792 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309793
9794 ret = hdd_features_init(hdd_ctx, adapter);
9795 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009796 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309797
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009798 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009799 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009800 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9801 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009802 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009803 goto cds_disable;
9804 }
9805
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309806 if (hdd_enable_egap(hdd_ctx))
9807 hdd_debug("enhance green ap is not enabled");
9808
Nachiket Kukadedd302662017-07-13 17:31:44 +05309809 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9810 hdd_debug("Failed to set wow pulse");
9811
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309812 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9813 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9814
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309815
9816 if (hdd_ctx->config->enable_phy_reg_retention)
9817 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9818 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9819
Arun Khandavallifae92942016-08-01 13:31:08 +05309820 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009821
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009822cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009823 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009824
Arun Khandavallifae92942016-08-01 13:31:08 +05309825out:
9826 return -EINVAL;
9827}
9828
9829/**
9830 * hdd_deconfigure_cds() -De-Configure cds
9831 * @hdd_ctx: HDD context
9832 *
9833 * Deconfigure Cds modules before WLAN firmware is down.
9834 *
9835 * Return: 0 on success and errno on failure.
9836 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009837static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309838{
9839 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009840 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309841
9842 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009843
9844 /* De-init features */
9845 hdd_features_deinit(hdd_ctx);
9846
Arun Khandavallifae92942016-08-01 13:31:08 +05309847 /* De-register the SME callbacks */
9848 hdd_deregister_cb(hdd_ctx);
9849
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009850 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309851 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9852 hdd_err("Failed to Disable the CDS Modules! :%d",
9853 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009854 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309855 }
9856
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309857 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9858 hdd_err("Failed to disconnect pipes");
9859 ret = -EINVAL;
9860 }
9861
Arun Khandavallifae92942016-08-01 13:31:08 +05309862 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009863 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309864}
9865
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009866#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9867static void hdd_deregister_policy_manager_callback(
9868 struct wlan_objmgr_psoc *psoc)
9869{
9870 if (QDF_STATUS_SUCCESS !=
9871 policy_mgr_deregister_hdd_cb(psoc)) {
9872 hdd_err("HDD callback deregister with policy manager failed");
9873 }
9874}
9875#else
9876static void hdd_deregister_policy_manager_callback(
9877 struct wlan_objmgr_psoc *psoc)
9878{
9879}
9880#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309881
9882/**
9883 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9884 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009885 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309886 *
9887 * This function maintains the driver state machine it will be invoked from
9888 * exit, shutdown and con_mode change handler. Depending on the driver state
9889 * shall perform the stopping/closing of the modules.
9890 *
9891 * Return: 0 for success; non-zero for failure
9892 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009893int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309894{
9895 void *hif_ctx;
9896 qdf_device_t qdf_ctx;
9897 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309898 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -08009899 bool is_recovery_stop = cds_is_driver_recovering();
9900 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop;
Dustin Brown70111822017-03-30 15:31:40 -07009901 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309902
9903 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009904 hdd_alert("stop WLAN module: entering driver status=%d",
9905 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309906
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009907 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9908
Arun Khandavallifae92942016-08-01 13:31:08 +05309909 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9910 if (!qdf_ctx) {
9911 hdd_err("QDF device context NULL");
9912 return -EINVAL;
9913 }
9914
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309915 mutex_lock(&hdd_ctx->iface_change_lock);
9916 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009917 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +05309918
Dustin Brown70111822017-03-30 15:31:40 -07009919 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -07009920 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009921 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -07009922 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -07009923
9924 cds_print_external_threads();
9925
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009926 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009927 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -07009928 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
9929 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309930 hdd_prevent_suspend_timeout(
9931 hdd_ctx->config->iface_change_wait_time,
9932 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009933 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009934 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -07009935 return 0;
9936 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009937 }
9938
Arun Khandavallifae92942016-08-01 13:31:08 +05309939 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9940
Kabilan Kannan6edafeb2017-11-16 16:34:34 -08009941 /* free user wowl patterns */
9942 hdd_free_user_wowl_ptrns();
9943
Arun Khandavallifae92942016-08-01 13:31:08 +05309944 switch (hdd_ctx->driver_status) {
9945 case DRIVER_MODULES_UNINITIALIZED:
9946 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309947 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309948 case DRIVER_MODULES_CLOSED:
9949 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309950 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309951 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -08009952 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
9953
Komal Seelamf2136bb2016-09-28 18:30:44 +05309954 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309955 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009956 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309957 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309958 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309959 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009960 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -08009961
Arun Khandavallifae92942016-08-01 13:31:08 +05309962 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08009963 hdd_info("Wlan transitioned (now OPENED)");
9964
9965 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +05309966 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08009967 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05309968 break;
9969 default:
9970 hdd_err("Trying to stop wlan in a wrong state: %d",
9971 hdd_ctx->driver_status);
9972 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309973 ret = -EINVAL;
9974 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309975 }
9976
Dustin Brown550f6d22017-12-14 15:44:01 -08009977 hdd_debug("Closing CDS modules!");
Rajeev Kumarbe021242017-02-16 16:12:23 -08009978 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309979 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9980 hdd_err("Failed to process post CDS disable Modules! :%d",
9981 qdf_status);
9982 ret = -EINVAL;
9983 QDF_ASSERT(0);
9984 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009985
psimhadeea0a12017-12-18 14:50:02 -08009986 hdd_runtime_suspend_context_deinit(hdd_ctx);
9987
Dustin Brownbd68fe12017-11-21 15:28:52 -08009988 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
9989 if (ret) {
9990 hdd_err("Failed to destroy pdev; errno:%d", ret);
9991 QDF_ASSERT(0);
9992 }
9993
9994 /*
9995 * Reset total mac phy during module stop such that during
9996 * next module start same psoc is used to populate new service
9997 * ready data
9998 */
9999 hdd_ctx->hdd_psoc->total_mac_phy = 0;
10000
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010001 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10002 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10003 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10004 ret = -EINVAL;
10005 QDF_ASSERT(0);
10006 }
10007
Jeff Johnsone4b14592017-09-13 14:23:33 -070010008 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010009 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010010 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010011 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010012 QDF_ASSERT(0);
10013 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010014
Arun Khandavallifae92942016-08-01 13:31:08 +053010015 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10016 if (!hif_ctx) {
10017 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010018 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010019 }
10020
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010021 if (hdd_ctx->target_hw_name) {
10022 qdf_mem_free(hdd_ctx->target_hw_name);
10023 hdd_ctx->target_hw_name = NULL;
10024 }
10025
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010026 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010027
10028 ol_cds_free();
10029
Dustin Brown70111822017-03-30 15:31:40 -070010030 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010031 ret = pld_power_off(qdf_ctx->dev);
10032 if (ret)
10033 hdd_err("CNSS power down failed put device into Low power mode:%d",
10034 ret);
10035 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010036
Dustin Brown4bc0a622017-12-06 15:56:50 -080010037 /* many adapter resources are not freed by design in SSR case */
10038 if (!is_recovery_stop)
10039 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010040 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010041
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010042 /* Once the firmware sequence is completed reset this flag */
10043 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010044 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010045 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010046
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010047done:
10048 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010049 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010050 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010051 hdd_alert("stop WLAN module: exit driver status=%d",
10052 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010053
Arun Khandavallifae92942016-08-01 13:31:08 +053010054 EXIT();
10055
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010056 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010057}
10058
Arun Khandavallifae92942016-08-01 13:31:08 +053010059
10060/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010061 * hdd_state_info_dump() - prints state information of hdd layer
10062 * @buf: buffer pointer
10063 * @size: size of buffer to be filled
10064 *
10065 * This function is used to dump state information of hdd layer
10066 *
10067 * Return: None
10068 */
10069static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10070{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010071 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010072 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010073 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010074 uint16_t len = 0;
10075 char *buf = *buf_ptr;
10076
10077 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10078 if (!hdd_ctx) {
10079 hdd_err("Failed to get hdd context ");
10080 return;
10081 }
10082
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010083 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010084
10085 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010086 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010087 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010088 "\n is_scheduler_suspended %d",
10089 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010090
Dustin Brown920397d2017-12-13 16:27:50 -080010091 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010092 if (adapter->dev)
10093 len += scnprintf(buf + len, *size - len,
10094 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010095 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010096 "\n device_mode: %d", adapter->device_mode);
10097 switch (adapter->device_mode) {
10098 case QDF_STA_MODE:
10099 case QDF_P2P_CLIENT_MODE:
10100 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10101 len += scnprintf(buf + len, *size - len,
10102 "\n connState: %d",
10103 hdd_sta_ctx->conn_info.connState);
10104 break;
10105
10106 default:
10107 break;
10108 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010109 }
10110
10111 *size -= len;
10112 *buf_ptr += len;
10113}
10114
10115/**
10116 * hdd_register_debug_callback() - registration function for hdd layer
10117 * to print hdd state information
10118 *
10119 * Return: None
10120 */
10121static void hdd_register_debug_callback(void)
10122{
10123 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10124}
10125
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010126/*
10127 * wlan_init_bug_report_lock() - Initialize bug report lock
10128 *
10129 * This function is used to create bug report lock
10130 *
10131 * Return: None
10132 */
10133static void wlan_init_bug_report_lock(void)
10134{
10135 p_cds_contextType p_cds_context;
10136
10137 p_cds_context = cds_get_global_context();
10138 if (!p_cds_context) {
10139 hdd_err("cds context is NULL");
10140 return;
10141 }
10142
10143 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10144}
10145
Mohit Khannaf8f96822017-05-17 17:11:59 -070010146void hdd_dp_trace_init(struct hdd_config *config)
10147{
10148
10149 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10150 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10151 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10152 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10153 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10154 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10155 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010156 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010157
10158 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10159 &num_entries, sizeof(config_params));
10160
10161 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010162 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010163 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010164 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010165 else if (bw_compute_interval > 1000) {
10166 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10167 thresh_time_limit = 1;
10168 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010169 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10170
10171 switch (num_entries) {
10172 case 4:
10173 proto_bitmap = config_params[3];
10174 case 3:
10175 verbosity = config_params[2];
10176 case 2:
10177 thresh = config_params[1];
10178 case 1:
10179 live_mode = config_params[0];
10180 default:
10181 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
10182 live_mode, thresh, thresh_time_limit,
10183 verbosity, proto_bitmap);
10184 };
10185
10186 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10187 verbosity, proto_bitmap);
10188
10189}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010190/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010191 * hdd_wlan_startup() - HDD init function
10192 * @dev: Pointer to the underlying device
10193 *
10194 * This is the driver startup code executed once a WLAN device has been detected
10195 *
10196 * Return: 0 for success, < 0 for failure
10197 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010198int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010199{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010200 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010201 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010202 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010203 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010204
10205 ENTER();
10206
Arun Khandavallifae92942016-08-01 13:31:08 +053010207 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010208
10209 if (IS_ERR(hdd_ctx))
10210 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010211
Abhishek Singhe9068f12017-03-31 14:14:52 +053010212 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10213 DEFAULT_PSOC_ID);
10214 if (ret) {
10215 hdd_err("Psoc creation fails!");
10216 QDF_BUG(0);
10217 goto err_hdd_free_context;
10218 }
10219
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010220 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010221#ifdef FEATURE_WLAN_CH_AVOID
10222 mutex_init(&hdd_ctx->avoid_freq_lock);
10223#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010224
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010225 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -070010226 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010227
Dustin Brown021cecd2017-12-11 13:56:43 -080010228 hdd_driver_memdump_init();
10229
Jeff Johnson957bc272017-02-02 08:54:48 -080010230 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010231 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010232 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010233 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010234 }
10235
Yingying Tang80e15f32016-09-27 18:23:01 +080010236 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010237
Anurag Chouhan6d760662016-02-20 16:05:43 +053010238 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010239
10240 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010241 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010242 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010243 }
10244
Prashanth Bhatta07998752016-04-28 12:35:33 -070010245 ret = hdd_wiphy_init(hdd_ctx);
10246 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010247 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010248 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010249 }
10250
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010251 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010252 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010253
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010254 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010255 goto err_wiphy_unregister;
10256
Kapil Gupta4f0c0c12017-02-07 15:21:15 +053010257 wlan_hdd_init_chan_info(hdd_ctx);
10258
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010259 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010260
Paul Zhangfb02f452017-12-22 11:58:43 +080010261 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10262 if (ret) {
10263 hdd_err("register_netdevice_notifier failed: %d", ret);
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010264 goto err_ipa_cleanup;
Paul Zhangfb02f452017-12-22 11:58:43 +080010265 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010266
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010267 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010268
Jeff Johnson957bc272017-02-02 08:54:48 -080010269 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10270 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010271 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010272 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010273 }
10274
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010275 hdd_release_rtnl_lock();
10276 rtnl_held = false;
10277
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010278 wlan_hdd_update_11n_mode(hdd_ctx->config);
10279
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010280#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010281 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010282 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010283 hdd_skip_acs_scan_timer_handler,
10284 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010285 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010286 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010287 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010288#endif
10289
Prashanth Bhattaab004382016-10-11 16:08:11 -070010290 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010291
Jeff Johnson9afc5012016-09-23 13:56:27 -070010292 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010293
Nirav Shahbd36b062016-07-18 11:12:59 +053010294 if (hdd_ctx->rps)
10295 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010296
Paul Zhangfb02f452017-12-22 11:58:43 +080010297 ret = hdd_register_notifiers(hdd_ctx);
10298 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010299 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010300
Paul Zhangfb02f452017-12-22 11:58:43 +080010301 status = wlansap_global_init();
10302 if (QDF_IS_STATUS_ERROR(status)) {
10303 hdd_unregister_notifiers(hdd_ctx);
10304 goto err_close_adapters;
10305 }
10306
Arun Khandavallifae92942016-08-01 13:31:08 +053010307 if (hdd_ctx->config->fIsImpsEnabled)
10308 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010309 else
10310 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010311
Mukul Sharma07bd8752017-10-10 16:58:14 +053010312 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010313 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10314 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010315 hdd_prevent_suspend_timeout(
10316 hdd_ctx->config->iface_change_wait_time,
10317 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10318 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010319
Sachin Ahujadddd2632017-03-07 19:07:24 +053010320 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010321 goto success;
10322
Jeff Johnson957bc272017-02-02 08:54:48 -080010323err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010324 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010325
Jeff Johnson46bde382017-02-01 15:31:16 -080010326err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010327 if (rtnl_held)
10328 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010329
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010330 unregister_netdevice_notifier(&hdd_netdev_notifier);
10331
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010332err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010333 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010334
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010335err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010336 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010337
Arun Khandavallifae92942016-08-01 13:31:08 +053010338err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010339 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010340
Dustin Brown021cecd2017-12-11 13:56:43 -080010341err_memdump_deinit:
10342 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010343
Houston Hoffman47a4a052016-11-14 23:22:44 -080010344 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010345 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010346 hdd_exit_netlink_services(hdd_ctx);
10347
Dustin Brown20912462017-06-07 13:48:25 -070010348 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10349
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010350err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010351 if (cds_is_fw_down())
10352 hdd_err("Not setting the complete event as fw is down");
10353 else
10354 hdd_start_complete(ret);
10355
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010356 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010357 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010358 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010359
10360success:
10361 EXIT();
10362 return 0;
10363}
10364
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010365/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010366 * hdd_wlan_update_target_info() - update target type info
10367 * @hdd_ctx: HDD context
10368 * @context: hif context
10369 *
10370 * Update target info received from firmware in hdd context
10371 * Return:None
10372 */
10373
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010374void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010375{
10376 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10377
10378 if (!tgt_info) {
10379 hdd_err("Target info is Null");
10380 return;
10381 }
10382
10383 hdd_ctx->target_type = tgt_info->target_type;
10384}
10385
10386/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010387 * hdd_get_nud_stats_cb() - callback api to update the stats
10388 * received from the firmware
10389 * @data: pointer to adapter.
10390 * @rsp: pointer to data received from FW.
10391 *
10392 * This is called when wlan driver received response event for
10393 * get arp stats to firmware.
10394 *
10395 * Return: None
10396 */
10397static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10398{
10399 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10400 struct hdd_nud_stats_context *context;
10401 int status;
10402 struct hdd_adapter *adapter = NULL;
10403
10404 ENTER();
10405
10406 if (!rsp) {
10407 hdd_err("data is null");
10408 return;
10409 }
10410
10411 status = wlan_hdd_validate_context(hdd_ctx);
10412 if (0 != status)
10413 return;
10414
10415 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10416 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10417 hdd_err("Invalid adapter or adapter has invalid magic");
10418 return;
10419 }
10420
10421 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10422 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10423 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10424 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10425 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10426 rsp->out_of_order_arp_rsp_drop_cnt);
10427 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10428 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10429 hdd_notice("rsp->ba_session_establishment_status :%x",
10430 rsp->ba_session_establishment_status);
10431
10432 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10433 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10434 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10435 adapter->dad |= rsp->dad_detected;
10436 adapter->con_status = rsp->connect_status;
10437
10438 spin_lock(&hdd_context_lock);
10439 context = &hdd_ctx->nud_stats_context;
10440 complete(&context->response_event);
10441 spin_unlock(&hdd_context_lock);
10442
10443 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010444}
10445
10446/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010447 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010448 * @hdd_ctx: HDD context
10449 *
10450 * Register the HDD callbacks to CDS/SME.
10451 *
10452 * Return: 0 for success or Error code for failure
10453 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010454int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010455{
10456 QDF_STATUS status;
10457 int ret = 0;
10458
10459 ENTER();
10460
10461 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10462
10463 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10464 hdd_send_oem_data_rsp_msg);
10465
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010466 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10467 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010468 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10469 sme_nan_register_callback(hdd_ctx->hHal,
10470 wlan_hdd_cfg80211_nan_callback);
10471 sme_stats_ext_register_callback(hdd_ctx->hHal,
10472 wlan_hdd_cfg80211_stats_ext_callback);
10473
10474 sme_ext_scan_register_callback(hdd_ctx->hHal,
10475 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010476 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10477 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010478
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010479 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10480 hdd_rssi_threshold_breached);
10481
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010482 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10483
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010484 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10485 wlan_hdd_cfg80211_link_layer_stats_callback);
10486
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010487 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10488
Zhang Qianca38fb12016-12-23 11:10:48 +080010489 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10490 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10491
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010492 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10493 hdd_lost_link_info_cb);
10494 /* print error and not block the startup process */
10495 if (!QDF_IS_STATUS_SUCCESS(status))
10496 hdd_err("set lost link info callback failed");
10497
Poddar, Siddarth34872782017-08-10 14:08:51 +053010498 ret = hdd_register_data_stall_detect_cb();
10499 if (ret) {
10500 hdd_err("Register data stall detect detect callback failed.");
10501 return ret;
10502 }
10503
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010504 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10505
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010506 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010507 hdd_set_connection_in_progress,
10508 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010509
10510 status = sme_congestion_register_callback(hdd_ctx->hHal,
10511 hdd_update_cca_info_cb);
10512 if (!QDF_IS_STATUS_SUCCESS(status))
10513 hdd_err("set congestion callback failed");
10514
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010515 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10516 hdd_bt_activity_cb);
10517 if (!QDF_IS_STATUS_SUCCESS(status))
10518 hdd_err("set bt activity info callback failed");
10519
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010520 EXIT();
10521
10522 return ret;
10523}
10524
10525/**
10526 * hdd_deregister_cb() - De-Register HDD callbacks.
10527 * @hdd_ctx: HDD context
10528 *
10529 * De-Register the HDD callbacks to CDS/SME.
10530 *
10531 * Return: void
10532 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010533void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010534{
10535 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010536 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010537
10538 ENTER();
10539
10540 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10541 if (!QDF_IS_STATUS_SUCCESS(status))
10542 hdd_err("De-register of dcc stats callback failed: %d",
10543 status);
10544
10545 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010546 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10547
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010548 sme_stats_ext_register_callback(hdd_ctx->hHal,
10549 wlan_hdd_cfg80211_stats_ext_callback);
10550
10551 sme_nan_deregister_callback(hdd_ctx->hHal);
10552 status = sme_reset_tsfcb(hdd_ctx->hHal);
10553 if (!QDF_IS_STATUS_SUCCESS(status))
10554 hdd_err("Failed to de-register tsfcb the callback:%d",
10555 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010556
Poddar, Siddarth34872782017-08-10 14:08:51 +053010557 ret = hdd_deregister_data_stall_detect_cb();
10558 if (ret)
10559 hdd_err("Failed to de-register data stall detect event callback");
10560
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010561 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10562 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10563
10564 EXIT();
10565}
10566
10567/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010568 * hdd_softap_sta_deauth() - handle deauth req from HDD
10569 * @adapter: Pointer to the HDD
10570 * @enable: bool value
10571 *
10572 * This to take counter measure to handle deauth req from HDD
10573 *
10574 * Return: None
10575 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010576QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010577 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010578{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010579 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010580
10581 ENTER();
10582
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010583 /* Ignore request to deauth bcmc station */
10584 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010585 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010586
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010587 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010588 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10589 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010590
10591 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010592 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010593}
10594
10595/**
10596 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10597 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010598 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010599 *
10600 * This to take counter measure to handle deauth req from HDD
10601 *
10602 * Return: None
10603 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010604void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010605 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010606{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010607 ENTER();
10608
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010609 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010610 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010611 return;
10612
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010613 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010614 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010615}
10616
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010617/**
10618 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10619 * @hdd_ctx: HDD Context
10620 *
10621 * API to find if there is any STA or P2P-Client is connected
10622 *
10623 * Return: true if connected; false otherwise
10624 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010625QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010626{
10627 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10628}
10629
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010630/**
10631 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10632 * @adapter: HDD adapter pointer
10633 *
10634 * This function loop through each adapter and disable roaming on each STA
10635 * device mode except the input adapter.
10636 *
10637 * Note: On the input adapter roaming is not enabled yet hence no need to
10638 * disable.
10639 *
10640 * Return: None
10641 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010642void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010643{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010644 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010645 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010646
10647 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010648 hdd_ctx->config->isRoamOffloadScanEnabled &&
10649 QDF_STA_MODE == adapter->device_mode &&
10650 policy_mgr_is_sta_active_connection_exists(
10651 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010652 hdd_debug("Connect received on STA session Id(%d)",
10653 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010654 /*
10655 * Loop through adapter and disable roaming for each STA device
10656 * mode except the input adapter.
10657 */
Dustin Brown920397d2017-12-13 16:27:50 -080010658 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010659 if (QDF_STA_MODE == adapterIdx->device_mode &&
10660 adapter->session_id != adapterIdx->session_id) {
10661 hdd_debug("Disable Roaming on session Id(%d)",
10662 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010663 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10664 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010665 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010666 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010667 }
10668 }
10669}
10670
10671/**
10672 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10673 * @adapter: HDD adapter pointer
10674 *
10675 * This function loop through each adapter and enable roaming on each STA
10676 * device mode except the input adapter.
10677 * Note: On the input adapter no need to enable roaming because link got
10678 * disconnected on this.
10679 *
10680 * Return: None
10681 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010682void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010683{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010684 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010685 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010686
10687 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010688 hdd_ctx->config->isRoamOffloadScanEnabled &&
10689 QDF_STA_MODE == adapter->device_mode &&
10690 policy_mgr_is_sta_active_connection_exists(
10691 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010692 hdd_debug("Disconnect received on STA session Id(%d)",
10693 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010694 /*
10695 * Loop through adapter and enable roaming for each STA device
10696 * mode except the input adapter.
10697 */
Dustin Brown920397d2017-12-13 16:27:50 -080010698 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010699 if (QDF_STA_MODE == adapterIdx->device_mode &&
10700 adapter->session_id != adapterIdx->session_id) {
10701 hdd_debug("Enabling Roaming on session Id(%d)",
10702 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010703 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10704 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010705 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010706 REASON_CONNECT);
10707 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010708 }
10709 }
10710}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010711
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010712/**
10713 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10714 * @skb: sk buffer pointer
10715 *
10716 * Sends the bcast message to SVC multicast group with generic nl socket
10717 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10718 *
10719 * Return: None
10720 */
10721static void nl_srv_bcast_svc(struct sk_buff *skb)
10722{
10723#ifdef CNSS_GENL
10724 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10725#else
10726 nl_srv_bcast(skb);
10727#endif
10728}
10729
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010730void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010731{
10732 struct sk_buff *skb;
10733 struct nlmsghdr *nlh;
10734 tAniMsgHdr *ani_hdr;
10735 void *nl_data = NULL;
10736 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010737 struct radio_index_tlv *radio_info;
10738 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010739
10740 if (in_interrupt() || irqs_disabled() || in_atomic())
10741 flags = GFP_ATOMIC;
10742
10743 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10744
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010745 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010746 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010747
10748 nlh = (struct nlmsghdr *)skb->data;
10749 nlh->nlmsg_pid = 0; /* from kernel */
10750 nlh->nlmsg_flags = 0;
10751 nlh->nlmsg_seq = 0;
10752 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10753
10754 ani_hdr = NLMSG_DATA(nlh);
10755 ani_hdr->type = type;
10756
10757 switch (type) {
10758 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010759 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010760 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010761 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010762 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010763 ani_hdr->length = 0;
10764 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010765 break;
10766 case WLAN_SVC_WLAN_STATUS_IND:
10767 case WLAN_SVC_WLAN_VERSION_IND:
10768 case WLAN_SVC_DFS_CAC_START_IND:
10769 case WLAN_SVC_DFS_CAC_END_IND:
10770 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10771 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10772 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010773 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010774 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010775 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010776 ani_hdr->length = len;
10777 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10778 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10779 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780 break;
10781
10782 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010783 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010784 type);
10785 kfree_skb(skb);
10786 return;
10787 }
10788
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010789 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010790 * Add radio index at the end of the svc event in TLV format
10791 * to maintain the backward compatibility with userspace
10792 * applications.
10793 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010794
10795 tlv_len = 0;
10796
10797 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10798 < WLAN_NL_MAX_PAYLOAD) {
10799 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10800 sizeof(*ani_hdr) + len);
10801 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10802 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10803 radio_info->radio = radio;
10804 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010805 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010806 "Added radio index tlv - radio index %d",
10807 radio_info->radio);
10808 }
10809
10810 nlh->nlmsg_len += tlv_len;
10811 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10812
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010813 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010814}
10815
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010816#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10817void wlan_hdd_auto_shutdown_cb(void)
10818{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010819 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010820
10821 if (!hdd_ctx)
10822 return;
10823
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010824 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010825 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10826 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010827}
10828
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010829void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010830{
Jeff Johnson9d295242017-08-29 14:39:48 -070010831 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010832 bool ap_connected = false, sta_connected = false;
10833 tHalHandle hal_handle;
10834
10835 hal_handle = hdd_ctx->hHal;
10836 if (hal_handle == NULL)
10837 return;
10838
10839 if (hdd_ctx->config->WlanAutoShutdown == 0)
10840 return;
10841
10842 if (enable == false) {
10843 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010844 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010845 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010846 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010847 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010848 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010849 return;
10850 }
10851
10852 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080010853 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
10854 hdd_for_each_adapter(hdd_ctx, adapter) {
10855 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010856 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10857 conn_info.connState ==
10858 eConnectionState_Associated) {
10859 sta_connected = true;
10860 break;
10861 }
10862 }
Dustin Brown920397d2017-12-13 16:27:50 -080010863
10864 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010865 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070010866 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010867 ap_connected = true;
10868 break;
10869 }
10870 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010871 }
10872 }
10873
10874 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010875 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010876 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010877 }
Jeff Johnson68755312017-02-10 11:46:55 -080010878
10879 if (sme_set_auto_shutdown_timer(hal_handle,
10880 hdd_ctx->config->WlanAutoShutdown)
10881 != QDF_STATUS_SUCCESS)
10882 hdd_err("Failed to start wlan auto shutdown timer");
10883 else
10884 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10885 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010886}
10887#endif
10888
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010889struct hdd_adapter *
10890hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10891 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010892{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010893 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010894 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010895
10896 con_sap_adapter = NULL;
10897
Dustin Brown920397d2017-12-13 16:27:50 -080010898 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010899 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10900 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010901 adapter != this_sap_adapter) {
10902 if (check_start_bss) {
10903 if (test_bit(SOFTAP_BSS_STARTED,
10904 &adapter->event_flags)) {
10905 con_sap_adapter = adapter;
10906 break;
10907 }
10908 } else {
10909 con_sap_adapter = adapter;
10910 break;
10911 }
10912 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010913 }
10914
10915 return con_sap_adapter;
10916}
10917
10918#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010919static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010920{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010921 return adapter->device_mode == QDF_STA_MODE ||
10922 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010923}
10924
Jeff Johnson9d295242017-08-29 14:39:48 -070010925static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010926{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010927 return adapter->device_mode == QDF_SAP_MODE ||
10928 adapter->device_mode == QDF_P2P_GO_MODE;
10929}
10930
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010931static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010932{
Dustin Brown920397d2017-12-13 16:27:50 -080010933 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010934
Dustin Brown920397d2017-12-13 16:27:50 -080010935 hdd_for_each_adapter(hdd_ctx, adapter) {
10936 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070010937 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10938 conn_info.connState == eConnectionState_Associated) {
10939 return true;
10940 }
10941
Dustin Brown920397d2017-12-13 16:27:50 -080010942 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070010943 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070010944 return true;
10945 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010946 }
10947
10948 return false;
10949}
10950
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010951static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010952{
10953 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010954
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010955 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010956 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010957 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010958
Dustin Brown5ec6b552017-03-31 12:11:40 -070010959 return is_running;
10960}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010961
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010962static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010963{
10964 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10965 hdd_ctx->bus_bw_timer_running = true;
10966 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10967 hdd_ctx->config->busBandwidthComputeInterval);
10968 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10969}
10970
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010971void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010972{
10973 ENTER();
10974
10975 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10976 hdd_debug("Bandwidth compute timer already started");
10977 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010978 }
10979
Dustin Brown5ec6b552017-03-31 12:11:40 -070010980 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10981
10982 EXIT();
10983}
10984
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010985void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010986{
10987 ENTER();
10988
10989 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10990 hdd_debug("Bandwidth compute timer already started");
10991 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010992 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010993
10994 if (hdd_any_adapter_is_assoc(hdd_ctx))
10995 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10996
10997 EXIT();
10998}
10999
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011000static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011001{
11002 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
11003
11004 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11005 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11006 hdd_ctx->bus_bw_timer_running = false;
11007 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11008
11009 hdd_reset_tcp_delack(hdd_ctx);
11010}
11011
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011012void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011013{
11014 ENTER();
11015
11016 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11017 hdd_debug("Bandwidth compute timer already stopped");
11018 return;
11019 }
11020
11021 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11022
11023 EXIT();
11024}
11025
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011026void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011027{
11028 ENTER();
11029
11030 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11031 hdd_debug("Bandwidth compute timer already stopped");
11032 return;
11033 }
11034
11035 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11036 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11037
11038 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011039}
11040#endif
11041
11042/**
11043 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11044 * and sta's operating channel.
11045 * @sta_adapter: Describe the first argument to foobar.
11046 * @ap_adapter: Describe the second argument to foobar.
11047 * @roam_profile: Roam profile of AP to which STA wants to connect.
11048 * @concurrent_chnl_same: If both SAP and STA channels are same then
11049 * set this flag to true else false.
11050 *
11051 * This function checks the sap's operating channel and sta's operating channel.
11052 * if both are same then it will return false else it will restart the sap in
11053 * sta's channel and return true.
11054 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011055 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011056 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011057QDF_STATUS
11058wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11059 struct hdd_adapter *ap_adapter,
11060 tCsrRoamProfile *roam_profile,
11061 tScanResultHandle *scan_cache,
11062 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011063{
Jeff Johnson87251032017-08-29 13:31:11 -070011064 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011065 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011066 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011067 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011068 *concurrent_chnl_same = true;
11069
11070 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11071 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011072 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011073 scan_cache,
11074 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011075 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011076 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011077 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011078 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011079 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011080 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011081 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011082 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011083 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011084 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011085 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011086 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011087 }
11088 }
11089 } else {
11090 /*
11091 * Lets handle worst case scenario here, Scan cache lookup is
11092 * failed so we have to stop the SAP to avoid any channel
11093 * discrepancy between SAP's channel and STA's channel.
11094 * Return the status as failure so caller function could know
11095 * that scan look up is failed.
11096 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011097 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011098 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011099 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011100 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011101}
11102
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011103/**
11104 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11105 * @ap_adapter: SAP adapter
11106 *
11107 * This function will process the stopping of sap adapter.
11108 *
11109 * Return: None
11110 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011111void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011112{
Jeff Johnson87251032017-08-29 13:31:11 -070011113 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011114 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011115 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011116 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011117
11118 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011119 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011120 return;
11121 }
11122
11123 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11124 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011125 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011126 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011127
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011128 mutex_lock(&hdd_ctx->sap_lock);
11129 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011130 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011131 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011132 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011133 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011134 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011135 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011136 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011137 qdf_stop_bss_event,
11138 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011139 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011140 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011141 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011142 return;
11143 }
11144 }
11145 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011146 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11147 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011148 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011149 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011150 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011151 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011152 }
11153 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011154}
11155
11156/**
11157 * wlan_hdd_start_sap() - this function starts bss of SAP.
11158 * @ap_adapter: SAP adapter
11159 *
11160 * This function will process the starting of sap adapter.
11161 *
11162 * Return: None
11163 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011164void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011165{
Jeff Johnson87251032017-08-29 13:31:11 -070011166 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011167 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011168 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011169 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011170 tsap_Config_t *sap_config;
11171
11172 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011173 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011174 return;
11175 }
11176
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011177 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011178 hdd_err("SoftAp role has not been enabled");
11179 return;
11180 }
11181
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011182 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11183 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11184 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011185 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011186
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011187 mutex_lock(&hdd_ctx->sap_lock);
11188 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11189 goto end;
11190
11191 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011192 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011193 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
11194 goto end;
11195 }
11196
Wei Song2f76f642016-11-18 16:32:53 +080011197 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011198 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011199 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011200 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011201 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011202 goto end;
11203
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011204 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011205 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011206 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011207 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011208 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011209 goto end;
11210 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011211 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011212 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011213 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011214 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11215 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011216 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011217 mutex_unlock(&hdd_ctx->sap_lock);
11218
11219 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011220end:
11221 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011222 /* SAP context and beacon cleanup will happen during driver unload
11223 * in hdd_stop_adapter
11224 */
11225 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011227}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011228
11229/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011230 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11231 * mac scan config
11232 * @status: Status of set antenna mode
11233 *
11234 * Callback on setting the dual mac configuration
11235 *
11236 * Return: None
11237 */
11238void wlan_hdd_soc_set_antenna_mode_cb(
11239 enum set_antenna_mode_status status)
11240{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011241 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011242
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011243 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011244
11245 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11246 if (0 != wlan_hdd_validate_context(hdd_ctx))
11247 return;
11248
11249 /* Signal the completion of set dual mac config */
11250 complete(&hdd_ctx->set_antenna_mode_cmpl);
11251}
11252
11253/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011254 * hdd_get_fw_version() - Get FW version
11255 * @hdd_ctx: pointer to HDD context.
11256 * @major_spid: FW version - major spid.
11257 * @minor_spid: FW version - minor spid
11258 * @ssid: FW version - ssid
11259 * @crmid: FW version - crmid
11260 *
11261 * This function is called to get the firmware build version stored
11262 * as part of the HDD context
11263 *
11264 * Return: None
11265 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011266void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011267 uint32_t *major_spid, uint32_t *minor_spid,
11268 uint32_t *siid, uint32_t *crmid)
11269{
11270 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11271 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11272 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11273 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11274}
11275
11276#ifdef QCA_CONFIG_SMP
11277/**
11278 * wlan_hdd_get_cpu() - get cpu_index
11279 *
11280 * Return: cpu_index
11281 */
11282int wlan_hdd_get_cpu(void)
11283{
11284 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011285
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011286 put_cpu();
11287 return cpu_index;
11288}
11289#endif
11290
11291/**
11292 * hdd_get_fwpath() - get framework path
11293 *
11294 * This function is used to get the string written by
11295 * userspace to start the wlan driver
11296 *
11297 * Return: string
11298 */
11299const char *hdd_get_fwpath(void)
11300{
11301 return fwpath.string;
11302}
11303
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011304static int hdd_qdf_print_init(void)
11305{
11306 int qdf_print_idx;
11307 QDF_STATUS status;
11308
11309 status = qdf_print_setup();
11310 if (status != QDF_STATUS_SUCCESS) {
11311 pr_err("qdf_print_setup failed\n");
11312 return -EINVAL;
11313 }
11314
11315 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11316
11317 if (qdf_print_idx < 0) {
11318 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11319 qdf_print_idx);
11320 return -EINVAL;
11321 }
11322
11323 qdf_set_pidx(qdf_print_idx);
11324
11325 return 0;
11326}
11327
11328static void hdd_qdf_print_deinit(void)
11329{
11330 int qdf_print_idx;
11331
11332 qdf_print_idx = qdf_get_pidx();
11333 qdf_print_ctrl_cleanup(qdf_print_idx);
11334}
11335
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011336/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011337 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011338 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011339 * This function initilizes CDS global context with the help of cds_init. This
11340 * has to be the first function called after probe to get a valid global
11341 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011342 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011343 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011344 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011345int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011346{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011347 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011348 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011349
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011350 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011351 if (QDF_IS_STATUS_ERROR(status)) {
11352 hdd_err("Failed to allocate CDS context");
11353 ret = -ENOMEM;
11354 goto err_out;
11355 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011356
11357 wlan_init_bug_report_lock();
11358
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011359#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11360 wlan_logging_sock_init_svc();
11361#endif
11362
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011363 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11364 (void *)hdd_drv_ops_inactivity_handler, NULL,
11365 QDF_TIMER_TYPE_SW);
11366
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011367 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011368 hdd_qdf_print_init();
11369
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011370 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011371
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011372err_out:
11373 return ret;
11374}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011375
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011376/**
11377 * hdd_deinit() - Deinitialize Driver
11378 *
11379 * This function frees CDS global context with the help of cds_deinit. This
11380 * has to be the last function call in remove callback to free the global
11381 * context.
11382 */
11383void hdd_deinit(void)
11384{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011385 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011386
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011387 wlan_destroy_bug_report_lock();
11388 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011389
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011390 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011391#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11392 wlan_logging_sock_deinit_svc();
11393#endif
11394}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011395
Yue Ma6e7b1a02017-04-03 14:17:46 -070011396#ifdef QCA_WIFI_NAPIER_EMULATION
11397#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11398#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011399#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011400#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011401
Sachin Ahujadddd2632017-03-07 19:07:24 +053011402static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11403 struct file *file)
11404{
11405 return 0;
11406}
11407
11408static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11409 const char __user *user_buf,
11410 size_t count,
11411 loff_t *f_pos)
11412{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011413 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011414 static const char wlan_off_str[] = "OFF";
11415 static const char wlan_on_str[] = "ON";
11416 int ret;
11417 unsigned long rc;
11418
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011419 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011420 pr_err("Failed to read buffer\n");
11421 return -EINVAL;
11422 }
11423
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011424 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011425 pr_debug("Wifi turning off from UI\n");
11426 goto exit;
11427 }
11428
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011429 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011430 pr_err("Invalid value received from framework");
11431 goto exit;
11432 }
11433
11434 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011435 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011436 rc = wait_for_completion_timeout(&wlan_start_comp,
11437 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11438 if (!rc) {
11439 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11440 ret = -EINVAL;
11441 hdd_start_complete(ret);
11442 return ret;
11443 }
11444
11445 hdd_start_complete(0);
11446 }
11447
11448exit:
11449 return count;
11450}
11451
11452
11453const struct file_operations wlan_hdd_state_fops = {
11454 .owner = THIS_MODULE,
11455 .open = wlan_hdd_state_ctrl_param_open,
11456 .write = wlan_hdd_state_ctrl_param_write,
11457};
11458
11459static int wlan_hdd_state_ctrl_param_create(void)
11460{
11461 unsigned int wlan_hdd_state_major = 0;
11462 int ret;
11463 struct device *dev;
11464
11465 device = MKDEV(wlan_hdd_state_major, 0);
11466
11467 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11468 if (ret) {
11469 pr_err("Failed to register qcwlanstate");
11470 goto dev_alloc_err;
11471 }
11472 wlan_hdd_state_major = MAJOR(device);
11473
11474 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11475 if (IS_ERR(class)) {
11476 pr_err("wlan_hdd_state class_create error");
11477 goto class_err;
11478 }
11479
11480 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11481 if (IS_ERR(dev)) {
11482 pr_err("wlan_hdd_statedevice_create error");
11483 goto err_class_destroy;
11484 }
11485
11486 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11487 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11488 if (ret) {
11489 pr_err("Failed to add cdev error");
11490 goto cdev_add_err;
11491 }
11492
11493 pr_info("wlan_hdd_state %s major(%d) initialized",
11494 WLAN_MODULE_NAME, wlan_hdd_state_major);
11495
11496 return 0;
11497
11498cdev_add_err:
11499 device_destroy(class, device);
11500err_class_destroy:
11501 class_destroy(class);
11502class_err:
11503 unregister_chrdev_region(device, dev_num);
11504dev_alloc_err:
11505 return -ENODEV;
11506}
11507
11508static void wlan_hdd_state_ctrl_param_destroy(void)
11509{
11510 cdev_del(&wlan_hdd_state_cdev);
11511 device_destroy(class, device);
11512 class_destroy(class);
11513 unregister_chrdev_region(device, dev_num);
11514
11515 pr_info("Device node unregistered");
11516}
11517
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011518/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011519 * component_init - API to init cld component's
11520 *
11521 * Return: None
11522 */
11523static void component_init(void)
11524{
11525 pmo_init();
11526}
11527
11528/**
11529 * component_deinit - API to deinit cld component's
11530 *
11531 * Return: None
11532 */
11533static void component_deinit(void)
11534{
11535 pmo_deinit();
11536}
11537
11538/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011539 * __hdd_module_init - Module init helper
11540 *
11541 * Module init helper function used by both module and static driver.
11542 *
11543 * Return: 0 for success, errno on failure
11544 */
11545static int __hdd_module_init(void)
11546{
11547 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011548
Dustin Brown96cd9632017-11-13 12:45:04 -080011549 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011550 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011551 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011552 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011553
Sachin Ahujadddd2632017-03-07 19:07:24 +053011554 ret = wlan_hdd_state_ctrl_param_create();
11555 if (ret) {
11556 pr_err("wlan_hdd_state_create:%x\n", ret);
11557 goto err_dev_state;
11558 }
11559
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011560 pld_init();
11561
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011562 ret = hdd_init();
11563 if (ret) {
11564 pr_err("hdd_init failed %x\n", ret);
11565 goto err_hdd_init;
11566 }
11567
Rajeev Kumar97767a02016-11-30 11:20:40 -080011568 dispatcher_init();
11569
Mukul Sharmad75a6672017-06-22 15:40:53 +053011570 /* Ensure to call post objmgr init */
11571 component_init();
11572
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011573 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011574
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011575 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011576
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011577 ret = wlan_hdd_register_driver();
11578 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011579 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11580 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011581 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011582 }
11583
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011584 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011585
11586 return 0;
11587out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011588 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011589 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011590 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011591 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011592
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011593err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011594 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011595 wlan_hdd_state_ctrl_param_destroy();
11596err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011597 return ret;
11598}
11599
11600/**
11601 * __hdd_module_exit - Module exit helper
11602 *
11603 * Module exit helper function used by both module and static driver.
11604 */
11605static void __hdd_module_exit(void)
11606{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011607
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011608 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11609 QWLAN_VERSIONSTR);
11610
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011611 hdd_wait_for_recovery_completion();
11612
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011613 wlan_hdd_unregister_driver();
11614
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011615 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011616
Mukul Sharmad75a6672017-06-22 15:40:53 +053011617 /* Ensure to call prior to objmgr deinit */
11618 component_deinit();
11619
Rajeev Kumar97767a02016-11-30 11:20:40 -080011620 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011621
11622 hdd_sysfs_destroy_version_interface();
11623
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011624 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011625 pld_deinit();
11626
Sachin Ahujadddd2632017-03-07 19:07:24 +053011627 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011628}
11629
Arun Khandavallifae92942016-08-01 13:31:08 +053011630#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011631/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011632 * wlan_boot_cb() - Wlan boot callback
11633 * @kobj: object whose directory we're creating the link in.
11634 * @attr: attribute the user is interacting with
11635 * @buff: the buffer containing the user data
11636 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011637 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011638 * This callback is invoked when the fs is ready to start the
11639 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011640 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011641 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011642 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011643static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011644 struct kobj_attribute *attr,
11645 const char *buf,
11646 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011647{
Arun Khandavallifae92942016-08-01 13:31:08 +053011648
Arun Khandavallifae92942016-08-01 13:31:08 +053011649 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011650 pr_err("%s: wlan driver already initialized\n", __func__);
11651 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011652 }
11653
Arun Khandavallifae92942016-08-01 13:31:08 +053011654 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011655 pr_err("%s: wlan driver initialization failed\n", __func__);
11656 return -EIO;
11657 }
11658
11659 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011660
11661 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011662}
Arun Khandavallifae92942016-08-01 13:31:08 +053011663
11664/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011665 * hdd_sysfs_cleanup() - cleanup sysfs
11666 *
11667 * Return: None
11668 *
11669 */
11670static void hdd_sysfs_cleanup(void)
11671{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011672 /* remove from group */
11673 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11674 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11675 wlan_loader->attr_group);
11676
11677 /* unlink the object from parent */
11678 kobject_del(wlan_loader->boot_wlan_obj);
11679
11680 /* free the object */
11681 kobject_put(wlan_loader->boot_wlan_obj);
11682
11683 kfree(wlan_loader->attr_group);
11684 kfree(wlan_loader);
11685
11686 wlan_loader = NULL;
11687}
11688
11689/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011690 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11691 * ready
11692 *
11693 * This is creates the syfs entry boot_wlan. Which shall be invoked
11694 * when the filesystem is ready.
11695 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011696 * QDF API cannot be used here since this function is called even before
11697 * initializing WLAN driver.
11698 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011699 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011700 */
11701static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011702{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011703 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011704
11705 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011706 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011707 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011708
11709 wlan_loader->boot_wlan_obj = NULL;
11710 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11711 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011712 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011713 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011714
11715 wlan_loader->loaded_state = 0;
11716 wlan_loader->attr_group->attrs = attrs;
11717
11718 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11719 kernel_kobj);
11720 if (!wlan_loader->boot_wlan_obj) {
11721 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011722 goto error_return;
11723 }
11724
11725 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11726 wlan_loader->attr_group);
11727 if (ret) {
11728 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11729 goto error_return;
11730 }
11731
11732 return 0;
11733
11734error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011735 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011736
11737 return ret;
11738}
11739
11740/**
11741 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11742 *
11743 * Return: 0 on success or errno on failure
11744 */
11745static int wlan_deinit_sysfs(void)
11746{
Arun Khandavallifae92942016-08-01 13:31:08 +053011747 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011748 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011749 return -EINVAL;
11750 }
11751
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011752 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011753 return 0;
11754}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011755
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011756#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011757
11758#ifdef MODULE
11759/**
11760 * __hdd_module_init - Module init helper
11761 *
11762 * Module init helper function used by both module and static driver.
11763 *
11764 * Return: 0 for success, errno on failure
11765 */
11766static int hdd_module_init(void)
11767{
Arun Khandavallifae92942016-08-01 13:31:08 +053011768 if (__hdd_module_init()) {
11769 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011770 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011771 }
11772
Dustin Brownab482ac2017-06-09 17:00:44 -070011773 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011774}
11775#else
11776static int __init hdd_module_init(void)
11777{
11778 int ret = -EINVAL;
11779
11780 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011781 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011782 pr_err("Failed to create sysfs entry for loading wlan");
11783
11784 return ret;
11785}
11786#endif
11787
11788
11789#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011790/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011791 * hdd_module_exit() - Exit function
11792 *
11793 * This is the driver exit point (invoked when module is unloaded using rmmod)
11794 *
11795 * Return: None
11796 */
11797static void __exit hdd_module_exit(void)
11798{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011799 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011800}
Arun Khandavallifae92942016-08-01 13:31:08 +053011801#else
11802static void __exit hdd_module_exit(void)
11803{
11804 __hdd_module_exit();
11805 wlan_deinit_sysfs();
11806}
11807#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011808
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011809static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11810{
11811 return param_set_copystring(kmessage, kp);
11812}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011813
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011814/**
11815 * is_con_mode_valid() check con mode is valid or not
11816 * @mode: global con mode
11817 *
11818 * Return: TRUE on success FALSE on failure
11819 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080011820static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011821{
11822 switch (mode) {
11823 case QDF_GLOBAL_MONITOR_MODE:
11824 case QDF_GLOBAL_FTM_MODE:
11825 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011826 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011827 return true;
11828 default:
11829 return false;
11830 }
11831}
11832
11833/**
11834 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11835 * @mode: global con mode
11836 *
11837 * Return: adapter mode
11838 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011839static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080011840 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011841{
11842
11843 switch (mode) {
11844 case QDF_GLOBAL_MISSION_MODE:
11845 return QDF_STA_MODE;
11846 case QDF_GLOBAL_MONITOR_MODE:
11847 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011848 case QDF_GLOBAL_EPPING_MODE:
11849 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011850 case QDF_GLOBAL_FTM_MODE:
11851 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011852 case QDF_GLOBAL_QVIT_MODE:
11853 return QDF_QVIT_MODE;
11854 default:
11855 return QDF_MAX_NO_OF_MODE;
11856 }
11857}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011858
Dustin Brown27cd9942017-09-27 16:11:44 -070011859static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080011860 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070011861{
11862 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11863 return;
11864
11865 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070011866 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053011867 hdd_info("Release wakelock for monitor mode!");
11868 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
11869 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
11870 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070011871 case QDF_GLOBAL_FTM_MODE:
11872 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11873 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Dustin Browndb2a8be2017-12-20 11:49:56 -080011874 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070011875
Dustin Brown27cd9942017-09-27 16:11:44 -070011876 break;
11877 default:
11878 break;
11879 }
11880}
11881
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011882static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080011883 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011884{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011885 int driver_status;
11886
11887 driver_status = hdd_ctx->driver_status;
11888
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011889 switch (curr_mode) {
11890 case QDF_GLOBAL_MISSION_MODE:
11891 case QDF_GLOBAL_MONITOR_MODE:
11892 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011893 hdd_deinit_all_adapters(hdd_ctx, false);
11894 hdd_close_all_adapters(hdd_ctx, false);
11895 break;
11896 case QDF_GLOBAL_EPPING_MODE:
11897 epping_disable();
11898 epping_close();
11899 break;
11900 default:
11901 return;
11902 }
11903}
11904
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011905static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080011906 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011907{
Jeff Johnson9d295242017-08-29 14:39:48 -070011908 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011909 int ret = 0;
11910 bool rtnl_held;
11911 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11912 QDF_STATUS status;
11913
11914 if (!qdf_dev) {
11915 hdd_err("qdf device context is Null return!");
11916 return -EINVAL;
11917 }
11918
11919 rtnl_held = hdd_hold_rtnl_lock();
11920 switch (mode) {
11921 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011922 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11923 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011924 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011925 break;
11926 case QDF_GLOBAL_FTM_MODE:
11927 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11928 wlan_hdd_get_intf_addr(hdd_ctx),
11929 NET_NAME_UNKNOWN, rtnl_held);
11930 if (adapter == NULL)
11931 ret = -EINVAL;
11932 break;
11933 case QDF_GLOBAL_MONITOR_MODE:
11934 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11935 wlan_hdd_get_intf_addr(hdd_ctx),
11936 NET_NAME_UNKNOWN, rtnl_held);
11937 if (adapter == NULL)
11938 ret = -EINVAL;
11939 break;
11940 case QDF_GLOBAL_EPPING_MODE:
11941 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011942 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011943 hdd_err("Failed to open in eeping mode: %d", status);
11944 ret = -EINVAL;
11945 break;
11946 }
11947 ret = epping_enable(qdf_dev->dev);
11948 if (ret) {
11949 hdd_err("Failed to enable in epping mode : %d", ret);
11950 epping_close();
11951 }
11952 break;
11953 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011954 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011955 ret = -ENOTSUPP;
11956 break;
11957 }
11958 hdd_release_rtnl_lock();
11959 rtnl_held = false;
11960 return ret;
11961}
11962
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011963/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011964 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011965 * @kmessage: con mode name on which driver to be bring up
11966 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011967 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011968 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011969 * This function is invoked when user updates con mode using sys entry,
11970 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011971 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011972 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011973 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011974static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011975 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011976{
11977 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011978 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080011979 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011980 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080011981 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011982
Dustin Brownab6029b2017-05-24 13:04:19 -070011983 hdd_info("con_mode handler: %s", kmessage);
11984
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011985 ret = wlan_hdd_validate_context(hdd_ctx);
11986 if (ret)
11987 return ret;
11988
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011989 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011990
Dustin Brown20024e32018-01-03 12:34:58 -080011991 ret = kstrtoint(kmessage, 0, &new_con_mode);
11992 if (ret) {
11993 hdd_err("Failed to parse con_mode '%s'", kmessage);
11994 goto reset_flags;
11995 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011996
Dustin Brown20024e32018-01-03 12:34:58 -080011997 if (!is_con_mode_valid(new_con_mode)) {
11998 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011999 ret = -EINVAL;
12000 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012001 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012002
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012003 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012004 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012005 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012006 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012007 ret = 0;
12008 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012009 }
12010
Sourav Mohapatra3bc5e982017-11-24 15:53:49 +053012011 if (!cds_wait_for_external_threads_completion(__func__))
12012 hdd_warn("Waiting for monitor mode: External threads are active");
12013
Dustin Brown27cd9942017-09-27 16:11:44 -070012014 /* ensure adapters are stopped */
12015 hdd_stop_present_mode(hdd_ctx, curr_mode);
12016
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012017 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012018 if (ret) {
12019 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012020 goto reset_flags;
12021 }
12022
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012023 /* Cleanup present mode before switching to new mode */
12024 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12025
Dustin Brown20024e32018-01-03 12:34:58 -080012026 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012027
12028 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012029 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012030 if (ret) {
12031 hdd_err("Failed to register for new mode");
12032 goto reset_flags;
12033 }
12034
Dustin Brown20024e32018-01-03 12:34:58 -080012035 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012036 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12037 hdd_err("invalid adapter");
12038 ret = -EINVAL;
12039 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012040 }
12041
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012042 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012043 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012044 hdd_err("Failed to get adapter:%d", adapter_mode);
12045 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012046 }
12047
12048 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12049 if (ret) {
12050 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012051 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012052 }
12053
Dustin Brown20024e32018-01-03 12:34:58 -080012054 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012055 if (hdd_start_adapter(adapter)) {
12056 hdd_err("Failed to start %s adapter", kmessage);
12057 ret = -EINVAL;
12058 goto reset_flags;
12059 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012060
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012061 hdd_info("Acquire wakelock for monitor mode!");
12062 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12063 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12064 }
12065
Dustin Brown20024e32018-01-03 12:34:58 -080012066 /* con_mode is a global module parameter */
12067 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012068 hdd_info("Mode successfully changed to %s", kmessage);
12069 ret = 0;
12070
12071reset_flags:
12072 cds_set_load_in_progress(false);
Dustin Brown20024e32018-01-03 12:34:58 -080012073
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012074 return ret;
12075}
12076
12077
12078static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12079{
12080 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012081 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012082
12083 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12084 ret = wlan_hdd_validate_context(hdd_ctx);
12085 if (ret)
12086 return ret;
12087
12088 cds_ssr_protect(__func__);
12089 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12090 cds_ssr_unprotect(__func__);
12091
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012092 return ret;
12093}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012094
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012095static int con_mode_handler_ftm(const char *kmessage,
12096 struct kernel_param *kp)
12097{
12098 int ret;
12099
12100 ret = param_set_int(kmessage, kp);
12101
12102 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12103 pr_err("Only FTM mode supported!");
12104 return -ENOTSUPP;
12105 }
12106
12107 hdd_set_conparam(con_mode_ftm);
12108 con_mode = con_mode_ftm;
12109
12110 return ret;
12111}
12112
Ravi Joshia307f632017-07-17 23:41:41 -070012113static int con_mode_handler_monitor(const char *kmessage,
12114 struct kernel_param *kp)
12115{
12116 int ret;
12117
12118 ret = param_set_int(kmessage, kp);
12119
12120 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12121 pr_err("Only Monitor mode supported!");
12122 return -ENOTSUPP;
12123 }
12124
12125 hdd_set_conparam(con_mode_monitor);
12126 con_mode = con_mode_monitor;
12127
12128 return ret;
12129}
12130
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012131/**
12132 * hdd_get_conparam() - driver exit point
12133 *
12134 * This is the driver exit point (invoked when module is unloaded using rmmod)
12135 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012136 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012137 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012138enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012139{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012140 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012141}
12142
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012143void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012144{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012145 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012146}
12147
Komal Seelamc11bb222016-01-27 18:57:10 +053012148/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012149 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12150 * @hdd_ctx: HDD context
12151 *
12152 * Cleans up the pre cac interface, if it exists
12153 *
12154 * Return: None
12155 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012156void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012157{
12158 uint8_t session_id;
12159 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012160 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012161
12162 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12163 if (QDF_IS_STATUS_ERROR(status)) {
12164 hdd_err("failed to get pre cac vdev id");
12165 return;
12166 }
12167
12168 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12169 if (!precac_adapter) {
12170 hdd_err("invalid pre cac adapater");
12171 return;
12172 }
12173
12174 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12175 wlan_hdd_sap_pre_cac_failure,
12176 (void *)precac_adapter);
12177 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12178
12179}
12180
12181/**
Komal Seelamec702b02016-02-24 18:42:16 +053012182 * hdd_update_ol_config - API to update ol configuration parameters
12183 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012184 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012185 * Return: void
12186 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012187static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012188{
Komal Seelamec702b02016-02-24 18:42:16 +053012189 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012190 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012191
Komal Seelamec702b02016-02-24 18:42:16 +053012192 if (!ol_ctx)
12193 return;
12194
12195 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12196 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12197 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12198 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012199 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012200
12201 ol_init_ini_config(ol_ctx, &cfg);
12202}
12203
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012204#ifdef FEATURE_RUNTIME_PM
12205/**
12206 * hdd_populate_runtime_cfg() - populate runtime configuration
12207 * @hdd_ctx: hdd context
12208 * @cfg: pointer to the configuration memory being populated
12209 *
12210 * Return: void
12211 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012212static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012213 struct hif_config_info *cfg)
12214{
12215 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12216 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12217}
12218#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012219static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012220 struct hif_config_info *cfg)
12221{
12222}
12223#endif
12224
Komal Seelamec702b02016-02-24 18:42:16 +053012225/**
12226 * hdd_update_hif_config - API to update HIF configuration parameters
12227 * @hdd_ctx: HDD Context
12228 *
12229 * Return: void
12230 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012231static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012232{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012233 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012234 struct hif_config_info cfg;
12235
12236 if (!scn)
12237 return;
12238
12239 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012240 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012241 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012242
12243 if (hdd_ctx->config->prevent_link_down)
12244 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012245}
12246
12247/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012248 * hdd_update_dp_config() - Propagate config parameters to Lithium
12249 * datapath
12250 * @hdd_ctx: HDD Context
12251 *
12252 * Return: 0 for success/errno for failure
12253 */
12254static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12255{
12256 struct cdp_config_params params;
12257 QDF_STATUS status;
12258
12259 params.tso_enable = hdd_ctx->config->tso_enable;
12260 params.lro_enable = hdd_ctx->config->lro_enable;
12261#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12262 params.tx_flow_stop_queue_threshold =
12263 hdd_ctx->config->TxFlowStopQueueThreshold;
12264 params.tx_flow_start_queue_offset =
12265 hdd_ctx->config->TxFlowStartQueueOffset;
12266#endif
12267 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12268 params.napi_enable = hdd_ctx->napi_enable;
12269 params.tcp_udp_checksumoffload =
12270 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12271
12272 status = cdp_update_config_parameters(
12273 cds_get_context(QDF_MODULE_ID_SOC),
12274 &params);
12275 if (status) {
12276 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12277 "%s: Failed to attach config parameters", __func__);
12278 return status;
12279 }
12280
12281 return 0;
12282}
12283
12284/**
Komal Seelamec702b02016-02-24 18:42:16 +053012285 * hdd_update_config() - Initialize driver per module ini parameters
12286 * @hdd_ctx: HDD Context
12287 *
12288 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012289 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012290 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012291int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012292{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012293 int ret;
12294
Komal Seelamec702b02016-02-24 18:42:16 +053012295 hdd_update_ol_config(hdd_ctx);
12296 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012297 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12298 ret = hdd_update_cds_config_ftm(hdd_ctx);
12299 else
12300 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012301 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012302
12303 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012304}
12305
Mukul Sharma9d797a02017-01-05 20:26:03 +053012306#ifdef FEATURE_WLAN_RA_FILTERING
12307/**
12308 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12309 * @psoc_cfg: pmo psoc Configuration
12310 * @hdd_ctx: Pointer to hdd context
12311 *
12312 * Return: none
12313 */
12314static inline void hdd_ra_populate_pmo_config(
12315 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012316 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012317{
12318 psoc_cfg->ra_ratelimit_interval =
12319 hdd_ctx->config->RArateLimitInterval;
12320 psoc_cfg->ra_ratelimit_enable =
12321 hdd_ctx->config->IsRArateLimitEnabled;
12322}
12323#else
12324static inline void hdd_ra_populate_pmo_config(
12325 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012326 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012327{
12328}
12329#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012330
Mukul Sharma9d797a02017-01-05 20:26:03 +053012331/**
12332 * hdd_update_pmo_config - API to update pmo configuration parameters
12333 * @hdd_ctx: HDD context
12334 *
12335 * Return: void
12336 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012337static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012338{
12339 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12340 struct pmo_psoc_cfg psoc_cfg;
12341 QDF_STATUS status;
12342
12343 /*
12344 * Value of hdd_ctx->wowEnable can be,
12345 * 0 - Disable both magic pattern match and pattern byte match.
12346 * 1 - Enable magic pattern match on all interfaces.
12347 * 2 - Enable pattern byte match on all interfaces.
12348 * 3 - Enable both magic patter and pattern byte match on
12349 * all interfaces.
12350 */
12351 psoc_cfg.magic_ptrn_enable =
12352 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12353 psoc_cfg.ptrn_match_enable_all_vdev =
12354 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012355 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12356 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012357 psoc_cfg.bpf_enable =
12358 hdd_ctx->config->bpf_packet_filter_enable;
12359 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012360 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012361 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12362 if (hdd_ctx->config->fhostNSOffload)
12363 psoc_cfg.ns_offload_enable_dynamic = true;
12364 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12365 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12366 psoc_cfg.active_mode_offload =
12367 hdd_ctx->config->active_mode_offload;
12368 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012369 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012370 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012371 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12372 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12373 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12374 psoc_cfg.power_save_mode =
12375 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012376 psoc_cfg.auto_power_save_fail_mode =
12377 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012378
12379 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012380 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12381 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012382 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012383 if (status != QDF_STATUS_SUCCESS) {
12384 hdd_err("failed pmo psoc configuration");
12385 return -EINVAL;
12386 }
12387
12388 return 0;
12389}
12390
Abhishek Singhb20db962017-03-03 21:28:46 +053012391#ifdef FEATURE_WLAN_SCAN_PNO
12392static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12393 struct hdd_config *cfg)
12394{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012395 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12396
Abhishek Singhb20db962017-03-03 21:28:46 +053012397 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12398 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12399 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12400 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12401 pno_cfg->channel_prediction_full_scan =
12402 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012403 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12404 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12405 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12406 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012407}
12408#else
12409static inline void
12410hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012411 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012412{
Abhishek Singhb20db962017-03-03 21:28:46 +053012413}
12414#endif
12415
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012416void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12417 struct hdd_config *cfg)
12418{
12419 uint8_t i = 0;
12420
12421 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12422 if (!ie_whitelist->white_list)
12423 return;
12424
12425 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12426 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12427 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12428 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12429 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12430 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12431 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12432 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12433
12434 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12435 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12436 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12437}
12438
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012439uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12440{
12441 uint8_t i, score;
12442
12443 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12444 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12445 if (score > MAX_INDEX_SCORE)
12446 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12447 MAX_INDEX_SCORE, i);
12448 }
12449
12450 return per_index_score;
12451}
12452
12453/**
12454 * hdd_update_score_config - API to update candidate scoring related params
12455 * configuration parameters
12456 * @score_config: score config to update
12457 * @cfg: config params
12458 *
12459 * Return: 0 if success else err
12460 */
12461static void hdd_update_score_config(
12462 struct scoring_config *score_config, struct hdd_config *cfg)
12463{
12464 int total_weight;
12465
12466 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12467 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12468 score_config->weight_cfg.vht_caps_weightage =
12469 cfg->vht_caps_weightage;
12470 score_config->weight_cfg.he_caps_weightage =
12471 cfg->he_caps_weightage;
12472 score_config->weight_cfg.chan_width_weightage =
12473 cfg->chan_width_weightage;
12474 score_config->weight_cfg.chan_band_weightage =
12475 cfg->chan_band_weightage;
12476 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12477 score_config->weight_cfg.beamforming_cap_weightage =
12478 cfg->beamforming_cap_weightage;
12479 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12480 score_config->weight_cfg.channel_congestion_weightage =
12481 cfg->channel_congestion_weightage;
12482 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12483
12484 total_weight = score_config->weight_cfg.rssi_weightage +
12485 score_config->weight_cfg.ht_caps_weightage +
12486 score_config->weight_cfg.vht_caps_weightage +
12487 score_config->weight_cfg.he_caps_weightage +
12488 score_config->weight_cfg.chan_width_weightage +
12489 score_config->weight_cfg.chan_band_weightage +
12490 score_config->weight_cfg.nss_weightage +
12491 score_config->weight_cfg.beamforming_cap_weightage +
12492 score_config->weight_cfg.pcl_weightage +
12493 score_config->weight_cfg.channel_congestion_weightage +
12494 score_config->weight_cfg.oce_wan_weightage;
12495
12496 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12497 hdd_err("total weight is greater than %d fallback to default values",
12498 BEST_CANDIDATE_MAX_WEIGHT);
12499
12500 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12501 score_config->weight_cfg.ht_caps_weightage =
12502 HT_CAPABILITY_WEIGHTAGE;
12503 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12504 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12505 score_config->weight_cfg.chan_width_weightage =
12506 CHAN_WIDTH_WEIGHTAGE;
12507 score_config->weight_cfg.chan_band_weightage =
12508 CHAN_BAND_WEIGHTAGE;
12509 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12510 score_config->weight_cfg.beamforming_cap_weightage =
12511 BEAMFORMING_CAP_WEIGHTAGE;
12512 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12513 score_config->weight_cfg.channel_congestion_weightage =
12514 CHANNEL_CONGESTION_WEIGHTAGE;
12515 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12516 }
12517
12518 score_config->bandwidth_weight_per_index =
12519 hdd_limit_max_per_index_score(
12520 cfg->bandwidth_weight_per_index);
12521 score_config->nss_weight_per_index =
12522 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12523 score_config->band_weight_per_index =
12524 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12525
12526 score_config->rssi_score.best_rssi_threshold =
12527 cfg->best_rssi_threshold;
12528 score_config->rssi_score.good_rssi_threshold =
12529 cfg->good_rssi_threshold;
12530 score_config->rssi_score.bad_rssi_threshold =
12531 cfg->bad_rssi_threshold;
12532 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12533 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12534 score_config->rssi_score.good_rssi_bucket_size =
12535 cfg->good_rssi_bucket_size;
12536 score_config->rssi_score.bad_rssi_bucket_size =
12537 cfg->bad_rssi_bucket_size;
12538 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12539 cfg->rssi_pref_5g_rssi_thresh;
12540
12541 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12542 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12543 hdd_limit_max_per_index_score(
12544 cfg->esp_qbss_score_slots3_to_0);
12545 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12546 hdd_limit_max_per_index_score(
12547 cfg->esp_qbss_score_slots7_to_4);
12548 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12549 hdd_limit_max_per_index_score(
12550 cfg->esp_qbss_score_slots11_to_8);
12551 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12552 hdd_limit_max_per_index_score(
12553 cfg->esp_qbss_score_slots15_to_12);
12554
12555 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12556 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12557 hdd_limit_max_per_index_score(
12558 cfg->oce_wan_score_slots3_to_0);
12559 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12560 hdd_limit_max_per_index_score(
12561 cfg->oce_wan_score_slots7_to_4);
12562 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12563 hdd_limit_max_per_index_score(
12564 cfg->oce_wan_score_slots11_to_8);
12565 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12566 hdd_limit_max_per_index_score(
12567 cfg->oce_wan_score_slots15_to_12);
12568
12569
12570 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12571 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12572 score_config->nss = cfg->enable2x2 ? 2 : 1;
12573
12574 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12575 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12576 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12577 score_config->he_cap = 1;
12578
12579 if (score_config->he_cap ||
12580 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12581 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12582 score_config->vht_cap = 1;
12583
12584 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12585 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12586 score_config->ht_cap = 1;
12587
12588 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12589 score_config->vht_24G_cap = 1;
12590
12591 if (cfg->enableTxBF)
12592 score_config->beamformee_cap = 1;
12593
12594}
12595
Abhishek Singh257a9482017-03-06 16:52:39 +053012596/**
12597 * hdd_update_scan_config - API to update scan configuration parameters
12598 * @hdd_ctx: HDD context
12599 *
12600 * Return: 0 if success else err
12601 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012602static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012603{
12604 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12605 struct scan_user_cfg scan_cfg;
12606 struct hdd_config *cfg = hdd_ctx->config;
12607 QDF_STATUS status;
12608
12609 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12610 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12611 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12612 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12613 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12614 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12615 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012616 /* convert to ms */
12617 scan_cfg.scan_cache_aging_time =
12618 cfg->scanAgingTimeout * 1000;
12619 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12620 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12621 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12622 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012623 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012624 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012625 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12626 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012627 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012628 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012629
Abhishek Singhb20db962017-03-03 21:28:46 +053012630 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012631 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012632 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012633
Abhishek Singh257a9482017-03-06 16:52:39 +053012634 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12635 if (status != QDF_STATUS_SUCCESS) {
12636 hdd_err("failed pmo psoc configuration");
12637 return -EINVAL;
12638 }
12639
12640 return 0;
12641}
Abhishek Singh257a9482017-03-06 16:52:39 +053012642
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012643int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012644{
12645 int ret;
12646
12647 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012648 if (ret)
12649 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012650
Abhishek Singh257a9482017-03-06 16:52:39 +053012651 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012652 if (ret)
12653 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012654
Frank Liud4b2fa02017-03-29 11:46:48 +080012655 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012656 if (ret)
12657 return ret;
12658
12659 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012660
12661 return ret;
12662}
12663
Agrawal Ashish65634612016-08-18 13:24:32 +053012664/**
12665 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12666 * @mode : cfg80211 DFS mode
12667 *
12668 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12669 */
12670enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12671{
12672 switch (mode) {
12673 case DFS_MODE_ENABLE:
12674 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012675 case DFS_MODE_DISABLE:
12676 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012677 case DFS_MODE_DEPRIORITIZE:
12678 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012679 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012680 hdd_debug("ACS dfs mode is NONE");
12681 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012682 }
12683}
12684
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012685/**
12686 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12687 * @hddctx: pointer to hdd context
12688 * @set_value: enable/disable
12689 *
12690 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12691 * Host(even though it is duplicate). When Host send vendor command
12692 * disable,FW doesn't perform any action. Whenever any change in
12693 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12694 *
12695 * return - 0 on success, appropriate error values on failure.
12696 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012697int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012698{
12699 QDF_STATUS status;
12700
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012701 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012702 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012703
12704 if (!hddctx->config->goptimize_chan_avoid_event) {
12705 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12706 return -EINVAL;
12707 }
12708
12709 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12710 if (!QDF_IS_STATUS_SUCCESS(status)) {
12711 hdd_err("Failed to send chan avoid command to SME");
12712 return -EINVAL;
12713 }
12714 return 0;
12715}
Agrawal Ashish65634612016-08-18 13:24:32 +053012716
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012717/**
12718 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12719 * @value: value to set
12720 *
12721 * This function will set the passed value to roaming in progress flag.
12722 *
12723 * Return: None
12724 */
12725void hdd_set_roaming_in_progress(bool value)
12726{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012727 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012728
12729 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12730 if (!hdd_ctx) {
12731 hdd_err("HDD context is NULL");
12732 return;
12733 }
12734
12735 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012736 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012737}
12738
12739/**
12740 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012741 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012742 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012743 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012744 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012745bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012746{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012747 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012748 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012749
12750 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12751 if (!hdd_ctx) {
12752 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012753 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012754 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012755 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12756 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012757 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12758 hdd_ctx->roaming_in_progress);
12759
12760 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012761}
12762
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012763/**
12764 * hdd_is_connection_in_progress() - check if connection is in
12765 * progress
12766 * @session_id: session id
12767 * @reason: scan reject reason
12768 *
12769 * Go through each adapter and check if Connection is in progress
12770 *
12771 * Return: true if connection is in progress else false
12772 */
12773bool hdd_is_connection_in_progress(uint8_t *session_id,
12774 enum scan_reject_states *reason)
12775{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012776 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012777 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012778 uint8_t sta_id = 0;
12779 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012780 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012781
12782 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12783 if (!hdd_ctx) {
12784 hdd_err("HDD context is NULL");
12785 return false;
12786 }
12787
Dustin Brown920397d2017-12-13 16:27:50 -080012788 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012789 hdd_info("Adapter with device mode %s(%d) exists",
12790 hdd_device_mode_to_string(adapter->device_mode),
12791 adapter->device_mode);
12792 if (((QDF_STA_MODE == adapter->device_mode)
12793 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12794 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12795 && (eConnectionState_Connecting ==
12796 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12797 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012798 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012799 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012800 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012801 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012802 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012803 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012804 }
12805 return true;
12806 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012807 /*
12808 * sme_neighbor_middle_of_roaming is for LFR2
12809 * hdd_is_roaming_in_progress is for LFR3
12810 */
12811 if (((QDF_STA_MODE == adapter->device_mode) &&
12812 sme_neighbor_middle_of_roaming(
12813 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012814 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012815 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012816 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012817 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012818 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012819 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012820 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012821 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012822 }
12823 return true;
12824 }
12825 if ((QDF_STA_MODE == adapter->device_mode) ||
12826 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12827 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12828 hdd_sta_ctx =
12829 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12830 if ((eConnectionState_Associated ==
12831 hdd_sta_ctx->conn_info.connState)
12832 && (false ==
12833 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12834 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070012835 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012836 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012837 " is in middle of WPS/EAPOL exchange.",
12838 MAC_ADDR_ARRAY(sta_mac));
12839 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012840 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012841 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012842 }
12843 return true;
12844 }
12845 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12846 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12847 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12848 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012849 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012850 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012851 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012852 continue;
12853
12854 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012855 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012856 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012857 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012858 " of SAP/GO is in middle of WPS/EAPOL exchange",
12859 MAC_ADDR_ARRAY(sta_mac));
12860 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012861 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012862 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012863 }
12864 return true;
12865 }
12866 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012867 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012868 return true;
12869 }
12870 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012871 }
Dustin Brown920397d2017-12-13 16:27:50 -080012872
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012873 return false;
12874}
12875
12876/**
12877 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012878 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012879 *
12880 * Return: None
12881 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012882void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012883{
Jeff Johnson87251032017-08-29 13:31:11 -070012884 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012885 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012886 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012887 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012888 tsap_Config_t *sap_config;
12889 void *sap_ctx;
12890
12891 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070012892 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012893 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012894
12895 mutex_lock(&hdd_ctx->sap_lock);
12896 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12897 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012898 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12899 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12900 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12901 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053012902 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012903 qdf_stop_bss_event,
12904 SME_CMD_TIMEOUT_VALUE);
12905
12906 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012907 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012908 goto end;
12909 }
12910 }
12911 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012912 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012913 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012914 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012915
12916 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012917 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012918 wlansap_reset_sap_config_add_ie(sap_config,
12919 eUPDATE_IE_ALL);
12920 goto end;
12921 }
12922
12923 qdf_event_reset(&hostapd_state->qdf_event);
12924 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12925 sap_config,
12926 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012927 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012928 wlansap_reset_sap_config_add_ie(sap_config,
12929 eUPDATE_IE_ALL);
12930 goto end;
12931 }
12932
Jeff Johnson6867ec32017-09-29 20:30:20 -070012933 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012934 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053012935 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012936 SME_CMD_TIMEOUT_VALUE);
12937 wlansap_reset_sap_config_add_ie(sap_config,
12938 eUPDATE_IE_ALL);
12939 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012940 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012941 goto end;
12942 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012943 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012944 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070012945 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012946 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12947 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012948 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012949 }
12950end:
12951 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012952}
12953
12954/**
12955 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12956 * with non dfs acs
12957 *
12958 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12959 *
12960 * Return: None
12961 */
12962void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12963{
Jeff Johnson9d295242017-08-29 14:39:48 -070012964 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012965 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012966 cds_context_type *cds_ctx;
12967
12968 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12969 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012970 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012971 return;
12972 }
12973
12974 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12975 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012976 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012977 return;
12978 }
12979
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012980 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12981 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012982 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012983 return;
12984 }
12985
12986 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012987 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12988 &ap_adapter->event_flags) &&
12989 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070012990 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012991
Jeff Johnson6867ec32017-09-29 20:30:20 -070012992 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070012993 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012994 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070012995 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012996 acs_cfg.acs_mode = true;
12997
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012998 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012999 }
13000}
13001
13002/**
13003 * hdd_set_connection_in_progress() - to set the connection in
13004 * progress flag
13005 * @value: value to set
13006 *
13007 * This function will set the passed value to connection in progress flag.
13008 * If value is previously being set to true then no need to set it again.
13009 *
13010 * Return: true if value is being set correctly and false otherwise.
13011 */
13012bool hdd_set_connection_in_progress(bool value)
13013{
13014 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013015 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013016
13017 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13018 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013019 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013020 return false;
13021 }
13022
13023 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13024 /*
13025 * if the value is set to true previously and if someone is
13026 * trying to make it true again then it could be some race
13027 * condition being triggered. Avoid this situation by returning
13028 * false
13029 */
13030 if (hdd_ctx->connection_in_progress && value)
13031 status = false;
13032 else
13033 hdd_ctx->connection_in_progress = value;
13034 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13035 return status;
13036}
13037
Jeff Johnson9d295242017-08-29 14:39:48 -070013038int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013039{
13040 if (!adapter) {
13041 hdd_err("Invalid adapter");
13042 return -EINVAL;
13043 }
13044 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013045 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013046 WMA_VDEV_MCC_SET_TIME_QUOTA,
13047 set_value, VDEV_CMD);
13048 return 0;
13049
13050}
13051
Jeff Johnson9d295242017-08-29 14:39:48 -070013052int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013053{
13054 if (!adapter) {
13055 hdd_err("Invalid adapter");
13056 return -EINVAL;
13057 }
13058
13059 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013060 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013061 WMA_VDEV_MCC_SET_TIME_LATENCY,
13062 set_value, VDEV_CMD);
13063 return 0;
13064}
13065
Jeff Johnson9d295242017-08-29 14:39:48 -070013066struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013067 *psoc, uint8_t vdev_id)
13068{
Jeff Johnson9d295242017-08-29 14:39:48 -070013069 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013070 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013071
13072 /*
13073 * Currently PSOC is not being used. But this logic will
13074 * change once we have the converged implementation of
13075 * HDD context per PSOC in place. This would break if
13076 * multiple vdev objects reuse the vdev id.
13077 */
13078 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13079 if (!adapter)
13080 hdd_err("Get adapter by vdev id failed");
13081
13082 return adapter;
13083}
13084
Jeff Johnson9d295242017-08-29 14:39:48 -070013085int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013086 int8_t *rssi, int8_t *snr)
13087{
13088 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070013089 struct hdd_wext_state *wext_state =
13090 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013091 tCsrRoamProfile *profile = &wext_state->roamProfile;
13092
13093 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
13094 profile, bssid, rssi, snr);
13095 if (QDF_STATUS_SUCCESS != status) {
13096 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13097 return -EINVAL;
13098 }
13099
13100 return 0;
13101}
13102
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013103/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013104 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13105 * @adapter - HDD adapter
13106 * @tos - type of service
13107 * @status - status of the traffic
13108 *
13109 * Return: 0 on success and non zero value on failure
13110 */
13111
13112int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13113 bool is_tos_active)
13114{
13115 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013116 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013117 uint32_t max_off_chan_time = 0;
13118 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013119 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013120 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013121
13122 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13123 ret = wlan_hdd_validate_context(hdd_ctx);
13124
13125 if (ret < 0) {
13126 hdd_err("failed to set limit off chan params");
13127 return ret;
13128 }
13129
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013130 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13131
13132 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013133 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013134 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013135 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013136
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013137 if (adapter->active_ac) {
13138 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013139 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013140 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13141 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13142 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013143 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013144 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013145 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13146 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13147 PM_LATENCY);
13148 } else {
13149 /*ignore this command if only BE/BK is active */
13150 is_tos_active = false;
13151 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13152 hdd_ctx->config->conc_system_pref);
13153 }
13154 } else {
13155 /* No active tos */
13156 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13157 hdd_ctx->config->conc_system_pref);
13158 }
13159
Jeff Johnson1b780e42017-10-31 14:11:45 -070013160 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013161 is_tos_active, max_off_chan_time,
13162 hdd_ctx->config->nRestTimeConc, true);
13163 if (!QDF_IS_STATUS_SUCCESS(status)) {
13164 hdd_err("failed to set limit off chan params");
13165 ret = -EINVAL;
13166 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013167
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013168 return ret;
13169}
13170
13171/**
13172 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13173 * @adapter - HDD adapter
13174 *
13175 * Return: 0 on success and non zero value on failure
13176 */
13177int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13178{
13179 struct hdd_context *hdd_ctx;
13180 int ret;
13181 QDF_STATUS status;
13182 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13183
13184 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13185 ret = wlan_hdd_validate_context(hdd_ctx);
13186 if (ret < 0)
13187 return ret;
13188
13189 /* set the system preferece to default */
13190 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13191 hdd_ctx->config->conc_system_pref);
13192
13193 /* clear the bitmap */
13194 adapter->active_ac = 0;
13195
13196 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013197 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013198
Jeff Johnson1b780e42017-10-31 14:11:45 -070013199 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013200 false, 0, 0, false);
13201 if (!QDF_IS_STATUS_SUCCESS(status)) {
13202 hdd_err("failed to reset limit off chan params");
13203 ret = -EINVAL;
13204 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013205
13206 return ret;
13207}
13208
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013209/**
13210 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13211 * @drv_op: Enum indicating driver op
13212 *
13213 * Return: none
13214 */
13215void hdd_start_driver_ops_timer(int drv_op)
13216{
13217 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13218 switch (drv_op) {
13219 case eHDD_DRV_OP_PROBE:
13220 memcpy(drv_ops_string, "probe", sizeof("probe"));
13221 break;
13222 case eHDD_DRV_OP_REMOVE:
13223 memcpy(drv_ops_string, "remove", sizeof("remove"));
13224 break;
13225 case eHDD_DRV_OP_SHUTDOWN:
13226 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13227 break;
13228 case eHDD_DRV_OP_REINIT:
13229 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13230 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013231 case eHDD_DRV_OP_IFF_UP:
13232 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13233 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013234 }
13235
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013236 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013237 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13238 HDD_OPS_INACTIVITY_TIMEOUT);
13239}
13240
13241/**
13242 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13243 *
13244 * Return: none
13245 */
13246void hdd_stop_driver_ops_timer(void)
13247{
13248 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13249}
13250
13251/**
13252 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13253 * inactivity timer
13254 *
13255 * Return: None
13256 */
13257void hdd_drv_ops_inactivity_handler(void)
13258{
13259 hdd_err("%s: %d Sec timer expired while in .%s",
13260 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13261
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013262 if (hdd_drv_ops_task) {
13263 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13264 qdf_print_thread_trace(hdd_drv_ops_task);
13265 } else {
13266 hdd_err("hdd_drv_ops_task is null");
13267 }
13268
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013269 /* Driver shutdown is stuck, no recovery possible at this point */
13270 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13271 sizeof("shutdown")))
13272 QDF_BUG(0);
13273
13274 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013275 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013276 else
13277 QDF_BUG(0);
13278}
13279
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013280void hdd_pld_ipa_uc_shutdown_pipes(void)
13281{
13282 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13283
13284 if (!hdd_ctx)
13285 return;
13286
13287 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13288}
13289
Yun Parkff6a16a2017-09-26 16:38:18 -070013290/**
13291 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13292 * @struct hdd_context *hdd_ctx
13293 * @struct hdd_adapter *padapter
13294 * @bool enble
13295 *
13296 * Return: none
13297 */
13298void hdd_set_rx_mode_rps(bool enable)
13299{
13300 struct cds_config_info *cds_cfg = cds_get_ini_config();
13301 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13302 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13303
13304 if (adapter && hdd_ctx &&
13305 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13306 if (enable && !cds_cfg->rps_enabled)
13307 hdd_send_rps_ind(adapter);
13308 else if (!enable && cds_cfg->rps_enabled)
13309 hdd_send_rps_disable_ind(adapter);
13310 }
13311}
13312
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013313/* Register the module init/exit functions */
13314module_init(hdd_module_init);
13315module_exit(hdd_module_exit);
13316
13317MODULE_LICENSE("Dual BSD/GPL");
13318MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13319MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13320
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013321module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13322 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013323
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013324module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13325 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13326
Ravi Joshia307f632017-07-17 23:41:41 -070013327module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13328 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13329
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013330module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13331 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13332
13333module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13334
13335module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13336
13337module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);