blob: 56a99251acf0f24d8951d36c5f821c936de66c85 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnsond9f08602016-12-02 11:31:30 -08002 * Copyright (c) 2012-2017 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"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070060#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080061#include <cdp_txrx_misc.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062
63#include <net/addrconf.h>
64#include <linux/wireless.h>
65#include <net/cfg80211.h>
66#include <linux/inetdevice.h>
67#include <net/addrconf.h>
68#include "wlan_hdd_cfg80211.h"
69#include "wlan_hdd_ext_scan.h"
70#include "wlan_hdd_p2p.h"
71#include <linux/rtnetlink.h>
72#include "sap_api.h"
73#include <linux/semaphore.h>
74#include <linux/ctype.h>
75#include <linux/compat.h>
76#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077#include <soc/qcom/subsystem_restart.h>
78#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <wlan_hdd_hostapd.h>
80#include <wlan_hdd_softap_tx_rx.h>
81#include "cfg_api.h"
82#include "qwlan_version.h"
83#include "wma_types.h"
84#include "wlan_hdd_tdls.h"
85#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053086#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070088#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070089#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080090#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include "wlan_hdd_nan.h"
92#include "wlan_hdd_debugfs.h"
93#include "wlan_hdd_driver_ops.h"
94#include "epping_main.h"
95#include "wlan_hdd_memdump.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053096#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097
98#include <wlan_hdd_ipa.h>
99#include "hif.h"
100#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800101#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700102#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800103#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530104#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700105#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700106#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530107#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700108#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530109#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800110#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800111#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530112#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800113#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800114#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530115#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530116#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800117#include "os_if_wifi_pos.h"
118#include "wifi_pos_api.h"
119#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800120#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700121#include "os_if_nan.h"
122#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700123#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700124#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530125#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530126#include "enet.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800127
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530128#ifdef CNSS_GENL
129#include <net/cnss_nl.h>
130#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800131#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530132
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800133#ifdef MODULE
134#define WLAN_MODULE_NAME module_name(THIS_MODULE)
135#else
136#define WLAN_MODULE_NAME "wlan"
137#endif
138
139#ifdef TIMER_MANAGER
140#define TIMER_MANAGER_STR " +TIMER_MANAGER"
141#else
142#define TIMER_MANAGER_STR ""
143#endif
144
145#ifdef MEMORY_DEBUG
146#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
147#else
148#define MEMORY_DEBUG_STR ""
149#endif
150
Sachin Ahujadddd2632017-03-07 19:07:24 +0530151int wlan_start_ret_val;
152static DECLARE_COMPLETION(wlan_start_comp);
153static unsigned int dev_num = 1;
154static struct cdev wlan_hdd_state_cdev;
155static struct class *class;
156static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530157#ifndef MODULE
158static struct gwlan_loader *wlan_loader;
159static ssize_t wlan_boot_cb(struct kobject *kobj,
160 struct kobj_attribute *attr,
161 const char *buf, size_t count);
162struct gwlan_loader {
163 bool loaded_state;
164 struct kobject *boot_wlan_obj;
165 struct attribute_group *attr_group;
166};
167
168static struct kobj_attribute wlan_boot_attribute =
169 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
170
171static struct attribute *attrs[] = {
172 &wlan_boot_attribute.attr,
173 NULL,
174};
175
176#define MODULE_INITIALIZED 1
177#endif
178
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530179#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
180#define MAX_OPS_NAME_STRING_SIZE 20
181
182static qdf_timer_t hdd_drv_ops_inactivity_timer;
183static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185/* the Android framework expects this param even though we don't use it */
186#define BUF_LEN 20
187static char fwpath_buffer[BUF_LEN];
188static struct kparam_string fwpath = {
189 .string = fwpath_buffer,
190 .maxlen = BUF_LEN,
191};
192
193static char *country_code;
194static int enable_11d = -1;
195static int enable_dfs_chan_scan = -1;
196
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800197/*
198 * spinlock for synchronizing asynchronous request/response
199 * (full description of use in wlan_hdd_main.h)
200 */
201DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530202DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800203
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800204#define WLAN_NLINK_CESIUM 30
205
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530206static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800207
208#define WOW_MAX_FILTER_LISTS 1
209#define WOW_MAX_FILTERS_PER_LIST 4
210#define WOW_MIN_PATTERN_SIZE 6
211#define WOW_MAX_PATTERN_SIZE 64
212
213#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
214static const struct wiphy_wowlan_support wowlan_support_reg_init = {
215 .flags = WIPHY_WOWLAN_ANY |
216 WIPHY_WOWLAN_MAGIC_PKT |
217 WIPHY_WOWLAN_DISCONNECT |
218 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
219 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
220 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
221 WIPHY_WOWLAN_4WAY_HANDSHAKE |
222 WIPHY_WOWLAN_RFKILL_RELEASE,
223 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
224 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
225 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
226};
227#endif
228
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700229static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
230 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
231 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
233 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
234 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
235 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
236 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
237 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
242 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
243 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
244 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
245 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
246 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700264 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700265 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700266};
267
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530268int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
269 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
270 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
271 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
272 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
273};
274
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800275/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530276struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800277
278struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800279#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700280static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800281#endif
282
Sachin Ahujadddd2632017-03-07 19:07:24 +0530283void hdd_start_complete(int ret)
284{
285 wlan_start_ret_val = ret;
286
287 complete(&wlan_start_comp);
288}
289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800290/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530291 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700292 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530293 *
294 * Return: none
295 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700296static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530297{
Jeff Johnson9d295242017-08-29 14:39:48 -0700298 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530299 hdd_adapter_list_node_t *adapter_node, *next;
300 QDF_STATUS status = QDF_STATUS_SUCCESS;
301
302 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
303 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -0700304 adapter = adapter_node->adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530305 if (NULL != adapter)
306 hdd_send_rps_ind(adapter);
307 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
308 adapter_node = next;
309 }
310}
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 */
340uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700341
342#ifndef BUILD_TIMESTAMP
343#define BUILD_TIMESTAMP ""
344#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700345uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800346
347/**
348 * hdd_device_mode_to_string() - return string conversion of device mode
349 * @device_mode: device mode
350 *
351 * This utility function helps log string conversion of device mode.
352 *
353 * Return: string conversion of device mode, if match found;
354 * "Unknown" otherwise.
355 */
356const char *hdd_device_mode_to_string(uint8_t device_mode)
357{
358 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800359 CASE_RETURN_STRING(QDF_STA_MODE);
360 CASE_RETURN_STRING(QDF_SAP_MODE);
361 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
362 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
363 CASE_RETURN_STRING(QDF_FTM_MODE);
364 CASE_RETURN_STRING(QDF_IBSS_MODE);
365 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
366 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700367 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800368 default:
369 return "Unknown";
370 }
371}
372
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530373/**
374 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
375 * @adapter: HDD adapter
376 * @chan_number: Channel number
377 * @chan_bw: Bandwidth
378 *
379 * Checks if the given bandwidth is valid for the given channel number.
380 *
381 * Return: 0 for success, non-zero for failure
382 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700383int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530384 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800385 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530386{
387 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
388 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
389 bool found = false;
390 tHalHandle hal;
391
392 hal = WLAN_HDD_GET_HAL_CTX(adapter);
393 if (!hal) {
394 hdd_err("Invalid HAL context");
395 return -EINVAL;
396 }
397
398 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
399 hdd_err("No valid channel list");
400 return -EOPNOTSUPP;
401 }
402
403 for (i = 0; i < len; i++) {
404 if (chan[i] == chan_number) {
405 found = true;
406 break;
407 }
408 }
409
410 if (found == false) {
411 hdd_err("Channel not in driver's valid channel list");
412 return -EOPNOTSUPP;
413 }
414
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700415 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
416 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530417 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
418 return -EINVAL;
419 }
420
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700421 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530422 if (chan_bw == CH_WIDTH_80MHZ) {
423 hdd_err("BW80 not possible in 2.4GHz band");
424 return -EINVAL;
425 }
426 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
427 (chan_bw != CH_WIDTH_MAX)) {
428 hdd_err("Only BW20 possible on channel 14");
429 return -EINVAL;
430 }
431 }
432
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700433 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530434 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
435 (chan_bw != CH_WIDTH_MAX)) {
436 hdd_err("Only BW20 possible on channel 165");
437 return -EINVAL;
438 }
439 }
440
441 return 0;
442}
443
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530444/**
445 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
446 *
447 * Block the unloading of the driver (or) interface up until the
448 * cds recovery is completed
449 *
450 * Return: true for recovery completion else false
451 */
452static bool hdd_wait_for_recovery_completion(void)
453{
454 int retry = 0;
455
456 /* Wait for recovery to complete */
457 while (cds_is_driver_recovering()) {
458 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
459 hdd_err("Recovery in progress; wait here!!!");
460 msleep(1000);
461 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
462 hdd_err("SSR never completed, error");
463 /*
464 * Trigger the bug_on in the internal builds, in the
465 * customer builds self-recovery will be enabled
466 * in those cases just return error.
467 */
468 if (cds_is_self_recovery_enabled())
469 return false;
470 QDF_BUG(0);
471 }
472 }
473
474 hdd_info("Recovery completed successfully!");
475 return true;
476}
477
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800478static int __hdd_netdev_notifier_call(struct notifier_block *nb,
479 unsigned long state, void *data)
480{
481#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
482 struct netdev_notifier_info *dev_notif_info = data;
483 struct net_device *dev = dev_notif_info->dev;
484#else
485 struct net_device *dev = data;
486#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700487 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700488 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800490 ENTER_DEV(dev);
491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800492 /* Make sure that this callback corresponds to our device. */
493 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
494 return NOTIFY_DONE;
495
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530496 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700498 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800499 return NOTIFY_DONE;
500 }
501
502 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700503 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800504 return NOTIFY_DONE;
505 }
506
507 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
508 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800509 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530510 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800511 return NOTIFY_DONE;
512 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530513 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800514 return NOTIFY_DONE;
515
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800516 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800517 dev->name, state);
518
519 switch (state) {
520 case NETDEV_REGISTER:
521 break;
522
523 case NETDEV_UNREGISTER:
524 break;
525
526 case NETDEV_UP:
527 sme_ch_avoid_update_req(hdd_ctx->hHal);
528 break;
529
530 case NETDEV_DOWN:
531 break;
532
533 case NETDEV_CHANGE:
534 if (true == adapter->isLinkUpSvcNeeded)
535 complete(&adapter->linkup_event_var);
536 break;
537
538 case NETDEV_GOING_DOWN:
539 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530540 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
541 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800542 } else {
hqueaa33ee2017-05-04 17:56:35 +0800543 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800544 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800545 }
546 break;
547
548 default:
549 break;
550 }
551
552 return NOTIFY_DONE;
553}
554
555/**
556 * hdd_netdev_notifier_call() - netdev notifier callback function
557 * @nb: pointer to notifier block
558 * @state: state
559 * @ndev: ndev pointer
560 *
561 * Return: 0 on success, error number otherwise.
562 */
563static int hdd_netdev_notifier_call(struct notifier_block *nb,
564 unsigned long state,
565 void *ndev)
566{
567 int ret;
568
569 cds_ssr_protect(__func__);
570 ret = __hdd_netdev_notifier_call(nb, state, ndev);
571 cds_ssr_unprotect(__func__);
572
573 return ret;
574}
575
576struct notifier_block hdd_netdev_notifier = {
577 .notifier_call = hdd_netdev_notifier_call,
578};
579
580/* variable to hold the insmod parameters */
581static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800582
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530583static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700584int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530585
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800586/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800587static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800588
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530589/**
590 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
591 * @ch_width: NL channel width
592 *
593 * Converts the NL channel width to the driver's internal representation
594 *
595 * Return: Converted channel width. In case of non matching NL channel width,
596 * CH_WIDTH_MAX will be returned.
597 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800598enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530599{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800600 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700601
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800602 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530603 switch (ch_width) {
604 case NL80211_CHAN_WIDTH_20_NOHT:
605 case NL80211_CHAN_WIDTH_20:
606 return CH_WIDTH_20MHZ;
607 case NL80211_CHAN_WIDTH_40:
608 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530609 case NL80211_CHAN_WIDTH_80:
610 return CH_WIDTH_80MHZ;
611 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800612 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
613 return CH_WIDTH_80P80MHZ;
614 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
615 return CH_WIDTH_160MHZ;
616 else
617 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530618 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800619 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
620 return CH_WIDTH_160MHZ;
621 else
622 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530623 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800624 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530625 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800626 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530627 default:
628 hdd_err("Invalid channel width %d, setting to default",
629 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800630 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530631 }
632}
633
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530634/* wlan_hdd_find_opclass() - Find operating class for a channel
635 * @hal: handler to HAL
636 * @channel: channel id
637 * @bw_offset: bandwidth offset
638 *
639 * Function invokes sme api to find the operating class
640 *
641 * Return: operating class
642 */
643uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
644 uint8_t bw_offset)
645{
646 uint8_t opclass = 0;
647
648 sme_get_opclass(hal, channel, bw_offset, &opclass);
649 return opclass;
650}
651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800652/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530653 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530654 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800655 * @bitmask: Bitmask of log levels to be enabled
656 *
657 * Called immediately after the cfg.ini is read in order to configure
658 * the desired trace levels.
659 *
660 * Return: None
661 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530662int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530664 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530665 int qdf_print_idx = -1;
666 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800667 /*
668 * if the bitmask is the default value, then a bitmask was not
669 * specified in cfg.ini, so leave the logging level alone (it
670 * will remain at the "compiled in" default value)
671 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700672 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530673 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530675 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800676
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530677 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530678 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530679 QDF_TRACE_LEVEL_NONE, 0);
680
681 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530682 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800683 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530684 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800685 while (0 != bitmask) {
686 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530687 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530688 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530689 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530690 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693 level++;
694 bitmask >>= 1;
695 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530696 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800697}
698
699/**
Chris Guo1751acf2017-07-03 14:09:01 +0800700 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
701 * @hdd_ctx: HDD context pointer
702 *
703 * Return: 0 if the context is valid. Error code otherwise
704 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700705int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800706{
707 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
708 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
709 return -ENODEV;
710 }
711
712 if (cds_is_driver_recovering()) {
713 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
714 (void *)_RET_IP_, cds_get_driver_state());
715 return -EAGAIN;
716 }
717
718 if (hdd_ctx->start_modules_in_progress ||
719 hdd_ctx->stop_modules_in_progress) {
720 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
721 (void *)_RET_IP_);
722 return -EAGAIN;
723 }
724
725 return 0;
726}
727
728
729/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800730 * wlan_hdd_validate_context() - check the HDD context
731 * @hdd_ctx: HDD context pointer
732 *
733 * Return: 0 if the context is valid. Error code otherwise
734 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700735int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800737 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530738 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 return -ENODEV;
740 }
741
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800742 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800743 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530744 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 return -EAGAIN;
746 }
747
Yue Ma9f275d92017-09-14 16:58:41 -0700748 if (cds_is_load_or_unload_in_progress()) {
749 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
750 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800751 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700752 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530753
754 if (hdd_ctx->start_modules_in_progress ||
755 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800756 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530757 (void *)_RET_IP_);
758 return -EAGAIN;
759 }
760
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530761 if (cds_is_driver_in_bad_state()) {
762 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
763 (void *)_RET_IP_, cds_get_driver_state());
764 return -ENODEV;
765 }
766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767 return 0;
768}
769
Jeff Johnson9d295242017-08-29 14:39:48 -0700770int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700771{
772 if (!adapter) {
773 hdd_err("adapter is null");
774 return -EINVAL;
775 }
776
777 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
778 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
779 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
780 return -EINVAL;
781 }
782
783 if (!adapter->dev) {
784 hdd_err("adapter net_device is null");
785 return -EINVAL;
786 }
787
788 if (!(adapter->dev->flags & IFF_UP)) {
789 hdd_info("adapter net_device is not up");
790 return -EAGAIN;
791 }
792
793 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
794 hdd_info("adapter session is not open");
795 return -EAGAIN;
796 }
797
798 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
799 hdd_err("bad adapter session Id: %u", adapter->sessionId);
800 return -EINVAL;
801 }
802
803 return 0;
804}
805
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800806/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530807 * wlan_hdd_validate_modules_state() - Check modules status
808 * @hdd_ctx: HDD context pointer
809 *
810 * Check's the driver module's state and returns true if the
811 * modules are enabled returns false if modules are closed.
812 *
813 * Return: True if modules are enabled or false.
814 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700815bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530816{
817 mutex_lock(&hdd_ctx->iface_change_lock);
818 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
819 mutex_unlock(&hdd_ctx->iface_change_lock);
820 hdd_notice("Modules not enabled, Present status: %d",
821 hdd_ctx->driver_status);
822 return false;
823 }
824 mutex_unlock(&hdd_ctx->iface_change_lock);
825 return true;
826}
827
828/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700830 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 *
832 * This function sets the IBSS power save config parameters to WMA
833 * which will send it to firmware if FW supports IBSS power save
834 * before vdev start.
835 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530836 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 * on failure.
838 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700839QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840{
841 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700842 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800843
844 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700845 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530846 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 }
848
Naveen Rawat247a8682017-06-05 15:00:31 -0700849 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
851 hdd_ctx->config->ibssATIMWinSize,
852 VDEV_CMD);
853 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700854 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530855 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856 }
857
Naveen Rawat247a8682017-06-05 15:00:31 -0700858 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
860 hdd_ctx->config->isIbssPowerSaveAllowed,
861 VDEV_CMD);
862 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700863 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
864 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530865 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 }
867
Naveen Rawat247a8682017-06-05 15:00:31 -0700868 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
870 hdd_ctx->config->
871 isIbssPowerCollapseAllowed, VDEV_CMD);
872 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700873 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
874 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530875 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876 }
877
Naveen Rawat247a8682017-06-05 15:00:31 -0700878 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
880 hdd_ctx->config->isIbssAwakeOnTxRx,
881 VDEV_CMD);
882 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700883 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530884 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885 }
886
Naveen Rawat247a8682017-06-05 15:00:31 -0700887 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800888 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
889 hdd_ctx->config->ibssInactivityCount,
890 VDEV_CMD);
891 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700892 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530893 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894 }
895
Naveen Rawat247a8682017-06-05 15:00:31 -0700896 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800897 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
898 hdd_ctx->config->ibssTxSpEndInactivityTime,
899 VDEV_CMD);
900 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700901 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
902 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530903 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 }
905
Naveen Rawat247a8682017-06-05 15:00:31 -0700906 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
908 hdd_ctx->config->ibssPsWarmupTime,
909 VDEV_CMD);
910 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700911 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
912 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530913 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 }
915
Naveen Rawat247a8682017-06-05 15:00:31 -0700916 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
918 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
919 VDEV_CMD);
920 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700921 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
922 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530923 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 }
925
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530926 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927}
928
Yue Macd359b72017-10-03 15:21:00 -0700929#ifdef FEATURE_RUNTIME_PM
930/**
931 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
932 * @hdd_ctx: HDD context
933 *
934 * Return: None
935 */
936static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
937{
938 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
939
940 qdf_runtime_lock_init(&ctx->roc);
941 qdf_runtime_lock_init(&ctx->dfs);
942
943 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
944}
945
946/**
947 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
948 * @hdd_ctx: HDD Context
949 *
950 * Return: None
951 */
952static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
953{
954 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
955
956 qdf_runtime_lock_deinit(&ctx->roc);
957 qdf_runtime_lock_deinit(&ctx->dfs);
958
959 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
960}
961
962static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
963{
964 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
965
966 qdf_runtime_lock_init(&ctx->connect);
967}
968
969static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
970{
971 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
972
973 qdf_runtime_lock_deinit(&ctx->connect);
974}
975#else /* FEATURE_RUNTIME_PM */
976static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
977static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
978static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
979static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
980#endif /* FEATURE_RUNTIME_PM */
981
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800982#define INTF_MACADDR_MASK 0x7
983
984/**
985 * hdd_update_macaddr() - update mac address
986 * @config: hdd configuration
987 * @hw_macaddr: mac address
988 *
989 * Mac address for multiple virtual interface is found as following
990 * i) The mac address of the first interface is just the actual hw mac address.
991 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
992 * define the mac address for the remaining interfaces and locally
993 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
994 * supported virtual interfaces, right now this is 0x07 (meaning 8
995 * interface).
996 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
997 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
998 *
999 * Return: None
1000 */
1001void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301002 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003{
1004 int8_t i;
1005 uint8_t macaddr_b3, tmp_br3;
1006
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301007 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301008 QDF_MAC_ADDR_SIZE);
1009 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301010 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301011 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1013 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1014 INTF_MACADDR_MASK;
1015 macaddr_b3 += tmp_br3;
1016
1017 /* XOR-ing bit-24 of the mac address. This will give enough
1018 * mac address range before collision
1019 */
1020 macaddr_b3 ^= (1 << 7);
1021
1022 /* Set locally administered bit */
1023 config->intfMacAddr[i].bytes[0] |= 0x02;
1024 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001025 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026 MAC_ADDRESS_STR, i,
1027 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1028 }
1029}
1030
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001031static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032 struct wma_tgt_services *cfg)
1033{
1034 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001035
1036 /* Set up UAPSD */
1037 config->apUapsdEnabled &= cfg->uapsd;
1038
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001039 /* 11AX mode support */
1040 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1041 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1042 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1043
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 /* 11AC mode support */
1045 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1046 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1047 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001048
1049 /* ARP offload: override user setting if invalid */
1050 config->fhostArpOffload &= cfg->arp_offload;
1051
1052#ifdef FEATURE_WLAN_SCAN_PNO
1053 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001054 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001055 if (cfg->pno_offload)
1056 config->PnoOffload = true;
1057#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058#ifdef FEATURE_WLAN_TDLS
1059 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301060 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1061 cfg->en_tdls_offchan;
1062 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1063 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001064 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001066 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001069#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1070 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1071#endif
Will Huang496b36c2017-07-11 16:38:50 +08001072 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001073 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074
1075}
1076
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001077/**
1078 * hdd_update_vdev_nss() - sets the vdev nss
1079 * @hdd_ctx: HDD context
1080 *
1081 * Sets the Nss per vdev type based on INI
1082 *
1083 * Return: None
1084 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001085static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001086{
1087 struct hdd_config *cfg_ini = hdd_ctx->config;
1088 uint8_t max_supp_nss = 1;
1089
Naveen Rawat10b1c152017-01-18 11:16:06 -08001090 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001091 max_supp_nss = 2;
1092
1093 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1094 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1095
1096 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1097 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1098}
1099
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301100/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301101 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1102 * @hdd_ctx: HDD context
1103 *
1104 * Updates wiphy vhtcap fields
1105 *
1106 * Return: None
1107 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001108static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301109{
1110 struct ieee80211_supported_band *band_5g =
1111 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1112 uint32_t val;
1113
1114 if (!band_5g) {
1115 hdd_debug("5GHz band disabled, skipping capability population");
1116 return;
1117 }
1118
1119 val = hdd_ctx->config->txBFCsnValue;
1120 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1121
1122 val = NUM_OF_SOUNDING_DIMENSIONS;
1123 band_5g->vht_cap.cap |=
1124 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1125
1126 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1127 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1128}
1129
1130/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301131 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1132 * @hdd_ctx: HDD context
1133 *
1134 * Sets the DBS capability as per INI and firmware capability
1135 *
1136 * Return: None
1137 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001138static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301139{
1140 struct hdd_config *cfg_ini = hdd_ctx->config;
1141 uint8_t hw_dbs_capable = 0;
1142
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001143 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1144 ((cfg_ini->dual_mac_feature_disable ==
1145 ENABLE_DBS_CXN_AND_SCAN) ||
1146 (cfg_ini->dual_mac_feature_disable ==
1147 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301148 hw_dbs_capable = 1;
1149
1150 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1151}
1152
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001153static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001154 struct wma_tgt_ht_cap *cfg)
1155{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301156 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157 uint32_t value, val32;
1158 uint16_t val16;
1159 struct hdd_config *pconfig = hdd_ctx->config;
1160 tSirMacHTCapabilityInfo *phtCapInfo;
1161 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1162 uint8_t enable_tx_stbc;
1163
1164 /* check and update RX STBC */
1165 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1166 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1167
1168 /* get the MPDU density */
1169 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1170
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301171 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001172 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001173 value = 0;
1174 }
1175
1176 /*
1177 * MPDU density:
1178 * override user's setting if value is larger
1179 * than the one supported by target
1180 */
1181 if (value > cfg->mpdu_density) {
1182 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1183 cfg->mpdu_density);
1184
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301185 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001186 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001187 }
1188
1189 /* get the HT capability info */
1190 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301191 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001192 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193 return;
1194 }
1195 val16 = (uint16_t) val32;
1196 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1197
1198 /* Set the LDPC capability */
1199 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1200
1201 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1202 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1203
1204 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1205 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1206
1207 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1208 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1209
1210 enable_tx_stbc = pconfig->enableTxSTBC;
1211
1212 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1213 pconfig->enable2x2 = 1;
1214 } else {
1215 pconfig->enable2x2 = 0;
1216 enable_tx_stbc = 0;
1217
1218 /* 1x1 */
1219 /* Update Rx Highest Long GI data Rate */
1220 if (sme_cfg_set_int(hdd_ctx->hHal,
1221 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001222 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301223 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001224 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001225 }
1226
1227 /* Update Tx Highest Long GI data Rate */
1228 if (sme_cfg_set_int
1229 (hdd_ctx->hHal,
1230 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001231 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301232 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001233 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234 }
1235 }
1236 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1237 enable_tx_stbc = 0;
1238 phtCapInfo->txSTBC = enable_tx_stbc;
1239
1240 val32 = val16;
1241 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301242 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001243 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1245 value = SIZE_OF_SUPPORTED_MCS_SET;
1246 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301247 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001248 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249
1250 if (pconfig->enable2x2) {
1251 for (value = 0; value < cfg->num_rf_chains; value++)
1252 mcs_set[value] =
1253 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1254
1255 status =
1256 sme_cfg_set_str(hdd_ctx->hHal,
1257 WNI_CFG_SUPPORTED_MCS_SET,
1258 mcs_set,
1259 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301260 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001261 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001262 }
1263 }
1264#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1265}
1266
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001267static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001268 struct wma_tgt_vht_cap *cfg)
1269{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301270 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001271 uint32_t value = 0;
1272 struct hdd_config *pconfig = hdd_ctx->config;
1273 struct wiphy *wiphy = hdd_ctx->wiphy;
1274 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001275 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001276 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001277 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001278 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001279
Dustin Brown5e06bd32016-10-04 12:49:10 -07001280 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001281 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001282 return;
1283 }
1284
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001285 /* Get the current MPDU length */
1286 status =
1287 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1288 &value);
1289
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301290 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001291 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001292 value = 0;
1293 }
1294
1295 /*
1296 * VHT max MPDU length:
1297 * override if user configured value is too high
1298 * that the target cannot support
1299 */
1300 if (value > cfg->vht_max_mpdu) {
1301 status = sme_cfg_set_int(hdd_ctx->hHal,
1302 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1303 cfg->vht_max_mpdu);
1304
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001305 if (status == QDF_STATUS_E_FAILURE)
1306 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001307 }
1308
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001309 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1310 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1311
1312 if (pconfig->enable2x2)
1313 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1314
1315 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1316 QDF_STATUS_E_FAILURE) {
1317 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1318 }
1319
1320 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1321 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1322 if (pconfig->enable2x2)
1323 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1324
1325 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1326 QDF_STATUS_E_FAILURE) {
1327 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1328 }
1329
1330 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1331 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1332 if (pconfig->enable2x2)
1333 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1334
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001335 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001336 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1337
1338 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1339 QDF_STATUS_E_FAILURE) {
1340 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1341 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001343 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344 &value);
1345
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301346 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001347 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001348 value = 0;
1349 }
1350
jiad4a7a33c2017-08-08 15:32:24 +08001351 /* Set HW RX LDPC capability */
1352 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1353 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 status = sme_cfg_set_int(hdd_ctx->hHal,
1355 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001356 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001357
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001358 if (status == QDF_STATUS_E_FAILURE)
1359 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 }
1361
1362 /* Get current GI 80 value */
1363 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1364 &value);
1365
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301366 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001367 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001368 value = 0;
1369 }
1370
1371 /* set the Guard interval 80MHz */
1372 if (value && !cfg->vht_short_gi_80) {
1373 status = sme_cfg_set_int(hdd_ctx->hHal,
1374 WNI_CFG_VHT_SHORT_GI_80MHZ,
1375 cfg->vht_short_gi_80);
1376
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001377 if (status == QDF_STATUS_E_FAILURE)
1378 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379 }
1380
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001381 /* Get VHT TX STBC cap */
1382 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1383
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301384 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001385 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386 value = 0;
1387 }
1388
1389 /* VHT TX STBC cap */
1390 if (value && !cfg->vht_tx_stbc) {
1391 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1392 cfg->vht_tx_stbc);
1393
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001394 if (status == QDF_STATUS_E_FAILURE)
1395 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396 }
1397
1398 /* Get VHT RX STBC cap */
1399 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1400
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301401 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001402 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 value = 0;
1404 }
1405
1406 /* VHT RX STBC cap */
1407 if (value && !cfg->vht_rx_stbc) {
1408 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1409 cfg->vht_rx_stbc);
1410
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001411 if (status == QDF_STATUS_E_FAILURE)
1412 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 }
1414
1415 /* Get VHT SU Beamformer cap */
1416 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1417 &value);
1418
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301419 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001420 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001421 value = 0;
1422 }
1423
1424 /* set VHT SU Beamformer cap */
1425 if (value && !cfg->vht_su_bformer) {
1426 status = sme_cfg_set_int(hdd_ctx->hHal,
1427 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1428 cfg->vht_su_bformer);
1429
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001430 if (status == QDF_STATUS_E_FAILURE)
1431 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001432 }
1433
1434 /* check and update SU BEAMFORMEE capabality */
1435 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1436 pconfig->enableTxBF = cfg->vht_su_bformee;
1437
1438 status = sme_cfg_set_int(hdd_ctx->hHal,
1439 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1440 pconfig->enableTxBF);
1441
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001442 if (status == QDF_STATUS_E_FAILURE)
1443 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001444
1445 /* Get VHT MU Beamformer cap */
1446 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1447 &value);
1448
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301449 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001450 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451 value = 0;
1452 }
1453
1454 /* set VHT MU Beamformer cap */
1455 if (value && !cfg->vht_mu_bformer) {
1456 status = sme_cfg_set_int(hdd_ctx->hHal,
1457 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1458 cfg->vht_mu_bformer);
1459
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001460 if (status == QDF_STATUS_E_FAILURE)
1461 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001462 }
1463
1464 /* Get VHT MU Beamformee cap */
1465 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1466 &value);
1467
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301468 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001469 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001470 value = 0;
1471 }
1472
1473 /* set VHT MU Beamformee cap */
1474 if (value && !cfg->vht_mu_bformee) {
1475 status = sme_cfg_set_int(hdd_ctx->hHal,
1476 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1477 cfg->vht_mu_bformee);
1478
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001479 if (status == QDF_STATUS_E_FAILURE)
1480 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481 }
1482
1483 /* Get VHT MAX AMPDU Len exp */
1484 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1485 &value);
1486
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301487 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001488 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001489 value = 0;
1490 }
1491
1492 /*
1493 * VHT max AMPDU len exp:
1494 * override if user configured value is too high
1495 * that the target cannot support.
1496 * Even though Rome publish ampdu_len=7, it can
1497 * only support 4 because of some h/w bug.
1498 */
1499
1500 if (value > cfg->vht_max_ampdu_len_exp) {
1501 status = sme_cfg_set_int(hdd_ctx->hHal,
1502 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1503 cfg->vht_max_ampdu_len_exp);
1504
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001505 if (status == QDF_STATUS_E_FAILURE)
1506 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507 }
1508
1509 /* Get VHT TXOP PS CAP */
1510 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1511
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301512 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001513 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514 value = 0;
1515 }
1516
1517 /* set VHT TXOP PS cap */
1518 if (value && !cfg->vht_txop_ps) {
1519 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1520 cfg->vht_txop_ps);
1521
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001522 if (status == QDF_STATUS_E_FAILURE)
1523 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001524 }
1525
1526 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1527 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1528 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1529 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1530 else
1531 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1532
1533
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001534 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1535 status = sme_cfg_set_int(hdd_ctx->hHal,
1536 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1537 VHT_CAP_160_AND_80P80_SUPP);
1538 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001539 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001540 band_5g->vht_cap.cap |=
1541 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001542 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1543 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1544 status = sme_cfg_set_int(hdd_ctx->hHal,
1545 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1546 VHT_CAP_160_SUPP);
1547 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001548 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549 band_5g->vht_cap.cap |=
1550 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001551 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1552 }
1553 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1554 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301555 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001556 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301557 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001558 &value);
1559 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301560 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001561 value = 0;
1562 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301563 /* set the Guard interval 160MHz */
1564 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001565 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301566 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1567 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001568
1569 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301570 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001571 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001572
1573 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1574 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1575
1576 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1577 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1578 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1579 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1580
1581 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1582 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1583
1584 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1585 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1586 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1587 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1588 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1589 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1590
1591 band_5g->vht_cap.cap |=
1592 (cfg->vht_max_ampdu_len_exp <<
1593 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1594
1595 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1596 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1597 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1598 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1599 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1600 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1601 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1602 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1603
1604 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1605 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1606
1607}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001609/**
1610 * hdd_generate_macaddr_auto() - Auto-generate mac address
1611 * @hdd_ctx: Pointer to the HDD context
1612 *
1613 * Auto-generate mac address using device serial number.
1614 * Keep the first 3 bytes of OUI as before and replace
1615 * the last 3 bytes with the lower 3 bytes of serial number.
1616 *
1617 * Return: 0 for success
1618 * Non zero failure code for errors
1619 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001620static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001621{
1622 unsigned int serialno = 0;
1623 struct qdf_mac_addr mac_addr = {
1624 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1625 };
1626
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001627 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001628 if (serialno == 0)
1629 return -EINVAL;
1630
1631 serialno &= 0x00ffffff;
1632
1633 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1634 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1635 mac_addr.bytes[5] = serialno & 0xff;
1636
1637 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1638 return 0;
1639}
1640
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301641/**
1642 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1643 * configuration to cfg_ini in HDD
1644 * @hdd_ctx: Pointer to hdd_ctx
1645 * @cfg: target configuration
1646 *
1647 * Return: None
1648 */
1649#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001650static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301651 struct wma_tgt_cfg *cfg)
1652{
1653 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1654}
1655#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001656static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301657 struct wma_tgt_cfg *cfg)
1658{
1659}
1660#endif
1661
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001662void hdd_update_tgt_cfg(void *context, void *param)
1663{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001664 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001665 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 struct wma_tgt_cfg *cfg = param;
1667 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001668 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301669 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301670
Yue Mae3e86ab2017-05-08 10:48:24 -07001671 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301672 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1673 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1674 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1675 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1676 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001677 /* Restore pdev to MAC/WMA contexts */
1678 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001679 } else {
1680 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1681 if (ret) {
1682 hdd_err("pdev creation fails!");
1683 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301684 } else
1685 hdd_debug("New pdev has been created with pdev_id = %u",
1686 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301687 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001688
Naveen Rawat64e477e2016-05-20 10:34:56 -07001689 if (cds_cfg) {
1690 if (hdd_ctx->config->enable_sub_20_channel_width !=
1691 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1692 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1693 cds_cfg->sub_20_channel_width =
1694 WLAN_SUB_20_CH_WIDTH_NONE;
1695 } else {
1696 cds_cfg->sub_20_channel_width =
1697 hdd_ctx->config->enable_sub_20_channel_width;
1698 }
1699 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001700
1701 /* first store the INI band capability */
1702 temp_band_cap = hdd_ctx->config->nBandCapability;
1703
1704 hdd_ctx->config->nBandCapability = cfg->band_cap;
1705
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001706 /*
1707 * now overwrite the target band capability with INI
1708 * setting if INI setting is a subset
1709 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001710
1711 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1712 (temp_band_cap != eCSR_BAND_ALL))
1713 hdd_ctx->config->nBandCapability = temp_band_cap;
1714 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1715 (temp_band_cap != eCSR_BAND_ALL) &&
1716 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001717 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718 }
1719
Amar Singhal58b45ef2017-08-01 13:43:54 -07001720 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1721
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301722 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001723 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1724 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1725 }
1726
1727 /* This can be extended to other configurations like ht, vht cap... */
1728
Anurag Chouhanc5548422016-02-24 18:33:27 +05301729 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001731 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001733 static struct qdf_mac_addr default_mac_addr = {
1734 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1735 };
1736 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1737 &default_mac_addr)) {
1738 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1739 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1740 MAC_ADDRESS_STR,
1741 MAC_ADDR_ARRAY(hdd_ctx->config->
1742 intfMacAddr[0].bytes));
1743 } else {
1744 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1745 MAC_ADDRESS_STR,
1746 MAC_ADDR_ARRAY(hdd_ctx->config->
1747 intfMacAddr[0].bytes));
1748 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001749 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001750 }
1751
1752 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001753 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001754
1755 hdd_ctx->max_intf_count = cfg->max_intf_count;
1756
Jeff Johnsonc875e242016-09-23 18:12:34 -07001757 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001758 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001759
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001760 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1761 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1762
1763 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001765 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001766 if (cfg->services.en_11ax) {
1767 hdd_info("11AX: 11ax is enabled - update HDD config");
1768 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1769 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001770
1771 hdd_update_vdev_nss(hdd_ctx);
1772
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301773 hdd_update_hw_dbs_capable(hdd_ctx);
1774
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001775 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001776 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001777 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001778 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001779
Nitesh Shahe50711f2017-04-26 16:30:45 +05301780 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1781 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1782 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001783 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001784 hdd_ctx->current_antenna_mode);
1785
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001786 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1787 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301788 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301789
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301790 if ((hdd_ctx->config->txBFCsnValue >
1791 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1792 !cfg->tx_bfee_8ss_enabled)
1793 hdd_ctx->config->txBFCsnValue =
1794 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1795
1796 if (sme_cfg_set_int(hdd_ctx->hHal,
1797 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1798 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1799 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1800
1801
1802 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1803 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1804 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301805
1806 /*
1807 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1808 */
1809 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301810
1811 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1812
Arun Khandavallid454d422016-08-17 12:47:05 +05301813 /*
1814 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1815 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1816 * configure the STA mode wow pattern.
1817 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301818 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301819 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301820
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301821 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1822
Yue Macd359b72017-10-03 15:21:00 -07001823 /*
1824 * This needs to be done after HDD pdev is created and stored since
1825 * it will access the HDD pdev object lock.
1826 */
1827 hdd_runtime_suspend_context_init(hdd_ctx);
1828
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001829 /* Configure NAN datapath features */
1830 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001831 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001832}
1833
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001834bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001835{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001836 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001837 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301838 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001839 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840
Arif Hussaincd151632017-02-11 16:57:19 -08001841 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001842 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001843 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301844 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001845 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001846
Arif Hussaincd151632017-02-11 16:57:19 -08001847 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1848 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001849 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001850 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1851
1852 if ((QDF_SAP_MODE == adapter->device_mode ||
1853 QDF_P2P_GO_MODE == adapter->device_mode) &&
1854 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1855 ap_ctx->operatingChannel))) {
1856 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1857 true;
1858 hdd_info("tx blocked for session: %d",
1859 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301860 }
Arif Hussaincd151632017-02-11 16:57:19 -08001861 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1862 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301864
1865 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001866}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001867
1868/**
1869 * hdd_is_valid_mac_address() - validate MAC address
1870 * @pMacAddr: Pointer to the input MAC address
1871 *
1872 * This function validates whether the given MAC address is valid or not
1873 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1874 * where X is the hexa decimal digit character and separated by ':'
1875 * This algorithm works even if MAC address is not separated by ':'
1876 *
1877 * This code checks given input string mac contains exactly 12 hexadecimal
1878 * digits and a separator colon : appears in the input string only after
1879 * an even number of hex digits.
1880 *
1881 * Return: 1 for valid and 0 for invalid
1882 */
1883bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1884{
1885 int xdigit = 0;
1886 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001888 while (*pMacAddr) {
1889 if (isxdigit(*pMacAddr)) {
1890 xdigit++;
1891 } else if (':' == *pMacAddr) {
1892 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1893 break;
1894
1895 ++separator;
1896 } else {
1897 /* Invalid MAC found */
1898 return 0;
1899 }
1900 ++pMacAddr;
1901 }
1902 return xdigit == 12 && (separator == 5 || separator == 0);
1903}
1904
1905/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301906 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1907 * @dev: Handle to struct net_device to be updated.
1908 *
1909 * Return: None
1910 */
1911static void hdd_mon_mode_ether_setup(struct net_device *dev)
1912{
1913 dev->header_ops = NULL;
1914 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1915 dev->hard_header_len = ETH_HLEN;
1916 dev->mtu = ETH_DATA_LEN;
1917 dev->addr_len = ETH_ALEN;
1918 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1919 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1920 dev->priv_flags |= IFF_TX_SKB_SHARING;
1921
1922 memset(dev->broadcast, 0xFF, ETH_ALEN);
1923}
1924
1925/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001926 * __hdd__mon_open() - HDD Open function
1927 * @dev: Pointer to net_device structure
1928 *
1929 * This is called in response to ifconfig up
1930 *
1931 * Return: 0 for success; non-zero for failure
1932 */
1933static int __hdd_mon_open(struct net_device *dev)
1934{
1935 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001936 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1937 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001938
1939 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001940
1941 ret = wlan_hdd_validate_context(hdd_ctx);
1942 if (ret)
1943 return ret;
1944
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301945 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001946
1947 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1948 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1949 if (ret) {
1950 hdd_err("Failed to start WLAN modules return");
1951 return ret;
1952 }
1953 hdd_err("hdd_wlan_start_modules() successful !");
1954
1955 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1956 ret = hdd_start_adapter(adapter);
1957 if (ret) {
1958 hdd_err("Failed to start adapter :%d",
1959 adapter->device_mode);
1960 return ret;
1961 }
1962 hdd_err("hdd_start_adapters() successful !");
1963 }
1964 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1965 }
1966
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001967 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001968
1969 if (!ret)
1970 ret = hdd_enable_monitor_mode(dev);
1971
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001972 return ret;
1973}
1974
1975/**
1976 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1977 * @dev: Pointer to net_device structure
1978 *
1979 * This is called in response to ifconfig up
1980 *
1981 * Return: 0 for success; non-zero for failure
1982 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001983static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001984{
1985 int ret;
1986
1987 cds_ssr_protect(__func__);
1988 ret = __hdd_mon_open(dev);
1989 cds_ssr_unprotect(__func__);
1990
1991 return ret;
1992}
1993
1994/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301995 * hdd_start_adapter() - Wrapper function for device specific adapter
1996 * @adapter: pointer to HDD adapter
1997 *
1998 * This function is called to start the device specific adapter for
1999 * the mode passed in the adapter's device_mode.
2000 *
2001 * Return: 0 for success; non-zero for failure
2002 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002003int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302004{
2005
2006 int ret;
2007 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
2008
2009 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002010 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302011
2012 switch (device_mode) {
2013 case QDF_P2P_CLIENT_MODE:
2014 case QDF_P2P_DEVICE_MODE:
2015 case QDF_OCB_MODE:
2016 case QDF_STA_MODE:
2017 case QDF_MONITOR_MODE:
2018 ret = hdd_start_station_adapter(adapter);
2019 if (ret)
2020 goto err_start_adapter;
2021 break;
2022 case QDF_P2P_GO_MODE:
2023 case QDF_SAP_MODE:
2024 ret = hdd_start_ap_adapter(adapter);
2025 if (ret)
2026 goto err_start_adapter;
2027 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302028 case QDF_IBSS_MODE:
2029 /*
2030 * For IBSS interface is initialized as part of
2031 * hdd_init_station_mode()
2032 */
2033 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302034 case QDF_FTM_MODE:
2035 ret = hdd_start_ftm_adapter(adapter);
2036 if (ret)
2037 goto err_start_adapter;
2038 break;
2039 default:
2040 hdd_err("Invalid session type %d", device_mode);
2041 QDF_ASSERT(0);
2042 goto err_start_adapter;
2043 }
2044 if (hdd_set_fw_params(adapter))
2045 hdd_err("Failed to set the FW params for the adapter!");
2046
2047 /*
2048 * Action frame registered in one adapter which will
2049 * applicable to all interfaces
2050 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302051 ret = wlan_hdd_cfg80211_register_frames(adapter);
2052 if (ret < 0) {
2053 hdd_err("Failed to register frames - ret %d", ret);
2054 goto err_start_adapter;
2055 }
2056
Arun Khandavallifae92942016-08-01 13:31:08 +05302057 EXIT();
2058 return 0;
2059err_start_adapter:
2060 return -EINVAL;
2061}
2062
2063/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302064 * hdd_enable_power_management() - API to Enable Power Management
2065 *
2066 * API invokes Bus Interface Layer power management functionality
2067 *
2068 * Return: None
2069 */
2070static void hdd_enable_power_management(void)
2071{
2072 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2073
2074 if (!hif_ctx) {
2075 hdd_err("Bus Interface Context is Invalid");
2076 return;
2077 }
2078
2079 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2080}
2081
2082/**
2083 * hdd_disable_power_management() - API to disable Power Management
2084 *
2085 * API disable Bus Interface Layer Power management functionality
2086 *
2087 * Return: None
2088 */
2089static void hdd_disable_power_management(void)
2090{
2091 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2092
2093 if (!hif_ctx) {
2094 hdd_err("Bus Interface Context is Invalid");
2095 return;
2096 }
2097
2098 hif_disable_power_management(hif_ctx);
2099}
2100
2101/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302102 * hdd_update_hw_sw_info() - API to update the HW/SW information
2103 *
2104 * API to update the HW and SW information in the driver
2105 *
2106 * Return: None
2107 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002108static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302109{
2110 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002111 size_t target_hw_name_len;
2112 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302113
2114 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2115 if (!hif_sc) {
2116 hdd_err("HIF context is NULL");
2117 return;
2118 }
2119
2120 /*
2121 * target hw version/revision would only be retrieved after firmware
2122 * download
2123 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002124 hif_get_hw_info(hif_sc,
2125 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302126 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002127 &target_hw_name);
2128
2129 if (hdd_ctx->target_hw_name)
2130 qdf_mem_free(hdd_ctx->target_hw_name);
2131
2132 target_hw_name_len = strlen(target_hw_name) + 1;
2133 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2134 if (hdd_ctx->target_hw_name)
2135 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2136 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302137
2138 /* Get the wlan hw/fw version */
2139 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302140}
2141
2142/**
gbian62edd7e2017-03-07 13:12:13 +08002143 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2144 * @hdd_ctx: Pointer to hdd context
2145 *
2146 * Return: none
2147 */
2148static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002149hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002150{
2151 uint8_t num_entries = 0;
2152 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2153 uint8_t *tx_sched_wrr_ac;
2154 int i;
2155 cds_context_type *cds_ctx;
2156
2157 if (NULL == hdd_ctx)
2158 return;
2159
2160 if (NULL == hdd_ctx->config) {
2161 /* Do nothing if hdd_ctx is invalid */
2162 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2163 return;
2164 }
2165
2166 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2167
2168 if (!cds_ctx) {
2169 hdd_err("Invalid CDS Context");
2170 return;
2171 }
2172
2173 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2174 switch (i) {
2175 case OL_TX_WMM_AC_BE:
2176 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2177 break;
2178 case OL_TX_WMM_AC_BK:
2179 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2180 break;
2181 case OL_TX_WMM_AC_VI:
2182 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2183 break;
2184 case OL_TX_WMM_AC_VO:
2185 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2186 break;
2187 default:
2188 tx_sched_wrr_ac = NULL;
2189 break;
2190 }
2191
2192 hdd_string_to_u8_array(tx_sched_wrr_ac,
2193 tx_sched_wrr_param,
2194 &num_entries,
2195 sizeof(tx_sched_wrr_param));
2196
2197 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2198 cds_ctx->ac_specs[i].wrr_skip_weight =
2199 tx_sched_wrr_param[0];
2200 cds_ctx->ac_specs[i].credit_threshold =
2201 tx_sched_wrr_param[1];
2202 cds_ctx->ac_specs[i].send_limit =
2203 tx_sched_wrr_param[2];
2204 cds_ctx->ac_specs[i].credit_reserve =
2205 tx_sched_wrr_param[3];
2206 cds_ctx->ac_specs[i].discard_weight =
2207 tx_sched_wrr_param[4];
2208 }
2209
2210 num_entries = 0;
2211 }
2212}
2213
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002214#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002215static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2216 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2217{
Jeff Johnson9d295242017-08-29 14:39:48 -07002218 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002219 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002220
2221 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2222 if (!adapter) {
2223 hdd_err("Adapter is NULL");
2224 return PM_MAX_NUM_OF_MODE;
2225 }
2226
2227 return policy_mgr_convert_device_mode_to_qdf_type(
2228 adapter->device_mode);
2229}
2230
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002231static void hdd_register_policy_manager_callback(
2232 struct wlan_objmgr_psoc *psoc)
2233{
2234 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002235
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002236 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002237 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002238 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2239 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002240 hdd_cbacks.get_mode_for_non_connected_vdev =
2241 wlan_hdd_get_mode_for_non_connected_vdev;
2242
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002243 if (QDF_STATUS_SUCCESS !=
2244 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2245 hdd_err("HDD callback registration with policy manager failed");
2246 }
2247}
2248#else
2249static void hdd_register_policy_manager_callback(
2250 struct wlan_objmgr_psoc *psoc)
2251{
2252}
2253#endif
2254
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002255#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002256static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002257{
2258 struct nan_callbacks cb_obj = {0};
2259
2260 cb_obj.ndi_open = hdd_ndi_open;
2261 cb_obj.ndi_close = hdd_ndi_close;
2262 cb_obj.ndi_start = hdd_ndi_start;
2263 cb_obj.ndi_delete = hdd_ndi_delete;
2264 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2265 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2266
Naveen Rawat37f62c82017-03-26 22:24:43 -07002267 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2268 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002269 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002270
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002271 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2272}
2273#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002274static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002275{
2276}
2277#endif
2278
gbian62edd7e2017-03-07 13:12:13 +08002279/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302280 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2281 * @hdd_ctx: HDD context
2282 * @adapter: HDD adapter
2283 * @reinit: flag to indicate from SSR or normal path
2284 *
2285 * This function maintains the driver state machine it will be invoked from
2286 * startup, reinit and change interface. Depending on the driver state shall
2287 * perform the opening of the modules.
2288 *
2289 * Return: 0 for success; non-zero for failure
2290 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002291int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2292 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302293 bool reinit)
2294{
2295 int ret;
2296 qdf_device_t qdf_dev;
2297 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302298 bool unint = false;
2299 void *hif_ctx;
2300
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002301 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302302
2303 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2304 if (!qdf_dev) {
2305 hdd_err("QDF Device Context is Invalid return");
2306 return -EINVAL;
2307 }
2308
2309 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302310 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302311
2312 if (QDF_TIMER_STATE_RUNNING ==
2313 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2314
2315 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002316 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302317 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2318 }
2319
2320 switch (hdd_ctx->driver_status) {
2321 case DRIVER_MODULES_UNINITIALIZED:
2322 unint = true;
2323 /* Fall through dont add break here */
2324 case DRIVER_MODULES_CLOSED:
2325 if (!reinit && !unint) {
2326 ret = pld_power_on(qdf_dev->dev);
2327 if (ret) {
2328 hdd_err("Failed to Powerup the device: %d", ret);
2329 goto release_lock;
2330 }
2331 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002332
2333 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2334 hdd_ctx->config->enable_fw_log);
2335
Arun Khandavallifae92942016-08-01 13:31:08 +05302336 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2337 qdf_dev->bus_type,
2338 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2339 HIF_ENABLE_TYPE_PROBE);
2340 if (ret) {
2341 hdd_err("Failed to open hif: %d", ret);
2342 goto power_down;
2343 }
2344
2345 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302346 if (!hif_ctx) {
2347 hdd_err("hif context is null!!");
2348 goto power_down;
2349 }
2350
Arun Khandavallifae92942016-08-01 13:31:08 +05302351 status = ol_cds_init(qdf_dev, hif_ctx);
2352 if (status != QDF_STATUS_SUCCESS) {
2353 hdd_err("No Memory to Create BMI Context :%d", status);
2354 goto hif_close;
2355 }
2356
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002357 ret = hdd_update_config(hdd_ctx);
2358 if (ret) {
2359 hdd_err("Failed to update configuration :%d", ret);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002360 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002361 }
2362
gbian62edd7e2017-03-07 13:12:13 +08002363 hdd_update_cds_ac_specs_params(hdd_ctx);
2364
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302365 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302366 if (!QDF_IS_STATUS_SUCCESS(status)) {
2367 hdd_err("Failed to Open CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002368 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302369 }
2370
Mukul Sharma9d797a02017-01-05 20:26:03 +05302371 /* initalize components configurations after psoc open */
2372 ret = hdd_update_components_config(hdd_ctx);
2373 if (ret) {
2374 hdd_err("Failed to update components configs :%d",
2375 ret);
2376 goto close;
2377 }
2378
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002379 /*
2380 * NAN compoenet requires certian operations like, open adapter,
2381 * close adapter, etc. to be initiated by HDD, for those
2382 * register HDD callbacks with UMAC's NAN componenet.
2383 */
2384 hdd_nan_register_callbacks(hdd_ctx);
2385
Arun Khandavallifae92942016-08-01 13:31:08 +05302386 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2387
Jeff Johnson3a280122017-09-13 07:42:00 -07002388 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302389 if (!QDF_IS_STATUS_SUCCESS(status)) {
2390 hdd_err("Failed to pre-enable CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002391 goto close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302392 }
2393
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002394 hdd_register_policy_manager_callback(
2395 hdd_ctx->hdd_psoc);
2396
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302397 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302398 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302399
Arun Khandavallifae92942016-08-01 13:31:08 +05302400 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2401 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2402 hdd_ftm_mc_process_msg);
2403 break;
2404 }
2405 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002406 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302407 break;
2408 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302409
2410 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002411 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2412 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002413 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002414 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302415 }
2416
Arun Khandavallifae92942016-08-01 13:31:08 +05302417 /* Fall through dont add break here */
2418 case DRIVER_MODULES_OPENED:
2419 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002420 hdd_alert("adapter is Null");
2421 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302422 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302423 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2424 hdd_err("in ftm mode, no need to configure cds modules");
2425 break;
2426 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302427 if (hdd_configure_cds(hdd_ctx, adapter)) {
2428 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002429 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302430 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302431 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302432 hdd_info("Driver Modules Successfully Enabled");
2433 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2434 break;
2435 case DRIVER_MODULES_ENABLED:
2436 hdd_info("Driver modules already Enabled");
2437 break;
2438 default:
2439 hdd_err("WLAN start invoked in wrong state! :%d\n",
2440 hdd_ctx->driver_status);
2441 goto release_lock;
2442 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302443 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302444 mutex_unlock(&hdd_ctx->iface_change_lock);
2445 EXIT();
2446 return 0;
2447
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002448post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002449 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002450
Arun Khandavallifae92942016-08-01 13:31:08 +05302451close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002452 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002453 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302454
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002455ol_cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302456 ol_cds_free();
2457
2458hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002459 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2460 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302461power_down:
2462 if (!reinit && !unint)
2463 pld_power_off(qdf_dev->dev);
2464release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302465 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302466 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302467 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002468
Arun Khandavallifae92942016-08-01 13:31:08 +05302469 return -EINVAL;
2470}
2471
Naveen Rawat910726a2017-03-06 11:42:51 -08002472#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002473static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002474{
2475 int ret = os_if_wifi_pos_register_nl();
2476
2477 if (ret)
2478 hdd_err("os_if_wifi_pos_register_nl failed");
2479
2480 return ret;
2481}
2482
2483static int hdd_deactivate_wifi_pos(void)
2484{
2485 int ret = os_if_wifi_pos_deregister_nl();
2486
2487 if (ret)
2488 hdd_err("os_if_wifi_pos_deregister_nl failed");
2489
2490 return ret;
2491}
2492
2493/**
2494 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2495 * @hdd_ctx: hdd context
2496 *
2497 * Return: status of operation
2498 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002499static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002500{
2501 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2502 struct hdd_config *cfg = hdd_ctx->config;
2503
2504 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2505 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2506 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2507 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2508 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2509 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2510 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2511 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2512}
2513#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002514static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002515{
2516 return oem_activate_service(hdd_ctx);
2517}
2518
2519static int hdd_deactivate_wifi_pos(void)
2520{
2521 return 0;
2522}
2523
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002524static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002525{
2526}
2527#endif
2528
Arun Khandavallifae92942016-08-01 13:31:08 +05302529/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002530 * __hdd_open() - HDD Open function
2531 * @dev: Pointer to net_device structure
2532 *
2533 * This is called in response to ifconfig up
2534 *
2535 * Return: 0 for success; non-zero for failure
2536 */
2537static int __hdd_open(struct net_device *dev)
2538{
Jeff Johnson9d295242017-08-29 14:39:48 -07002539 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002540 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002541 int ret;
2542
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002543 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302544 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302545 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002546
Arunk Khandavallie1b3a382017-09-26 12:01:26 +05302547 if (!hdd_wait_for_recovery_completion()) {
2548 hdd_err("Recovery failed");
2549 return -EIO;
2550 }
2551
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302552 /* Nothing to be done if device is unloading */
2553 if (cds_is_driver_unloading()) {
2554 hdd_err("Driver is unloading can not open the hdd");
2555 return -EBUSY;
2556 }
2557
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302558 mutex_lock(&hdd_init_deinit_lock);
2559
2560 /*
2561 * This scenario can be hit in cases where in the wlan driver after
2562 * registering the netdevices and there is a failure in driver
2563 * initialization. So return error gracefully because the netdevices
2564 * will be de-registered as part of the load failure.
2565 */
2566
2567 if (!cds_is_driver_loaded()) {
2568 hdd_err("Failed to start the wlan driver!!");
2569 ret = -EIO;
2570 goto err_hdd_hdd_init_deinit_lock;
2571 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302572
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002573
Arun Khandavallifae92942016-08-01 13:31:08 +05302574 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2575 if (ret) {
2576 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302577 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302578 }
2579
2580
2581 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2582 ret = hdd_start_adapter(adapter);
2583 if (ret) {
2584 hdd_err("Failed to start adapter :%d",
2585 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302586 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302587 }
2588 }
2589
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002590 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2591 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002592 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002593 /* Enable TX queues only when we are connected */
2594 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302595 WLAN_START_ALL_NETIF_QUEUE,
2596 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002597 }
2598
Naveen Rawat286def52016-09-23 15:38:02 -07002599 /* Enable carrier and transmit queues for NDI */
2600 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002601 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002602 wlan_hdd_netif_queue_control(adapter,
2603 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2604 WLAN_CONTROL_PATH);
2605 }
2606
Naveen Rawat910726a2017-03-06 11:42:51 -08002607 hdd_populate_wifi_pos_cfg(hdd_ctx);
2608
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302609err_hdd_hdd_init_deinit_lock:
2610 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002611 return ret;
2612}
2613
Arun Khandavallifae92942016-08-01 13:31:08 +05302614
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002615/**
2616 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2617 * @dev: Pointer to net_device structure
2618 *
2619 * This is called in response to ifconfig up
2620 *
2621 * Return: 0 for success; non-zero for failure
2622 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002623static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002624{
2625 int ret;
2626
2627 cds_ssr_protect(__func__);
2628 ret = __hdd_open(dev);
2629 cds_ssr_unprotect(__func__);
2630
2631 return ret;
2632}
2633
2634/**
2635 * __hdd_stop() - HDD stop function
2636 * @dev: Pointer to net_device structure
2637 *
2638 * This is called in response to ifconfig down
2639 *
2640 * Return: 0 for success; non-zero for failure
2641 */
2642static int __hdd_stop(struct net_device *dev)
2643{
Jeff Johnson9d295242017-08-29 14:39:48 -07002644 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002645 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002646 int ret;
2647
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002648 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002649
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302650 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002651 adapter->sessionId, adapter->device_mode));
2652
2653 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302654 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002655 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002656
2657 /* Nothing to be done if the interface is not opened */
2658 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002659 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002660 return -ENODEV;
2661 }
2662
2663 /* Make sure the interface is marked as closed */
2664 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302665
2666 hdd_debug("Disabling Auto Power save timer");
2667 sme_ps_disable_auto_ps_timer(
2668 WLAN_HDD_GET_HAL_CTX(adapter),
2669 adapter->sessionId);
2670
2671 /*
2672 * Disable TX on the interface, after this hard_start_xmit() will not
2673 * be called on that interface
2674 */
2675 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302676 wlan_hdd_netif_queue_control(adapter,
2677 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2678 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002679
2680 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002681 * NAN data interface is different in some sense. The traffic on NDI is
2682 * bursty in nature and depends on the need to transfer. The service
2683 * layer may down the interface after the usage and up again when
2684 * required. In some sense, the NDI is expected to be available
2685 * (like SAP) iface until NDI delete request is issued by the service
2686 * layer. Skip BSS termination and adapter deletion for NAN Data
2687 * interface (NDI).
2688 */
2689 if (WLAN_HDD_IS_NDI(adapter))
2690 return 0;
2691
2692 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002693 * The interface is marked as down for outside world (aka kernel)
2694 * But the driver is pretty much alive inside. The driver needs to
2695 * tear down the existing connection on the netdev (session)
2696 * cleanup the data pipes and wait until the control plane is stabilized
2697 * for this interface. The call also needs to wait until the above
2698 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002699 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002700 * That is intentional to be able to scan if it is a STA/P2P interface
2701 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302702 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002703
2704 /* DeInit the adapter. This ensures datapath cleanup as well */
2705 hdd_deinit_adapter(hdd_ctx, adapter, true);
2706
Arun Khandavallifae92942016-08-01 13:31:08 +05302707
2708 /*
2709 * Find if any iface is up. If any iface is up then can't put device to
2710 * sleep/power save mode
2711 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302712 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002713 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302714 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302715 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302716 hdd_prevent_suspend_timeout(
2717 hdd_ctx->config->iface_change_wait_time,
2718 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302719 }
2720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002721 EXIT();
2722 return 0;
2723}
2724
2725/**
2726 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2727 * @dev: pointer to net_device structure
2728 *
2729 * This is called in response to ifconfig down
2730 *
2731 * Return: 0 for success and error number for failure
2732 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002733static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002734{
2735 int ret;
2736
2737 cds_ssr_protect(__func__);
2738 ret = __hdd_stop(dev);
2739 cds_ssr_unprotect(__func__);
2740
2741 return ret;
2742}
2743
2744/**
2745 * __hdd_uninit() - HDD uninit function
2746 * @dev: Pointer to net_device structure
2747 *
2748 * This is called during the netdev unregister to uninitialize all data
2749 * associated with the device
2750 *
2751 * Return: None
2752 */
2753static void __hdd_uninit(struct net_device *dev)
2754{
Jeff Johnson9d295242017-08-29 14:39:48 -07002755 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002756 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002757
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002758 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002759
2760 do {
2761 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002762 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002763 break;
2764 }
2765
Jeff Johnson399c6272017-08-30 10:51:00 -07002766 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2767 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002768 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002769 break;
2770 }
2771
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002772 if (dev != adapter->dev)
2773 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002774
Jeff Johnson399c6272017-08-30 10:51:00 -07002775 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002776
2777 /* after uninit our adapter structure will no longer be valid */
2778 adapter->dev = NULL;
2779 adapter->magic = 0;
2780 } while (0);
2781
2782 EXIT();
2783}
2784
2785/**
2786 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2787 * @dev: pointer to net_device structure
2788 *
2789 * This is called during the netdev unregister to uninitialize all data
2790 * associated with the device
2791 *
2792 * Return: none
2793 */
2794static void hdd_uninit(struct net_device *dev)
2795{
2796 cds_ssr_protect(__func__);
2797 __hdd_uninit(dev);
2798 cds_ssr_unprotect(__func__);
2799}
2800
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002801static int hdd_open_cesium_nl_sock(void)
2802{
2803#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2804 struct netlink_kernel_cfg cfg = {
2805 .groups = WLAN_NLINK_MCAST_GRP_ID,
2806 .input = NULL
2807 };
2808#endif
2809 int ret = 0;
2810
2811#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2812 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2813#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2814 THIS_MODULE,
2815#endif
2816 &cfg);
2817#else
2818 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2819 WLAN_NLINK_MCAST_GRP_ID,
2820 NULL, NULL, THIS_MODULE);
2821#endif
2822
2823 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002824 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002825 ret = -ECONNREFUSED;
2826 }
2827
2828 return ret;
2829}
2830
2831static void hdd_close_cesium_nl_sock(void)
2832{
2833 if (NULL != cesium_nl_srv_sock) {
2834 netlink_kernel_release(cesium_nl_srv_sock);
2835 cesium_nl_srv_sock = NULL;
2836 }
2837}
2838
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002839/**
2840 * __hdd_set_mac_address() - set the user specified mac address
2841 * @dev: Pointer to the net device.
2842 * @addr: Pointer to the sockaddr.
2843 *
2844 * This function sets the user specified mac address using
2845 * the command ifconfig wlanX hw ether <mac adress>.
2846 *
2847 * Return: 0 for success, non zero for failure
2848 */
2849static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2850{
Jeff Johnson9d295242017-08-29 14:39:48 -07002851 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002852 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002853 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302854 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002855 int ret;
2856
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002857 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002858
2859 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2860 ret = wlan_hdd_validate_context(hdd_ctx);
2861 if (0 != ret)
2862 return ret;
2863
2864 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2865 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2866
2867 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302868 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869}
2870
2871/**
2872 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2873 * function from SSR
2874 * @dev: pointer to net_device structure
2875 * @addr: Pointer to the sockaddr
2876 *
2877 * This function sets the user specified mac address using
2878 * the command ifconfig wlanX hw ether <mac adress>.
2879 *
2880 * Return: 0 for success.
2881 */
2882static int hdd_set_mac_address(struct net_device *dev, void *addr)
2883{
2884 int ret;
2885
2886 cds_ssr_protect(__func__);
2887 ret = __hdd_set_mac_address(dev, addr);
2888 cds_ssr_unprotect(__func__);
2889
2890 return ret;
2891}
2892
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002893uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002894{
2895 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002896
Anurag Chouhan6d760662016-02-20 16:05:43 +05302897 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002898 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2899 break;
2900 }
2901
Anurag Chouhan6d760662016-02-20 16:05:43 +05302902 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903 return NULL;
2904
2905 hdd_ctx->config->intfAddrMask |= (1 << i);
2906 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2907}
2908
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07002909void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
2910 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911{
2912 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002913
Anurag Chouhan6d760662016-02-20 16:05:43 +05302914 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002915 if (!memcmp(releaseAddr,
2916 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2917 6)) {
2918 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2919 break;
2920 }
2921 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922}
2923
2924#ifdef WLAN_FEATURE_PACKET_FILTERING
2925/**
2926 * __hdd_set_multicast_list() - set the multicast address list
2927 * @dev: Pointer to the WLAN device.
2928 * @skb: Pointer to OS packet (sk_buff).
2929 *
2930 * This funciton sets the multicast address list.
2931 *
2932 * Return: None
2933 */
2934static void __hdd_set_multicast_list(struct net_device *dev)
2935{
Jeff Johnson9d295242017-08-29 14:39:48 -07002936 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002937 int i = 0, status;
2938 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002939 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302940 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2941 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2942 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002943
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002944 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302945 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302946 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302947
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002948 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302949 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302950 goto out;
2951
Dustin Brownc788acb2017-08-01 17:43:51 -07002952 status = hdd_validate_adapter(adapter);
2953 if (status)
2954 goto out;
2955
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302956 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2957 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002958 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302959 goto out;
2960 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002961
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302962 /* Delete already configured multicast address list */
2963 if (adapter->mc_addr_list.mc_cnt > 0) {
2964 hdd_info("clear previously configured MC address list");
2965 hdd_disable_and_flush_mc_addr_list(adapter,
2966 pmo_mc_list_change_notify);
2967 }
2968
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002969 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002970 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302971 hdd_disable_and_flush_mc_addr_list(adapter,
2972 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002973 } else {
2974 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302975 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002976 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302977 pmo_ucfg_max_mc_addr_supported(psoc));
2978 hdd_disable_and_flush_mc_addr_list(adapter,
2979 pmo_mc_list_change_notify);
2980 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002981 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002983 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302984 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002985 if (i == mc_count)
2986 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302987 memset(&(mc_list_request->mc_addr[i].bytes),
2988 0, ETH_ALEN);
2989 memcpy(&(mc_list_request->mc_addr[i].bytes),
2990 ha->addr, ETH_ALEN);
2991 hdd_info("mlist[%d] = %pM", i,
2992 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993 i++;
2994 }
2995 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302996
2997 mc_list_request->psoc = psoc;
2998 mc_list_request->vdev_id = adapter->sessionId;
2999 mc_list_request->count = mc_count;
3000 status = hdd_cache_mc_addr_list(mc_list_request);
3001 if (status == 0) {
3002 hdd_enable_mc_addr_filtering(adapter,
3003 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303005 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003006 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303007out:
3008 if (mc_list_request)
3009 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303010 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011}
3012
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303013
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003014/**
3015 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3016 * @dev: pointer to net_device
3017 *
3018 * Return: none
3019 */
3020static void hdd_set_multicast_list(struct net_device *dev)
3021{
3022 cds_ssr_protect(__func__);
3023 __hdd_set_multicast_list(dev);
3024 cds_ssr_unprotect(__func__);
3025}
3026#endif
3027
3028/**
3029 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3030 * @dev: Pointer to the WLAN device.
3031 * @skb: Pointer to OS packet (sk_buff).
3032 *
3033 * This function is registered with the Linux OS for network
3034 * core to decide which queue to use first.
3035 *
3036 * Return: ac, Queue Index/access category corresponding to UP in IP header
3037 */
3038static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3039#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3040 , void *accel_priv
3041#endif
3042#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3043 , select_queue_fallback_t fallback
3044#endif
3045)
3046{
3047 return hdd_wmm_select_queue(dev, skb);
3048}
3049
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003050static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003051 .ndo_open = hdd_open,
3052 .ndo_stop = hdd_stop,
3053 .ndo_uninit = hdd_uninit,
3054 .ndo_start_xmit = hdd_hard_start_xmit,
3055 .ndo_tx_timeout = hdd_tx_timeout,
3056 .ndo_get_stats = hdd_get_stats,
3057 .ndo_do_ioctl = hdd_ioctl,
3058 .ndo_set_mac_address = hdd_set_mac_address,
3059 .ndo_select_queue = hdd_select_queue,
3060#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003061 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003062#endif
3063};
3064
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003065/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003066static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003067 .ndo_open = hdd_mon_open,
3068 .ndo_stop = hdd_stop,
3069 .ndo_get_stats = hdd_get_stats,
3070};
3071
3072/**
3073 * hdd_set_station_ops() - update net_device ops for monitor mode
3074 * @pWlanDev: Handle to struct net_device to be updated.
3075 * Return: None
3076 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003077void hdd_set_station_ops(struct net_device *pWlanDev)
3078{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003079 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3080 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3081 else
3082 pWlanDev->netdev_ops = &wlan_drv_ops;
3083}
3084
3085/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003086 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3087 * @hdd_ctx: global hdd context
3088 * @macAddr: mac address to assign to the interface
3089 * @name: User-visible name of the interface
3090 *
3091 * hdd adapter pointer would point to the netdev->priv space, this function
3092 * would retrive the pointer, and setup the hdd adapter configuration.
3093 *
3094 * Return: the pointer to hdd adapter, otherwise NULL
3095 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003096static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003097 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003098 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003099 const char *name)
3100{
3101 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003102 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003103 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003104 /*
3105 * cfg80211 initialization and registration....
3106 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003107 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003108#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3109 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003111 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3112 hdd_mon_mode_ether_setup : ether_setup),
3113 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003114
3115 if (pWlanDev != NULL) {
3116
3117 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003118 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003119
Jeff Johnson9d295242017-08-29 14:39:48 -07003120 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303121 sta_ctx = &adapter->sessionCtx.station;
3122 qdf_mem_set(sta_ctx->conn_info.staId,
3123 sizeof(sta_ctx->conn_info.staId),
3124 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003125 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003126 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303128 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003129
3130 init_completion(&adapter->session_open_comp_var);
3131 init_completion(&adapter->session_close_comp_var);
3132 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303133 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003134 init_completion(&adapter->linkup_event_var);
3135 init_completion(&adapter->cancel_rem_on_chan_var);
3136 init_completion(&adapter->rem_on_chan_ready_event);
3137 init_completion(&adapter->sta_authorized_event);
3138 init_completion(&adapter->offchannel_tx_event);
3139 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003140 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141 init_completion(&adapter->change_country_code);
3142
3143
3144 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303145 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146
3147 adapter->offloads_configured = false;
3148 adapter->isLinkUpSvcNeeded = false;
3149 adapter->higherDtimTransition = true;
3150 /* Init the net_device structure */
3151 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3152
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303153 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303155 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003156 sizeof(tSirMacAddr));
3157 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158
3159 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3160 pWlanDev->features |=
3161 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3162 pWlanDev->features |= NETIF_F_RXCSUM;
3163
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003164 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3165
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166 hdd_set_station_ops(adapter->dev);
3167
Dustin Brownc81dd412017-08-15 16:26:28 -07003168 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003170 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171 adapter->wdev.wiphy = hdd_ctx->wiphy;
3172 adapter->wdev.netdev = pWlanDev;
3173 /* set pWlanDev's parent to underlying device */
3174 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3175 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303176 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303178 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 }
3180
3181 return adapter;
3182}
3183
Jeff Johnson9d295242017-08-29 14:39:48 -07003184static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003185{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003186 struct net_device *dev = adapter->dev;
3187 int ret;
3188
3189 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003191 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003192 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3193
3194 ret = dev_alloc_name(dev, dev->name);
3195 if (ret < 0) {
3196 hdd_err(
3197 "unable to get dev name: %s, err = 0x%x",
3198 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303199 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200 }
3201 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003202
3203 ret = register_netdevice(dev);
3204 if (ret) {
3205 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3206 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303207 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208 }
3209 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003210 ret = register_netdev(dev);
3211 if (ret) {
3212 hdd_err("register_netdev(%s) failed, err = 0x%x",
3213 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303214 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 }
3216 }
3217 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3218
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003219 EXIT();
3220
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303221 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003222}
3223
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003224QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003225{
Jeff Johnson9d295242017-08-29 14:39:48 -07003226 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003227
3228 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003229 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303230 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231 }
3232
3233 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003234 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303235 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003236 }
3237
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003238 /*
3239 * For NAN Data interface, the close session results in the final
3240 * indication to the userspace
3241 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003242 if (adapter->device_mode == QDF_NDI_MODE)
3243 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003244
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003245 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3246
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247 /*
3248 * We can be blocked while waiting for scheduled work to be
3249 * flushed, and the adapter structure can potentially be freed, in
3250 * which case the magic will have been reset. So make sure the
3251 * magic is still good, and hence the adapter structure is still
3252 * valid, before signaling completion
3253 */
3254 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3255 complete(&adapter->session_close_comp_var);
3256
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303257 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003258}
3259
Jeff Johnson9d295242017-08-29 14:39:48 -07003260int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261{
Dustin Brownd28772b2017-03-17 14:16:07 -07003262 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263
Dustin Brownd28772b2017-03-17 14:16:07 -07003264 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003265 if (QDF_IS_STATUS_ERROR(status))
3266 return qdf_status_to_os_return(status);
3267
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003268 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003269 if (QDF_IS_STATUS_ERROR(status))
3270 return qdf_status_to_os_return(status);
3271
3272 if (wma_capability_enhanced_mcast_filter())
3273 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3274 else
3275 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003276
3277 return qdf_status_to_os_return(status);
3278}
3279
Jeff Johnson9d295242017-08-29 14:39:48 -07003280int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003281{
3282 QDF_STATUS status;
3283 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003284 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003285 unsigned long rc;
3286
3287 hdd_info("destroying vdev %d", adapter->sessionId);
3288
3289 /* vdev created sanity check */
3290 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3291 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3292 return -EINVAL;
3293 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003294 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003295 /*
3296 * In SSR case, there is no need to destroy vdev in firmware since
3297 * it has already asserted. vdev can be released directly.
3298 */
3299 if (cds_is_driver_recovering())
3300 goto release_vdev;
3301
Dustin Brownd28772b2017-03-17 14:16:07 -07003302 /* close sme session (destroy vdev in firmware via legacy API) */
3303 INIT_COMPLETION(adapter->session_close_comp_var);
3304 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3305 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3306 hdd_sme_close_session_callback, adapter);
3307 if (QDF_IS_STATUS_ERROR(status)) {
3308 hdd_err("failed to close sme session: %d", status);
3309 return qdf_status_to_os_return(status);
3310 }
3311
3312 /* block on a completion variable until sme session is closed */
3313 rc = wait_for_completion_timeout(
3314 &adapter->session_close_comp_var,
3315 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3316 if (!rc) {
3317 hdd_err("timed out waiting for close sme session: %ld", rc);
3318 if (adapter->device_mode == QDF_NDI_MODE)
3319 hdd_ndp_session_end_handler(adapter);
3320 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3321 return -ETIMEDOUT;
3322 }
Yue Maf9782842017-05-08 12:49:49 -07003323release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003324 /* do vdev logical destroy via objmgr */
3325 errno = hdd_objmgr_destroy_vdev(adapter);
3326 if (errno) {
3327 hdd_err("failed to destroy objmgr vdev: %d", errno);
3328 return errno;
3329 }
3330
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003331 /* now that sme session is closed, allow physical vdev destroy */
3332 errno = hdd_objmgr_release_vdev(adapter);
3333 if (errno) {
3334 hdd_err("failed to release objmgr vdev: %d", errno);
3335 return errno;
3336 }
3337
Dustin Brownd28772b2017-03-17 14:16:07 -07003338 hdd_info("vdev destroyed successfully");
3339
3340 return 0;
3341}
3342
Jeff Johnson9d295242017-08-29 14:39:48 -07003343int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003344{
3345 QDF_STATUS status;
3346 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003347 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003348 uint32_t type;
3349 uint32_t sub_type;
3350 unsigned long rc;
3351
3352 hdd_info("creating new vdev");
3353
3354 /* determine vdev (sub)type */
3355 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303356 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003357 hdd_err("failed to get vdev type: %d", status);
3358 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003360
3361 /* do vdev create via objmgr */
3362 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003363 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003364 if (errno) {
3365 hdd_err("failed to create objmgr vdev: %d", errno);
3366 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003367 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003368
3369 /* Open a SME session (prepare vdev in firmware via legacy API) */
3370 INIT_COMPLETION(adapter->session_open_comp_var);
3371 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3372 (uint8_t *)&adapter->macAddressCurrent,
3373 adapter->sessionId, type, sub_type);
3374 if (QDF_IS_STATUS_ERROR(status)) {
3375 hdd_err("failed to open sme session: %d", status);
3376 errno = qdf_status_to_os_return(status);
3377 goto objmgr_vdev_destroy;
3378 }
3379
3380 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003381 rc = wait_for_completion_timeout(
3382 &adapter->session_open_comp_var,
3383 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3384 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003385 hdd_err("timed out waiting for open sme session: %ld", rc);
3386 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303387 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3388 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003389 }
3390
3391 /* firmware ready for component communication, raise vdev_ready event */
3392 errno = hdd_vdev_ready(adapter);
3393 if (errno) {
3394 hdd_err("failed to dispatch vdev ready event: %d", errno);
3395 goto hdd_vdev_destroy;
3396 }
3397
3398 hdd_info("vdev %d created successfully", adapter->sessionId);
3399
3400 return 0;
3401
3402 /*
3403 * Due to legacy constraints, we need to destroy in the same order as
3404 * create. So, split error handling into 2 cases to accommodate.
3405 */
3406
3407objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003408 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003409
3410 return errno;
3411
3412hdd_vdev_destroy:
3413 QDF_BUG(!hdd_vdev_destroy(adapter));
3414
3415 return errno;
3416}
3417
Jeff Johnson9d295242017-08-29 14:39:48 -07003418QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003419{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003420 struct hdd_station_ctx *sta_ctx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003421 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003422 QDF_STATUS status;
3423 int ret_val;
3424
3425 ret_val = hdd_vdev_create(adapter);
3426 if (ret_val) {
3427 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303428 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429 }
3430
Dustin Brownd28772b2017-03-17 14:16:07 -07003431 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3432 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3433 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003434 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003435
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003437 status = hdd_register_wext(adapter->dev);
3438 if (QDF_IS_STATUS_ERROR(status)) {
3439 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440 goto error_register_wext;
3441 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003442 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443
Jeff Johnsond377dce2017-10-04 10:32:42 -07003444 qdf_mem_set(sta_ctx->conn_info.staId,
3445 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303446
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003447 /* set fast roaming capability in sme session */
3448 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3449 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003451 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 hdd_ctx->config->OperatingChannel;
3453
3454 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003455 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003456
3457 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303458 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003459 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 status, status);
3461 goto error_init_txrx;
3462 }
3463
3464 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3465
3466 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303467 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003468 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469 status, status);
3470 goto error_wmm_init;
3471 }
3472
3473 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3474
Naveen Rawat247a8682017-06-05 15:00:31 -07003475 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476 WMI_PDEV_PARAM_BURST_ENABLE,
3477 hdd_ctx->config->enableSifsBurst,
3478 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003479 if (ret_val)
3480 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003481
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003482 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303483 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003484
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485error_wmm_init:
3486 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3487 hdd_deinit_tx_rx(adapter);
3488error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003489 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003490error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003491 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493 return status;
3494}
3495
Jeff Johnson9d295242017-08-29 14:39:48 -07003496void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497{
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003498 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499
3500 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3501
3502 if (NULL != cfgState->buf) {
3503 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003504
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003505 rc = wait_for_completion_timeout(
3506 &adapter->tx_action_cnf_event,
3507 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3508 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003509 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303510 /*
3511 * Inform tx status as FAILURE to upper layer and free
3512 * cfgState->buf
3513 */
3514 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003515 }
3516 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003517}
3518
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303519/**
3520 * hdd_station_adapter_deinit() - De-initialize the station adapter
3521 * @hdd_ctx: global hdd context
3522 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003523 * @rtnl_held: Used to indicate whether or not the caller is holding
3524 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303525 *
3526 * This function De-initializes the STA/P2P/OCB adapter.
3527 *
3528 * Return: None.
3529 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003530static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003531 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003532 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303533{
3534 ENTER_DEV(adapter->dev);
3535
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303536 if (adapter->dev) {
3537 if (rtnl_held)
3538 adapter->dev->wireless_handlers = NULL;
3539 else {
3540 rtnl_lock();
3541 adapter->dev->wireless_handlers = NULL;
3542 rtnl_unlock();
3543 }
3544 }
3545
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303546 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3547 hdd_deinit_tx_rx(adapter);
3548 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3549 }
3550
3551 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3552 hdd_wmm_adapter_close(adapter);
3553 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3554 }
3555
3556 hdd_cleanup_actionframe(hdd_ctx, adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303557
3558 EXIT();
3559}
3560
3561/**
3562 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3563 * @hdd_ctx: global hdd context
3564 * @adapter: HDD adapter
3565 * @rtnl_held: the rtnl lock hold flag
3566 * This function De-initializes the AP/P2PGo adapter.
3567 *
3568 * Return: None.
3569 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003570static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003571 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003572 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303573{
3574 ENTER_DEV(adapter->dev);
3575
3576 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3577 hdd_wmm_adapter_close(adapter);
3578 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3579 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003580 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303581
3582 hdd_cleanup_actionframe(hdd_ctx, adapter);
3583
3584 hdd_unregister_hostapd(adapter, rtnl_held);
3585
3586 EXIT();
3587}
3588
Jeff Johnson9d295242017-08-29 14:39:48 -07003589void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590 bool rtnl_held)
3591{
3592 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303593
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003595 case QDF_STA_MODE:
3596 case QDF_P2P_CLIENT_MODE:
3597 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003598 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303599 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 break;
3601 }
3602
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003603 case QDF_SAP_MODE:
3604 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605 {
3606
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303607 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608 break;
3609 }
3610
3611 default:
3612 break;
3613 }
3614
3615 EXIT();
3616}
3617
Jeff Johnson9d295242017-08-29 14:39:48 -07003618static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003619 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620{
3621 struct net_device *pWlanDev = NULL;
3622
3623 if (adapter)
3624 pWlanDev = adapter->dev;
3625 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003626 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003627 return;
3628 }
3629
Rajeev Kumardca5f812016-02-04 17:28:06 -08003630 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303631
3632 if (adapter->scan_info.default_scan_ies) {
3633 qdf_mem_free(adapter->scan_info.default_scan_ies);
3634 adapter->scan_info.default_scan_ies = NULL;
3635 }
3636
Komal Seelama89be8d2016-09-29 11:09:26 +05303637 hdd_adapter_runtime_suspend_denit(adapter);
3638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003639 /*
3640 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3641 * the driver is almost closed and cannot handle either control
3642 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003643 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3644 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645 * is not right. Setting this flag helps hdd_stop() to recognize that
3646 * the interface is closed and restricts any operations on that
3647 */
3648 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3649
3650 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003651 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003653 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003654 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655 /*
3656 * Note that the adapter is no longer valid at this point
3657 * since the memory has been reclaimed
3658 */
3659 }
3660}
3661
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003662static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003663 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003664{
3665 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003666 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303667 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003668
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003669 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303670 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003671 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003672 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303673 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303675 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676 }
3677 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3678 adapterNode = pNext;
3679 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303680 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003681}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003682
Arun Khandavalli2358d522016-05-16 18:05:37 +05303683#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3684/**
3685 * hdd_set_fw_log_params() - Set log parameters to FW
3686 * @hdd_ctx: HDD Context
3687 * @adapter: HDD Adapter
3688 *
3689 * This function set the FW Debug log level based on the INI.
3690 *
3691 * Return: None
3692 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003693static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003694 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303695{
3696 uint8_t count = 0, numentries = 0,
3697 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3698 uint32_t value = 0;
3699 int ret;
3700
Arun Khandavallifae92942016-08-01 13:31:08 +05303701 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3702 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003703 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303704 return;
3705 }
3706
Arun Khandavallifae92942016-08-01 13:31:08 +05303707 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303708 hdd_ctx->fw_log_settings.dl_type =
3709 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003710 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303711 WMI_DBGLOG_TYPE,
3712 hdd_ctx->config->enableFwLogType,
3713 DBG_CMD);
3714 if (ret != 0)
3715 hdd_err("Failed to enable FW log type ret %d",
3716 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303717
3718 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303719 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003720 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303721 WMI_DBGLOG_LOG_LEVEL,
3722 hdd_ctx->config->enableFwLogLevel,
3723 DBG_CMD);
3724 if (ret != 0)
3725 hdd_err("Failed to enable FW log level ret %d",
3726 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303727
3728 hdd_string_to_u8_array(
3729 hdd_ctx->config->enableFwModuleLogLevel,
3730 moduleloglevel,
3731 &numentries,
3732 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3733
3734 while (count < numentries) {
3735 /*
3736 * FW module log level input string looks like
3737 * below:
3738 * gFwDebugModuleLoglevel=<FW Module ID>,
3739 * <Log Level>,...
3740 * For example:
3741 * gFwDebugModuleLoglevel=
3742 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3743 * Above input string means :
3744 * For FW module ID 1 enable log level 0
3745 * For FW module ID 2 enable log level 1
3746 * For FW module ID 3 enable log level 2
3747 * For FW module ID 4 enable log level 3
3748 * For FW module ID 5 enable log level 4
3749 * For FW module ID 6 enable log level 5
3750 * For FW module ID 7 enable log level 6
3751 */
3752
Nishank Aggarwale239d962017-03-03 12:26:02 +05303753 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3754 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3755 hdd_err("Module id %d and dbglog level %d input length is more than max",
3756 moduleloglevel[count],
3757 moduleloglevel[count + 1]);
3758 return;
3759 }
3760
3761 value = moduleloglevel[count] << 16;
3762 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003763 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303764 WMI_DBGLOG_MOD_LOG_LEVEL,
3765 value, DBG_CMD);
3766 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303767 hdd_err("Failed to enable FW module log level %d ret %d",
3768 value, ret);
3769
3770 count += 2;
3771 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303772
Arun Khandavalli2358d522016-05-16 18:05:37 +05303773}
3774#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003775static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003776 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303777{
3778}
3779
3780#endif
3781
3782/**
3783 * hdd_set_fw_params() - Set parameters to firmware
3784 * @adapter: HDD adapter
3785 *
3786 * This function Sets various parameters to fw once the
3787 * adapter is started.
3788 *
3789 * Return: 0 on success or errno on failure
3790 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003791int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303792{
3793 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003794 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303795
3796 ENTER_DEV(adapter->dev);
3797
3798 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3799 if (!hdd_ctx)
3800 return -EINVAL;
3801
Dustin Brown732ab9c2017-06-15 13:24:09 -07003802 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3803 hdd_debug("FTM Mode is active; nothing to do");
3804 return 0;
3805 }
3806
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303807 ret = sme_cli_set_command(adapter->sessionId,
3808 WMI_PDEV_PARAM_DTIM_SYNTH,
3809 hdd_ctx->config->enable_lprx, PDEV_CMD);
3810 if (ret) {
3811 hdd_err("Failed to set LPRx");
3812 goto error;
3813 }
3814
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303815 if (adapter->device_mode == QDF_STA_MODE) {
3816 sme_set_smps_cfg(adapter->sessionId,
3817 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3818 hdd_ctx->config->upper_brssi_thresh);
3819
3820 sme_set_smps_cfg(adapter->sessionId,
3821 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3822 hdd_ctx->config->lower_brssi_thresh);
3823
3824 sme_set_smps_cfg(adapter->sessionId,
3825 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3826 hdd_ctx->config->enable_dtim_1chrx);
3827 }
3828
Dustin Brown732ab9c2017-06-15 13:24:09 -07003829 if (hdd_ctx->config->enable2x2) {
3830 hdd_debug("configuring 2x2 mode fw params");
3831
Naveen Rawat247a8682017-06-05 15:00:31 -07003832 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003833 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3834 hdd_ctx->config->enable_cck_tx_fir_override,
3835 PDEV_CMD);
3836 if (ret) {
3837 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3838 ret);
3839 goto error;
3840 }
3841 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303842#define HDD_DTIM_1CHAIN_RX_ID 0x5
3843#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003844 hdd_debug("configuring 1x1 mode fw params");
3845
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003846 /*
3847 * Disable DTIM 1 chain Rx when in 1x1,
3848 * we are passing two value
3849 * as param_id << 29 | param_value.
3850 * Below param_value = 0(disable)
3851 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003852 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003853 WMI_STA_SMPS_PARAM_CMDID,
3854 HDD_DTIM_1CHAIN_RX_ID <<
3855 HDD_SMPS_PARAM_VALUE_S,
3856 VDEV_CMD);
3857 if (ret) {
3858 hdd_err("DTIM 1 chain set failed %d", ret);
3859 goto error;
3860 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303861
Naveen Rawat247a8682017-06-05 15:00:31 -07003862 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003863 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3864 hdd_ctx->config->txchainmask1x1,
3865 PDEV_CMD);
3866 if (ret) {
3867 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3868 ret);
3869 goto error;
3870 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303871
Naveen Rawat247a8682017-06-05 15:00:31 -07003872 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003873 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3874 hdd_ctx->config->rxchainmask1x1,
3875 PDEV_CMD);
3876 if (ret) {
3877 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3878 ret);
3879 goto error;
3880 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303881#undef HDD_DTIM_1CHAIN_RX_ID
3882#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003883 }
3884
Naveen Rawat247a8682017-06-05 15:00:31 -07003885 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003886 WMI_PDEV_PARAM_HYST_EN,
3887 hdd_ctx->config->enableMemDeepSleep,
3888 PDEV_CMD);
3889 if (ret) {
3890 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3891 goto error;
3892 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303893
Naveen Rawat247a8682017-06-05 15:00:31 -07003894 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003895 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3896 hdd_ctx->config->rts_profile,
3897 VDEV_CMD);
3898 if (ret) {
3899 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3900 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303901 }
3902
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003903 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3904
3905 ret = wma_cli_set_command(adapter->sessionId,
3906 GEN_VDEV_PARAM_AMSDU,
3907 hdd_ctx->config->max_amsdu_num,
3908 GEN_CMD);
3909 if (ret != 0) {
3910 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3911 goto error;
3912 }
3913
Arun Khandavalli2358d522016-05-16 18:05:37 +05303914 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303915 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003916
Arun Khandavalli2358d522016-05-16 18:05:37 +05303917 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303918
Arun Khandavalli2358d522016-05-16 18:05:37 +05303919error:
3920 return -EINVAL;
3921}
3922
Ryan Hsu07495ea2016-01-21 15:25:39 -08003923/**
3924 * hdd_open_adapter() - open and setup the hdd adatper
3925 * @hdd_ctx: global hdd context
3926 * @session_type: type of the interface to be created
3927 * @iface_name: User-visible name of the interface
3928 * @macAddr: MAC address to assign to the interface
3929 * @name_assign_type: the name of assign type of the netdev
3930 * @rtnl_held: the rtnl lock hold flag
3931 *
3932 * This function open and setup the hdd adpater according to the device
3933 * type request, assign the name, the mac address assigned, and then prepared
3934 * the hdd related parameters, queue, lock and ready to start.
3935 *
3936 * Return: the pointer of hdd adapter, otherwise NULL.
3937 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003938struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003940 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003941 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942{
Jeff Johnson9d295242017-08-29 14:39:48 -07003943 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003944 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303945 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003946 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948
3949 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3950 /*
3951 * Max limit reached on the number of vdevs configured by the
3952 * host. Return error
3953 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303954 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3955 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 return NULL;
3957 }
3958
3959 if (macAddr == NULL) {
3960 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303961 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 return NULL;
3963 }
3964 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303965 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303966 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3967 " already exists",
3968 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003969 return NULL;
3970 }
3971
3972 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003973 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974 /* Reset locally administered bit if the device mode is STA */
3975 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303976 hdd_info("locally administered bit reset in sta mode: "
3977 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003979 case QDF_P2P_CLIENT_MODE:
3980 case QDF_P2P_DEVICE_MODE:
3981 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003982 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303983 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003984 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3985 name_assign_type,
3986 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987
3988 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303989 hdd_err("failed to allocate adapter for session %d",
3990 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 return NULL;
3992 }
3993
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003994 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003995 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003996 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003997 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303998 else if (QDF_MONITOR_MODE == session_type)
3999 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 else
4001 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4002
4003 adapter->device_mode = session_type;
4004
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 /*
4007 * Workqueue which gets scheduled in IPv4 notification
4008 * callback
4009 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4011 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012
4013#ifdef WLAN_NS_OFFLOAD
4014 /*
4015 * Workqueue which gets scheduled in IPv6
4016 * notification callback.
4017 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4019 hdd_ipv6_notifier_work_queue);
4020#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304022 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304024 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 }
4026
4027 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004028 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304030 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4031 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304032
Ravi Joshi1a292562017-05-18 16:28:54 -07004033 /* Initialize NAN Data Interface */
4034 if (QDF_NDI_MODE == session_type) {
4035 status = hdd_init_nan_data_mode(adapter);
4036 if (QDF_STATUS_SUCCESS != status)
4037 goto err_free_netdev;
4038 }
4039
4040 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004042 case QDF_P2P_GO_MODE:
4043 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004044 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4045 name_assign_type,
4046 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004047 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004048 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304049 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 return NULL;
4051 }
4052
4053 adapter->wdev.iftype =
4054 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004055 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056 NL80211_IFTYPE_P2P_GO;
4057 adapter->device_mode = session_type;
4058
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004059 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304060 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4062 goto err_free_netdev;
4063 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004064 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304066 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4067 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304069 case QDF_FTM_MODE:
4070 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4071 name_assign_type,
4072 "wlan0");
4073 if (NULL == adapter) {
4074 hdd_err("Failed to allocate adapter for FTM mode");
4075 return NULL;
4076 }
4077 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4078 adapter->device_mode = session_type;
4079 status = hdd_register_interface(adapter, rtnl_held);
4080 if (QDF_STATUS_SUCCESS != status) {
4081 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4082 goto err_free_netdev;
4083 }
4084 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004085 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304086 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304087 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4088 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304089 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004091 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304092 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004093 return NULL;
4094 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095
hqueaa33ee2017-05-04 17:56:35 +08004096 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4097
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4099 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4100
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304101 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004102 /* Add it to the hdd's session list. */
4103 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304104 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304106 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004107 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004108 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4110 }
4111 }
4112
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304113 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 if (NULL != adapter) {
4115 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4116 adapter = NULL;
4117 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004118 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304119 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004120
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004121 return NULL;
4122 }
4123
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304124 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004125 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4126 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004127
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004128 /* Adapter successfully added. Increment the vdev count */
4129 hdd_ctx->current_intf_count++;
4130
Jeff Johnson5880d792016-08-15 13:32:30 -07004131 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132 hdd_ctx->current_intf_count);
4133
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004134 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004135 }
4136
Rajeev Kumardca5f812016-02-04 17:28:06 -08004137 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004138 hdd_err("Interface %s wow debug_fs init failed",
4139 netdev_name(adapter->dev));
4140
4141 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4142 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004143
4144 return adapter;
4145
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004147 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304148 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004149
4150 return NULL;
4151}
4152
Jeff Johnson9d295242017-08-29 14:39:48 -07004153QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004154 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155{
4156 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304157 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004158
4159 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304160 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004161 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004162 status);
4163 return status;
4164 }
4165
Jeff Johnson57eb2732017-10-02 11:40:20 -07004166 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004167 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304168 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004169 break;
4170
4171 pCurrent = pNext;
4172 }
4173 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304174 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004175 /*
4176 * Here we are stopping global bus_bw timer & work per adapter.
4177 *
4178 * The reason is to fix one race condition between
4179 * bus bandwidth work and cleaning up an adapter.
4180 * Under some conditions, it is possible for the bus bandwidth
4181 * work to access a particularly destroyed adapter, leading to
4182 * use-after-free.
4183 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004184 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004185 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004186 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004187
4188 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004189 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4190 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004191 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304193 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004194 adapterNode = NULL;
4195
Dustin Brown5ec6b552017-03-31 12:11:40 -07004196 /* conditionally restart the bw timer */
4197 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4198
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004199 /* Adapter removed. Decrement vdev count */
4200 if (hdd_ctx->current_intf_count != 0)
4201 hdd_ctx->current_intf_count--;
4202
4203 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304204 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304206
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304207 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004208}
4209
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004210/**
4211 * hdd_close_all_adapters - Close all open adapters
4212 * @hdd_ctx: Hdd context
4213 * rtnl_held: True if RTNL lock held
4214 *
4215 * Close all open adapters.
4216 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304217 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004218 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004219QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220{
4221 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304222 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004223
4224 ENTER();
4225
4226 do {
4227 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304228 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304229 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004230 pHddAdapterNode->adapter->macAddressCurrent.bytes);
4231 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004232 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304233 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304234 /* Adapter removed. Decrement vdev count */
4235 if (hdd_ctx->current_intf_count != 0)
4236 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004237 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304238 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239
4240 EXIT();
4241
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304242 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004243}
4244
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004245void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004246{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304247 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004249
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004250 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004251 case QDF_STA_MODE:
4252 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004254 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004255 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004256 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004257 break;
4258 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004259 case QDF_SAP_MODE:
4260 case QDF_P2P_GO_MODE:
4261 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262 {
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004263 bssid = &adapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264 break;
4265 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004266 case QDF_FTM_MODE:
4267 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268 default:
4269 /*
4270 * wlan_hdd_reset_prob_rspies should not have been called
4271 * for these kind of devices
4272 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004273 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004274 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275 return;
4276 }
4277
Anurag Chouhanc5548422016-02-24 18:33:27 +05304278 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004279 updateIE.smeSessionId = adapter->sessionId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280 updateIE.ieBufferlength = 0;
4281 updateIE.pAdditionIEBuffer = NULL;
4282 updateIE.append = true;
4283 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004284 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304286 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004287 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288 }
4289}
4290
Jeff Johnson9d295242017-08-29 14:39:48 -07004291QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004292 const bool bCloseSession)
4293{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304294 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004295 struct hdd_wext_state *pWextState =
4296 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297 union iwreq_data wrqu;
4298 tSirUpdateIE updateIE;
4299 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004300 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301
4302 ENTER();
4303
Sachin Ahuja988fd102016-09-15 17:16:25 +05304304 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004305 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304306 wlan_hdd_netif_queue_control(adapter,
4307 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4308 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004309 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004310 case QDF_STA_MODE:
4311 case QDF_P2P_CLIENT_MODE:
4312 case QDF_IBSS_MODE:
4313 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004314 case QDF_NDI_MODE:
4315 if ((QDF_NDI_MODE == adapter->device_mode) ||
4316 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004317 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4318 hdd_is_connecting(
4319 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004320 INIT_COMPLETION(adapter->disconnect_comp_var);
4321 /*
4322 * For NDI do not use pWextState from sta_ctx, if needed
4323 * extract from ndi_ctx.
4324 */
4325 if (QDF_NDI_MODE == adapter->device_mode)
4326 qdf_ret_status = sme_roam_disconnect(
4327 hdd_ctx->hHal,
4328 adapter->sessionId,
4329 eCSR_DISCONNECT_REASON_NDI_DELETE);
4330 else if (pWextState->roamProfile.BSSType ==
4331 eCSR_BSS_TYPE_START_IBSS)
4332 qdf_ret_status = sme_roam_disconnect(
4333 hdd_ctx->hHal,
4334 adapter->sessionId,
4335 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004336 else if (QDF_STA_MODE == adapter->device_mode)
4337 qdf_ret_status =
4338 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004340 qdf_ret_status = sme_roam_disconnect(
4341 hdd_ctx->hHal,
4342 adapter->sessionId,
4343 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004344 /* success implies disconnect command got
4345 * queued up successfully
4346 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004347 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4348 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349 rc = wait_for_completion_timeout(
4350 &adapter->disconnect_comp_var,
4351 msecs_to_jiffies
4352 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004353 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004354 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004355 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004356 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4357 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358 memset(&wrqu, '\0', sizeof(wrqu));
4359 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4360 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4361 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4362 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304363 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004364 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304365 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004366
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304367 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304368 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369
4370#ifdef WLAN_OPEN_SOURCE
4371 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4372#endif
4373
4374 hdd_deregister_tx_flow_control(adapter);
4375
4376#ifdef WLAN_NS_OFFLOAD
4377#ifdef WLAN_OPEN_SOURCE
4378 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4379#endif
4380#endif
4381
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304382 if (adapter->device_mode == QDF_STA_MODE)
4383 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4384 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 /*
4386 * It is possible that the caller of this function does not
4387 * wish to close the session
4388 */
Krunal Soni985b8132017-02-10 18:49:08 -08004389 if (true == bCloseSession) {
4390 if (0 != wlan_hdd_try_disconnect(adapter)) {
4391 hdd_err("Error: Can't disconnect adapter");
4392 return QDF_STATUS_E_FAILURE;
4393 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004394 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004395 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 break;
4397
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004398 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304399 /* Flush IPA exception path packets */
4400 hdd_ipa_flush(hdd_ctx);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004401 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004402 if (QDF_SAP_MODE == adapter->device_mode) {
4403 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4404 cds_flush_delayed_work(
4405 &adapter->acs_pending_work);
4406 clear_bit(ACS_PENDING, &adapter->event_flags);
4407 }
4408 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004409 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004410 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004411 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4412
4413 hdd_deregister_tx_flow_control(adapter);
4414
Kapil Guptac1224bf2017-06-22 21:22:40 +05304415 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 mutex_lock(&hdd_ctx->sap_lock);
4417 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304418 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304419 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420
4421 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 status = wlansap_stop_bss(
4423 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304425 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004426 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304428 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304429 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304430 qdf_status =
4431 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004432 qdf_stop_bss_event,
4433 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434
Anurag Chouhance0dc992016-02-16 18:18:03 +05304435 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004436 hdd_err("failure waiting for wlansap_stop_bss %d",
4437 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438 }
4439 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004440 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441 }
4442 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004443 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4444 adapter->device_mode,
4445 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446
Anurag Chouhanc5548422016-02-24 18:33:27 +05304447 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004448 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004449 updateIE.smeSessionId = adapter->sessionId;
4450 updateIE.ieBufferlength = 0;
4451 updateIE.pAdditionIEBuffer = NULL;
4452 updateIE.append = false;
4453 updateIE.notify = false;
4454 /* Probe bcn reset */
4455 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4456 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304457 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004458 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004459 }
4460 /* Assoc resp reset */
4461 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4462 &updateIE,
4463 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304464 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004465 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466 }
4467 /* Reset WNI_CFG_PROBE_RSP Flags */
4468 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004469 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004470 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4471 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304472 /*
4473 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4474 */
4475 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4476 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4477
Peng Xu66162de2016-02-11 17:01:20 -08004478 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004479 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004480 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004482 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004483 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004484 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004485 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486 break;
4487 default:
4488 break;
4489 }
4490
4491 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304492 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004493}
4494
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304495/**
4496 * hdd_deinit_all_adapters - deinit all adapters
4497 * @hdd_ctx: HDD context
4498 * @rtnl_held: True if RTNL lock held
4499 *
4500 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004501void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304502{
4503 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4504 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004505 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304506
4507 ENTER();
4508
4509 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4510
4511 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004512 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304513 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4514 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4515 adapter_node = next;
4516 }
4517
4518 EXIT();
4519}
4520
Dustin Brown27cd9942017-09-27 16:11:44 -07004521QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4522 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004523{
4524 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304525 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004526 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527
4528 ENTER();
4529
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304530 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4531
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004532 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4533
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304534 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004535 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004536 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4538 adapterNode = pNext;
4539 }
4540
4541 EXIT();
4542
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304543 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004544}
4545
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004546QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004547{
4548 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304549 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004550 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004551 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004552 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004553
4554 ENTER();
4555
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304556 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4557
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004558 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4559
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304560 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004561 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004562 hdd_notice("Disabling queues for adapter type: %d",
4563 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304564
4565 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004566 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304567 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004568 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304569
Arun Khandavallicc544b32017-01-30 19:52:16 +05304570 if (hdd_ctx->config->sap_internal_restart &&
4571 adapter->device_mode == QDF_SAP_MODE) {
4572 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304573 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304574 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004575 if (test_bit(SOFTAP_BSS_STARTED,
4576 &adapter->event_flags)) {
4577 hdd_sap_indicate_disconnect_for_sta(adapter);
4578 hdd_cleanup_actionframe(hdd_ctx, adapter);
4579 hdd_sap_destroy_events(adapter);
4580 }
4581 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4582 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304583 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304584 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004585 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004586 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004587
4588 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4589
4590 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004591 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4592 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004593 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4594 hdd_wmm_adapter_close(adapter);
4595 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4596 }
4597
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304598 if (adapter->device_mode == QDF_STA_MODE)
4599 hdd_clear_fils_connection_info(adapter);
4600
Wu Gao3545e642017-07-14 19:24:41 +08004601 if (adapter->device_mode == QDF_SAP_MODE) {
4602 /*
4603 * If adapter is SAP, set session ID to invalid
4604 * since SAP session will be cleanup during SSR.
4605 */
Wu Gao36717432016-11-21 15:09:48 +08004606 wlansap_set_invalid_session(
4607 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4608
Wu Gao3545e642017-07-14 19:24:41 +08004609 wlansap_cleanup_cac_timer(
4610 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4611 }
4612
Yue Mad5b4b9f2017-05-26 16:23:40 -07004613 /* Delete peers if any for STA and P2P client modes */
4614 if (adapter->device_mode == QDF_STA_MODE ||
4615 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004616 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004617 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004618 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004619
4620 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4621 peerMacAddr.bytes);
4622 }
4623
Yue Maf9782842017-05-08 12:49:49 -07004624 /* Destroy vdev which will be recreated during reinit. */
4625 hdd_vdev_destroy(adapter);
4626
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004627 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4628 adapterNode = pNext;
4629 }
4630
4631 EXIT();
4632
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304633 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004634}
4635
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004636bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304637{
4638 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4639 QDF_STATUS status;
4640 bool close_modules = true;
4641
Arun Khandavalliba479c42017-07-26 21:29:40 +05304642 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4643 hdd_info("FTM mode, don't close the module");
4644 return false;
4645 }
4646
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304647 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4648 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4649 if (test_bit(DEVICE_IFACE_OPENED,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004650 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004651 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304652 close_modules = false;
4653 break;
4654 }
4655 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4656 adapter_node = next;
4657 }
4658
4659 return close_modules;
4660}
4661
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304662bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304663{
4664 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4665 return true;
4666 else
4667 return false;
4668}
4669
Anurag Chouhanc4092922016-09-08 15:56:11 +05304670#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004671 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304672struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4673 struct ieee80211_channel *channel,
4674 const u8 *bssid, const u8 *ssid,
4675 size_t ssid_len)
4676{
4677 return cfg80211_get_bss(wiphy, channel, bssid,
4678 ssid, ssid_len,
4679 WLAN_CAPABILITY_ESS,
4680 WLAN_CAPABILITY_ESS);
4681}
4682#else
4683struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4684 struct ieee80211_channel *channel,
4685 const u8 *bssid, const u8 *ssid,
4686 size_t ssid_len)
4687{
4688 return cfg80211_get_bss(wiphy, channel, bssid,
4689 ssid, ssid_len,
4690 IEEE80211_BSS_TYPE_ESS,
4691 IEEE80211_PRIVACY_ANY);
4692}
4693#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304694
Abhishek Singha84d3952016-09-13 13:45:05 +05304695#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304696#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4697 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4698/**
4699 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4700 * @timeout_reason: reason for connect timeout
4701 *
4702 * This function is used to convert host timeout
4703 * reason enum to kernel specific enum.
4704 *
4705 * Return: nl timeout enum
4706 */
4707static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4708 tSirResultCodes timeout_reason)
4709{
4710 switch (timeout_reason) {
4711 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4712 return NL80211_TIMEOUT_SCAN;
4713 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4714 return NL80211_TIMEOUT_AUTH;
4715 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4716 return NL80211_TIMEOUT_ASSOC;
4717 default:
4718 return NL80211_TIMEOUT_UNSPECIFIED;
4719 }
4720}
4721
4722/**
4723 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4724 * @dev: network device
4725 * @bssid: bssid to which we want to associate
4726 * @timeout_reason: reason for connect timeout
4727 *
4728 * This API is used to send connection timeout reason to supplicant
4729 *
4730 * Return: void
4731 */
4732static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4733 const u8 *bssid,
4734 tSirResultCodes timeout_reason)
4735{
4736 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004737
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304738 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4739
4740 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4741 nl_timeout_reason);
4742}
4743
4744/**
4745 * __hdd_connect_bss() - API to send connection status to supplicant
4746 * @dev: network device
4747 * @bssid: bssid to which we want to associate
4748 * @req_ie: Request Information Element
4749 * @req_ie_len: len of the req IE
4750 * @resp_ie: Response IE
4751 * @resp_ie_len: len of ht response IE
4752 * @status: status
4753 * @gfp: Kernel Flag
4754 * @timeout_reason: reason for connect timeout
4755 *
4756 * Return: void
4757 */
4758static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4759 struct cfg80211_bss *bss, const u8 *req_ie,
4760 size_t req_ie_len, const u8 *resp_ie,
4761 size_t resp_ie_len, int status, gfp_t gfp,
4762 tSirResultCodes timeout_reason)
4763{
4764 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004765
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304766 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4767
4768 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4769 resp_ie, resp_ie_len, status, gfp,
4770 nl_timeout_reason);
4771}
4772#else
4773#if defined CFG80211_CONNECT_TIMEOUT
4774static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4775 const u8 *bssid,
4776 tSirResultCodes timeout_reason)
4777{
4778 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4779}
4780#endif
4781
4782static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4783 struct cfg80211_bss *bss, const u8 *req_ie,
4784 size_t req_ie_len, const u8 *resp_ie,
4785 size_t resp_ie_len, int status, gfp_t gfp,
4786 tSirResultCodes timeout_reason)
4787{
4788 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4789 resp_ie, resp_ie_len, status, gfp);
4790}
4791#endif
4792
Abhishek Singha84d3952016-09-13 13:45:05 +05304793/**
4794 * hdd_connect_bss() - API to send connection status to supplicant
4795 * @dev: network device
4796 * @bssid: bssid to which we want to associate
4797 * @req_ie: Request Information Element
4798 * @req_ie_len: len of the req IE
4799 * @resp_ie: Response IE
4800 * @resp_ie_len: len of ht response IE
4801 * @status: status
4802 * @gfp: Kernel Flag
4803 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304804 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304805 *
4806 * The API is a wrapper to send connection status to supplicant
4807 *
4808 * Return: Void
4809 */
4810#if defined CFG80211_CONNECT_TIMEOUT
4811static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4812 struct cfg80211_bss *bss, const u8 *req_ie,
4813 size_t req_ie_len, const u8 *resp_ie,
4814 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304815 bool connect_timeout,
4816 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304817{
4818 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304819 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304820 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304821 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4822 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304823}
4824#else
4825static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4826 struct cfg80211_bss *bss, const u8 *req_ie,
4827 size_t req_ie_len, const u8 *resp_ie,
4828 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304829 bool connect_timeout,
4830 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304831{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304832 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4833 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304834}
4835#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304836
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304837#ifdef WLAN_FEATURE_FILS_SK
4838#ifdef CFG80211_CONNECT_DONE
4839#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4840/**
4841 * hdd_populate_fils_params() - Populate FILS keys to connect response
4842 * @fils_params: connect response to supplicant
4843 * @fils_kek: FILS kek
4844 * @fils_kek_len: FILS kek length
4845 * @pmk: FILS PMK
4846 * @pmk_len: FILS PMK length
4847 * @pmkid: PMKID
4848 * @fils_seq_num: FILS Seq number
4849 *
4850 * Return: None
4851 */
4852static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4853 *fils_params, const uint8_t *fils_kek,
4854 size_t fils_kek_len, const uint8_t *pmk,
4855 size_t pmk_len, const uint8_t *pmkid,
4856 uint16_t fils_seq_num)
4857{
4858 /* Increament seq number to be used for next FILS */
4859 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4860 fils_params->update_erp_next_seq_num = true;
4861 fils_params->fils_kek = fils_kek;
4862 fils_params->fils_kek_len = fils_kek_len;
4863 fils_params->pmk = pmk;
4864 fils_params->pmk_len = pmk_len;
4865 fils_params->pmkid = pmkid;
4866}
4867#else
4868static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4869 *fils_params, const uint8_t
4870 *fils_kek, size_t fils_kek_len,
4871 const uint8_t *pmk, size_t pmk_len,
4872 const uint8_t *pmkid,
4873 uint16_t fils_seq_num)
4874{ }
4875#endif
4876
4877/**
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304878 * hdd_update_hlp_info() - Update HLP packet received in FILS assoc rsp
4879 * @dev: net device
4880 * @roam_fils_params: Fils join rsp params
4881 *
4882 * This API is used to send the received HLP packet in Assoc rsp(FILS AKM)
4883 * to the network layer.
4884 *
4885 * Return: None
4886 */
4887static void hdd_update_hlp_info(struct net_device *dev,
4888 struct fils_join_rsp_params *roam_fils_params)
4889{
4890 struct sk_buff *skb;
4891 uint16_t skb_len;
4892 struct llc_snap_hdr_t *llc_hdr;
4893 QDF_STATUS status;
4894 uint8_t *hlp_data = roam_fils_params->hlp_data;
4895 uint16_t hlp_data_len = roam_fils_params->hlp_data_len;
4896 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4897
4898 /* Calculate skb length */
4899 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4900 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4901 if (skb == NULL) {
4902 hdd_err("HLP packet nbuf alloc fails");
4903 return;
4904 }
4905
4906 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4907 QDF_MAC_ADDR_SIZE);
4908 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4909 QDF_MAC_ADDR_SIZE);
4910
4911 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4912 if (IS_SNAP(llc_hdr)) {
4913 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4914 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4915 }
4916
4917 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4918
4919 /*
4920 * This HLP packet is formed from HLP info encapsulated
4921 * in assoc response frame which is AEAD encrypted.
4922 * Hence, this checksum validation can be set unnecessary.
4923 * i.e. network layer need not worry about checksum.
4924 */
4925 skb->ip_summed = CHECKSUM_UNNECESSARY;
4926
4927 status = hdd_rx_packet_cbk(padapter, skb);
4928 if (QDF_IS_STATUS_ERROR(status)) {
4929 hdd_err("Sending HLP packet fails");
4930 return;
4931 }
4932 hdd_debug("send HLP packet to netif successfully");
4933}
4934
4935/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304936 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4937 * @dev: network device
4938 * @bssid: bssid to which we want to associate
4939 * @bss: cfg80211 bss info
4940 * @roam_info: information about connected bss
4941 * @req_ie: Request Information Element
4942 * @req_ie_len: len of the req IE
4943 * @resp_ie: Response IE
4944 * @resp_ie_len: len of ht response IE
4945 * @status: status
4946 * @gfp: allocation flags
4947 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4948 * @timeout_reason: reason for connect timeout
4949 * @roam_fils_params: FILS join response params
4950 *
4951 * This API is used as wrapper to send FILS key/sequence number
4952 * params etc. to supplicant in case of FILS connection
4953 *
4954 * Return: None
4955 */
4956static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4957 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4958 const u8 *req_ie, size_t req_ie_len,
4959 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004960 gfp_t gfp, bool connect_timeout,
4961 tSirResultCodes timeout_reason,
4962 struct fils_join_rsp_params *roam_fils_params)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304963{
4964 struct cfg80211_connect_resp_params fils_params;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004965
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304966 qdf_mem_zero(&fils_params, sizeof(fils_params));
4967
4968 if (!roam_fils_params) {
4969 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4970 } else {
4971 fils_params.status = status;
4972 fils_params.bssid = bssid;
4973 fils_params.timeout_reason = timeout_reason;
4974 fils_params.req_ie = req_ie;
4975 fils_params.req_ie_len = req_ie_len;
4976 fils_params.resp_ie = resp_ie;
4977 fils_params.resp_ie_len = resp_ie_len;
4978 fils_params.bss = bss;
4979 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4980 roam_fils_params->kek_len,
4981 roam_fils_params->fils_pmk,
4982 roam_fils_params->fils_pmk_len,
4983 roam_fils_params->fils_pmkid,
4984 roam_info->fils_seq_num);
4985 }
4986 hdd_debug("FILS indicate connect status %d seq no %d",
4987 fils_params.status,
4988 fils_params.fils_erp_next_seq_num);
4989
4990 cfg80211_connect_done(dev, &fils_params, gfp);
4991
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304992 if (roam_fils_params && roam_fils_params->hlp_data_len)
4993 hdd_update_hlp_info(dev, roam_fils_params);
4994
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304995 /* Clear all the FILS key info */
4996 if (roam_fils_params && roam_fils_params->fils_pmk)
4997 qdf_mem_free(roam_fils_params->fils_pmk);
4998 if (roam_fils_params)
4999 qdf_mem_free(roam_fils_params);
5000 roam_info->fils_join_rsp = NULL;
5001}
5002#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005003static inline void
5004hdd_connect_done(struct net_device *dev, const u8 *bssid,
5005 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
5006 const u8 *req_ie, size_t req_ie_len,
5007 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5008 gfp_t gfp, bool connect_timeout,
5009 tSirResultCodes timeout_reason,
5010 struct fils_join_rsp_params *roam_fils_params)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305011{ }
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305012
5013static inline void hdd_update_hlp_info(struct net_device *dev,
5014 struct fils_join_rsp_params *roam_fils_params)
5015
5016{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305017#endif
5018#endif
5019
5020#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
5021/**
5022 * hdd_fils_update_connect_results() - API to send fils connection status to
5023 * supplicant.
5024 * @dev: network device
5025 * @bssid: bssid to which we want to associate
5026 * @bss: cfg80211 bss info
5027 * @roam_info: information about connected bss
5028 * @req_ie: Request Information Element
5029 * @req_ie_len: len of the req IE
5030 * @resp_ie: Response IE
5031 * @resp_ie_len: len of ht response IE
5032 * @status: status
5033 * @gfp: allocation flags
5034 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5035 * @timeout_reason: reason for connect timeout
5036 *
5037 * The API is a wrapper to send connection status to supplicant
5038 *
5039 * Return: 0 if success else failure
5040 */
5041static int hdd_fils_update_connect_results(struct net_device *dev,
5042 const u8 *bssid,
5043 struct cfg80211_bss *bss,
5044 tCsrRoamInfo *roam_info, const u8 *req_ie,
5045 size_t req_ie_len, const u8 *resp_ie,
5046 size_t resp_ie_len, u16 status, gfp_t gfp,
5047 bool connect_timeout,
5048 tSirResultCodes timeout_reason)
5049{
5050 ENTER();
5051 if (!roam_info || !roam_info->is_fils_connection)
5052 return -EINVAL;
5053
5054 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5055 resp_ie, resp_ie_len, status, gfp, connect_timeout,
5056 timeout_reason, roam_info->fils_join_rsp);
5057 return 0;
5058}
5059#else
5060static inline int hdd_fils_update_connect_results(struct net_device *dev,
5061 const u8 *bssid,
5062 struct cfg80211_bss *bss,
5063 tCsrRoamInfo *roam_info, const u8 *req_ie,
5064 size_t req_ie_len, const u8 *resp_ie,
5065 size_t resp_ie_len, u16 status, gfp_t gfp,
5066 bool connect_timeout,
5067 tSirResultCodes timeout_reason)
5068{
5069 return -EINVAL;
5070}
5071#endif
5072
Anurag Chouhanc4092922016-09-08 15:56:11 +05305073/**
5074 * hdd_connect_result() - API to send connection status to supplicant
5075 * @dev: network device
5076 * @bssid: bssid to which we want to associate
5077 * @roam_info: information about connected bss
5078 * @req_ie: Request Information Element
5079 * @req_ie_len: len of the req IE
5080 * @resp_ie: Response IE
5081 * @resp_ie_len: len of ht response IE
5082 * @status: status
5083 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305084 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305085 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305086 *
5087 * The API is a wrapper to send connection status to supplicant
5088 * and allow runtime suspend
5089 *
5090 * Return: Void
5091 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305092void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5093 tCsrRoamInfo *roam_info, const u8 *req_ie,
5094 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305095 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305096 bool connect_timeout,
5097 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305098{
Jeff Johnson9d295242017-08-29 14:39:48 -07005099 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305100 struct cfg80211_bss *bss = NULL;
5101
5102 if (WLAN_STATUS_SUCCESS == status) {
5103 struct ieee80211_channel *chan;
5104 int freq;
5105 int chan_no = roam_info->pBssDesc->channelId;
5106
5107 if (chan_no <= 14)
5108 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005109 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305110 else
5111 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005112 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305113
5114 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5115 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5116 roam_info->u.pConnectedProfile->SSID.ssId,
5117 roam_info->u.pConnectedProfile->SSID.length);
5118 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305119
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305120 if (hdd_fils_update_connect_results(dev, bssid, bss,
5121 roam_info, req_ie, req_ie_len, resp_ie,
5122 resp_ie_len, status, gfp, connect_timeout,
5123 timeout_reason) != 0) {
5124 hdd_connect_bss(dev, bssid, bss, req_ie,
5125 req_ie_len, resp_ie, resp_ie_len,
5126 status, gfp, connect_timeout, timeout_reason);
5127 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305128
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005129 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005130 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305131}
5132#else
5133void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5134 tCsrRoamInfo *roam_info, const u8 *req_ie,
5135 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305136 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305137 bool connect_timeout,
5138 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305139{
Jeff Johnson9d295242017-08-29 14:39:48 -07005140 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305141
Anurag Chouhanc4092922016-09-08 15:56:11 +05305142 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5143 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005144
5145 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005146 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305147}
5148#endif
5149
5150
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005151QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152{
5153 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305154 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005155 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005156#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305157 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005158#endif
5159 eConnectionState connState;
5160
5161 ENTER();
5162
5163 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305164 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005165 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005166
Arun Khandavallifae92942016-08-01 13:31:08 +05305167 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305168 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305169
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170 hdd_wmm_init(adapter);
5171
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005172 adapter->scan_info.mScanPending = false;
5173
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005174 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005175 case QDF_STA_MODE:
5176 case QDF_P2P_CLIENT_MODE:
5177 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005178
5179 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5180 ->conn_info.connState;
5181
5182 hdd_init_station_mode(adapter);
5183 /* Open the gates for HDD to receive Wext commands */
5184 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005185
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005186 /* Indicate disconnect event to supplicant
5187 * if associated previously
5188 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005190 eConnectionState_IbssConnected == connState ||
5191 eConnectionState_NotConnected == connState ||
5192 eConnectionState_IbssDisconnected == connState ||
5193 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005195
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196 memset(&wrqu, '\0', sizeof(wrqu));
5197 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5198 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5199 wireless_send_event(adapter->dev, SIOCGIWAP,
5200 &wrqu, NULL);
5201 adapter->sessionCtx.station.
5202 hdd_ReassocScenario = false;
5203
5204 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305205 wlan_hdd_cfg80211_indicate_disconnect(
5206 adapter->dev, false,
5207 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005208 } else if (eConnectionState_Connecting == connState) {
5209 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005210 * Indicate connect failure to supplicant if we
5211 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305213 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305214 NULL, 0, NULL, 0,
5215 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005216 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 }
5218
5219 hdd_register_tx_flow_control(adapter,
5220 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005221 hdd_tx_resume_cb,
5222 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223
5224 break;
5225
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005226 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005227 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305228 hdd_init_ap_mode(adapter, true);
5229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230 break;
5231
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005232 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005234 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005235 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5236#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005237 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005238 /* event supplicant to restart */
5239 cfg80211_del_sta(adapter->dev,
5240 (const u8 *)&bcastMac.bytes[0],
5241 GFP_KERNEL);
5242#endif
5243 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305244 case QDF_MONITOR_MODE:
5245 hdd_init_station_mode(adapter);
5246 hdd_set_mon_rx_cb(adapter->dev);
5247 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5248 adapter->mon_bandwidth);
5249 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005250 default:
5251 break;
5252 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005253 /*
5254 * Action frame registered in one adapter which will
5255 * applicable to all interfaces
5256 */
5257 wlan_hdd_cfg80211_register_frames(adapter);
5258
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305259get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005260 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5261 adapterNode = pNext;
5262 }
5263
5264 EXIT();
5265
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305266 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005267}
5268
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005269QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270 hdd_adapter_list_node_t **padapterNode)
5271{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305272 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005273
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005274 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305275 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5276 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005277 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005278 return status;
5279}
5280
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005281QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282 hdd_adapter_list_node_t *adapterNode,
5283 hdd_adapter_list_node_t **pNextAdapterNode)
5284{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305285 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005286
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005287 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305288 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5289 (qdf_list_node_t *) adapterNode,
5290 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005291
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005292 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005293 return status;
5294}
5295
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005296QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297 hdd_adapter_list_node_t *adapterNode)
5298{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305299 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005300
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005301 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305302 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005304 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305 return status;
5306}
5307
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005308QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005309 hdd_adapter_list_node_t **padapterNode)
5310{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305311 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005312
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005313 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305314 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5315 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005316 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005317 return status;
5318}
5319
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005320QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005321 hdd_adapter_list_node_t *adapterNode)
5322{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305323 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005324
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005325 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305326 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5327 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005328 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005329 return status;
5330}
5331
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005332QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005333 hdd_adapter_list_node_t *adapterNode)
5334{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305335 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005336
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005337 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305338 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5339 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005340 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005341 return status;
5342}
5343
Jeff Johnson9d295242017-08-29 14:39:48 -07005344struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005345 tSirMacAddr macAddr)
5346{
5347 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005348 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305349 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005350
5351 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5352
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305353 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005354 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355
5356 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305357 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005358 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005360
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005361 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5362 adapterNode = pNext;
5363 }
5364
5365 return NULL;
5366
5367}
5368
Jeff Johnson9d295242017-08-29 14:39:48 -07005369struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005370 uint32_t vdev_id)
5371{
5372 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005373 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305374 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005375
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305376 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005377
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305378 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005379 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005380
5381 if (adapter->sessionId == vdev_id)
5382 return adapter;
5383
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305384 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005385 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5386 adapterNode = pNext;
5387 }
5388
Jeff Johnson5880d792016-08-15 13:32:30 -07005389 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005390
5391 return NULL;
5392}
5393
Abhishek Singh7996eb72015-12-30 17:24:02 +05305394/**
5395 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5396 * the sessionid
5397 * @hdd_ctx: hdd context.
5398 * @sme_session_id: sme session is for the adapter to get.
5399 *
5400 * This function is used to get the adapter with provided session id
5401 *
5402 * Return: adapter pointer if found
5403 *
5404 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005405struct hdd_adapter *
5406hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5407 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305408{
5409 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005410 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305411 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305412
5413
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305414 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305415
5416 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305417 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005418 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305419
5420 if (adapter &&
5421 adapter->sessionId == sme_session_id)
5422 return adapter;
5423
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305424 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305425 hdd_get_next_adapter(hdd_ctx,
5426 adapter_node, &next);
5427 adapter_node = next;
5428 }
5429 return NULL;
5430}
5431
Jeff Johnson9d295242017-08-29 14:39:48 -07005432struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005433 const char *iface_name)
5434{
5435 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005436 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005437 QDF_STATUS qdf_status;
5438
5439 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5440
5441 while ((NULL != adapter_node) &&
5442 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005443 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005444
5445 if (adapter &&
5446 !qdf_str_cmp(adapter->dev->name, iface_name))
5447 return adapter;
5448
5449 qdf_status =
5450 hdd_get_next_adapter(hdd_ctx,
5451 adapter_node, &next);
5452 adapter_node = next;
5453 }
5454 return NULL;
5455}
5456
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005457/**
5458 * hdd_get_adapter() - to get adapter matching the mode
5459 * @hdd_ctx: hdd context
5460 * @mode: adapter mode
5461 *
5462 * This routine will return the pointer to adapter matching
5463 * with the passed mode.
5464 *
5465 * Return: pointer to adapter or null
5466 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005467struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005468 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005469{
5470 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005471 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305472 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005473
5474 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5475
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305476 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005477 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005478
5479 if (adapter && (mode == adapter->device_mode))
5480 return adapter;
5481
5482 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5483 adapterNode = pNext;
5484 }
5485
5486 return NULL;
5487
5488}
5489
5490/**
5491 * hdd_get_operating_channel() - return operating channel of the device mode
5492 * @hdd_ctx: Pointer to the HDD context.
5493 * @mode: Device mode for which operating channel is required.
5494 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005495 * QDF_STA_MODE,
5496 * QDF_P2P_CLIENT_MODE,
5497 * QDF_SAP_MODE,
5498 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005499 *
5500 * This API returns the operating channel of the requested device mode
5501 *
5502 * Return: channel number. "0" id the requested device is not found OR it is
5503 * not connected.
5504 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005505uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005506 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005507{
5508 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305509 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005510 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005511 uint8_t operatingChannel = 0;
5512
5513 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5514
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305515 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005516 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005517
5518 if (mode == adapter->device_mode) {
5519 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005520 case QDF_STA_MODE:
5521 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005522 if (hdd_conn_is_connected
5523 (WLAN_HDD_GET_STATION_CTX_PTR
5524 (adapter))) {
5525 operatingChannel =
5526 (WLAN_HDD_GET_STATION_CTX_PTR
5527 (adapter))->conn_info.
5528 operationChannel;
5529 }
5530 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005531 case QDF_SAP_MODE:
5532 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005533 /* softap connection info */
5534 if (test_bit
5535 (SOFTAP_BSS_STARTED,
5536 &adapter->event_flags))
5537 operatingChannel =
5538 (WLAN_HDD_GET_AP_CTX_PTR
5539 (adapter))->operatingChannel;
5540 break;
5541 default:
5542 break;
5543 }
5544
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005545 /* Found the device of interest. break the loop */
5546 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005547 }
5548
5549 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5550 adapterNode = pNext;
5551 }
5552 return operatingChannel;
5553}
5554
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005555static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005556 hdd_ctx)
5557{
5558 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305559 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005560 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005561
5562 ENTER();
5563
5564 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5565
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305566 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005567 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005568 if ((adapter->device_mode == QDF_STA_MODE) ||
5569 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5570 (adapter->device_mode == QDF_IBSS_MODE) ||
5571 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5572 (adapter->device_mode == QDF_SAP_MODE) ||
5573 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005574 wlan_hdd_cfg80211_deregister_frames(adapter);
5575 hdd_unregister_wext(adapter->dev);
5576 }
5577 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5578 adapterNode = pNext;
5579 }
5580
5581 EXIT();
5582
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305583 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005584}
5585
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005586QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587{
5588 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305589 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005590 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005591
5592 ENTER();
5593
5594 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5595
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305596 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005597 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005598 if ((adapter->device_mode == QDF_STA_MODE) ||
5599 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5600 (adapter->device_mode == QDF_IBSS_MODE) ||
5601 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5602 (adapter->device_mode == QDF_SAP_MODE) ||
5603 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005604 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5605 adapter->sessionId, INVALID_SCAN_ID,
5606 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005607 }
5608 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5609 adapterNode = pNext;
5610 }
5611
5612 EXIT();
5613
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305614 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005615}
5616
Dustin Brownf27bce82016-11-03 12:52:27 -07005617/**
5618 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5619 * adapters
5620 * @hdd_ctx: The HDD context containing the adapters to operate on
5621 *
5622 * return: QDF_STATUS_SUCCESS
5623 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005624static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005625{
5626 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5627 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005628 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005629 int err;
5630
5631 ENTER();
5632
5633 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5634
5635 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005636 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005637 if ((adapter->device_mode == QDF_STA_MODE) ||
5638 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5639 (adapter->device_mode == QDF_IBSS_MODE) ||
5640 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5641 (adapter->device_mode == QDF_SAP_MODE) ||
5642 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5643 err = wlan_hdd_sched_scan_stop(adapter->dev);
5644 if (err)
5645 hdd_err("Unable to stop scheduled scan");
5646 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005647 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5648 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005649 adapter_node = next_node;
5650 }
5651
5652 EXIT();
5653
5654 return QDF_STATUS_SUCCESS;
5655}
5656
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657#ifdef WLAN_NS_OFFLOAD
5658/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005659 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660 * @hdd_ctx: Pointer to hdd context
5661 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005662 * Unregister for IPv6 address change notifications.
5663 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005664 * Return: None
5665 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005666static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005667{
5668 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005669}
5670
5671/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005672 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673 * @hdd_ctx: Pointer to hdd context
5674 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005675 * Register for IPv6 address change notifications.
5676 *
5677 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005678 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005679static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005680{
5681 int ret;
5682
5683 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5684 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005685 if (ret) {
5686 hdd_err("Failed to register IPv6 notifier: %d", ret);
5687 goto out;
5688 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005690 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005691out:
5692 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005693}
5694#else
5695/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005696 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697 * @hdd_ctx: Pointer to hdd context
5698 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005699 * Unregister for IPv6 address change notifications.
5700 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005701 * Return: None
5702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005703static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005704{
5705}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005706
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005707/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005708 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005709 * @hdd_ctx: Pointer to hdd context
5710 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005711 * Register for IPv6 address change notifications.
5712 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005713 * Return: None
5714 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005715static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005716{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005717 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005718}
5719#endif
5720
5721/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005722 * hdd_register_notifiers - Register netdev notifiers.
5723 * @hdd_ctx: HDD context
5724 *
5725 * Register netdev notifiers like IPv4 and IPv6.
5726 *
5727 * Return: 0 on success and errno on failure
5728 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005729static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005730{
5731 int ret;
5732
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005733 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5734 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305735 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005736
5737 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5738 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5739 if (ret) {
5740 hdd_err("Failed to register IPv4 notifier: %d", ret);
5741 goto unregister_ip6_notifier;
5742 }
5743
5744 return 0;
5745
5746unregister_ip6_notifier:
5747 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005748out:
5749 return ret;
5750
5751}
5752
5753/**
5754 * hdd_unregister_notifiers - Unregister netdev notifiers.
5755 * @hdd_ctx: HDD context
5756 *
5757 * Unregister netdev notifiers like IPv4 and IPv6.
5758 *
5759 * Return: None.
5760 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005761void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005762{
5763 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5764
5765 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005766}
5767
5768/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005769 * hdd_exit_netlink_services - Exit netlink services
5770 * @hdd_ctx: HDD context
5771 *
5772 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5773 * nl service.
5774 *
5775 * Return: None.
5776 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005777static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005778{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005779 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005780 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005781 ptt_sock_deactivate_svc();
5782
5783 nl_srv_exit();
5784}
5785
5786/**
5787 * hdd_init_netlink_services- Init netlink services
5788 * @hdd_ctx: HDD context
5789 *
5790 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5791 * nl service.
5792 *
5793 * Return: 0 on success and errno on failure.
5794 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005795static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005796{
5797 int ret;
5798
Ryan Hsuceddceb2016-04-28 10:20:14 -07005799 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005800 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005801 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005802 goto out;
5803 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005804 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005805
Naveen Rawat910726a2017-03-06 11:42:51 -08005806 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005807 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005808 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005809 goto err_nl_srv;
5810 }
5811
5812 ret = ptt_sock_activate_svc();
5813 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005814 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005815 goto err_nl_srv;
5816 }
5817
5818 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005819 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005820 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005821
5822 ret = cnss_diag_activate_service();
5823 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005824 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005825 goto err_close_cesium;
5826 }
5827
5828 return 0;
5829
5830err_close_cesium:
5831 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005832 ptt_sock_deactivate_svc();
5833err_nl_srv:
5834 nl_srv_exit();
5835out:
5836 return ret;
5837}
5838
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005839/**
5840 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5841 * @hdd_ctx: HDD context.
5842 *
5843 * Destroy RX wakelock.
5844 *
5845 * Return: None.
5846 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005847static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005848{
5849 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5850}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005851
5852/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005853 * hdd_rx_wake_lock_create() - Create RX wakelock
5854 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005855 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005856 * Create RX wakelock.
5857 *
5858 * Return: None.
5859 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005860static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005861{
5862 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5863}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005864
5865/**
5866 * hdd_roc_context_init() - Init ROC context
5867 * @hdd_ctx: HDD context.
5868 *
5869 * Initialize ROC context.
5870 *
5871 * Return: 0 on success and errno on failure.
5872 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005873static int hdd_roc_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005874{
5875 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5876 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5877
5878 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5879
5880 return 0;
5881}
5882
5883/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305884 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5885 * @hdd_ctx: HDD context.
5886 *
5887 * Free memory allocations made in ROC Req Queue nodes.
5888 *
5889 * Return: None.
5890 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005891static void hdd_destroy_roc_req_q(struct hdd_context *hdd_ctx)
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305892{
Jeff Johnson52b50602017-09-30 17:54:56 -07005893 struct hdd_roc_req *hdd_roc_req;
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305894 QDF_STATUS status;
5895
5896 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5897
5898 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5899 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5900 (qdf_list_node_t **) &hdd_roc_req);
5901
5902 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305903 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5904 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305905 QDF_ASSERT(0);
5906 return;
5907 }
5908
Jeff Johnson44d8af92017-10-02 12:25:55 -07005909 if (hdd_roc_req->remain_chan_ctx)
5910 qdf_mem_free(hdd_roc_req->remain_chan_ctx);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305911
5912 qdf_mem_free(hdd_roc_req);
5913 }
5914
5915 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5916}
5917
5918/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005919 * hdd_roc_context_destroy() - Destroy ROC context
5920 * @hdd_ctx: HDD context.
5921 *
5922 * Destroy roc list and flush the pending roc work.
5923 *
5924 * Return: None.
5925 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005926static void hdd_roc_context_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005927{
5928 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305929 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005930 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005931}
5932
5933/**
Houston Hoffman160db392016-10-10 17:37:51 -07005934 * hdd_context_deinit() - Deinitialize HDD context
5935 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005936 *
Houston Hoffman160db392016-10-10 17:37:51 -07005937 * Deinitialize HDD context along with all the feature specific contexts but
5938 * do not free hdd context itself. Caller of this API is supposed to free
5939 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005940 *
Houston Hoffman160db392016-10-10 17:37:51 -07005941 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005942 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005943static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005944{
Houston Hoffman160db392016-10-10 17:37:51 -07005945 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005946
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005947 hdd_roc_context_destroy(hdd_ctx);
5948
5949 hdd_sap_context_destroy(hdd_ctx);
5950
5951 hdd_rx_wake_lock_destroy(hdd_ctx);
5952
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005953 hdd_scan_context_destroy(hdd_ctx);
5954
5955 qdf_list_destroy(&hdd_ctx->hddAdapters);
5956
Houston Hoffman160db392016-10-10 17:37:51 -07005957 return 0;
5958}
5959
5960/**
5961 * hdd_context_destroy() - Destroy HDD context
5962 * @hdd_ctx: HDD context to be destroyed.
5963 *
5964 * Free config and HDD context as well as destroy all the resources.
5965 *
5966 * Return: None
5967 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005968static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005969{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005970 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305971
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305972 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5973
Houston Hoffman160db392016-10-10 17:37:51 -07005974 hdd_context_deinit(hdd_ctx);
5975
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305976 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005977 hdd_ctx->config = NULL;
5978
5979 wiphy_free(hdd_ctx->wiphy);
5980}
5981
5982/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305983 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5984 *
5985 * This function is used to destroy bug report lock
5986 *
5987 * Return: None
5988 */
5989static void wlan_destroy_bug_report_lock(void)
5990{
5991 p_cds_contextType p_cds_context;
5992
5993 p_cds_context = cds_get_global_context();
5994 if (!p_cds_context) {
5995 hdd_err("cds context is NULL");
5996 return;
5997 }
5998
5999 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6000}
6001
6002/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006003 * hdd_wlan_exit() - HDD WLAN exit function
6004 * @hdd_ctx: Pointer to the HDD Context
6005 *
6006 * This is the driver exit point (invoked during rmmod)
6007 *
6008 * Return: None
6009 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006010static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006011{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306012 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006013 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306014 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015
6016 ENTER();
6017
Arun Khandavallifae92942016-08-01 13:31:08 +05306018 if (QDF_TIMER_STATE_RUNNING ==
6019 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006020 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05306021 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006022 }
6023
Arun Khandavallifae92942016-08-01 13:31:08 +05306024 if (!QDF_IS_STATUS_SUCCESS
6025 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
6026 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006027
Arun Khandavallifae92942016-08-01 13:31:08 +05306028
6029 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006030
Prashanth Bhattaab004382016-10-11 16:08:11 -07006031 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006032
6033#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306034 if (QDF_TIMER_STATE_RUNNING ==
6035 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6036 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006037 }
6038
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306039 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306040 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006041 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006042 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006043 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6044 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6045 hdd_ctx->last_acs_channel_list = NULL;
6046 hdd_ctx->num_of_channels = 0;
6047 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006048#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006049
Arun Khandavallifae92942016-08-01 13:31:08 +05306050 mutex_lock(&hdd_ctx->iface_change_lock);
6051 driver_status = hdd_ctx->driver_status;
6052 mutex_unlock(&hdd_ctx->iface_change_lock);
6053
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006054 /*
6055 * Powersave Offload Case
6056 * Disable Idle Power Save Mode
6057 */
6058 hdd_set_idle_ps_config(hdd_ctx, false);
6059
Arun Khandavallifae92942016-08-01 13:31:08 +05306060 if (driver_status != DRIVER_MODULES_CLOSED) {
6061 hdd_unregister_wext_all_adapters(hdd_ctx);
6062 /*
6063 * Cancel any outstanding scan requests. We are about to close
6064 * all of our adapters, but an adapter structure is what SME
6065 * passes back to our callback function. Hence if there
6066 * are any outstanding scan requests then there is a
6067 * race condition between when the adapter is closed and
6068 * when the callback is invoked. We try to resolve that
6069 * race condition here by canceling any outstanding scans
6070 * before we close the adapters.
6071 * Note that the scans may be cancelled in an asynchronous
6072 * manner, so ideally there needs to be some kind of
6073 * synchronization. Rather than introduce a new
6074 * synchronization here, we will utilize the fact that we are
6075 * about to Request Full Power, and since that is synchronized,
6076 * the expectation is that by the time Request Full Power has
6077 * completed, all scans will be cancelled
6078 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07006079 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05306080 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006081 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006082 hdd_stop_all_adapters(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006083 }
6084
6085 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306086 * Close the scheduler before calling cds_close to make sure
6087 * no thread is scheduled after the each module close is
6088 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006089 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006090 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306091 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306092 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306093 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006094 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006095
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306096 unregister_netdevice_notifier(&hdd_netdev_notifier);
6097
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006098 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306099
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306100 qdf_nbuf_deinit_replenish_timer();
6101
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306102 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6103 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6104 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6105
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006106 /*
6107 * Close CDS
6108 * This frees pMac(HAL) context. There should not be any call
6109 * that requires pMac access after this.
6110 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006111
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006112 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006113 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006114
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006115 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006116
6117 hdd_ipa_cleanup(hdd_ctx);
6118
6119 /* Free up RoC request queue and flush workqueue */
6120 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006121
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306122 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306123 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306124 /*
6125 * If there is re_init failure wiphy would have already de-registered
6126 * check the wiphy status before un-registering again
6127 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306128 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306129 wiphy_unregister(wiphy);
6130 wlan_hdd_cfg80211_deinit(wiphy);
6131 hdd_lpass_notify_stop(hdd_ctx);
6132 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006133
Arun Khandavallifae92942016-08-01 13:31:08 +05306134 hdd_exit_netlink_services(hdd_ctx);
6135 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306136#ifdef FEATURE_WLAN_CH_AVOID
6137 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6138#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306139
6140 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6141 if (driver_status)
6142 hdd_err("Pdev delete failed");
6143
6144 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6145 if (driver_status)
6146 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006147
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006148 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006149}
6150
6151void __hdd_wlan_exit(void)
6152{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006153 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006154
6155 ENTER();
6156
Anurag Chouhan6d760662016-02-20 16:05:43 +05306157 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006158 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006159 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006160 EXIT();
6161 return;
6162 }
6163
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006164 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306165 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006166
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006167 /* Do all the cleanup before deregistering the driver */
6168 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006169
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006170 EXIT();
6171}
6172
6173#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006174/**
6175 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006176 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006177 *
6178 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6179 * Then new ACS request will do a fresh scan without reusing the cached
6180 * scan information.
6181 *
6182 * Return: void
6183 */
Tang Yingying523322d2017-01-17 23:28:43 +08006184static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006186 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006187
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006188 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006189 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006190 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6191 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6192 hdd_ctx->last_acs_channel_list = NULL;
6193 hdd_ctx->num_of_channels = 0;
6194 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006195
6196 if (!hdd_ctx->hHal)
6197 return;
6198 sme_scan_flush_result(hdd_ctx->hHal);
6199}
6200#endif
6201
6202#ifdef QCA_HT_2040_COEX
6203/**
6204 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6205 * @adapter: pointer to adapter
6206 * @staId: station id
6207 * @macAddrSTA: station MAC address
6208 * @channel_type: channel type
6209 *
6210 * This function notifies FW with HT20/HT40 mode
6211 *
6212 * Return: 0 if successful, error number otherwise
6213 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006214int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306215 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006216{
6217 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306218 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006219 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220
6221 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6222
6223 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306224 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006225 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006227 if (!hdd_ctx->hHal)
6228 return -EINVAL;
6229
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306230 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006231 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306232 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006233 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234 return -EINVAL;
6235 }
6236
6237 return 0;
6238}
6239#endif
6240
6241/**
6242 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6243 * @state: state
6244 *
6245 * This function notifies FW with modem power status
6246 *
6247 * Return: 0 if successful, error number otherwise
6248 */
6249int hdd_wlan_notify_modem_power_state(int state)
6250{
6251 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306252 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006253 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254
Anurag Chouhan6d760662016-02-20 16:05:43 +05306255 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006256 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306257 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006258 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306259
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260 if (!hdd_ctx->hHal)
6261 return -EINVAL;
6262
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306263 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6264 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006265 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006266 state);
6267 return -EINVAL;
6268 }
6269 return 0;
6270}
6271
6272/**
6273 *
6274 * hdd_post_cds_enable_config() - HDD post cds start config helper
6275 * @adapter - Pointer to the HDD
6276 *
6277 * Return: None
6278 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006279QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006280{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306281 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006282
6283 /*
6284 * Send ready indication to the HDD. This will kick off the MAC
6285 * into a 'running' state and should kick off an initial scan.
6286 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306287 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6288 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006289 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6290 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306291 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006292 }
6293
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306294 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006295}
6296
6297/* wake lock APIs for HDD */
6298void hdd_prevent_suspend(uint32_t reason)
6299{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306300 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301}
6302
6303void hdd_allow_suspend(uint32_t reason)
6304{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306305 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006306}
6307
6308void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6309{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306310 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6311 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006312}
6313
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006314/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006315QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006316{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006317
Amar Singhal6f8592b2017-04-26 14:31:58 -07006318 return sme_init_chan_list(hdd_ctx->hHal,
6319 hdd_ctx->reg.alpha2,
6320 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006321}
6322
6323/**
6324 * hdd_is_5g_supported() - check if hardware supports 5GHz
6325 * @hdd_ctx: Pointer to the hdd context
6326 *
6327 * HDD function to know if hardware supports 5GHz
6328 *
6329 * Return: true if hardware supports 5GHz
6330 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006331bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006332{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006333 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006334 return true;
6335
Amar Singhal58b45ef2017-08-01 13:43:54 -07006336 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006337 return true;
6338 else
6339 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006340}
6341
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006342static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006343{
6344 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006345 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346
6347 wiphy = hdd_ctx->wiphy;
6348
6349 /*
6350 * The channel information in
6351 * wiphy needs to be initialized before wiphy registration
6352 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006353 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6354 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006355 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006356 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006357 }
6358
6359#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6360 wiphy->wowlan = &wowlan_support_reg_init;
6361#else
6362 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6363 WIPHY_WOWLAN_MAGIC_PKT |
6364 WIPHY_WOWLAN_DISCONNECT |
6365 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6366 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6367 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6368 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6369 WIPHY_WOWLAN_RFKILL_RELEASE;
6370
6371 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6372 WOW_MAX_FILTERS_PER_LIST);
6373 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6374 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6375#endif
6376
6377 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006378 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306379 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006380 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306381 return ret_val;
6382 }
6383
Amar Singhal5cccafe2017-02-15 12:42:58 -08006384 if (!hdd_ctx->reg_offload)
6385 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006386
Amar Singhale4f28ee2015-10-21 14:36:56 -07006387 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006388}
6389
Ravi Joshie2331e82015-07-01 18:18:54 -07006390/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006391 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006392 * @hdd_ctx - handle to hdd context
6393 * @tx_packets - transmit packet count
6394 * @rx_packets - receive packet count
6395 *
6396 * The function controls the bus bandwidth and dynamic control of
6397 * tcp delayed ack configuration
6398 *
6399 * Returns: None
6400 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006401#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006402static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006403 const uint64_t tx_packets,
6404 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006405{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006406 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006407 uint64_t temp_rx = 0;
6408 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006409 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006410 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006411 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006412 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006413 uint16_t index = 0;
6414 bool vote_level_change = false;
6415 bool rx_level_change = false;
6416 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006417
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006418 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006419 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006420 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006421 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006422 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006423 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006424 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006425 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006427 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006428 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6429 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006430 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006431 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006432 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306433 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306434 if (hdd_ctx->hbw_requested) {
6435 pld_remove_pm_qos(hdd_ctx->parent_dev);
6436 hdd_ctx->hbw_requested = false;
6437 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306438 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006439 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006440 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306441 if (!hdd_ctx->hbw_requested) {
6442 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6443 hdd_ctx->hbw_requested = true;
6444 }
6445
Nirav Shah3bbfa512016-05-12 16:43:49 +05306446 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006447 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006448 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006449 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006451
Mohit Khannaf8f96822017-05-17 17:11:59 -07006452 qdf_dp_trace_throttle_live_mode(
6453 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6454
Mohit Khannae71e2262015-11-10 09:37:24 -08006455 /* fine-tuning parameters for RX Flows */
6456 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6457
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006458 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006459
Ravi Joshifed83572016-10-07 16:20:37 -07006460 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6461 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6462 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6463 next_rx_level = WLAN_SVC_TP_HIGH;
6464 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006465 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006466 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006467 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006468 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006469
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006470 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006471 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006472 next_rx_level, temp_rx);
6473 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006474 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006475 /* Send throughput indication only if it is enabled.
6476 * Disabling tcp_del_ack will revert the tcp stack behavior
6477 * to default delayed ack. Note that this will disable the
6478 * dynamic delayed ack mechanism across the system
6479 */
6480 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306481 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6482 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006483 &next_rx_level,
6484 sizeof(next_rx_level));
6485 }
6486
Mohit Khannae71e2262015-11-10 09:37:24 -08006487 /* fine-tuning parameters for TX Flows */
6488 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6489 hdd_ctx->prev_tx = tx_packets;
6490 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6491 next_tx_level = WLAN_SVC_TP_HIGH;
6492 else
6493 next_tx_level = WLAN_SVC_TP_LOW;
6494
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006495 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006496 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6497 next_tx_level, temp_tx);
6498 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006499 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306500 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6501 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006502 &next_tx_level,
6503 sizeof(next_tx_level));
6504 }
6505
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006506 index = hdd_ctx->hdd_txrx_hist_idx;
6507
6508 if (vote_level_change || tx_level_change || rx_level_change) {
6509 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6510 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6511 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6512 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6513 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6514 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6515 hdd_ctx->hdd_txrx_hist_idx++;
6516 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6517 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006518}
6519
6520#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306521static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006523 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306524 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006525 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306526 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306527 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6528 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006529 uint64_t total_tx = 0, total_rx = 0;
6530 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306531 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306532 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006533 bool connected = false;
6534 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6535
Prashanth Bhattaab004382016-10-11 16:08:11 -07006536 if (wlan_hdd_validate_context(hdd_ctx))
6537 return;
6538
Jingxiang Gec64e1932017-08-22 14:38:59 +08006539 if (hdd_ctx->isWiphySuspended)
6540 goto restart_timer;
6541
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006542 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306543 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006544 status =
6545 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6546
Jeff Johnson57eb2732017-10-02 11:40:20 -07006547 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006548 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006549 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306550 /*
6551 * Validate magic so we don't end up accessing
6552 * an invalid adapter.
6553 */
6554 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6555 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006556
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006557 if ((adapter->device_mode == QDF_STA_MODE ||
6558 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006559 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6560 != eConnectionState_Associated) {
6561
6562 continue;
6563 }
6564
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006565 if ((adapter->device_mode == QDF_SAP_MODE ||
6566 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006567 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6568
6569 continue;
6570 }
6571
6572 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6573 adapter->prev_tx_packets);
6574 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6575 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306576
6577 if (adapter->device_mode == QDF_SAP_MODE ||
6578 adapter->device_mode == QDF_P2P_GO_MODE ||
6579 adapter->device_mode == QDF_IBSS_MODE) {
6580
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006581 ret = cdp_get_intra_bss_fwd_pkts_count(
6582 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306583 adapter->sessionId,
6584 &fwd_tx_packets, &fwd_rx_packets);
6585 if (ret == A_OK) {
6586 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6587 fwd_tx_packets,
6588 adapter->prev_fwd_tx_packets);
6589 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6590 fwd_tx_packets,
6591 adapter->prev_fwd_rx_packets);
6592 }
6593 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594
6595 total_rx += adapter->stats.rx_packets;
6596 total_tx += adapter->stats.tx_packets;
6597
6598 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6599 adapter->prev_tx_packets = adapter->stats.tx_packets;
6600 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306601 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6602 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006603 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6604 connected = true;
6605 }
6606
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306607 /* add intra bss forwarded tx and rx packets */
6608 tx_packets += fwd_tx_packets_diff;
6609 rx_packets += fwd_rx_packets_diff;
6610
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006611 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6612 tx_packets += (uint64_t)ipa_tx_packets;
6613 rx_packets += (uint64_t)ipa_rx_packets;
6614
6615 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006616 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006617 return;
6618 }
6619
Yuanyuan Liu13738502016-04-06 17:41:37 -07006620 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006621
6622 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6623 hdd_ipa_uc_stat_request(adapter, 2);
6624
Jingxiang Gec64e1932017-08-22 14:38:59 +08006625restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006626 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006627 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006628 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306629 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006630 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006631 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006633
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306634/**
6635 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6636 * @arg: Argument of timer function
6637 *
6638 * Schedule a workqueue in this function where all the processing is done.
6639 *
6640 * Return: None.
6641 */
6642static void __hdd_bus_bw_cbk(void *arg)
6643{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006644 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306645
6646 if (wlan_hdd_validate_context(hdd_ctx))
6647 return;
6648
6649 schedule_work(&hdd_ctx->bus_bw_work);
6650}
6651
6652/**
6653 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6654 * @arg: Argument of timer function
6655 *
6656 * Return: None.
6657 */
6658static void hdd_bus_bw_cbk(void *arg)
6659{
6660 cds_ssr_protect(__func__);
6661 __hdd_bus_bw_cbk(arg);
6662 cds_ssr_unprotect(__func__);
6663}
6664
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006665int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006666{
6667 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306668 INIT_WORK(&hdd_ctx->bus_bw_work,
6669 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006670 hdd_ctx->bus_bw_timer_running = false;
6671 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306672 qdf_timer_init(NULL,
6673 &hdd_ctx->bus_bw_timer,
6674 hdd_bus_bw_cbk, (void *)hdd_ctx,
6675 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006676
6677 return 0;
6678}
6679
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006680void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006681{
Dustin Brownfce08d12017-01-17 16:29:38 -08006682 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006683 hdd_reset_tcp_delack(hdd_ctx);
6684
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006685 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306686 cancel_work_sync(&hdd_ctx->bus_bw_work);
6687 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006688 hdd_ctx->bus_bw_timer_running = false;
6689 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006690}
Lin Baic5c06882017-09-21 13:58:43 +08006691
6692void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6693{
6694 if (hdd_ctx)
6695 cancel_work_sync(&hdd_ctx->bus_bw_work);
6696}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006697#endif
6698
6699/**
Nirav Shahed34b212016-04-25 10:59:16 +05306700 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6701 * @hdd_ctx: hdd context
6702 *
6703 * Return: 0 for success or error code
6704 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006705static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306706{
6707 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6708 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6709 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006710 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306711 return -ENOMEM;
6712 }
6713 return 0;
6714}
6715
6716/**
6717 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6718 * @hdd_ctx: hdd context
6719 *
6720 * Return: none
6721 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006722void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306723{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306724 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6725 return;
6726
6727 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6728 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306729}
6730
Nirav Shahda008342016-05-17 18:50:40 +05306731static uint8_t *convert_level_to_string(uint32_t level)
6732{
6733 switch (level) {
6734 /* initialize the wlan sub system */
6735 case WLAN_SVC_TP_NONE:
6736 return "NONE";
6737 case WLAN_SVC_TP_LOW:
6738 return "LOW";
6739 case WLAN_SVC_TP_MEDIUM:
6740 return "MED";
6741 case WLAN_SVC_TP_HIGH:
6742 return "HIGH";
6743 default:
6744 return "INVAL";
6745 }
6746}
6747
Nirav Shahed34b212016-04-25 10:59:16 +05306748
6749/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006750 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6751 * @hdd_ctx: hdd context
6752 *
6753 * Return: none
6754 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006755void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006756{
6757 int i;
6758
6759#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006760 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306761 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006762 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006763 hdd_ctx->config->busBandwidthHighThreshold,
6764 hdd_ctx->config->busBandwidthMediumThreshold,
6765 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006766 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306767 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006768 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006769 hdd_ctx->config->tcpDelackThresholdHigh,
6770 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006771 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306772 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773#endif
6774
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006775 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306776 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6777
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006778 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779
6780 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006781 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006782 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006783 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006784 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6785 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006786 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006787 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6788 convert_level_to_string(
6789 hdd_ctx->hdd_txrx_hist[i].
6790 next_vote_level),
6791 convert_level_to_string(
6792 hdd_ctx->hdd_txrx_hist[i].
6793 next_rx_level),
6794 convert_level_to_string(
6795 hdd_ctx->hdd_txrx_hist[i].
6796 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006797 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798}
6799
6800/**
6801 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6802 * @hdd_ctx: hdd context
6803 *
6804 * Return: none
6805 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006806void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807{
6808 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306809 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6810 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006811}
6812
6813/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006814 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006815 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006816 *
6817 * Return: none
6818 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006819void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006820{
6821
Jeff Johnson9d295242017-08-29 14:39:48 -07006822 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006823 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306824 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006825 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306826 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006827
6828 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306829 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006830 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006831
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006832 hdd_debug("Netif queue operation statistics:");
6833 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306834 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006835 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306836 curr_time = qdf_system_ticks();
6837 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306838 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306839 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306840 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306841 unpause = adapter->total_unpause_time;
6842 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306843 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306844 pause = adapter->total_pause_time;
6845 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006846 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306847 qdf_system_ticks_to_msecs(total),
6848 qdf_system_ticks_to_msecs(pause),
6849 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006850 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006851
Nirav Shahda008342016-05-17 18:50:40 +05306852 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6853 qdf_time_t pause_delta = 0;
6854
6855 if (adapter->pause_map & (1 << i))
6856 pause_delta = delta;
6857
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006858 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006859 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006860 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006861 hdd_reason_type_to_string(i),
6862 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306863 adapter->queue_oper_stats[i].unpause_count,
6864 qdf_system_ticks_to_msecs(
6865 adapter->queue_oper_stats[i].total_pause_time +
6866 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006867 }
6868
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006869 hdd_debug("Netif queue operation history:");
6870 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306871 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6872
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006873 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006874
6875 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006876 /* using hdd_log to avoid printing function name */
6877 if (adapter->queue_oper_history[i].time == 0)
6878 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006879 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006880 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306881 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882 adapter->queue_oper_history[i].time),
6883 hdd_action_type_to_string(
6884 adapter->queue_oper_history[i].netif_action),
6885 hdd_reason_type_to_string(
6886 adapter->queue_oper_history[i].netif_reason),
6887 adapter->queue_oper_history[i].pause_map);
6888 }
6889
6890 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6891 adapter_node = next;
6892 }
6893
6894
6895}
6896
6897/**
6898 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6899 * @hdd_ctx: hdd context
6900 *
6901 * Return: none
6902 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006903void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006904{
Jeff Johnson9d295242017-08-29 14:39:48 -07006905 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006906 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306907 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006908
6909 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306910 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006911 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006912
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306913 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006914 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306915 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006916 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306917 adapter->history_index = 0;
6918 adapter->start_time = adapter->last_time = qdf_system_ticks();
6919 adapter->total_pause_time = 0;
6920 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006921 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6922 adapter_node = next;
6923 }
6924}
6925
6926/**
6927 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6928 * @halHandle: Hal handle
6929 * @pContext: Pointer to the context
6930 * @sessionId: Session ID
6931 * @scanId: Scan ID
6932 * @status: Status
6933 *
6934 * This is the callback to be executed when 11d scan is completed to flush out
6935 * the scan results
6936 *
6937 * 11d scan is done during driver load and is a passive scan on all
6938 * channels supported by the device, 11d scans may find some APs on
6939 * frequencies which are forbidden to be used in the regulatory domain
6940 * the device is operating in. If these APs are notified to the supplicant
6941 * it may try to connect to these APs, thus flush out all the scan results
6942 * which are present in SME after 11d scan is done.
6943 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306944 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006945 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306946static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006947 uint8_t sessionId, uint32_t scanId,
6948 eCsrScanStatus status)
6949{
6950 ENTER();
6951
6952 sme_scan_flush_result(halHandle);
6953
6954 EXIT();
6955
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306956 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006957}
6958
6959#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6960/**
6961 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6962 * @hdd_ctx: hdd global context
6963 *
6964 * Return: none
6965 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006966static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006967{
6968 uint8_t i;
6969
6970 mutex_init(&hdd_ctx->op_ctx.op_lock);
6971 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6972 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6973 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6974 }
6975}
6976#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006977static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006978{
6979}
6980#endif
6981
Yingying Tang95409972016-10-20 15:16:15 +08006982#ifdef WLAN_FEATURE_WOW_PULSE
6983/**
6984 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006985 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006986 * @enable: enable or disable this behaviour
6987 *
6988 * Return: int
6989 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006990static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006991{
6992 struct hdd_config *pcfg_ini = phddctx->config;
6993 struct wow_pulse_mode wow_pulse_set_info;
6994 QDF_STATUS status;
6995
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006996 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006997
6998 if (false == phddctx->config->wow_pulse_support)
6999 return 0;
7000
7001 /* prepare the request to send to SME */
7002 if (enable == true) {
7003 wow_pulse_set_info.wow_pulse_enable = true;
7004 wow_pulse_set_info.wow_pulse_pin =
7005 pcfg_ini->wow_pulse_pin;
7006 wow_pulse_set_info.wow_pulse_interval_low =
7007 pcfg_ini->wow_pulse_interval_low;
7008 wow_pulse_set_info.wow_pulse_interval_high =
7009 pcfg_ini->wow_pulse_interval_high;
7010 } else {
7011 wow_pulse_set_info.wow_pulse_enable = false;
7012 wow_pulse_set_info.wow_pulse_pin = 0;
7013 wow_pulse_set_info.wow_pulse_interval_low = 0;
7014 wow_pulse_set_info.wow_pulse_interval_high = 0;
7015 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007016 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007017 wow_pulse_set_info.wow_pulse_enable,
7018 wow_pulse_set_info.wow_pulse_pin,
7019 wow_pulse_set_info.wow_pulse_interval_low,
7020 wow_pulse_set_info.wow_pulse_interval_high);
7021
7022 status = sme_set_wow_pulse(&wow_pulse_set_info);
7023 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007024 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007025 return -EIO;
7026 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007027 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007028 return 0;
7029}
7030#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007031static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007032{
7033 return 0;
7034}
7035#endif
7036
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007037#ifdef WLAN_FEATURE_FASTPATH
7038/**
7039 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7040 * @hdd_cfg: hdd config
7041 * @context: lower layer context
7042 *
7043 * Return: none
7044 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307045void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007046 void *context)
7047{
7048 if (hdd_cfg->fastpath_enable)
7049 hif_enable_fastpath(context);
7050}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007051#endif
7052
Yuanyuan Liu13738502016-04-06 17:41:37 -07007053#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007054/**
7055 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007056 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007057 * @level: thermal level
7058 *
7059 * Change IPA data path to SW path when the thermal throttle level greater
7060 * than 0, and restore the original data path when throttle level is 0
7061 *
7062 * Return: none
7063 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007064static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007065{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007066 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007067
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007068 /* Change IPA to SW path when throttle level greater than 0 */
7069 if (level > THROTTLE_LEVEL_0)
7070 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7071 else
7072 /* restore original concurrency mode */
7073 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7074}
7075
7076/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307077 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7078 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307079 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007080 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307081 * Get a safe channel to restart SAP. PCL already takes into account the
7082 * unsafe channels. So, the PCL is validated with the ACS range to provide
7083 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007084 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307085 * Return: Channel number to restart SAP in case of success. In case of any
7086 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007087 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307088static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007089 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007090{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307091 struct sir_pcl_list pcl;
7092 QDF_STATUS status;
7093 uint32_t i, j;
7094 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007095 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307096 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007097
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307098 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7099 if (!hdd_ctx) {
7100 hdd_err("invalid HDD context");
7101 return INVALID_CHANNEL_ID;
7102 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007103
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307104 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7105 if (!hal_handle) {
7106 hdd_err("invalid HAL handle");
7107 return INVALID_CHANNEL_ID;
7108 }
7109
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007110 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7111 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007112 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7113 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307114 if (QDF_IS_STATUS_ERROR(status)) {
7115 hdd_err("Get PCL failed");
7116 return INVALID_CHANNEL_ID;
7117 }
7118
Frank Liudc2cefb2017-06-21 15:38:18 +08007119 /*
7120 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7121 * channel is unsafe channel, the pcl may be empty, instead of return,
7122 * try to choose a safe channel from acs range.
7123 */
7124 if (!pcl.pcl_len)
7125 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307126
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007127 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307128 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7129 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7130
7131 /* PCL already takes unsafe channel into account */
7132 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007133 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307134 if ((pcl.pcl_list[i] >=
7135 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7136 (pcl.pcl_list[i] <=
7137 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007138 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307139 return pcl.pcl_list[i];
7140 }
7141 }
7142
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007143 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307144
7145 /* Try for safe channel from all valid channel */
7146 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007147 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307148 &pcl.pcl_len);
7149 if (QDF_IS_STATUS_ERROR(status)) {
7150 hdd_err("error in getting valid channel list");
7151 return INVALID_CHANNEL_ID;
7152 }
7153
7154 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007155 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307156 found = false;
7157 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007158 if (pcl.pcl_list[i] ==
7159 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007160 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307161 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007162 break;
7163 }
7164 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307165
7166 if (found)
7167 continue;
7168
7169 if ((pcl.pcl_list[i] >=
7170 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7171 (pcl.pcl_list[i] <=
7172 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007173 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307174 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007175 }
7176 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307177
7178 return INVALID_CHANNEL_ID;
7179}
7180
7181/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007182 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307183 * @adapter: AP adapter
7184 * @channel: Channel
7185 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007186 * Moves the SAP interface by invoking the function which
7187 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307188 *
7189 * Return: None
7190 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007191void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307192{
Jeff Johnson87251032017-08-29 13:31:11 -07007193 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307194 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007195 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307196
7197 if (!adapter) {
7198 hdd_err("invalid adapter");
7199 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007200 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307201
7202 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7203
7204 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7205 if (!hal_handle) {
7206 hdd_err("invalid HAL handle");
7207 return;
7208 }
7209
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007210 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7211
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307212 hdd_ap_ctx->sapConfig.channel = channel;
7213 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7214 hdd_ap_ctx->sapConfig.ch_width_orig;
7215
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007216 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307217 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7218
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007219 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7220 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307221 hdd_ap_ctx->sapConfig.sec_ch,
7222 &hdd_ap_ctx->sapConfig.ch_params);
7223
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007224 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7225 adapter->sessionId, channel,
7226 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007227}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307228
Jeff Johnson9d295242017-08-29 14:39:48 -07007229int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307230{
7231 struct hdd_external_acs_timer_context *timer_context;
7232
7233 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7234
7235 if (QDF_TIMER_STATE_RUNNING ==
7236 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7237 ap.vendor_acs_timer)) {
7238 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7239 }
7240 timer_context = (struct hdd_external_acs_timer_context *)
7241 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7242 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307243 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307244 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307245 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7246 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307247 hdd_notice("Updated ACS config to nl with reason %d", reason);
7248
7249 return 0;
7250}
7251
Agrawal Ashish467dde42016-09-08 18:44:22 +05307252/**
7253 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7254 * @hdd_ctx: hdd context pointer
7255 *
7256 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7257 * and if ACS is enabled, driver will ask userspace to restart the
7258 * sap. User space on LTE coex indication restart driver.
7259 *
7260 * Return - none
7261 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007262void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307263{
7264 QDF_STATUS status;
7265 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007266 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307267 uint32_t i;
7268 bool found = false;
7269 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007270
Agrawal Ashish467dde42016-09-08 18:44:22 +05307271 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7272 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007273 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307274
7275 if (!adapter_temp) {
7276 hdd_err("adapter is NULL, moving to next one");
7277 goto next_adapater;
7278 }
7279
7280 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7281 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007282 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307283 adapter_temp->device_mode,
7284 adapter_temp->sessionCtx.ap.sapConfig.
7285 acs_cfg.acs_mode);
7286 goto next_adapater;
7287 }
7288
7289 found = false;
7290 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007291 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307292 hdd_ctxt->unsafe_channel_list[i]) {
7293 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007294 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307295 adapter_temp->sessionCtx.ap.operatingChannel);
7296 break;
7297 }
7298 }
7299
7300 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007301 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307302 adapter_temp->sessionCtx.ap.operatingChannel);
7303 goto next_adapater;
7304 }
7305
Kapil Gupta8878ad92017-02-13 11:56:04 +05307306 if (hdd_ctxt->config->vendor_acs_support &&
7307 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7308 hdd_update_acs_timer_reason(adapter_temp,
7309 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7310 goto next_adapater;
7311 } else
7312 restart_chan =
7313 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307314 adapter_temp);
7315 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007316 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307317 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007318 /*
7319 * SAP restart due to unsafe channel. While
7320 * restarting the SAP, make sure to clear
7321 * acs_channel, channel to reset to
7322 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307323 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007324 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307325 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7326 adapter_temp->sessionCtx.ap.sapConfig.channel =
7327 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007328 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307329 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7330 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007331 hdd_debug("driver to start sap: %d",
7332 hdd_ctxt->config->sap_internal_restart);
7333 if (hdd_ctxt->config->sap_internal_restart)
7334 hdd_switch_sap_channel(adapter_temp, restart_chan);
7335 else
7336 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307337 }
7338
7339next_adapater:
7340 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7341 adapter_node = next;
7342 }
7343}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307344
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007345/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007346 * hdd_init_channel_avoidance() - Initialize channel avoidance
7347 * @hdd_ctx: HDD global context
7348 *
7349 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007350 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351 * down to the lower layers. Then subscribe to subsequent channel
7352 * avoidance events.
7353 *
7354 * Return: None
7355 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007356static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007357{
7358 uint16_t unsafe_channel_count;
7359 int index;
7360
Yuanyuan Liu13738502016-04-06 17:41:37 -07007361 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7362 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007363 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007364 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007365
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007366 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007367 hdd_ctx->unsafe_channel_count);
7368
Anurag Chouhan6d760662016-02-20 16:05:43 +05307369 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007370 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007371
7372 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007373 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007374 hdd_ctx->unsafe_channel_list[index]);
7375
7376 }
7377
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007378}
Dustin Brown676a2322017-08-15 13:16:13 -07007379
Jeff Johnson9d295242017-08-29 14:39:48 -07007380static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007381 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007382{
7383 uint8_t restart_chan;
7384
7385 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7386 if (!restart_chan) {
7387 hdd_alert("fail to restart SAP");
7388 return;
7389 }
7390
7391 /* SAP restart due to unsafe channel. While restarting
7392 * the SAP, make sure to clear acs_channel, channel to
7393 * reset to 0. Otherwise these settings will override
7394 * the ACS while restart.
7395 */
7396 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7397 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7398
7399 hdd_debug("sending coex indication");
7400
7401 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7402 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7403 hdd_switch_sap_channel(adapter, restart_chan);
7404}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007405
7406int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7407 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7408{
7409 uint32_t size;
7410 uint16_t *unsafe_list;
7411 uint16_t chan_count;
7412
7413 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7414 return -EINVAL;
7415
7416 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7417 NUM_CHANNELS);
7418 if (chan_count) {
7419 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7420 unsafe_list = qdf_mem_malloc(size);
7421 if (!unsafe_list) {
7422 hdd_err("No memory for unsafe chan list size%d",
7423 size);
7424 return -ENOMEM;
7425 }
7426 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7427 } else {
7428 unsafe_list = NULL;
7429 }
7430
7431 *local_unsafe_list = unsafe_list;
7432 *local_unsafe_list_count = chan_count;
7433
7434 return 0;
7435}
7436
7437bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7438 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7439{
7440 int i, j;
7441
7442 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7443 return true;
7444 if (local_unsafe_list_count == 0)
7445 return false;
7446 for (i = 0; i < local_unsafe_list_count; i++) {
7447 for (j = 0; j < local_unsafe_list_count; j++)
7448 if (local_unsafe_list[i] ==
7449 hdd_ctx->unsafe_channel_list[j])
7450 break;
7451 if (j >= local_unsafe_list_count)
7452 break;
7453 }
7454 if (i >= local_unsafe_list_count) {
7455 hdd_info("unsafe chan list same");
7456 return false;
7457 }
7458
7459 return true;
7460}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007461#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007462static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007463{
7464}
Dustin Brown676a2322017-08-15 13:16:13 -07007465
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007466static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007467{
7468}
Dustin Brown676a2322017-08-15 13:16:13 -07007469
Jeff Johnson9d295242017-08-29 14:39:48 -07007470static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007471 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007472{
7473 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7474}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007475#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007476
7477/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007478 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7479 * user space
7480 * @frame_ind: Management frame data to be informed.
7481 *
7482 * This function is used to indicate management frame to
7483 * user space
7484 *
7485 * Return: None
7486 *
7487 */
7488void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7489{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007490 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007491 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007492 int i;
7493
Rajeev Kumard004abc2016-02-17 12:09:56 -08007494 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007495 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007496
7497 if (0 != wlan_hdd_validate_context(hdd_ctx))
7498 return;
7499
7500 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7501 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7502 adapter =
7503 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7504 if (adapter)
7505 break;
7506 }
7507 } else {
7508 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7509 frame_ind->sessionId);
7510 }
7511
7512 if ((NULL != adapter) &&
7513 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7514 __hdd_indicate_mgmt_frame(adapter,
7515 frame_ind->frame_len,
7516 frame_ind->frameBuf,
7517 frame_ind->frameType,
7518 frame_ind->rxChan,
7519 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007520}
7521
Kapil Gupta8878ad92017-02-13 11:56:04 +05307522void hdd_acs_response_timeout_handler(void *context)
7523{
7524 struct hdd_external_acs_timer_context *timer_context =
7525 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007526 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007527 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307528 uint8_t reason;
7529
7530 ENTER();
7531 if (!timer_context) {
7532 hdd_err("invlaid timer context");
7533 return;
7534 }
7535 adapter = timer_context->adapter;
7536 reason = timer_context->reason;
7537
7538
7539 if ((!adapter) ||
7540 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7541 hdd_err("invalid adapter or adapter has invalid magic");
7542 return;
7543 }
7544 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7545 if (wlan_hdd_validate_context(hdd_ctx))
7546 return;
7547
7548 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7549 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7550 else
7551 return;
7552
7553 hdd_err("ACS timeout happened for %s reason %d",
7554 adapter->dev->name, reason);
7555 switch (reason) {
7556 /* SAP init case */
7557 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7558 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7559 false);
7560 wlan_hdd_cfg80211_start_acs(adapter);
7561 break;
7562 /* DFS detected on current channel */
7563 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7564 wlan_sap_update_next_channel(
7565 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7566 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7567 adapter->sessionId);
7568 break;
7569 /* LTE coex event on current channel */
7570 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7571 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7572 break;
7573 default:
7574 hdd_info("invalid reason for timer invoke");
7575
7576 }
7577}
7578
Rajeev Kumard004abc2016-02-17 12:09:56 -08007579/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007580 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7581 * @hdd_ctx: HDD context
7582 *
7583 * Disables all the dual mac features like DBS, Agile DFS etc.
7584 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307585 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007586 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007587static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007588{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007589 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307590 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007591
7592 if (!hdd_ctx) {
7593 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307594 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007595 }
7596
7597 cfg.scan_config = 0;
7598 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007599 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007600
7601 hdd_debug("Disabling all dual mac features...");
7602
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007603 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307604 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007605 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7606 return status;
7607 }
7608
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307609 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007610}
7611
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007612static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007613wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007614{
7615 struct policy_mgr_dual_mac_config cfg = {0};
7616 QDF_STATUS status;
7617
7618 if (!hdd_ctx) {
7619 hdd_err("HDD context is NULL");
7620 return QDF_STATUS_E_FAILURE;
7621 }
7622
7623 cfg.scan_config = 0;
7624 cfg.fw_mode_config = 0;
7625 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7626 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7627 hdd_ctx->hdd_psoc, &cfg.scan_config,
7628 &cfg.fw_mode_config,
7629 hdd_ctx->config->dual_mac_feature_disable);
7630
7631 if (status != QDF_STATUS_SUCCESS) {
7632 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7633 status);
7634 return status;
7635 }
7636
7637 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7638 cfg.scan_config, cfg.fw_mode_config);
7639
7640 status = sme_soc_set_dual_mac_config(cfg);
7641 if (status != QDF_STATUS_SUCCESS) {
7642 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7643 return status;
7644 }
7645
7646 return QDF_STATUS_SUCCESS;
7647}
7648
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007649/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007650 * hdd_override_ini_config - Override INI config
7651 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007652 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007653 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007654 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007655 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007656 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007657static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007658{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007659
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007660 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7661 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007662 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007663 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007664 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007665 if (0 == enable_11d || 1 == enable_11d) {
7666 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007667 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007668 }
Leo Chang11545d62016-10-17 14:53:50 -07007669
7670 if (!hdd_ipa_is_present(hdd_ctx))
7671 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007672}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007673
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007674/**
7675 * hdd_set_trace_level_for_each - Set trace level for each INI config
7676 * @hdd_ctx - HDD context
7677 *
7678 * Set trace level for each module based on INI config.
7679 *
7680 * Return: None
7681 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007682static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007683{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307684 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7685 hdd_ctx->config->qdf_trace_enable_wdi);
7686 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7687 hdd_ctx->config->qdf_trace_enable_hdd);
7688 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7689 hdd_ctx->config->qdf_trace_enable_sme);
7690 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7691 hdd_ctx->config->qdf_trace_enable_pe);
7692 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7693 hdd_ctx->config->qdf_trace_enable_wma);
7694 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7695 hdd_ctx->config->qdf_trace_enable_sys);
7696 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7697 hdd_ctx->config->qdf_trace_enable_qdf);
7698 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7699 hdd_ctx->config->qdf_trace_enable_sap);
7700 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7701 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7702 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7703 hdd_ctx->config->qdf_trace_enable_bmi);
7704 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7705 hdd_ctx->config->qdf_trace_enable_cfg);
7706 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7707 hdd_ctx->config->qdf_trace_enable_epping);
7708 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7709 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7710 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007711 hdd_ctx->config->qdf_trace_enable_txrx);
7712 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7713 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307714 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7715 hdd_ctx->config->qdf_trace_enable_htc);
7716 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7717 hdd_ctx->config->qdf_trace_enable_hif);
7718 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7719 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7720 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7721 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007722 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7723 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007724 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7725 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007726 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7727 hdd_ctx->config->qdf_trace_enable_regulatory);
7728
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007729 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007730}
7731
7732/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007733 * hdd_context_init() - Initialize HDD context
7734 * @hdd_ctx: HDD context.
7735 *
7736 * Initialize HDD context along with all the feature specific contexts.
7737 *
7738 * return: 0 on success and errno on failure.
7739 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007740static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007741{
7742 int ret;
7743
7744 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7745 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7746
7747 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307748 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007749
7750 init_completion(&hdd_ctx->mc_sus_event_var);
7751 init_completion(&hdd_ctx->ready_to_suspend);
7752
7753 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307754 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007755 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307756
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007757 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7758
7759 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7760
7761 ret = hdd_scan_context_init(hdd_ctx);
7762 if (ret)
7763 goto list_destroy;
7764
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007765 hdd_rx_wake_lock_create(hdd_ctx);
7766
7767 ret = hdd_sap_context_init(hdd_ctx);
7768 if (ret)
7769 goto scan_destroy;
7770
7771 ret = hdd_roc_context_init(hdd_ctx);
7772 if (ret)
7773 goto sap_destroy;
7774
7775 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7776
7777 hdd_init_offloaded_packets_ctx(hdd_ctx);
7778
7779 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7780 hdd_ctx->config);
7781 if (ret)
7782 goto roc_destroy;
7783
7784 return 0;
7785
7786roc_destroy:
7787 hdd_roc_context_destroy(hdd_ctx);
7788
7789sap_destroy:
7790 hdd_sap_context_destroy(hdd_ctx);
7791
7792scan_destroy:
7793 hdd_scan_context_destroy(hdd_ctx);
7794 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007795list_destroy:
7796 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007797
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007798 return ret;
7799}
7800
7801/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307802 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7803 * @hdd_ctx: pointer to hdd context
7804 *
7805 * Return: status of initialization
7806 * 0 - success
7807 * negative value - failure
7808 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007809static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307810{
7811 int ret;
7812
7813 if (!hdd_ctx->config->probe_req_ie_whitelist)
7814 return 0;
7815
7816 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7817 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7818 hdd_ctx->config->probe_req_ie_whitelist = false;
7819 return -EINVAL;
7820 }
7821
7822 /* parse ini string probe req oui */
7823 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7824 if (ret) {
7825 hdd_err("parsing error: disable ie whitelisting");
7826 hdd_ctx->config->probe_req_ie_whitelist = false;
7827 }
7828
7829 return ret;
7830}
7831
7832/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007833 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307834 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007835 *
7836 * Allocate and initialize HDD context. HDD context is allocated as part of
7837 * wiphy allocation and then context is initialized.
7838 *
7839 * Return: HDD context on success and ERR_PTR on failure
7840 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007841static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007842{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307843 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007844 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007845 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007846
7847 ENTER();
7848
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007849 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007850 if (hdd_ctx == NULL) {
7851 ret = -ENOMEM;
7852 goto err_out;
7853 }
7854
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007855 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307856 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007857
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307858 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007859 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007860 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007861 ret = -ENOMEM;
7862 goto err_free_hdd_context;
7863 }
7864
7865 /* Read and parse the qcom_cfg.ini file */
7866 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307867 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307868 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007869 WLAN_INI_FILE);
7870 ret = -EINVAL;
7871 goto err_free_config;
7872 }
7873
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307874 ie_whitelist_attrs_init(hdd_ctx);
7875
Dustin Brown7f939932017-05-18 15:02:17 -07007876 hdd_debug("setting timer multiplier: %u",
7877 hdd_ctx->config->timer_multiplier);
7878 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7879
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007880
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307881 if (hdd_ctx->config->fhostNSOffload)
7882 hdd_ctx->ns_offload_enable = true;
7883
Abhishek Singh5ea86532016-04-27 14:10:53 +05307884 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7885
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007886 hdd_override_ini_config(hdd_ctx);
7887
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007888 ret = hdd_context_init(hdd_ctx);
7889
7890 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007891 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007892
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007893 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307894 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007895
Anurag Chouhan6d760662016-02-20 16:05:43 +05307896 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007897 goto skip_multicast_logging;
7898
7899 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7900
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007901 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7902 if (ret)
7903 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307904
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007905 ret = hdd_init_netlink_services(hdd_ctx);
7906 if (ret)
7907 goto err_deinit_txrx_histogram;
7908
Dustin Brown7b3dea22017-07-10 13:02:47 -07007909 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7910 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307911
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007912skip_multicast_logging:
7913 hdd_set_trace_level_for_each(hdd_ctx);
7914
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007915 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7916
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007917 EXIT();
7918
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007919 return hdd_ctx;
7920
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007921err_deinit_txrx_histogram:
7922 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7923
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007924err_deinit_hdd_context:
7925 hdd_context_deinit(hdd_ctx);
7926
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007927err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307928 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007929
7930err_free_hdd_context:
7931 wiphy_free(hdd_ctx->wiphy);
7932
7933err_out:
7934 return ERR_PTR(ret);
7935}
7936
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007937#ifdef WLAN_OPEN_P2P_INTERFACE
7938/**
7939 * hdd_open_p2p_interface - Open P2P interface
7940 * @hdd_ctx: HDD context
7941 * @rtnl_held: True if RTNL lock held
7942 *
7943 * Open P2P interface during probe. This function called to open the P2P
7944 * interface at probe along with STA interface.
7945 *
7946 * Return: 0 on success and errno on failure
7947 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007948static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007949{
Jeff Johnson9d295242017-08-29 14:39:48 -07007950 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007951 uint8_t *p2p_dev_addr;
7952
7953 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7954 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307955 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007956 hdd_ctx->config->intfMacAddr[0].bytes,
7957 sizeof(tSirMacAddr));
7958
7959 /*
7960 * Generate the P2P Device Address. This consists of
7961 * the device's primary MAC address with the locally
7962 * administered bit set.
7963 */
7964 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7965 } else {
7966 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7967 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007968 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007969 return -ENOSPC;
7970 }
7971
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307972 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307973 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007974 }
7975
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007976 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007977 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007978 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007979
7980 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007981 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007982 return -ENOSPC;
7983 }
7984
7985 return 0;
7986}
7987#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007988static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007989 bool rtnl_held)
7990{
7991 return 0;
7992}
7993#endif
7994
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007995static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007996{
Jeff Johnson9d295242017-08-29 14:39:48 -07007997 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007998 int ret = 0;
7999
8000 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8001 wlan_hdd_get_intf_addr(hdd_ctx),
8002 NET_NAME_UNKNOWN, rtnl_held);
8003 if (adapter == NULL) {
8004 hdd_err("Failed to open 802.11p interface");
8005 ret = -ENOSPC;
8006 }
8007
8008 return ret;
8009}
8010
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008011/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308012 * hdd_start_station_adapter()- Start the Station Adapter
8013 * @adapter: HDD adapter
8014 *
8015 * This function initializes the adapter for the station mode.
8016 *
8017 * Return: 0 on success or errno on failure.
8018 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008019int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308020{
8021 QDF_STATUS status;
8022
8023 ENTER_DEV(adapter->dev);
8024
8025 status = hdd_init_station_mode(adapter);
8026
8027 if (QDF_STATUS_SUCCESS != status) {
8028 hdd_err("Error Initializing station mode: %d", status);
8029 return qdf_status_to_os_return(status);
8030 }
8031
Arun Khandavallifae92942016-08-01 13:31:08 +05308032 hdd_register_tx_flow_control(adapter,
8033 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008034 hdd_tx_resume_cb,
8035 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308036
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308037 EXIT();
8038 return 0;
8039}
8040
8041/**
8042 * hdd_start_ap_adapter()- Start AP Adapter
8043 * @adapter: HDD adapter
8044 *
8045 * This function initializes the adapter for the AP mode.
8046 *
8047 * Return: 0 on success errno on failure.
8048 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008049int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308050{
8051 QDF_STATUS status;
8052
8053 ENTER();
8054
Arun Khandavallicc544b32017-01-30 19:52:16 +05308055 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308056
8057 if (QDF_STATUS_SUCCESS != status) {
8058 hdd_err("Error Initializing the AP mode: %d", status);
8059 return qdf_status_to_os_return(status);
8060 }
8061
Arun Khandavallifae92942016-08-01 13:31:08 +05308062 hdd_register_tx_flow_control(adapter,
8063 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008064 hdd_softap_tx_resume_cb,
8065 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308066
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308067 EXIT();
8068 return 0;
8069}
8070
8071/**
8072 * hdd_start_ftm_adapter()- Start FTM adapter
8073 * @adapter: HDD adapter
8074 *
8075 * This function initializes the adapter for the FTM mode.
8076 *
8077 * Return: 0 on success or errno on failure.
8078 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008079int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308080{
8081 QDF_STATUS qdf_status;
8082
8083 ENTER_DEV(adapter->dev);
8084
8085 qdf_status = hdd_init_tx_rx(adapter);
8086
8087 if (QDF_STATUS_SUCCESS != qdf_status) {
8088 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8089 return qdf_status_to_os_return(qdf_status);
8090 }
8091
8092 return 0;
8093 EXIT();
8094}
8095
8096/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008097 * hdd_open_interfaces - Open all required interfaces
8098 * hdd_ctx: HDD context
8099 * rtnl_held: True if RTNL lock is held
8100 *
8101 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8102 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008103 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008105static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008106{
Jeff Johnson9d295242017-08-29 14:39:48 -07008107 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008108 int ret;
8109
Ravi Joshia307f632017-07-17 23:41:41 -07008110 /* open monitor mode adapter if con_mode is monitor mode */
8111 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8112 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8113 wlan_hdd_get_intf_addr(hdd_ctx),
8114 NET_NAME_UNKNOWN, rtnl_held);
8115 if (!adapter) {
8116 hdd_err("open adapter failed");
8117 return -ENOSPC;
8118 }
8119 return 0;
8120 }
8121
Jeff Johnson957bc272017-02-02 08:54:48 -08008122 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308123 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008124 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008125
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008126 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008127 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008128 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008129
8130 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008131 return -ENOSPC;
8132
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008133 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8134 adapter->fast_roaming_allowed = true;
8135
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008136 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8137 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008138 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008139
8140 /* Open 802.11p Interface */
8141 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008142 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8143 if (ret)
8144 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008145 }
8146
Jeff Johnson957bc272017-02-02 08:54:48 -08008147 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008148
Jeff Johnson957bc272017-02-02 08:54:48 -08008149err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008150 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008151 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008152}
8153
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008154/**
8155 * hdd_update_country_code - Update country code
8156 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008157 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008158 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008159 *
8160 * Return: 0 on success and errno on failure
8161 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008162static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008163{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008164 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008165 return 0;
8166
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008167 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008168}
8169
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308170#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8171/**
8172 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8173 * @cds_cfg: CDS Configuration
8174 * @hdd_ctx: Pointer to hdd context
8175 *
8176 * Return: none
8177 */
8178static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8179 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008180 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308181{
8182 cds_cfg->tx_flow_stop_queue_th =
8183 hdd_ctx->config->TxFlowStopQueueThreshold;
8184 cds_cfg->tx_flow_start_queue_offset =
8185 hdd_ctx->config->TxFlowStartQueueOffset;
8186}
8187#else
8188static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8189 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008190 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308191{
8192}
8193#endif
8194
8195#ifdef FEATURE_WLAN_RA_FILTERING
8196/**
8197 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8198 * @cds_cfg: CDS Configuration
8199 * @hdd_ctx: Pointer to hdd context
8200 *
8201 * Return: none
8202 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308203static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008204 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308205{
8206 cds_cfg->ra_ratelimit_interval =
8207 hdd_ctx->config->RArateLimitInterval;
8208 cds_cfg->is_ra_ratelimit_enabled =
8209 hdd_ctx->config->IsRArateLimitEnabled;
8210}
8211#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308212static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008213 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308214{
8215}
8216#endif
8217
8218/**
8219 * hdd_update_cds_config() - API to update cds configuration parameters
8220 * @hdd_ctx: HDD Context
8221 *
8222 * Return: 0 for Success, errno on failure
8223 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008224static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308225{
8226 struct cds_config_info *cds_cfg;
8227
8228 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8229 if (!cds_cfg) {
8230 hdd_err("failed to allocate cds config");
8231 return -ENOMEM;
8232 }
8233
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008234 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008235 if (!hdd_ctx->config->nMaxPsPoll ||
8236 !hdd_ctx->config->enablePowersaveOffload) {
8237 cds_cfg->powersave_offload_enabled =
8238 hdd_ctx->config->enablePowersaveOffload;
8239 } else {
8240 if ((hdd_ctx->config->enablePowersaveOffload ==
8241 PS_QPOWER_NODEEPSLEEP) ||
8242 (hdd_ctx->config->enablePowersaveOffload ==
8243 PS_LEGACY_NODEEPSLEEP))
8244 cds_cfg->powersave_offload_enabled =
8245 PS_LEGACY_NODEEPSLEEP;
8246 else
8247 cds_cfg->powersave_offload_enabled =
8248 PS_LEGACY_DEEPSLEEP;
8249 hdd_info("Qpower disabled in cds config, %d",
8250 cds_cfg->powersave_offload_enabled);
8251 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308252 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8253 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8254 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8255 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8256 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8257
8258 /* Here ol_ini_info is used to store ini status of arp offload
8259 * ns offload and others. Currently 1st bit is used for arp
8260 * off load and 2nd bit for ns offload currently, rest bits are unused
8261 */
8262 if (hdd_ctx->config->fhostArpOffload)
8263 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8264 if (hdd_ctx->config->fhostNSOffload)
8265 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8266
8267 /*
8268 * Copy the DFS Phyerr Filtering Offload status.
8269 * This parameter reflects the value of the
8270 * dfs_phyerr_filter_offload flag as set in the ini.
8271 */
8272 cds_cfg->dfs_phyerr_filter_offload =
8273 hdd_ctx->config->fDfsPhyerrFilterOffload;
8274 if (hdd_ctx->config->ssdp)
8275 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8276
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308277 cds_cfg->force_target_assert_enabled =
8278 hdd_ctx->config->crash_inject_enabled;
8279
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308280 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8281 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8282
8283 cds_cfg->ap_maxoffload_reorderbuffs =
8284 hdd_ctx->config->apMaxOffloadReorderBuffs;
8285
8286 cds_cfg->ap_disable_intrabss_fwd =
8287 hdd_ctx->config->apDisableIntraBssFwd;
8288
8289 cds_cfg->dfs_pri_multiplier =
8290 hdd_ctx->config->dfsRadarPriMultiplier;
8291 cds_cfg->reorder_offload =
8292 hdd_ctx->config->reorderOffloadSupport;
8293
8294 /* IPA micro controller data path offload resource config item */
8295 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008296 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8297 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008298 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008299 hdd_ctx->config->IpaUcTxBufCount);
8300 hdd_ctx->config->IpaUcTxBufCount =
8301 rounddown_pow_of_two(
8302 hdd_ctx->config->IpaUcTxBufCount);
8303 if (!hdd_ctx->config->IpaUcTxBufCount) {
8304 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308305 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008306 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008307 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008308 hdd_ctx->config->IpaUcTxBufCount);
8309 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308310 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8311 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008312 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8313 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008314 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008315 hdd_ctx->config->IpaUcRxIndRingCount);
8316 hdd_ctx->config->IpaUcRxIndRingCount =
8317 rounddown_pow_of_two(
8318 hdd_ctx->config->IpaUcRxIndRingCount);
8319 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8320 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308321 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008322 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008323 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008324 hdd_ctx->config->IpaUcRxIndRingCount);
8325 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308326 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008327 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308328 cds_cfg->uc_tx_partition_base =
8329 hdd_ctx->config->IpaUcTxPartitionBase;
8330 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8331
8332 cds_cfg->ip_tcp_udp_checksum_offload =
8333 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308334 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308335 cds_cfg->ce_classify_enabled =
8336 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008337 cds_cfg->bpf_packet_filter_enable =
8338 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308339 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8340 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8341 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008342 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008343 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008344 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008345 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308346 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8347 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308348 cds_cfg->auto_power_save_fail_mode =
8349 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308350
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308351 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008352 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308353
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308354 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8355 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8356 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008357 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308358 cds_init_ini_config(cds_cfg);
8359 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308360
8361exit:
8362 qdf_mem_free(cds_cfg);
8363 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308364}
8365
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008366/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008367 * hdd_update_user_config() - API to update user configuration
8368 * parameters to obj mgr which are used by multiple components
8369 * @hdd_ctx: HDD Context
8370 *
8371 * Return: 0 for Success, errno on failure
8372 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008373static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008374{
8375 struct wlan_objmgr_psoc_user_config *user_config;
8376
8377 user_config = qdf_mem_malloc(sizeof(*user_config));
8378 if (user_config == NULL) {
8379 hdd_alert("Failed to alloc memory for user_config!");
8380 return -ENOMEM;
8381 }
8382
8383 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8384 user_config->dual_mac_feature_disable =
8385 hdd_ctx->config->dual_mac_feature_disable;
8386 user_config->indoor_channel_support =
8387 hdd_ctx->config->indoor_channel_support;
8388 user_config->is_11d_support_enabled =
8389 hdd_ctx->config->Is11dSupportEnabled;
8390 user_config->is_11h_support_enabled =
8391 hdd_ctx->config->Is11hSupportEnabled;
8392 user_config->optimize_chan_avoid_event =
8393 hdd_ctx->config->goptimize_chan_avoid_event;
8394 user_config->skip_dfs_chnl_in_p2p_search =
8395 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008396 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008397 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8398
8399 qdf_mem_free(user_config);
8400 return 0;
8401}
8402
8403/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008404 * hdd_init_thermal_info - Initialize thermal level
8405 * @hdd_ctx: HDD context
8406 *
8407 * Initialize thermal level at SME layer and set the thermal level callback
8408 * which would be called when a configured thermal threshold is hit.
8409 *
8410 * Return: 0 on success and errno on failure
8411 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008412static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008413{
8414 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308415 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008416
8417 thermal_param.smeThermalMgmtEnabled =
8418 hdd_ctx->config->thermalMitigationEnable;
8419 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8420
Poddar, Siddarth83905022016-04-16 17:56:08 -07008421 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8422 hdd_ctx->config->throttle_dutycycle_level0;
8423 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8424 hdd_ctx->config->throttle_dutycycle_level1;
8425 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8426 hdd_ctx->config->throttle_dutycycle_level2;
8427 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8428 hdd_ctx->config->throttle_dutycycle_level3;
8429
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008430 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8431 hdd_ctx->config->thermalTempMinLevel0;
8432 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8433 hdd_ctx->config->thermalTempMaxLevel0;
8434 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8435 hdd_ctx->config->thermalTempMinLevel1;
8436 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8437 hdd_ctx->config->thermalTempMaxLevel1;
8438 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8439 hdd_ctx->config->thermalTempMinLevel2;
8440 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8441 hdd_ctx->config->thermalTempMaxLevel2;
8442 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8443 hdd_ctx->config->thermalTempMinLevel3;
8444 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8445 hdd_ctx->config->thermalTempMaxLevel3;
8446
8447 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8448
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308449 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308450 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008451
8452 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8453 hdd_set_thermal_level_cb);
8454
8455 return 0;
8456
8457}
8458
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008459#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8460/**
8461 * hdd_hold_rtnl_lock - Hold RTNL lock
8462 *
8463 * Hold RTNL lock
8464 *
8465 * Return: True if held and false otherwise
8466 */
8467static inline bool hdd_hold_rtnl_lock(void)
8468{
8469 rtnl_lock();
8470 return true;
8471}
8472
8473/**
8474 * hdd_release_rtnl_lock - Release RTNL lock
8475 *
8476 * Release RTNL lock
8477 *
8478 * Return: None
8479 */
8480static inline void hdd_release_rtnl_lock(void)
8481{
8482 rtnl_unlock();
8483}
8484#else
8485static inline bool hdd_hold_rtnl_lock(void) { return false; }
8486static inline void hdd_release_rtnl_lock(void) { }
8487#endif
8488
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008489#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008490
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308491/* MAX iwpriv command support */
8492#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308493#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308494#define MAX_PKTLOG_SIZE 16
8495
8496/**
8497 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8498 * @hdd_ctx: hdd context
8499 * @set_value2: pktlog buffer size value
8500 *
8501 *
8502 * Return: 0 for success or error.
8503 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008504static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308505{
8506 struct sir_wifi_start_log start_log = { 0 };
8507 QDF_STATUS status;
8508
8509 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8510 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8511 start_log.ini_triggered = cds_is_packet_log_enabled();
8512 start_log.user_triggered = 1;
8513 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308514 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308515
8516 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8517 if (!QDF_IS_STATUS_SUCCESS(status)) {
8518 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8519 EXIT();
8520 return -EINVAL;
8521 }
8522
8523 return 0;
8524}
8525
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008526/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308527 * hdd_pktlog_clear_buff() - clear pktlog buffer
8528 * @hdd_ctx: hdd context
8529 *
8530 * Return: 0 for success or error.
8531 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008532static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308533{
8534 struct sir_wifi_start_log start_log;
8535 QDF_STATUS status;
8536
8537 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8538 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8539 start_log.ini_triggered = cds_is_packet_log_enabled();
8540 start_log.user_triggered = 1;
8541 start_log.size = 0;
8542 start_log.is_pktlog_buff_clear = true;
8543
8544 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8545 if (!QDF_IS_STATUS_SUCCESS(status)) {
8546 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8547 EXIT();
8548 return -EINVAL;
8549 }
8550
8551 return 0;
8552}
8553
8554
8555/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008556 * hdd_process_pktlog_command() - process pktlog command
8557 * @hdd_ctx: hdd context
8558 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308559 * @set_value2: pktlog buffer size value
8560 *
8561 * This function process pktlog command.
8562 * set_value2 only matters when set_value is 3 (set buff size)
8563 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008564 *
8565 * Return: 0 for success or error.
8566 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008567int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308568 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008569{
8570 int ret;
8571 bool enable;
8572 uint8_t user_triggered = 0;
8573
8574 ret = wlan_hdd_validate_context(hdd_ctx);
8575 if (0 != ret)
8576 return ret;
8577
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008578 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008579
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308580 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008581 hdd_err("invalid pktlog value %d", set_value);
8582 return -EINVAL;
8583 }
8584
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308585 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8586 if (set_value2 <= 0) {
8587 hdd_err("invalid pktlog size %d", set_value2);
8588 return -EINVAL;
8589 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8590 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8591 return -EINVAL;
8592 }
8593 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308594 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8595 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308596 }
8597
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008598 /*
8599 * set_value = 0 then disable packetlog
8600 * set_value = 1 enable packetlog forcefully
8601 * set_vlaue = 2 then disable packetlog if disabled through ini or
8602 * enable packetlog with AUTO type.
8603 */
8604 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8605 true : false;
8606
8607 if (1 == set_value) {
8608 enable = true;
8609 user_triggered = 1;
8610 }
8611
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308612 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008613}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008614
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008615/**
8616 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8617 * @hdd_ctx: HDD context
8618 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308619 * @user_triggered: triggered through iwpriv
8620 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008621 *
8622 * Return: 0 on success; error number otherwise
8623 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008624int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308625 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008626{
8627 struct sir_wifi_start_log start_log;
8628 QDF_STATUS status;
8629
8630 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8631 start_log.verbose_level =
8632 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008633 start_log.ini_triggered = cds_is_packet_log_enabled();
8634 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308635 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308636 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308637 /*
8638 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8639 * commands. Host uses this flag to decide whether to send pktlog
8640 * disable command to fw without sending pktlog enable command
8641 * previously. For eg, If vendor sends pktlog disable command without
8642 * sending pktlog enable command, then host discards the packet
8643 * but for iwpriv command, host will send it to fw.
8644 */
8645 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008646 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8647 if (!QDF_IS_STATUS_SUCCESS(status)) {
8648 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8649 EXIT();
8650 return -EINVAL;
8651 }
8652
8653 return 0;
8654}
8655#endif /* REMOVE_PKT_LOG */
8656
Komal Seelam92fff912016-03-24 11:51:41 +05308657/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008658 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8659 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308660 * @dev: Device Pointer
8661 * @num: Number of Valid Mac address
8662 *
8663 * Return: Pointer to MAC address buffer
8664 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008665static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8666 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308667{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008668 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308669}
Komal Seelam92fff912016-03-24 11:51:41 +05308670
8671/**
8672 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8673 * @hdd_ctx: HDD Context
8674 * @num: Number of random mac addresses needed
8675 *
8676 * Generate random addresses using bit manipulation on the base mac address
8677 *
8678 * Return: None
8679 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008680void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308681{
8682 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8683 uint32_t iter;
8684 struct hdd_config *ini = hdd_ctx->config;
8685 uint8_t *buf = NULL;
8686 uint8_t macaddr_b3, tmp_br3;
8687 uint8_t *src = ini->intfMacAddr[0].bytes;
8688
8689 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8690 buf = ini->intfMacAddr[iter].bytes;
8691 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8692 macaddr_b3 = buf[3];
8693 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8694 INTF_MACADDR_MASK;
8695 macaddr_b3 += tmp_br3;
8696 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8697 buf[0] |= 0x02;
8698 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008699 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308700 }
8701}
8702
8703/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008704 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308705 * @hdd_ctx: HDD Context
8706 *
8707 * API to get mac addresses from platform driver and update the driver
8708 * structures and configure FW with the base mac address.
8709 * Return: int
8710 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008711static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308712{
8713 uint32_t no_of_mac_addr, iter;
8714 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8715 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8716 uint8_t *addr, *buf;
8717 struct device *dev = hdd_ctx->parent_dev;
8718 struct hdd_config *ini = hdd_ctx->config;
8719 tSirMacAddr mac_addr;
8720 QDF_STATUS status;
8721
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008722 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308723
8724 if (no_of_mac_addr == 0 || !addr) {
8725 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8726 return -EINVAL;
8727 }
8728
8729 if (no_of_mac_addr > max_mac_addr)
8730 no_of_mac_addr = max_mac_addr;
8731
8732 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8733
8734 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8735 buf = ini->intfMacAddr[iter].bytes;
8736 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008737 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308738 }
8739
8740 status = sme_set_custom_mac_addr(mac_addr);
8741
8742 if (!QDF_IS_STATUS_SUCCESS(status))
8743 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008744
Komal Seelam92fff912016-03-24 11:51:41 +05308745 if (no_of_mac_addr < max_mac_addr)
8746 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8747 no_of_mac_addr);
8748 return 0;
8749}
8750
8751/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008752 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8753 * @hdd_ctx: HDD Context
8754 *
8755 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8756 * will generate its own MAC and update it to FW.
8757 *
8758 * Return: 0 for success
8759 * Non-zero error code for failure
8760 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008761static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008762{
8763 tSirMacAddr customMacAddr;
8764 QDF_STATUS status;
8765
8766 qdf_mem_copy(&customMacAddr,
8767 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8768 sizeof(tSirMacAddr));
8769 status = sme_set_custom_mac_addr(customMacAddr);
8770 if (!QDF_IS_STATUS_SUCCESS(status))
8771 return -EAGAIN;
8772 return 0;
8773}
8774
8775/**
Komal Seelam92fff912016-03-24 11:51:41 +05308776 * hdd_initialize_mac_address() - API to get wlan mac addresses
8777 * @hdd_ctx: HDD Context
8778 *
8779 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8780 * is provisioned with mac addresses, driver uses it, else it will use
8781 * wlan_mac.bin to update HW MAC addresses.
8782 *
8783 * Return: None
8784 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008785static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308786{
8787 QDF_STATUS status;
8788 int ret;
8789
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008790 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308791 if (ret == 0)
8792 return;
8793
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008794 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8795 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308796
8797 status = hdd_update_mac_config(hdd_ctx);
8798
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008799 if (QDF_IS_STATUS_SUCCESS(status))
8800 return;
8801
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008802 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8803 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008804
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008805 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008806 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008807 if (ret != 0) {
8808 hdd_err("MAC address out-of-sync, ret:%d", ret);
8809 QDF_ASSERT(ret);
8810 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008811 }
Komal Seelam92fff912016-03-24 11:51:41 +05308812}
8813
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008814static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008815{
8816 int vdev_id = 0;
8817 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8818 int value = hdd_ctx->config->smart_chainmask_enabled;
8819 int vpdev = PDEV_CMD;
8820 int ret;
8821
Naveen Rawat247a8682017-06-05 15:00:31 -07008822 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008823 if (ret)
8824 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8825
8826 return ret;
8827}
8828
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008829static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008830{
8831 int vdev_id = 0;
8832 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8833 int value = hdd_ctx->config->alternative_chainmask_enabled;
8834 int vpdev = PDEV_CMD;
8835 int ret;
8836
Naveen Rawat247a8682017-06-05 15:00:31 -07008837 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008838 if (ret)
8839 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8840 ret);
8841
8842 return ret;
8843}
8844
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008845static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008846{
8847 int vdev_id = 0;
8848 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8849 int value = hdd_ctx->config->ani_enabled;
8850 int vpdev = PDEV_CMD;
8851 int ret;
8852
Naveen Rawat247a8682017-06-05 15:00:31 -07008853 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008854 if (ret)
8855 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8856
8857 return ret;
8858}
8859
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008860/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008861 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8862 * @hdd_ctx: HDD context
8863 *
8864 * Pre configurations to be done at lower layer before calling cds enable.
8865 *
8866 * Return: 0 on success and errno on failure.
8867 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008868static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008869{
8870 int ret;
8871 QDF_STATUS status;
8872 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008873 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008874
Leo Changfdb45c32016-10-28 11:09:23 -07008875 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008876 /*
8877 * Set 802.11p config
8878 * TODO-OCB: This has been temporarily added here to ensure this
8879 * parameter is set in CSR when we init the channel list. This should
8880 * be removed once the 5.9 GHz channels are added to the regulatory
8881 * domain.
8882 */
8883 hdd_set_dot11p_config(hdd_ctx);
8884
8885 /*
8886 * Note that the cds_pre_enable() sequence triggers the cfg download.
8887 * The cfg download must occur before we update the SME config
8888 * since the SME config operation must access the cfg database
8889 */
8890 status = hdd_set_sme_config(hdd_ctx);
8891
8892 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008893 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008894 ret = qdf_status_to_os_return(status);
8895 goto out;
8896 }
8897
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008898 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8899 if (QDF_STATUS_SUCCESS != status) {
8900 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8901 ret = qdf_status_to_os_return(status);
8902 goto out;
8903 }
8904
Naveen Rawat247a8682017-06-05 15:00:31 -07008905 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008906 hdd_ctx->config->tx_chain_mask_1ss,
8907 PDEV_CMD);
8908 if (0 != ret) {
8909 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8910 goto out;
8911 }
8912
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008913 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8914 if (ret)
8915 goto out;
8916
8917 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8918 if (ret)
8919 goto out;
8920
Jeff Johnson12a744b2017-04-04 08:19:37 -07008921 ret = hdd_set_ani_enabled(hdd_ctx);
8922 if (ret)
8923 goto out;
8924
Naveen Rawat247a8682017-06-05 15:00:31 -07008925 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008926 hdd_ctx->config->arp_ac_category,
8927 PDEV_CMD);
8928 if (0 != ret) {
8929 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8930 hdd_ctx->config->arp_ac_category, ret);
8931 goto out;
8932 }
8933
8934
Prashanth Bhatta07998752016-04-28 12:35:33 -07008935 status = hdd_set_sme_chan_list(hdd_ctx);
8936 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008937 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008938 ret = qdf_status_to_os_return(status);
8939 goto out;
8940 }
8941
8942 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008943 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008944 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008945 ret = -EINVAL;
8946 goto out;
8947 }
8948
Prashanth Bhatta07998752016-04-28 12:35:33 -07008949 /*
8950 * Set the MAC Address Currently this is used by HAL to add self sta.
8951 * Remove this once self sta is added as part of session open.
8952 */
8953 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8954 hdd_ctx->config->intfMacAddr[0].bytes,
8955 sizeof(hdd_ctx->config->intfMacAddr[0]));
8956
8957 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8958 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8959 hal_status, hal_status);
8960 ret = -EINVAL;
8961 goto out;
8962 }
8963
8964 hdd_init_channel_avoidance(hdd_ctx);
8965
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308966 /* update enable sap mandatory chan list */
8967 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8968 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008969out:
8970 return ret;
8971}
8972
8973/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008974 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8975 * @context_ptr - hdd context pointer
8976 * @event_ptr - event structure pointer
8977 *
8978 * This is the p2p listen offload stop event handler, it sends vendor
8979 * event back to supplicant to notify the stop reason.
8980 *
8981 * Return: None
8982 */
8983static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8984 void *event_ptr)
8985{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008986 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008987 struct sir_p2p_lo_event *evt = event_ptr;
8988 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008989 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008990
8991 ENTER();
8992
8993 if (hdd_ctx == NULL) {
8994 hdd_err("Invalid HDD context pointer");
8995 return;
8996 }
8997
Peng Xu5c682812017-08-06 07:39:13 -07008998 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8999 if (!adapter) {
9000 hdd_err("Cannot find adapter by vdev_id = %d",
9001 evt->vdev_id);
9002 return;
9003 }
9004
Peng Xu8fdaa492016-06-22 10:20:47 -07009005 vendor_event =
9006 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009007 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009008 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9009 GFP_KERNEL);
9010
9011 if (!vendor_event) {
9012 hdd_err("cfg80211_vendor_event_alloc failed");
9013 return;
9014 }
9015
9016 if (nla_put_u32(vendor_event,
9017 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9018 evt->reason_code)) {
9019 hdd_err("nla put failed");
9020 kfree_skb(vendor_event);
9021 return;
9022 }
9023
9024 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009025 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9026 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009027}
9028
9029/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309030 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9031 * @hdd_ctx: HDD context
9032 *
9033 * This function sends the adaptive dwell time config configuration to the
9034 * firmware via WMA
9035 *
9036 * Return: 0 - success, < 0 - failure
9037 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009038static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309039{
9040 QDF_STATUS status;
9041 struct adaptive_dwelltime_params dwelltime_params;
9042
9043 dwelltime_params.is_enabled =
9044 hdd_ctx->config->adaptive_dwell_mode_enabled;
9045 dwelltime_params.dwelltime_mode =
9046 hdd_ctx->config->global_adapt_dwelltime_mode;
9047 dwelltime_params.lpf_weight =
9048 hdd_ctx->config->adapt_dwell_lpf_weight;
9049 dwelltime_params.passive_mon_intval =
9050 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9051 dwelltime_params.wifi_act_threshold =
9052 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9053
9054 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9055 &dwelltime_params);
9056
9057 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9058 if (!QDF_IS_STATUS_SUCCESS(status)) {
9059 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9060 return -EAGAIN;
9061 }
9062 return 0;
9063}
9064
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009065int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309066{
9067 QDF_STATUS status;
9068 struct wmi_dbs_scan_sel_params dbs_scan_params;
9069 uint32_t i = 0;
9070 uint8_t count = 0, numentries = 0;
9071 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9072 * CDS_DBS_SCAN_CLIENTS_MAX];
9073
9074 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009075 if (hdd_ctx->config->dual_mac_feature_disable ==
9076 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309077 return -EINVAL;
9078
9079 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9080 dbs_scan_config, &numentries,
9081 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9082 * CDS_DBS_SCAN_CLIENTS_MAX));
9083
9084 hdd_info("numentries %hu", numentries);
9085 if (!numentries) {
9086 hdd_info("Donot send scan_selection_config");
9087 return 0;
9088 }
9089
9090 /* hdd_set_fw_log_params */
9091 dbs_scan_params.num_clients = 0;
9092 while (count < (numentries - 2)) {
9093 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9094 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9095 dbs_scan_params.num_non_dbs_scans[i] =
9096 dbs_scan_config[count + 2];
9097 dbs_scan_params.num_clients++;
9098 hdd_debug("module:%d NDS:%d NNDS:%d",
9099 dbs_scan_params.module_id[i],
9100 dbs_scan_params.num_dbs_scans[i],
9101 dbs_scan_params.num_non_dbs_scans[i]);
9102 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9103 i++;
9104 }
9105
9106 dbs_scan_params.pdev_id = 0;
9107
9108 hdd_debug("clients:%d pdev:%d",
9109 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9110
9111 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9112 &dbs_scan_params);
9113 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9114 if (!QDF_IS_STATUS_SUCCESS(status)) {
9115 hdd_err("Failed to send DBS Scan selection configuration!");
9116 return -EAGAIN;
9117 }
9118 return 0;
9119}
9120
Arun Khandavallid4349a92016-07-25 11:10:43 +05309121#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9122/**
9123 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9124 * @hdd_ctx: HDD context
9125 *
9126 * Set auto shutdown callback to get indications from firmware to indicate
9127 * userspace to shutdown WLAN after a configured amount of inactivity.
9128 *
9129 * Return: 0 on success and errno on failure.
9130 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009131static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309132{
9133 QDF_STATUS status;
9134
9135 if (!hdd_ctx->config->WlanAutoShutdown)
9136 return 0;
9137
9138 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9139 wlan_hdd_auto_shutdown_cb);
9140 if (status != QDF_STATUS_SUCCESS)
9141 hdd_err("Auto shutdown feature could not be enabled: %d",
9142 status);
9143
9144 return qdf_status_to_os_return(status);
9145}
9146#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009147static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309148{
9149 return 0;
9150}
9151#endif
9152
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009153static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009154{
9155 QDF_STATUS status = QDF_STATUS_SUCCESS;
9156
9157 switch (hdd_ctx->config->dual_mac_feature_disable) {
9158 case DISABLE_DBS_CXN_AND_SCAN:
9159 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9160 if (status != QDF_STATUS_SUCCESS)
9161 hdd_err("Failed to disable dual mac features");
9162 break;
9163 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9164 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9165 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9166 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9167 if (status != QDF_STATUS_SUCCESS)
9168 hdd_err("Failed to set dbs scan and fw mode config");
9169 break;
9170 default:
9171 break;
9172 }
9173
9174 return status;
9175}
9176
Arun Khandavallid4349a92016-07-25 11:10:43 +05309177/**
9178 * hdd_features_init() - Init features
9179 * @hdd_ctx: HDD context
9180 * @adapter: Primary adapter context
9181 *
9182 * Initialize features and their feature context after WLAN firmware is up.
9183 *
9184 * Return: 0 on success and errno on failure.
9185 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009186static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309187{
9188 tSirTxPowerLimit hddtxlimit;
9189 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309190 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309191 int ret;
9192
9193 ENTER();
9194
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009195 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309196 if (ret) {
9197 hdd_err("Failed to update country code: %d", ret);
9198 goto out;
9199 }
9200
9201 /* FW capabilities received, Set the Dot11 mode */
9202 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009203 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9204 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309205
Arun Khandavallid4349a92016-07-25 11:10:43 +05309206
9207 if (hdd_ctx->config->fIsImpsEnabled)
9208 hdd_set_idle_ps_config(hdd_ctx, true);
9209 else
9210 hdd_set_idle_ps_config(hdd_ctx, false);
9211
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309212 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009213 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309214
Arun Khandavallid4349a92016-07-25 11:10:43 +05309215 if (hdd_lro_init(hdd_ctx))
9216 hdd_err("Unable to initialize LRO in fw");
9217
9218 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9219 hdd_err("Unable to send adaptive dwelltime setting to FW");
9220
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309221 if (hdd_dbs_scan_selection_init(hdd_ctx))
9222 hdd_err("Unable to send DBS scan selection setting to FW");
9223
Arun Khandavallid4349a92016-07-25 11:10:43 +05309224 ret = hdd_init_thermal_info(hdd_ctx);
9225 if (ret) {
9226 hdd_err("Error while initializing thermal information");
9227 goto deregister_frames;
9228 }
9229
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309230 if (cds_is_packet_log_enabled())
9231 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9232
Arun Khandavallid4349a92016-07-25 11:10:43 +05309233 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9234 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9235 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9236 if (!QDF_IS_STATUS_SUCCESS(status))
9237 hdd_err("Error setting txlimit in sme: %d", status);
9238
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009239 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309240
Arun Khandavallid4349a92016-07-25 11:10:43 +05309241 ret = hdd_register_cb(hdd_ctx);
9242 if (ret) {
9243 hdd_err("Failed to register HDD callbacks!");
9244 goto deregister_frames;
9245 }
9246
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009247 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9248 if (!QDF_IS_STATUS_SUCCESS(status)) {
9249 hdd_err("Failed to set dbs scan and fw mode cfg");
9250 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309251 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009252
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309253 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9254 status = sme_enable_disable_chanavoidind_event(
9255 hdd_ctx->hHal, 0);
9256 if (!QDF_IS_STATUS_SUCCESS(status)) {
9257 hdd_err("Failed to disable Chan Avoidance Indication");
9258 goto deregister_cb;
9259 }
9260 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309261
Manjeet Singha9cae432017-02-28 11:58:22 +05309262 if (hdd_ctx->config->enable_5g_band_pref) {
9263 band_pref_params.rssi_boost_threshold_5g =
9264 hdd_ctx->config->rssi_boost_threshold_5g;
9265 band_pref_params.rssi_boost_factor_5g =
9266 hdd_ctx->config->rssi_boost_factor_5g;
9267 band_pref_params.max_rssi_boost_5g =
9268 hdd_ctx->config->max_rssi_boost_5g;
9269 band_pref_params.rssi_penalize_threshold_5g =
9270 hdd_ctx->config->rssi_penalize_threshold_5g;
9271 band_pref_params.rssi_penalize_factor_5g =
9272 hdd_ctx->config->rssi_penalize_factor_5g;
9273 band_pref_params.max_rssi_penalize_5g =
9274 hdd_ctx->config->max_rssi_penalize_5g;
9275 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9276 }
9277
Arun Khandavallid4349a92016-07-25 11:10:43 +05309278 /* register P2P Listen Offload event callback */
9279 if (wma_is_p2p_lo_capable())
9280 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9281 wlan_hdd_p2p_lo_event_callback);
9282
9283 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9284
9285 if (ret)
9286 goto deregister_cb;
9287
9288 EXIT();
9289 return 0;
9290
9291deregister_cb:
9292 hdd_deregister_cb(hdd_ctx);
9293deregister_frames:
9294 wlan_hdd_cfg80211_deregister_frames(adapter);
9295out:
9296 return -EINVAL;
9297
9298}
9299
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009300/**
9301 * hdd_features_deinit() - Deinit features
9302 * @hdd_ctx: HDD context
9303 *
9304 * De-Initialize features and their feature context.
9305 *
9306 * Return: none.
9307 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009308static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009309{
9310 wlan_hdd_tsf_deinit(hdd_ctx);
9311}
9312
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309313/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009314 * hdd_register_bcn_cb() - register scan beacon callback
9315 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309316 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009317 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309318 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009319static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309320{
9321 QDF_STATUS status;
9322
9323 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9324 wlan_cfg80211_inform_bss_frame,
9325 SCAN_CB_TYPE_INFORM_BCN);
9326 if (!QDF_IS_STATUS_SUCCESS(status)) {
9327 hdd_err("failed with status code %08d [x%08x]",
9328 status, status);
9329 return status;
9330 }
9331
9332 return QDF_STATUS_SUCCESS;
9333}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309334
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309335/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309336 * hdd_configure_cds() - Configure cds modules
9337 * @hdd_ctx: HDD context
9338 * @adapter: Primary adapter context
9339 *
9340 * Enable Cds modules after WLAN firmware is up.
9341 *
9342 * Return: 0 on success and errno on failure.
9343 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009344int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309345{
9346 int ret;
9347 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309348 int set_value;
9349 uint32_t num_abg_tx_chains = 0;
9350 uint32_t num_11b_tx_chains = 0;
9351 uint32_t num_11ag_tx_chains = 0;
9352
9353 if (hdd_ctx->config->sifs_burst_duration) {
9354 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9355 hdd_ctx->config->sifs_burst_duration;
9356
9357 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9358 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9359 set_value, PDEV_CMD);
9360 }
9361
9362 if (hdd_ctx->config->is_force_1x1)
9363 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9364 1, PDEV_CMD);
9365 /* set chip power save failure detected callback */
9366 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9367 hdd_chip_pwr_save_fail_detected_cb);
9368
9369 if (hdd_ctx->config->max_mpdus_inampdu) {
9370 set_value = hdd_ctx->config->max_mpdus_inampdu;
9371 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9372 set_value, PDEV_CMD);
9373 }
9374
9375 if (hdd_ctx->config->enable_rts_sifsbursting) {
9376 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9377 sme_cli_set_command(0,
9378 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9379 set_value, PDEV_CMD);
9380 }
9381
9382 if (hdd_ctx->config->sap_get_peer_info) {
9383 set_value = hdd_ctx->config->sap_get_peer_info;
9384 sme_cli_set_command(0,
9385 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9386 set_value, PDEV_CMD);
9387 }
9388
9389 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9390 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9391 if (!hdd_ctx->config->enable2x2) {
9392 if (num_11b_tx_chains > 1)
9393 num_11b_tx_chains = 1;
9394 if (num_11ag_tx_chains > 1)
9395 num_11ag_tx_chains = 1;
9396 }
9397 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9398 num_11b_tx_chains);
9399 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9400 num_11ag_tx_chains);
9401 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9402 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309403
9404 ret = hdd_pre_enable_configure(hdd_ctx);
9405 if (ret) {
9406 hdd_err("Failed to pre-configure cds");
9407 goto out;
9408 }
9409
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009410 /* Always get latest IPA resources allocated from cds_open and configure
9411 * IPA module before configuring them to FW. Sequence required as crash
9412 * observed otherwise.
9413 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009414 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9415 hdd_err("Failed to setup pipes");
9416 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009417 }
9418
Arun Khandavallifae92942016-08-01 13:31:08 +05309419 /*
9420 * Start CDS which starts up the SME/MAC/HAL modules and everything
9421 * else
9422 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009423 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309424
9425 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009426 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309427 goto out;
9428 }
9429
9430 status = hdd_post_cds_enable_config(hdd_ctx);
9431 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009432 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009433 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309434 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309435 status = hdd_register_bcn_cb(hdd_ctx);
9436 if (!QDF_IS_STATUS_SUCCESS(status)) {
9437 hdd_alert("hdd_post_cds_enable_config failed");
9438 goto cds_disable;
9439 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309440
9441 ret = hdd_features_init(hdd_ctx, adapter);
9442 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009443 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309444
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309445 if (hdd_enable_egap(hdd_ctx))
9446 hdd_debug("enhance green ap is not enabled");
9447
Nachiket Kukadedd302662017-07-13 17:31:44 +05309448 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9449 hdd_debug("Failed to set wow pulse");
9450
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309451 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9452 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9453
Arun Khandavallifae92942016-08-01 13:31:08 +05309454 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009455
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009456cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009457 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009458
Arun Khandavallifae92942016-08-01 13:31:08 +05309459out:
9460 return -EINVAL;
9461}
9462
9463/**
9464 * hdd_deconfigure_cds() -De-Configure cds
9465 * @hdd_ctx: HDD context
9466 *
9467 * Deconfigure Cds modules before WLAN firmware is down.
9468 *
9469 * Return: 0 on success and errno on failure.
9470 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009471static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309472{
9473 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009474 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309475
9476 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009477
9478 /* De-init features */
9479 hdd_features_deinit(hdd_ctx);
9480
Arun Khandavallifae92942016-08-01 13:31:08 +05309481 /* De-register the SME callbacks */
9482 hdd_deregister_cb(hdd_ctx);
9483
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009484 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309485 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9486 hdd_err("Failed to Disable the CDS Modules! :%d",
9487 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009488 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309489 }
9490
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309491 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9492 hdd_err("Failed to disconnect pipes");
9493 ret = -EINVAL;
9494 }
9495
Arun Khandavallifae92942016-08-01 13:31:08 +05309496 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009497 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309498}
9499
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009500#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9501static void hdd_deregister_policy_manager_callback(
9502 struct wlan_objmgr_psoc *psoc)
9503{
9504 if (QDF_STATUS_SUCCESS !=
9505 policy_mgr_deregister_hdd_cb(psoc)) {
9506 hdd_err("HDD callback deregister with policy manager failed");
9507 }
9508}
9509#else
9510static void hdd_deregister_policy_manager_callback(
9511 struct wlan_objmgr_psoc *psoc)
9512{
9513}
9514#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309515
9516/**
9517 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9518 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009519 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309520 *
9521 * This function maintains the driver state machine it will be invoked from
9522 * exit, shutdown and con_mode change handler. Depending on the driver state
9523 * shall perform the stopping/closing of the modules.
9524 *
9525 * Return: 0 for success; non-zero for failure
9526 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009527int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309528{
9529 void *hif_ctx;
9530 qdf_device_t qdf_ctx;
9531 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309532 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009533 bool is_idle_stop = !cds_is_driver_unloading() &&
9534 !cds_is_driver_recovering();
9535 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309536
9537 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009538 hdd_alert("stop WLAN module: entering driver status=%d",
9539 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309540
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009541 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9542
Arun Khandavallifae92942016-08-01 13:31:08 +05309543 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9544 if (!qdf_ctx) {
9545 hdd_err("QDF device context NULL");
9546 return -EINVAL;
9547 }
9548
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309549 mutex_lock(&hdd_ctx->iface_change_lock);
9550 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309551
Dustin Brown70111822017-03-30 15:31:40 -07009552 active_threads = cds_return_external_threads_count();
9553 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009554 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009555 active_threads, hdd_ctx->isWiphySuspended);
9556
9557 cds_print_external_threads();
9558
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009559 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009560 mutex_unlock(&hdd_ctx->iface_change_lock);
9561 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009562 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309563 hdd_prevent_suspend_timeout(
9564 hdd_ctx->config->iface_change_wait_time,
9565 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009566 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009567 return 0;
9568 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009569 }
9570
Arun Khandavallifae92942016-08-01 13:31:08 +05309571 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9572
9573 switch (hdd_ctx->driver_status) {
9574 case DRIVER_MODULES_UNINITIALIZED:
9575 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309576 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309577 case DRIVER_MODULES_CLOSED:
9578 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309579 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309580 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309581 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309582 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009583 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309584 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309585 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309586 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009587 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309588 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9589 break;
9590 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009591 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309592 break;
9593 default:
9594 hdd_err("Trying to stop wlan in a wrong state: %d",
9595 hdd_ctx->driver_status);
9596 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309597 ret = -EINVAL;
9598 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309599 }
9600
Rajeev Kumarbe021242017-02-16 16:12:23 -08009601 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309602 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9603 hdd_err("Failed to process post CDS disable Modules! :%d",
9604 qdf_status);
9605 ret = -EINVAL;
9606 QDF_ASSERT(0);
9607 }
Jeff Johnsone4b14592017-09-13 14:23:33 -07009608 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309609 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009610 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309611 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309612 QDF_ASSERT(0);
9613 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009614
Arun Khandavallifae92942016-08-01 13:31:08 +05309615 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9616 if (!hif_ctx) {
9617 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309618 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309619 }
9620
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309621 hdd_runtime_suspend_context_deinit(hdd_ctx);
9622
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309623 if (hdd_ctx->target_hw_name) {
9624 qdf_mem_free(hdd_ctx->target_hw_name);
9625 hdd_ctx->target_hw_name = NULL;
9626 }
9627
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309628 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309629
9630 ol_cds_free();
9631
Dustin Brown70111822017-03-30 15:31:40 -07009632 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309633 ret = pld_power_off(qdf_ctx->dev);
9634 if (ret)
9635 hdd_err("CNSS power down failed put device into Low power mode:%d",
9636 ret);
9637 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309638
9639 /* Once the firmware sequence is completed reset this flag */
9640 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309641 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009642 /*
9643 * Reset total mac phy during module stop such that during
9644 * next module start same psoc is used to populate new service
9645 * ready data
9646 */
9647 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309648
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309649done:
9650 hdd_ctx->stop_modules_in_progress = false;
9651 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07009652 hdd_alert("stop WLAN module: exit driver status=%d",
9653 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309654 EXIT();
9655
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309656 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309657
9658}
9659
9660/**
9661 * hdd_iface_change_callback() - Function invoked when stop modules expires
9662 * @priv: pointer to hdd context
9663 *
9664 * This function is invoked when the timer waiting for the interface change
9665 * expires, it shall cut-down the power to wlan and stop all the modules.
9666 *
9667 * Return: void
9668 */
9669static void hdd_iface_change_callback(void *priv)
9670{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009671 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309672 int ret;
9673 int status = wlan_hdd_validate_context(hdd_ctx);
9674
9675 if (status)
9676 return;
9677
9678 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009679 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009680 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309681 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009682 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309683 EXIT();
9684}
9685
9686/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309687 * hdd_state_info_dump() - prints state information of hdd layer
9688 * @buf: buffer pointer
9689 * @size: size of buffer to be filled
9690 *
9691 * This function is used to dump state information of hdd layer
9692 *
9693 * Return: None
9694 */
9695static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9696{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009697 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309698 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9699 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009700 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009701 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309702 uint16_t len = 0;
9703 char *buf = *buf_ptr;
9704
9705 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9706 if (!hdd_ctx) {
9707 hdd_err("Failed to get hdd context ");
9708 return;
9709 }
9710
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009711 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309712
9713 len += scnprintf(buf + len, *size - len,
9714 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9715 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009716 "\n is_scheduler_suspended %d",
9717 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309718
9719 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9720
9721 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009722 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309723 if (adapter->dev)
9724 len += scnprintf(buf + len, *size - len,
9725 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009726 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309727 "\n device_mode: %d", adapter->device_mode);
9728 switch (adapter->device_mode) {
9729 case QDF_STA_MODE:
9730 case QDF_P2P_CLIENT_MODE:
9731 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9732 len += scnprintf(buf + len, *size - len,
9733 "\n connState: %d",
9734 hdd_sta_ctx->conn_info.connState);
9735 break;
9736
9737 default:
9738 break;
9739 }
9740 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9741 adapter_node = next;
9742 }
9743
9744 *size -= len;
9745 *buf_ptr += len;
9746}
9747
9748/**
9749 * hdd_register_debug_callback() - registration function for hdd layer
9750 * to print hdd state information
9751 *
9752 * Return: None
9753 */
9754static void hdd_register_debug_callback(void)
9755{
9756 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9757}
9758
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309759/*
9760 * wlan_init_bug_report_lock() - Initialize bug report lock
9761 *
9762 * This function is used to create bug report lock
9763 *
9764 * Return: None
9765 */
9766static void wlan_init_bug_report_lock(void)
9767{
9768 p_cds_contextType p_cds_context;
9769
9770 p_cds_context = cds_get_global_context();
9771 if (!p_cds_context) {
9772 hdd_err("cds context is NULL");
9773 return;
9774 }
9775
9776 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9777}
9778
Mohit Khannaf8f96822017-05-17 17:11:59 -07009779void hdd_dp_trace_init(struct hdd_config *config)
9780{
9781
9782 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9783 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9784 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9785 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9786 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9787 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9788 uint8_t num_entries = 0;
9789
9790 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9791 &num_entries, sizeof(config_params));
9792
9793 /* calculating, num bw timer intervals in a second (1000ms) */
9794 if (config->busBandwidthComputeInterval)
9795 thresh_time_limit =
9796 (1000 / config->busBandwidthComputeInterval);
9797 else
9798 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9799
9800 switch (num_entries) {
9801 case 4:
9802 proto_bitmap = config_params[3];
9803 case 3:
9804 verbosity = config_params[2];
9805 case 2:
9806 thresh = config_params[1];
9807 case 1:
9808 live_mode = config_params[0];
9809 default:
9810 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9811 live_mode, thresh, thresh_time_limit,
9812 verbosity, proto_bitmap);
9813 };
9814
9815 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9816 verbosity, proto_bitmap);
9817
9818}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309819/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009820 * hdd_wlan_startup() - HDD init function
9821 * @dev: Pointer to the underlying device
9822 *
9823 * This is the driver startup code executed once a WLAN device has been detected
9824 *
9825 * Return: 0 for success, < 0 for failure
9826 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309827int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009828{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309829 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009830 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009831 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009832 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009833
9834 ENTER();
9835
Arun Khandavallifae92942016-08-01 13:31:08 +05309836 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009837
9838 if (IS_ERR(hdd_ctx))
9839 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009840
Abhishek Singhe9068f12017-03-31 14:14:52 +05309841 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9842 DEFAULT_PSOC_ID);
9843 if (ret) {
9844 hdd_err("Psoc creation fails!");
9845 QDF_BUG(0);
9846 goto err_hdd_free_context;
9847 }
9848
Arun Khandavallifae92942016-08-01 13:31:08 +05309849 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9850 hdd_iface_change_callback, (void *)hdd_ctx);
9851
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309852 qdf_nbuf_init_replenish_timer();
9853
Arun Khandavallifae92942016-08-01 13:31:08 +05309854 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309855#ifdef FEATURE_WLAN_CH_AVOID
9856 mutex_init(&hdd_ctx->avoid_freq_lock);
9857#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309858
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009859 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009860 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309861
Jeff Johnson957bc272017-02-02 08:54:48 -08009862 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309863 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009864 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009865 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009866 }
9867
Yingying Tang80e15f32016-09-27 18:23:01 +08009868 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009869
Anurag Chouhan6d760662016-02-20 16:05:43 +05309870 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009871
9872 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009873 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309874 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009875 }
9876
Prashanth Bhatta07998752016-04-28 12:35:33 -07009877 ret = hdd_wiphy_init(hdd_ctx);
9878 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009879 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309880 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009881 }
9882
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309883 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009884 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309885
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309886 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009887 goto err_wiphy_unregister;
9888
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309889 wlan_hdd_init_chan_info(hdd_ctx);
9890
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009891 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009892
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309893 ret = hdd_register_notifiers(hdd_ctx);
9894 if (ret)
9895 goto err_ipa_cleanup;
9896
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009897 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009898
Jeff Johnson957bc272017-02-02 08:54:48 -08009899 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9900 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009901 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009902 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009903 }
9904
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009905 hdd_release_rtnl_lock();
9906 rtnl_held = false;
9907
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009908 wlan_hdd_update_11n_mode(hdd_ctx->config);
9909
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009910#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309911 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309912 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009913 hdd_skip_acs_scan_timer_handler,
9914 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309915 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009916 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009917 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009918#endif
9919
Prashanth Bhattaab004382016-10-11 16:08:11 -07009920 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009921
Jeff Johnson9afc5012016-09-23 13:56:27 -07009922 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009923
Nirav Shahbd36b062016-07-18 11:12:59 +05309924 if (hdd_ctx->rps)
9925 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009926
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309927 status = wlansap_global_init();
9928 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009929 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009930
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009931 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309932 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009933
Arun Khandavallifae92942016-08-01 13:31:08 +05309934 if (hdd_ctx->config->fIsImpsEnabled)
9935 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309936
Mukul Sharma07bd8752017-10-10 16:58:14 +05309937 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309938 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309939 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309940 hdd_prevent_suspend_timeout(
9941 hdd_ctx->config->iface_change_wait_time,
9942 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
9943 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309944
Sachin Ahujadddd2632017-03-07 19:07:24 +05309945 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009946 goto success;
9947
Jeff Johnson957bc272017-02-02 08:54:48 -08009948err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009949 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009950
Jeff Johnson46bde382017-02-01 15:31:16 -08009951err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309952 if (rtnl_held)
9953 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009954
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309955 unregister_netdevice_notifier(&hdd_netdev_notifier);
9956
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309957err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309958 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009959
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009960err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009961 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009962
Arun Khandavallifae92942016-08-01 13:31:08 +05309963err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009964 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309965
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009966err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309967 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009968 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309969 if (!QDF_IS_STATUS_SUCCESS(status)) {
9970 hdd_err("Failed to close CDS Scheduler");
9971 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9972 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009973 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009974
Houston Hoffman47a4a052016-11-14 23:22:44 -08009975 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009976 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009977 hdd_exit_netlink_services(hdd_ctx);
9978
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309979 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009980
Dustin Brown20912462017-06-07 13:48:25 -07009981 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9982
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009983err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309984 if (cds_is_fw_down())
9985 hdd_err("Not setting the complete event as fw is down");
9986 else
9987 hdd_start_complete(ret);
9988
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309989 qdf_nbuf_deinit_replenish_timer();
Arun Khandavallifae92942016-08-01 13:31:08 +05309990 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9991 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009992 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009993 return -EIO;
9994
9995success:
9996 EXIT();
9997 return 0;
9998}
9999
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010000/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010001 * hdd_wlan_update_target_info() - update target type info
10002 * @hdd_ctx: HDD context
10003 * @context: hif context
10004 *
10005 * Update target info received from firmware in hdd context
10006 * Return:None
10007 */
10008
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010009void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010010{
10011 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10012
10013 if (!tgt_info) {
10014 hdd_err("Target info is Null");
10015 return;
10016 }
10017
10018 hdd_ctx->target_type = tgt_info->target_type;
10019}
10020
10021/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010022 * hdd_get_nud_stats_cb() - callback api to update the stats
10023 * received from the firmware
10024 * @data: pointer to adapter.
10025 * @rsp: pointer to data received from FW.
10026 *
10027 * This is called when wlan driver received response event for
10028 * get arp stats to firmware.
10029 *
10030 * Return: None
10031 */
10032static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10033{
10034 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10035 struct hdd_nud_stats_context *context;
10036 int status;
10037 struct hdd_adapter *adapter = NULL;
10038
10039 ENTER();
10040
10041 if (!rsp) {
10042 hdd_err("data is null");
10043 return;
10044 }
10045
10046 status = wlan_hdd_validate_context(hdd_ctx);
10047 if (0 != status)
10048 return;
10049
10050 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10051 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10052 hdd_err("Invalid adapter or adapter has invalid magic");
10053 return;
10054 }
10055
10056 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10057 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10058 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10059 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10060 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10061 rsp->out_of_order_arp_rsp_drop_cnt);
10062 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10063 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10064 hdd_notice("rsp->ba_session_establishment_status :%x",
10065 rsp->ba_session_establishment_status);
10066
10067 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10068 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10069 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10070 adapter->dad |= rsp->dad_detected;
10071 adapter->con_status = rsp->connect_status;
10072
10073 spin_lock(&hdd_context_lock);
10074 context = &hdd_ctx->nud_stats_context;
10075 complete(&context->response_event);
10076 spin_unlock(&hdd_context_lock);
10077
10078 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010079}
10080
10081/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010082 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010083 * @hdd_ctx: HDD context
10084 *
10085 * Register the HDD callbacks to CDS/SME.
10086 *
10087 * Return: 0 for success or Error code for failure
10088 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010089int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010090{
10091 QDF_STATUS status;
10092 int ret = 0;
10093
10094 ENTER();
10095
10096 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10097
10098 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10099 hdd_send_oem_data_rsp_msg);
10100
10101 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10102 wlan_hdd_cfg80211_fw_mem_dump_cb);
10103 if (!QDF_IS_STATUS_SUCCESS(status)) {
10104 hdd_err("Failed to register memdump callback");
10105 ret = -EINVAL;
10106 return ret;
10107 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010108 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10109 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010110 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10111 sme_nan_register_callback(hdd_ctx->hHal,
10112 wlan_hdd_cfg80211_nan_callback);
10113 sme_stats_ext_register_callback(hdd_ctx->hHal,
10114 wlan_hdd_cfg80211_stats_ext_callback);
10115
10116 sme_ext_scan_register_callback(hdd_ctx->hHal,
10117 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010118 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10119 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010120
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010121 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10122 hdd_rssi_threshold_breached);
10123
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010124 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10125
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010126 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10127 wlan_hdd_cfg80211_link_layer_stats_callback);
10128
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010129 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10130
Zhang Qianca38fb12016-12-23 11:10:48 +080010131 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10132 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10133
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010134 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10135 hdd_lost_link_info_cb);
10136 /* print error and not block the startup process */
10137 if (!QDF_IS_STATUS_SUCCESS(status))
10138 hdd_err("set lost link info callback failed");
10139
Poddar, Siddarth34872782017-08-10 14:08:51 +053010140 ret = hdd_register_data_stall_detect_cb();
10141 if (ret) {
10142 hdd_err("Register data stall detect detect callback failed.");
10143 return ret;
10144 }
10145
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010146 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10147
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010148 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010149 hdd_set_connection_in_progress,
10150 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010151
10152 status = sme_congestion_register_callback(hdd_ctx->hHal,
10153 hdd_update_cca_info_cb);
10154 if (!QDF_IS_STATUS_SUCCESS(status))
10155 hdd_err("set congestion callback failed");
10156
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010157 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10158 hdd_bt_activity_cb);
10159 if (!QDF_IS_STATUS_SUCCESS(status))
10160 hdd_err("set bt activity info callback failed");
10161
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010162 EXIT();
10163
10164 return ret;
10165}
10166
10167/**
10168 * hdd_deregister_cb() - De-Register HDD callbacks.
10169 * @hdd_ctx: HDD context
10170 *
10171 * De-Register the HDD callbacks to CDS/SME.
10172 *
10173 * Return: void
10174 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010175void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010176{
10177 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010178 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010179
10180 ENTER();
10181
10182 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10183 if (!QDF_IS_STATUS_SUCCESS(status))
10184 hdd_err("De-register of dcc stats callback failed: %d",
10185 status);
10186
10187 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010188 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10189
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010190 sme_stats_ext_register_callback(hdd_ctx->hHal,
10191 wlan_hdd_cfg80211_stats_ext_callback);
10192
10193 sme_nan_deregister_callback(hdd_ctx->hHal);
10194 status = sme_reset_tsfcb(hdd_ctx->hHal);
10195 if (!QDF_IS_STATUS_SUCCESS(status))
10196 hdd_err("Failed to de-register tsfcb the callback:%d",
10197 status);
10198 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10199 if (!QDF_IS_STATUS_SUCCESS(status))
10200 hdd_err("Failed to de-register the fw mem dump callback: %d",
10201 status);
10202
Poddar, Siddarth34872782017-08-10 14:08:51 +053010203 ret = hdd_deregister_data_stall_detect_cb();
10204 if (ret)
10205 hdd_err("Failed to de-register data stall detect event callback");
10206
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010207 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10208 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10209
10210 EXIT();
10211}
10212
10213/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010214 * hdd_softap_sta_deauth() - handle deauth req from HDD
10215 * @adapter: Pointer to the HDD
10216 * @enable: bool value
10217 *
10218 * This to take counter measure to handle deauth req from HDD
10219 *
10220 * Return: None
10221 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010222QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010223 struct tagCsrDelStaParams *pDelStaParams)
10224{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010225 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010226
10227 ENTER();
10228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010229 /* Ignore request to deauth bcmc station */
10230 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010231 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010232
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010233 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010234 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10235 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010236
10237 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010238 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010239}
10240
10241/**
10242 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10243 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010244 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010245 *
10246 * This to take counter measure to handle deauth req from HDD
10247 *
10248 * Return: None
10249 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010250void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010251 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010252{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010253 ENTER();
10254
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010255 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010256 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010257 return;
10258
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010259 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010260 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010261}
10262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010263/**
10264 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10265 * @hdd_ctx: HDD Context
10266 *
10267 * API to find if there is any STA or P2P-Client is connected
10268 *
10269 * Return: true if connected; false otherwise
10270 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010271QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010272{
10273 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10274}
10275
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010276/**
10277 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10278 * @adapter: HDD adapter pointer
10279 *
10280 * This function loop through each adapter and disable roaming on each STA
10281 * device mode except the input adapter.
10282 *
10283 * Note: On the input adapter roaming is not enabled yet hence no need to
10284 * disable.
10285 *
10286 * Return: None
10287 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010288void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010289{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010290 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010291 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010292 hdd_adapter_list_node_t *adapterNode = NULL;
10293 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010294 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010295
10296 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010297 hdd_ctx->config->isRoamOffloadScanEnabled &&
10298 QDF_STA_MODE == adapter->device_mode &&
10299 policy_mgr_is_sta_active_connection_exists(
10300 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010301 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010302 adapter->sessionId);
10303 /*
10304 * Loop through adapter and disable roaming for each STA device
10305 * mode except the input adapter.
10306 */
10307 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10308
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010309 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010310 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010311
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010312 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010313 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010314 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010315 adapterIdx->sessionId);
10316 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10317 (adapterIdx),
10318 adapterIdx->sessionId, 0);
10319 }
10320
10321 status = hdd_get_next_adapter(hdd_ctx,
10322 adapterNode,
10323 &pNext);
10324 adapterNode = pNext;
10325 }
10326 }
10327}
10328
10329/**
10330 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10331 * @adapter: HDD adapter pointer
10332 *
10333 * This function loop through each adapter and enable roaming on each STA
10334 * device mode except the input adapter.
10335 * Note: On the input adapter no need to enable roaming because link got
10336 * disconnected on this.
10337 *
10338 * Return: None
10339 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010340void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010341{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010342 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010343 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010344 hdd_adapter_list_node_t *adapterNode = NULL;
10345 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010346 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010347
10348 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010349 hdd_ctx->config->isRoamOffloadScanEnabled &&
10350 QDF_STA_MODE == adapter->device_mode &&
10351 policy_mgr_is_sta_active_connection_exists(
10352 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010353 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010354 adapter->sessionId);
10355 /*
10356 * Loop through adapter and enable roaming for each STA device
10357 * mode except the input adapter.
10358 */
10359 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10360
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010361 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010362 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010363
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010364 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010365 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010366 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010367 adapterIdx->sessionId);
10368 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10369 (adapterIdx),
10370 adapterIdx->sessionId,
10371 REASON_CONNECT);
10372 }
10373
10374 status = hdd_get_next_adapter(hdd_ctx,
10375 adapterNode,
10376 &pNext);
10377 adapterNode = pNext;
10378 }
10379 }
10380}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010381
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010382/**
10383 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10384 * @skb: sk buffer pointer
10385 *
10386 * Sends the bcast message to SVC multicast group with generic nl socket
10387 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10388 *
10389 * Return: None
10390 */
10391static void nl_srv_bcast_svc(struct sk_buff *skb)
10392{
10393#ifdef CNSS_GENL
10394 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10395#else
10396 nl_srv_bcast(skb);
10397#endif
10398}
10399
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010400void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010401{
10402 struct sk_buff *skb;
10403 struct nlmsghdr *nlh;
10404 tAniMsgHdr *ani_hdr;
10405 void *nl_data = NULL;
10406 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010407 struct radio_index_tlv *radio_info;
10408 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010409
10410 if (in_interrupt() || irqs_disabled() || in_atomic())
10411 flags = GFP_ATOMIC;
10412
10413 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10414
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010415 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010416 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010417
10418 nlh = (struct nlmsghdr *)skb->data;
10419 nlh->nlmsg_pid = 0; /* from kernel */
10420 nlh->nlmsg_flags = 0;
10421 nlh->nlmsg_seq = 0;
10422 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10423
10424 ani_hdr = NLMSG_DATA(nlh);
10425 ani_hdr->type = type;
10426
10427 switch (type) {
10428 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010429 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010430 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010431 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010432 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010433 ani_hdr->length = 0;
10434 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010435 break;
10436 case WLAN_SVC_WLAN_STATUS_IND:
10437 case WLAN_SVC_WLAN_VERSION_IND:
10438 case WLAN_SVC_DFS_CAC_START_IND:
10439 case WLAN_SVC_DFS_CAC_END_IND:
10440 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10441 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10442 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010443 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010444 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010445 ani_hdr->length = len;
10446 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10447 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10448 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010449 break;
10450
10451 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010452 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010453 type);
10454 kfree_skb(skb);
10455 return;
10456 }
10457
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010458 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010459 * Add radio index at the end of the svc event in TLV format
10460 * to maintain the backward compatibility with userspace
10461 * applications.
10462 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010463
10464 tlv_len = 0;
10465
10466 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10467 < WLAN_NL_MAX_PAYLOAD) {
10468 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10469 sizeof(*ani_hdr) + len);
10470 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10471 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10472 radio_info->radio = radio;
10473 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010474 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010475 "Added radio index tlv - radio index %d",
10476 radio_info->radio);
10477 }
10478
10479 nlh->nlmsg_len += tlv_len;
10480 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10481
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010482 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010483}
10484
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010485#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10486void wlan_hdd_auto_shutdown_cb(void)
10487{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010488 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010489
10490 if (!hdd_ctx)
10491 return;
10492
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010493 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010494 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10495 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010496}
10497
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010498void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010499{
10500 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010501 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010502 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010503 bool ap_connected = false, sta_connected = false;
10504 tHalHandle hal_handle;
10505
10506 hal_handle = hdd_ctx->hHal;
10507 if (hal_handle == NULL)
10508 return;
10509
10510 if (hdd_ctx->config->WlanAutoShutdown == 0)
10511 return;
10512
10513 if (enable == false) {
10514 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010515 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010516 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010517 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010518 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010519 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010520 return;
10521 }
10522
10523 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010524 if (policy_mgr_concurrent_open_sessions_running(
10525 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010526 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10527
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010528 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010529 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010530 if (adapter
10531 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010532 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010533 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10534 conn_info.connState ==
10535 eConnectionState_Associated) {
10536 sta_connected = true;
10537 break;
10538 }
10539 }
10540 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010541 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010542 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10543 bApActive == true) {
10544 ap_connected = true;
10545 break;
10546 }
10547 }
10548 status = hdd_get_next_adapter(hdd_ctx,
10549 adapterNode,
10550 &pNext);
10551 adapterNode = pNext;
10552 }
10553 }
10554
10555 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010556 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010557 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010558 }
Jeff Johnson68755312017-02-10 11:46:55 -080010559
10560 if (sme_set_auto_shutdown_timer(hal_handle,
10561 hdd_ctx->config->WlanAutoShutdown)
10562 != QDF_STATUS_SUCCESS)
10563 hdd_err("Failed to start wlan auto shutdown timer");
10564 else
10565 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10566 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010567}
10568#endif
10569
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010570struct hdd_adapter *
10571hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10572 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010573{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010574 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010575 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010576 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010577 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10578
10579 con_sap_adapter = NULL;
10580
10581 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010582 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010583 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010584 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10585 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010586 adapter != this_sap_adapter) {
10587 if (check_start_bss) {
10588 if (test_bit(SOFTAP_BSS_STARTED,
10589 &adapter->event_flags)) {
10590 con_sap_adapter = adapter;
10591 break;
10592 }
10593 } else {
10594 con_sap_adapter = adapter;
10595 break;
10596 }
10597 }
10598 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10599 adapterNode = pNext;
10600 }
10601
10602 return con_sap_adapter;
10603}
10604
10605#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010606static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010607{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010608 return adapter->device_mode == QDF_STA_MODE ||
10609 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010610}
10611
Jeff Johnson9d295242017-08-29 14:39:48 -070010612static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010613{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010614 return adapter->device_mode == QDF_SAP_MODE ||
10615 adapter->device_mode == QDF_P2P_GO_MODE;
10616}
10617
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010618static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010619{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010620 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010621 hdd_adapter_list_node_t *node;
10622
10623 status = hdd_get_front_adapter(hdd_ctx, &node);
10624 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010625 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010626
10627 if (adapter &&
10628 hdd_adapter_is_sta(adapter) &&
10629 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10630 conn_info.connState == eConnectionState_Associated) {
10631 return true;
10632 }
10633
10634 if (adapter &&
10635 hdd_adapter_is_ap(adapter) &&
10636 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10637 return true;
10638 }
10639
10640 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10641 }
10642
10643 return false;
10644}
10645
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010646static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010647{
10648 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010649
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010650 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010651 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010652 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010653
Dustin Brown5ec6b552017-03-31 12:11:40 -070010654 return is_running;
10655}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010656
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010657static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010658{
10659 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10660 hdd_ctx->bus_bw_timer_running = true;
10661 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10662 hdd_ctx->config->busBandwidthComputeInterval);
10663 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10664}
10665
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010666void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010667{
10668 ENTER();
10669
10670 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10671 hdd_debug("Bandwidth compute timer already started");
10672 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010673 }
10674
Dustin Brown5ec6b552017-03-31 12:11:40 -070010675 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10676
10677 EXIT();
10678}
10679
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010680void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010681{
10682 ENTER();
10683
10684 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10685 hdd_debug("Bandwidth compute timer already started");
10686 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010687 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010688
10689 if (hdd_any_adapter_is_assoc(hdd_ctx))
10690 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10691
10692 EXIT();
10693}
10694
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010695static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010696{
10697 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10698
10699 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10700 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10701 hdd_ctx->bus_bw_timer_running = false;
10702 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10703
10704 hdd_reset_tcp_delack(hdd_ctx);
10705}
10706
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010707void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010708{
10709 ENTER();
10710
10711 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10712 hdd_debug("Bandwidth compute timer already stopped");
10713 return;
10714 }
10715
10716 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10717
10718 EXIT();
10719}
10720
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010721void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010722{
10723 ENTER();
10724
10725 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10726 hdd_debug("Bandwidth compute timer already stopped");
10727 return;
10728 }
10729
10730 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10731 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10732
10733 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010734}
10735#endif
10736
10737/**
10738 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10739 * and sta's operating channel.
10740 * @sta_adapter: Describe the first argument to foobar.
10741 * @ap_adapter: Describe the second argument to foobar.
10742 * @roam_profile: Roam profile of AP to which STA wants to connect.
10743 * @concurrent_chnl_same: If both SAP and STA channels are same then
10744 * set this flag to true else false.
10745 *
10746 * This function checks the sap's operating channel and sta's operating channel.
10747 * if both are same then it will return false else it will restart the sap in
10748 * sta's channel and return true.
10749 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010750 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010751 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010752QDF_STATUS
10753wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10754 struct hdd_adapter *ap_adapter,
10755 tCsrRoamProfile *roam_profile,
10756 tScanResultHandle *scan_cache,
10757 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010758{
Jeff Johnson87251032017-08-29 13:31:11 -070010759 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010760 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010761 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010762 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010763 *concurrent_chnl_same = true;
10764
10765 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10766 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010767 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010768 scan_cache,
10769 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010770 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010771 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010772 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10773 if (hdd_ap_ctx->operatingChannel != channel_id) {
10774 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010775 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010776 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010777 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010778 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10779 if (hdd_ap_ctx->operatingChannel != channel_id) {
10780 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010781 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010782 }
10783 }
10784 } else {
10785 /*
10786 * Lets handle worst case scenario here, Scan cache lookup is
10787 * failed so we have to stop the SAP to avoid any channel
10788 * discrepancy between SAP's channel and STA's channel.
10789 * Return the status as failure so caller function could know
10790 * that scan look up is failed.
10791 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010792 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010793 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010794 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010795 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010796}
10797
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010798/**
10799 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10800 * @ap_adapter: SAP adapter
10801 *
10802 * This function will process the stopping of sap adapter.
10803 *
10804 * Return: None
10805 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010806void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010807{
Jeff Johnson87251032017-08-29 13:31:11 -070010808 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010809 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010810 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010811 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010812
10813 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010814 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010815 return;
10816 }
10817
10818 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10819 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010820 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010821 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010822
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010823 mutex_lock(&hdd_ctx->sap_lock);
10824 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010825 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010826 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10827 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010828 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010829 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010830 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010831 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010832 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010833 qdf_stop_bss_event,
10834 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010835 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010836 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010837 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010838 return;
10839 }
10840 }
10841 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010842 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10843 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010844 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010845 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010846 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010847 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010848 }
10849 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010850}
10851
10852/**
10853 * wlan_hdd_start_sap() - this function starts bss of SAP.
10854 * @ap_adapter: SAP adapter
10855 *
10856 * This function will process the starting of sap adapter.
10857 *
10858 * Return: None
10859 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010860void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010861{
Jeff Johnson87251032017-08-29 13:31:11 -070010862 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010863 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010864 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010865 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010866 tsap_Config_t *sap_config;
10867
10868 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010869 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010870 return;
10871 }
10872
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010873 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010874 hdd_err("SoftAp role has not been enabled");
10875 return;
10876 }
10877
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010878 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10879 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10880 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10881 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10882
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010883 mutex_lock(&hdd_ctx->sap_lock);
10884 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10885 goto end;
10886
10887 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010888 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010889 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10890 goto end;
10891 }
10892
Wei Song2f76f642016-11-18 16:32:53 +080010893 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010894 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10895 &hdd_ap_ctx->sapConfig,
10896 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010897 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010898 goto end;
10899
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010900 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010901 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010902 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010903 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010904 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010905 goto end;
10906 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010907 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010908 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010909 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010910 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10911 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010912 ap_adapter->sessionId);
10913 hostapd_state->bCommit = true;
10914
10915end:
10916 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010917 /* SAP context and beacon cleanup will happen during driver unload
10918 * in hdd_stop_adapter
10919 */
10920 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10921
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010922}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010923
10924/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010925 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10926 * mac scan config
10927 * @status: Status of set antenna mode
10928 *
10929 * Callback on setting the dual mac configuration
10930 *
10931 * Return: None
10932 */
10933void wlan_hdd_soc_set_antenna_mode_cb(
10934 enum set_antenna_mode_status status)
10935{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010936 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010937
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010938 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010939
10940 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10941 if (0 != wlan_hdd_validate_context(hdd_ctx))
10942 return;
10943
10944 /* Signal the completion of set dual mac config */
10945 complete(&hdd_ctx->set_antenna_mode_cmpl);
10946}
10947
10948/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010949 * hdd_get_fw_version() - Get FW version
10950 * @hdd_ctx: pointer to HDD context.
10951 * @major_spid: FW version - major spid.
10952 * @minor_spid: FW version - minor spid
10953 * @ssid: FW version - ssid
10954 * @crmid: FW version - crmid
10955 *
10956 * This function is called to get the firmware build version stored
10957 * as part of the HDD context
10958 *
10959 * Return: None
10960 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010961void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010962 uint32_t *major_spid, uint32_t *minor_spid,
10963 uint32_t *siid, uint32_t *crmid)
10964{
10965 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10966 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10967 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10968 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10969}
10970
10971#ifdef QCA_CONFIG_SMP
10972/**
10973 * wlan_hdd_get_cpu() - get cpu_index
10974 *
10975 * Return: cpu_index
10976 */
10977int wlan_hdd_get_cpu(void)
10978{
10979 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010980
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010981 put_cpu();
10982 return cpu_index;
10983}
10984#endif
10985
10986/**
10987 * hdd_get_fwpath() - get framework path
10988 *
10989 * This function is used to get the string written by
10990 * userspace to start the wlan driver
10991 *
10992 * Return: string
10993 */
10994const char *hdd_get_fwpath(void)
10995{
10996 return fwpath.string;
10997}
10998
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010999static int hdd_qdf_print_init(void)
11000{
11001 int qdf_print_idx;
11002 QDF_STATUS status;
11003
11004 status = qdf_print_setup();
11005 if (status != QDF_STATUS_SUCCESS) {
11006 pr_err("qdf_print_setup failed\n");
11007 return -EINVAL;
11008 }
11009
11010 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11011
11012 if (qdf_print_idx < 0) {
11013 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11014 qdf_print_idx);
11015 return -EINVAL;
11016 }
11017
11018 qdf_set_pidx(qdf_print_idx);
11019
11020 return 0;
11021}
11022
11023static void hdd_qdf_print_deinit(void)
11024{
11025 int qdf_print_idx;
11026
11027 qdf_print_idx = qdf_get_pidx();
11028 qdf_print_ctrl_cleanup(qdf_print_idx);
11029}
11030
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011031/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011032 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011033 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011034 * This function initilizes CDS global context with the help of cds_init. This
11035 * has to be the first function called after probe to get a valid global
11036 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011037 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011038 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011039 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011040int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011041{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011042 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011043 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011044
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011045 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011046
11047 wlan_init_bug_report_lock();
11048
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011049#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11050 wlan_logging_sock_init_svc();
11051#endif
11052
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011053 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011054 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011055 ret = -ENOMEM;
11056 goto err_out;
11057 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011058
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011059 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11060 (void *)hdd_drv_ops_inactivity_handler, NULL,
11061 QDF_TIMER_TYPE_SW);
11062
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011063 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011064 hdd_qdf_print_init();
11065
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011066 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011067
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011068err_out:
11069 return ret;
11070}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011071
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011072/**
11073 * hdd_deinit() - Deinitialize Driver
11074 *
11075 * This function frees CDS global context with the help of cds_deinit. This
11076 * has to be the last function call in remove callback to free the global
11077 * context.
11078 */
11079void hdd_deinit(void)
11080{
Dustin Brownedce4a52017-05-10 11:59:15 -070011081 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011082 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011083
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011084 hdd_qdf_print_deinit();
11085
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011086#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11087 wlan_logging_sock_deinit_svc();
11088#endif
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011089
11090 wlan_destroy_bug_report_lock();
11091 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011092}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011093
Yue Ma6e7b1a02017-04-03 14:17:46 -070011094#ifdef QCA_WIFI_NAPIER_EMULATION
11095#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11096#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011097#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011098#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011099
Sachin Ahujadddd2632017-03-07 19:07:24 +053011100static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11101 struct file *file)
11102{
11103 return 0;
11104}
11105
11106static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11107 const char __user *user_buf,
11108 size_t count,
11109 loff_t *f_pos)
11110{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011111 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011112 static const char wlan_off_str[] = "OFF";
11113 static const char wlan_on_str[] = "ON";
11114 int ret;
11115 unsigned long rc;
11116
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011117 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011118 pr_err("Failed to read buffer\n");
11119 return -EINVAL;
11120 }
11121
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011122 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011123 pr_debug("Wifi turning off from UI\n");
11124 goto exit;
11125 }
11126
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011127 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011128 pr_err("Invalid value received from framework");
11129 goto exit;
11130 }
11131
11132 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011133 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011134 rc = wait_for_completion_timeout(&wlan_start_comp,
11135 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11136 if (!rc) {
11137 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11138 ret = -EINVAL;
11139 hdd_start_complete(ret);
11140 return ret;
11141 }
11142
11143 hdd_start_complete(0);
11144 }
11145
11146exit:
11147 return count;
11148}
11149
11150
11151const struct file_operations wlan_hdd_state_fops = {
11152 .owner = THIS_MODULE,
11153 .open = wlan_hdd_state_ctrl_param_open,
11154 .write = wlan_hdd_state_ctrl_param_write,
11155};
11156
11157static int wlan_hdd_state_ctrl_param_create(void)
11158{
11159 unsigned int wlan_hdd_state_major = 0;
11160 int ret;
11161 struct device *dev;
11162
11163 device = MKDEV(wlan_hdd_state_major, 0);
11164
11165 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11166 if (ret) {
11167 pr_err("Failed to register qcwlanstate");
11168 goto dev_alloc_err;
11169 }
11170 wlan_hdd_state_major = MAJOR(device);
11171
11172 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11173 if (IS_ERR(class)) {
11174 pr_err("wlan_hdd_state class_create error");
11175 goto class_err;
11176 }
11177
11178 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11179 if (IS_ERR(dev)) {
11180 pr_err("wlan_hdd_statedevice_create error");
11181 goto err_class_destroy;
11182 }
11183
11184 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11185 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11186 if (ret) {
11187 pr_err("Failed to add cdev error");
11188 goto cdev_add_err;
11189 }
11190
11191 pr_info("wlan_hdd_state %s major(%d) initialized",
11192 WLAN_MODULE_NAME, wlan_hdd_state_major);
11193
11194 return 0;
11195
11196cdev_add_err:
11197 device_destroy(class, device);
11198err_class_destroy:
11199 class_destroy(class);
11200class_err:
11201 unregister_chrdev_region(device, dev_num);
11202dev_alloc_err:
11203 return -ENODEV;
11204}
11205
11206static void wlan_hdd_state_ctrl_param_destroy(void)
11207{
11208 cdev_del(&wlan_hdd_state_cdev);
11209 device_destroy(class, device);
11210 class_destroy(class);
11211 unregister_chrdev_region(device, dev_num);
11212
11213 pr_info("Device node unregistered");
11214}
11215
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011216/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011217 * component_init - API to init cld component's
11218 *
11219 * Return: None
11220 */
11221static void component_init(void)
11222{
11223 pmo_init();
11224}
11225
11226/**
11227 * component_deinit - API to deinit cld component's
11228 *
11229 * Return: None
11230 */
11231static void component_deinit(void)
11232{
11233 pmo_deinit();
11234}
11235
11236/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011237 * __hdd_module_init - Module init helper
11238 *
11239 * Module init helper function used by both module and static driver.
11240 *
11241 * Return: 0 for success, errno on failure
11242 */
11243static int __hdd_module_init(void)
11244{
11245 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011246
Dustin Brownab482ac2017-06-09 17:00:44 -070011247 pr_err("%s: Loading driver v%s (%s)%s\n",
11248 WLAN_MODULE_NAME,
11249 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011250 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011251 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011252
Sachin Ahujadddd2632017-03-07 19:07:24 +053011253 ret = wlan_hdd_state_ctrl_param_create();
11254 if (ret) {
11255 pr_err("wlan_hdd_state_create:%x\n", ret);
11256 goto err_dev_state;
11257 }
11258
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011259 pld_init();
11260
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011261 ret = hdd_init();
11262 if (ret) {
11263 pr_err("hdd_init failed %x\n", ret);
11264 goto err_hdd_init;
11265 }
11266
Rajeev Kumar97767a02016-11-30 11:20:40 -080011267 dispatcher_init();
11268
Mukul Sharmad75a6672017-06-22 15:40:53 +053011269 /* Ensure to call post objmgr init */
11270 component_init();
11271
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011272 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011273
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011274 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011275
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011276 ret = wlan_hdd_register_driver();
11277 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011278 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11279 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011280 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011281 }
11282
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011283 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011284
11285 return 0;
11286out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011287 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011288 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011289 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011290
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011291err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011292 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011293 wlan_hdd_state_ctrl_param_destroy();
11294err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011295 return ret;
11296}
11297
11298/**
11299 * __hdd_module_exit - Module exit helper
11300 *
11301 * Module exit helper function used by both module and static driver.
11302 */
11303static void __hdd_module_exit(void)
11304{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011305
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011306 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11307 QWLAN_VERSIONSTR);
11308
bings6028ee82017-03-29 07:51:40 +080011309 cds_set_unload_in_progress(true);
11310
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011311 hdd_wait_for_recovery_completion();
11312
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011313 wlan_hdd_unregister_driver();
11314
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011315 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011316
Mukul Sharmad75a6672017-06-22 15:40:53 +053011317 /* Ensure to call prior to objmgr deinit */
11318 component_deinit();
11319
Rajeev Kumar97767a02016-11-30 11:20:40 -080011320 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011321 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011322 pld_deinit();
11323
Sachin Ahujadddd2632017-03-07 19:07:24 +053011324 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011325}
11326
Arun Khandavallifae92942016-08-01 13:31:08 +053011327#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011328/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011329 * wlan_boot_cb() - Wlan boot callback
11330 * @kobj: object whose directory we're creating the link in.
11331 * @attr: attribute the user is interacting with
11332 * @buff: the buffer containing the user data
11333 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011334 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011335 * This callback is invoked when the fs is ready to start the
11336 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011337 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011338 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011339 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011340static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011341 struct kobj_attribute *attr,
11342 const char *buf,
11343 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011344{
Arun Khandavallifae92942016-08-01 13:31:08 +053011345
Arun Khandavallifae92942016-08-01 13:31:08 +053011346 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011347 pr_err("%s: wlan driver already initialized\n", __func__);
11348 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011349 }
11350
Arun Khandavallifae92942016-08-01 13:31:08 +053011351 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011352 pr_err("%s: wlan driver initialization failed\n", __func__);
11353 return -EIO;
11354 }
11355
11356 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011357
11358 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011359}
Arun Khandavallifae92942016-08-01 13:31:08 +053011360
11361/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011362 * hdd_sysfs_cleanup() - cleanup sysfs
11363 *
11364 * Return: None
11365 *
11366 */
11367static void hdd_sysfs_cleanup(void)
11368{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011369 /* remove from group */
11370 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11371 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11372 wlan_loader->attr_group);
11373
11374 /* unlink the object from parent */
11375 kobject_del(wlan_loader->boot_wlan_obj);
11376
11377 /* free the object */
11378 kobject_put(wlan_loader->boot_wlan_obj);
11379
11380 kfree(wlan_loader->attr_group);
11381 kfree(wlan_loader);
11382
11383 wlan_loader = NULL;
11384}
11385
11386/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011387 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11388 * ready
11389 *
11390 * This is creates the syfs entry boot_wlan. Which shall be invoked
11391 * when the filesystem is ready.
11392 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011393 * QDF API cannot be used here since this function is called even before
11394 * initializing WLAN driver.
11395 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011396 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011397 */
11398static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011399{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011400 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011401
11402 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011403 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011404 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011405
11406 wlan_loader->boot_wlan_obj = NULL;
11407 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11408 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011409 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011410 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011411
11412 wlan_loader->loaded_state = 0;
11413 wlan_loader->attr_group->attrs = attrs;
11414
11415 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11416 kernel_kobj);
11417 if (!wlan_loader->boot_wlan_obj) {
11418 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011419 goto error_return;
11420 }
11421
11422 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11423 wlan_loader->attr_group);
11424 if (ret) {
11425 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11426 goto error_return;
11427 }
11428
11429 return 0;
11430
11431error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011432 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011433
11434 return ret;
11435}
11436
11437/**
11438 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11439 *
11440 * Return: 0 on success or errno on failure
11441 */
11442static int wlan_deinit_sysfs(void)
11443{
Arun Khandavallifae92942016-08-01 13:31:08 +053011444 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011445 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011446 return -EINVAL;
11447 }
11448
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011449 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011450 return 0;
11451}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011452
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011453#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011454
11455#ifdef MODULE
11456/**
11457 * __hdd_module_init - Module init helper
11458 *
11459 * Module init helper function used by both module and static driver.
11460 *
11461 * Return: 0 for success, errno on failure
11462 */
11463static int hdd_module_init(void)
11464{
Arun Khandavallifae92942016-08-01 13:31:08 +053011465 if (__hdd_module_init()) {
11466 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011467 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011468 }
11469
Dustin Brownab482ac2017-06-09 17:00:44 -070011470 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011471}
11472#else
11473static int __init hdd_module_init(void)
11474{
11475 int ret = -EINVAL;
11476
11477 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011478 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011479 pr_err("Failed to create sysfs entry for loading wlan");
11480
11481 return ret;
11482}
11483#endif
11484
11485
11486#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011487/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011488 * hdd_module_exit() - Exit function
11489 *
11490 * This is the driver exit point (invoked when module is unloaded using rmmod)
11491 *
11492 * Return: None
11493 */
11494static void __exit hdd_module_exit(void)
11495{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011496 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011497}
Arun Khandavallifae92942016-08-01 13:31:08 +053011498#else
11499static void __exit hdd_module_exit(void)
11500{
11501 __hdd_module_exit();
11502 wlan_deinit_sysfs();
11503}
11504#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011505
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011506static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11507{
11508 return param_set_copystring(kmessage, kp);
11509}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011510
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011511/**
11512 * is_con_mode_valid() check con mode is valid or not
11513 * @mode: global con mode
11514 *
11515 * Return: TRUE on success FALSE on failure
11516 */
11517static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11518{
11519 switch (mode) {
11520 case QDF_GLOBAL_MONITOR_MODE:
11521 case QDF_GLOBAL_FTM_MODE:
11522 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011523 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011524 return true;
11525 default:
11526 return false;
11527 }
11528}
11529
11530/**
11531 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11532 * @mode: global con mode
11533 *
11534 * Return: adapter mode
11535 */
11536static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11537 enum tQDF_GLOBAL_CON_MODE mode)
11538{
11539
11540 switch (mode) {
11541 case QDF_GLOBAL_MISSION_MODE:
11542 return QDF_STA_MODE;
11543 case QDF_GLOBAL_MONITOR_MODE:
11544 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011545 case QDF_GLOBAL_EPPING_MODE:
11546 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011547 case QDF_GLOBAL_FTM_MODE:
11548 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011549 case QDF_GLOBAL_QVIT_MODE:
11550 return QDF_QVIT_MODE;
11551 default:
11552 return QDF_MAX_NO_OF_MODE;
11553 }
11554}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011555
Dustin Brown27cd9942017-09-27 16:11:44 -070011556static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11557 enum tQDF_GLOBAL_CON_MODE curr_mode)
11558{
11559 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11560 return;
11561
11562 switch (curr_mode) {
11563 case QDF_GLOBAL_MISSION_MODE:
11564 case QDF_GLOBAL_MONITOR_MODE:
11565 case QDF_GLOBAL_FTM_MODE:
11566 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11567 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11568
11569 /* re-use the existing session */
11570 hdd_stop_all_adapters(hdd_ctx, false);
11571 break;
11572 default:
11573 break;
11574 }
11575}
11576
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011577static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011578 enum tQDF_GLOBAL_CON_MODE curr_mode)
11579{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011580 int driver_status;
11581
11582 driver_status = hdd_ctx->driver_status;
11583
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011584 switch (curr_mode) {
11585 case QDF_GLOBAL_MISSION_MODE:
11586 case QDF_GLOBAL_MONITOR_MODE:
11587 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011588 hdd_deinit_all_adapters(hdd_ctx, false);
11589 hdd_close_all_adapters(hdd_ctx, false);
11590 break;
11591 case QDF_GLOBAL_EPPING_MODE:
11592 epping_disable();
11593 epping_close();
11594 break;
11595 default:
11596 return;
11597 }
11598}
11599
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011600static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011601 enum tQDF_GLOBAL_CON_MODE mode)
11602{
Jeff Johnson9d295242017-08-29 14:39:48 -070011603 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011604 int ret = 0;
11605 bool rtnl_held;
11606 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11607 QDF_STATUS status;
11608
11609 if (!qdf_dev) {
11610 hdd_err("qdf device context is Null return!");
11611 return -EINVAL;
11612 }
11613
11614 rtnl_held = hdd_hold_rtnl_lock();
11615 switch (mode) {
11616 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011617 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11618 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011619 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011620 break;
11621 case QDF_GLOBAL_FTM_MODE:
11622 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11623 wlan_hdd_get_intf_addr(hdd_ctx),
11624 NET_NAME_UNKNOWN, rtnl_held);
11625 if (adapter == NULL)
11626 ret = -EINVAL;
11627 break;
11628 case QDF_GLOBAL_MONITOR_MODE:
11629 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11630 wlan_hdd_get_intf_addr(hdd_ctx),
11631 NET_NAME_UNKNOWN, rtnl_held);
11632 if (adapter == NULL)
11633 ret = -EINVAL;
11634 break;
11635 case QDF_GLOBAL_EPPING_MODE:
11636 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011637 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011638 hdd_err("Failed to open in eeping mode: %d", status);
11639 ret = -EINVAL;
11640 break;
11641 }
11642 ret = epping_enable(qdf_dev->dev);
11643 if (ret) {
11644 hdd_err("Failed to enable in epping mode : %d", ret);
11645 epping_close();
11646 }
11647 break;
11648 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011649 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011650 ret = -ENOTSUPP;
11651 break;
11652 }
11653 hdd_release_rtnl_lock();
11654 rtnl_held = false;
11655 return ret;
11656}
11657
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011658/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011659 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011660 * @kmessage: con mode name on which driver to be bring up
11661 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011662 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011663 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011664 * This function is invoked when user updates con mode using sys entry,
11665 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011666 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011667 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011668 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011669static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011670 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011671{
11672 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011673 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011674 enum tQDF_GLOBAL_CON_MODE curr_mode;
11675 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011676
Dustin Brownab6029b2017-05-24 13:04:19 -070011677 hdd_info("con_mode handler: %s", kmessage);
11678
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011679 ret = wlan_hdd_validate_context(hdd_ctx);
11680 if (ret)
11681 return ret;
11682
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011683 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011684
11685 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011686
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011687 if (!(is_con_mode_valid(con_mode))) {
11688 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011689 ret = -EINVAL;
11690 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011691 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011692
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011693 curr_mode = hdd_get_conparam();
11694 if (curr_mode == con_mode) {
11695 hdd_err("curr mode: %d is same as user triggered mode %d",
11696 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011697 ret = 0;
11698 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011699 }
11700
Dustin Brown27cd9942017-09-27 16:11:44 -070011701 /* ensure adapters are stopped */
11702 hdd_stop_present_mode(hdd_ctx, curr_mode);
11703
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011704 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011705 if (ret) {
11706 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011707 goto reset_flags;
11708 }
11709
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011710 /* Cleanup present mode before switching to new mode */
11711 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11712
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011713 hdd_set_conparam(con_mode);
11714
11715 /* Register for new con_mode & then kick_start modules again */
11716 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11717 if (ret) {
11718 hdd_err("Failed to register for new mode");
11719 goto reset_flags;
11720 }
11721
11722 adapter_mode = hdd_get_adpter_mode(con_mode);
11723 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11724 hdd_err("invalid adapter");
11725 ret = -EINVAL;
11726 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011727 }
11728
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011729 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011730 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011731 hdd_err("Failed to get adapter:%d", adapter_mode);
11732 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011733 }
11734
11735 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11736 if (ret) {
11737 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011738 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011739 }
11740
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011741 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011742 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011743 if (hdd_start_adapter(adapter)) {
11744 hdd_err("Failed to start %s adapter", kmessage);
11745 ret = -EINVAL;
11746 goto reset_flags;
11747 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011748 }
11749
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011750 hdd_info("Mode successfully changed to %s", kmessage);
11751 ret = 0;
11752
11753reset_flags:
11754 cds_set_load_in_progress(false);
11755 return ret;
11756}
11757
11758
11759static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11760{
11761 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011762 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011763
11764 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11765 ret = wlan_hdd_validate_context(hdd_ctx);
11766 if (ret)
11767 return ret;
11768
11769 cds_ssr_protect(__func__);
11770 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11771 cds_ssr_unprotect(__func__);
11772
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011773 return ret;
11774}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011775
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011776static int con_mode_handler_ftm(const char *kmessage,
11777 struct kernel_param *kp)
11778{
11779 int ret;
11780
11781 ret = param_set_int(kmessage, kp);
11782
11783 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11784 pr_err("Only FTM mode supported!");
11785 return -ENOTSUPP;
11786 }
11787
11788 hdd_set_conparam(con_mode_ftm);
11789 con_mode = con_mode_ftm;
11790
11791 return ret;
11792}
11793
Ravi Joshia307f632017-07-17 23:41:41 -070011794static int con_mode_handler_monitor(const char *kmessage,
11795 struct kernel_param *kp)
11796{
11797 int ret;
11798
11799 ret = param_set_int(kmessage, kp);
11800
11801 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11802 pr_err("Only Monitor mode supported!");
11803 return -ENOTSUPP;
11804 }
11805
11806 hdd_set_conparam(con_mode_monitor);
11807 con_mode = con_mode_monitor;
11808
11809 return ret;
11810}
11811
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011812/**
11813 * hdd_get_conparam() - driver exit point
11814 *
11815 * This is the driver exit point (invoked when module is unloaded using rmmod)
11816 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011817 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011818 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011819enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011820{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011821 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011822}
11823
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011824void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011825{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011826 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011827}
11828
Komal Seelamc11bb222016-01-27 18:57:10 +053011829/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011830 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11831 * @hdd_ctx: HDD context
11832 *
11833 * Cleans up the pre cac interface, if it exists
11834 *
11835 * Return: None
11836 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011837void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011838{
11839 uint8_t session_id;
11840 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011841 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011842
11843 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11844 if (QDF_IS_STATUS_ERROR(status)) {
11845 hdd_err("failed to get pre cac vdev id");
11846 return;
11847 }
11848
11849 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11850 if (!precac_adapter) {
11851 hdd_err("invalid pre cac adapater");
11852 return;
11853 }
11854
11855 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11856 wlan_hdd_sap_pre_cac_failure,
11857 (void *)precac_adapter);
11858 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11859
11860}
11861
11862/**
Komal Seelamec702b02016-02-24 18:42:16 +053011863 * hdd_update_ol_config - API to update ol configuration parameters
11864 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011865 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011866 * Return: void
11867 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011868static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011869{
Komal Seelamec702b02016-02-24 18:42:16 +053011870 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011871 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011872
Komal Seelamec702b02016-02-24 18:42:16 +053011873 if (!ol_ctx)
11874 return;
11875
11876 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11877 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11878 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11879 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011880 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011881
11882 ol_init_ini_config(ol_ctx, &cfg);
11883}
11884
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011885#ifdef FEATURE_RUNTIME_PM
11886/**
11887 * hdd_populate_runtime_cfg() - populate runtime configuration
11888 * @hdd_ctx: hdd context
11889 * @cfg: pointer to the configuration memory being populated
11890 *
11891 * Return: void
11892 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011893static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011894 struct hif_config_info *cfg)
11895{
11896 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11897 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11898}
11899#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011900static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011901 struct hif_config_info *cfg)
11902{
11903}
11904#endif
11905
Komal Seelamec702b02016-02-24 18:42:16 +053011906/**
11907 * hdd_update_hif_config - API to update HIF configuration parameters
11908 * @hdd_ctx: HDD Context
11909 *
11910 * Return: void
11911 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011912static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011913{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011914 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011915 struct hif_config_info cfg;
11916
11917 if (!scn)
11918 return;
11919
11920 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011921 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011922 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011923
11924 if (hdd_ctx->config->prevent_link_down)
11925 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011926}
11927
11928/**
11929 * hdd_update_config() - Initialize driver per module ini parameters
11930 * @hdd_ctx: HDD Context
11931 *
11932 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011933 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011934 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011935int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011936{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011937 int ret;
11938
Komal Seelamec702b02016-02-24 18:42:16 +053011939 hdd_update_ol_config(hdd_ctx);
11940 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011941 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11942 ret = hdd_update_cds_config_ftm(hdd_ctx);
11943 else
11944 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011945 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011946
11947 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011948}
11949
Mukul Sharma9d797a02017-01-05 20:26:03 +053011950#ifdef FEATURE_WLAN_RA_FILTERING
11951/**
11952 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11953 * @psoc_cfg: pmo psoc Configuration
11954 * @hdd_ctx: Pointer to hdd context
11955 *
11956 * Return: none
11957 */
11958static inline void hdd_ra_populate_pmo_config(
11959 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011960 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011961{
11962 psoc_cfg->ra_ratelimit_interval =
11963 hdd_ctx->config->RArateLimitInterval;
11964 psoc_cfg->ra_ratelimit_enable =
11965 hdd_ctx->config->IsRArateLimitEnabled;
11966}
11967#else
11968static inline void hdd_ra_populate_pmo_config(
11969 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011970 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011971{
11972}
11973#endif
11974/**
11975 * hdd_update_pmo_config - API to update pmo configuration parameters
11976 * @hdd_ctx: HDD context
11977 *
11978 * Return: void
11979 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011980static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011981{
11982 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11983 struct pmo_psoc_cfg psoc_cfg;
11984 QDF_STATUS status;
11985
11986 /*
11987 * Value of hdd_ctx->wowEnable can be,
11988 * 0 - Disable both magic pattern match and pattern byte match.
11989 * 1 - Enable magic pattern match on all interfaces.
11990 * 2 - Enable pattern byte match on all interfaces.
11991 * 3 - Enable both magic patter and pattern byte match on
11992 * all interfaces.
11993 */
11994 psoc_cfg.magic_ptrn_enable =
11995 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11996 psoc_cfg.ptrn_match_enable_all_vdev =
11997 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080011998 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
11999 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012000 psoc_cfg.bpf_enable =
12001 hdd_ctx->config->bpf_packet_filter_enable;
12002 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012003 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012004 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12005 if (hdd_ctx->config->fhostNSOffload)
12006 psoc_cfg.ns_offload_enable_dynamic = true;
12007 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12008 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12009 psoc_cfg.active_mode_offload =
12010 hdd_ctx->config->active_mode_offload;
12011 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
12012 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012013 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12014 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12015 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12016 psoc_cfg.power_save_mode =
12017 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012018 psoc_cfg.auto_power_save_fail_mode =
12019 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012020
12021 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012022 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12023 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012024 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
12025 if (status != QDF_STATUS_SUCCESS) {
12026 hdd_err("failed pmo psoc configuration");
12027 return -EINVAL;
12028 }
12029
12030 return 0;
12031}
12032
Abhishek Singhb20db962017-03-03 21:28:46 +053012033#ifdef FEATURE_WLAN_SCAN_PNO
12034static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12035 struct hdd_config *cfg)
12036{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012037 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12038
Abhishek Singhb20db962017-03-03 21:28:46 +053012039 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12040 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12041 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12042 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12043 pno_cfg->channel_prediction_full_scan =
12044 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012045 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12046 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12047 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12048 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012049}
12050#else
12051static inline void
12052hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012053 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012054{
Abhishek Singhb20db962017-03-03 21:28:46 +053012055}
12056#endif
12057
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012058void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12059 struct hdd_config *cfg)
12060{
12061 uint8_t i = 0;
12062
12063 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12064 if (!ie_whitelist->white_list)
12065 return;
12066
12067 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12068 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12069 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12070 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12071 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12072 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12073 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12074 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12075
12076 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12077 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12078 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12079}
12080
Abhishek Singh257a9482017-03-06 16:52:39 +053012081/**
12082 * hdd_update_scan_config - API to update scan configuration parameters
12083 * @hdd_ctx: HDD context
12084 *
12085 * Return: 0 if success else err
12086 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012087static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012088{
12089 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12090 struct scan_user_cfg scan_cfg;
12091 struct hdd_config *cfg = hdd_ctx->config;
12092 QDF_STATUS status;
12093
12094 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12095 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12096 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12097 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12098 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12099 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12100 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012101 /* convert to ms */
12102 scan_cfg.scan_cache_aging_time =
12103 cfg->scanAgingTimeout * 1000;
12104 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12105 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12106 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12107 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012108 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012109 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012110 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Abhishek Singh257a9482017-03-06 16:52:39 +053012111
Abhishek Singhb20db962017-03-03 21:28:46 +053012112 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012113 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012114
Abhishek Singh257a9482017-03-06 16:52:39 +053012115 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12116 if (status != QDF_STATUS_SUCCESS) {
12117 hdd_err("failed pmo psoc configuration");
12118 return -EINVAL;
12119 }
12120
12121 return 0;
12122}
Abhishek Singh257a9482017-03-06 16:52:39 +053012123
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012124static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012125{
12126 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12127 struct tdls_start_params tdls_cfg;
12128 struct tdls_user_config *config = &tdls_cfg.config;
12129 struct hdd_config *cfg = hdd_ctx->config;
12130 QDF_STATUS status;
12131
12132 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12133 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12134 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12135 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12136 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12137 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12138 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12139 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12140 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12141 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12142 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12143 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12144 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12145 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12146 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12147 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12148 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12149 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12150 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12151 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12152 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12153 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12154 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12155 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12156 (cfg->fEnableTDLSImplicitTrigger ?
12157 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12158 (cfg->fTDLSExternalControl ?
12159 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12160
12161 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12162 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12163 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12164 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012165 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012166 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012167 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12168 tdls_cfg.tdls_evt_cb_data = psoc;
12169 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12170 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12171 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012172 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12173 tdls_cfg.tdls_wmm_cb_data = psoc;
12174 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12175 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012176 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012177
12178 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12179 if (status != QDF_STATUS_SUCCESS) {
12180 hdd_err("failed pmo psoc configuration");
12181 return -EINVAL;
12182 }
12183
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012184 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012185 /* enable napier specific tdls data path */
12186 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012187
Frank Liud4b2fa02017-03-29 11:46:48 +080012188 return 0;
12189}
Frank Liud4b2fa02017-03-29 11:46:48 +080012190
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012191int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012192{
12193 int ret;
12194
12195 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012196 if (ret)
12197 return ret;
12198 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012199 if (ret)
12200 return ret;
12201 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012202
12203 return ret;
12204}
12205
Agrawal Ashish65634612016-08-18 13:24:32 +053012206/**
12207 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12208 * @mode : cfg80211 DFS mode
12209 *
12210 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12211 */
12212enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12213{
12214 switch (mode) {
12215 case DFS_MODE_ENABLE:
12216 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012217 case DFS_MODE_DISABLE:
12218 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012219 case DFS_MODE_DEPRIORITIZE:
12220 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012221 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012222 hdd_debug("ACS dfs mode is NONE");
12223 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012224 }
12225}
12226
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012227/**
12228 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12229 * @hddctx: pointer to hdd context
12230 * @set_value: enable/disable
12231 *
12232 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12233 * Host(even though it is duplicate). When Host send vendor command
12234 * disable,FW doesn't perform any action. Whenever any change in
12235 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12236 *
12237 * return - 0 on success, appropriate error values on failure.
12238 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012239int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012240{
12241 QDF_STATUS status;
12242
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012243 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012244 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012245
12246 if (!hddctx->config->goptimize_chan_avoid_event) {
12247 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12248 return -EINVAL;
12249 }
12250
12251 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12252 if (!QDF_IS_STATUS_SUCCESS(status)) {
12253 hdd_err("Failed to send chan avoid command to SME");
12254 return -EINVAL;
12255 }
12256 return 0;
12257}
Agrawal Ashish65634612016-08-18 13:24:32 +053012258
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012259/**
12260 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12261 * @value: value to set
12262 *
12263 * This function will set the passed value to roaming in progress flag.
12264 *
12265 * Return: None
12266 */
12267void hdd_set_roaming_in_progress(bool value)
12268{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012269 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012270
12271 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12272 if (!hdd_ctx) {
12273 hdd_err("HDD context is NULL");
12274 return;
12275 }
12276
12277 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012278 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012279}
12280
12281/**
12282 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012283 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012284 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012285 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012286 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012287bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012288{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012289 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012290 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012291
12292 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12293 if (!hdd_ctx) {
12294 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012295 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012296 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012297 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12298 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012299 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12300 hdd_ctx->roaming_in_progress);
12301
12302 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012303}
12304
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012305/**
12306 * hdd_is_connection_in_progress() - check if connection is in
12307 * progress
12308 * @session_id: session id
12309 * @reason: scan reject reason
12310 *
12311 * Go through each adapter and check if Connection is in progress
12312 *
12313 * Return: true if connection is in progress else false
12314 */
12315bool hdd_is_connection_in_progress(uint8_t *session_id,
12316 enum scan_reject_states *reason)
12317{
12318 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012319 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012320 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012321 QDF_STATUS status = 0;
12322 uint8_t sta_id = 0;
12323 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012324 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012325
12326 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12327 if (!hdd_ctx) {
12328 hdd_err("HDD context is NULL");
12329 return false;
12330 }
12331
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012332 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12333 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012334 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012335 if (!adapter)
12336 goto end;
12337
12338 hdd_info("Adapter with device mode %s(%d) exists",
12339 hdd_device_mode_to_string(adapter->device_mode),
12340 adapter->device_mode);
12341 if (((QDF_STA_MODE == adapter->device_mode)
12342 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12343 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12344 && (eConnectionState_Connecting ==
12345 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12346 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012347 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012348 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12349 adapter->sessionId);
12350 if (session_id && reason) {
12351 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012352 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012353 }
12354 return true;
12355 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012356 /*
12357 * sme_neighbor_middle_of_roaming is for LFR2
12358 * hdd_is_roaming_in_progress is for LFR3
12359 */
12360 if (((QDF_STA_MODE == adapter->device_mode) &&
12361 sme_neighbor_middle_of_roaming(
12362 WLAN_HDD_GET_HAL_CTX(adapter),
12363 adapter->sessionId)) ||
12364 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012365 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012366 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12367 adapter->sessionId);
12368 if (session_id && reason) {
12369 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012370 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012371 }
12372 return true;
12373 }
12374 if ((QDF_STA_MODE == adapter->device_mode) ||
12375 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12376 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12377 hdd_sta_ctx =
12378 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12379 if ((eConnectionState_Associated ==
12380 hdd_sta_ctx->conn_info.connState)
12381 && (false ==
12382 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12383 sta_mac = (uint8_t *)
12384 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012385 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012386 " is in middle of WPS/EAPOL exchange.",
12387 MAC_ADDR_ARRAY(sta_mac));
12388 if (session_id && reason) {
12389 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012390 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012391 }
12392 return true;
12393 }
12394 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12395 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12396 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12397 sta_id++) {
12398 if (!((adapter->aStaInfo[sta_id].isUsed)
12399 && (OL_TXRX_PEER_STATE_CONN ==
12400 adapter->aStaInfo[sta_id].tlSTAState)))
12401 continue;
12402
12403 sta_mac = (uint8_t *)
12404 &(adapter->aStaInfo[sta_id].
12405 macAddrSTA.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012406 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012407 " of SAP/GO is in middle of WPS/EAPOL exchange",
12408 MAC_ADDR_ARRAY(sta_mac));
12409 if (session_id && reason) {
12410 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012411 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012412 }
12413 return true;
12414 }
12415 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012416 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012417 return true;
12418 }
12419 }
12420end:
12421 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12422 adapter_node = next;
12423 }
12424 return false;
12425}
12426
12427/**
12428 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012429 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012430 *
12431 * Return: None
12432 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012433void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012434{
Jeff Johnson87251032017-08-29 13:31:11 -070012435 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012436 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012437 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012438 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012439 tsap_Config_t *sap_config;
12440 void *sap_ctx;
12441
12442 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12443 sap_config = &hdd_ap_ctx->sapConfig;
12444 sap_ctx = hdd_ap_ctx->sapContext;
12445
12446 mutex_lock(&hdd_ctx->sap_lock);
12447 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12448 wlan_hdd_del_station(ap_adapter);
12449 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12450 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12451 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12452 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12453 qdf_status =
12454 qdf_wait_single_event(&hostapd_state->
12455 qdf_stop_bss_event,
12456 SME_CMD_TIMEOUT_VALUE);
12457
12458 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012459 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012460 goto end;
12461 }
12462 }
12463 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012464 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012465 ap_adapter->device_mode, ap_adapter->sessionId);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012466 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012467
12468 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012469 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012470 wlansap_reset_sap_config_add_ie(sap_config,
12471 eUPDATE_IE_ALL);
12472 goto end;
12473 }
12474
12475 qdf_event_reset(&hostapd_state->qdf_event);
12476 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12477 sap_config,
12478 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012479 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012480 wlansap_reset_sap_config_add_ie(sap_config,
12481 eUPDATE_IE_ALL);
12482 goto end;
12483 }
12484
Jeff Johnson6867ec32017-09-29 20:30:20 -070012485 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012486 qdf_status =
12487 qdf_wait_single_event(&hostapd_state->qdf_event,
12488 SME_CMD_TIMEOUT_VALUE);
12489 wlansap_reset_sap_config_add_ie(sap_config,
12490 eUPDATE_IE_ALL);
12491 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012492 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012493 goto end;
12494 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012495 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012496 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12497 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012498 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12499 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012500 ap_adapter->sessionId);
12501 hostapd_state->bCommit = true;
12502 }
12503end:
12504 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012505}
12506
12507/**
12508 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12509 * with non dfs acs
12510 *
12511 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12512 *
12513 * Return: None
12514 */
12515void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12516{
Jeff Johnson9d295242017-08-29 14:39:48 -070012517 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012518 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012519 cds_context_type *cds_ctx;
12520
12521 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12522 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012523 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012524 return;
12525 }
12526
12527 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12528 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012529 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012530 return;
12531 }
12532
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012533 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12534 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012535 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012536 return;
12537 }
12538
12539 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012540 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12541 &ap_adapter->event_flags) &&
12542 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12543 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012544
Jeff Johnson6867ec32017-09-29 20:30:20 -070012545 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012546 ap_adapter->sessionCtx.ap.sapConfig.channel =
12547 AUTO_CHANNEL_SELECT;
12548 ap_adapter->sessionCtx.ap.sapConfig.
12549 acs_cfg.acs_mode = true;
12550
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012551 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012552 }
12553}
12554
12555/**
12556 * hdd_set_connection_in_progress() - to set the connection in
12557 * progress flag
12558 * @value: value to set
12559 *
12560 * This function will set the passed value to connection in progress flag.
12561 * If value is previously being set to true then no need to set it again.
12562 *
12563 * Return: true if value is being set correctly and false otherwise.
12564 */
12565bool hdd_set_connection_in_progress(bool value)
12566{
12567 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012568 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012569
12570 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12571 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012572 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012573 return false;
12574 }
12575
12576 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12577 /*
12578 * if the value is set to true previously and if someone is
12579 * trying to make it true again then it could be some race
12580 * condition being triggered. Avoid this situation by returning
12581 * false
12582 */
12583 if (hdd_ctx->connection_in_progress && value)
12584 status = false;
12585 else
12586 hdd_ctx->connection_in_progress = value;
12587 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12588 return status;
12589}
12590
Jeff Johnson9d295242017-08-29 14:39:48 -070012591int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012592{
12593 if (!adapter) {
12594 hdd_err("Invalid adapter");
12595 return -EINVAL;
12596 }
12597 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012598 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012599 WMA_VDEV_MCC_SET_TIME_QUOTA,
12600 set_value, VDEV_CMD);
12601 return 0;
12602
12603}
12604
Jeff Johnson9d295242017-08-29 14:39:48 -070012605int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012606{
12607 if (!adapter) {
12608 hdd_err("Invalid adapter");
12609 return -EINVAL;
12610 }
12611
12612 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012613 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012614 WMA_VDEV_MCC_SET_TIME_LATENCY,
12615 set_value, VDEV_CMD);
12616 return 0;
12617}
12618
Jeff Johnson9d295242017-08-29 14:39:48 -070012619struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012620 *psoc, uint8_t vdev_id)
12621{
Jeff Johnson9d295242017-08-29 14:39:48 -070012622 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012623 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012624
12625 /*
12626 * Currently PSOC is not being used. But this logic will
12627 * change once we have the converged implementation of
12628 * HDD context per PSOC in place. This would break if
12629 * multiple vdev objects reuse the vdev id.
12630 */
12631 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12632 if (!adapter)
12633 hdd_err("Get adapter by vdev id failed");
12634
12635 return adapter;
12636}
12637
Jeff Johnson9d295242017-08-29 14:39:48 -070012638int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012639 int8_t *rssi, int8_t *snr)
12640{
12641 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012642 struct hdd_wext_state *wext_state =
12643 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012644 tCsrRoamProfile *profile = &wext_state->roamProfile;
12645
12646 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12647 profile, bssid, rssi, snr);
12648 if (QDF_STATUS_SUCCESS != status) {
12649 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12650 return -EINVAL;
12651 }
12652
12653 return 0;
12654}
12655
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012656/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012657 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12658 * @adapter - HDD adapter
12659 * @tos - type of service
12660 * @status - status of the traffic
12661 *
12662 * Return: 0 on success and non zero value on failure
12663 */
12664
12665int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12666 bool is_tos_active)
12667{
12668 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012669 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012670 uint32_t max_off_chan_time = 0;
12671 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012672 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012673 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012674
12675 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12676 ret = wlan_hdd_validate_context(hdd_ctx);
12677
12678 if (ret < 0) {
12679 hdd_err("failed to set limit off chan params");
12680 return ret;
12681 }
12682
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012683 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12684
12685 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012686 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012687 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012688 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012689
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012690 if (adapter->active_ac) {
12691 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012692 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012693 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12694 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12695 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012696 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012697 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012698 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12699 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12700 PM_LATENCY);
12701 } else {
12702 /*ignore this command if only BE/BK is active */
12703 is_tos_active = false;
12704 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12705 hdd_ctx->config->conc_system_pref);
12706 }
12707 } else {
12708 /* No active tos */
12709 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12710 hdd_ctx->config->conc_system_pref);
12711 }
12712
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012713 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12714 is_tos_active, max_off_chan_time,
12715 hdd_ctx->config->nRestTimeConc, true);
12716 if (!QDF_IS_STATUS_SUCCESS(status)) {
12717 hdd_err("failed to set limit off chan params");
12718 ret = -EINVAL;
12719 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012720
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012721 return ret;
12722}
12723
12724/**
12725 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12726 * @adapter - HDD adapter
12727 *
12728 * Return: 0 on success and non zero value on failure
12729 */
12730int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12731{
12732 struct hdd_context *hdd_ctx;
12733 int ret;
12734 QDF_STATUS status;
12735 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12736
12737 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12738 ret = wlan_hdd_validate_context(hdd_ctx);
12739 if (ret < 0)
12740 return ret;
12741
12742 /* set the system preferece to default */
12743 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12744 hdd_ctx->config->conc_system_pref);
12745
12746 /* clear the bitmap */
12747 adapter->active_ac = 0;
12748
12749 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
12750 adapter->sessionId, adapter->active_ac);
12751
12752 status = sme_send_limit_off_channel_params(hal, adapter->sessionId,
12753 false, 0, 0, false);
12754 if (!QDF_IS_STATUS_SUCCESS(status)) {
12755 hdd_err("failed to reset limit off chan params");
12756 ret = -EINVAL;
12757 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012758
12759 return ret;
12760}
12761
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012762/**
12763 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12764 * @drv_op: Enum indicating driver op
12765 *
12766 * Return: none
12767 */
12768void hdd_start_driver_ops_timer(int drv_op)
12769{
12770 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12771 switch (drv_op) {
12772 case eHDD_DRV_OP_PROBE:
12773 memcpy(drv_ops_string, "probe", sizeof("probe"));
12774 break;
12775 case eHDD_DRV_OP_REMOVE:
12776 memcpy(drv_ops_string, "remove", sizeof("remove"));
12777 break;
12778 case eHDD_DRV_OP_SHUTDOWN:
12779 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12780 break;
12781 case eHDD_DRV_OP_REINIT:
12782 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12783 break;
12784 }
12785
12786 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12787 HDD_OPS_INACTIVITY_TIMEOUT);
12788}
12789
12790/**
12791 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12792 *
12793 * Return: none
12794 */
12795void hdd_stop_driver_ops_timer(void)
12796{
12797 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12798}
12799
12800/**
12801 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12802 * inactivity timer
12803 *
12804 * Return: None
12805 */
12806void hdd_drv_ops_inactivity_handler(void)
12807{
12808 hdd_err("%s: %d Sec timer expired while in .%s",
12809 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12810
12811 /* Driver shutdown is stuck, no recovery possible at this point */
12812 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12813 sizeof("shutdown")))
12814 QDF_BUG(0);
12815
12816 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012817 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012818 else
12819 QDF_BUG(0);
12820}
12821
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012822void hdd_pld_ipa_uc_shutdown_pipes(void)
12823{
12824 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12825
12826 if (!hdd_ctx)
12827 return;
12828
12829 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12830}
12831
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012832/* Register the module init/exit functions */
12833module_init(hdd_module_init);
12834module_exit(hdd_module_exit);
12835
12836MODULE_LICENSE("Dual BSD/GPL");
12837MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12838MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12839
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012840module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12841 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012842
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012843module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12844 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12845
Ravi Joshia307f632017-07-17 23:41:41 -070012846module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12847 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12848
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012849module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12850 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12851
12852module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12853
12854module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12855
12856module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);